1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2#ifndef _LINUX_XFRM_H
3#define _LINUX_XFRM_H
4
5#include <linux/in6.h>
6#include <linux/types.h>
7#include <linux/stddef.h>
8
9/* All of the structures in this file may not change size as they are
10 * passed into the kernel from userspace via netlink sockets.
11 */
12
13/* Structure to encapsulate addresses. I do not want to use
14 * "standard" structure. My apologies.
15 */
16typedef union {
17 __be32 a4;
18 __be32 a6[4];
19 struct in6_addr in6;
20} xfrm_address_t;
21
22/* Ident of a specific xfrm_state. It is used on input to lookup
23 * the state by (spi,daddr,ah/esp) or to store information about
24 * spi, protocol and tunnel address on output.
25 */
26struct xfrm_id {
27 xfrm_address_t daddr;
28 __be32 spi;
29 __u8 proto;
30};
31
32struct xfrm_sec_ctx {
33 __u8 ctx_doi;
34 __u8 ctx_alg;
35 __u16 ctx_len;
36 __u32 ctx_sid;
37 char ctx_str[] __counted_by(ctx_len);
38};
39
40/* Security Context Domains of Interpretation */
41#define XFRM_SC_DOI_RESERVED 0
42#define XFRM_SC_DOI_LSM 1
43
44/* Security Context Algorithms */
45#define XFRM_SC_ALG_RESERVED 0
46#define XFRM_SC_ALG_SELINUX 1
47
48/* Selector, used as selector both on policy rules (SPD) and SAs. */
49
50struct xfrm_selector {
51 xfrm_address_t daddr;
52 xfrm_address_t saddr;
53 __be16 dport;
54 __be16 dport_mask;
55 __be16 sport;
56 __be16 sport_mask;
57 __u16 family;
58 __u8 prefixlen_d;
59 __u8 prefixlen_s;
60 __u8 proto;
61 int ifindex;
62 __kernel_uid32_t user;
63};
64
65#define XFRM_INF (~(__u64)0)
66
67struct xfrm_lifetime_cfg {
68 __u64 soft_byte_limit;
69 __u64 hard_byte_limit;
70 __u64 soft_packet_limit;
71 __u64 hard_packet_limit;
72 __u64 soft_add_expires_seconds;
73 __u64 hard_add_expires_seconds;
74 __u64 soft_use_expires_seconds;
75 __u64 hard_use_expires_seconds;
76};
77
78struct xfrm_lifetime_cur {
79 __u64 bytes;
80 __u64 packets;
81 __u64 add_time;
82 __u64 use_time;
83};
84
85struct xfrm_replay_state {
86 __u32 oseq;
87 __u32 seq;
88 __u32 bitmap;
89};
90
91#define XFRMA_REPLAY_ESN_MAX 4096
92
93struct xfrm_replay_state_esn {
94 unsigned int bmp_len;
95 __u32 oseq;
96 __u32 seq;
97 __u32 oseq_hi;
98 __u32 seq_hi;
99 __u32 replay_window;
100 __u32 bmp[];
101};
102
103struct xfrm_algo {
104 char alg_name[64];
105 unsigned int alg_key_len; /* in bits */
106 char alg_key[];
107};
108
109struct xfrm_algo_auth {
110 char alg_name[64];
111 unsigned int alg_key_len; /* in bits */
112 unsigned int alg_trunc_len; /* in bits */
113 char alg_key[];
114};
115
116struct xfrm_algo_aead {
117 char alg_name[64];
118 unsigned int alg_key_len; /* in bits */
119 unsigned int alg_icv_len; /* in bits */
120 char alg_key[];
121};
122
123struct xfrm_stats {
124 __u32 replay_window;
125 __u32 replay;
126 __u32 integrity_failed;
127};
128
129enum {
130 XFRM_POLICY_TYPE_MAIN = 0,
131 XFRM_POLICY_TYPE_SUB = 1,
132 XFRM_POLICY_TYPE_MAX = 2,
133 XFRM_POLICY_TYPE_ANY = 255
134};
135
136enum {
137 XFRM_POLICY_IN = 0,
138 XFRM_POLICY_OUT = 1,
139 XFRM_POLICY_FWD = 2,
140 XFRM_POLICY_MASK = 3,
141 XFRM_POLICY_MAX = 3
142};
143
144enum xfrm_sa_dir {
145 XFRM_SA_DIR_IN = 1,
146 XFRM_SA_DIR_OUT = 2
147};
148
149enum {
150 XFRM_SHARE_ANY, /* No limitations */
151 XFRM_SHARE_SESSION, /* For this session only */
152 XFRM_SHARE_USER, /* For this user only */
153 XFRM_SHARE_UNIQUE /* Use once */
154};
155
156#define XFRM_MODE_TRANSPORT 0
157#define XFRM_MODE_TUNNEL 1
158#define XFRM_MODE_ROUTEOPTIMIZATION 2
159#define XFRM_MODE_IN_TRIGGER 3
160#define XFRM_MODE_BEET 4
161#define XFRM_MODE_IPTFS 5
162#define XFRM_MODE_MAX 6
163
164/* Netlink configuration messages. */
165enum {
166 XFRM_MSG_BASE = 0x10,
167
168 XFRM_MSG_NEWSA = 0x10,
169#define XFRM_MSG_NEWSA XFRM_MSG_NEWSA
170 XFRM_MSG_DELSA,
171#define XFRM_MSG_DELSA XFRM_MSG_DELSA
172 XFRM_MSG_GETSA,
173#define XFRM_MSG_GETSA XFRM_MSG_GETSA
174
175 XFRM_MSG_NEWPOLICY,
176#define XFRM_MSG_NEWPOLICY XFRM_MSG_NEWPOLICY
177 XFRM_MSG_DELPOLICY,
178#define XFRM_MSG_DELPOLICY XFRM_MSG_DELPOLICY
179 XFRM_MSG_GETPOLICY,
180#define XFRM_MSG_GETPOLICY XFRM_MSG_GETPOLICY
181
182 XFRM_MSG_ALLOCSPI,
183#define XFRM_MSG_ALLOCSPI XFRM_MSG_ALLOCSPI
184 XFRM_MSG_ACQUIRE,
185#define XFRM_MSG_ACQUIRE XFRM_MSG_ACQUIRE
186 XFRM_MSG_EXPIRE,
187#define XFRM_MSG_EXPIRE XFRM_MSG_EXPIRE
188
189 XFRM_MSG_UPDPOLICY,
190#define XFRM_MSG_UPDPOLICY XFRM_MSG_UPDPOLICY
191 XFRM_MSG_UPDSA,
192#define XFRM_MSG_UPDSA XFRM_MSG_UPDSA
193
194 XFRM_MSG_POLEXPIRE,
195#define XFRM_MSG_POLEXPIRE XFRM_MSG_POLEXPIRE
196
197 XFRM_MSG_FLUSHSA,
198#define XFRM_MSG_FLUSHSA XFRM_MSG_FLUSHSA
199 XFRM_MSG_FLUSHPOLICY,
200#define XFRM_MSG_FLUSHPOLICY XFRM_MSG_FLUSHPOLICY
201
202 XFRM_MSG_NEWAE,
203#define XFRM_MSG_NEWAE XFRM_MSG_NEWAE
204 XFRM_MSG_GETAE,
205#define XFRM_MSG_GETAE XFRM_MSG_GETAE
206
207 XFRM_MSG_REPORT,
208#define XFRM_MSG_REPORT XFRM_MSG_REPORT
209
210 XFRM_MSG_MIGRATE,
211#define XFRM_MSG_MIGRATE XFRM_MSG_MIGRATE
212
213 XFRM_MSG_NEWSADINFO,
214#define XFRM_MSG_NEWSADINFO XFRM_MSG_NEWSADINFO
215 XFRM_MSG_GETSADINFO,
216#define XFRM_MSG_GETSADINFO XFRM_MSG_GETSADINFO
217
218 XFRM_MSG_NEWSPDINFO,
219#define XFRM_MSG_NEWSPDINFO XFRM_MSG_NEWSPDINFO
220 XFRM_MSG_GETSPDINFO,
221#define XFRM_MSG_GETSPDINFO XFRM_MSG_GETSPDINFO
222
223 XFRM_MSG_MAPPING,
224#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING
225
226 XFRM_MSG_SETDEFAULT,
227#define XFRM_MSG_SETDEFAULT XFRM_MSG_SETDEFAULT
228 XFRM_MSG_GETDEFAULT,
229#define XFRM_MSG_GETDEFAULT XFRM_MSG_GETDEFAULT
230
231 XFRM_MSG_MIGRATE_STATE,
232#define XFRM_MSG_MIGRATE_STATE XFRM_MSG_MIGRATE_STATE
233 __XFRM_MSG_MAX
234};
235#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
236
237#define XFRM_NR_MSGTYPES (XFRM_MSG_MAX + 1 - XFRM_MSG_BASE)
238
239/*
240 * Generic LSM security context for communicating to user space
241 * NOTE: Same format as sadb_x_sec_ctx
242 */
243struct xfrm_user_sec_ctx {
244 __u16 len;
245 __u16 exttype;
246 __u8 ctx_alg; /* LSMs: e.g., selinux == 1 */
247 __u8 ctx_doi;
248 __u16 ctx_len;
249};
250
251struct xfrm_user_tmpl {
252 struct xfrm_id id;
253 __u16 family;
254 xfrm_address_t saddr;
255 __u32 reqid;
256 __u8 mode;
257 __u8 share;
258 __u8 optional;
259 __u32 aalgos;
260 __u32 ealgos;
261 __u32 calgos;
262};
263
264struct xfrm_encap_tmpl {
265 __u16 encap_type;
266 __be16 encap_sport;
267 __be16 encap_dport;
268 xfrm_address_t encap_oa;
269};
270
271/* AEVENT flags */
272enum xfrm_ae_ftype_t {
273 XFRM_AE_UNSPEC,
274 XFRM_AE_RTHR=1, /* replay threshold*/
275 XFRM_AE_RVAL=2, /* replay value */
276 XFRM_AE_LVAL=4, /* lifetime value */
277 XFRM_AE_ETHR=8, /* expiry timer threshold */
278 XFRM_AE_CR=16, /* Event cause is replay update */
279 XFRM_AE_CE=32, /* Event cause is timer expiry */
280 XFRM_AE_CU=64, /* Event cause is policy update */
281 __XFRM_AE_MAX
282
283#define XFRM_AE_MAX (__XFRM_AE_MAX - 1)
284};
285
286struct xfrm_userpolicy_type {
287 __u8 type;
288 __u16 reserved1;
289 __u8 reserved2;
290};
291
292/* Netlink message attributes. */
293enum xfrm_attr_type_t {
294 XFRMA_UNSPEC,
295 XFRMA_ALG_AUTH, /* struct xfrm_algo */
296 XFRMA_ALG_CRYPT, /* struct xfrm_algo */
297 XFRMA_ALG_COMP, /* struct xfrm_algo */
298 XFRMA_ENCAP, /* struct xfrm_algo + struct xfrm_encap_tmpl */
299 XFRMA_TMPL, /* 1 or more struct xfrm_user_tmpl */
300 XFRMA_SA, /* struct xfrm_usersa_info */
301 XFRMA_POLICY, /*struct xfrm_userpolicy_info */
302 XFRMA_SEC_CTX, /* struct xfrm_sec_ctx */
303 XFRMA_LTIME_VAL,
304 XFRMA_REPLAY_VAL,
305 XFRMA_REPLAY_THRESH,
306 XFRMA_ETIMER_THRESH,
307 XFRMA_SRCADDR, /* xfrm_address_t */
308 XFRMA_COADDR, /* xfrm_address_t */
309 XFRMA_LASTUSED, /* __u64 */
310 XFRMA_POLICY_TYPE, /* struct xfrm_userpolicy_type */
311 XFRMA_MIGRATE,
312 XFRMA_ALG_AEAD, /* struct xfrm_algo_aead */
313 XFRMA_KMADDRESS, /* struct xfrm_user_kmaddress */
314 XFRMA_ALG_AUTH_TRUNC, /* struct xfrm_algo_auth */
315 XFRMA_MARK, /* struct xfrm_mark */
316 XFRMA_TFCPAD, /* __u32 */
317 XFRMA_REPLAY_ESN_VAL, /* struct xfrm_replay_state_esn */
318 XFRMA_SA_EXTRA_FLAGS, /* __u32 */
319 XFRMA_PROTO, /* __u8 */
320 XFRMA_ADDRESS_FILTER, /* struct xfrm_address_filter */
321 XFRMA_PAD,
322 XFRMA_OFFLOAD_DEV, /* struct xfrm_user_offload */
323 XFRMA_SET_MARK, /* __u32 */
324 XFRMA_SET_MARK_MASK, /* __u32 */
325 XFRMA_IF_ID, /* __u32 */
326 XFRMA_MTIMER_THRESH, /* __u32 in seconds for input SA */
327 XFRMA_SA_DIR, /* __u8 */
328 XFRMA_NAT_KEEPALIVE_INTERVAL, /* __u32 in seconds for NAT keepalive */
329 XFRMA_SA_PCPU, /* __u32 */
330 XFRMA_IPTFS_DROP_TIME, /* __u32 in: usec to wait for next seq */
331 XFRMA_IPTFS_REORDER_WINDOW, /* __u16 in: reorder window size (pkts) */
332 XFRMA_IPTFS_DONT_FRAG, /* out: don't use fragmentation */
333 XFRMA_IPTFS_INIT_DELAY, /* __u32 out: initial packet wait delay (usec) */
334 XFRMA_IPTFS_MAX_QSIZE, /* __u32 out: max ingress queue size (octets) */
335 XFRMA_IPTFS_PKT_SIZE, /* __u32 out: size of outer packet, 0 for PMTU */
336 __XFRMA_MAX
337
338#define XFRMA_OUTPUT_MARK XFRMA_SET_MARK /* Compatibility */
339#define XFRMA_MAX (__XFRMA_MAX - 1)
340};
341
342struct xfrm_mark {
343 __u32 v; /* value */
344 __u32 m; /* mask */
345};
346
347enum xfrm_sadattr_type_t {
348 XFRMA_SAD_UNSPEC,
349 XFRMA_SAD_CNT,
350 XFRMA_SAD_HINFO,
351 __XFRMA_SAD_MAX
352
353#define XFRMA_SAD_MAX (__XFRMA_SAD_MAX - 1)
354};
355
356struct xfrmu_sadhinfo {
357 __u32 sadhcnt; /* current hash bkts */
358 __u32 sadhmcnt; /* max allowed hash bkts */
359};
360
361enum xfrm_spdattr_type_t {
362 XFRMA_SPD_UNSPEC,
363 XFRMA_SPD_INFO,
364 XFRMA_SPD_HINFO,
365 XFRMA_SPD_IPV4_HTHRESH,
366 XFRMA_SPD_IPV6_HTHRESH,
367 __XFRMA_SPD_MAX
368
369#define XFRMA_SPD_MAX (__XFRMA_SPD_MAX - 1)
370};
371
372struct xfrmu_spdinfo {
373 __u32 incnt;
374 __u32 outcnt;
375 __u32 fwdcnt;
376 __u32 inscnt;
377 __u32 outscnt;
378 __u32 fwdscnt;
379};
380
381struct xfrmu_spdhinfo {
382 __u32 spdhcnt;
383 __u32 spdhmcnt;
384};
385
386struct xfrmu_spdhthresh {
387 __u8 lbits;
388 __u8 rbits;
389};
390
391struct xfrm_usersa_info {
392 struct xfrm_selector sel;
393 struct xfrm_id id;
394 xfrm_address_t saddr;
395 struct xfrm_lifetime_cfg lft;
396 struct xfrm_lifetime_cur curlft;
397 struct xfrm_stats stats;
398 __u32 seq;
399 __u32 reqid;
400 __u16 family;
401 __u8 mode; /* XFRM_MODE_xxx */
402 __u8 replay_window;
403 __u8 flags;
404#define XFRM_STATE_NOECN 1
405#define XFRM_STATE_DECAP_DSCP 2
406#define XFRM_STATE_NOPMTUDISC 4
407#define XFRM_STATE_WILDRECV 8
408#define XFRM_STATE_ICMP 16
409#define XFRM_STATE_AF_UNSPEC 32
410#define XFRM_STATE_ALIGN4 64
411#define XFRM_STATE_ESN 128
412};
413
414#define XFRM_SA_XFLAG_DONT_ENCAP_DSCP 1
415#define XFRM_SA_XFLAG_OSEQ_MAY_WRAP 2
416
417struct xfrm_usersa_id {
418 xfrm_address_t daddr;
419 __be32 spi;
420 __u16 family;
421 __u8 proto;
422};
423
424struct xfrm_aevent_id {
425 struct xfrm_usersa_id sa_id;
426 xfrm_address_t saddr;
427 __u32 flags;
428 __u32 reqid;
429};
430
431struct xfrm_userspi_info {
432 struct xfrm_usersa_info info;
433 __u32 min;
434 __u32 max;
435};
436
437struct xfrm_userpolicy_info {
438 struct xfrm_selector sel;
439 struct xfrm_lifetime_cfg lft;
440 struct xfrm_lifetime_cur curlft;
441 __u32 priority;
442 __u32 index;
443 __u8 dir;
444 __u8 action;
445#define XFRM_POLICY_ALLOW 0
446#define XFRM_POLICY_BLOCK 1
447 __u8 flags;
448#define XFRM_POLICY_LOCALOK 1 /* Allow user to override global policy */
449 /* Automatically expand selector to include matching ICMP payloads. */
450#define XFRM_POLICY_ICMP 2
451#define XFRM_POLICY_CPU_ACQUIRE 4
452 __u8 share;
453};
454
455struct xfrm_userpolicy_id {
456 struct xfrm_selector sel;
457 __u32 index;
458 __u8 dir;
459};
460
461struct xfrm_user_acquire {
462 struct xfrm_id id;
463 xfrm_address_t saddr;
464 struct xfrm_selector sel;
465 struct xfrm_userpolicy_info policy;
466 __u32 aalgos;
467 __u32 ealgos;
468 __u32 calgos;
469 __u32 seq;
470};
471
472struct xfrm_user_expire {
473 struct xfrm_usersa_info state;
474 __u8 hard;
475};
476
477struct xfrm_user_polexpire {
478 struct xfrm_userpolicy_info pol;
479 __u8 hard;
480};
481
482struct xfrm_usersa_flush {
483 __u8 proto;
484};
485
486struct xfrm_user_report {
487 __u8 proto;
488 struct xfrm_selector sel;
489};
490
491/* Used by MIGRATE to pass addresses IKE should use to perform
492 * SA negotiation with the peer */
493struct xfrm_user_kmaddress {
494 xfrm_address_t local;
495 xfrm_address_t remote;
496 __u32 reserved;
497 __u16 family;
498};
499
500struct xfrm_user_migrate {
501 xfrm_address_t old_daddr;
502 xfrm_address_t old_saddr;
503 xfrm_address_t new_daddr;
504 xfrm_address_t new_saddr;
505 __u8 proto;
506 __u8 mode;
507 __u16 reserved;
508 __u32 reqid;
509 __u16 old_family;
510 __u16 new_family;
511};
512
513struct xfrm_user_migrate_state {
514 struct xfrm_usersa_id id;
515 xfrm_address_t new_daddr;
516 xfrm_address_t new_saddr;
517 struct xfrm_mark old_mark;
518 struct xfrm_selector new_sel;
519 __u32 new_reqid;
520 __u32 flags;
521 __u16 new_family;
522 __u16 reserved;
523};
524
525/* Flags for xfrm_user_migrate_state.flags */
526enum xfrm_migrate_state_flags {
527 XFRM_MIGRATE_STATE_CLEAR_OFFLOAD = 1, /* do not inherit offload from existing SA */
528 XFRM_MIGRATE_STATE_UPDATE_H2H_SEL = 2, /* update H2H selector from new daddr/saddr */
529};
530
531/* All flags defined as of this header version; unknown bits are rejected. */
532#define XFRM_MIGRATE_STATE_KNOWN_FLAGS \
533 (XFRM_MIGRATE_STATE_CLEAR_OFFLOAD | XFRM_MIGRATE_STATE_UPDATE_H2H_SEL)
534
535struct xfrm_user_mapping {
536 struct xfrm_usersa_id id;
537 __u32 reqid;
538 xfrm_address_t old_saddr;
539 xfrm_address_t new_saddr;
540 __be16 old_sport;
541 __be16 new_sport;
542};
543
544struct xfrm_address_filter {
545 xfrm_address_t saddr;
546 xfrm_address_t daddr;
547 __u16 family;
548 __u8 splen;
549 __u8 dplen;
550};
551
552struct xfrm_user_offload {
553 int ifindex;
554 __u8 flags;
555};
556/* This flag was exposed without any kernel code that supports it.
557 * Unfortunately, strongswan has the code that sets this flag,
558 * which makes it impossible to reuse this bit.
559 *
560 * So leave it here to make sure that it won't be reused by mistake.
561 */
562#define XFRM_OFFLOAD_IPV6 1
563#define XFRM_OFFLOAD_INBOUND 2
564/* Two bits above are relevant for state path only, while
565 * offload is used for both policy and state flows.
566 *
567 * In policy offload mode, they are free and can be safely reused.
568 */
569#define XFRM_OFFLOAD_PACKET 4
570
571struct xfrm_userpolicy_default {
572#define XFRM_USERPOLICY_UNSPEC 0
573#define XFRM_USERPOLICY_BLOCK 1
574#define XFRM_USERPOLICY_ACCEPT 2
575 __u8 in;
576 __u8 fwd;
577 __u8 out;
578};
579
580/* backwards compatibility for userspace */
581#define XFRMGRP_ACQUIRE 1
582#define XFRMGRP_EXPIRE 2
583#define XFRMGRP_SA 4
584#define XFRMGRP_POLICY 8
585#define XFRMGRP_REPORT 0x20
586
587enum xfrm_nlgroups {
588 XFRMNLGRP_NONE,
589#define XFRMNLGRP_NONE XFRMNLGRP_NONE
590 XFRMNLGRP_ACQUIRE,
591#define XFRMNLGRP_ACQUIRE XFRMNLGRP_ACQUIRE
592 XFRMNLGRP_EXPIRE,
593#define XFRMNLGRP_EXPIRE XFRMNLGRP_EXPIRE
594 XFRMNLGRP_SA,
595#define XFRMNLGRP_SA XFRMNLGRP_SA
596 XFRMNLGRP_POLICY,
597#define XFRMNLGRP_POLICY XFRMNLGRP_POLICY
598 XFRMNLGRP_AEVENTS,
599#define XFRMNLGRP_AEVENTS XFRMNLGRP_AEVENTS
600 XFRMNLGRP_REPORT,
601#define XFRMNLGRP_REPORT XFRMNLGRP_REPORT
602 XFRMNLGRP_MIGRATE,
603#define XFRMNLGRP_MIGRATE XFRMNLGRP_MIGRATE
604 XFRMNLGRP_MAPPING,
605#define XFRMNLGRP_MAPPING XFRMNLGRP_MAPPING
606 __XFRMNLGRP_MAX
607};
608#define XFRMNLGRP_MAX (__XFRMNLGRP_MAX - 1)
609
610#endif /* _LINUX_XFRM_H */