xfrm.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. __u32 a4;
  13. __u32 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. __u32 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. __u16 dport;
  44. __u16 dport_mask;
  45. __u16 sport;
  46. __u16 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_IN = 0,
  92. XFRM_POLICY_OUT = 1,
  93. XFRM_POLICY_FWD = 2,
  94. XFRM_POLICY_MAX = 3
  95. };
  96. enum
  97. {
  98. XFRM_SHARE_ANY, /* No limitations */
  99. XFRM_SHARE_SESSION, /* For this session only */
  100. XFRM_SHARE_USER, /* For this user only */
  101. XFRM_SHARE_UNIQUE /* Use once */
  102. };
  103. #define XFRM_MODE_TRANSPORT 0
  104. #define XFRM_MODE_TUNNEL 1
  105. #define XFRM_MODE_ROUTEOPTIMIZATION 2
  106. #define XFRM_MODE_IN_TRIGGER 3
  107. #define XFRM_MODE_MAX 4
  108. /* Netlink configuration messages. */
  109. enum {
  110. XFRM_MSG_BASE = 0x10,
  111. XFRM_MSG_NEWSA = 0x10,
  112. #define XFRM_MSG_NEWSA XFRM_MSG_NEWSA
  113. XFRM_MSG_DELSA,
  114. #define XFRM_MSG_DELSA XFRM_MSG_DELSA
  115. XFRM_MSG_GETSA,
  116. #define XFRM_MSG_GETSA XFRM_MSG_GETSA
  117. XFRM_MSG_NEWPOLICY,
  118. #define XFRM_MSG_NEWPOLICY XFRM_MSG_NEWPOLICY
  119. XFRM_MSG_DELPOLICY,
  120. #define XFRM_MSG_DELPOLICY XFRM_MSG_DELPOLICY
  121. XFRM_MSG_GETPOLICY,
  122. #define XFRM_MSG_GETPOLICY XFRM_MSG_GETPOLICY
  123. XFRM_MSG_ALLOCSPI,
  124. #define XFRM_MSG_ALLOCSPI XFRM_MSG_ALLOCSPI
  125. XFRM_MSG_ACQUIRE,
  126. #define XFRM_MSG_ACQUIRE XFRM_MSG_ACQUIRE
  127. XFRM_MSG_EXPIRE,
  128. #define XFRM_MSG_EXPIRE XFRM_MSG_EXPIRE
  129. XFRM_MSG_UPDPOLICY,
  130. #define XFRM_MSG_UPDPOLICY XFRM_MSG_UPDPOLICY
  131. XFRM_MSG_UPDSA,
  132. #define XFRM_MSG_UPDSA XFRM_MSG_UPDSA
  133. XFRM_MSG_POLEXPIRE,
  134. #define XFRM_MSG_POLEXPIRE XFRM_MSG_POLEXPIRE
  135. XFRM_MSG_FLUSHSA,
  136. #define XFRM_MSG_FLUSHSA XFRM_MSG_FLUSHSA
  137. XFRM_MSG_FLUSHPOLICY,
  138. #define XFRM_MSG_FLUSHPOLICY XFRM_MSG_FLUSHPOLICY
  139. XFRM_MSG_NEWAE,
  140. #define XFRM_MSG_NEWAE XFRM_MSG_NEWAE
  141. XFRM_MSG_GETAE,
  142. #define XFRM_MSG_GETAE XFRM_MSG_GETAE
  143. XFRM_MSG_REPORT,
  144. #define XFRM_MSG_REPORT XFRM_MSG_REPORT
  145. __XFRM_MSG_MAX
  146. };
  147. #define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
  148. #define XFRM_NR_MSGTYPES (XFRM_MSG_MAX + 1 - XFRM_MSG_BASE)
  149. /*
  150. * Generic LSM security context for comunicating to user space
  151. * NOTE: Same format as sadb_x_sec_ctx
  152. */
  153. struct xfrm_user_sec_ctx {
  154. __u16 len;
  155. __u16 exttype;
  156. __u8 ctx_alg; /* LSMs: e.g., selinux == 1 */
  157. __u8 ctx_doi;
  158. __u16 ctx_len;
  159. };
  160. struct xfrm_user_tmpl {
  161. struct xfrm_id id;
  162. __u16 family;
  163. xfrm_address_t saddr;
  164. __u32 reqid;
  165. __u8 mode;
  166. __u8 share;
  167. __u8 optional;
  168. __u32 aalgos;
  169. __u32 ealgos;
  170. __u32 calgos;
  171. };
  172. struct xfrm_encap_tmpl {
  173. __u16 encap_type;
  174. __u16 encap_sport;
  175. __u16 encap_dport;
  176. xfrm_address_t encap_oa;
  177. };
  178. /* AEVENT flags */
  179. enum xfrm_ae_ftype_t {
  180. XFRM_AE_UNSPEC,
  181. XFRM_AE_RTHR=1, /* replay threshold*/
  182. XFRM_AE_RVAL=2, /* replay value */
  183. XFRM_AE_LVAL=4, /* lifetime value */
  184. XFRM_AE_ETHR=8, /* expiry timer threshold */
  185. XFRM_AE_CR=16, /* Event cause is replay update */
  186. XFRM_AE_CE=32, /* Event cause is timer expiry */
  187. XFRM_AE_CU=64, /* Event cause is policy update */
  188. __XFRM_AE_MAX
  189. #define XFRM_AE_MAX (__XFRM_AE_MAX - 1)
  190. };
  191. /* Netlink message attributes. */
  192. enum xfrm_attr_type_t {
  193. XFRMA_UNSPEC,
  194. XFRMA_ALG_AUTH, /* struct xfrm_algo */
  195. XFRMA_ALG_CRYPT, /* struct xfrm_algo */
  196. XFRMA_ALG_COMP, /* struct xfrm_algo */
  197. XFRMA_ENCAP, /* struct xfrm_algo + struct xfrm_encap_tmpl */
  198. XFRMA_TMPL, /* 1 or more struct xfrm_user_tmpl */
  199. XFRMA_SA,
  200. XFRMA_POLICY,
  201. XFRMA_SEC_CTX, /* struct xfrm_sec_ctx */
  202. XFRMA_LTIME_VAL,
  203. XFRMA_REPLAY_VAL,
  204. XFRMA_REPLAY_THRESH,
  205. XFRMA_ETIMER_THRESH,
  206. XFRMA_SRCADDR, /* xfrm_address_t */
  207. XFRMA_COADDR, /* xfrm_address_t */
  208. XFRMA_LASTUSED,
  209. __XFRMA_MAX
  210. #define XFRMA_MAX (__XFRMA_MAX - 1)
  211. };
  212. struct xfrm_usersa_info {
  213. struct xfrm_selector sel;
  214. struct xfrm_id id;
  215. xfrm_address_t saddr;
  216. struct xfrm_lifetime_cfg lft;
  217. struct xfrm_lifetime_cur curlft;
  218. struct xfrm_stats stats;
  219. __u32 seq;
  220. __u32 reqid;
  221. __u16 family;
  222. __u8 mode; /* XFRM_MODE_xxx */
  223. __u8 replay_window;
  224. __u8 flags;
  225. #define XFRM_STATE_NOECN 1
  226. #define XFRM_STATE_DECAP_DSCP 2
  227. #define XFRM_STATE_NOPMTUDISC 4
  228. #define XFRM_STATE_WILDRECV 8
  229. };
  230. struct xfrm_usersa_id {
  231. xfrm_address_t daddr;
  232. __u32 spi;
  233. __u16 family;
  234. __u8 proto;
  235. };
  236. struct xfrm_aevent_id {
  237. struct xfrm_usersa_id sa_id;
  238. __u32 flags;
  239. };
  240. struct xfrm_userspi_info {
  241. struct xfrm_usersa_info info;
  242. __u32 min;
  243. __u32 max;
  244. };
  245. struct xfrm_userpolicy_info {
  246. struct xfrm_selector sel;
  247. struct xfrm_lifetime_cfg lft;
  248. struct xfrm_lifetime_cur curlft;
  249. __u32 priority;
  250. __u32 index;
  251. __u8 dir;
  252. __u8 action;
  253. #define XFRM_POLICY_ALLOW 0
  254. #define XFRM_POLICY_BLOCK 1
  255. __u8 flags;
  256. #define XFRM_POLICY_LOCALOK 1 /* Allow user to override global policy */
  257. __u8 share;
  258. };
  259. struct xfrm_userpolicy_id {
  260. struct xfrm_selector sel;
  261. __u32 index;
  262. __u8 dir;
  263. };
  264. struct xfrm_user_acquire {
  265. struct xfrm_id id;
  266. xfrm_address_t saddr;
  267. struct xfrm_selector sel;
  268. struct xfrm_userpolicy_info policy;
  269. __u32 aalgos;
  270. __u32 ealgos;
  271. __u32 calgos;
  272. __u32 seq;
  273. };
  274. struct xfrm_user_expire {
  275. struct xfrm_usersa_info state;
  276. __u8 hard;
  277. };
  278. struct xfrm_user_polexpire {
  279. struct xfrm_userpolicy_info pol;
  280. __u8 hard;
  281. };
  282. struct xfrm_usersa_flush {
  283. __u8 proto;
  284. };
  285. struct xfrm_user_report {
  286. __u8 proto;
  287. struct xfrm_selector sel;
  288. };
  289. #ifndef __KERNEL__
  290. /* backwards compatibility for userspace */
  291. #define XFRMGRP_ACQUIRE 1
  292. #define XFRMGRP_EXPIRE 2
  293. #define XFRMGRP_SA 4
  294. #define XFRMGRP_POLICY 8
  295. #define XFRMGRP_REPORT 0x10
  296. #endif
  297. enum xfrm_nlgroups {
  298. XFRMNLGRP_NONE,
  299. #define XFRMNLGRP_NONE XFRMNLGRP_NONE
  300. XFRMNLGRP_ACQUIRE,
  301. #define XFRMNLGRP_ACQUIRE XFRMNLGRP_ACQUIRE
  302. XFRMNLGRP_EXPIRE,
  303. #define XFRMNLGRP_EXPIRE XFRMNLGRP_EXPIRE
  304. XFRMNLGRP_SA,
  305. #define XFRMNLGRP_SA XFRMNLGRP_SA
  306. XFRMNLGRP_POLICY,
  307. #define XFRMNLGRP_POLICY XFRMNLGRP_POLICY
  308. XFRMNLGRP_AEVENTS,
  309. #define XFRMNLGRP_AEVENTS XFRMNLGRP_AEVENTS
  310. XFRMNLGRP_REPORT,
  311. #define XFRMNLGRP_REPORT XFRMNLGRP_REPORT
  312. __XFRMNLGRP_MAX
  313. };
  314. #define XFRMNLGRP_MAX (__XFRMNLGRP_MAX - 1)
  315. #endif /* _LINUX_XFRM_H */