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