Commit 38379c5c authored by Brian Wellington's avatar Brian Wellington
Browse files

lwresd search list stuff. This isn't used by getaddrbyname yet, but

it's used by the uncommitted getrrsetbyname.
parent 389c749a
......@@ -13,7 +13,7 @@
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# $Id: Makefile.in,v 1.55 2000/09/20 19:05:54 gson Exp $
# $Id: Makefile.in,v 1.56 2000/10/24 04:25:13 bwelling Exp $
srcdir = @srcdir@
VPATH = @srcdir@
......@@ -52,7 +52,7 @@ OBJS = client.@O@ interfacemgr.@O@ listenlist.@O@ \
log.@O@ logconf.@O@ main.@O@ notify.@O@ omapi.@O@ \
omapiconf.@O@ query.@O@ server.@O@ update.@O@ xfrout.@O@ \
lwresd.@O@ lwdclient.@O@ lwderror.@O@ lwdgabn.@O@ \
lwdgnba.@O@ lwdnoop.@O@
lwdgnba.@O@ lwdnoop.@O@ lwsearch.@O@
UOBJS = unix/os.@O@
......@@ -60,7 +60,7 @@ SRCS = client.c interfacemgr.c listenlist.c \
log.c logconf.c main.c notify.c omapi.c \
omapiconf.c query.c server.c update.c xfrout.c \
lwresd.c lwdclient.c lwderror.c lwdgabn.c \
lwdgnba.c lwdnoop.c
lwdgnba.c lwdnoop.c lwsearch.c
@BIND9_MAKE_RULES@
......
/*
* Copyright (C) 2000 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
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: lwsearch.h,v 1.1 2000/10/24 04:25:14 bwelling Exp $ */
#ifndef NAMED_LWSEARCH_H
#define NAMED_LWSEARCH_H 1
#include <isc/mutex.h>
#include <isc/result.h>
#include <isc/types.h>
#include <dns/types.h>
#include <named/types.h>
/*
* Lightweight resolver search list types and routines.
*
* An ns_lwsearchlist_t holds a list of search path elements.
*
* An ns_lwsearchctx stores the state of search list during a lookup
* operation.
*/
struct ns_lwsearchlist {
isc_uint32_t magic;
isc_mutex_t lock;
isc_mem_t *mctx;
unsigned int refs;
dns_namelist_t names;
};
struct ns_lwsearchctx {
dns_name_t *relname;
dns_name_t *searchname;
unsigned int ndots;
ns_lwsearchlist_t *list;
isc_boolean_t doneexact;
};
isc_result_t
ns_lwsearchlist_create(isc_mem_t *mctx, ns_lwsearchlist_t **listp);
/*
* Create an empty search list object.
*/
void
ns_lwsearchlist_attach(ns_lwsearchlist_t *source, ns_lwsearchlist_t **target);
/*
* Attach to a search list object.
*/
void
ns_lwsearchlist_detach(ns_lwsearchlist_t **listp);
/*
* Detach from a search list object.
*/
isc_result_t
ns_lwsearchlist_append(ns_lwsearchlist_t *list, dns_name_t *name);
/*
* Append an element to a search list. This creates a copy of the name.
*/
void
ns_lwsearchctx_init(ns_lwsearchctx_t *sctx, ns_lwsearchlist_t *list,
dns_name_t *name, unsigned int ndots);
/*
* Creates a search list context structure.
*/
void
ns_lwsearchctx_first(ns_lwsearchctx_t *sctx);
/*
* Moves the search list context iterator to the first element, which
* is usually the exact name.
*/
isc_result_t
ns_lwsearchctx_next(ns_lwsearchctx_t *sctx);
/*
* Moves the search list context iterator to the next element.
*/
isc_result_t
ns_lwsearchctx_current(ns_lwsearchctx_t *sctx, dns_name_t *absname);
/*
* Obtains the current name to be looked up. This involves either
* concatenating the name with a search path element, making an
* exact name absolute, or doing nothing.
*/
#endif /* NAMED_LWSEARCH_H */
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: types.h,v 1.15 2000/08/01 01:12:17 tale Exp $ */
/* $Id: types.h,v 1.16 2000/10/24 04:25:14 bwelling Exp $ */
#ifndef NAMED_TYPES_H
#define NAMED_TYPES_H 1
......@@ -31,5 +31,7 @@ typedef struct ns_interfacemgr ns_interfacemgr_t;
typedef struct ns_lwresd ns_lwresd_t;
typedef struct ns_lwdclient ns_lwdclient_t;
typedef struct ns_lwdclientmgr ns_lwdclientmgr_t;
typedef struct ns_lwsearchlist ns_lwsearchlist_t;
typedef struct ns_lwsearchctx ns_lwsearchctx_t;
#endif /* NAMED_TYPES_H */
/*
* Copyright (C) 2000 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
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: lwsearch.c,v 1.1 2000/10/24 04:25:14 bwelling Exp $ */
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/mutex.h>
#include <isc/result.h>
#include <isc/types.h>
#include <isc/util.h>
#include <dns/name.h>
#include <dns/types.h>
#include <named/lwsearch.h>
#include <named/types.h>
#define LWSEARCHLIST_MAGIC ISC_MAGIC('L', 'W', 'S', 'L')
#define VALID_LWSEARCHLIST(l) ISC_MAGIC_VALID(l, LWSEARCHLIST_MAGIC)
isc_result_t
ns_lwsearchlist_create(isc_mem_t *mctx, ns_lwsearchlist_t **listp) {
ns_lwsearchlist_t *list;
REQUIRE(mctx != NULL);
REQUIRE(listp != NULL && *listp == NULL);
list = isc_mem_get(mctx, sizeof(ns_lwsearchlist_t));
if (list == NULL)
return (ISC_R_NOMEMORY);
RUNTIME_CHECK(isc_mutex_init(&list->lock) == ISC_R_SUCCESS);
list->mctx = NULL;
isc_mem_attach(mctx, &list->mctx);
list->refs = 1;
ISC_LIST_INIT(list->names);
list->magic = LWSEARCHLIST_MAGIC;
*listp = list;
return (ISC_R_SUCCESS);
}
void
ns_lwsearchlist_attach(ns_lwsearchlist_t *source, ns_lwsearchlist_t **target) {
REQUIRE(VALID_LWSEARCHLIST(source));
REQUIRE(target != NULL && *target == NULL);
LOCK(&source->lock);
INSIST(source->refs > 0);
source->refs++;
INSIST(source->refs != 0);
UNLOCK(&source->lock);
*target = source;
}
void
ns_lwsearchlist_detach(ns_lwsearchlist_t **listp) {
ns_lwsearchlist_t *list;
isc_mem_t *mctx;
REQUIRE(listp != NULL);
list = *listp;
REQUIRE(VALID_LWSEARCHLIST(list));
LOCK(&list->lock);
INSIST(list->refs > 0);
list->refs--;
UNLOCK(&list->lock);
*listp = NULL;
if (list->refs != 0)
return;
mctx = list->mctx;
while (!ISC_LIST_EMPTY(list->names)) {
dns_name_t *name = ISC_LIST_HEAD(list->names);
ISC_LIST_UNLINK(list->names, name, link);
dns_name_free(name, list->mctx);
isc_mem_put(list->mctx, name, sizeof(dns_name_t));
}
list->magic = 0;
isc_mem_put(mctx, list, sizeof(ns_lwsearchlist_t));
isc_mem_detach(&mctx);
}
isc_result_t
ns_lwsearchlist_append(ns_lwsearchlist_t *list, dns_name_t *name) {
dns_name_t *newname;
isc_result_t result;
REQUIRE(VALID_LWSEARCHLIST(list));
REQUIRE(name != NULL);
newname = isc_mem_get(list->mctx, sizeof(dns_name_t));
if (newname == NULL)
return (ISC_R_NOMEMORY);
dns_name_init(newname, NULL);
result = dns_name_dup(name, list->mctx, newname);
if (result != ISC_R_SUCCESS) {
isc_mem_put(list->mctx, newname, sizeof(dns_name_t));
return (result);
}
ISC_LINK_INIT(newname, link);
ISC_LIST_APPEND(list->names, newname, link);
return (ISC_R_SUCCESS);
}
void
ns_lwsearchctx_init(ns_lwsearchctx_t *sctx, ns_lwsearchlist_t *list,
dns_name_t *name, unsigned int ndots)
{
INSIST(sctx != NULL);
sctx->relname = name;
sctx->searchname = NULL;
if (dns_name_isabsolute(name) || dns_name_countlabels(name) > ndots)
sctx->list = NULL;
else
sctx->list = list;
sctx->doneexact = ISC_FALSE;
}
void
ns_lwsearchctx_first(ns_lwsearchctx_t *sctx) {
REQUIRE(sctx != NULL);
UNUSED(sctx);
}
isc_result_t
ns_lwsearchctx_next(ns_lwsearchctx_t *sctx) {
REQUIRE(sctx != NULL);
if (sctx->searchname == NULL) {
if (sctx->doneexact || sctx->list == NULL)
return (ISC_R_NOMORE);
else
sctx->searchname = ISC_LIST_HEAD(sctx->list->names);
} else
sctx->searchname = ISC_LIST_NEXT(sctx->searchname, link);
return (ISC_R_SUCCESS);
}
isc_result_t
ns_lwsearchctx_current(ns_lwsearchctx_t *sctx, dns_name_t *absname) {
dns_name_t *tname;
REQUIRE(sctx != NULL);
if (sctx->searchname != NULL)
tname = sctx->searchname;
else if (dns_name_isabsolute(sctx->relname))
tname = NULL;
else
tname = dns_rootname;
return (dns_name_concatenate(sctx->relname, tname, absname, NULL));
}
......@@ -42,6 +42,7 @@
./bin/named/include/named/logconf.h C 1999,2000
./bin/named/include/named/lwdclient.h C 2000
./bin/named/include/named/lwresd.h C 2000
./bin/named/include/named/lwsearch.h C 2000
./bin/named/include/named/main.h C 1999,2000
./bin/named/include/named/notify.h C 1999,2000
./bin/named/include/named/omapi.h C 2000
......@@ -60,6 +61,7 @@
./bin/named/lwdgnba.c C 2000
./bin/named/lwdnoop.c C 2000
./bin/named/lwresd.c C 2000
./bin/named/lwsearch.c C 2000
./bin/named/main.c C 1999,2000
./bin/named/named.conf.test CONF-C 1999,2000
./bin/named/notify.c C 1999,2000
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment