- tested sa with traffic selectors
[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 #include <encoding/payloads/traffic_selector_substructure.h>
28
29
30 typedef struct traffic_selector_t traffic_selector_t;
31
32 /**
33 * @brief Object representing a traffic selector entry.
34 *
35 * A traffic selector defines an range of addresses
36 * and a range of ports.
37 *
38 * @ingroup config
39 */
40 struct traffic_selector_t {
41
42 /**
43 * @brief Compare two traffic selectors, and create a new one
44 * which is the largest subset of bouth (subnet & port).
45 *
46 * Resulting traffic_selector is newly created and must be destroyed.
47 *
48 * @param this first to compare
49 * @param other second to compare
50 * @return
51 * - created subset of them
52 * - or NULL if no match between this and other
53 */
54 traffic_selector_t *(*get_subset) (traffic_selector_t *this, traffic_selector_t *other);
55
56 /**
57 * @brief Clone a traffic selector.
58 *
59 * @param this traffic selector to clone
60 * @return clone of it
61 */
62 traffic_selector_t *(*clone) (traffic_selector_t *this);
63
64 /**
65 * @brief Get starting address of this ts as a chunk.
66 *
67 * Data is in network order and represents the address.
68 * Size depends on protocol.
69 *
70 * Resulting chunk data is allocated and must be freed!
71 *
72 * @param this calling object
73 * @return chunk containing the address
74 */
75 chunk_t (*get_from_address) (traffic_selector_t *this);
76
77 /**
78 * @brief Get ending address of this ts as a chunk.
79 *
80 * Data is in network order and represents the address.
81 * Size depends on protocol.
82 *
83 * Resulting chunk data is allocated and must be freed!
84 *
85 * @param this calling object
86 * @return chunk containing the address
87 */
88 chunk_t (*get_to_address) (traffic_selector_t *this);
89
90 /**
91 * @brief Get starting port of this ts.
92 *
93 * Port is in host order, since the parser converts it.
94 * Size depends on protocol.
95 *
96 * @param this calling object
97 * @return port
98 */
99 u_int16_t (*get_from_port) (traffic_selector_t *this);
100
101 /**
102 * @brief Get ending port of this ts.
103 *
104 * Port is in host order, since the parser converts it.
105 * Size depends on protocol.
106 *
107 * @param this calling object
108 * @return port
109 */
110 u_int16_t (*get_to_port) (traffic_selector_t *this);
111
112 /**
113 * @brief Destroys the ts object
114 *
115 *
116 * @param this calling object
117 */
118 void (*destroy) (traffic_selector_t *this);
119 };
120
121 /**
122 * @brief Create a new traffic selector using human readable params.
123 *
124 * @param protocol protocol for this ts, such as TCP or UDP
125 * @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
126 * @param from_addr start of address range as string
127 * @param from_port port number in host order
128 * @param to_addr end of address range as string
129 * @param to_port port number in host order
130 * @return
131 * - created traffic_selector_t
132 * - NULL if invalid address strings
133 *
134 * @ingroup config
135 */
136 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);
137
138 /**
139 * @brief Create a new traffic selector using data read from the net.
140 *
141 * There exists a mix of network and host order in the params.
142 * But the parser gives us this data in this format, so we
143 * don't have to convert twice.
144 *
145 * @param protocol protocol for this ts, such as TCP or UDP
146 * @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
147 * @param from_addr start of address range, network order
148 * @param from_port port number, host order
149 * @param to_addr end of address range as string, network
150 * @param to_port port number, host order
151 * @return
152 * - created traffic_selector_t
153 * - NULL if invalid address strings
154 *
155 * @ingroup config
156 */
157 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);
158
159 #endif //_TRAFFIC_SELECTOR_H_