1 /* $NetBSD: portset.h,v 1.4 2014/12/10 04:38:00 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2008, 2009 Internet Systems Consortium, Inc. ("ISC") 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /* Id: portset.h,v 1.6 2009/06/25 05:28:34 marka Exp */ 20 21 /*! \file isc/portset.h 22 * \brief Transport Protocol Port Manipulation Module 23 * 24 * This module provides simple utilities to handle a set of transport protocol 25 * (UDP or TCP) port numbers, e.g., for creating an ACL list. An isc_portset_t 26 * object is an opaque instance of a port set, for which the user can add or 27 * remove a specific port or a range of consecutive ports. This object is 28 * expected to be used as a temporary work space only, and does not protect 29 * simultaneous access from multiple threads. Therefore it must not be stored 30 * in a place that can be accessed from multiple threads. 31 */ 32 33 #ifndef ISC_PORTSET_H 34 #define ISC_PORTSET_H 1 35 36 /*** 37 *** Imports 38 ***/ 39 40 #include <isc/net.h> 41 42 /*** 43 *** Functions 44 ***/ 45 46 ISC_LANG_BEGINDECLS 47 48 isc_result_t 49 isc_portset_create(isc_mem_t *mctx, isc_portset_t **portsetp); 50 /*%< 51 * Create a port set and initialize it as an empty set. 52 * 53 * Requires: 54 *\li 'mctx' to be valid. 55 *\li 'portsetp' to be non NULL and '*portsetp' to be NULL; 56 * 57 * Returns: 58 *\li #ISC_R_SUCCESS 59 *\li #ISC_R_NOMEMORY 60 */ 61 62 void 63 isc_portset_destroy(isc_mem_t *mctx, isc_portset_t **portsetp); 64 /*%< 65 * Destroy a port set. 66 * 67 * Requires: 68 *\li 'mctx' to be valid and must be the same context given when the port set 69 * was created. 70 *\li '*portsetp' to be a valid set. 71 */ 72 73 isc_boolean_t 74 isc_portset_isset(isc_portset_t *portset, in_port_t port); 75 /*%< 76 * Test whether the given port is stored in the portset. 77 * 78 * Requires: 79 *\li 'portset' to be a valid set. 80 * 81 * Returns 82 * \li #ISC_TRUE if the port is found, ISC_FALSE otherwise. 83 */ 84 85 unsigned int 86 isc_portset_nports(isc_portset_t *portset); 87 /*%< 88 * Provides the number of ports stored in the given portset. 89 * 90 * Requires: 91 *\li 'portset' to be a valid set. 92 * 93 * Returns 94 * \li the number of ports stored in portset. 95 */ 96 97 void 98 isc_portset_add(isc_portset_t *portset, in_port_t port); 99 /*%< 100 * Add the given port to the portset. The port may or may not be stored in 101 * the portset. 102 * 103 * Requires: 104 *\li 'portlist' to be valid. 105 */ 106 107 void 108 isc_portset_remove(isc_portset_t *portset, in_port_t port); 109 /*%< 110 * Remove the given port to the portset. The port may or may not be stored in 111 * the portset. 112 * 113 * Requires: 114 *\li 'portlist' to be valid. 115 */ 116 117 void 118 isc_portset_addrange(isc_portset_t *portset, in_port_t port_lo, 119 in_port_t port_hi); 120 /*%< 121 * Add a subset of [port_lo, port_hi] (inclusive) to the portset. Ports in the 122 * subset may or may not be stored in portset. 123 * 124 * Requires: 125 *\li 'portlist' to be valid. 126 *\li port_lo <= port_hi 127 */ 128 129 void 130 isc_portset_removerange(isc_portset_t *portset, in_port_t port_lo, 131 in_port_t port_hi); 132 /*%< 133 * Subtract a subset of [port_lo, port_hi] (inclusive) from the portset. Ports 134 * in the subset may or may not be stored in portset. 135 * 136 * Requires: 137 *\li 'portlist' to be valid. 138 *\li port_lo <= port_hi 139 */ 140 141 ISC_LANG_ENDDECLS 142 143 #endif /* ISC_PORTSET_H */ 144