Added encapsulation mode transform attribute to IPComp proposal.
[strongswan.git] / src / libcharon / encoding / payloads / proposal_substructure.h
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Copyright (C) 2005-2006 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup proposal_substructure proposal_substructure
20 * @{ @ingroup payloads
21 */
22
23 #ifndef PROPOSAL_SUBSTRUCTURE_H_
24 #define PROPOSAL_SUBSTRUCTURE_H_
25
26 typedef struct proposal_substructure_t proposal_substructure_t;
27
28 #include <library.h>
29 #include <encoding/payloads/payload.h>
30 #include <encoding/payloads/transform_substructure.h>
31 #include <config/proposal.h>
32 #include <utils/linked_list.h>
33 #include <kernel/kernel_ipsec.h>
34 #include <sa/authenticator.h>
35
36 /**
37 * Class representing an IKEv1/IKEv2 proposal substructure.
38 */
39 struct proposal_substructure_t {
40
41 /**
42 * The payload_t interface.
43 */
44 payload_t payload_interface;
45
46 /**
47 * Sets the proposal number of current proposal.
48 *
49 * @param id proposal number to set
50 */
51 void (*set_proposal_number) (proposal_substructure_t *this,
52 u_int8_t proposal_number);
53 /**
54 * get proposal number of current proposal.
55 *
56 * @return proposal number of current proposal substructure.
57 */
58 u_int8_t (*get_proposal_number) (proposal_substructure_t *this);
59
60 /**
61 * Sets the protocol id of current proposal.
62 *
63 * @param id protocol id to set
64 */
65 void (*set_protocol_id) (proposal_substructure_t *this,
66 u_int8_t protocol_id);
67
68 /**
69 * get protocol id of current proposal.
70 *
71 * @return protocol id of current proposal substructure.
72 */
73 u_int8_t (*get_protocol_id) (proposal_substructure_t *this);
74
75 /**
76 * Sets the next_payload field of this substructure
77 *
78 * If this is the last proposal, next payload field is set to 0,
79 * otherwise to 2
80 *
81 * @param is_last When TRUE, next payload field is set to 0, otherwise to 2
82 */
83 void (*set_is_last_proposal) (proposal_substructure_t *this, bool is_last);
84
85 /**
86 * Returns the currently set SPI of this proposal.
87 *
88 * @return chunk_t pointing to the value
89 */
90 chunk_t (*get_spi) (proposal_substructure_t *this);
91
92 /**
93 * Sets the SPI of the current proposal.
94 *
95 * @warning SPI is getting copied
96 *
97 * @param spi chunk_t pointing to the value to set
98 */
99 void (*set_spi) (proposal_substructure_t *this, chunk_t spi);
100
101 /**
102 * Gets the CPI of the current proposal (IKEv1 only).
103 *
104 * @param cpi the CPI if a supported algorithm is proposed
105 * @return TRUE if a supported algorithm is proposed
106 */
107 bool (*get_cpi) (proposal_substructure_t *this, u_int16_t *cpi);
108
109 /**
110 * Get proposals contained in a propsal_substructure_t.
111 *
112 * @param list list to add created proposals to
113 */
114 void (*get_proposals) (proposal_substructure_t *this, linked_list_t *list);
115
116 /**
117 * Create an enumerator over transform substructures.
118 *
119 * @return enumerator over transform_substructure_t
120 */
121 enumerator_t* (*create_substructure_enumerator)(proposal_substructure_t *this);
122
123 /**
124 * Get the (shortest) lifetime of a proposal (IKEv1 only).
125 *
126 * @return lifetime, in seconds
127 */
128 u_int32_t (*get_lifetime)(proposal_substructure_t *this);
129
130 /**
131 * Get the (shortest) life duration of a proposal (IKEv1 only).
132 *
133 * @return life duration, in bytes
134 */
135 u_int64_t (*get_lifebytes)(proposal_substructure_t *this);
136
137 /**
138 * Get the first authentication method from the proposal (IKEv1 only).
139 *
140 * @return auth method, or AUTH_NONE
141 */
142 auth_method_t (*get_auth_method)(proposal_substructure_t *this);
143
144 /**
145 * Get the (first) encapsulation mode from a proposal (IKEv1 only).
146 *
147 * @param udp set to TRUE if UDP encapsulation used
148 * @return ipsec encapsulation mode
149 */
150 ipsec_mode_t (*get_encap_mode)(proposal_substructure_t *this, bool *udp);
151
152 /**
153 * Destroys an proposal_substructure_t object.
154 */
155 void (*destroy) (proposal_substructure_t *this);
156 };
157
158 /**
159 * Creates an empty proposal_substructure_t object
160 *
161 * @param type PROPOSAL_SUBSTRUCTURE or PROPOSAL_SUBSTRUCTURE_V1
162 * @return proposal_substructure_t object
163 */
164 proposal_substructure_t *proposal_substructure_create(payload_type_t type);
165
166 /**
167 * Creates an IKEv2 proposal_substructure_t from a proposal_t.
168 *
169 * @param proposal proposal to build a substruct out of it
170 * @return proposal_substructure_t PROPOSAL_SUBSTRUCTURE
171 */
172 proposal_substructure_t *proposal_substructure_create_from_proposal_v2(
173 proposal_t *proposal);
174 /**
175 * Creates an IKEv1 proposal_substructure_t from a proposal_t.
176 *
177 * @param proposal proposal to build a substruct out of it
178 * @param lifetime lifetime in seconds
179 * @param lifebytes lifebytes, in bytes
180 * @param auth authentication method to use, or AUTH_NONE
181 * @param mode IPsec encapsulation mode, TRANSPORT or TUNNEL
182 * @param udp TRUE to use UDP encapsulation
183 * @return proposal_substructure_t object PROPOSAL_SUBSTRUCTURE_V1
184 */
185 proposal_substructure_t *proposal_substructure_create_from_proposal_v1(
186 proposal_t *proposal, u_int32_t lifetime, u_int64_t lifebytes,
187 auth_method_t auth, ipsec_mode_t mode, bool udp);
188
189 /**
190 * Creates an IKEv1 proposal_substructure_t from a list of proposal_t.
191 *
192 * @param proposals list of proposal_t to encode in a substructure
193 * @param lifetime lifetime in seconds
194 * @param lifebytes lifebytes, in bytes
195 * @param auth authentication method to use, or AUTH_NONE
196 * @param mode IPsec encapsulation mode, TRANSPORT or TUNNEL
197 * @param udp TRUE to use UDP encapsulation
198 * @return IKEv1 proposal_substructure_t PROPOSAL_SUBSTRUCTURE_V1
199 */
200 proposal_substructure_t *proposal_substructure_create_from_proposals_v1(
201 linked_list_t *proposals, u_int32_t lifetime, u_int64_t lifebytes,
202 auth_method_t auth, ipsec_mode_t mode, bool udp);
203
204 /**
205 * Creates an IKEv1 proposal_substructure_t for IPComp with the given
206 * proposal_number (e.g. of a ESP proposal to bundle them).
207 *
208 * @param lifetime lifetime in seconds
209 * @param lifebytes lifebytes, in bytes
210 * @param cpi the CPI to be used
211 * @param mode IPsec encapsulation mode, TRANSPORT or TUNNEL
212 * @param udp TRUE to use UDP encapsulation
213 * @param proposal_number the proposal number of the proposal to be linked
214 * @return IKEv1 proposal_substructure_t PROPOSAL_SUBSTRUCTURE_V1
215 */
216 proposal_substructure_t *proposal_substructure_create_for_ipcomp_v1(
217 u_int32_t lifetime, u_int64_t lifebytes, u_int16_t cpi,
218 ipsec_mode_t mode, bool udp, u_int8_t proposal_number);
219
220 #endif /** PROPOSAL_SUBSTRUCTURE_H_ @}*/