xref: /netbsd-src/external/mpl/bind/dist/lib/ns/include/ns/sortlist.h (revision bcda20f65a8566e103791ec395f7f499ef322704)
1 /*	$NetBSD: sortlist.h,v 1.7 2025/01/26 16:25:46 christos Exp $	*/
2 
3 /*
4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5  *
6  * SPDX-License-Identifier: MPL-2.0
7  *
8  * This Source Code Form is subject to the terms of the Mozilla Public
9  * License, v. 2.0. If a copy of the MPL was not distributed with this
10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11  *
12  * See the COPYRIGHT file distributed with this work for additional
13  * information regarding copyright ownership.
14  */
15 
16 #pragma once
17 
18 /*! \file */
19 
20 #include <isc/types.h>
21 
22 #include <dns/acl.h>
23 #include <dns/types.h>
24 
25 /*%
26  * Type for callback functions that rank addresses.
27  */
28 typedef int (*dns_addressorderfunc_t)(const isc_netaddr_t *address,
29 				      const void	  *arg);
30 
31 /*%
32  * Return value type for setup_sortlist.
33  */
34 typedef enum {
35 	NS_SORTLISTTYPE_NONE,
36 	NS_SORTLISTTYPE_1ELEMENT,
37 	NS_SORTLISTTYPE_2ELEMENT
38 } ns_sortlisttype_t;
39 
40 ns_sortlisttype_t
41 ns_sortlist_setup(dns_acl_t *acl, dns_aclenv_t *env, isc_netaddr_t *clientaddr,
42 		  void **argp);
43 /*%<
44  * Find the sortlist statement in 'acl' (for ACL environment 'env')
45  * that applies to 'clientaddr', if any.
46  *
47  * If a 1-element sortlist item applies, return NS_SORTLISTTYPE_1ELEMENT and
48  * make '*argp' point to the matching subelement.
49  *
50  * If a 2-element sortlist item applies, return NS_SORTLISTTYPE_2ELEMENT and
51  * make '*argp' point to ACL that forms the second element.
52  *
53  * If no sortlist item applies, return NS_SORTLISTTYPE_NONE and set '*argp'
54  * to NULL.
55  */
56 
57 int
58 ns_sortlist_addrorder1(const isc_netaddr_t *addr, const void *arg);
59 /*%<
60  * Find the sort order of 'addr' in 'arg', the matching element
61  * of a 1-element top-level sortlist statement.
62  */
63 
64 int
65 ns_sortlist_addrorder2(const isc_netaddr_t *addr, const void *arg);
66 /*%<
67  * Find the sort order of 'addr' in 'arg', a topology-like
68  * ACL forming the second element in a 2-element top-level
69  * sortlist statement.
70  */
71