xfrm.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. {
  12. __be32 a4;
  13. __be32 a6[4];
  14. } xfrm_address_t;
  15. /* Ident of a specific xfrm_state. It is used on input to lookup
  16. * the state by (spi,daddr,ah/esp) or to store information about
  17. * spi, protocol and tunnel address on output.
  18. */
  19. struct xfrm_id
  20. {
  21. xfrm_address_t daddr;
  22. __be32 spi;
  23. __u8 proto;
  24. };
  25. struct xfrm_sec_ctx {
  26. __u8 ctx_doi;
  27. __u8 ctx_alg;
  28. __u16 ctx_len;
  29. __u32 ctx_sid;
  30. char ctx_str[0];
  31. };
  32. /* Security Context Domains of Interpretation */
  33. #define XFRM_SC_DOI_RESERVED 0
  34. #define XFRM_SC_DOI_LSM 1
  35. /* Security Context Algorithms */
  36. #define XFRM_SC_ALG_RESERVED 0
  37. #define XFRM_SC_ALG_SELINUX 1
  38. /* Selector, used as selector both on policy rules (SPD) and SAs. */
  39. struct xfrm_selector
  40. {
  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. uid_t user;
  53. };
  54. #define XFRM_INF (~(__u64)0)
  55. struct xfrm_lifetime_cfg
  56. {
  57. __u64 soft_byte_limit;
  58. __u64 hard_byte_limit;
  59. __u64 soft_packet_limit;
  60. __u64 hard_packet_limit;
  61. __u64 soft_add_expires_seconds;
  62. __u64 hard_add_expires_seconds;
  63. __u64 soft_use_expires_seconds;
  64. __u64 hard_use_expires_seconds;
  65. };
  66. struct xfrm_lifetime_cur
  67. {
  68. __u64 bytes;
  69. __u64 packets;
  70. __u64 add_time;
  71. __u64 use_time;
  72. };
  73. struct xfrm_replay_state
  74. {
  75. __u32 oseq;
  76. __u32 seq;
  77. __u32 bitmap;
  78. };
  79. struct xfrm_algo {
  80. char alg_name[64];
  81. int alg_key_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. {
  91. XFRM_POLICY_TYPE_MAIN = 0,
  92. XFRM_POLICY_TYPE_SUB = 1,
  93. XFRM_POLICY_TYPE_MAX = 2
  94. };
  95. enum
  96. {
  97. XFRM_POLICY_IN = 0,
  98. XFRM_POLICY_OUT = 1,
  99. XFRM_POLICY_FWD = 2,
  100. XFRM_POLICY_MAX = 3
  101. };
  102. enum
  103. {
  104. XFRM_SHARE_ANY, /* No limitations */
  105. XFRM_SHARE_SESSION, /* For this session only */
  106. XFRM_SHARE_USER, /* For this user only */
  107. XFRM_SHARE_UNIQUE /* Use once */
  108. };
  109. #define XFRM_MODE_TRANSPORT 0
  110. #define XFRM_MODE_TUNNEL 1
  111. #define XFRM_MODE_ROUTEOPTIMIZATION 2
  112. #define XFRM_MODE_IN_TRIGGER 3
  113. #define XFRM_MODE_BEET 4
  114. #define XFRM_MODE_MAX 5
  115. /* Netlink configuration messages. */
  116. enum {
  117. XFRM_MSG_BASE = 0x10,
  118. XFRM_MSG_NEWSA = 0x10,
  119. #define XFRM_MSG_NEWSA XFRM_MSG_NEWSA
  120. XFRM_MSG_DELSA,
  121. #define XFRM_MSG_DELSA XFRM_MSG_DELSA
  122. XFRM_MSG_GETSA,
  123. #define XFRM_MSG_GETSA XFRM_MSG_GETSA
  124. XFRM_MSG_NEWPOLICY,
  125. #define XFRM_MSG_NEWPOLICY XFRM_MSG_NEWPOLICY
  126. XFRM_MSG_DELPOLICY,
  127. #define XFRM_MSG_DELPOLICY XFRM_MSG_DELPOLICY
  128. XFRM_MSG_GETPOLICY,
  129. #define XFRM_MSG_GETPOLICY XFRM_MSG_GETPOLICY
  130. XFRM_MSG_ALLOCSPI,
  131. #define XFRM_MSG_ALLOCSPI XFRM_MSG_ALLOCSPI
  132. XFRM_MSG_ACQUIRE,
  133. #define XFRM_MSG_ACQUIRE XFRM_MSG_ACQUIRE
  134. XFRM_MSG_EXPIRE,
  135. #define XFRM_MSG_EXPIRE XFRM_MSG_EXPIRE
  136. XFRM_MSG_UPDPOLICY,
  137. #define XFRM_MSG_UPDPOLICY XFRM_MSG_UPDPOLICY
  138. XFRM_MSG_UPDSA,
  139. #define XFRM_MSG_UPDSA XFRM_MSG_UPDSA
  140. XFRM_MSG_POLEXPIRE,
  141. #define XFRM_MSG_POLEXPIRE XFRM_MSG_POLEXPIRE
  142. XFRM_MSG_FLUSHSA,
  143. #define XFRM_MSG_FLUSHSA XFRM_MSG_FLUSHSA
  144. XFRM_MSG_FLUSHPOLICY,
  145. #define XFRM_MSG_FLUSHPOLICY XFRM_MSG_FLUSHPOLICY
  146. XFRM_MSG_NEWAE,
  147. #define XFRM_MSG_NEWAE XFRM_MSG_NEWAE
  148. XFRM_MSG_GETAE,
  149. #define XFRM_MSG_GETAE XFRM_MSG_GETAE
  150. XFRM_MSG_REPORT,
  151. #define XFRM_MSG_REPORT XFRM_MSG_REPORT
  152. XFRM_MSG_MIGRATE,
  153. #define XFRM_MSG_MIGRATE XFRM_MSG_MIGRATE
  154. XFRM_MSG_NEWSADINFO,
  155. #define XFRM_MSG_NEWSADINFO XFRM_MSG_NEWSADINFO
  156. XFRM_MSG_GETSADINFO,
  157. #define XFRM_MSG_GETSADINFO XFRM_MSG_GETSADINFO
  158. XFRM_MSG_NEWSPDINFO,
  159. #define XFRM_MSG_NEWSPDINFO XFRM_MSG_NEWSPDINFO
  160. XFRM_MSG_GETSPDINFO,
  161. #define XFRM_MSG_GETSPDINFO XFRM_MSG_GETSPDINFO
  162. __XFRM_MSG_MAX
  163. };
  164. #define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
  165. #define XFRM_NR_MSGTYPES (XFRM_MSG_MAX + 1 - XFRM_MSG_BASE)
  166. /*
  167. * Generic LSM security context for comunicating to user space
  168. * NOTE: Same format as sadb_x_sec_ctx
  169. */
  170. struct xfrm_user_sec_ctx {
  171. __u16 len;
  172. __u16 exttype;
  173. __u8 ctx_alg; /* LSMs: e.g., selinux == 1 */
  174. __u8 ctx_doi;
  175. __u16 ctx_len;
  176. };
  177. struct xfrm_user_tmpl {
  178. struct xfrm_id id;
  179. __u16 family;
  180. xfrm_address_t saddr;
  181. __u32 reqid;
  182. __u8 mode;
  183. __u8 share;
  184. __u8 optional;
  185. __u32 aalgos;
  186. __u32 ealgos;
  187. __u32 calgos;
  188. };
  189. struct xfrm_encap_tmpl {
  190. __u16 encap_type;
  191. __be16 encap_sport;
  192. __be16 encap_dport;
  193. xfrm_address_t encap_oa;
  194. };
  195. /* AEVENT flags */
  196. enum xfrm_ae_ftype_t {
  197. XFRM_AE_UNSPEC,
  198. XFRM_AE_RTHR=1, /* replay threshold*/
  199. XFRM_AE_RVAL=2, /* replay value */
  200. XFRM_AE_LVAL=4, /* lifetime value */
  201. XFRM_AE_ETHR=8, /* expiry timer threshold */
  202. XFRM_AE_CR=16, /* Event cause is replay update */
  203. XFRM_AE_CE=32, /* Event cause is timer expiry */
  204. XFRM_AE_CU=64, /* Event cause is policy update */
  205. __XFRM_AE_MAX
  206. #define XFRM_AE_MAX (__XFRM_AE_MAX - 1)
  207. };
  208. /* SAD Table filter flags */
  209. enum xfrm_sad_ftype_t {
  210. XFRM_SAD_UNSPEC,
  211. XFRM_SAD_HMASK=1,
  212. XFRM_SAD_HMAX=2,
  213. XFRM_SAD_CNT=4,
  214. __XFRM_SAD_MAX
  215. #define XFRM_SAD_MAX (__XFRM_SAD_MAX - 1)
  216. };
  217. struct xfrm_userpolicy_type {
  218. __u8 type;
  219. __u16 reserved1;
  220. __u8 reserved2;
  221. };
  222. /* Netlink message attributes. */
  223. enum xfrm_attr_type_t {
  224. XFRMA_UNSPEC,
  225. XFRMA_ALG_AUTH, /* struct xfrm_algo */
  226. XFRMA_ALG_CRYPT, /* struct xfrm_algo */
  227. XFRMA_ALG_COMP, /* struct xfrm_algo */
  228. XFRMA_ENCAP, /* struct xfrm_algo + struct xfrm_encap_tmpl */
  229. XFRMA_TMPL, /* 1 or more struct xfrm_user_tmpl */
  230. XFRMA_SA,
  231. XFRMA_POLICY,
  232. XFRMA_SEC_CTX, /* struct xfrm_sec_ctx */
  233. XFRMA_LTIME_VAL,
  234. XFRMA_REPLAY_VAL,
  235. XFRMA_REPLAY_THRESH,
  236. XFRMA_ETIMER_THRESH,
  237. XFRMA_SRCADDR, /* xfrm_address_t */
  238. XFRMA_COADDR, /* xfrm_address_t */
  239. XFRMA_LASTUSED,
  240. XFRMA_POLICY_TYPE, /* struct xfrm_userpolicy_type */
  241. XFRMA_MIGRATE,
  242. __XFRMA_MAX
  243. #define XFRMA_MAX (__XFRMA_MAX - 1)
  244. };
  245. enum xfrm_sadattr_type_t {
  246. XFRMA_SAD_UNSPEC,
  247. XFRMA_SADHMASK,
  248. XFRMA_SADHMAX,
  249. XFRMA_SADCNT,
  250. __XFRMA_SAD_MAX
  251. #define XFRMA_SAD_MAX (__XFRMA_SAD_MAX - 1)
  252. };
  253. /* SPD Table filter flags */
  254. enum xfrm_spd_ftype_t {
  255. XFRM_SPD_UNSPEC,
  256. XFRM_SPD_HMASK=1,
  257. XFRM_SPD_HMAX=2,
  258. XFRM_SPD_ICNT=4,
  259. XFRM_SPD_OCNT=8,
  260. XFRM_SPD_FCNT=16,
  261. XFRM_SPD_ISCNT=32,
  262. XFRM_SPD_OSCNT=64,
  263. XFRM_SPD_FSCNT=128,
  264. __XFRM_SPD_MAX
  265. #define XFRM_SPD_MAX (__XFRM_SPD_MAX - 1)
  266. };
  267. enum xfrm_spdattr_type_t {
  268. XFRMA_SPD_UNSPEC,
  269. XFRMA_SPDHMASK,
  270. XFRMA_SPDHMAX,
  271. XFRMA_SPDICNT,
  272. XFRMA_SPDOCNT,
  273. XFRMA_SPDFCNT,
  274. XFRMA_SPDISCNT,
  275. XFRMA_SPDOSCNT,
  276. XFRMA_SPDFSCNT,
  277. __XFRMA_SPD_MAX
  278. #define XFRMA_SPD_MAX (__XFRMA_SPD_MAX - 1)
  279. };
  280. struct xfrm_usersa_info {
  281. struct xfrm_selector sel;
  282. struct xfrm_id id;
  283. xfrm_address_t saddr;
  284. struct xfrm_lifetime_cfg lft;
  285. struct xfrm_lifetime_cur curlft;
  286. struct xfrm_stats stats;
  287. __u32 seq;
  288. __u32 reqid;
  289. __u16 family;
  290. __u8 mode; /* XFRM_MODE_xxx */
  291. __u8 replay_window;
  292. __u8 flags;
  293. #define XFRM_STATE_NOECN 1
  294. #define XFRM_STATE_DECAP_DSCP 2
  295. #define XFRM_STATE_NOPMTUDISC 4
  296. #define XFRM_STATE_WILDRECV 8
  297. };
  298. struct xfrm_usersa_id {
  299. xfrm_address_t daddr;
  300. __be32 spi;
  301. __u16 family;
  302. __u8 proto;
  303. };
  304. struct xfrm_aevent_id {
  305. struct xfrm_usersa_id sa_id;
  306. xfrm_address_t saddr;
  307. __u32 flags;
  308. __u32 reqid;
  309. };
  310. struct xfrm_userspi_info {
  311. struct xfrm_usersa_info info;
  312. __u32 min;
  313. __u32 max;
  314. };
  315. struct xfrm_userpolicy_info {
  316. struct xfrm_selector sel;
  317. struct xfrm_lifetime_cfg lft;
  318. struct xfrm_lifetime_cur curlft;
  319. __u32 priority;
  320. __u32 index;
  321. __u8 dir;
  322. __u8 action;
  323. #define XFRM_POLICY_ALLOW 0
  324. #define XFRM_POLICY_BLOCK 1
  325. __u8 flags;
  326. #define XFRM_POLICY_LOCALOK 1 /* Allow user to override global policy */
  327. __u8 share;
  328. };
  329. struct xfrm_userpolicy_id {
  330. struct xfrm_selector sel;
  331. __u32 index;
  332. __u8 dir;
  333. };
  334. struct xfrm_user_acquire {
  335. struct xfrm_id id;
  336. xfrm_address_t saddr;
  337. struct xfrm_selector sel;
  338. struct xfrm_userpolicy_info policy;
  339. __u32 aalgos;
  340. __u32 ealgos;
  341. __u32 calgos;
  342. __u32 seq;
  343. };
  344. struct xfrm_user_expire {
  345. struct xfrm_usersa_info state;
  346. __u8 hard;
  347. };
  348. struct xfrm_user_polexpire {
  349. struct xfrm_userpolicy_info pol;
  350. __u8 hard;
  351. };
  352. struct xfrm_usersa_flush {
  353. __u8 proto;
  354. };
  355. struct xfrm_user_report {
  356. __u8 proto;
  357. struct xfrm_selector sel;
  358. };
  359. struct xfrm_user_migrate {
  360. xfrm_address_t old_daddr;
  361. xfrm_address_t old_saddr;
  362. xfrm_address_t new_daddr;
  363. xfrm_address_t new_saddr;
  364. __u8 proto;
  365. __u8 mode;
  366. __u16 reserved;
  367. __u32 reqid;
  368. __u16 old_family;
  369. __u16 new_family;
  370. };
  371. #ifndef __KERNEL__
  372. /* backwards compatibility for userspace */
  373. #define XFRMGRP_ACQUIRE 1
  374. #define XFRMGRP_EXPIRE 2
  375. #define XFRMGRP_SA 4
  376. #define XFRMGRP_POLICY 8
  377. #define XFRMGRP_REPORT 0x20
  378. #endif
  379. enum xfrm_nlgroups {
  380. XFRMNLGRP_NONE,
  381. #define XFRMNLGRP_NONE XFRMNLGRP_NONE
  382. XFRMNLGRP_ACQUIRE,
  383. #define XFRMNLGRP_ACQUIRE XFRMNLGRP_ACQUIRE
  384. XFRMNLGRP_EXPIRE,
  385. #define XFRMNLGRP_EXPIRE XFRMNLGRP_EXPIRE
  386. XFRMNLGRP_SA,
  387. #define XFRMNLGRP_SA XFRMNLGRP_SA
  388. XFRMNLGRP_POLICY,
  389. #define XFRMNLGRP_POLICY XFRMNLGRP_POLICY
  390. XFRMNLGRP_AEVENTS,
  391. #define XFRMNLGRP_AEVENTS XFRMNLGRP_AEVENTS
  392. XFRMNLGRP_REPORT,
  393. #define XFRMNLGRP_REPORT XFRMNLGRP_REPORT
  394. XFRMNLGRP_MIGRATE,
  395. #define XFRMNLGRP_MIGRATE XFRMNLGRP_MIGRATE
  396. __XFRMNLGRP_MAX
  397. };
  398. #define XFRMNLGRP_MAX (__XFRMNLGRP_MAX - 1)
  399. #endif /* _LINUX_XFRM_H */