summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoritojun <>2001-06-11 10:06:01 +0000
committeritojun <>2001-06-11 10:06:01 +0000
commit3181f54059d8f111597b6e6ebec0e24f7939ada7 (patch)
treebfe7ada7d6c92fea65c972ec4fb3bcfcdbfc2dc5 /src
parente48fbbe799cf5b7ff38a184af2aa7f3ce90f7f65 (diff)
downloadopenbsd-3181f54059d8f111597b6e6ebec0e24f7939ada7.tar.gz
openbsd-3181f54059d8f111597b6e6ebec0e24f7939ada7.tar.bz2
openbsd-3181f54059d8f111597b6e6ebec0e24f7939ada7.zip
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 'src')
-rw-r--r--src/lib/libc/net/getaddrinfo.c5
-rw-r--r--src/lib/libc/net/res_debug.c6
-rw-r--r--src/lib/libc/net/res_init.c6
-rw-r--r--src/lib/libc/net/res_mkquery.c41
-rw-r--r--src/lib/libc/net/res_query.c7
5 files changed, 56 insertions, 9 deletions
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c
index 1326473fb7..0a0b112589 100644
--- a/src/lib/libc/net/getaddrinfo.c
+++ b/src/lib/libc/net/getaddrinfo.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getaddrinfo.c,v 1.27 2000/08/31 17:41:51 itojun Exp $ */ 1/* $OpenBSD: getaddrinfo.c,v 1.28 2001/06/11 10:05:58 itojun Exp $ */
2/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ 2/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */
3 3
4/* 4/*
@@ -1511,6 +1511,7 @@ _yp_getaddrinfo(name, pai)
1511 1511
1512extern const char *__hostalias __P((const char *)); 1512extern const char *__hostalias __P((const char *));
1513extern int h_errno; 1513extern int h_errno;
1514extern int res_opt __P((int, u_char *, int, int));
1514 1515
1515/* 1516/*
1516 * Formulate a normal query, send, and await answer. 1517 * Formulate a normal query, send, and await answer.
@@ -1562,6 +1563,8 @@ res_queryN(name, target)
1562 1563
1563 n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, 1564 n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL,
1564 buf, sizeof(buf)); 1565 buf, sizeof(buf));
1566 if (n > 0 && (_res.options & RES_USE_EDNS0) != 0)
1567 n = res_opt(n, buf, sizeof(buf), anslen);
1565 if (n <= 0) { 1568 if (n <= 0) {
1566#ifdef DEBUG 1569#ifdef DEBUG
1567 if (_res.options & RES_DEBUG) 1570 if (_res.options & RES_DEBUG)
diff --git a/src/lib/libc/net/res_debug.c b/src/lib/libc/net/res_debug.c
index e1894b1508..54be69cef7 100644
--- a/src/lib/libc/net/res_debug.c
+++ b/src/lib/libc/net/res_debug.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: res_debug.c,v 1.10 2000/07/07 20:59:47 deraadt Exp $ */ 1/* $OpenBSD: res_debug.c,v 1.11 2001/06/11 10:05:59 itojun Exp $ */
2 2
3/* 3/*
4 * ++Copyright++ 1985, 1990, 1993 4 * ++Copyright++ 1985, 1990, 1993
@@ -82,7 +82,7 @@
82static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; 82static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
83static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $"; 83static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $";
84#else 84#else
85static char rcsid[] = "$OpenBSD: res_debug.c,v 1.10 2000/07/07 20:59:47 deraadt Exp $"; 85static char rcsid[] = "$OpenBSD: res_debug.c,v 1.11 2001/06/11 10:05:59 itojun Exp $";
86#endif 86#endif
87#endif /* LIBC_SCCS and not lint */ 87#endif /* LIBC_SCCS and not lint */
88 88
@@ -1028,6 +1028,8 @@ __p_option(option)
1028 case RES_DNSRCH: return "dnsrch"; 1028 case RES_DNSRCH: return "dnsrch";
1029 case RES_INSECURE1: return "insecure1"; 1029 case RES_INSECURE1: return "insecure1";
1030 case RES_INSECURE2: return "insecure2"; 1030 case RES_INSECURE2: return "insecure2";
1031 case RES_USE_INET6: return "inet6";
1032 case RES_USE_EDNS0: return "edns0";
1031 default: sprintf(nbuf, "?0x%lx?", (u_long)option); 1033 default: sprintf(nbuf, "?0x%lx?", (u_long)option);
1032 return (nbuf); 1034 return (nbuf);
1033 } 1035 }
diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c
index bba8cfaad1..c44539604a 100644
--- a/src/lib/libc/net/res_init.c
+++ b/src/lib/libc/net/res_init.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: res_init.c,v 1.20 2000/11/10 15:33:04 provos Exp $ */ 1/* $OpenBSD: res_init.c,v 1.21 2001/06/11 10:06:00 itojun Exp $ */
2 2
3/* 3/*
4 * ++Copyright++ 1985, 1989, 1993 4 * ++Copyright++ 1985, 1989, 1993
@@ -64,7 +64,7 @@
64static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; 64static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
65static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; 65static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $";
66#else 66#else
67static char rcsid[] = "$OpenBSD: res_init.c,v 1.20 2000/11/10 15:33:04 provos Exp $"; 67static char rcsid[] = "$OpenBSD: res_init.c,v 1.21 2001/06/11 10:06:00 itojun Exp $";
68#endif 68#endif
69#endif /* LIBC_SCCS and not lint */ 69#endif /* LIBC_SCCS and not lint */
70 70
@@ -608,6 +608,8 @@ res_setoptions(options, source)
608#endif 608#endif
609 } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) { 609 } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
610 _res.options |= RES_USE_INET6; 610 _res.options |= RES_USE_INET6;
611 } else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) {
612 _res.options |= RES_USE_EDNS0;
611 } else { 613 } else {
612 /* XXX - print a warning here? */ 614 /* XXX - print a warning here? */
613 } 615 }
diff --git a/src/lib/libc/net/res_mkquery.c b/src/lib/libc/net/res_mkquery.c
index 3e7e2ae5d3..61595a6e8c 100644
--- a/src/lib/libc/net/res_mkquery.c
+++ b/src/lib/libc/net/res_mkquery.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: res_mkquery.c,v 1.8 1997/04/13 22:37:21 provos Exp $ */ 1/* $OpenBSD: res_mkquery.c,v 1.9 2001/06/11 10:06:00 itojun Exp $ */
2 2
3/* 3/*
4 * ++Copyright++ 1985, 1993 4 * ++Copyright++ 1985, 1993
@@ -60,7 +60,7 @@
60static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; 60static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
61static char rcsid[] = "$From: res_mkquery.c,v 8.5 1996/08/27 08:33:28 vixie Exp $"; 61static char rcsid[] = "$From: res_mkquery.c,v 8.5 1996/08/27 08:33:28 vixie Exp $";
62#else 62#else
63static char rcsid[] = "$OpenBSD: res_mkquery.c,v 1.8 1997/04/13 22:37:21 provos Exp $"; 63static char rcsid[] = "$OpenBSD: res_mkquery.c,v 1.9 2001/06/11 10:06:00 itojun Exp $";
64#endif 64#endif
65#endif /* LIBC_SCCS and not lint */ 65#endif /* LIBC_SCCS and not lint */
66 66
@@ -193,3 +193,40 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
193 } 193 }
194 return (cp - buf); 194 return (cp - buf);
195} 195}
196
197/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */
198int
199res_opt(n0, buf, buflen, anslen)
200 int n0;
201 u_char *buf; /* buffer to put query */
202 int buflen; /* size of buffer */
203 int anslen; /* answer buffer length */
204{
205 register HEADER *hp;
206 register u_char *cp;
207
208 hp = (HEADER *) buf;
209 cp = buf + n0;
210 buflen -= n0;
211
212 if (buflen < 1 + RRFIXEDSZ)
213 return -1;
214
215 *cp++ = 0; /* "." */
216 buflen--;
217
218 __putshort(T_OPT, cp); /* TYPE */
219 cp += INT16SZ;
220 __putshort(anslen & 0xffff, cp); /* CLASS = UDP payload size */
221 cp += INT16SZ;
222 *cp++ = NOERROR; /* extended RCODE */
223 *cp++ = 0; /* EDNS version */
224 __putshort(0, cp); /* MBZ */
225 cp += INT16SZ;
226 __putshort(0, cp); /* RDLEN */
227 cp += INT16SZ;
228 hp->arcount = htons(ntohs(hp->arcount) + 1);
229 buflen -= RRFIXEDSZ;
230
231 return cp - buf;
232}
diff --git a/src/lib/libc/net/res_query.c b/src/lib/libc/net/res_query.c
index 01d1f691cb..433e80f648 100644
--- a/src/lib/libc/net/res_query.c
+++ b/src/lib/libc/net/res_query.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: res_query.c,v 1.13 1999/09/27 23:58:26 alex Exp $ */ 1/* $OpenBSD: res_query.c,v 1.14 2001/06/11 10:06:01 itojun Exp $ */
2 2
3/* 3/*
4 * ++Copyright++ 1988, 1993 4 * ++Copyright++ 1988, 1993
@@ -60,7 +60,7 @@
60static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; 60static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
61static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $"; 61static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $";
62#else 62#else
63static char rcsid[] = "$OpenBSD: res_query.c,v 1.13 1999/09/27 23:58:26 alex Exp $"; 63static char rcsid[] = "$OpenBSD: res_query.c,v 1.14 2001/06/11 10:06:01 itojun Exp $";
64#endif 64#endif
65#endif /* LIBC_SCCS and not lint */ 65#endif /* LIBC_SCCS and not lint */
66 66
@@ -87,6 +87,7 @@ static char rcsid[] = "$OpenBSD: res_query.c,v 1.13 1999/09/27 23:58:26 alex Exp
87 87
88const char *hostalias __P((const char *)); 88const char *hostalias __P((const char *));
89int h_errno; 89int h_errno;
90extern int res_opt __P((int, u_char *, int, int));
90 91
91/* 92/*
92 * Formulate a normal query, send, and await answer. 93 * Formulate a normal query, send, and await answer.
@@ -122,6 +123,8 @@ res_query(name, class, type, answer, anslen)
122 123
123 n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, 124 n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL,
124 buf, sizeof(buf)); 125 buf, sizeof(buf));
126 if (n > 0 && (_res.options & RES_USE_EDNS0) != 0)
127 n = res_opt(n, buf, sizeof(buf), anslen);
125 if (n <= 0) { 128 if (n <= 0) {
126#ifdef DEBUG 129#ifdef DEBUG
127 if (_res.options & RES_DEBUG) 130 if (_res.options & RES_DEBUG)