2
include/proto/port_range.h
3
This file defines everything needed to manage port ranges
5
Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
7
This library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Lesser General Public
9
License as published by the Free Software Foundation, version 2.1
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Lesser General Public License for more details.
17
You should have received a copy of the GNU Lesser General Public
18
License along with this library; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
#ifndef _PROTO_PORT_RANGE_H
23
#define _PROTO_PORT_RANGE_H
25
#include <types/port_range.h>
27
/* return an available port from range <range>, or zero if none is left */
28
static inline int port_range_alloc_port(struct port_range *range)
34
ret = range->ports[range->get];
36
if (range->get >= range->size)
42
/* release port <port> into port range <range>. Does nothing if <port> is zero
43
* nor if <range> is null. The caller is responsible for marking the port
44
* unused by either setting the port to zero or the range to NULL.
46
static inline void port_range_release_port(struct port_range *range, int port)
51
range->ports[range->put] = port;
54
if (range->put >= range->size)
58
/* return a new initialized port range of N ports. The ports are not
59
* filled in, it's up to the caller to do it.
61
static inline struct port_range *port_range_alloc_range(int n)
63
struct port_range *ret;
64
ret = calloc(1, sizeof(struct port_range) +
65
n * sizeof(((struct port_range *)0)->ports[0]));
66
ret->size = ret->avail = n;
70
#endif /* _PROTO_PORT_RANGE_H */