2 * @file traffic_selector.h
4 * @brief Interface of traffic_selector_t.
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 #ifndef TRAFFIC_SELECTOR_H_
25 #define TRAFFIC_SELECTOR_H_
28 #include <utils/host.h>
31 * printf() specifier for tRaffic selectors
33 #define TRAFFIC_SELECTOR_PRINTF_SPEC 'R'
35 typedef enum ts_type_t ts_type_t
;
38 * Traffic selector types.
45 * A range of IPv4 addresses, represented by two four (4) octet
46 * values. The first value is the beginning IPv4 address
47 * (inclusive) and the second value is the ending IPv4 address
48 * (inclusive). All addresses falling between the two specified
49 * addresses are considered to be within the list.
51 TS_IPV4_ADDR_RANGE
= 7,
54 * A range of IPv6 addresses, represented by two sixteen (16)
55 * octet values. The first value is the beginning IPv6 address
56 * (inclusive) and the second value is the ending IPv6 address
57 * (inclusive). All addresses falling between the two specified
58 * addresses are considered to be within the list.
60 TS_IPV6_ADDR_RANGE
= 8
64 * enum names for ts_type_t
66 extern enum_name_t
*ts_type_name
;
69 typedef struct traffic_selector_t traffic_selector_t
;
72 * @brief Object representing a traffic selector entry.
74 * A traffic selector defines an range of addresses
75 * and a range of ports. IPv6 is not fully supported yet.
78 * - traffic_selector_create_from_bytes()
79 * - traffic_selector_create_from_string()
81 * @todo Add IPv6 support
85 struct traffic_selector_t
{
88 * @brief Compare two traffic selectors, and create a new one
89 * which is the largest subset of both (subnet & port).
91 * Resulting traffic_selector is newly created and must be destroyed.
93 * @param this first to compare
94 * @param other second to compare
96 * - created subset of them
97 * - or NULL if no match between this and other
99 traffic_selector_t
*(*get_subset
) (traffic_selector_t
*this,
100 traffic_selector_t
*other
);
103 * @brief Clone a traffic selector.
105 * @param this traffic selector to clone
106 * @return clone of it
108 traffic_selector_t
*(*clone
) (traffic_selector_t
*this);
111 * @brief Get starting address of this ts as a chunk.
113 * Chunk is in network order gets allocated.
115 * @param this calling object
116 * @return chunk containing the address
118 chunk_t (*get_from_address
) (traffic_selector_t
*this);
121 * @brief Get ending address of this ts as a chunk.
123 * Chunk is in network order gets allocated.
125 * @param this calling object
126 * @return chunk containing the address
128 chunk_t (*get_to_address
) (traffic_selector_t
*this);
131 * @brief Get starting port of this ts.
133 * Port is in host order, since the parser converts it.
134 * Size depends on protocol.
136 * @param this calling object
139 u_int16_t (*get_from_port
) (traffic_selector_t
*this);
142 * @brief Get ending port of this ts.
144 * Port is in host order, since the parser converts it.
145 * Size depends on protocol.
147 * @param this calling object
150 u_int16_t (*get_to_port
) (traffic_selector_t
*this);
153 * @brief Get the type of the traffic selector.
155 * @param this calling obect
156 * @return ts_type_t specifying the type
158 ts_type_t (*get_type
) (traffic_selector_t
*this);
161 * @brief Get the protocol id of this ts.
163 * @param this calling obect
164 * @return protocol id
166 u_int8_t (*get_protocol
) (traffic_selector_t
*this);
169 * @brief Check if the traffic selector is for a single host.
171 * Traffic selector may describe the end of *-to-host tunnel. In this
172 * case, the address range is a single address equal to the hosts
175 * @param this calling obect
176 * @param host host_t specifying the address range
178 bool (*is_host
) (traffic_selector_t
*this, host_t
* host
);
181 * @brief Update the address of a traffic selector.
183 * Update the address range of a traffic selector,
184 * if the current address is 0.0.0.0. The new address range
185 * starts from the supplied address and also ends there
186 * (which means it is a one-host-address-range ;-).
188 * @param this calling obect
189 * @param host host_t specifying the address range
191 void (*update_address_range
) (traffic_selector_t
*this, host_t
* host
);
194 * @brief Compare two traffic selectors for equality.
196 * @param this first to compare
197 * @param other second to compare with first
198 * @return pointer to a string.
200 bool (*equals
) (traffic_selector_t
*this, traffic_selector_t
*other
);
203 * @brief Destroys the ts object
205 * @param this calling object
207 void (*destroy
) (traffic_selector_t
*this);
211 * @brief Create a new traffic selector using human readable params.
213 * @param protocol protocol for this ts, such as TCP or UDP
214 * @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
215 * @param from_addr start of address range as string
216 * @param from_port port number in host order
217 * @param to_addr end of address range as string
218 * @param to_port port number in host order
220 * - traffic_selector_t object
221 * - NULL if invalid address strings/protocol
225 traffic_selector_t
*traffic_selector_create_from_string(
226 u_int8_t protocol
, ts_type_t type
,
227 char *from_addr
, u_int16_t from_port
,
228 char *to_addr
, u_int16_t to_port
);
231 * @brief Create a new traffic selector using data read from the net.
233 * There exists a mix of network and host order in the params.
234 * But the parser gives us this data in this format, so we
235 * don't have to convert twice.
237 * @param protocol protocol for this ts, such as TCP or UDP
238 * @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
239 * @param from_address start of address range, network order
240 * @param from_port port number, host order
241 * @param to_address end of address range as string, network
242 * @param to_port port number, host order
244 * - traffic_selector_t object
245 * - NULL if invalid address input/protocol
249 traffic_selector_t
*traffic_selector_create_from_bytes(
250 u_int8_t protocol
, ts_type_t type
,
251 chunk_t from_address
, u_int16_t from_port
,
252 chunk_t to_address
, u_int16_t to_port
);
255 * @brief Create a new traffic selector defining a whole subnet.
257 * In most cases, definition of a traffic selector for full subnets
258 * is sufficient. This constructor creates a traffic selector for
259 * all protocols, all ports and the address range specified by the
261 * Additionally, a protocol and a port may be specified. Port ranges
262 * are not supported via this constructor.
264 * @param net subnet to use
265 * @param netbits size of the subnet, as used in e.g. 192.168.0.0/24 notation
267 * - traffic_selector_t object
268 * - NULL if address family of net not supported
272 traffic_selector_t
*traffic_selector_create_from_subnet(
273 host_t
*net
, u_int8_t netbits
,
274 u_int8_t protocol
, u_int16_t port
);
276 #endif /* TRAFFIC_SELECTOR_H_ */