43e6974150309d77de4e27ca04278872c68d1636
[strongswan.git] / Source / charon / encoding / payloads / traffic_selector_substructure.h
1 /**
2 * @file traffic_selector_substructure.h
3 *
4 * @brief Interface of traffic_selector_substructure_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
24 #ifndef TRAFFIC_SELECTOR_SUBSTRUCTURE_H_
25 #define TRAFFIC_SELECTOR_SUBSTRUCTURE_H_
26
27 #include <types.h>
28 #include <encoding/payloads/payload.h>
29 #include <network/host.h>
30
31 /**
32 * Length of a TRAFFIC SELECTOR SUBSTRUCTURE without start and end address.
33 *
34 * @ingroup payloads
35 */
36 #define TRAFFIC_SELECTOR_HEADER_LENGTH 8
37
38
39 typedef enum ts_type_t ts_type_t;
40
41 /**
42 * Traffic selector Types.
43 *
44 * @ingroup payloads
45 */
46 enum ts_type_t {
47 /*
48 * A range of IPv4 addresses, represented by two four (4) octet
49 * values. The first value is the beginning IPv4 address
50 * (inclusive) and the second value is the ending IPv4 address
51 * (inclusive). All addresses falling between the two specified
52 * addresses are considered to be within the list.
53 */
54 TS_IPV4_ADDR_RANGE = 7,
55 /*
56 * A range of IPv6 addresses, represented by two sixteen (16)
57 * octet values. The first value is the beginning IPv6 address
58 * (inclusive) and the second value is the ending IPv6 address
59 * (inclusive). All addresses falling between the two specified
60 * addresses are considered to be within the list.
61 */
62 TS_IPV6_ADDR_RANGE = 8
63 };
64
65 extern mapping_t ts_type_m[];
66
67 typedef struct traffic_selector_substructure_t traffic_selector_substructure_t;
68
69 /**
70 * Object representing an IKEv2 TRAFFIC SELECTOR.
71 *
72 * The TRAFFIC SELECTOR format is described in draft section 3.13.1.
73 *
74 * @ingroup payloads
75 *
76 */
77 struct traffic_selector_substructure_t {
78 /**
79 * The payload_t interface.
80 */
81 payload_t payload_interface;
82
83 /**
84 * @brief Get the type of Traffic selector.
85 *
86 * @param this calling traffic_selector_substructure_t object
87 * @return type of traffic selector
88 *
89 */
90 ts_type_t (*get_ts_type) (traffic_selector_substructure_t *this);
91
92 /**
93 * @brief Set the type of Traffic selector.
94 *
95 * @param this calling traffic_selector_substructure_t object
96 * @param ts_type type of traffic selector
97 */
98 void (*set_ts_type) (traffic_selector_substructure_t *this,ts_type_t ts_type);
99
100 /**
101 * @brief Get the IP protocol ID of Traffic selector.
102 *
103 * @param this calling traffic_selector_substructure_t object
104 * @return type of traffic selector
105 *
106 */
107 u_int8_t (*get_protocol_id) (traffic_selector_substructure_t *this);
108
109 /**
110 * @brief Set the IP protocol ID of Traffic selector
111 *
112 * @param this calling traffic_selector_substructure_t object
113 * @param protocol_id protocol ID of traffic selector
114 */
115 void (*set_protocol_id) (traffic_selector_substructure_t *this,u_int8_t protocol_id);
116
117 /**
118 * @brief Get the start port and address as host_t object.
119 *
120 * Returned host_t object has to get destroyed by the caller.
121 *
122 * @param this calling traffic_selector_substructure_t object
123 * @return start host as host_t object
124 *
125 */
126 host_t *(*get_start_host) (traffic_selector_substructure_t *this);
127
128 /**
129 * @brief Set the start port and address as host_t object.
130 *
131 * @param this calling traffic_selector_substructure_t object
132 * @param start_host start host as host_t object
133 */
134 void (*set_start_host) (traffic_selector_substructure_t *this,host_t *start_host);
135
136 /**
137 * @brief Get the end port and address as host_t object.
138 *
139 * Returned host_t object has to get destroyed by the caller.
140 *
141 * @param this calling traffic_selector_substructure_t object
142 * @return end host as host_t object
143 *
144 */
145 host_t *(*get_end_host) (traffic_selector_substructure_t *this);
146
147 /**
148 * @brief Set the end port and address as host_t object.
149 *
150 * @param this calling traffic_selector_substructure_t object
151 * @param end_host end host as host_t object
152 */
153 void (*set_end_host) (traffic_selector_substructure_t *this,host_t *end_host);
154
155 /**
156 * @brief Destroys an traffic_selector_substructure_t object.
157 *
158 * @param this traffic_selector_substructure_t object to destroy
159 */
160 void (*destroy) (traffic_selector_substructure_t *this);
161 };
162
163 /**
164 * @brief Creates an empty traffic_selector_substructure_t object.
165 *
166 * TS type is set to default TS_IPV4_ADDR_RANGE!
167 *
168 * @return created traffic_selector_substructure_t object
169 *
170 * @ingroup payloads
171 */
172 traffic_selector_substructure_t *traffic_selector_substructure_create();
173
174
175 #endif //TRAFFIC_SELECTOR_SUBSTRUCTURE_H_