PageRenderTime 37ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/sys/netproto/ipsec/ipsec.h

https://gitlab.com/tlevine/DragonFlyBSD
C Header | 390 lines | 247 code | 46 blank | 97 comment | 6 complexity | faf0851d221674e4731615e544c2c3b7 MD5 | raw file
  1. /* $FreeBSD: src/sys/netipsec/ipsec.h,v 1.2.4.1 2003/01/24 05:11:35 sam Exp $ */
  2. /* $DragonFly: src/sys/netproto/ipsec/ipsec.h,v 1.5 2006/12/22 23:57:54 swildner Exp $ */
  3. /* $KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 itojun Exp $ */
  4. /*
  5. * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the name of the project nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  21. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  24. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. */
  32. /*
  33. * IPsec controller part.
  34. */
  35. #ifndef _NETIPSEC_IPSEC_H_
  36. #define _NETIPSEC_IPSEC_H_
  37. #if defined(_KERNEL) && !defined(_LKM) && !defined(KLD_MODULE)
  38. #include "opt_inet.h"
  39. #include "opt_ipsec.h"
  40. #endif
  41. #include <net/pfkeyv2.h>
  42. #include "keydb.h"
  43. #ifdef _KERNEL
  44. /*
  45. * Security Policy Index
  46. * Ensure that both address families in the "src" and "dst" are same.
  47. * When the value of the ul_proto is ICMPv6, the port field in "src"
  48. * specifies ICMPv6 type, and the port field in "dst" specifies ICMPv6 code.
  49. */
  50. struct secpolicyindex {
  51. u_int8_t dir; /* direction of packet flow, see blow */
  52. union sockaddr_union src; /* IP src address for SP */
  53. union sockaddr_union dst; /* IP dst address for SP */
  54. u_int8_t prefs; /* prefix length in bits for src */
  55. u_int8_t prefd; /* prefix length in bits for dst */
  56. u_int16_t ul_proto; /* upper layer Protocol */
  57. #ifdef notyet
  58. uid_t uids;
  59. uid_t uidd;
  60. gid_t gids;
  61. gid_t gidd;
  62. #endif
  63. };
  64. /* Security Policy Data Base */
  65. struct secpolicy {
  66. LIST_ENTRY(secpolicy) chain;
  67. u_int refcnt; /* reference count */
  68. struct secpolicyindex spidx; /* selector */
  69. u_int32_t id; /* It's unique number on the system. */
  70. u_int state; /* 0: dead, others: alive */
  71. #define IPSEC_SPSTATE_DEAD 0
  72. #define IPSEC_SPSTATE_ALIVE 1
  73. u_int policy; /* DISCARD, NONE or IPSEC, see keyv2.h */
  74. struct ipsecrequest *req;
  75. /* pointer to the ipsec request tree, */
  76. /* if policy == IPSEC else this value == NULL.*/
  77. /*
  78. * lifetime handler.
  79. * the policy can be used without limitiation if both lifetime and
  80. * validtime are zero.
  81. * "lifetime" is passed by sadb_lifetime.sadb_lifetime_addtime.
  82. * "validtime" is passed by sadb_lifetime.sadb_lifetime_usetime.
  83. */
  84. long created; /* time created the policy */
  85. long lastused; /* updated every when kernel sends a packet */
  86. long lifetime; /* duration of the lifetime of this policy */
  87. long validtime; /* duration this policy is valid without use */
  88. };
  89. /* Request for IPsec */
  90. struct ipsecrequest {
  91. struct ipsecrequest *next;
  92. /* pointer to next structure */
  93. /* If NULL, it means the end of chain. */
  94. struct secasindex saidx;/* hint for search proper SA */
  95. /* if __ss_len == 0 then no address specified.*/
  96. u_int level; /* IPsec level defined below. */
  97. struct secasvar *sav; /* place holder of SA for use */
  98. struct secpolicy *sp; /* back pointer to SP */
  99. };
  100. /* security policy in PCB */
  101. struct inpcbpolicy {
  102. struct secpolicy *sp_in;
  103. struct secpolicy *sp_out;
  104. int priv; /* privileged socket ? */
  105. };
  106. /* SP acquiring list table. */
  107. struct secspacq {
  108. LIST_ENTRY(secspacq) chain;
  109. struct secpolicyindex spidx;
  110. long created; /* for lifetime */
  111. int count; /* for lifetime */
  112. /* XXX: here is mbuf place holder to be sent ? */
  113. };
  114. #endif /* _KERNEL */
  115. /* according to IANA assignment, port 0x0000 and proto 0xff are reserved. */
  116. #define IPSEC_PORT_ANY 0
  117. #define IPSEC_ULPROTO_ANY 255
  118. #define IPSEC_PROTO_ANY 255
  119. /* mode of security protocol */
  120. /* NOTE: DON'T use IPSEC_MODE_ANY at SPD. It's only use in SAD */
  121. #define IPSEC_MODE_ANY 0 /* i.e. wildcard. */
  122. #define IPSEC_MODE_TRANSPORT 1
  123. #define IPSEC_MODE_TUNNEL 2
  124. /*
  125. * Direction of security policy.
  126. * NOTE: Since INVALID is used just as flag.
  127. * The other are used for loop counter too.
  128. */
  129. #define IPSEC_DIR_ANY 0
  130. #define IPSEC_DIR_INBOUND 1
  131. #define IPSEC_DIR_OUTBOUND 2
  132. #define IPSEC_DIR_MAX 3
  133. #define IPSEC_DIR_INVALID 4
  134. /* Policy level */
  135. /*
  136. * IPSEC, ENTRUST and BYPASS are allowed for setsockopt() in PCB,
  137. * DISCARD, IPSEC and NONE are allowed for setkey() in SPD.
  138. * DISCARD and NONE are allowed for system default.
  139. */
  140. #define IPSEC_POLICY_DISCARD 0 /* discarding packet */
  141. #define IPSEC_POLICY_NONE 1 /* through IPsec engine */
  142. #define IPSEC_POLICY_IPSEC 2 /* do IPsec */
  143. #define IPSEC_POLICY_ENTRUST 3 /* consulting SPD if present. */
  144. #define IPSEC_POLICY_BYPASS 4 /* only for privileged socket. */
  145. /* Security protocol level */
  146. #define IPSEC_LEVEL_DEFAULT 0 /* reference to system default */
  147. #define IPSEC_LEVEL_USE 1 /* use SA if present. */
  148. #define IPSEC_LEVEL_REQUIRE 2 /* require SA. */
  149. #define IPSEC_LEVEL_UNIQUE 3 /* unique SA. */
  150. #define IPSEC_MANUAL_REQID_MAX 0x3fff
  151. /*
  152. * if security policy level == unique, this id
  153. * indicate to a relative SA for use, else is
  154. * zero.
  155. * 1 - 0x3fff are reserved for manual keying.
  156. * 0 are reserved for above reason. Others is
  157. * for kernel use.
  158. * Note that this id doesn't identify SA
  159. * by only itself.
  160. */
  161. #define IPSEC_REPLAYWSIZE 32
  162. /* old statistics for ipsec processing */
  163. struct ipsecstat {
  164. u_quad_t in_success; /* succeeded inbound process */
  165. u_quad_t in_polvio;
  166. /* security policy violation for inbound process */
  167. u_quad_t in_nosa; /* inbound SA is unavailable */
  168. u_quad_t in_inval; /* inbound processing failed due to EINVAL */
  169. u_quad_t in_nomem; /* inbound processing failed due to ENOBUFS */
  170. u_quad_t in_badspi; /* failed getting a SPI */
  171. u_quad_t in_ahreplay; /* AH replay check failed */
  172. u_quad_t in_espreplay; /* ESP replay check failed */
  173. u_quad_t in_ahauthsucc; /* AH authentication success */
  174. u_quad_t in_ahauthfail; /* AH authentication failure */
  175. u_quad_t in_espauthsucc; /* ESP authentication success */
  176. u_quad_t in_espauthfail; /* ESP authentication failure */
  177. u_quad_t in_esphist[256];
  178. u_quad_t in_ahhist[256];
  179. u_quad_t in_comphist[256];
  180. u_quad_t out_success; /* succeeded outbound process */
  181. u_quad_t out_polvio;
  182. /* security policy violation for outbound process */
  183. u_quad_t out_nosa; /* outbound SA is unavailable */
  184. u_quad_t out_inval; /* outbound process failed due to EINVAL */
  185. u_quad_t out_nomem; /* inbound processing failed due to ENOBUFS */
  186. u_quad_t out_noroute; /* there is no route */
  187. u_quad_t out_esphist[256];
  188. u_quad_t out_ahhist[256];
  189. u_quad_t out_comphist[256];
  190. };
  191. /* statistics for ipsec processing */
  192. struct newipsecstat {
  193. u_int32_t ips_in_polvio; /* input: sec policy violation */
  194. u_int32_t ips_out_polvio; /* output: sec policy violation */
  195. u_int32_t ips_out_nosa; /* output: SA unavailable */
  196. u_int32_t ips_out_nomem; /* output: no memory available */
  197. u_int32_t ips_out_noroute; /* output: no route available */
  198. u_int32_t ips_out_inval; /* output: generic error */
  199. u_int32_t ips_out_bundlesa; /* output: bundled SA processed */
  200. u_int32_t ips_mbcoalesced; /* mbufs coalesced during clone */
  201. u_int32_t ips_clcoalesced; /* clusters coalesced during clone */
  202. u_int32_t ips_clcopied; /* clusters copied during clone */
  203. u_int32_t ips_mbinserted; /* mbufs inserted during makespace */
  204. /*
  205. * Temporary statistics for performance analysis.
  206. */
  207. /* See where ESP/AH/IPCOMP header land in mbuf on input */
  208. u_int32_t ips_input_front;
  209. u_int32_t ips_input_middle;
  210. u_int32_t ips_input_end;
  211. };
  212. /*
  213. * Definitions for IPsec & Key sysctl operations.
  214. */
  215. /*
  216. * Names for IPsec & Key sysctl objects
  217. */
  218. #define IPSECCTL_STATS 1 /* stats */
  219. #define IPSECCTL_DEF_POLICY 2
  220. #define IPSECCTL_DEF_ESP_TRANSLEV 3 /* int; ESP transport mode */
  221. #define IPSECCTL_DEF_ESP_NETLEV 4 /* int; ESP tunnel mode */
  222. #define IPSECCTL_DEF_AH_TRANSLEV 5 /* int; AH transport mode */
  223. #define IPSECCTL_DEF_AH_NETLEV 6 /* int; AH tunnel mode */
  224. #if 0 /* obsolete, do not reuse */
  225. #define IPSECCTL_INBOUND_CALL_IKE 7
  226. #endif
  227. #define IPSECCTL_AH_CLEARTOS 8
  228. #define IPSECCTL_AH_OFFSETMASK 9
  229. #define IPSECCTL_DFBIT 10
  230. #define IPSECCTL_ECN 11
  231. #define IPSECCTL_DEBUG 12
  232. #define IPSECCTL_ESP_RANDPAD 13
  233. #define IPSECCTL_MAXID 14
  234. #define IPSECCTL_NAMES { \
  235. { 0, 0 }, \
  236. { 0, 0 }, \
  237. { "def_policy", CTLTYPE_INT }, \
  238. { "esp_trans_deflev", CTLTYPE_INT }, \
  239. { "esp_net_deflev", CTLTYPE_INT }, \
  240. { "ah_trans_deflev", CTLTYPE_INT }, \
  241. { "ah_net_deflev", CTLTYPE_INT }, \
  242. { 0, 0 }, \
  243. { "ah_cleartos", CTLTYPE_INT }, \
  244. { "ah_offsetmask", CTLTYPE_INT }, \
  245. { "dfbit", CTLTYPE_INT }, \
  246. { "ecn", CTLTYPE_INT }, \
  247. { "debug", CTLTYPE_INT }, \
  248. { "esp_randpad", CTLTYPE_INT }, \
  249. }
  250. #define IPSEC6CTL_NAMES { \
  251. { 0, 0 }, \
  252. { 0, 0 }, \
  253. { "def_policy", CTLTYPE_INT }, \
  254. { "esp_trans_deflev", CTLTYPE_INT }, \
  255. { "esp_net_deflev", CTLTYPE_INT }, \
  256. { "ah_trans_deflev", CTLTYPE_INT }, \
  257. { "ah_net_deflev", CTLTYPE_INT }, \
  258. { 0, 0 }, \
  259. { 0, 0 }, \
  260. { 0, 0 }, \
  261. { 0, 0 }, \
  262. { "ecn", CTLTYPE_INT }, \
  263. { "debug", CTLTYPE_INT }, \
  264. { "esp_randpad", CTLTYPE_INT }, \
  265. }
  266. #ifdef _KERNEL
  267. struct ipsec_output_state {
  268. struct mbuf *m;
  269. struct route *ro;
  270. struct sockaddr *dst;
  271. };
  272. struct ipsec_history {
  273. int ih_proto;
  274. u_int32_t ih_spi;
  275. };
  276. extern int ipsec_debug;
  277. extern struct newipsecstat newipsecstat;
  278. extern struct secpolicy ip4_def_policy;
  279. extern int ip4_esp_trans_deflev;
  280. extern int ip4_esp_net_deflev;
  281. extern int ip4_ah_trans_deflev;
  282. extern int ip4_ah_net_deflev;
  283. extern int ip4_ah_cleartos;
  284. extern int ip4_ah_offsetmask;
  285. extern int ip4_ipsec_dfbit;
  286. extern int ip4_ipsec_ecn;
  287. extern int ip4_esp_randpad;
  288. extern int crypto_support;
  289. #define ipseclog(x) do { if (ipsec_debug) log x; } while (0)
  290. /* for openbsd compatibility */
  291. #define DPRINTF(x) do { if (ipsec_debug) kprintf x; } while (0)
  292. struct tdb_ident;
  293. extern struct secpolicy *ipsec_getpolicy (struct tdb_ident*, u_int);
  294. struct inpcb;
  295. extern struct secpolicy *ipsec4_checkpolicy (struct mbuf *, u_int, u_int,
  296. int *, struct inpcb *);
  297. extern struct secpolicy *ipsec_getpolicybysock(struct mbuf *, u_int,
  298. struct inpcb *, int *);
  299. extern struct secpolicy * ipsec_getpolicybyaddr(struct mbuf *, u_int,
  300. int, int *);
  301. struct inpcb;
  302. extern int ipsec_init_policy (struct socket *so, struct inpcbpolicy **);
  303. extern int ipsec_copy_policy
  304. (struct inpcbpolicy *, struct inpcbpolicy *);
  305. extern u_int ipsec_get_reqlevel (struct ipsecrequest *);
  306. extern int ipsec_in_reject (struct secpolicy *, struct mbuf *);
  307. extern int ipsec4_set_policy (struct inpcb *inp, int optname,
  308. caddr_t request, size_t len, int priv);
  309. extern int ipsec4_get_policy (struct inpcb *inpcb, caddr_t request,
  310. size_t len, struct mbuf **mp);
  311. extern int ipsec4_delete_pcbpolicy (struct inpcb *);
  312. extern int ipsec4_in_reject (struct mbuf *, struct inpcb *);
  313. struct secas;
  314. struct tcpcb;
  315. extern int ipsec_chkreplay (u_int32_t, struct secasvar *);
  316. extern int ipsec_updatereplay (u_int32_t, struct secasvar *);
  317. extern size_t ipsec4_hdrsiz (struct mbuf *, u_int, struct inpcb *);
  318. extern size_t ipsec_hdrsiz_tcp (struct tcpcb *);
  319. union sockaddr_union;
  320. extern char * ipsec_address(union sockaddr_union* sa);
  321. extern const char *ipsec_logsastr (struct secasvar *);
  322. extern void ipsec_dumpmbuf (struct mbuf *);
  323. struct m_tag;
  324. extern int ipsec4_common_input(struct mbuf **m, int *offp, int proto);
  325. extern int ipsec4_common_input_cb(struct mbuf *m, struct secasvar *sav,
  326. int skip, int protoff, struct m_tag *mt);
  327. extern int ipsec4_process_packet (struct mbuf *, struct ipsecrequest *,
  328. int, int);
  329. extern int ipsec_process_done (struct mbuf *, struct ipsecrequest *);
  330. extern struct mbuf *ipsec_copypkt (struct mbuf *);
  331. extern void m_checkalignment(const char* where, struct mbuf *m0,
  332. int off, int len);
  333. extern struct mbuf *m_clone(struct mbuf *m0);
  334. extern struct mbuf *m_makespace(struct mbuf *m0, int skip, int hlen, int *off);
  335. extern caddr_t m_pad(struct mbuf *m, int n);
  336. extern int m_striphdr(struct mbuf *m, int skip, int hlen);
  337. #endif /* _KERNEL */
  338. #ifndef _KERNEL
  339. extern caddr_t ipsec_set_policy (char *, int);
  340. extern int ipsec_get_policylen (caddr_t);
  341. extern char *ipsec_dump_policy (caddr_t, char *);
  342. extern const char *ipsec_strerror (void);
  343. #endif /* !_KERNEL */
  344. #endif /* _NETIPSEC_IPSEC_H_ */