1186448Sdougb/* 2193149Sdougb * Copyright (C) 2008, 2009 Internet Systems Consortium, Inc. ("ISC") 3186448Sdougb * 4186448Sdougb * Permission to use, copy, modify, and/or distribute this software for any 5186448Sdougb * purpose with or without fee is hereby granted, provided that the above 6186448Sdougb * copyright notice and this permission notice appear in all copies. 7186448Sdougb * 8186448Sdougb * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 9186448Sdougb * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10186448Sdougb * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 11186448Sdougb * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12186448Sdougb * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13186448Sdougb * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14186448Sdougb * PERFORMANCE OF THIS SOFTWARE. 15186448Sdougb */ 16186448Sdougb 17234010Sdougb/* $Id: portset.h,v 1.6 2009/06/25 05:28:34 marka Exp $ */ 18186448Sdougb 19186448Sdougb/*! \file isc/portset.h 20193149Sdougb * \brief Transport Protocol Port Manipulation Module 21186448Sdougb * 22186448Sdougb * This module provides simple utilities to handle a set of transport protocol 23186448Sdougb * (UDP or TCP) port numbers, e.g., for creating an ACL list. An isc_portset_t 24186448Sdougb * object is an opaque instance of a port set, for which the user can add or 25186448Sdougb * remove a specific port or a range of consecutive ports. This object is 26186448Sdougb * expected to be used as a temporary work space only, and does not protect 27186448Sdougb * simultaneous access from multiple threads. Therefore it must not be stored 28186448Sdougb * in a place that can be accessed from multiple threads. 29186448Sdougb */ 30186448Sdougb 31186448Sdougb#ifndef ISC_PORTSET_H 32186448Sdougb#define ISC_PORTSET_H 1 33186448Sdougb 34186448Sdougb/*** 35186448Sdougb *** Imports 36186448Sdougb ***/ 37186448Sdougb 38186448Sdougb#include <isc/net.h> 39186448Sdougb 40186448Sdougb/*** 41186448Sdougb *** Functions 42186448Sdougb ***/ 43186448Sdougb 44186448SdougbISC_LANG_BEGINDECLS 45186448Sdougb 46186448Sdougbisc_result_t 47186448Sdougbisc_portset_create(isc_mem_t *mctx, isc_portset_t **portsetp); 48186448Sdougb/*%< 49186448Sdougb * Create a port set and initialize it as an empty set. 50186448Sdougb * 51186448Sdougb * Requires: 52186448Sdougb *\li 'mctx' to be valid. 53186448Sdougb *\li 'portsetp' to be non NULL and '*portsetp' to be NULL; 54186448Sdougb * 55186448Sdougb * Returns: 56186448Sdougb *\li #ISC_R_SUCCESS 57186448Sdougb *\li #ISC_R_NOMEMORY 58186448Sdougb */ 59186448Sdougb 60186448Sdougbvoid 61186448Sdougbisc_portset_destroy(isc_mem_t *mctx, isc_portset_t **portsetp); 62186448Sdougb/*%< 63186448Sdougb * Destroy a port set. 64186448Sdougb * 65186448Sdougb * Requires: 66186448Sdougb *\li 'mctx' to be valid and must be the same context given when the port set 67186448Sdougb * was created. 68186448Sdougb *\li '*portsetp' to be a valid set. 69186448Sdougb */ 70186448Sdougb 71186448Sdougbisc_boolean_t 72186448Sdougbisc_portset_isset(isc_portset_t *portset, in_port_t port); 73186448Sdougb/*%< 74186448Sdougb * Test whether the given port is stored in the portset. 75186448Sdougb * 76186448Sdougb * Requires: 77186448Sdougb *\li 'portset' to be a valid set. 78186448Sdougb * 79186448Sdougb * Returns 80186448Sdougb * \li #ISC_TRUE if the port is found, ISC_FALSE otherwise. 81186448Sdougb */ 82186448Sdougb 83186448Sdougbunsigned int 84186448Sdougbisc_portset_nports(isc_portset_t *portset); 85186448Sdougb/*%< 86186448Sdougb * Provides the number of ports stored in the given portset. 87186448Sdougb * 88186448Sdougb * Requires: 89186448Sdougb *\li 'portset' to be a valid set. 90186448Sdougb * 91186448Sdougb * Returns 92186448Sdougb * \li the number of ports stored in portset. 93186448Sdougb */ 94186448Sdougb 95186448Sdougbvoid 96186448Sdougbisc_portset_add(isc_portset_t *portset, in_port_t port); 97186448Sdougb/*%< 98186448Sdougb * Add the given port to the portset. The port may or may not be stored in 99186448Sdougb * the portset. 100186448Sdougb * 101186448Sdougb * Requires: 102186448Sdougb *\li 'portlist' to be valid. 103186448Sdougb */ 104186448Sdougb 105186448Sdougbvoid 106186448Sdougbisc_portset_remove(isc_portset_t *portset, in_port_t port); 107186448Sdougb/*%< 108186448Sdougb * Remove the given port to the portset. The port may or may not be stored in 109186448Sdougb * the portset. 110186448Sdougb * 111186448Sdougb * Requires: 112186448Sdougb *\li 'portlist' to be valid. 113186448Sdougb */ 114186448Sdougb 115186448Sdougbvoid 116186448Sdougbisc_portset_addrange(isc_portset_t *portset, in_port_t port_lo, 117186448Sdougb in_port_t port_hi); 118186448Sdougb/*%< 119186448Sdougb * Add a subset of [port_lo, port_hi] (inclusive) to the portset. Ports in the 120186448Sdougb * subset may or may not be stored in portset. 121186448Sdougb * 122186448Sdougb * Requires: 123186448Sdougb *\li 'portlist' to be valid. 124186448Sdougb *\li port_lo <= port_hi 125186448Sdougb */ 126186448Sdougb 127186448Sdougbvoid 128186448Sdougbisc_portset_removerange(isc_portset_t *portset, in_port_t port_lo, 129186448Sdougb in_port_t port_hi); 130186448Sdougb/*%< 131186448Sdougb * Subtract a subset of [port_lo, port_hi] (inclusive) from the portset. Ports 132186448Sdougb * in the subset may or may not be stored in portset. 133186448Sdougb * 134186448Sdougb * Requires: 135186448Sdougb *\li 'portlist' to be valid. 136186448Sdougb *\li port_lo <= port_hi 137186448Sdougb */ 138186448Sdougb 139186448SdougbISC_LANG_ENDDECLS 140186448Sdougb 141204619Sdougb#endif /* ISC_PORTSET_H */ 142