pfkeyv2.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /* $OpenBSD: pfkeyv2.h,v 1.69 2015/05/23 12:38:53 markus Exp $ */
  2. /*
  3. * @(#)COPYRIGHT 1.1 (NRL) January 1998
  4. *
  5. * NRL grants permission for redistribution and use in source and binary
  6. * forms, with or without modification, of the software and documentation
  7. * created at NRL provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. All advertising materials mentioning features or use of this software
  15. * must display the following acknowledgements:
  16. * This product includes software developed by the University of
  17. * California, Berkeley and its contributors.
  18. * This product includes software developed at the Information
  19. * Technology Division, US Naval Research Laboratory.
  20. * 4. Neither the name of the NRL nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS
  25. * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  26. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  27. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NRL OR
  28. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. * The views and conclusions contained in the software and documentation
  37. * are those of the authors and should not be interpreted as representing
  38. * official policies, either expressed or implied, of the US Naval
  39. * Research Laboratory (NRL).
  40. */
  41. #ifndef _NET_PFKEY_V2_H_
  42. #define _NET_PFKEY_V2_H_
  43. #define PF_KEY_V2 2
  44. #define PFKEYV2_REVISION 199806L
  45. /* This should be updated whenever the API is altered. */
  46. #define _OPENBSD_IPSEC_API_VERSION 2
  47. #define SADB_RESERVED 0
  48. #define SADB_GETSPI 1
  49. #define SADB_UPDATE 2
  50. #define SADB_ADD 3
  51. #define SADB_DELETE 4
  52. #define SADB_GET 5
  53. #define SADB_ACQUIRE 6
  54. #define SADB_REGISTER 7
  55. #define SADB_EXPIRE 8
  56. #define SADB_FLUSH 9
  57. #define SADB_DUMP 10
  58. #define SADB_X_PROMISC 11
  59. #define SADB_X_ADDFLOW 12
  60. #define SADB_X_DELFLOW 13
  61. #define SADB_X_GRPSPIS 14
  62. #define SADB_X_ASKPOLICY 15
  63. #define SADB_X_SPDDUMP 16
  64. #define SADB_MAX 16
  65. struct sadb_msg {
  66. uint8_t sadb_msg_version;
  67. uint8_t sadb_msg_type;
  68. uint8_t sadb_msg_errno;
  69. uint8_t sadb_msg_satype;
  70. uint16_t sadb_msg_len;
  71. uint16_t sadb_msg_reserved;
  72. uint32_t sadb_msg_seq;
  73. uint32_t sadb_msg_pid;
  74. };
  75. struct sadb_ext {
  76. uint16_t sadb_ext_len;
  77. uint16_t sadb_ext_type;
  78. };
  79. struct sadb_sa {
  80. uint16_t sadb_sa_len;
  81. uint16_t sadb_sa_exttype;
  82. uint32_t sadb_sa_spi;
  83. uint8_t sadb_sa_replay;
  84. uint8_t sadb_sa_state;
  85. uint8_t sadb_sa_auth;
  86. uint8_t sadb_sa_encrypt;
  87. uint32_t sadb_sa_flags;
  88. };
  89. struct sadb_lifetime {
  90. uint16_t sadb_lifetime_len;
  91. uint16_t sadb_lifetime_exttype;
  92. uint32_t sadb_lifetime_allocations;
  93. uint64_t sadb_lifetime_bytes;
  94. uint64_t sadb_lifetime_addtime;
  95. uint64_t sadb_lifetime_usetime;
  96. };
  97. struct sadb_address {
  98. uint16_t sadb_address_len;
  99. uint16_t sadb_address_exttype;
  100. uint32_t sadb_address_reserved;
  101. };
  102. struct sadb_key {
  103. uint16_t sadb_key_len;
  104. uint16_t sadb_key_exttype;
  105. uint16_t sadb_key_bits;
  106. uint16_t sadb_key_reserved;
  107. };
  108. struct sadb_ident {
  109. uint16_t sadb_ident_len;
  110. uint16_t sadb_ident_exttype;
  111. uint16_t sadb_ident_type;
  112. uint16_t sadb_ident_reserved;
  113. uint64_t sadb_ident_id;
  114. };
  115. struct sadb_sens {
  116. uint16_t sadb_sens_len;
  117. uint16_t sadb_sens_exttype;
  118. uint32_t sadb_sens_dpd;
  119. uint8_t sadb_sens_sens_level;
  120. uint8_t sadb_sens_sens_len;
  121. uint8_t sadb_sens_integ_level;
  122. uint8_t sadb_sens_integ_len;
  123. uint32_t sadb_sens_reserved;
  124. };
  125. struct sadb_prop {
  126. uint16_t sadb_prop_len;
  127. uint16_t sadb_prop_exttype;
  128. uint8_t sadb_prop_num;
  129. uint8_t sadb_prop_replay;
  130. uint16_t sadb_prop_reserved;
  131. };
  132. struct sadb_comb {
  133. uint8_t sadb_comb_auth;
  134. uint8_t sadb_comb_encrypt;
  135. uint16_t sadb_comb_flags;
  136. uint16_t sadb_comb_auth_minbits;
  137. uint16_t sadb_comb_auth_maxbits;
  138. uint16_t sadb_comb_encrypt_minbits;
  139. uint16_t sadb_comb_encrypt_maxbits;
  140. uint32_t sadb_comb_reserved;
  141. uint32_t sadb_comb_soft_allocations;
  142. uint32_t sadb_comb_hard_allocations;
  143. uint64_t sadb_comb_soft_bytes;
  144. uint64_t sadb_comb_hard_bytes;
  145. uint64_t sadb_comb_soft_addtime;
  146. uint64_t sadb_comb_hard_addtime;
  147. uint64_t sadb_comb_soft_usetime;
  148. uint64_t sadb_comb_hard_usetime;
  149. };
  150. struct sadb_supported {
  151. uint16_t sadb_supported_len;
  152. uint16_t sadb_supported_exttype;
  153. uint32_t sadb_supported_reserved;
  154. };
  155. struct sadb_alg {
  156. uint8_t sadb_alg_id;
  157. uint8_t sadb_alg_ivlen;
  158. uint16_t sadb_alg_minbits;
  159. uint16_t sadb_alg_maxbits;
  160. uint16_t sadb_alg_reserved;
  161. };
  162. struct sadb_spirange {
  163. uint16_t sadb_spirange_len;
  164. uint16_t sadb_spirange_exttype;
  165. uint32_t sadb_spirange_min;
  166. uint32_t sadb_spirange_max;
  167. uint32_t sadb_spirange_reserved;
  168. };
  169. struct sadb_protocol {
  170. uint16_t sadb_protocol_len;
  171. uint16_t sadb_protocol_exttype;
  172. uint8_t sadb_protocol_proto;
  173. uint8_t sadb_protocol_direction;
  174. uint8_t sadb_protocol_flags;
  175. uint8_t sadb_protocol_reserved2;
  176. };
  177. struct sadb_x_policy {
  178. uint16_t sadb_x_policy_len;
  179. uint16_t sadb_x_policy_exttype;
  180. u_int32_t sadb_x_policy_seq;
  181. };
  182. struct sadb_x_udpencap {
  183. uint16_t sadb_x_udpencap_len;
  184. uint16_t sadb_x_udpencap_exttype;
  185. uint16_t sadb_x_udpencap_port;
  186. uint16_t sadb_x_udpencap_reserved;
  187. };
  188. struct sadb_x_tag {
  189. uint16_t sadb_x_tag_len;
  190. uint16_t sadb_x_tag_exttype;
  191. u_int32_t sadb_x_tag_taglen;
  192. };
  193. struct sadb_x_tap {
  194. uint16_t sadb_x_tap_len;
  195. uint16_t sadb_x_tap_exttype;
  196. u_int32_t sadb_x_tap_unit;
  197. };
  198. #ifdef _KERNEL
  199. #define SADB_X_GETSPROTO(x) \
  200. ( (x) == SADB_SATYPE_AH ? IPPROTO_AH :\
  201. (x) == SADB_SATYPE_ESP ? IPPROTO_ESP :\
  202. (x) == SADB_X_SATYPE_TCPSIGNATURE ? IPPROTO_TCP :\
  203. (x) == SADB_X_SATYPE_IPCOMP ? IPPROTO_IPCOMP: IPPROTO_IPIP )
  204. #endif
  205. #define SADB_EXT_RESERVED 0
  206. #define SADB_EXT_SA 1
  207. #define SADB_EXT_LIFETIME_CURRENT 2
  208. #define SADB_EXT_LIFETIME_HARD 3
  209. #define SADB_EXT_LIFETIME_SOFT 4
  210. #define SADB_EXT_ADDRESS_SRC 5
  211. #define SADB_EXT_ADDRESS_DST 6
  212. #define SADB_EXT_ADDRESS_PROXY 7
  213. #define SADB_EXT_KEY_AUTH 8
  214. #define SADB_EXT_KEY_ENCRYPT 9
  215. #define SADB_EXT_IDENTITY_SRC 10
  216. #define SADB_EXT_IDENTITY_DST 11
  217. #define SADB_EXT_SENSITIVITY 12
  218. #define SADB_EXT_PROPOSAL 13
  219. #define SADB_EXT_SUPPORTED_AUTH 14
  220. #define SADB_EXT_SUPPORTED_ENCRYPT 15
  221. #define SADB_EXT_SPIRANGE 16
  222. #define SADB_X_EXT_SRC_MASK 17
  223. #define SADB_X_EXT_DST_MASK 18
  224. #define SADB_X_EXT_PROTOCOL 19
  225. #define SADB_X_EXT_FLOW_TYPE 20
  226. #define SADB_X_EXT_SRC_FLOW 21
  227. #define SADB_X_EXT_DST_FLOW 22
  228. #define SADB_X_EXT_SA2 23
  229. #define SADB_X_EXT_DST2 24
  230. #define SADB_X_EXT_POLICY 25
  231. #define SADB_X_EXT_LOCAL_CREDENTIALS 26
  232. #define SADB_X_EXT_REMOTE_CREDENTIALS 27
  233. #define SADB_X_EXT_LOCAL_AUTH 28
  234. #define SADB_X_EXT_REMOTE_AUTH 29
  235. #define SADB_X_EXT_SUPPORTED_COMP 30
  236. #define SADB_X_EXT_UDPENCAP 31
  237. #define SADB_X_EXT_LIFETIME_LASTUSE 32
  238. #define SADB_X_EXT_TAG 33
  239. #define SADB_X_EXT_TAP 34
  240. #define SADB_EXT_MAX 34
  241. /* Fix pfkeyv2.c struct pfkeyv2_socket if SATYPE_MAX > 31 */
  242. #define SADB_SATYPE_UNSPEC 0
  243. #define SADB_SATYPE_AH 1
  244. #define SADB_SATYPE_ESP 2
  245. #define SADB_SATYPE_RSVP 3
  246. #define SADB_SATYPE_OSPFV2 4
  247. #define SADB_SATYPE_RIPV2 5
  248. #define SADB_SATYPE_MIP 6
  249. #define SADB_X_SATYPE_IPIP 7
  250. #define SADB_X_SATYPE_TCPSIGNATURE 8
  251. #define SADB_X_SATYPE_IPCOMP 9
  252. #define SADB_SATYPE_MAX 9
  253. #define SADB_SASTATE_LARVAL 0
  254. #define SADB_SASTATE_MATURE 1
  255. #define SADB_SASTATE_DYING 2
  256. #define SADB_SASTATE_DEAD 3
  257. #define SADB_SASTATE_MAX 3
  258. #define SADB_AALG_NONE 0
  259. #define SADB_AALG_MD5HMAC 2
  260. #define SADB_AALG_SHA1HMAC 3
  261. #define SADB_X_AALG_DES 4
  262. #define SADB_X_AALG_SHA2_256 5
  263. #define SADB_X_AALG_SHA2_384 6
  264. #define SADB_X_AALG_SHA2_512 7
  265. #define SADB_X_AALG_RIPEMD160HMAC 8
  266. #define SADB_X_AALG_AES128GMAC 9
  267. #define SADB_X_AALG_AES192GMAC 10
  268. #define SADB_X_AALG_AES256GMAC 11
  269. #define SADB_AALG_MAX 11
  270. #define SADB_EALG_NONE 0
  271. #define SADB_X_EALG_DES_IV64 1
  272. #define SADB_EALG_DESCBC 2
  273. #define SADB_EALG_3DESCBC 3
  274. #define SADB_X_EALG_RC5 4
  275. #define SADB_X_EALG_IDEA 5
  276. #define SADB_X_EALG_CAST 6
  277. #define SADB_X_EALG_BLF 7
  278. #define SADB_X_EALG_3IDEA 8
  279. #define SADB_X_EALG_DES_IV32 9
  280. #define SADB_X_EALG_RC4 10
  281. #define SADB_EALG_NULL 11
  282. #define SADB_X_EALG_AES 12
  283. #define SADB_X_EALG_AESCTR 13
  284. #define SADB_X_EALG_AESGCM8 18
  285. #define SADB_X_EALG_AESGCM12 19
  286. #define SADB_X_EALG_AESGCM16 20
  287. #define SADB_X_EALG_AESGMAC 21
  288. #define SADB_EALG_MAX 21
  289. #define SADB_X_CALG_NONE 0
  290. #define SADB_X_CALG_OUI 1
  291. #define SADB_X_CALG_DEFLATE 2
  292. #define SADB_X_CALG_LZS 3
  293. #define SADB_X_CALG_MAX 3
  294. #define SADB_SAFLAGS_PFS 0x001 /* perfect forward secrecy */
  295. #define SADB_X_SAFLAGS_TUNNEL 0x004 /* Force tunneling */
  296. #define SADB_X_SAFLAGS_CHAINDEL 0x008 /* Delete whole SA chain */
  297. #define SADB_X_SAFLAGS_UDPENCAP 0x200 /* ESP in UDP */
  298. #define SADB_X_SAFLAGS_ESN 0x400 /* Extended Sequence Number */
  299. #define SADB_X_POLICYFLAGS_POLICY 0x0001 /* This is a static policy */
  300. #define SADB_IDENTTYPE_RESERVED 0
  301. #define SADB_IDENTTYPE_PREFIX 1
  302. #define SADB_IDENTTYPE_FQDN 2
  303. #define SADB_IDENTTYPE_USERFQDN 3
  304. #define SADB_IDENTTYPE_MAX 3
  305. #define SADB_KEY_FLAGS_MAX 0
  306. #ifdef _KERNEL
  307. #define PFKEYV2_LIFETIME_HARD 0
  308. #define PFKEYV2_LIFETIME_SOFT 1
  309. #define PFKEYV2_LIFETIME_CURRENT 2
  310. #define PFKEYV2_LIFETIME_LASTUSE 3
  311. #define PFKEYV2_IDENTITY_SRC 0
  312. #define PFKEYV2_IDENTITY_DST 1
  313. #define PFKEYV2_ENCRYPTION_KEY 0
  314. #define PFKEYV2_AUTHENTICATION_KEY 1
  315. #define PFKEYV2_SOCKETFLAGS_REGISTERED 1
  316. #define PFKEYV2_SOCKETFLAGS_PROMISC 2
  317. #define PFKEYV2_SENDMESSAGE_UNICAST 1
  318. #define PFKEYV2_SENDMESSAGE_REGISTERED 2
  319. #define PFKEYV2_SENDMESSAGE_BROADCAST 3
  320. #endif /* _KERNEL */
  321. #define SADB_X_FLOW_TYPE_USE 1
  322. #define SADB_X_FLOW_TYPE_ACQUIRE 2
  323. #define SADB_X_FLOW_TYPE_REQUIRE 3
  324. #define SADB_X_FLOW_TYPE_BYPASS 4
  325. #define SADB_X_FLOW_TYPE_DENY 5
  326. #define SADB_X_FLOW_TYPE_DONTACQ 6
  327. #ifdef _KERNEL
  328. struct tdb;
  329. struct socket;
  330. struct mbuf;
  331. #define EXTLEN(x) (((struct sadb_ext *)(x))->sadb_ext_len * sizeof(uint64_t))
  332. #define PADUP(x) (((x) + sizeof(uint64_t) - 1) & ~(sizeof(uint64_t) - 1))
  333. struct pfkey_version {
  334. int protocol;
  335. int (*create)(struct socket *socket);
  336. int (*release)(struct socket *socket);
  337. int (*send)(struct socket *socket, void *message, int len);
  338. int (*sysctl)(int *, u_int, void *, size_t *, void *, size_t);
  339. };
  340. struct pfkeyv2_socket {
  341. struct pfkeyv2_socket *next;
  342. struct socket *socket;
  343. int flags;
  344. uint32_t pid;
  345. uint32_t registration; /* Increase size if SATYPE_MAX > 31 */
  346. uint rdomain;
  347. };
  348. struct dump_state {
  349. struct sadb_msg *sadb_msg;
  350. struct socket *socket;
  351. };
  352. int pfkeyv2_init(void);
  353. int pfkeyv2_cleanup(void);
  354. int pfkeyv2_parsemessage(void *, int, void **);
  355. int pfkeyv2_expire(struct tdb *, u_int16_t);
  356. int pfkeyv2_acquire(struct ipsec_policy *, union sockaddr_union *,
  357. union sockaddr_union *, u_int32_t *, struct sockaddr_encap *);
  358. int pfkey_register(struct pfkey_version *version);
  359. int pfkey_unregister(struct pfkey_version *version);
  360. int pfkey_sendup(struct socket *socket, struct mbuf *packet, int more);
  361. int pfkeyv2_create(struct socket *);
  362. int pfkeyv2_get(struct tdb *, void **, void **, int *);
  363. int pfkeyv2_policy(struct ipsec_acquire *, void **, void **);
  364. int pfkeyv2_release(struct socket *);
  365. int pfkeyv2_send(struct socket *, void *, int);
  366. int pfkeyv2_sendmessage(void **, int, struct socket *, u_int8_t, int, u_int);
  367. int pfkeyv2_dump_policy(struct ipsec_policy *, void **, void **, int *);
  368. int pfkeyv2_dump_walker(struct tdb *, void *, int);
  369. int pfkeyv2_flush_walker(struct tdb *, void *, int);
  370. int pfkeyv2_get_proto_alg(u_int8_t, u_int8_t *, int *);
  371. int pfkeyv2_sysctl(int *, u_int, void *, size_t *, void *, size_t);
  372. int pfkeyv2_sysctl_walker(struct tdb *, void *, int);
  373. int pfkeyv2_ipo_walk(u_int, int (*)(struct ipsec_policy *, void *), void *);
  374. int pfkeyv2_sysctl_dump(void *);
  375. int pfkeyv2_sysctl_policydumper(struct ipsec_policy *, void *);
  376. int pfdatatopacket(void *, int, struct mbuf **);
  377. void export_address(void **, struct sockaddr *);
  378. void export_identities(void **, struct ipsec_ids *, int, void **);
  379. void export_lifetime(void **, struct tdb *, int);
  380. void export_sa(void **, struct tdb *);
  381. void export_flow(void **, u_int8_t, struct sockaddr_encap *,
  382. struct sockaddr_encap *, void **);
  383. void export_key(void **, struct tdb *, int);
  384. void export_udpencap(void **, struct tdb *);
  385. void export_tag(void **, struct tdb *);
  386. void export_tap(void **, struct tdb *);
  387. void import_address(struct sockaddr *, struct sadb_address *);
  388. void import_identities(struct ipsec_ids **, int, struct sadb_ident *,
  389. struct sadb_ident *);
  390. void import_key(struct ipsecinit *, struct sadb_key *, int);
  391. void import_lifetime(struct tdb *, struct sadb_lifetime *, int);
  392. void import_sa(struct tdb *, struct sadb_sa *, struct ipsecinit *);
  393. void import_flow(struct sockaddr_encap *, struct sockaddr_encap *,
  394. struct sadb_address *, struct sadb_address *, struct sadb_address *,
  395. struct sadb_address *, struct sadb_protocol *, struct sadb_protocol *);
  396. void import_udpencap(struct tdb *, struct sadb_x_udpencap *);
  397. void import_tag(struct tdb *, struct sadb_x_tag *);
  398. void import_tap(struct tdb *, struct sadb_x_tap *);
  399. #endif /* _KERNEL */
  400. #endif /* _NET_PFKEY_V2_H_ */