summaryrefslogtreecommitdiff
path: root/lib/libc/net
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2001-06-11 10:06:05 +0000
committerJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2001-06-11 10:06:05 +0000
commit2661edd5e2d7a0106c9507f4de4c44d6fbe5102d (patch)
tree7a116003b29bcf48ddb6f76a18479bd911b44af3 /lib/libc/net
parent9f4fa9f45bad8232fea1393de0e5ddeb8b9d20c0 (diff)
support EDNS0 (RFC2671) buffer size notification on DNS queries.
"options edns0" in /etc/resolv.conf will enable the behavior. no behavior change if you don't have the line. see resolv.conf(5) for more details. EDNS0 is useful for avoiding TCP DNS queries/replies on larger DNS responses. also, draft-ietf-dnsext-message-size-* plans to mandate EDNS0 support for DNS clients that support IPv6 transport.
Diffstat (limited to 'lib/libc/net')
-rw-r--r--lib/libc/net/getaddrinfo.c5
-rw-r--r--lib/libc/net/res_debug.c6
-rw-r--r--lib/libc/net/res_init.c6
-rw-r--r--lib/libc/net/res_mkquery.c41
-rw-r--r--lib/libc/net/res_query.c7
5 files changed, 56 insertions, 9 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c
index 1326473fb74..0a0b112589d 100644
--- a/lib/libc/net/getaddrinfo.c
+++ b/lib/libc/net/getaddrinfo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getaddrinfo.c,v 1.27 2000/08/31 17:41:51 itojun Exp $ */
+/* $OpenBSD: getaddrinfo.c,v 1.28 2001/06/11 10:05:58 itojun Exp $ */
/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */
/*
@@ -1511,6 +1511,7 @@ _yp_getaddrinfo(name, pai)
extern const char *__hostalias __P((const char *));
extern int h_errno;
+extern int res_opt __P((int, u_char *, int, int));
/*
* Formulate a normal query, send, and await answer.
@@ -1562,6 +1563,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 e1894b15086..54be69cef74 100644
--- a/lib/libc/net/res_debug.c
+++ b/lib/libc/net/res_debug.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_debug.c,v 1.10 2000/07/07 20:59:47 deraadt Exp $ */
+/* $OpenBSD: res_debug.c,v 1.11 2001/06/11 10:05:59 itojun Exp $ */
/*
* ++Copyright++ 1985, 1990, 1993
@@ -82,7 +82,7 @@
static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $";
#else
-static char rcsid[] = "$OpenBSD: res_debug.c,v 1.10 2000/07/07 20:59:47 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: res_debug.c,v 1.11 2001/06/11 10:05:59 itojun Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -1028,6 +1028,8 @@ __p_option(option)
case RES_DNSRCH: return "dnsrch";
case RES_INSECURE1: return "insecure1";
case RES_INSECURE2: return "insecure2";
+ case RES_USE_INET6: return "inet6";
+ 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 bba8cfaad16..c44539604a3 100644
--- a/lib/libc/net/res_init.c
+++ b/lib/libc/net/res_init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_init.c,v 1.20 2000/11/10 15:33:04 provos Exp $ */
+/* $OpenBSD: res_init.c,v 1.21 2001/06/11 10:06:00 itojun Exp $ */
/*
* ++Copyright++ 1985, 1989, 1993
@@ -64,7 +64,7 @@
static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $";
#else
-static char rcsid[] = "$OpenBSD: res_init.c,v 1.20 2000/11/10 15:33:04 provos Exp $";
+static char rcsid[] = "$OpenBSD: res_init.c,v 1.21 2001/06/11 10:06:00 itojun Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -608,6 +608,8 @@ res_setoptions(options, source)
#endif
} else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
_res.options |= RES_USE_INET6;
+ } 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 3e7e2ae5d31..61595a6e8c5 100644
--- a/lib/libc/net/res_mkquery.c
+++ b/lib/libc/net/res_mkquery.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_mkquery.c,v 1.8 1997/04/13 22:37:21 provos Exp $ */
+/* $OpenBSD: res_mkquery.c,v 1.9 2001/06/11 10:06:00 itojun Exp $ */
/*
* ++Copyright++ 1985, 1993
@@ -60,7 +60,7 @@
static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "$From: res_mkquery.c,v 8.5 1996/08/27 08:33:28 vixie Exp $";
#else
-static char rcsid[] = "$OpenBSD: res_mkquery.c,v 1.8 1997/04/13 22:37:21 provos Exp $";
+static char rcsid[] = "$OpenBSD: res_mkquery.c,v 1.9 2001/06/11 10:06:00 itojun Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -193,3 +193,40 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
}
return (cp - buf);
}
+
+/* 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 01d1f691cb7..433e80f6482 100644
--- a/lib/libc/net/res_query.c
+++ b/lib/libc/net/res_query.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_query.c,v 1.13 1999/09/27 23:58:26 alex Exp $ */
+/* $OpenBSD: res_query.c,v 1.14 2001/06/11 10:06:01 itojun Exp $ */
/*
* ++Copyright++ 1988, 1993
@@ -60,7 +60,7 @@
static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $";
#else
-static char rcsid[] = "$OpenBSD: res_query.c,v 1.13 1999/09/27 23:58:26 alex Exp $";
+static char rcsid[] = "$OpenBSD: res_query.c,v 1.14 2001/06/11 10:06:01 itojun Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -87,6 +87,7 @@ static char rcsid[] = "$OpenBSD: res_query.c,v 1.13 1999/09/27 23:58:26 alex Exp
const char *hostalias __P((const char *));
int h_errno;
+extern int res_opt __P((int, u_char *, int, int));
/*
* Formulate a normal query, send, and await answer.
@@ -122,6 +123,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)