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