xref: /netbsd-src/external/mpl/bind/dist/lib/isc/include/isc/portset.h (revision eceb233b9bd0dfebb902ed73b531ae6964fa3f9b)
1 /*	$NetBSD: portset.h,v 1.4 2020/05/24 19:46:26 christos Exp $	*/
2 
3 /*
4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9  *
10  * See the COPYRIGHT file distributed with this work for additional
11  * information regarding copyright ownership.
12  */
13 
14 /*! \file isc/portset.h
15  * \brief Transport Protocol Port Manipulation Module
16  *
17  * This module provides simple utilities to handle a set of transport protocol
18  * (UDP or TCP) port numbers, e.g., for creating an ACL list.  An isc_portset_t
19  * object is an opaque instance of a port set, for which the user can add or
20  * remove a specific port or a range of consecutive ports.  This object is
21  * expected to be used as a temporary work space only, and does not protect
22  * simultaneous access from multiple threads.  Therefore it must not be stored
23  * in a place that can be accessed from multiple threads.
24  */
25 
26 #ifndef ISC_PORTSET_H
27 #define ISC_PORTSET_H 1
28 
29 /***
30  ***	Imports
31  ***/
32 
33 #include <stdbool.h>
34 
35 #include <isc/net.h>
36 
37 /***
38  *** Functions
39  ***/
40 
41 ISC_LANG_BEGINDECLS
42 
43 isc_result_t
44 isc_portset_create(isc_mem_t *mctx, isc_portset_t **portsetp);
45 /*%<
46  * Create a port set and initialize it as an empty set.
47  *
48  * Requires:
49  *\li	'mctx' to be valid.
50  *\li	'portsetp' to be non NULL and '*portsetp' to be NULL;
51  *
52  * Returns:
53  *\li	#ISC_R_SUCCESS
54  *\li	#ISC_R_NOMEMORY
55  */
56 
57 void
58 isc_portset_destroy(isc_mem_t *mctx, isc_portset_t **portsetp);
59 /*%<
60  * Destroy a port set.
61  *
62  * Requires:
63  *\li	'mctx' to be valid and must be the same context given when the port set
64  *       was created.
65  *\li	'*portsetp' to be a valid set.
66  */
67 
68 bool
69 isc_portset_isset(isc_portset_t *portset, in_port_t port);
70 /*%<
71  * Test whether the given port is stored in the portset.
72  *
73  * Requires:
74  *\li	'portset' to be a valid set.
75  *
76  * Returns
77  * \li	#true if the port is found, false otherwise.
78  */
79 
80 unsigned int
81 isc_portset_nports(isc_portset_t *portset);
82 /*%<
83  * Provides the number of ports stored in the given portset.
84  *
85  * Requires:
86  *\li	'portset' to be a valid set.
87  *
88  * Returns
89  * \li	the number of ports stored in portset.
90  */
91 
92 void
93 isc_portset_add(isc_portset_t *portset, in_port_t port);
94 /*%<
95  * Add the given port to the portset.  The port may or may not be stored in
96  * the portset.
97  *
98  * Requires:
99  *\li	'portlist' to be valid.
100  */
101 
102 void
103 isc_portset_remove(isc_portset_t *portset, in_port_t port);
104 /*%<
105  * Remove the given port to the portset.  The port may or may not be stored in
106  * the portset.
107  *
108  * Requires:
109  *\li	'portlist' to be valid.
110  */
111 
112 void
113 isc_portset_addrange(isc_portset_t *portset, in_port_t port_lo,
114 		     in_port_t port_hi);
115 /*%<
116  * Add a subset of [port_lo, port_hi] (inclusive) to the portset.  Ports in the
117  * subset may or may not be stored in portset.
118  *
119  * Requires:
120  *\li	'portlist' to be valid.
121  *\li	port_lo <= port_hi
122  */
123 
124 void
125 isc_portset_removerange(isc_portset_t *portset, in_port_t port_lo,
126 			in_port_t port_hi);
127 /*%<
128  * Subtract a subset of [port_lo, port_hi] (inclusive) from the portset.  Ports
129  * in the subset may or may not be stored in portset.
130  *
131  * Requires:
132  *\li	'portlist' to be valid.
133  *\li	port_lo <= port_hi
134  */
135 
136 ISC_LANG_ENDDECLS
137 
138 #endif /* ISC_PORTSET_H */
139