From: Wouter Wijngaards Date: Wed, 1 Apr 2009 10:01:43 +0000 (+0000) Subject: suppress ipv4mapped errors from logs. X-Git-Tag: release-1.3.0~53 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c6da8de51734f3629fedbe65c706482a8a3815a5;p=thirdparty%2Funbound.git suppress ipv4mapped errors from logs. git-svn-id: file:///svn/unbound/trunk@1570 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index e2fb79e56..68c114e50 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,9 @@ +1 April 2009: Wouter + - suppress errors when trying to contact authority servers that gave + ipv6 AAAA records for their nameservers with ipv4 mapped contents. + Still tries to do so, could work when deployed in intranet. + Higher verbosity shows the error. + 30 March 2009: Wouter - Fixup LDFLAGS from libevent sourcedir compile configure restore. - Fixup so no non-absolute rpaths are added. diff --git a/testcode/unitmain.c b/testcode/unitmain.c index fb0d88f29..a8b4763b8 100644 --- a/testcode/unitmain.c +++ b/testcode/unitmain.c @@ -238,6 +238,29 @@ net_test() (struct sockaddr_storage*)&b6, i, l6) == i); } } + /* test addr_is_ip4mapped */ + if(1) { + struct sockaddr_storage a; + socklen_t l = (socklen_t)sizeof(a); + unit_assert(ipstrtoaddr("12.13.14.15", 53, &a, &l)); + unit_assert(!addr_is_ip4mapped(&a, l)); + unit_assert(ipstrtoaddr("fe80::217:31ff:fe91:df", 53, &a, &l)); + unit_assert(!addr_is_ip4mapped(&a, l)); + unit_assert(ipstrtoaddr("ffff::217:31ff:fe91:df", 53, &a, &l)); + unit_assert(!addr_is_ip4mapped(&a, l)); + unit_assert(ipstrtoaddr("::ffff:31ff:fe91:df", 53, &a, &l)); + unit_assert(!addr_is_ip4mapped(&a, l)); + unit_assert(ipstrtoaddr("::fffe:fe91:df", 53, &a, &l)); + unit_assert(!addr_is_ip4mapped(&a, l)); + unit_assert(ipstrtoaddr("::ffff:127.0.0.1", 53, &a, &l)); + unit_assert(addr_is_ip4mapped(&a, l)); + unit_assert(ipstrtoaddr("::ffff:127.0.0.2", 53, &a, &l)); + unit_assert(addr_is_ip4mapped(&a, l)); + unit_assert(ipstrtoaddr("::ffff:192.168.0.2", 53, &a, &l)); + unit_assert(addr_is_ip4mapped(&a, l)); + unit_assert(ipstrtoaddr("2::ffff:192.168.0.2", 53, &a, &l)); + unit_assert(!addr_is_ip4mapped(&a, l)); + } } #include "util/config_file.h" diff --git a/util/net_help.c b/util/net_help.c index c77ccdc7c..66276b519 100644 --- a/util/net_help.c +++ b/util/net_help.c @@ -474,3 +474,17 @@ addr_to_str(struct sockaddr_storage* addr, socklen_t addrlen, snprintf(buf, len, "(inet_ntop_error)"); } } + +int +addr_is_ip4mapped(struct sockaddr_storage* addr, socklen_t addrlen) +{ + /* prefix for ipv4 into ipv6 mapping is ::ffff:x.x.x.x */ + const uint8_t map_prefix[16] = + {0,0,0,0, 0,0,0,0, 0,0,0xff,0xff, 0,0,0,0}; + uint8_t* s; + if(!addr_is_ip6(addr, addrlen)) + return 0; + /* s is 16 octet ipv6 address string */ + s = (uint8_t*)&((struct sockaddr_in6*)addr)->sin6_addr; + return (memcmp(s, map_prefix, 12) == 0); +} diff --git a/util/net_help.h b/util/net_help.h index 0a60cae98..8fa486722 100644 --- a/util/net_help.h +++ b/util/net_help.h @@ -269,4 +269,12 @@ int addr_in_common(struct sockaddr_storage* addr1, int net1, void addr_to_str(struct sockaddr_storage* addr, socklen_t addrlen, char* buf, size_t len); +/** + * See if sockaddr is an ipv6 mapped ipv4 address, ::ffff:0.0.0.0 + * @param addr: address + * @param addrlen: length of address + * @return true if so + */ +int addr_is_ip4mapped(struct sockaddr_storage* addr, socklen_t addrlen); + #endif /* NET_HELP_H */ diff --git a/util/netevent.c b/util/netevent.c index 6ec949562..7989f9c2f 100644 --- a/util/netevent.c +++ b/util/netevent.c @@ -254,6 +254,12 @@ comm_point_send_udp_msg(struct comm_point *c, ldns_buffer* packet, if(errno == ENETUNREACH && verbosity < VERB_ALGO) return 0; #endif + /* squelch errors where people deploy AAAA ::ffff:bla for + * authority servers, which we try for intranets. */ + if(errno == EINVAL && addr_is_ip4mapped( + (struct sockaddr_storage*)addr, addrlen) && + verbosity < VERB_DETAIL) + return 0; #ifndef USE_WINSOCK verbose(VERB_OPS, "sendto failed: %s", strerror(errno)); #else diff --git a/util/random.c b/util/random.c index c86fdf673..d98b88917 100644 --- a/util/random.c +++ b/util/random.c @@ -81,7 +81,7 @@ struct ub_randstate { /** Number of bytes to reseed after */ #define REKEY_BYTES (1 << 24) -/** (re)setup system seed */ +/* (re)setup system seed */ void ub_systemseed(unsigned int seed) {