removed dependencies on linux/types.h
[strongswan.git] / src / include / linux / xfrm.h
1 #ifndef _LINUX_XFRM_H
2 #define _LINUX_XFRM_H
3
4 #include <stdint.h>
5
6 /* All of the structures in this file may not change size as they are
7 * passed into the kernel from userspace via netlink sockets.
8 */
9
10 /* Structure to encapsulate addresses. I do not want to use
11 * "standard" structure. My apologies.
12 */
13 typedef union
14 {
15 uint32_t a4;
16 uint32_t a6[4];
17 } xfrm_address_t;
18
19 /* Ident of a specific xfrm_state. It is used on input to lookup
20 * the state by (spi,daddr,ah/esp) or to store information about
21 * spi, protocol and tunnel address on output.
22 */
23 struct xfrm_id
24 {
25 xfrm_address_t daddr;
26 uint32_t spi;
27 uint8_t proto;
28 };
29
30 struct xfrm_sec_ctx {
31 uint8_t ctx_doi;
32 uint8_t ctx_alg;
33 uint16_t ctx_len;
34 uint32_t ctx_sid;
35 char ctx_str[0];
36 };
37
38 /* Security Context Domains of Interpretation */
39 #define XFRM_SC_DOI_RESERVED 0
40 #define XFRM_SC_DOI_LSM 1
41
42 /* Security Context Algorithms */
43 #define XFRM_SC_ALG_RESERVED 0
44 #define XFRM_SC_ALG_SELINUX 1
45
46 /* Selector, used as selector both on policy rules (SPD) and SAs. */
47
48 struct xfrm_selector
49 {
50 xfrm_address_t daddr;
51 xfrm_address_t saddr;
52 uint16_t dport;
53 uint16_t dport_mask;
54 uint16_t sport;
55 uint16_t sport_mask;
56 uint16_t family;
57 uint8_t prefixlen_d;
58 uint8_t prefixlen_s;
59 uint8_t proto;
60 int ifindex;
61 uid_t user;
62 };
63
64 #define XFRM_INF (~(uint64_t)0)
65
66 struct xfrm_lifetime_cfg
67 {
68 uint64_t soft_byte_limit;
69 uint64_t hard_byte_limit;
70 uint64_t soft_packet_limit;
71 uint64_t hard_packet_limit;
72 uint64_t soft_add_expires_seconds;
73 uint64_t hard_add_expires_seconds;
74 uint64_t soft_use_expires_seconds;
75 uint64_t hard_use_expires_seconds;
76 };
77
78 struct xfrm_lifetime_cur
79 {
80 uint64_t bytes;
81 uint64_t packets;
82 uint64_t add_time;
83 uint64_t use_time;
84 };
85
86 struct xfrm_replay_state
87 {
88 uint32_t oseq;
89 uint32_t seq;
90 uint32_t bitmap;
91 };
92
93 struct xfrm_algo {
94 char alg_name[64];
95 int alg_key_len; /* in bits */
96 char alg_key[0];
97 };
98
99 struct xfrm_stats {
100 uint32_t replay_window;
101 uint32_t replay;
102 uint32_t integrity_failed;
103 };
104
105 enum
106 {
107 XFRM_POLICY_IN = 0,
108 XFRM_POLICY_OUT = 1,
109 XFRM_POLICY_FWD = 2,
110 XFRM_POLICY_MAX = 3
111 };
112
113 enum
114 {
115 XFRM_SHARE_ANY, /* No limitations */
116 XFRM_SHARE_SESSION, /* For this session only */
117 XFRM_SHARE_USER, /* For this user only */
118 XFRM_SHARE_UNIQUE /* Use once */
119 };
120
121 /* Netlink configuration messages. */
122 enum {
123 XFRM_MSG_BASE = 0x10,
124
125 XFRM_MSG_NEWSA = 0x10,
126 #define XFRM_MSG_NEWSA XFRM_MSG_NEWSA
127 XFRM_MSG_DELSA,
128 #define XFRM_MSG_DELSA XFRM_MSG_DELSA
129 XFRM_MSG_GETSA,
130 #define XFRM_MSG_GETSA XFRM_MSG_GETSA
131
132 XFRM_MSG_NEWPOLICY,
133 #define XFRM_MSG_NEWPOLICY XFRM_MSG_NEWPOLICY
134 XFRM_MSG_DELPOLICY,
135 #define XFRM_MSG_DELPOLICY XFRM_MSG_DELPOLICY
136 XFRM_MSG_GETPOLICY,
137 #define XFRM_MSG_GETPOLICY XFRM_MSG_GETPOLICY
138
139 XFRM_MSG_ALLOCSPI,
140 #define XFRM_MSG_ALLOCSPI XFRM_MSG_ALLOCSPI
141 XFRM_MSG_ACQUIRE,
142 #define XFRM_MSG_ACQUIRE XFRM_MSG_ACQUIRE
143 XFRM_MSG_EXPIRE,
144 #define XFRM_MSG_EXPIRE XFRM_MSG_EXPIRE
145
146 XFRM_MSG_UPDPOLICY,
147 #define XFRM_MSG_UPDPOLICY XFRM_MSG_UPDPOLICY
148 XFRM_MSG_UPDSA,
149 #define XFRM_MSG_UPDSA XFRM_MSG_UPDSA
150
151 XFRM_MSG_POLEXPIRE,
152 #define XFRM_MSG_POLEXPIRE XFRM_MSG_POLEXPIRE
153
154 XFRM_MSG_FLUSHSA,
155 #define XFRM_MSG_FLUSHSA XFRM_MSG_FLUSHSA
156 XFRM_MSG_FLUSHPOLICY,
157 #define XFRM_MSG_FLUSHPOLICY XFRM_MSG_FLUSHPOLICY
158
159 XFRM_MSG_NEWAE,
160 #define XFRM_MSG_NEWAE XFRM_MSG_NEWAE
161 XFRM_MSG_GETAE,
162 #define XFRM_MSG_GETAE XFRM_MSG_GETAE
163 __XFRM_MSG_MAX
164 };
165 #define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
166
167 #define XFRM_NR_MSGTYPES (XFRM_MSG_MAX + 1 - XFRM_MSG_BASE)
168
169 /*
170 * Generic LSM security context for comunicating to user space
171 * NOTE: Same format as sadb_x_sec_ctx
172 */
173 struct xfrm_user_sec_ctx {
174 uint16_t len;
175 uint16_t exttype;
176 uint8_t ctx_alg; /* LSMs: e.g., selinux == 1 */
177 uint8_t ctx_doi;
178 uint16_t ctx_len;
179 };
180
181 struct xfrm_user_tmpl {
182 struct xfrm_id id;
183 uint16_t family;
184 xfrm_address_t saddr;
185 uint32_t reqid;
186 uint8_t mode;
187 uint8_t share;
188 uint8_t optional;
189 uint32_t aalgos;
190 uint32_t ealgos;
191 uint32_t calgos;
192 };
193
194 struct xfrm_encap_tmpl {
195 uint16_t encap_type;
196 uint16_t encap_sport;
197 uint16_t encap_dport;
198 xfrm_address_t encap_oa;
199 };
200
201 /* AEVENT flags */
202 enum xfrm_ae_ftype_t {
203 XFRM_AE_UNSPEC,
204 XFRM_AE_RTHR=1, /* replay threshold*/
205 XFRM_AE_RVAL=2, /* replay value */
206 XFRM_AE_LVAL=4, /* lifetime value */
207 XFRM_AE_ETHR=8, /* expiry timer threshold */
208 XFRM_AE_CR=16, /* Event cause is replay update */
209 XFRM_AE_CE=32, /* Event cause is timer expiry */
210 XFRM_AE_CU=64, /* Event cause is policy update */
211 __XFRM_AE_MAX
212
213 #define XFRM_AE_MAX (__XFRM_AE_MAX - 1)
214 };
215
216 /* Netlink message attributes. */
217 enum xfrm_attr_type_t {
218 XFRMA_UNSPEC,
219 XFRMA_ALG_AUTH, /* struct xfrm_algo */
220 XFRMA_ALG_CRYPT, /* struct xfrm_algo */
221 XFRMA_ALG_COMP, /* struct xfrm_algo */
222 XFRMA_ENCAP, /* struct xfrm_algo + struct xfrm_encap_tmpl */
223 XFRMA_TMPL, /* 1 or more struct xfrm_user_tmpl */
224 XFRMA_SA,
225 XFRMA_POLICY,
226 XFRMA_SEC_CTX, /* struct xfrm_sec_ctx */
227 XFRMA_LTIME_VAL,
228 XFRMA_REPLAY_VAL,
229 XFRMA_REPLAY_THRESH,
230 XFRMA_ETIMER_THRESH,
231 __XFRMA_MAX
232
233 #define XFRMA_MAX (__XFRMA_MAX - 1)
234 };
235
236 struct xfrm_usersa_info {
237 struct xfrm_selector sel;
238 struct xfrm_id id;
239 xfrm_address_t saddr;
240 struct xfrm_lifetime_cfg lft;
241 struct xfrm_lifetime_cur curlft;
242 struct xfrm_stats stats;
243 uint32_t seq;
244 uint32_t reqid;
245 uint16_t family;
246 uint8_t mode; /* 0=transport,1=tunnel */
247 uint8_t replay_window;
248 uint8_t flags;
249 #define XFRM_STATE_NOECN 1
250 #define XFRM_STATE_DECAP_DSCP 2
251 #define XFRM_STATE_NOPMTUDISC 4
252 };
253
254 struct xfrm_usersa_id {
255 xfrm_address_t daddr;
256 uint32_t spi;
257 uint16_t family;
258 uint8_t proto;
259 };
260
261 struct xfrm_aevent_id {
262 struct xfrm_usersa_id sa_id;
263 uint32_t flags;
264 };
265
266 struct xfrm_userspi_info {
267 struct xfrm_usersa_info info;
268 uint32_t min;
269 uint32_t max;
270 };
271
272 struct xfrm_userpolicy_info {
273 struct xfrm_selector sel;
274 struct xfrm_lifetime_cfg lft;
275 struct xfrm_lifetime_cur curlft;
276 uint32_t priority;
277 uint32_t index;
278 uint8_t dir;
279 uint8_t action;
280 #define XFRM_POLICY_ALLOW 0
281 #define XFRM_POLICY_BLOCK 1
282 uint8_t flags;
283 #define XFRM_POLICY_LOCALOK 1 /* Allow user to override global policy */
284 uint8_t share;
285 };
286
287 struct xfrm_userpolicy_id {
288 struct xfrm_selector sel;
289 uint32_t index;
290 uint8_t dir;
291 };
292
293 struct xfrm_user_acquire {
294 struct xfrm_id id;
295 xfrm_address_t saddr;
296 struct xfrm_selector sel;
297 struct xfrm_userpolicy_info policy;
298 uint32_t aalgos;
299 uint32_t ealgos;
300 uint32_t calgos;
301 uint32_t seq;
302 };
303
304 struct xfrm_user_expire {
305 struct xfrm_usersa_info state;
306 uint8_t hard;
307 };
308
309 struct xfrm_user_polexpire {
310 struct xfrm_userpolicy_info pol;
311 uint8_t hard;
312 };
313
314 struct xfrm_usersa_flush {
315 uint8_t proto;
316 };
317
318 /* backwards compatibility for userspace */
319 #define XFRMGRP_ACQUIRE 1
320 #define XFRMGRP_EXPIRE 2
321 #define XFRMGRP_SA 4
322 #define XFRMGRP_POLICY 8
323
324 enum xfrm_nlgroups {
325 XFRMNLGRP_NONE,
326 #define XFRMNLGRP_NONE XFRMNLGRP_NONE
327 XFRMNLGRP_ACQUIRE,
328 #define XFRMNLGRP_ACQUIRE XFRMNLGRP_ACQUIRE
329 XFRMNLGRP_EXPIRE,
330 #define XFRMNLGRP_EXPIRE XFRMNLGRP_EXPIRE
331 XFRMNLGRP_SA,
332 #define XFRMNLGRP_SA XFRMNLGRP_SA
333 XFRMNLGRP_POLICY,
334 #define XFRMNLGRP_POLICY XFRMNLGRP_POLICY
335 XFRMNLGRP_AEVENTS,
336 #define XFRMNLGRP_AEVENTS XFRMNLGRP_AEVENTS
337 __XFRMNLGRP_MAX
338 };
339 #define XFRMNLGRP_MAX (__XFRMNLGRP_MAX - 1)
340
341 #endif /* _LINUX_XFRM_H */