2 * @file proposal_substructure.h
4 * @brief Interface of proposal_substructure_t.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
23 #ifndef PROPOSAL_SUBSTRUCTURE_H_
24 #define PROPOSAL_SUBSTRUCTURE_H_
27 #include <encoding/payloads/payload.h>
28 #include <encoding/payloads/transform_substructure.h>
29 #include <config/proposal.h>
30 #include <utils/linked_list.h>
34 * Length of the proposal substructure header (without spi).
38 #define PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH 8
41 typedef struct proposal_substructure_t proposal_substructure_t
;
44 * @brief Class representing an IKEv2-PROPOSAL SUBSTRUCTURE.
46 * The PROPOSAL SUBSTRUCTURE format is described in RFC section 3.3.1.
49 * - proposal_substructure_create()
53 struct proposal_substructure_t
{
55 * The payload_t interface.
57 payload_t payload_interface
;
60 * @brief Creates an iterator of stored transform_substructure_t objects.
62 * @warning The created iterator has to get destroyed by the caller!
63 * When deleting any transform over this iterator, call
64 * get_size to make sure the length and number values are ok.
66 * @param this calling proposal_substructure_t object
67 * @param forward iterator direction (TRUE: front to end)
68 * @return created iterator_t object
70 iterator_t
* (*create_transform_substructure_iterator
) (proposal_substructure_t
*this, bool forward
);
73 * @brief Adds a transform_substructure_t object to this object.
75 * @warning The added transform_substructure_t object is
76 * getting destroyed in destroy function of proposal_substructure_t.
78 * @param this calling proposal_substructure_t object
79 * @param transform transform_substructure_t object to add
81 void (*add_transform_substructure
) (proposal_substructure_t
*this,transform_substructure_t
*transform
);
84 * @brief Sets the proposal number of current proposal.
86 * @param this calling proposal_substructure_t object
87 * @param id proposal number to set
89 void (*set_proposal_number
) (proposal_substructure_t
*this,u_int8_t proposal_number
);
92 * @brief get proposal number of current proposal.
94 * @param this calling proposal_substructure_t object
95 * @return proposal number of current proposal substructure.
97 u_int8_t (*get_proposal_number
) (proposal_substructure_t
*this);
100 * @brief get the number of transforms in current proposal.
102 * @param this calling proposal_substructure_t object
103 * @return transform count in current proposal
105 size_t (*get_transform_count
) (proposal_substructure_t
*this);
108 * @brief get size of the set spi in bytes.
110 * @param this calling proposal_substructure_t object
111 * @return size of the spi in bytes
113 size_t (*get_spi_size
) (proposal_substructure_t
*this);
116 * @brief Sets the protocol id of current proposal.
118 * @param this calling proposal_substructure_t object
119 * @param id protocol id to set
121 void (*set_protocol_id
) (proposal_substructure_t
*this,u_int8_t protocol_id
);
124 * @brief get protocol id of current proposal.
126 * @param this calling proposal_substructure_t object
127 * @return protocol id of current proposal substructure.
129 u_int8_t (*get_protocol_id
) (proposal_substructure_t
*this);
132 * @brief Get informations for a specific transform type.
134 * @param this calling proposal_substructure_t object
135 * @param type type to get informations for
136 * @param transform_id transform id of the specific type
137 * @param key_length key length of the specific key length transform attribute
139 * - SUCCESS if transform type is part of this proposal and
140 * all data (incl. key length) could be fetched
141 * - NOT_FOUND if transform type is not part of this proposal
143 status_t (*get_info_for_transform_type
) (proposal_substructure_t
*this,transform_type_t type
, u_int16_t
*transform_id
, u_int16_t
*key_length
);
146 * @brief Sets the next_payload field of this substructure
148 * If this is the last proposal, next payload field is set to 0,
151 * @param this calling proposal_substructure_t object
152 * @param is_last When TRUE, next payload field is set to 0, otherwise to 2
154 void (*set_is_last_proposal
) (proposal_substructure_t
*this, bool is_last
);
157 * @brief Returns the currently set SPI of this proposal.
159 * @warning Returned data are not copied
161 * @param this calling proposal_substructure_t object
162 * @return chunk_t pointing to the value
164 chunk_t (*get_spi
) (proposal_substructure_t
*this);
167 * @brief Sets the SPI of the current proposal.
169 * @warning SPI is getting copied
171 * @param this calling proposal_substructure_t object
172 * @param spi chunk_t pointing to the value to set
174 void (*set_spi
) (proposal_substructure_t
*this, chunk_t spi
);
177 * @brief Add this proposal_substructure to a proposal.
179 * Since a proposal_t may contain the data of multiple
180 * proposal_sbustructure_t's, it may be necessary to call
181 * the function multiple times with the same proposal.
183 * @param this calling proposal_substructure_t object
184 * @param proposal proposal where the data should be added
186 void (*add_to_proposal
) (proposal_substructure_t
*this, proposal_t
*proposal
);
189 * @brief Clones an proposal_substructure_t object.
191 * @param this proposal_substructure_t object to clone
192 * @return cloned object
194 proposal_substructure_t
* (*clone
) (proposal_substructure_t
*this);
197 * @brief Destroys an proposal_substructure_t object.
199 * @param this proposal_substructure_t object to destroy
201 void (*destroy
) (proposal_substructure_t
*this);
205 * @brief Creates an empty proposal_substructure_t object
207 * @return proposal_substructure_t object
211 proposal_substructure_t
*proposal_substructure_create();
214 * @brief Creates a proposal substructure from a proposal.
216 * Since a child proposal may contain data for both AH and ESP,
217 * the protocol must be specified. If the proposal does not contain
218 * data for proto, NULL is returned. Call twice, once with AH, once
219 * with ESP, with the same proposal to build the two substructures
222 * @param proposal proposal to build a substruct out of it
223 * @param proto for which protocol the substructure should be built
224 * @return proposal_substructure_t object, or NULL
228 proposal_substructure_t
*proposal_substructure_create_from_proposal(proposal_t
*proposal
, protocol_id_t proto
);
231 #endif /*PROPOSAL_SUBSTRUCTURE_H_*/