xfrm.h 9.9 KB

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