2 * @file traffic_selector.h
4 * @brief Interface of traffic_selector_t.
9 * Copyright (C) 2007 Tobias Brunner
10 * Copyright (C) 2005-2006 Martin Willi
11 * Copyright (C) 2005 Jan Hutter
12 * Hochschule fuer Technik Rapperswil
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 #ifndef TRAFFIC_SELECTOR_H_
26 #define TRAFFIC_SELECTOR_H_
28 typedef enum ts_type_t ts_type_t
;
29 typedef struct traffic_selector_t traffic_selector_t
;
32 #include <utils/host.h>
35 * Traffic selector types.
42 * A range of IPv4 addresses, represented by two four (4) octet
43 * values. The first value is the beginning IPv4 address
44 * (inclusive) and the second value is the ending IPv4 address
45 * (inclusive). All addresses falling between the two specified
46 * addresses are considered to be within the list.
48 TS_IPV4_ADDR_RANGE
= 7,
51 * A range of IPv6 addresses, represented by two sixteen (16)
52 * octet values. The first value is the beginning IPv6 address
53 * (inclusive) and the second value is the ending IPv6 address
54 * (inclusive). All addresses falling between the two specified
55 * addresses are considered to be within the list.
57 TS_IPV6_ADDR_RANGE
= 8
61 * enum names for ts_type_t
63 extern enum_name_t
*ts_type_name
;
66 * @brief Object representing a traffic selector entry.
68 * A traffic selector defines an range of addresses
69 * and a range of ports. IPv6 is not fully supported yet.
72 * - traffic_selector_create_from_bytes()
73 * - traffic_selector_create_from_string()
75 * @todo Add IPv6 support
79 struct traffic_selector_t
{
82 * @brief Compare two traffic selectors, and create a new one
83 * which is the largest subset of both (subnet & port).
85 * Resulting traffic_selector is newly created and must be destroyed.
87 * @param this first to compare
88 * @param other second to compare
90 * - created subset of them
91 * - or NULL if no match between this and other
93 traffic_selector_t
*(*get_subset
) (traffic_selector_t
*this,
94 traffic_selector_t
*other
);
97 * @brief Clone a traffic selector.
99 * @param this traffic selector to clone
100 * @return clone of it
102 traffic_selector_t
*(*clone
) (traffic_selector_t
*this);
105 * @brief Get starting address of this ts as a chunk.
107 * Chunk is in network order gets allocated.
109 * @param this called object
110 * @return chunk containing the address
112 chunk_t (*get_from_address
) (traffic_selector_t
*this);
115 * @brief Get ending address of this ts as a chunk.
117 * Chunk is in network order gets allocated.
119 * @param this called object
120 * @return chunk containing the address
122 chunk_t (*get_to_address
) (traffic_selector_t
*this);
125 * @brief Get starting port of this ts.
127 * Port is in host order, since the parser converts it.
128 * Size depends on protocol.
130 * @param this called object
133 u_int16_t (*get_from_port
) (traffic_selector_t
*this);
136 * @brief Get ending port of this ts.
138 * Port is in host order, since the parser converts it.
139 * Size depends on protocol.
141 * @param this called object
144 u_int16_t (*get_to_port
) (traffic_selector_t
*this);
147 * @brief Get the type of the traffic selector.
149 * @param this called object
150 * @return ts_type_t specifying the type
152 ts_type_t (*get_type
) (traffic_selector_t
*this);
155 * @brief Get the protocol id of this ts.
157 * @param this called object
158 * @return protocol id
160 u_int8_t (*get_protocol
) (traffic_selector_t
*this);
163 * @brief Check if the traffic selector is for a single host.
165 * Traffic selector may describe the end of *-to-host tunnel. In this
166 * case, the address range is a single address equal to the hosts
168 * If host is NULL, the traffic selector is checked if it is a single host,
169 * but not a specific one.
171 * @param this called object
172 * @param host host_t specifying the address range
174 bool (*is_host
) (traffic_selector_t
*this, host_t
* host
);
177 * @brief Update the address of a traffic selector.
179 * Update the address range of a traffic selector,
180 * if the current address is 0.0.0.0. The new address range
181 * starts from the supplied address and also ends there
182 * (which means it is a one-host-address-range ;-).
184 * @param this called object
185 * @param host host_t specifying the address range
187 void (*update_address_range
) (traffic_selector_t
*this, host_t
* host
);
190 * @brief Compare two traffic selectors for equality.
192 * @param this first to compare
193 * @param other second to compare with first
194 * @return pointer to a string.
196 bool (*equals
) (traffic_selector_t
*this, traffic_selector_t
*other
);
199 * @brief Check if a specific host is included in the address range of this traffic selector.
201 * @param this called object
202 * @param host the host to check
204 bool (*includes
) (traffic_selector_t
*this, host_t
*host
);
207 * @brief Destroys the ts object
209 * @param this called object
211 void (*destroy
) (traffic_selector_t
*this);
215 * @brief Create a new traffic selector using human readable params.
217 * @param protocol protocol for this ts, such as TCP or UDP
218 * @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
219 * @param from_addr start of address range as string
220 * @param from_port port number in host order
221 * @param to_addr end of address range as string
222 * @param to_port port number in host order
224 * - traffic_selector_t object
225 * - NULL if invalid address strings/protocol
229 traffic_selector_t
*traffic_selector_create_from_string(
230 u_int8_t protocol
, ts_type_t type
,
231 char *from_addr
, u_int16_t from_port
,
232 char *to_addr
, u_int16_t to_port
);
235 * @brief Create a new traffic selector using data read from the net.
237 * There exists a mix of network and host order in the params.
238 * But the parser gives us this data in this format, so we
239 * don't have to convert twice.
241 * @param protocol protocol for this ts, such as TCP or UDP
242 * @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
243 * @param from_address start of address range, network order
244 * @param from_port port number, host order
245 * @param to_address end of address range as string, network
246 * @param to_port port number, host order
248 * - traffic_selector_t object
249 * - NULL if invalid address input/protocol
253 traffic_selector_t
*traffic_selector_create_from_bytes(
254 u_int8_t protocol
, ts_type_t type
,
255 chunk_t from_address
, u_int16_t from_port
,
256 chunk_t to_address
, u_int16_t to_port
);
259 * @brief Create a new traffic selector defining a whole subnet.
261 * In most cases, definition of a traffic selector for full subnets
262 * is sufficient. This constructor creates a traffic selector for
263 * all protocols, all ports and the address range specified by the
265 * Additionally, a protocol and a port may be specified. Port ranges
266 * are not supported via this constructor.
268 * @param net subnet to use
269 * @param netbits size of the subnet, as used in e.g. 192.168.0.0/24 notation
271 * - traffic_selector_t object
272 * - NULL if address family of net not supported
276 traffic_selector_t
*traffic_selector_create_from_subnet(
277 host_t
*net
, u_int8_t netbits
,
278 u_int8_t protocol
, u_int16_t port
);
280 #endif /* TRAFFIC_SELECTOR_H_ */
282 /* vim: set ts=4 sw=4 noet: */