]>
Commit | Line | Data |
---|---|---|
da42afc5 | 1 | /* |
7a75cae8 | 2 | * Copyright (C) 2012 Tobias Brunner |
c71d53ba MW |
3 | * Copyright (C) 2005-2006 Martin Willi |
4 | * Copyright (C) 2005 Jan Hutter | |
da42afc5 JH |
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. | |
552cc11b MW |
16 | */ |
17 | ||
18 | /** | |
19 | * @defgroup proposal_substructure proposal_substructure | |
20 | * @{ @ingroup payloads | |
da42afc5 JH |
21 | */ |
22 | ||
23 | #ifndef PROPOSAL_SUBSTRUCTURE_H_ | |
24 | #define PROPOSAL_SUBSTRUCTURE_H_ | |
25 | ||
0ff8d20a | 26 | typedef enum encap_t encap_t; |
382b4817 MW |
27 | typedef struct proposal_substructure_t proposal_substructure_t; |
28 | ||
db7ef624 | 29 | #include <library.h> |
4a962238 MW |
30 | #include <encoding/payloads/payload.h> |
31 | #include <encoding/payloads/transform_substructure.h> | |
2307bffe | 32 | #include <crypto/proposal/proposal.h> |
12642a68 | 33 | #include <collections/linked_list.h> |
fbebc2a0 | 34 | #include <kernel/kernel_ipsec.h> |
15a682f4 | 35 | #include <sa/authenticator.h> |
da42afc5 | 36 | |
0ff8d20a VR |
37 | /** |
38 | * Encap type for proposal substructure | |
39 | */ | |
40 | enum encap_t { | |
41 | ENCAP_NONE = 0, | |
42 | ENCAP_UDP, | |
43 | ENCAP_UDP_DRAFT_00_03, | |
44 | }; | |
45 | ||
da42afc5 | 46 | /** |
1bf2971f | 47 | * Class representing an IKEv1/IKEv2 proposal substructure. |
da42afc5 | 48 | */ |
95c61cb9 | 49 | struct proposal_substructure_t { |
806b69a4 | 50 | |
da42afc5 | 51 | /** |
3fe05870 | 52 | * The payload_t interface. |
da42afc5 JH |
53 | */ |
54 | payload_t payload_interface; | |
b860cffd | 55 | |
67978e0b | 56 | /** |
552cc11b | 57 | * Sets the proposal number of current proposal. |
67978e0b | 58 | * |
552cc11b | 59 | * @param id proposal number to set |
67978e0b | 60 | */ |
552cc11b | 61 | void (*set_proposal_number) (proposal_substructure_t *this, |
b12c53ce | 62 | uint8_t proposal_number); |
67978e0b | 63 | /** |
552cc11b | 64 | * get proposal number of current proposal. |
7daf5226 | 65 | * |
7a75cae8 | 66 | * @return proposal number of current proposal substructure. |
67978e0b | 67 | */ |
b12c53ce | 68 | uint8_t (*get_proposal_number) (proposal_substructure_t *this); |
67978e0b JH |
69 | |
70 | /** | |
552cc11b | 71 | * Sets the protocol id of current proposal. |
67978e0b | 72 | * |
552cc11b | 73 | * @param id protocol id to set |
67978e0b | 74 | */ |
552cc11b | 75 | void (*set_protocol_id) (proposal_substructure_t *this, |
b12c53ce | 76 | uint8_t protocol_id); |
7daf5226 | 77 | |
67978e0b | 78 | /** |
552cc11b | 79 | * get protocol id of current proposal. |
7daf5226 | 80 | * |
7a75cae8 | 81 | * @return protocol id of current proposal substructure. |
67978e0b | 82 | */ |
b12c53ce | 83 | uint8_t (*get_protocol_id) (proposal_substructure_t *this); |
7daf5226 | 84 | |
b737e9d9 | 85 | /** |
552cc11b | 86 | * Sets the next_payload field of this substructure |
7daf5226 | 87 | * |
b737e9d9 JH |
88 | * If this is the last proposal, next payload field is set to 0, |
89 | * otherwise to 2 | |
90 | * | |
b737e9d9 JH |
91 | * @param is_last When TRUE, next payload field is set to 0, otherwise to 2 |
92 | */ | |
93 | void (*set_is_last_proposal) (proposal_substructure_t *this, bool is_last); | |
7daf5226 | 94 | |
67978e0b | 95 | /** |
552cc11b MW |
96 | * Returns the currently set SPI of this proposal. |
97 | * | |
7a75cae8 | 98 | * @return chunk_t pointing to the value |
67978e0b JH |
99 | */ |
100 | chunk_t (*get_spi) (proposal_substructure_t *this); | |
7daf5226 | 101 | |
67978e0b | 102 | /** |
552cc11b | 103 | * Sets the SPI of the current proposal. |
7daf5226 | 104 | * |
67978e0b | 105 | * @warning SPI is getting copied |
7daf5226 | 106 | * |
552cc11b | 107 | * @param spi chunk_t pointing to the value to set |
67978e0b | 108 | */ |
3fe05870 | 109 | void (*set_spi) (proposal_substructure_t *this, chunk_t spi); |
7daf5226 | 110 | |
7a75cae8 TB |
111 | /** |
112 | * Gets the CPI of the current proposal (IKEv1 only). | |
113 | * | |
114 | * @param cpi the CPI if a supported algorithm is proposed | |
115 | * @return TRUE if a supported algorithm is proposed | |
116 | */ | |
b12c53ce | 117 | bool (*get_cpi) (proposal_substructure_t *this, uint16_t *cpi); |
7a75cae8 | 118 | |
fcfeb322 | 119 | /** |
d50152a7 | 120 | * Get proposals contained in a propsal_substructure_t. |
7daf5226 | 121 | * |
d50152a7 | 122 | * @param list list to add created proposals to |
fcfeb322 | 123 | */ |
d50152a7 | 124 | void (*get_proposals) (proposal_substructure_t *this, linked_list_t *list); |
b860cffd | 125 | |
54f2bdd6 MW |
126 | /** |
127 | * Create an enumerator over transform substructures. | |
128 | * | |
129 | * @return enumerator over transform_substructure_t | |
130 | */ | |
131 | enumerator_t* (*create_substructure_enumerator)(proposal_substructure_t *this); | |
132 | ||
914ec2db MW |
133 | /** |
134 | * Get the (shortest) lifetime of a proposal (IKEv1 only). | |
135 | * | |
136 | * @return lifetime, in seconds | |
137 | */ | |
b12c53ce | 138 | uint32_t (*get_lifetime)(proposal_substructure_t *this); |
914ec2db MW |
139 | |
140 | /** | |
141 | * Get the (shortest) life duration of a proposal (IKEv1 only). | |
142 | * | |
143 | * @return life duration, in bytes | |
144 | */ | |
b12c53ce | 145 | uint64_t (*get_lifebytes)(proposal_substructure_t *this); |
914ec2db MW |
146 | |
147 | /** | |
148 | * Get the first authentication method from the proposal (IKEv1 only). | |
149 | * | |
150 | * @return auth method, or AUTH_NONE | |
151 | */ | |
152 | auth_method_t (*get_auth_method)(proposal_substructure_t *this); | |
153 | ||
154 | /** | |
155 | * Get the (first) encapsulation mode from a proposal (IKEv1 only). | |
156 | * | |
157 | * @param udp set to TRUE if UDP encapsulation used | |
158 | * @return ipsec encapsulation mode | |
159 | */ | |
160 | ipsec_mode_t (*get_encap_mode)(proposal_substructure_t *this, bool *udp); | |
161 | ||
da42afc5 | 162 | /** |
552cc11b | 163 | * Destroys an proposal_substructure_t object. |
da42afc5 | 164 | */ |
3fe05870 | 165 | void (*destroy) (proposal_substructure_t *this); |
da42afc5 JH |
166 | }; |
167 | ||
168 | /** | |
552cc11b | 169 | * Creates an empty proposal_substructure_t object |
7daf5226 | 170 | * |
3ecfc83c | 171 | * @param type PLV2_PROPOSAL_SUBSTRUCTURE or PLV1_PROPOSAL_SUBSTRUCTURE |
1bf2971f | 172 | * @return proposal_substructure_t object |
da42afc5 | 173 | */ |
1bf2971f | 174 | proposal_substructure_t *proposal_substructure_create(payload_type_t type); |
da42afc5 | 175 | |
384efc76 | 176 | /** |
fbebc2a0 | 177 | * Creates an IKEv2 proposal_substructure_t from a proposal_t. |
8d77edde | 178 | * |
62a27ba3 | 179 | * @param proposal proposal to build a substruct out of it |
3ecfc83c | 180 | * @return proposal_substructure_t PLV2_PROPOSAL_SUBSTRUCTURE |
384efc76 | 181 | */ |
fbebc2a0 MW |
182 | proposal_substructure_t *proposal_substructure_create_from_proposal_v2( |
183 | proposal_t *proposal); | |
62a27ba3 | 184 | /** |
fbebc2a0 | 185 | * Creates an IKEv1 proposal_substructure_t from a proposal_t. |
62a27ba3 MW |
186 | * |
187 | * @param proposal proposal to build a substruct out of it | |
fbebc2a0 MW |
188 | * @param lifetime lifetime in seconds |
189 | * @param lifebytes lifebytes, in bytes | |
190 | * @param auth authentication method to use, or AUTH_NONE | |
191 | * @param mode IPsec encapsulation mode, TRANSPORT or TUNNEL | |
0ff8d20a | 192 | * @param udp ENCAP_UDP to use UDP encapsulation |
3ecfc83c | 193 | * @return proposal_substructure_t object PLV1_PROPOSAL_SUBSTRUCTURE |
fbebc2a0 MW |
194 | */ |
195 | proposal_substructure_t *proposal_substructure_create_from_proposal_v1( | |
b12c53ce | 196 | proposal_t *proposal, uint32_t lifetime, uint64_t lifebytes, |
0ff8d20a | 197 | auth_method_t auth, ipsec_mode_t mode, encap_t udp); |
fbebc2a0 MW |
198 | |
199 | /** | |
200 | * Creates an IKEv1 proposal_substructure_t from a list of proposal_t. | |
201 | * | |
202 | * @param proposals list of proposal_t to encode in a substructure | |
203 | * @param lifetime lifetime in seconds | |
204 | * @param lifebytes lifebytes, in bytes | |
205 | * @param auth authentication method to use, or AUTH_NONE | |
206 | * @param mode IPsec encapsulation mode, TRANSPORT or TUNNEL | |
0ff8d20a | 207 | * @param udp ENCAP_UDP to use UDP encapsulation |
3ecfc83c | 208 | * @return IKEv1 proposal_substructure_t PLV1_PROPOSAL_SUBSTRUCTURE |
62a27ba3 | 209 | */ |
fbebc2a0 | 210 | proposal_substructure_t *proposal_substructure_create_from_proposals_v1( |
b12c53ce | 211 | linked_list_t *proposals, uint32_t lifetime, uint64_t lifebytes, |
0ff8d20a | 212 | auth_method_t auth, ipsec_mode_t mode, encap_t udp); |
62a27ba3 | 213 | |
7a75cae8 TB |
214 | /** |
215 | * Creates an IKEv1 proposal_substructure_t for IPComp with the given | |
216 | * proposal_number (e.g. of a ESP proposal to bundle them). | |
217 | * | |
daab61e5 TB |
218 | * @param lifetime lifetime in seconds |
219 | * @param lifebytes lifebytes, in bytes | |
7a75cae8 | 220 | * @param cpi the CPI to be used |
daab61e5 | 221 | * @param mode IPsec encapsulation mode, TRANSPORT or TUNNEL |
0ff8d20a | 222 | * @param udp ENCAP_UDP to use UDP encapsulation |
7a75cae8 | 223 | * @param proposal_number the proposal number of the proposal to be linked |
3ecfc83c | 224 | * @return IKEv1 proposal_substructure_t PLV1_PROPOSAL_SUBSTRUCTURE |
7a75cae8 TB |
225 | */ |
226 | proposal_substructure_t *proposal_substructure_create_for_ipcomp_v1( | |
b12c53ce AS |
227 | uint32_t lifetime, uint64_t lifebytes, uint16_t cpi, |
228 | ipsec_mode_t mode, encap_t udp, uint8_t proposal_number); | |
7a75cae8 | 229 | |
1490ff4d | 230 | #endif /** PROPOSAL_SUBSTRUCTURE_H_ @}*/ |