summaryrefslogtreecommitdiffstats
path: root/contrib/bind/lib/irs/gen_nw.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1999-11-30 02:43:11 +0000
committerpeter <peter@FreeBSD.org>1999-11-30 02:43:11 +0000
commit4ef23ce6957fc75fc005885496d605fed48213e1 (patch)
tree7828b08c74ef918938b1b853c98f0cb41edac52c /contrib/bind/lib/irs/gen_nw.c
parent67e0f3ce71726dc4058c2f80a813341a59244dbd (diff)
downloadFreeBSD-src-4ef23ce6957fc75fc005885496d605fed48213e1.zip
FreeBSD-src-4ef23ce6957fc75fc005885496d605fed48213e1.tar.gz
Import bind v8.2.2.p5, minus the crypto for the time being. The bind
package does have BXA export approval, but the licensing strings on the dnssafe code are a bit unpleasant. The crypto is easy to restore and bind will run without it - just without full dnssec support. Obtained from: The Internet Software Consortium (www.isc.org)
Diffstat (limited to 'contrib/bind/lib/irs/gen_nw.c')
-rw-r--r--contrib/bind/lib/irs/gen_nw.c110
1 files changed, 97 insertions, 13 deletions
diff --git a/contrib/bind/lib/irs/gen_nw.c b/contrib/bind/lib/irs/gen_nw.c
index 8ae8074..fad436c 100644
--- a/contrib/bind/lib/irs/gen_nw.c
+++ b/contrib/bind/lib/irs/gen_nw.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996 by Internet Software Consortium.
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -16,7 +16,7 @@
*/
#if !defined(LINT) && !defined(CODECENTER)
-static char rcsid[] = "$Id: gen_nw.c,v 1.8 1997/12/04 04:57:50 halley Exp $";
+static const char rcsid[] = "$Id: gen_nw.c,v 1.13 1999/10/13 16:39:29 vixie Exp $";
#endif
/* Imports */
@@ -25,10 +25,15 @@ static char rcsid[] = "$Id: gen_nw.c,v 1.8 1997/12/04 04:57:50 halley Exp $";
#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+
#include <errno.h>
+#include <resolv.h>
#include <stdlib.h>
#include <string.h>
+#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
@@ -41,6 +46,8 @@ static char rcsid[] = "$Id: gen_nw.c,v 1.8 1997/12/04 04:57:50 halley Exp $";
struct pvt {
struct irs_rule * rules;
struct irs_rule * rule;
+ struct __res_state * res;
+ void (*free_res)(void *);
};
/* Forward */
@@ -51,6 +58,12 @@ static struct nwent * nw_byname(struct irs_nw *, const char *, int);
static struct nwent * nw_byaddr(struct irs_nw *, void *, int, int);
static void nw_rewind(struct irs_nw *);
static void nw_minimize(struct irs_nw *);
+static struct __res_state * nw_res_get(struct irs_nw *this);
+static void nw_res_set(struct irs_nw *this,
+ struct __res_state *res,
+ void (*free_res)(void *));
+
+static int init(struct irs_nw *this);
/* Public */
@@ -60,17 +73,17 @@ irs_gen_nw(struct irs_acc *this) {
struct irs_nw *nw;
struct pvt *pvt;
- if (!(nw = (struct irs_nw *)malloc(sizeof *nw))) {
+ if (!(pvt = memget(sizeof *pvt))) {
errno = ENOMEM;
return (NULL);
}
- memset(nw, 0x5e, sizeof *nw);
- if (!(pvt = (struct pvt *)malloc(sizeof *pvt))) {
- free(nw);
+ memset(pvt, 0, sizeof *pvt);
+ if (!(nw = memget(sizeof *nw))) {
+ memput(pvt, sizeof *pvt);
errno = ENOMEM;
return (NULL);
}
- memset(pvt, 0, sizeof *pvt);
+ memset(nw, 0x5e, sizeof *nw);
pvt->rules = accpvt->map_rules[irs_nw];
pvt->rule = pvt->rules;
nw->private = pvt;
@@ -80,6 +93,8 @@ irs_gen_nw(struct irs_acc *this) {
nw->byaddr = nw_byaddr;
nw->rewind = nw_rewind;
nw->minimize = nw_minimize;
+ nw->res_get = nw_res_get;
+ nw->res_set = nw_res_set;
return (nw);
}
@@ -89,8 +104,13 @@ static void
nw_close(struct irs_nw *this) {
struct pvt *pvt = (struct pvt *)this->private;
- free(pvt);
- free(this);
+ nw_minimize(this);
+
+ if (pvt->res && pvt->free_res)
+ (*pvt->free_res)(pvt->res);
+
+ memput(pvt, sizeof *pvt);
+ memput(this, sizeof *this);
}
static struct nwent *
@@ -99,6 +119,9 @@ nw_next(struct irs_nw *this) {
struct nwent *rval;
struct irs_nw *nw;
+ if (init(this) == -1)
+ return(NULL);
+
while (pvt->rule) {
nw = pvt->rule->inst->nw;
rval = (*nw->next)(nw);
@@ -122,13 +145,17 @@ nw_byname(struct irs_nw *this, const char *name, int type) {
struct nwent *rval;
struct irs_nw *nw;
+ if (init(this) == -1)
+ return(NULL);
+
for (rule = pvt->rules; rule; rule = rule->next) {
nw = rule->inst->nw;
- h_errno = NETDB_INTERNAL;
+ RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
rval = (*nw->byname)(nw, name, type);
if (rval != NULL)
return (rval);
- if (h_errno != TRY_AGAIN && !(rule->flags & IRS_CONTINUE))
+ if (pvt->res->res_h_errno != TRY_AGAIN &&
+ !(rule->flags & IRS_CONTINUE))
break;
}
return (NULL);
@@ -141,13 +168,17 @@ nw_byaddr(struct irs_nw *this, void *net, int length, int type) {
struct nwent *rval;
struct irs_nw *nw;
+ if (init(this) == -1)
+ return(NULL);
+
for (rule = pvt->rules; rule; rule = rule->next) {
nw = rule->inst->nw;
- h_errno = NETDB_INTERNAL;
+ RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
rval = (*nw->byaddr)(nw, net, length, type);
if (rval != NULL)
return (rval);
- if (h_errno != TRY_AGAIN && !(rule->flags & IRS_CONTINUE))
+ if (pvt->res->res_h_errno != TRY_AGAIN &&
+ !(rule->flags & IRS_CONTINUE))
break;
}
return (NULL);
@@ -170,9 +201,62 @@ nw_minimize(struct irs_nw *this) {
struct pvt *pvt = (struct pvt *)this->private;
struct irs_rule *rule;
+ if (pvt->res)
+ res_nclose(pvt->res);
for (rule = pvt->rules; rule != NULL; rule = rule->next) {
struct irs_nw *nw = rule->inst->nw;
(*nw->minimize)(nw);
}
}
+
+static struct __res_state *
+nw_res_get(struct irs_nw *this) {
+ struct pvt *pvt = (struct pvt *)this->private;
+
+ if (!pvt->res) {
+ struct __res_state *res;
+ res = (struct __res_state *)malloc(sizeof *res);
+ if (!res) {
+ errno = ENOMEM;
+ return (NULL);
+ }
+ memset(res, 0, sizeof *res);
+ nw_res_set(this, res, free);
+ }
+
+ return (pvt->res);
+}
+
+static void
+nw_res_set(struct irs_nw *this, struct __res_state *res,
+ void (*free_res)(void *)) {
+ struct pvt *pvt = (struct pvt *)this->private;
+ struct irs_rule *rule;
+
+ if (pvt->res && pvt->free_res) {
+ res_nclose(pvt->res);
+ (*pvt->free_res)(pvt->res);
+ }
+
+ pvt->res = res;
+ pvt->free_res = free_res;
+
+ for (rule = pvt->rules; rule != NULL; rule = rule->next) {
+ struct irs_nw *nw = rule->inst->nw;
+
+ (*nw->res_set)(nw, pvt->res, NULL);
+ }
+}
+
+static int
+init(struct irs_nw *this) {
+ struct pvt *pvt = (struct pvt *)this->private;
+
+ if (!pvt->res && !nw_res_get(this))
+ return (-1);
+ if (((pvt->res->options & RES_INIT) == 0) &&
+ res_ninit(pvt->res) == -1)
+ return (-1);
+ return (0);
+}
OpenPOWER on IntegriCloud