payload: Use common prefixes for all payload type identifiers
[strongswan.git] / src / libcharon / encoding / payloads / sa_payload.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 sa_payload sa_payload
19 * @{ @ingroup payloads
20 */
21
22 #ifndef SA_PAYLOAD_H_
23 #define SA_PAYLOAD_H_
24
25 typedef struct sa_payload_t sa_payload_t;
26
27 #include <library.h>
28 #include <encoding/payloads/payload.h>
29 #include <encoding/payloads/proposal_substructure.h>
30 #include <collections/linked_list.h>
31 #include <kernel/kernel_ipsec.h>
32 #include <sa/authenticator.h>
33
34 /**
35 * Class representing an IKEv1 or IKEv2 SA Payload.
36 *
37 * The SA Payload format is described in RFC section 3.3.
38 */
39 struct sa_payload_t {
40
41 /**
42 * The payload_t interface.
43 */
44 payload_t payload_interface;
45
46 /**
47 * Gets the proposals in this payload as a list.
48 *
49 * @return a list containing proposal_ts
50 */
51 linked_list_t *(*get_proposals) (sa_payload_t *this);
52
53 /**
54 * Gets the proposals from the first proposal in this payload with IPComp
55 * enabled (IKEv1 only).
56 *
57 * @param cpi the CPI of the first IPComp (sub)proposal
58 * @return a list containing proposal_ts
59 */
60 linked_list_t *(*get_ipcomp_proposals) (sa_payload_t *this, u_int16_t *cpi);
61
62 /**
63 * Get the (shortest) lifetime of a proposal (IKEv1 only).
64 *
65 * @return lifetime, in seconds
66 */
67 u_int32_t (*get_lifetime)(sa_payload_t *this);
68
69 /**
70 * Get the (shortest) life duration of a proposal (IKEv1 only).
71 *
72 * @return life duration, in bytes
73 */
74 u_int64_t (*get_lifebytes)(sa_payload_t *this);
75
76 /**
77 * Get the first authentication method from the proposal (IKEv1 only).
78 *
79 * @return auth method, or AUTH_NONE
80 */
81 auth_method_t (*get_auth_method)(sa_payload_t *this);
82
83 /**
84 * Get the (first) encapsulation mode from a proposal (IKEv1 only).
85 *
86 * @param udp set to TRUE if UDP encapsulation used
87 * @return ipsec encapsulation mode
88 */
89 ipsec_mode_t (*get_encap_mode)(sa_payload_t *this, bool *udp);
90
91 /**
92 * Create an enumerator over all proposal substructures.
93 *
94 * @return enumerator over proposal_substructure_t
95 */
96 enumerator_t* (*create_substructure_enumerator)(sa_payload_t *this);
97
98 /**
99 * Destroys an sa_payload_t object.
100 */
101 void (*destroy) (sa_payload_t *this);
102 };
103
104 /**
105 * Creates an empty sa_payload_t object
106 *
107 * @param type PLV2_SECURITY_ASSOCIATION or PLV1_SECURITY_ASSOCIATION
108 * @return created sa_payload_t object
109 */
110 sa_payload_t *sa_payload_create(payload_type_t type);
111
112 /**
113 * Creates an IKEv2 sa_payload_t object from a list of proposals.
114 *
115 * @param proposals list of proposals to build the payload from
116 * @return sa_payload_t object
117 */
118 sa_payload_t *sa_payload_create_from_proposals_v2(linked_list_t *proposals);
119
120 /**
121 * Creates an IKEv2 sa_payload_t object from a single proposal.
122 *
123 * @param proposal proposal from which the payload should be built.
124 * @return sa_payload_t object
125 */
126 sa_payload_t *sa_payload_create_from_proposal_v2(proposal_t *proposal);
127
128 /**
129 * Creates an IKEv1 sa_payload_t object from a list of proposals.
130 *
131 * @param proposals list of proposals to build the payload from
132 * @param lifetime lifetime in seconds
133 * @param lifebytes lifebytes, in bytes
134 * @param auth authentication method to use, or AUTH_NONE
135 * @param mode IPsec encapsulation mode, TRANSPORT or TUNNEL
136 * @param udp ENCAP_UDP to use UDP encapsulation
137 * @param cpi CPI in case IPComp should be used
138 * @return sa_payload_t object
139 */
140 sa_payload_t *sa_payload_create_from_proposals_v1(linked_list_t *proposals,
141 u_int32_t lifetime, u_int64_t lifebytes,
142 auth_method_t auth, ipsec_mode_t mode, encap_t udp,
143 u_int16_t cpi);
144
145 /**
146 * Creates an IKEv1 sa_payload_t object from a single proposal.
147 *
148 * @param proposal proposal from which the payload should be built.
149 * @param lifetime lifetime in seconds
150 * @param lifebytes lifebytes, in bytes
151 * @param auth authentication method to use, or AUTH_NONE
152 * @param mode IPsec encapsulation mode, TRANSPORT or TUNNEL
153 * @param udp ENCAP_UDP to use UDP encapsulation
154 * @param cpi CPI in case IPComp should be used
155 * @return sa_payload_t object
156 */
157 sa_payload_t *sa_payload_create_from_proposal_v1(proposal_t *proposal,
158 u_int32_t lifetime, u_int64_t lifebytes,
159 auth_method_t auth, ipsec_mode_t mode, encap_t udp,
160 u_int16_t cpi);
161
162 #endif /** SA_PAYLOAD_H_ @}*/