fixed CHILD_SA proposal selection when not using DH exchange
[strongswan.git] / src / charon / config / traffic_selector.h
1 /**
2 * @file traffic_selector.h
3 *
4 * @brief Interface of traffic_selector_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2007 Tobias Brunner
10 * Copyright (C) 2005-2006 Martin Willi
11 * Copyright (C) 2005 Jan Hutter
12 * Hochschule fuer Technik Rapperswil
13 *
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>.
18 *
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
22 * for more details.
23 */
24
25 #ifndef TRAFFIC_SELECTOR_H_
26 #define TRAFFIC_SELECTOR_H_
27
28 typedef enum ts_type_t ts_type_t;
29 typedef struct traffic_selector_t traffic_selector_t;
30
31 #include <library.h>
32 #include <utils/host.h>
33
34 /**
35 * Traffic selector types.
36 *
37 * @ingroup config
38 */
39 enum ts_type_t {
40
41 /**
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.
47 */
48 TS_IPV4_ADDR_RANGE = 7,
49
50 /**
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.
56 */
57 TS_IPV6_ADDR_RANGE = 8
58 };
59
60 /**
61 * enum names for ts_type_t
62 */
63 extern enum_name_t *ts_type_name;
64
65 /**
66 * @brief Object representing a traffic selector entry.
67 *
68 * A traffic selector defines an range of addresses
69 * and a range of ports. IPv6 is not fully supported yet.
70 *
71 * @b Constructors:
72 * - traffic_selector_create_from_bytes()
73 * - traffic_selector_create_from_string()
74 *
75 * @todo Add IPv6 support
76 *
77 * @ingroup config
78 */
79 struct traffic_selector_t {
80
81 /**
82 * @brief Compare two traffic selectors, and create a new one
83 * which is the largest subset of both (subnet & port).
84 *
85 * Resulting traffic_selector is newly created and must be destroyed.
86 *
87 * @param this first to compare
88 * @param other second to compare
89 * @return
90 * - created subset of them
91 * - or NULL if no match between this and other
92 */
93 traffic_selector_t *(*get_subset) (traffic_selector_t *this,
94 traffic_selector_t *other);
95
96 /**
97 * @brief Clone a traffic selector.
98 *
99 * @param this traffic selector to clone
100 * @return clone of it
101 */
102 traffic_selector_t *(*clone) (traffic_selector_t *this);
103
104 /**
105 * @brief Get starting address of this ts as a chunk.
106 *
107 * Chunk is in network order gets allocated.
108 *
109 * @param this called object
110 * @return chunk containing the address
111 */
112 chunk_t (*get_from_address) (traffic_selector_t *this);
113
114 /**
115 * @brief Get ending address of this ts as a chunk.
116 *
117 * Chunk is in network order gets allocated.
118 *
119 * @param this called object
120 * @return chunk containing the address
121 */
122 chunk_t (*get_to_address) (traffic_selector_t *this);
123
124 /**
125 * @brief Get starting port of this ts.
126 *
127 * Port is in host order, since the parser converts it.
128 * Size depends on protocol.
129 *
130 * @param this called object
131 * @return port
132 */
133 u_int16_t (*get_from_port) (traffic_selector_t *this);
134
135 /**
136 * @brief Get ending port of this ts.
137 *
138 * Port is in host order, since the parser converts it.
139 * Size depends on protocol.
140 *
141 * @param this called object
142 * @return port
143 */
144 u_int16_t (*get_to_port) (traffic_selector_t *this);
145
146 /**
147 * @brief Get the type of the traffic selector.
148 *
149 * @param this called object
150 * @return ts_type_t specifying the type
151 */
152 ts_type_t (*get_type) (traffic_selector_t *this);
153
154 /**
155 * @brief Get the protocol id of this ts.
156 *
157 * @param this called object
158 * @return protocol id
159 */
160 u_int8_t (*get_protocol) (traffic_selector_t *this);
161
162 /**
163 * @brief Check if the traffic selector is for a single host.
164 *
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
167 * peer address.
168 * If host is NULL, the traffic selector is checked if it is a single host,
169 * but not a specific one.
170 *
171 * @param this called object
172 * @param host host_t specifying the address range
173 */
174 bool (*is_host) (traffic_selector_t *this, host_t* host);
175
176 /**
177 * @brief Update the address of a traffic selector.
178 *
179 * Update the address range of a traffic selector, if it is
180 * constructed with the traffic_selector_create_dynamic().
181 *
182 * @param this called object
183 * @param host host_t specifying the address
184 */
185 void (*set_address) (traffic_selector_t *this, host_t* host);
186
187 /**
188 * @brief Compare two traffic selectors for equality.
189 *
190 * @param this first to compare
191 * @param other second to compare with first
192 * @return pointer to a string.
193 */
194 bool (*equals) (traffic_selector_t *this, traffic_selector_t *other);
195
196 /**
197 * @brief Check if a traffic selector is contained completly in another.
198 *
199 * contains() allows to check if multiple traffic selectors are redundant.
200 *
201 * @param this ts that is contained in another
202 * @param other ts that contains this
203 * @return TRUE if other contains this completly, FALSE otherwise
204 */
205 bool (*is_contained_in) (traffic_selector_t *this, traffic_selector_t *other);
206
207 /**
208 * @brief Check if a specific host is included in the address range of
209 * this traffic selector.
210 *
211 * @param this called object
212 * @param host the host to check
213 */
214 bool (*includes) (traffic_selector_t *this, host_t *host);
215
216 /**
217 * @brief Destroys the ts object
218 *
219 * @param this called object
220 */
221 void (*destroy) (traffic_selector_t *this);
222 };
223
224 /**
225 * @brief Create a new traffic selector using human readable params.
226 *
227 * @param protocol protocol for this ts, such as TCP or UDP
228 * @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
229 * @param from_addr start of address range as string
230 * @param from_port port number in host order
231 * @param to_addr end of address range as string
232 * @param to_port port number in host order
233 * @return
234 * - traffic_selector_t object
235 * - NULL if invalid address strings/protocol
236 *
237 * @ingroup config
238 */
239 traffic_selector_t *traffic_selector_create_from_string(
240 u_int8_t protocol, ts_type_t type,
241 char *from_addr, u_int16_t from_port,
242 char *to_addr, u_int16_t to_port);
243
244 /**
245 * @brief Create a new traffic selector using data read from the net.
246 *
247 * There exists a mix of network and host order in the params.
248 * But the parser gives us this data in this format, so we
249 * don't have to convert twice.
250 *
251 * @param protocol protocol for this ts, such as TCP or UDP
252 * @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
253 * @param from_address start of address range, network order
254 * @param from_port port number, host order
255 * @param to_address end of address range as string, network
256 * @param to_port port number, host order
257 * @return traffic_selector_t object
258 *
259 * @ingroup config
260 */
261 traffic_selector_t *traffic_selector_create_from_bytes(
262 u_int8_t protocol, ts_type_t type,
263 chunk_t from_address, u_int16_t from_port,
264 chunk_t to_address, u_int16_t to_port);
265
266 /**
267 * @brief Create a new traffic selector defining a whole subnet.
268 *
269 * In most cases, definition of a traffic selector for full subnets
270 * is sufficient. This constructor creates a traffic selector for
271 * all protocols, all ports and the address range specified by the
272 * subnet.
273 * Additionally, a protocol and a port may be specified. Port ranges
274 * are not supported via this constructor.
275 *
276 * @param net subnet to use
277 * @param netbits size of the subnet, as used in e.g. 192.168.0.0/24 notation
278 * @return
279 * - traffic_selector_t object
280 * - NULL if address family of net not supported
281 *
282 * @ingroup config
283 */
284 traffic_selector_t *traffic_selector_create_from_subnet(
285 host_t *net, u_int8_t netbits,
286 u_int8_t protocol, u_int16_t port);
287
288 /**
289 * @brief Create a traffic selector for host-to-host cases.
290 *
291 * For host2host or virtual IP setups, the traffic selectors gets
292 * created at runtime using the external/virtual IP. Using this constructor,
293 * a call to set_address() sets this traffic selector to the supplied host.
294 *
295 *
296 * @param protocol upper layer protocl to allow
297 * @param type family type
298 * @param from_port start of allowed port range
299 * @param to_port end of range
300 * @return
301 * - traffic_selector_t object
302 * - NULL if type not supported
303 *
304 * @ingroup config
305 */
306 traffic_selector_t *traffic_selector_create_dynamic(
307 u_int8_t protocol, ts_type_t type,
308 u_int16_t from_port, u_int16_t to_port);
309
310 #endif /* TRAFFIC_SELECTOR_H_ */
311
312 /* vim: set ts=4 sw=4 noet: */