xfrm.h 12 KB

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