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