summaryrefslogtreecommitdiffstats
path: root/contrib/bind/lib/resolv
diff options
context:
space:
mode:
authornectar <nectar@FreeBSD.org>2002-05-13 19:31:58 +0000
committernectar <nectar@FreeBSD.org>2002-05-13 19:31:58 +0000
commite044c1fb924b46fc1bd38b298ebea9ff73ea93a8 (patch)
treead4e7f0a2c657d90248bf0c8bd8fac9e5f66a622 /contrib/bind/lib/resolv
parentebeabb1ba32f14e308ae9aff9a2a7151265259cf (diff)
downloadFreeBSD-src-e044c1fb924b46fc1bd38b298ebea9ff73ea93a8.zip
FreeBSD-src-e044c1fb924b46fc1bd38b298ebea9ff73ea93a8.tar.gz
Import of ISC BIND 8.3.2-T1B.
Diffstat (limited to 'contrib/bind/lib/resolv')
-rw-r--r--contrib/bind/lib/resolv/res_findzonecut.c158
-rw-r--r--contrib/bind/lib/resolv/res_send.c14
-rw-r--r--contrib/bind/lib/resolv/res_update.c50
3 files changed, 142 insertions, 80 deletions
diff --git a/contrib/bind/lib/resolv/res_findzonecut.c b/contrib/bind/lib/resolv/res_findzonecut.c
index 02a28da..a82c3f1 100644
--- a/contrib/bind/lib/resolv/res_findzonecut.c
+++ b/contrib/bind/lib/resolv/res_findzonecut.c
@@ -1,5 +1,5 @@
#if !defined(lint) && !defined(SABER)
-static const char rcsid[] = "$Id: res_findzonecut.c,v 8.15 2001/11/01 05:21:22 marka Exp $";
+static const char rcsid[] = "$Id: res_findzonecut.c,v 8.16 2002/04/12 06:27:46 marka Exp $";
#endif /* not lint */
/*
@@ -34,7 +34,6 @@ static const char rcsid[] = "$Id: res_findzonecut.c,v 8.15 2001/11/01 05:21:22 m
#include <errno.h>
#include <limits.h>
#include <netdb.h>
-#include <resolv.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -44,35 +43,40 @@ static const char rcsid[] = "$Id: res_findzonecut.c,v 8.15 2001/11/01 05:21:22 m
#include "port_after.h"
+#include <resolv.h>
+
/* Data structures. */
typedef struct rr_a {
LINK(struct rr_a) link;
- struct in_addr addr;
+ union res_sockaddr_union addr;
} rr_a;
typedef LIST(rr_a) rrset_a;
typedef struct rr_ns {
LINK(struct rr_ns) link;
const char * name;
+ int have_v4;
+ int have_v6;
rrset_a addrs;
} rr_ns;
typedef LIST(rr_ns) rrset_ns;
/* Forward. */
-static int satisfy(res_state,
- const char *, rrset_ns *, struct in_addr *, int);
-static int add_addrs(res_state, rr_ns *, struct in_addr *, int);
-static int get_soa(res_state, const char *, ns_class,
+static int satisfy(res_state, const char *, rrset_ns *,
+ union res_sockaddr_union *, int);
+static int add_addrs(res_state, rr_ns *,
+ union res_sockaddr_union *, int);
+static int get_soa(res_state, const char *, ns_class, int,
char *, size_t, char *, size_t,
rrset_ns *);
-static int get_ns(res_state, const char *, ns_class, rrset_ns *);
-static int get_glue(res_state, ns_class, rrset_ns *);
+static int get_ns(res_state, const char *, ns_class, int, rrset_ns *);
+static int get_glue(res_state, ns_class, int, rrset_ns *);
static int save_ns(res_state, ns_msg *, ns_sect,
- const char *, ns_class, rrset_ns *);
+ const char *, ns_class, int, rrset_ns *);
static int save_a(res_state, ns_msg *, ns_sect,
- const char *, ns_class, rrset_a *);
+ const char *, ns_class, int, rr_ns *);
static void free_nsrrset(rrset_ns *);
static void free_nsrr(rrset_ns *, rr_ns *);
static rr_ns * find_ns(rrset_ns *, const char *);
@@ -145,7 +149,32 @@ static void res_dprintf(const char *, ...) ISC_FORMAT_PRINTF(1, 2);
int
res_findzonecut(res_state statp, const char *dname, ns_class class, int opts,
- char *zname, size_t zsize, struct in_addr *addrs, int naddrs)
+ char *zname, size_t zsize, struct in_addr *addrs, int naddrs) {
+ int result, i;
+ union res_sockaddr_union *u;
+
+
+ opts |= RES_IPV4ONLY;
+ opts &= ~RES_IPV6ONLY;
+
+ u = calloc(naddrs, sizeof(*u));
+ if (u == NULL)
+ return(-1);
+
+ result = res_findzonecut2(statp, dname, class, opts, zname, zsize,
+ u, naddrs);
+
+ for (i = 0; i < result; i++) {
+ addrs[i] = u[i].sin.sin_addr;
+ }
+ free(u);
+ return (result);
+}
+
+int
+res_findzonecut2(res_state statp, const char *dname, ns_class class, int opts,
+ char *zname, size_t zsize, union res_sockaddr_union *addrs,
+ int naddrs)
{
char mname[NS_MAXDNAME];
u_long save_pfcode;
@@ -161,20 +190,20 @@ res_findzonecut(res_state statp, const char *dname, ns_class class, int opts,
INIT_LIST(nsrrs);
DPRINTF(("get the soa, and see if it has enough glue"));
- if ((n = get_soa(statp, dname, class, zname, zsize,
+ if ((n = get_soa(statp, dname, class, opts, zname, zsize,
mname, sizeof mname, &nsrrs)) < 0 ||
((opts & RES_EXHAUSTIVE) == 0 &&
(n = satisfy(statp, mname, &nsrrs, addrs, naddrs)) > 0))
goto done;
DPRINTF(("get the ns rrset and see if it has enough glue"));
- if ((n = get_ns(statp, zname, class, &nsrrs)) < 0 ||
+ if ((n = get_ns(statp, zname, class, opts, &nsrrs)) < 0 ||
((opts & RES_EXHAUSTIVE) == 0 &&
(n = satisfy(statp, mname, &nsrrs, addrs, naddrs)) > 0))
goto done;
DPRINTF(("get the missing glue and see if it's finally enough"));
- if ((n = get_glue(statp, class, &nsrrs)) >= 0)
+ if ((n = get_glue(statp, class, opts, &nsrrs)) >= 0)
n = satisfy(statp, mname, &nsrrs, addrs, naddrs);
done:
@@ -187,8 +216,8 @@ res_findzonecut(res_state statp, const char *dname, ns_class class, int opts,
/* Private. */
static int
-satisfy(res_state statp,
- const char *mname, rrset_ns *nsrrsp, struct in_addr *addrs, int naddrs)
+satisfy(res_state statp, const char *mname, rrset_ns *nsrrsp,
+ union res_sockaddr_union *addrs, int naddrs)
{
rr_ns *nsrr;
int n, x;
@@ -215,7 +244,9 @@ satisfy(res_state statp,
}
static int
-add_addrs(res_state statp, rr_ns *nsrr, struct in_addr *addrs, int naddrs) {
+add_addrs(res_state statp, rr_ns *nsrr,
+ union res_sockaddr_union *addrs, int naddrs)
+{
rr_a *arr;
int n = 0;
@@ -231,7 +262,7 @@ add_addrs(res_state statp, rr_ns *nsrr, struct in_addr *addrs, int naddrs) {
}
static int
-get_soa(res_state statp, const char *dname, ns_class class,
+get_soa(res_state statp, const char *dname, ns_class class, int opts,
char *zname, size_t zsize, char *mname, size_t msize,
rrset_ns *nsrrsp)
{
@@ -332,7 +363,7 @@ get_soa(res_state statp, const char *dname, ns_class class,
return (-1);
}
if (save_ns(statp, &msg, ns_s_ns,
- zname, class, nsrrsp) < 0) {
+ zname, class, opts, nsrrsp) < 0) {
DPRINTF(("get_soa: save_ns failed"));
return (-1);
}
@@ -359,7 +390,9 @@ get_soa(res_state statp, const char *dname, ns_class class,
}
static int
-get_ns(res_state statp, const char *zname, ns_class class, rrset_ns *nsrrsp) {
+get_ns(res_state statp, const char *zname, ns_class class, int opts,
+ rrset_ns *nsrrsp)
+{
u_char resp[NS_PACKETSZ];
ns_msg msg;
int n;
@@ -373,7 +406,7 @@ get_ns(res_state statp, const char *zname, ns_class class, rrset_ns *nsrrsp) {
}
/* Remember the NS RRs and associated A RRs that came back. */
- if (save_ns(statp, &msg, ns_s_an, zname, class, nsrrsp) < 0) {
+ if (save_ns(statp, &msg, ns_s_an, zname, class, opts, nsrrsp) < 0) {
DPRINTF(("get_ns save_ns('%s', %s) failed",
zname, p_class(class)));
return (-1);
@@ -383,7 +416,7 @@ get_ns(res_state statp, const char *zname, ns_class class, rrset_ns *nsrrsp) {
}
static int
-get_glue(res_state statp, ns_class class, rrset_ns *nsrrsp) {
+get_glue(res_state statp, ns_class class, int opts, rrset_ns *nsrrsp) {
rr_ns *nsrr, *nsrr_n;
/* Go and get the A RRs for each empty NS RR on our list. */
@@ -394,7 +427,7 @@ get_glue(res_state statp, ns_class class, rrset_ns *nsrrsp) {
nsrr_n = NEXT(nsrr, link);
- if (EMPTY(nsrr->addrs)) {
+ if (!nsrr->have_v4) {
n = do_query(statp, nsrr->name, class, ns_t_a,
resp, &msg);
if (n < 0) {
@@ -408,25 +441,47 @@ get_glue(res_state statp, ns_class class, rrset_ns *nsrrsp) {
nsrr->name, p_class(class)));
}
if (save_a(statp, &msg, ns_s_an, nsrr->name, class,
- &nsrr->addrs) < 0) {
+ opts, nsrr) < 0) {
DPRINTF(("get_glue: save_r('%s', %s) failed",
nsrr->name, p_class(class)));
return (-1);
}
- /* If it's still empty, it's just chaff. */
- if (EMPTY(nsrr->addrs)) {
- DPRINTF(("get_glue: removing empty '%s' NS",
- nsrr->name));
- free_nsrr(nsrrsp, nsrr);
+ }
+
+ if (!nsrr->have_v6) {
+ n = do_query(statp, nsrr->name, class, ns_t_aaaa,
+ resp, &msg);
+ if (n < 0) {
+ DPRINTF(("get_glue: do_query('%s', %s') failed",
+ nsrr->name, p_class(class)));
+ return (-1);
+ }
+ if (n > 0) {
+ DPRINTF((
+ "get_glue: do_query('%s', %s') CNAME or DNAME found",
+ nsrr->name, p_class(class)));
+ }
+ if (save_a(statp, &msg, ns_s_an, nsrr->name, class,
+ opts, nsrr) < 0) {
+ DPRINTF(("get_glue: save_r('%s', %s) failed",
+ nsrr->name, p_class(class)));
+ return (-1);
}
}
+
+ /* If it's still empty, it's just chaff. */
+ if (EMPTY(nsrr->addrs)) {
+ DPRINTF(("get_glue: removing empty '%s' NS",
+ nsrr->name));
+ free_nsrr(nsrrsp, nsrr);
+ }
}
return (0);
}
static int
save_ns(res_state statp, ns_msg *msg, ns_sect sect,
- const char *owner, ns_class class,
+ const char *owner, ns_class class, int opts,
rrset_ns *nsrrsp)
{
int i;
@@ -471,10 +526,12 @@ save_ns(res_state statp, ns_msg *msg, ns_sect sect,
}
INIT_LINK(nsrr, link);
INIT_LIST(nsrr->addrs);
+ nsrr->have_v4 = 0;
+ nsrr->have_v6 = 0;
APPEND(*nsrrsp, nsrr, link);
}
if (save_a(statp, msg, ns_s_ar,
- nsrr->name, class, &nsrr->addrs) < 0) {
+ nsrr->name, class, opts, nsrr) < 0) {
DPRINTF(("save_ns: save_r('%s', %s) failed",
nsrr->name, p_class(class)));
return (-1);
@@ -485,8 +542,8 @@ save_ns(res_state statp, ns_msg *msg, ns_sect sect,
static int
save_a(res_state statp, ns_msg *msg, ns_sect sect,
- const char *owner, ns_class class,
- rrset_a *arrsp)
+ const char *owner, ns_class class, int opts,
+ rr_ns *nsrr)
{
int i;
@@ -499,19 +556,46 @@ save_a(res_state statp, ns_msg *msg, ns_sect sect,
p_section(sect, ns_o_query), i));
return (-1);
}
- if (ns_rr_type(rr) != ns_t_a ||
+ if ((ns_rr_type(rr) != ns_t_a && ns_rr_type(rr) != ns_t_aaaa) ||
ns_rr_class(rr) != class ||
ns_samename(ns_rr_name(rr), owner) != 1 ||
ns_rr_rdlen(rr) != NS_INADDRSZ)
continue;
+ if ((opts & RES_IPV6ONLY) != 0 && ns_rr_type(rr) != ns_t_aaaa)
+ continue;
+ if ((opts & RES_IPV4ONLY) != 0 && ns_rr_type(rr) != ns_t_a)
+ continue;
arr = malloc(sizeof *arr);
if (arr == NULL) {
DPRINTF(("save_a: malloc failed"));
return (-1);
}
INIT_LINK(arr, link);
- memcpy(&arr->addr, ns_rr_rdata(rr), NS_INADDRSZ);
- APPEND(*arrsp, arr, link);
+ memset(&arr->addr, 0, sizeof(arr->addr));
+ switch (ns_rr_type(rr)) {
+ case ns_t_a:
+ arr->addr.sin.sin_family = AF_INET;
+#ifdef HAVE_SA_LEN
+ arr->addr.sin.sin_len = sizeof(arr->addr.sin);
+#endif
+ memcpy(&arr->addr.sin.sin_addr, ns_rr_rdata(rr),
+ NS_INADDRSZ);
+ arr->addr.sin.sin_port = htons(NAMESERVER_PORT);
+ nsrr->have_v4 = 1;
+ break;
+ case ns_t_aaaa:
+ arr->addr.sin6.sin6_family = AF_INET6;
+#ifdef HAVE_SA_LEN
+ arr->addr.sin6.sin6_len = sizeof(arr->addr.sin6);
+#endif
+ memcpy(&arr->addr.sin6.sin6_addr, ns_rr_rdata(rr), 16);
+ arr->addr.sin.sin_port = htons(NAMESERVER_PORT);
+ nsrr->have_v6 = 1;
+ break;
+ default:
+ abort();
+ }
+ APPEND(nsrr->addrs, arr, link);
}
return (0);
}
diff --git a/contrib/bind/lib/resolv/res_send.c b/contrib/bind/lib/resolv/res_send.c
index 6dfea59..6f0e430 100644
--- a/contrib/bind/lib/resolv/res_send.c
+++ b/contrib/bind/lib/resolv/res_send.c
@@ -70,7 +70,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: res_send.c,v 8.48 2001/07/03 06:27:17 marka Exp $";
+static const char rcsid[] = "$Id: res_send.c,v 8.49 2002/03/29 21:50:51 marka Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -521,17 +521,17 @@ get_salen(sa)
{
#ifdef HAVE_SA_LEN
- /* there are people do not set sa_len. be forgibing to them */
+ /* There are people do not set sa_len. Be forgiving to them. */
if (sa->sa_len)
- return sa->sa_len;
+ return (sa->sa_len);
#endif
if (sa->sa_family == AF_INET)
- return sizeof(struct sockaddr_in);
- else if (sa->sa_family == AF_INET)
- return sizeof(struct sockaddr_in6);
+ return (sizeof(struct sockaddr_in));
+ else if (sa->sa_family == AF_INET6)
+ return (sizeof(struct sockaddr_in6));
else
- return 0; /* unknown, die on connect */
+ return (0); /* unknown, die on connect */
}
/*
diff --git a/contrib/bind/lib/resolv/res_update.c b/contrib/bind/lib/resolv/res_update.c
index 54d3b15..12ee326 100644
--- a/contrib/bind/lib/resolv/res_update.c
+++ b/contrib/bind/lib/resolv/res_update.c
@@ -1,5 +1,5 @@
#if !defined(lint) && !defined(SABER)
-static const char rcsid[] = "$Id: res_update.c,v 1.31 2001/11/01 05:21:23 marka Exp $";
+static const char rcsid[] = "$Id: res_update.c,v 1.34 2002/04/12 06:28:52 marka Exp $";
#endif /* not lint */
/*
@@ -77,8 +77,6 @@ struct zonegrp {
/* Forward. */
-static int nscopy(union res_sockaddr_union *,
- const union res_sockaddr_union *, int);
static void res_dprintf(const char *, ...);
/* Macros. */
@@ -102,29 +100,21 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) {
/* Thread all of the updates onto a list of groups. */
INIT_LIST(zgrps);
+ memset(&tgrp, 0, sizeof (tgrp));
for (rrecp = rrecp_in; rrecp;
rrecp = LINKED(rrecp, r_link) ? NEXT(rrecp, r_link) : NULL) {
- struct in_addr nsaddrs[MAXNS];
- int i;
- /* XXX need to rewrite res_findzonecut */
- for (i = 0; i < MAXNS; i++) {
- nsaddrs[i].s_addr = 0;
- if (tgrp.z_nsaddrs[i].sin.sin_family == AF_INET)
- nsaddrs[i] = tgrp.z_nsaddrs[i].sin.sin_addr;
- }
+ int nscnt;
/* Find the origin for it if there is one. */
tgrp.z_class = rrecp->r_class;
- tgrp.z_nscount =
- res_findzonecut(statp, rrecp->r_dname, tgrp.z_class,
- RES_EXHAUSTIVE,
- tgrp.z_origin,
- sizeof tgrp.z_origin,
- nsaddrs, MAXNS);
- if (tgrp.z_nscount <= 0) {
- DPRINTF(("res_findzonecut failed (%d)",
- tgrp.z_nscount));
+ nscnt = res_findzonecut2(statp, rrecp->r_dname, tgrp.z_class,
+ RES_EXHAUSTIVE, tgrp.z_origin,
+ sizeof tgrp.z_origin,
+ tgrp.z_nsaddrs, MAXNS);
+ if (nscnt <= 0) {
+ DPRINTF(("res_findzonecut failed (%d)", nscnt));
goto done;
}
+ tgrp.z_nscount = nscnt;
/* Find the group for it if there is one. */
for (zptr = HEAD(zgrps); zptr != NULL; zptr = NEXT(zptr, z_link))
if (ns_samename(tgrp.z_origin, zptr->z_origin) == 1 &&
@@ -166,9 +156,8 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) {
goto done;
/* Temporarily replace the resolver's nameserver set. */
- nscount = nscopy(nsaddrs, statp->_u._ext.ext->nsaddrs, statp->nscount);
- statp->nscount = nscopy(statp->_u._ext.ext->nsaddrs,
- zptr->z_nsaddrs, zptr->z_nscount);
+ nscount = res_getservers(statp, nsaddrs, MAXNS);
+ res_setservers(statp, zptr->z_nsaddrs, zptr->z_nscount);
/* Send the update and remember the result. */
if (key != NULL)
@@ -185,7 +174,7 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) {
nzones++;
/* Restore resolver's nameserver set. */
- statp->nscount = nscopy(statp->_u._ext.ext->nsaddrs, nsaddrs, nscount);
+ res_setservers(statp, nsaddrs, nscount);
nscount = 0;
}
done:
@@ -197,24 +186,13 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) {
free(zptr);
}
if (nscount != 0)
- statp->nscount = nscopy(statp->_u._ext.ext->nsaddrs, nsaddrs, nscount);
+ res_setservers(statp, nsaddrs, nscount);
return (nzones);
}
/* Private. */
-static int
-nscopy(union res_sockaddr_union *dst, const union res_sockaddr_union *src,
- int n)
-{
- int i;
-
- for (i = 0; i < n; i++)
- dst[i] = src[i];
- return (n);
-}
-
static void
res_dprintf(const char *fmt, ...) {
va_list ap;
OpenPOWER on IntegriCloud