Commit 221fd7bd authored by Andreas Gustafsson's avatar Andreas Gustafsson
Browse files

refactored sortlist code to make it possible to sort addresses

that are not part of an rdata, as required by lwresd
parent 51b951ab
......@@ -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.57 2000/11/02 01:53:22 bwelling Exp $
# $Id: Makefile.in,v 1.58 2000/11/14 03:22:52 gson Exp $
srcdir = @srcdir@
VPATH = @srcdir@
......@@ -50,7 +50,8 @@ TARGETS = named lwresd
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@ \
omapiconf.@O@ query.@O@ server.@O@ sortlist.@O@ \
update.@O@ xfrout.@O@ \
lwresd.@O@ lwdclient.@O@ lwderror.@O@ lwdgabn.@O@ \
lwdgnba.@O@ lwdgrbn.@O@ lwdnoop.@O@ lwsearch.@O@
......@@ -58,7 +59,8 @@ UOBJS = unix/os.@O@
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 \
omapiconf.c query.c server.c sortlist.c \
update.c xfrout.c \
lwresd.c lwdclient.c lwderror.c lwdgabn.c \
lwdgnba.c lwdgrbn.c lwdnoop.c lwsearch.c
......
/*
* 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: sortlist.h,v 1.1 2000/11/14 03:22:53 gson Exp $ */
#ifndef NAMED_SORTLIST_H
#define NAMED_SORTLIST_H 1
#include <isc/types.h>
#include <dns/types.h>
/*
* Type for callback functions that rank addresses.
*/
typedef int
(*dns_addressorderfunc_t)(isc_netaddr_t *address, void *arg);
/*
* Return value type for setup_sortlist.
*/
typedef enum {
NS_SORTLISTTYPE_NONE,
NS_SORTLISTTYPE_1ELEMENT,
NS_SORTLISTTYPE_2ELEMENT
} ns_sortlisttype_t;
ns_sortlisttype_t
setup_sortlist(dns_acl_t *acl, isc_netaddr_t *clientaddr, void **argp);
/*
* Find the sortlist statement in 'acl' that applies to 'clientaddr', if any.
*
* If a 1-element sortlist item applies, return NS_SORTLISTTYPE_1ELEMENT and
* make '*argp' point to the matching subelement.
*
* If a 2-element sortlist item applies, return NS_SORTLISTTYPE_2ELEMENT and
* make '*argp' point to ACL that forms the second element.
*
* If no sortlist item applies, return NS_SORTLISTTYPE_NONE and set '*argp'
* to NULL.
*/
int
ns_sortlist_addrorder1(isc_netaddr_t *addr, void *arg);
/*
* Find the sort order of 'addr' in 'arg', the matching element
* of a 1-element top-level sortlist statement.
*/
int
ns_sortlist_addrorder2(isc_netaddr_t *addr, void *arg);
/*
* Find the sort order of 'addr' in 'arg', a topology-like
* ACL forming the second element in a 2-element top-level
* sortlist statement.
*/
void
ns_sortlist_byaddrsetup(dns_acl_t *sortlist_acl, isc_netaddr_t *client_addr,
dns_addressorderfunc_t *orderp,
void **argp);
/*
* Find the sortlist statement in 'acl' that applies to 'clientaddr', if any,
* and return in '*orderp' a pointer to a function for ranking network addresses
* based on that sortlist statement, and in '*argp' an argument to pass
* to said function.
*/
#endif /* NAMED_SORTLIST_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: sortlist.c,v 1.1 2000/11/14 03:22:53 gson Exp $ */
#include <config.h>
#include <isc/mem.h>
#include <isc/util.h>
#include <dns/acl.h>
#include <dns/result.h>
#include <named/globals.h>
#include <named/server.h>
#include <named/sortlist.h>
ns_sortlisttype_t
setup_sortlist(dns_acl_t *acl, isc_netaddr_t *clientaddr, void **argp) {
unsigned int i;
if (acl == NULL)
goto dont_sort;
for (i = 0; i < acl->length; i++) {
/*
* 'e' refers to the current 'top level statement'
* in the sortlist (see ARM).
*/
dns_aclelement_t *e = &acl->elements[i];
dns_aclelement_t *matchelt = NULL;
dns_acl_t *inner;
if (e->type != dns_aclelementtype_nestedacl)
goto dont_sort;
inner = e->u.nestedacl;
if (inner->length < 1 || inner->length > 2)
goto dont_sort;
if (inner->elements[0].negative)
goto dont_sort;
if (dns_aclelement_match(clientaddr, NULL,
&inner->elements[0],
&ns_g_server->aclenv,
&matchelt)) {
if (inner->length == 2) {
dns_aclelement_t *elt1 = &inner->elements[1];
if (elt1->type != dns_aclelementtype_nestedacl)
goto dont_sort;
*argp = elt1->u.nestedacl;
return (NS_SORTLISTTYPE_2ELEMENT);
} else {
INSIST(matchelt != NULL);
*argp = matchelt;
return (NS_SORTLISTTYPE_1ELEMENT);
}
}
}
/* No match; don't sort. */
dont_sort:
*argp = NULL;
return (NS_SORTLISTTYPE_NONE);
}
int
ns_sortlist_addrorder2(isc_netaddr_t *addr, void *arg) {
dns_acl_t *sortacl = (dns_acl_t *) arg;
int match;
(void)dns_acl_match(addr, NULL, sortacl,
&ns_g_server->aclenv,
&match, NULL);
if (match > 0)
return (match);
else if (match < 0)
return (INT_MAX - (-match));
else
return (INT_MAX / 2);
}
int
ns_sortlist_addrorder1(isc_netaddr_t *addr, void *arg) {
dns_aclelement_t *matchelt = (dns_aclelement_t *) arg;
if (dns_aclelement_match(addr, NULL, matchelt,
&ns_g_server->aclenv,
NULL)) {
return (0);
} else {
return (INT_MAX);
}
}
void
ns_sortlist_byaddrsetup(dns_acl_t *sortlist_acl, isc_netaddr_t *client_addr,
dns_addressorderfunc_t *orderp,
void **argp)
{
dns_addressorderfunc_t order;
switch (setup_sortlist(sortlist_acl, client_addr, argp)) {
case NS_SORTLISTTYPE_1ELEMENT:
order = ns_sortlist_addrorder1;
break;
case NS_SORTLISTTYPE_2ELEMENT:
order = ns_sortlist_addrorder2;
break;
case NS_SORTLISTTYPE_NONE:
order = NULL;
break;
}
*orderp = order;
}
......@@ -48,6 +48,7 @@
./bin/named/include/named/omapi.h C 2000
./bin/named/include/named/query.h C 1999,2000
./bin/named/include/named/server.h C 1999,2000
./bin/named/include/named/sortlist.h C 2000
./bin/named/include/named/types.h C 1999,2000
./bin/named/include/named/update.h C 1999,2000
./bin/named/include/named/xfrout.h C 1999,2000
......@@ -69,6 +70,7 @@
./bin/named/omapiconf.c C 2000
./bin/named/query.c C 1999,2000
./bin/named/server.c C 1999,2000
./bin/named/sortlist.c C 2000
./bin/named/unix/.cvsignore X 1999,2000
./bin/named/unix/Makefile.in MAKE 1999,2000
./bin/named/unix/include/named/os.h 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