diff options
author | ume <ume@FreeBSD.org> | 2001-06-10 20:25:24 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2001-06-10 20:25:24 +0000 |
commit | 32dc912febbf3960c47a0ebfd387977b2c78656b (patch) | |
tree | 262ae419994b75015819bd1f21a102e4d30832d2 /lib/libc | |
parent | 28fc250493cc9938edeed93280f363eeba7bcd2f (diff) | |
download | FreeBSD-src-32dc912febbf3960c47a0ebfd387977b2c78656b.zip FreeBSD-src-32dc912febbf3960c47a0ebfd387977b2c78656b.tar.gz |
Implement EDNS0 support, as EDNS0 support will be made mandatory for
IPv6 transport-ready resolvers/DNS servers. Need careful configuration
when enable it. (default config is not affected).
See manpage for details.
XXX visible symbol __res_opt() is added, however, it is not supposed to be
called from outside, libc minor is not bumped.
Obtained from: KAME/NetBSD
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/net/getaddrinfo.c | 6 | ||||
-rw-r--r-- | lib/libc/net/res_debug.c | 4 | ||||
-rw-r--r-- | lib/libc/net/res_init.c | 2 | ||||
-rw-r--r-- | lib/libc/net/res_mkquery.c | 37 | ||||
-rw-r--r-- | lib/libc/net/res_query.c | 2 | ||||
-rw-r--r-- | lib/libc/net/resolver.3 | 15 |
6 files changed, 64 insertions, 2 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index c54b252..8ff92c2 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -79,7 +79,6 @@ * - other KAME platforms already nuked FAITH ($GAI), but as FreeBSD * 4.0-RELEASE supplies it, we still have the code here. * - AI_ADDRCONFIG support is supplied - * - EDNS0 support is not available due to resolver differences * - some of FreeBSD style (#define tabify and others) * - classful IPv4 numeric (127.1) is allowed. */ @@ -101,6 +100,9 @@ #include <unistd.h> #include <stdio.h> #include <errno.h> +#ifdef DEBUG +#include <syslog.h> +#endif #include <syslog.h> #include <stdarg.h> @@ -1718,6 +1720,8 @@ res_queryN(name, target) n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, buf, sizeof(buf)); + if (n > 0 && (_res.options & RES_USE_EDNS0) != 0) + n = res_opt(n, buf, sizeof(buf), anslen); if (n <= 0) { #ifdef DEBUG if (_res.options & RES_DEBUG) diff --git a/lib/libc/net/res_debug.c b/lib/libc/net/res_debug.c index 16033f2..b6ed1f5 100644 --- a/lib/libc/net/res_debug.c +++ b/lib/libc/net/res_debug.c @@ -519,6 +519,10 @@ p_option(u_long option) { case RES_DNSRCH: return "dnsrch"; case RES_INSECURE1: return "insecure1"; case RES_INSECURE2: return "insecure2"; + case RES_NOALIASES: return "noaliases"; + case RES_USE_INET6: return "inet6"; + case RES_NOTLDQUERY: return "no-tld-query"; + case RES_USE_EDNS0: return "edns0"; default: sprintf(nbuf, "?0x%lx?", (u_long)option); return (nbuf); } diff --git a/lib/libc/net/res_init.c b/lib/libc/net/res_init.c index 9203b69..035dd05 100644 --- a/lib/libc/net/res_init.c +++ b/lib/libc/net/res_init.c @@ -532,6 +532,8 @@ res_setoptions(options, source) _res.options |= RES_USE_INET6; } else if (!strncmp(cp, "no_tld_query", sizeof("no_tld_query") - 1)) { _res.options |= RES_NOTLDQUERY; + } else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) { + _res.options |= RES_USE_EDNS0; } else { /* XXX - print a warning here? */ } diff --git a/lib/libc/net/res_mkquery.c b/lib/libc/net/res_mkquery.c index 5ac662b..6cbd373 100644 --- a/lib/libc/net/res_mkquery.c +++ b/lib/libc/net/res_mkquery.c @@ -204,3 +204,40 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) */ #undef res_mkquery __weak_reference(__res_mkquery, res_mkquery); + +/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */ +int +res_opt(n0, buf, buflen, anslen) + int n0; + u_char *buf; /* buffer to put query */ + int buflen; /* size of buffer */ + int anslen; /* answer buffer length */ +{ + register HEADER *hp; + register u_char *cp; + + hp = (HEADER *) buf; + cp = buf + n0; + buflen -= n0; + + if (buflen < 1 + RRFIXEDSZ) + return -1; + + *cp++ = 0; /* "." */ + buflen--; + + __putshort(T_OPT, cp); /* TYPE */ + cp += INT16SZ; + __putshort(anslen & 0xffff, cp); /* CLASS = UDP payload size */ + cp += INT16SZ; + *cp++ = NOERROR; /* extended RCODE */ + *cp++ = 0; /* EDNS version */ + __putshort(0, cp); /* MBZ */ + cp += INT16SZ; + __putshort(0, cp); /* RDLEN */ + cp += INT16SZ; + hp->arcount = htons(ntohs(hp->arcount) + 1); + buflen -= RRFIXEDSZ; + + return cp - buf; +} diff --git a/lib/libc/net/res_query.c b/lib/libc/net/res_query.c index 0ee2ad2..8a94a42 100644 --- a/lib/libc/net/res_query.c +++ b/lib/libc/net/res_query.c @@ -129,6 +129,8 @@ res_query(name, class, type, answer, anslen) n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, buf, sizeof(buf)); + if (n > 0 && (_res.options & RES_USE_EDNS0) != 0) + n = res_opt(n, buf, sizeof(buf), anslen); if (n <= 0) { #ifdef DEBUG if (_res.options & RES_DEBUG) diff --git a/lib/libc/net/resolver.3 b/lib/libc/net/resolver.3 index 1fb97f5..e06a5fd 100644 --- a/lib/libc/net/resolver.3 +++ b/lib/libc/net/resolver.3 @@ -119,7 +119,7 @@ are defined in and are as follows. Options are stored as a simple bit mask containing the bitwise ``or'' of the options enabled. -.Bl -tag -width RES_DEFNAMES +.Bl -tag -width RES_USE_INET6 .It Dv RES_INIT True if the initial name server address and default domain name are initialized (i.e., @@ -176,6 +176,19 @@ This option is enabled by default. This option turns off the user level aliasing feature controlled by the .Dq Ev HOSTALIASES environment variable. Network daemons should set this option. +.It Dv RES_USE_INET6 +Enables support for IPv6-only applications. +This causes IPv4 addresses to be returned as an IPv4 mapped address. +For example, 10.1.1.1 will be returned as ::ffff:10.1.1.1. +The option is meaningful with certain kernel configuration only. +.It Dv RES_USE_EDNS0 +Enables support for OPT pseudo-RR for EDNS0 extension. +With the option, resolver code will attach OPT pseudo-RR into DNS queries, +to inform of our receive buffer size. +The option will allow DNS servers to take advantage of non-default receive +buffer size, and to send larger replies. +DNS query packets with EDNS0 extension is not compatible with +non-EDNS0 DNS servers. .El .Pp The |