Implemented encoding of additional IKEv1 proposal attributes
[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 * Destroys an proposal_substructure_t object.
116 */
117 void (*destroy) (proposal_substructure_t *this);
118 };
119
120 /**
121 * Creates an empty proposal_substructure_t object
122 *
123 * @param type PROPOSAL_SUBSTRUCTURE or PROPOSAL_SUBSTRUCTURE_V1
124 * @return proposal_substructure_t object
125 */
126 proposal_substructure_t *proposal_substructure_create(payload_type_t type);
127
128 /**
129 * Creates an IKEv2 proposal_substructure_t from a proposal_t.
130 *
131 * @param proposal proposal to build a substruct out of it
132 * @return proposal_substructure_t PROPOSAL_SUBSTRUCTURE
133 */
134 proposal_substructure_t *proposal_substructure_create_from_proposal_v2(
135 proposal_t *proposal);
136 /**
137 * Creates an IKEv1 proposal_substructure_t from a proposal_t.
138 *
139 * @param proposal proposal to build a substruct out of it
140 * @param lifetime lifetime in seconds
141 * @param lifebytes lifebytes, in bytes
142 * @param auth authentication method to use, or AUTH_NONE
143 * @param mode IPsec encapsulation mode, TRANSPORT or TUNNEL
144 * @param udp TRUE to use UDP encapsulation
145 *
146 *
147 * @return proposal_substructure_t object PROPOSAL_SUBSTRUCTURE_V1
148 */
149 proposal_substructure_t *proposal_substructure_create_from_proposal_v1(
150 proposal_t *proposal, u_int32_t lifetime, u_int64_t lifebytes,
151 auth_method_t auth, ipsec_mode_t mode, bool udp);
152
153 /**
154 * Creates an IKEv1 proposal_substructure_t from a list of proposal_t.
155 *
156 * @param proposals list of proposal_t to encode in a substructure
157 * @param lifetime lifetime in seconds
158 * @param lifebytes lifebytes, in bytes
159 * @param auth authentication method to use, or AUTH_NONE
160 * @param mode IPsec encapsulation mode, TRANSPORT or TUNNEL
161 * @param udp TRUE to use UDP encapsulation
162 * @return IKEv1 proposal_substructure_t PROPOSAL_SUBSTRUCTURE_V1
163 */
164 proposal_substructure_t *proposal_substructure_create_from_proposals_v1(
165 linked_list_t *proposals, u_int32_t lifetime, u_int64_t lifebytes,
166 auth_method_t auth, ipsec_mode_t mode, bool udp);
167
168 #endif /** PROPOSAL_SUBSTRUCTURE_H_ @}*/