ip_ipsp.h revision 1.203
1/* $OpenBSD: ip_ipsp.h,v 1.203 2021/07/18 18:19:22 mvs Exp $ */ 2/* 3 * The authors of this code are John Ioannidis (ji@tla.org), 4 * Angelos D. Keromytis (kermit@csd.uch.gr), 5 * Niels Provos (provos@physnet.uni-hamburg.de) and 6 * Niklas Hallqvist (niklas@appli.se). 7 * 8 * The original version of this code was written by John Ioannidis 9 * for BSD/OS in Athens, Greece, in November 1995. 10 * 11 * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996, 12 * by Angelos D. Keromytis. 13 * 14 * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis 15 * and Niels Provos. 16 * 17 * Additional features in 1999 by Angelos D. Keromytis and Niklas Hallqvist. 18 * 19 * Copyright (c) 1995, 1996, 1997, 1998, 1999 by John Ioannidis, 20 * Angelos D. Keromytis and Niels Provos. 21 * Copyright (c) 1999 Niklas Hallqvist. 22 * Copyright (c) 2001, Angelos D. Keromytis. 23 * 24 * Permission to use, copy, and modify this software with or without fee 25 * is hereby granted, provided that this entire notice is included in 26 * all copies of any software which is or includes a copy or 27 * modification of this software. 28 * You may use this code under the GNU public license if you so wish. Please 29 * contribute changes back to the authors under this freer than GPL license 30 * so that we may further the use of strong encryption without limitations to 31 * all. 32 * 33 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR 34 * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY 35 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE 36 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR 37 * PURPOSE. 38 */ 39 40#ifndef _NETINET_IPSP_H_ 41#define _NETINET_IPSP_H_ 42 43/* IPSP global definitions. */ 44 45#include <sys/types.h> 46#include <netinet/in.h> 47 48union sockaddr_union { 49 struct sockaddr sa; 50 struct sockaddr_in sin; 51 struct sockaddr_in6 sin6; 52}; 53 54#define AH_HMAC_MAX_HASHLEN 32 /* 256 bits of authenticator for SHA512 */ 55#define AH_HMAC_RPLENGTH 4 /* 32 bits of replay counter */ 56#define AH_HMAC_INITIAL_RPL 1 /* Replay counter initial value */ 57 58/* Authenticator lengths */ 59#define AH_MD5_ALEN 16 60#define AH_SHA1_ALEN 20 61#define AH_RMD160_ALEN 20 62#define AH_SHA2_256_ALEN 32 63#define AH_SHA2_384_ALEN 48 64#define AH_SHA2_512_ALEN 64 65#define AH_ALEN_MAX 64 /* Keep updated */ 66 67/* Reserved SPI numbers */ 68#define SPI_LOCAL_USE 0 69#define SPI_RESERVED_MIN 1 70#define SPI_RESERVED_MAX 255 71 72/* Reserved CPI numbers */ 73#define CPI_RESERVED_MIN 1 74#define CPI_RESERVED_MAX 255 75#define CPI_PRIVATE_MIN 61440 76#define CPI_PRIVATE_MAX 65535 77 78/* sysctl default values */ 79#define IPSEC_DEFAULT_EMBRYONIC_SA_TIMEOUT 60 /* 1 minute */ 80#define IPSEC_DEFAULT_PFS 1 81#define IPSEC_DEFAULT_SOFT_ALLOCATIONS 0 82#define IPSEC_DEFAULT_EXP_ALLOCATIONS 0 83#define IPSEC_DEFAULT_SOFT_BYTES 0 84#define IPSEC_DEFAULT_EXP_BYTES 0 85#define IPSEC_DEFAULT_SOFT_TIMEOUT 80000 86#define IPSEC_DEFAULT_EXP_TIMEOUT 86400 87#define IPSEC_DEFAULT_SOFT_FIRST_USE 3600 88#define IPSEC_DEFAULT_EXP_FIRST_USE 7200 89#define IPSEC_DEFAULT_DEF_ENC "aes" 90#define IPSEC_DEFAULT_DEF_AUTH "hmac-sha1" 91#define IPSEC_DEFAULT_EXPIRE_ACQUIRE 30 92#define IPSEC_DEFAULT_DEF_COMP "deflate" 93 94struct sockaddr_encap { 95 u_int8_t sen_len; /* length */ 96 u_int8_t sen_family; /* PF_KEY */ 97 u_int16_t sen_type; /* see SENT_* */ 98 union { 99 struct { /* SENT_IP4 */ 100 u_int8_t Direction; 101 struct in_addr Src; 102 struct in_addr Dst; 103 u_int8_t Proto; 104 u_int16_t Sport; 105 u_int16_t Dport; 106 } Sip4; 107 108 struct { /* SENT_IP6 */ 109 u_int8_t Direction; 110 struct in6_addr Src; 111 struct in6_addr Dst; 112 u_int8_t Proto; 113 u_int16_t Sport; 114 u_int16_t Dport; 115 } Sip6; 116 } Sen; 117}; 118 119#define IPSP_DIRECTION_IN 0x1 120#define IPSP_DIRECTION_OUT 0x2 121 122struct ipsecstat { 123 uint64_t ipsec_tunnels; /* Number of active tunnels */ 124 uint64_t ipsec_prevtunnels; /* Past number of tunnels */ 125 uint64_t ipsec_ipackets; /* Input IPsec packets */ 126 uint64_t ipsec_opackets; /* Output IPsec packets */ 127 uint64_t ipsec_ibytes; /* Input bytes */ 128 uint64_t ipsec_obytes; /* Output bytes */ 129 uint64_t ipsec_idecompbytes; /* Input bytes, decompressed */ 130 uint64_t ipsec_ouncompbytes; /* Output bytes, uncompressed */ 131 uint64_t ipsec_idrops; /* Dropped on input */ 132 uint64_t ipsec_odrops; /* Dropped on output */ 133 uint64_t ipsec_crypto; /* Crypto processing failure */ 134 uint64_t ipsec_notdb; /* Expired while in crypto */ 135 uint64_t ipsec_noxform; /* Crypto error */ 136}; 137 138struct tdb_data { 139 uint64_t tdd_ipackets; /* Input IPsec packets */ 140 uint64_t tdd_opackets; /* Output IPsec packets */ 141 uint64_t tdd_ibytes; /* Input bytes */ 142 uint64_t tdd_obytes; /* Output bytes */ 143 uint64_t tdd_idrops; /* Dropped on input */ 144 uint64_t tdd_odrops; /* Dropped on output */ 145 uint64_t tdd_idecompbytes; /* Input bytes, decompressed */ 146 uint64_t tdd_ouncompbytes; /* Output bytes, uncompressed */ 147}; 148 149#ifdef _KERNEL 150 151#include <sys/timeout.h> 152#include <sys/tree.h> 153#include <sys/queue.h> 154#include <net/radix.h> 155#include <sys/percpu.h> 156 157enum ipsec_counters { 158 ipsec_tunnels, 159 ipsec_prevtunnels, 160 ipsec_ipackets, 161 ipsec_opackets, 162 ipsec_ibytes, 163 ipsec_obytes, 164 ipsec_idecompbytes, 165 ipsec_ouncompbytes, 166 ipsec_idrops, 167 ipsec_odrops, 168 ipsec_crypto, 169 ipsec_notdb, 170 ipsec_noxform, 171 ipsec_ncounters 172}; 173 174extern struct cpumem *ipseccounters; 175 176static inline void 177ipsecstat_inc(enum ipsec_counters c) 178{ 179 counters_inc(ipseccounters, c); 180} 181 182static inline void 183ipsecstat_dec(enum ipsec_counters c) 184{ 185 counters_dec(ipseccounters, c); 186} 187 188static inline void 189ipsecstat_add(enum ipsec_counters c, uint64_t v) 190{ 191 counters_add(ipseccounters, c, v); 192} 193 194struct m_tag; 195 196#define sen_data Sen.Data 197#define sen_ip_src Sen.Sip4.Src 198#define sen_ip_dst Sen.Sip4.Dst 199#define sen_proto Sen.Sip4.Proto 200#define sen_sport Sen.Sip4.Sport 201#define sen_dport Sen.Sip4.Dport 202#define sen_direction Sen.Sip4.Direction 203#define sen_ip6_src Sen.Sip6.Src 204#define sen_ip6_dst Sen.Sip6.Dst 205#define sen_ip6_proto Sen.Sip6.Proto 206#define sen_ip6_sport Sen.Sip6.Sport 207#define sen_ip6_dport Sen.Sip6.Dport 208#define sen_ip6_direction Sen.Sip6.Direction 209 210/* 211 * The "type" is really part of the address as far as the routing 212 * system is concerned. By using only one bit in the type field 213 * for each type, we sort-of make sure that different types of 214 * encapsulation addresses won't be matched against the wrong type. 215 * 216 */ 217 218#define SENT_IP4 0x0001 /* data is two struct in_addr */ 219#define SENT_IP6 0x0002 220 221#define SENT_LEN sizeof(struct sockaddr_encap) 222 223struct ipsec_id { 224 u_int16_t type; /* Subtype of data */ 225 int16_t len; /* Length of data following */ 226}; 227 228struct ipsec_ids { 229 LIST_ENTRY(ipsec_ids) id_gc_list; 230 RBT_ENTRY(ipsec_ids) id_node_id; 231 RBT_ENTRY(ipsec_ids) id_node_flow; 232 struct ipsec_id *id_local; 233 struct ipsec_id *id_remote; 234 u_int32_t id_flow; 235 int id_refcount; 236 u_int id_gc_ttl; 237}; 238RBT_HEAD(ipsec_ids_flows, ipsec_ids); 239RBT_HEAD(ipsec_ids_tree, ipsec_ids); 240 241struct ipsec_acquire { 242 union sockaddr_union ipa_addr; 243 u_int32_t ipa_seq; 244 struct sockaddr_encap ipa_info; 245 struct sockaddr_encap ipa_mask; 246 struct timeout ipa_timeout; 247 struct ipsec_policy *ipa_policy; 248 struct inpcb *ipa_pcb; 249 TAILQ_ENTRY(ipsec_acquire) ipa_ipo_next; 250 TAILQ_ENTRY(ipsec_acquire) ipa_next; 251}; 252 253struct ipsec_policy { 254 struct radix_node ipo_nodes[2]; /* radix tree glue */ 255 struct sockaddr_encap ipo_addr; 256 struct sockaddr_encap ipo_mask; 257 258 union sockaddr_union ipo_src; /* Local address to use */ 259 union sockaddr_union ipo_dst; /* Remote gateway -- if it's zeroed: 260 * - on output, we try to 261 * contact the remote host 262 * directly (if needed). 263 * - on input, we accept on if 264 * the inner source is the 265 * same as the outer source 266 * address, or if transport 267 * mode was used. 268 */ 269 270 u_int64_t ipo_last_searched; /* Timestamp of last lookup */ 271 272 u_int8_t ipo_flags; /* See IPSP_POLICY_* definitions */ 273 u_int8_t ipo_type; /* USE/ACQUIRE/... */ 274 u_int8_t ipo_sproto; /* ESP/AH; if zero, use system dflts */ 275 u_int ipo_rdomain; 276 277 int ipo_ref_count; 278 279 struct tdb *ipo_tdb; /* Cached entry */ 280 281 struct ipsec_ids *ipo_ids; 282 283 TAILQ_HEAD(ipo_acquires_head, ipsec_acquire) ipo_acquires; /* List of acquires */ 284 TAILQ_ENTRY(ipsec_policy) ipo_tdb_next; /* List TDB policies */ 285 TAILQ_ENTRY(ipsec_policy) ipo_list; /* List of all policies */ 286}; 287 288#define IPSP_POLICY_NONE 0x0000 /* No flags set */ 289#define IPSP_POLICY_STATIC 0x0002 /* Static policy */ 290 291#define IPSP_IPSEC_USE 0 /* Use if existing, don't acquire */ 292#define IPSP_IPSEC_ACQUIRE 1 /* Try acquire, let packet through */ 293#define IPSP_IPSEC_REQUIRE 2 /* Require SA */ 294#define IPSP_PERMIT 3 /* Permit traffic through */ 295#define IPSP_DENY 4 /* Deny traffic */ 296#define IPSP_IPSEC_DONTACQ 5 /* Require, but don't acquire */ 297 298/* Identity types */ 299#define IPSP_IDENTITY_NONE 0 300#define IPSP_IDENTITY_PREFIX 1 301#define IPSP_IDENTITY_FQDN 2 302#define IPSP_IDENTITY_USERFQDN 3 303#define IPSP_IDENTITY_ASN1_DN 4 304 305struct tdb { /* tunnel descriptor block */ 306 /* 307 * Each TDB is on three hash tables: one keyed on dst/spi/sproto, 308 * one keyed on dst/sproto, and one keyed on src/sproto. The first 309 * is used for finding a specific TDB, the second for finding TDBs 310 * for outgoing policy matching, and the third for incoming 311 * policy matching. The following three fields maintain the hash 312 * queues in those three tables. 313 */ 314 struct tdb *tdb_hnext; /* dst/spi/sproto table */ 315 struct tdb *tdb_dnext; /* dst/sproto table */ 316 struct tdb *tdb_snext; /* src/sproto table */ 317 struct tdb *tdb_inext; 318 struct tdb *tdb_onext; 319 320 const struct xformsw *tdb_xform; /* Transform to use */ 321 const struct enc_xform *tdb_encalgxform; /* Enc algorithm */ 322 const struct auth_hash *tdb_authalgxform; /* Auth algorithm */ 323 const struct comp_algo *tdb_compalgxform; /* Compression algo */ 324 325#define TDBF_UNIQUE 0x00001 /* This should not be used by others */ 326#define TDBF_TIMER 0x00002 /* Absolute expiration timer in use */ 327#define TDBF_BYTES 0x00004 /* Check the byte counters */ 328#define TDBF_ALLOCATIONS 0x00008 /* Check the flows counters */ 329#define TDBF_INVALID 0x00010 /* This SPI is not valid yet/anymore */ 330#define TDBF_FIRSTUSE 0x00020 /* Expire after first use */ 331#define TDBF_SOFT_TIMER 0x00080 /* Soft expiration */ 332#define TDBF_SOFT_BYTES 0x00100 /* Soft expiration */ 333#define TDBF_SOFT_ALLOCATIONS 0x00200 /* Soft expiration */ 334#define TDBF_SOFT_FIRSTUSE 0x00400 /* Soft expiration */ 335#define TDBF_PFS 0x00800 /* Ask for PFS from Key Mgmt. */ 336#define TDBF_TUNNELING 0x01000 /* Force IP-IP encapsulation */ 337#define TDBF_USEDTUNNEL 0x10000 /* Appended a tunnel header in past */ 338#define TDBF_UDPENCAP 0x20000 /* UDP encapsulation */ 339#define TDBF_PFSYNC 0x40000 /* TDB will be synced */ 340#define TDBF_PFSYNC_RPL 0x80000 /* Replay counter should be bumped */ 341#define TDBF_ESN 0x100000 /* 64-bit sequence numbers (ESN) */ 342 343 u_int32_t tdb_flags; /* Flags related to this TDB */ 344 345 struct timeout tdb_timer_tmo; 346 struct timeout tdb_first_tmo; 347 struct timeout tdb_stimer_tmo; 348 struct timeout tdb_sfirst_tmo; 349 350 u_int32_t tdb_seq; /* Tracking number for PFKEY */ 351 u_int32_t tdb_exp_allocations; /* Expire after so many flows */ 352 u_int32_t tdb_soft_allocations; /* Expiration warning */ 353 u_int32_t tdb_cur_allocations; /* Total number of allocs */ 354 355 u_int64_t tdb_exp_bytes; /* Expire after so many bytes passed */ 356 u_int64_t tdb_soft_bytes; /* Expiration warning */ 357 u_int64_t tdb_cur_bytes; /* Current count of bytes */ 358 359 u_int64_t tdb_exp_timeout; /* When does the SPI expire */ 360 u_int64_t tdb_soft_timeout; /* Send soft-expire warning */ 361 u_int64_t tdb_established; /* When was SPI established */ 362 363 u_int64_t tdb_first_use; /* When was it first used */ 364 u_int64_t tdb_soft_first_use; /* Soft warning */ 365 u_int64_t tdb_exp_first_use; /* Expire if tdb_first_use + 366 * tdb_exp_first_use <= curtime 367 */ 368 369 u_int64_t tdb_last_used; /* When was this SA last used */ 370 u_int64_t tdb_last_marked;/* Last SKIPCRYPTO status change */ 371 372 struct tdb_data tdb_data; /* stats about this TDB */ 373 u_int64_t tdb_cryptoid; /* Crypto session ID */ 374 375 u_int32_t tdb_spi; /* SPI */ 376 u_int16_t tdb_amxkeylen; /* Raw authentication key length */ 377 u_int16_t tdb_emxkeylen; /* Raw encryption key length */ 378 u_int16_t tdb_ivlen; /* IV length */ 379 u_int8_t tdb_sproto; /* IPsec protocol */ 380 u_int8_t tdb_wnd; /* Replay window */ 381 u_int8_t tdb_satype; /* SA type (RFC2367, PF_KEY) */ 382 u_int8_t tdb_updates; /* pfsync update counter */ 383 384 union sockaddr_union tdb_dst; /* Destination address */ 385 union sockaddr_union tdb_src; /* Source address */ 386 387 u_int8_t *tdb_amxkey; /* Raw authentication key */ 388 u_int8_t *tdb_emxkey; /* Raw encryption key */ 389 390#define TDB_REPLAYWASTE 32 391#define TDB_REPLAYMAX (2100+TDB_REPLAYWASTE) 392 393 u_int64_t tdb_rpl; /* Replay counter */ 394 u_int32_t tdb_seen[howmany(TDB_REPLAYMAX, 32)]; /* Anti-replay window */ 395 396 u_int8_t tdb_iv[4]; /* Used for HALF-IV ESP */ 397 398 struct ipsec_ids *tdb_ids; /* Src/Dst ID for this SA */ 399 int tdb_ids_swapped; /* XXX */ 400 401 u_int32_t tdb_mtu; /* MTU at this point in the chain */ 402 u_int64_t tdb_mtutimeout; /* When to ignore this entry */ 403 404 u_int16_t tdb_udpencap_port; /* Peer UDP port */ 405 406 u_int16_t tdb_tag; /* Packet filter tag */ 407 u_int32_t tdb_tap; /* Alternate enc(4) interface */ 408 409 u_int tdb_rdomain; /* Routing domain */ 410 u_int tdb_rdomain_post; /* Change domain */ 411 412 struct sockaddr_encap tdb_filter; /* What traffic is acceptable */ 413 struct sockaddr_encap tdb_filtermask; /* And the mask */ 414 415 TAILQ_HEAD(tdb_policy_head, ipsec_policy) tdb_policy_head; 416 TAILQ_ENTRY(tdb) tdb_sync_entry; 417}; 418#define tdb_ipackets tdb_data.tdd_ipackets 419#define tdb_opackets tdb_data.tdd_opackets 420#define tdb_ibytes tdb_data.tdd_ibytes 421#define tdb_obytes tdb_data.tdd_obytes 422#define tdb_idrops tdb_data.tdd_idrops 423#define tdb_odrops tdb_data.tdd_odrops 424#define tdb_idecompbytes tdb_data.tdd_idecompbytes 425#define tdb_ouncompbytes tdb_data.tdd_ouncompbytes 426 427 428struct tdb_ident { 429 u_int32_t spi; 430 union sockaddr_union dst; 431 u_int8_t proto; 432 u_int rdomain; 433}; 434 435struct tdb_crypto { 436 union sockaddr_union tc_dst; 437 u_int64_t tc_rpl; 438 u_int32_t tc_spi; 439 int tc_protoff; 440 int tc_skip; 441 u_int tc_rdomain; 442 u_int8_t tc_proto; 443}; 444 445struct ipsecinit { 446 u_int8_t *ii_enckey; 447 u_int8_t *ii_authkey; 448 u_int16_t ii_enckeylen; 449 u_int16_t ii_authkeylen; 450 u_int8_t ii_encalg; 451 u_int8_t ii_authalg; 452 u_int8_t ii_compalg; 453}; 454 455/* xform IDs */ 456#define XF_IP4 1 /* IP inside IP */ 457#define XF_AH 2 /* AH */ 458#define XF_ESP 3 /* ESP */ 459#define XF_TCPSIGNATURE 5 /* TCP MD5 Signature option, RFC 2358 */ 460#define XF_IPCOMP 6 /* IPCOMP */ 461 462/* xform attributes */ 463#define XFT_AUTH 0x0001 464#define XFT_CONF 0x0100 465#define XFT_COMP 0x1000 466 467#define IPSEC_ZEROES_SIZE 256 /* Larger than an IP6 extension hdr. */ 468 469struct xformsw { 470 u_short xf_type; /* Unique ID of xform */ 471 u_short xf_flags; /* flags (see below) */ 472 char *xf_name; /* human-readable name */ 473 int (*xf_attach)(void); /* called at config time */ 474 int (*xf_init)(struct tdb *, const struct xformsw *, 475 struct ipsecinit *); 476 int (*xf_zeroize)(struct tdb *); /* termination */ 477 int (*xf_input)(struct mbuf *, struct tdb *, int, int); /* input */ 478 int (*xf_output)(struct mbuf *, struct tdb *, struct mbuf **, 479 int, int); /* output */ 480}; 481 482extern int ipsec_in_use; 483extern u_int64_t ipsec_last_added; 484extern int encdebug; /* enable message reporting */ 485 486extern int ipsec_keep_invalid; /* lifetime of embryonic SAs (in sec) */ 487extern int ipsec_require_pfs; /* use Perfect Forward Secrecy */ 488extern int ipsec_expire_acquire; /* wait for security assoc. (in sec) */ 489extern int ipsec_soft_allocations; /* flows/SA before renegotiation */ 490extern int ipsec_exp_allocations; /* num. of flows/SA before it expires */ 491extern int ipsec_soft_bytes; /* bytes/SA before renegotiation */ 492extern int ipsec_exp_bytes; /* num of bytes/SA before it expires */ 493extern int ipsec_soft_timeout; /* seconds/SA before renegotiation */ 494extern int ipsec_exp_timeout; /* seconds/SA before it expires */ 495extern int ipsec_soft_first_use; /* seconds between 1st asso & renego */ 496extern int ipsec_exp_first_use; /* seconds between 1st asso & expire */ 497 498/* 499 * Names for IPsec sysctl objects 500 */ 501#define IPSEC_ENCDEBUG IPCTL_ENCDEBUG /* 12 */ 502#define IPSEC_STATS IPCTL_IPSEC_STATS /* 13 */ 503#define IPSEC_EXPIRE_ACQUIRE IPCTL_IPSEC_EXPIRE_ACQUIRE /* 14 */ 504#define IPSEC_EMBRYONIC_SA_TIMEOUT IPCTL_IPSEC_EMBRYONIC_SA_TIMEOUT/* 15 */ 505#define IPSEC_REQUIRE_PFS IPCTL_IPSEC_REQUIRE_PFS /* 16 */ 506#define IPSEC_SOFT_ALLOCATIONS IPCTL_IPSEC_SOFT_ALLOCATIONS /* 17 */ 507#define IPSEC_ALLOCATIONS IPCTL_IPSEC_ALLOCATIONS /* 18 */ 508#define IPSEC_SOFT_BYTES IPCTL_IPSEC_SOFT_BYTES /* 19 */ 509#define IPSEC_BYTES IPCTL_IPSEC_BYTES /* 20 */ 510#define IPSEC_TIMEOUT IPCTL_IPSEC_TIMEOUT /* 21 */ 511#define IPSEC_SOFT_TIMEOUT IPCTL_IPSEC_SOFT_TIMEOUT /* 22 */ 512#define IPSEC_SOFT_FIRSTUSE IPCTL_IPSEC_SOFT_FIRSTUSE /* 23 */ 513#define IPSEC_FIRSTUSE IPCTL_IPSEC_FIRSTUSE /* 24 */ 514#define IPSEC_MAXID 25 515 516extern char ipsec_def_enc[]; 517extern char ipsec_def_auth[]; 518extern char ipsec_def_comp[]; 519 520extern TAILQ_HEAD(ipsec_policy_head, ipsec_policy) ipsec_policy_head; 521 522struct cryptop; 523 524/* Misc. */ 525#ifdef ENCDEBUG 526const char *ipsp_address(union sockaddr_union *, char *, socklen_t); 527#endif /* ENCDEBUG */ 528 529/* SPD tables */ 530struct radix_node_head *spd_table_add(unsigned int); 531struct radix_node_head *spd_table_get(unsigned int); 532int spd_table_walk(unsigned int, 533 int (*walker)(struct ipsec_policy *, void *, unsigned int), void *); 534 535/* TDB management routines */ 536uint32_t reserve_spi(u_int, u_int32_t, u_int32_t, union sockaddr_union *, 537 union sockaddr_union *, u_int8_t, int *); 538struct tdb *gettdb_dir(u_int, u_int32_t, union sockaddr_union *, u_int8_t, int); 539#define gettdb(a,b,c,d) gettdb_dir((a),(b),(c),(d),0) 540#define gettdb_rev(a,b,c,d) gettdb_dir((a),(b),(c),(d),1) 541struct tdb *gettdbbydst(u_int, union sockaddr_union *, u_int8_t, 542 struct ipsec_ids *, 543 struct sockaddr_encap *, struct sockaddr_encap *); 544struct tdb *gettdbbysrc(u_int, union sockaddr_union *, u_int8_t, 545 struct ipsec_ids *, 546 struct sockaddr_encap *, struct sockaddr_encap *); 547struct tdb *gettdbbysrcdst_dir(u_int, u_int32_t, union sockaddr_union *, 548 union sockaddr_union *, u_int8_t, int); 549#define gettdbbysrcdst(a,b,c,d,e) gettdbbysrcdst_dir((a),(b),(c),(d),(e),0) 550#define gettdbbysrcdst_rev(a,b,c,d,e) gettdbbysrcdst_dir((a),(b),(c),(d),(e),1) 551void puttdb(struct tdb *); 552void tdb_delete(struct tdb *); 553struct tdb *tdb_alloc(u_int); 554void tdb_free(struct tdb *); 555int tdb_init(struct tdb *, u_int16_t, struct ipsecinit *); 556void tdb_unlink(struct tdb *); 557int tdb_walk(u_int, int (*)(struct tdb *, void *, int), void *); 558 559/* XF_IP4 */ 560int ipe4_attach(void); 561int ipe4_init(struct tdb *, const struct xformsw *, struct ipsecinit *); 562int ipe4_zeroize(struct tdb *); 563int ipe4_input(struct mbuf *, struct tdb *, int, int); 564 565/* XF_AH */ 566int ah_attach(void); 567int ah_init(struct tdb *, const struct xformsw *, struct ipsecinit *); 568int ah_zeroize(struct tdb *); 569int ah_input(struct mbuf *, struct tdb *, int, int); 570int ah_input_cb(struct tdb *, struct tdb_crypto *, struct mbuf *, int); 571int ah_output(struct mbuf *, struct tdb *, struct mbuf **, int, int); 572int ah_output_cb(struct tdb *, struct tdb_crypto *, struct mbuf *, int, 573 int); 574int ah_sysctl(int *, u_int, void *, size_t *, void *, size_t); 575 576int ah4_input(struct mbuf **, int *, int, int); 577void ah4_ctlinput(int, struct sockaddr *, u_int, void *); 578void udpencap_ctlinput(int, struct sockaddr *, u_int, void *); 579 580#ifdef INET6 581int ah6_input(struct mbuf **, int *, int, int); 582#endif /* INET6 */ 583 584/* XF_ESP */ 585int esp_attach(void); 586int esp_init(struct tdb *, const struct xformsw *, struct ipsecinit *); 587int esp_zeroize(struct tdb *); 588int esp_input(struct mbuf *, struct tdb *, int, int); 589int esp_input_cb(struct tdb *, struct tdb_crypto *, struct mbuf *, int); 590int esp_output(struct mbuf *, struct tdb *, struct mbuf **, int, int); 591int esp_output_cb(struct tdb *, struct tdb_crypto *, struct mbuf *, int, 592 int); 593int esp_sysctl(int *, u_int, void *, size_t *, void *, size_t); 594 595int esp4_input(struct mbuf **, int *, int, int); 596void esp4_ctlinput(int, struct sockaddr *, u_int, void *); 597 598#ifdef INET6 599int esp6_input(struct mbuf **, int *, int, int); 600#endif /* INET6 */ 601 602/* XF_IPCOMP */ 603int ipcomp_attach(void); 604int ipcomp_init(struct tdb *, const struct xformsw *, struct ipsecinit *); 605int ipcomp_zeroize(struct tdb *); 606int ipcomp_input(struct mbuf *, struct tdb *, int, int); 607int ipcomp_input_cb(struct tdb *, struct tdb_crypto *, struct mbuf *, int); 608int ipcomp_output(struct mbuf *, struct tdb *, struct mbuf **, int, int); 609int ipcomp_output_cb(struct tdb *, struct tdb_crypto *, struct mbuf *, int, 610 int); 611int ipcomp_sysctl(int *, u_int, void *, size_t *, void *, size_t); 612int ipcomp4_input(struct mbuf **, int *, int, int); 613#ifdef INET6 614int ipcomp6_input(struct mbuf **, int *, int, int); 615#endif /* INET6 */ 616 617/* XF_TCPSIGNATURE */ 618int tcp_signature_tdb_attach(void); 619int tcp_signature_tdb_init(struct tdb *, const struct xformsw *, 620 struct ipsecinit *); 621int tcp_signature_tdb_zeroize(struct tdb *); 622int tcp_signature_tdb_input(struct mbuf *, struct tdb *, int, int); 623int tcp_signature_tdb_output(struct mbuf *, struct tdb *, struct mbuf **, 624 int, int); 625 626/* Replay window */ 627int checkreplaywindow(struct tdb *, u_int64_t, u_int32_t, u_int32_t *, int); 628 629/* Packet processing */ 630int ipsp_process_packet(struct mbuf *, struct tdb *, int, int); 631int ipsp_process_done(struct mbuf *, struct tdb *); 632struct tdb *ipsp_spd_lookup(struct mbuf *, int, int, int *, int, 633 struct tdb *, struct inpcb *, u_int32_t); 634struct tdb *ipsp_spd_inp(struct mbuf *, int, int, int *, int, 635 struct tdb *, struct inpcb *, struct ipsec_policy *); 636int ipsp_is_unspecified(union sockaddr_union); 637int ipsp_aux_match(struct tdb *, struct ipsec_ids *, 638 struct sockaddr_encap *, struct sockaddr_encap *); 639int ipsp_ids_match(struct ipsec_ids *, struct ipsec_ids *); 640struct ipsec_ids *ipsp_ids_insert(struct ipsec_ids *); 641struct ipsec_ids *ipsp_ids_lookup(u_int32_t); 642void ipsp_ids_free(struct ipsec_ids *); 643 644void ipsec_init(void); 645int ipsec_sysctl(int *, u_int, void *, size_t *, void *, size_t); 646int ipsec_common_input(struct mbuf *, int, int, int, int, int); 647void ipsec_input_cb(struct cryptop *); 648void ipsec_output_cb(struct cryptop *); 649int ipsec_common_input_cb(struct mbuf *, struct tdb *, int, int); 650int ipsec_delete_policy(struct ipsec_policy *); 651ssize_t ipsec_hdrsz(struct tdb *); 652void ipsec_adjust_mtu(struct mbuf *, u_int32_t); 653struct ipsec_acquire *ipsec_get_acquire(u_int32_t); 654int ipsec_forward_check(struct mbuf *, int, int); 655int ipsec_local_check(struct mbuf *, int, int, int); 656 657#endif /* _KERNEL */ 658#endif /* _NETINET_IPSP_H_ */ 659