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_
27 typedef enum ts_type_t ts_type_t
;
28 typedef struct traffic_selector_t traffic_selector_t
;
31 #include <utils/host.h>
34 * Traffic selector types.
41 * A range of IPv4 addresses, represented by two four (4) octet
42 * values. The first value is the beginning IPv4 address
43 * (inclusive) and the second value is the ending IPv4 address
44 * (inclusive). All addresses falling between the two specified
45 * addresses are considered to be within the list.
47 TS_IPV4_ADDR_RANGE
= 7,
50 * A range of IPv6 addresses, represented by two sixteen (16)
51 * octet values. The first value is the beginning IPv6 address
52 * (inclusive) and the second value is the ending IPv6 address
53 * (inclusive). All addresses falling between the two specified
54 * addresses are considered to be within the list.
56 TS_IPV6_ADDR_RANGE
= 8
60 * enum names for ts_type_t
62 extern enum_name_t
*ts_type_name
;
65 * @brief Object representing a traffic selector entry.
67 * A traffic selector defines an range of addresses
68 * and a range of ports. IPv6 is not fully supported yet.
71 * - traffic_selector_create_from_bytes()
72 * - traffic_selector_create_from_string()
74 * @todo Add IPv6 support
78 struct traffic_selector_t
{
81 * @brief Compare two traffic selectors, and create a new one
82 * which is the largest subset of both (subnet & port).
84 * Resulting traffic_selector is newly created and must be destroyed.
86 * @param this first to compare
87 * @param other second to compare
89 * - created subset of them
90 * - or NULL if no match between this and other
92 traffic_selector_t
*(*get_subset
) (traffic_selector_t
*this,
93 traffic_selector_t
*other
);
96 * @brief Clone a traffic selector.
98 * @param this traffic selector to clone
101 traffic_selector_t
*(*clone
) (traffic_selector_t
*this);
104 * @brief Get starting address of this ts as a chunk.
106 * Chunk is in network order gets allocated.
108 * @param this calling object
109 * @return chunk containing the address
111 chunk_t (*get_from_address
) (traffic_selector_t
*this);
114 * @brief Get ending address of this ts as a chunk.
116 * Chunk is in network order gets allocated.
118 * @param this calling object
119 * @return chunk containing the address
121 chunk_t (*get_to_address
) (traffic_selector_t
*this);
124 * @brief Get starting port of this ts.
126 * Port is in host order, since the parser converts it.
127 * Size depends on protocol.
129 * @param this calling object
132 u_int16_t (*get_from_port
) (traffic_selector_t
*this);
135 * @brief Get ending port of this ts.
137 * Port is in host order, since the parser converts it.
138 * Size depends on protocol.
140 * @param this calling object
143 u_int16_t (*get_to_port
) (traffic_selector_t
*this);
146 * @brief Get the type of the traffic selector.
148 * @param this calling obect
149 * @return ts_type_t specifying the type
151 ts_type_t (*get_type
) (traffic_selector_t
*this);
154 * @brief Get the protocol id of this ts.
156 * @param this calling obect
157 * @return protocol id
159 u_int8_t (*get_protocol
) (traffic_selector_t
*this);
162 * @brief Check if the traffic selector is for a single host.
164 * Traffic selector may describe the end of *-to-host tunnel. In this
165 * case, the address range is a single address equal to the hosts
167 * If host is NULL, the traffic selector is checked if it is a single host,
168 * but not a specific one.
170 * @param this calling obect
171 * @param host host_t specifying the address range
173 bool (*is_host
) (traffic_selector_t
*this, host_t
* host
);
176 * @brief Update the address of a traffic selector.
178 * Update the address range of a traffic selector,
179 * if the current address is 0.0.0.0. The new address range
180 * starts from the supplied address and also ends there
181 * (which means it is a one-host-address-range ;-).
183 * @param this calling obect
184 * @param host host_t specifying the address range
186 void (*update_address_range
) (traffic_selector_t
*this, host_t
* host
);
189 * @brief Compare two traffic selectors for equality.
191 * @param this first to compare
192 * @param other second to compare with first
193 * @return pointer to a string.
195 bool (*equals
) (traffic_selector_t
*this, traffic_selector_t
*other
);
198 * @brief Destroys the ts object
200 * @param this calling object
202 void (*destroy
) (traffic_selector_t
*this);
206 * @brief Create a new traffic selector using human readable params.
208 * @param protocol protocol for this ts, such as TCP or UDP
209 * @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
210 * @param from_addr start of address range as string
211 * @param from_port port number in host order
212 * @param to_addr end of address range as string
213 * @param to_port port number in host order
215 * - traffic_selector_t object
216 * - NULL if invalid address strings/protocol
220 traffic_selector_t
*traffic_selector_create_from_string(
221 u_int8_t protocol
, ts_type_t type
,
222 char *from_addr
, u_int16_t from_port
,
223 char *to_addr
, u_int16_t to_port
);
226 * @brief Create a new traffic selector using data read from the net.
228 * There exists a mix of network and host order in the params.
229 * But the parser gives us this data in this format, so we
230 * don't have to convert twice.
232 * @param protocol protocol for this ts, such as TCP or UDP
233 * @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
234 * @param from_address start of address range, network order
235 * @param from_port port number, host order
236 * @param to_address end of address range as string, network
237 * @param to_port port number, host order
239 * - traffic_selector_t object
240 * - NULL if invalid address input/protocol
244 traffic_selector_t
*traffic_selector_create_from_bytes(
245 u_int8_t protocol
, ts_type_t type
,
246 chunk_t from_address
, u_int16_t from_port
,
247 chunk_t to_address
, u_int16_t to_port
);
250 * @brief Create a new traffic selector defining a whole subnet.
252 * In most cases, definition of a traffic selector for full subnets
253 * is sufficient. This constructor creates a traffic selector for
254 * all protocols, all ports and the address range specified by the
256 * Additionally, a protocol and a port may be specified. Port ranges
257 * are not supported via this constructor.
259 * @param net subnet to use
260 * @param netbits size of the subnet, as used in e.g. 192.168.0.0/24 notation
262 * - traffic_selector_t object
263 * - NULL if address family of net not supported
267 traffic_selector_t
*traffic_selector_create_from_subnet(
268 host_t
*net
, u_int8_t netbits
,
269 u_int8_t protocol
, u_int16_t port
);
271 #endif /* TRAFFIC_SELECTOR_H_ */