- dead end implementation
[strongswan.git] / Source / 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) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef _TRAFFIC_SELECTOR_H_
24 #define _TRAFFIC_SELECTOR_H_
25
26 #include <types.h>
27
28 typedef enum ts_type_t ts_type_t;
29
30 /**
31 * Traffic selector types.
32 *
33 * @ingroup config
34 */
35 enum ts_type_t {
36 /*
37 * A range of IPv4 addresses, represented by two four (4) octet
38 * values. The first value is the beginning IPv4 address
39 * (inclusive) and the second value is the ending IPv4 address
40 * (inclusive). All addresses falling between the two specified
41 * addresses are considered to be within the list.
42 */
43 TS_IPV4_ADDR_RANGE = 7,
44 /*
45 * A range of IPv6 addresses, represented by two sixteen (16)
46 * octet values. The first value is the beginning IPv6 address
47 * (inclusive) and the second value is the ending IPv6 address
48 * (inclusive). All addresses falling between the two specified
49 * addresses are considered to be within the list.
50 */
51 TS_IPV6_ADDR_RANGE = 8
52 };
53
54 /**
55 * string mappings for ts_type_t
56 */
57 extern mapping_t ts_type_m[];
58
59
60 typedef struct traffic_selector_t traffic_selector_t;
61
62 /**
63 * @brief Object representing a traffic selector entry.
64 *
65 * A traffic selector defines an range of addresses
66 * and a range of ports.
67 *
68 * @b Constructors:
69 * - traffic_selector_create_from_bytes()
70 * - traffic_selector_create_from_string()
71 *
72 * @ingroup config
73 */
74 struct traffic_selector_t {
75
76 /**
77 * @brief Compare two traffic selectors, and create a new one
78 * which is the largest subset of bouth (subnet & port).
79 *
80 * Resulting traffic_selector is newly created and must be destroyed.
81 *
82 * @param this first to compare
83 * @param other second to compare
84 * @return
85 * - created subset of them
86 * - or NULL if no match between this and other
87 */
88 traffic_selector_t *(*get_subset) (traffic_selector_t *this, traffic_selector_t *other);
89
90 /**
91 * @brief Clone a traffic selector.
92 *
93 * @param this traffic selector to clone
94 * @return clone of it
95 */
96 traffic_selector_t *(*clone) (traffic_selector_t *this);
97
98 /**
99 * @brief Get starting address of this ts as a chunk.
100 *
101 * Data is in network order and represents the address.
102 * Size depends on protocol.
103 *
104 * Resulting chunk data is allocated and must be freed!
105 *
106 * @param this calling object
107 * @return chunk containing the address
108 */
109 chunk_t (*get_from_address) (traffic_selector_t *this);
110
111 /**
112 * @brief Get ending address of this ts as a chunk.
113 *
114 * Data is in network order and represents the address.
115 * Size depends on protocol.
116 *
117 * Resulting chunk data is allocated and must be freed!
118 *
119 * @param this calling 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 calling 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 calling 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 calling obect
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 calling obect
158 * @return protocol id
159 */
160 u_int8_t (*get_protocol) (traffic_selector_t *this);
161
162 /**
163 * @brief Destroys the ts object
164 *
165 * @param this calling object
166 */
167 void (*destroy) (traffic_selector_t *this);
168 };
169
170 /**
171 * @brief Create a new traffic selector using human readable params.
172 *
173 * @param protocol protocol for this ts, such as TCP or UDP
174 * @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
175 * @param from_addr start of address range as string
176 * @param from_port port number in host order
177 * @param to_addr end of address range as string
178 * @param to_port port number in host order
179 * @return
180 * - traffic_selector_t object
181 * - NULL if invalid address strings/protocol
182 *
183 * @ingroup config
184 */
185 traffic_selector_t *traffic_selector_create_from_string(u_int8_t protocol, ts_type_t type, char *from_addr, u_int16_t from_port, char *to_addr, u_int16_t to_port);
186
187 /**
188 * @brief Create a new traffic selector using data read from the net.
189 *
190 * There exists a mix of network and host order in the params.
191 * But the parser gives us this data in this format, so we
192 * don't have to convert twice.
193 *
194 * @param protocol protocol for this ts, such as TCP or UDP
195 * @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
196 * @param from_address start of address range, network order
197 * @param from_port port number, host order
198 * @param to_address end of address range as string, network
199 * @param to_port port number, host order
200 * @return
201 * - traffic_selector_t object
202 * - NULL if invalid address input/protocol
203 *
204 * @ingroup config
205 */
206 traffic_selector_t *traffic_selector_create_from_bytes(u_int8_t protocol, ts_type_t type, chunk_t from_address, int16_t from_port, chunk_t to_address, u_int16_t to_port);
207
208 #endif //_TRAFFIC_SELECTOR_H_