From bc282425088455198a7a99511c75914477d4ed32 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 23:14:51 +0200 Subject: Merging upstream version 1.9.3. Signed-off-by: Daniel Baumann --- iputils.hh | 72 +++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 19 deletions(-) (limited to 'iputils.hh') diff --git a/iputils.hh b/iputils.hh index dafc24a..e5943c8 100644 --- a/iputils.hh +++ b/iputils.hh @@ -123,6 +123,24 @@ union ComboAddress { return rhs.operator<(*this); } + struct addressPortOnlyHash + { + uint32_t operator()(const ComboAddress& ca) const + { + const unsigned char* start = nullptr; + if (ca.sin4.sin_family == AF_INET) { + start = reinterpret_cast(&ca.sin4.sin_addr.s_addr); + auto tmp = burtle(start, 4, 0); + return burtle(reinterpret_cast(&ca.sin4.sin_port), 2, tmp); + } + { + start = reinterpret_cast(&ca.sin6.sin6_addr.s6_addr); + auto tmp = burtle(start, 16, 0); + return burtle(reinterpret_cast(&ca.sin6.sin6_port), 2, tmp); + } + } + }; + struct addressOnlyHash { uint32_t operator()(const ComboAddress& ca) const @@ -212,8 +230,9 @@ union ComboAddress { sin4.sin_port = 0; if(makeIPv4sockaddr(str, &sin4)) { sin6.sin6_family = AF_INET6; - if(makeIPv6sockaddr(str, &sin6) < 0) + if(makeIPv6sockaddr(str, &sin6) < 0) { throw PDNSException("Unable to convert presentation address '"+ str +"'"); + } } if(!sin4.sin_port) // 'str' overrides port! @@ -332,6 +351,11 @@ union ComboAddress { return toStringWithPortExcept(53); } + [[nodiscard]] string toStructuredLogString() const + { + return toStringWithPort(); + } + string toByteString() const { if (isIPv4()) { @@ -342,11 +366,14 @@ union ComboAddress { void truncate(unsigned int bits) noexcept; - uint16_t getPort() const + uint16_t getNetworkOrderPort() const noexcept { - return ntohs(sin4.sin_port); + return sin4.sin_port; + } + uint16_t getPort() const noexcept + { + return ntohs(getNetworkOrderPort()); } - void setPort(uint16_t port) { sin4.sin_port = htons(port); @@ -483,22 +510,22 @@ public: Netmask(const ComboAddress& network, uint8_t bits=0xff): d_network(network) { d_network.sin4.sin_port = 0; - setBits(network.isIPv4() ? std::min(bits, static_cast(32)) : std::min(bits, static_cast(128))); + setBits(bits); } Netmask(const sockaddr_in* network, uint8_t bits = 0xff): d_network(network) { d_network.sin4.sin_port = 0; - setBits(std::min(bits, static_cast(32))); + setBits(bits); } Netmask(const sockaddr_in6* network, uint8_t bits = 0xff): d_network(network) { d_network.sin4.sin_port = 0; - setBits(std::min(bits, static_cast(128))); + setBits(bits); } void setBits(uint8_t value) { - d_bits = value; + d_bits = d_network.isIPv4() ? std::min(value, static_cast(32U)) : std::min(value, static_cast(128U)); if (d_bits < 32) { d_mask = ~(0xFFFFFFFF >> d_bits); @@ -1182,13 +1209,13 @@ public: } // addr_bits) { max_bits = addr_bits; @@ -1257,7 +1284,7 @@ public: } //* vec) const + std::vector toStringVector() const { - for(auto iter = tree.begin(); iter != tree.end(); ++iter) { - vec->push_back((iter->second ? "" : "!") + iter->first.toString()); + std::vector out; + out.reserve(tree.size()); + for (const auto& entry : tree) { + out.push_back((entry.second ? "" : "!") + entry.first.toString()); } + return out; } void toMasks(const string &ips) @@ -1509,7 +1539,8 @@ public: d_addr.sin4.sin_port = 0; // this guarantees d_network compares identical } - AddressAndPortRange(ComboAddress ca, uint8_t addrMask, uint8_t portMask = 0): d_addr(std::move(ca)), d_addrMask(addrMask), d_portMask(portMask) + AddressAndPortRange(ComboAddress ca, uint8_t addrMask, uint8_t portMask = 0) : + d_addr(ca), d_addrMask(addrMask), d_portMask(portMask) { if (!d_addr.isIPv4()) { d_portMask = 0; @@ -1691,6 +1722,7 @@ int SAccept(int sockfd, ComboAddress& remote); int SListen(int sockfd, int limit); int SSetsockopt(int sockfd, int level, int opname, int value); void setSocketIgnorePMTU(int sockfd, int family); +void setSocketForcePMTU(int sockfd, int family); bool setReusePort(int sockfd); #if defined(IP_PKTINFO) @@ -1721,3 +1753,5 @@ std::vector getListOfRangesOfNetworkInterface(const std::string& itf); void setSocketBuffer(int fd, int optname, uint32_t size); void setSocketReceiveBuffer(int fd, uint32_t size); void setSocketSendBuffer(int fd, uint32_t size); +uint32_t raiseSocketReceiveBufferToMax(int socket); +uint32_t raiseSocketSendBufferToMax(int socket); -- cgit v1.2.3