1135446Strhodes/*
2193149Sdougb * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
3135446Strhodes * Copyright (C) 2000, 2001  Internet Software Consortium.
4135446Strhodes *
5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any
6135446Strhodes * purpose with or without fee is hereby granted, provided that the above
7135446Strhodes * copyright notice and this permission notice appear in all copies.
8135446Strhodes *
9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11135446Strhodes * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15135446Strhodes * PERFORMANCE OF THIS SOFTWARE.
16135446Strhodes */
17135446Strhodes
18234010Sdougb/* $Id: sortlist.h,v 1.11 2007/06/19 23:46:59 tbox Exp $ */
19135446Strhodes
20135446Strhodes#ifndef NAMED_SORTLIST_H
21135446Strhodes#define NAMED_SORTLIST_H 1
22135446Strhodes
23170222Sdougb/*! \file */
24170222Sdougb
25135446Strhodes#include <isc/types.h>
26135446Strhodes
27135446Strhodes#include <dns/types.h>
28135446Strhodes
29170222Sdougb/*%
30135446Strhodes * Type for callback functions that rank addresses.
31135446Strhodes */
32135446Strhodestypedef int
33165071Sdougb(*dns_addressorderfunc_t)(const isc_netaddr_t *address, const void *arg);
34135446Strhodes
35170222Sdougb/*%
36135446Strhodes * Return value type for setup_sortlist.
37135446Strhodes */
38135446Strhodestypedef enum {
39135446Strhodes	NS_SORTLISTTYPE_NONE,
40135446Strhodes	NS_SORTLISTTYPE_1ELEMENT,
41135446Strhodes	NS_SORTLISTTYPE_2ELEMENT
42135446Strhodes} ns_sortlisttype_t;
43135446Strhodes
44135446Strhodesns_sortlisttype_t
45165071Sdougbns_sortlist_setup(dns_acl_t *acl, isc_netaddr_t *clientaddr,
46165071Sdougb		  const void **argp);
47170222Sdougb/*%<
48135446Strhodes * Find the sortlist statement in 'acl' that applies to 'clientaddr', if any.
49135446Strhodes *
50135446Strhodes * If a 1-element sortlist item applies, return NS_SORTLISTTYPE_1ELEMENT and
51135446Strhodes * make '*argp' point to the matching subelement.
52135446Strhodes *
53135446Strhodes * If a 2-element sortlist item applies, return NS_SORTLISTTYPE_2ELEMENT and
54135446Strhodes * make '*argp' point to ACL that forms the second element.
55135446Strhodes *
56135446Strhodes * If no sortlist item applies, return NS_SORTLISTTYPE_NONE and set '*argp'
57135446Strhodes * to NULL.
58135446Strhodes */
59135446Strhodes
60135446Strhodesint
61165071Sdougbns_sortlist_addrorder1(const isc_netaddr_t *addr, const void *arg);
62170222Sdougb/*%<
63135446Strhodes * Find the sort order of 'addr' in 'arg', the matching element
64135446Strhodes * of a 1-element top-level sortlist statement.
65135446Strhodes */
66135446Strhodes
67135446Strhodesint
68165071Sdougbns_sortlist_addrorder2(const isc_netaddr_t *addr, const void *arg);
69170222Sdougb/*%<
70135446Strhodes * Find the sort order of 'addr' in 'arg', a topology-like
71135446Strhodes * ACL forming the second element in a 2-element top-level
72135446Strhodes * sortlist statement.
73135446Strhodes */
74135446Strhodes
75135446Strhodesvoid
76135446Strhodesns_sortlist_byaddrsetup(dns_acl_t *sortlist_acl, isc_netaddr_t *client_addr,
77135446Strhodes			dns_addressorderfunc_t *orderp,
78165071Sdougb			const void **argp);
79170222Sdougb/*%<
80135446Strhodes * Find the sortlist statement in 'acl' that applies to 'clientaddr', if any.
81135446Strhodes * If a sortlist statement applies, return in '*orderp' a pointer to a function
82135446Strhodes * for ranking network addresses based on that sortlist statement, and in
83135446Strhodes * '*argp' an argument to pass to said function.  If no sortlist statement
84135446Strhodes * applies, set '*orderp' and '*argp' to NULL.
85135446Strhodes */
86135446Strhodes
87135446Strhodes#endif /* NAMED_SORTLIST_H */
88