1 /* $KAME: pfkeyv2.h,v 1.37 2003/09/06 05:15:43 itojun Exp $ */ 2 3 /*- 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the project nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 /* 35 * This file has been derived rfc 2367, 36 * And added some flags of SADB_KEY_FLAGS_ as SADB_X_EXT_. 37 * sakane@ydc.co.jp 38 */ 39 40 #ifndef _NET_PFKEYV2_H_ 41 #define _NET_PFKEYV2_H_ 42 43 /* 44 This file defines structures and symbols for the PF_KEY Version 2 45 key management interface. It was written at the U.S. Naval Research 46 Laboratory. This file is in the public domain. The authors ask that 47 you leave this credit intact on any copies of this file. 48 */ 49 #ifndef __PFKEY_V2_H 50 #define __PFKEY_V2_H 1 51 52 #define PF_KEY_V2 2 53 #define PFKEYV2_REVISION 199806L 54 55 #define SADB_RESERVED 0 56 #define SADB_GETSPI 1 57 #define SADB_UPDATE 2 58 #define SADB_ADD 3 59 #define SADB_DELETE 4 60 #define SADB_GET 5 61 #define SADB_ACQUIRE 6 62 #define SADB_REGISTER 7 63 #define SADB_EXPIRE 8 64 #define SADB_FLUSH 9 65 #define SADB_DUMP 10 66 #define SADB_X_PROMISC 11 67 #define SADB_X_PCHANGE 12 68 69 #define SADB_X_SPDUPDATE 13 70 #define SADB_X_SPDADD 14 71 #define SADB_X_SPDDELETE 15 /* by policy index */ 72 #define SADB_X_SPDGET 16 73 #define SADB_X_SPDACQUIRE 17 74 #define SADB_X_SPDDUMP 18 75 #define SADB_X_SPDFLUSH 19 76 #define SADB_X_SPDSETIDX 20 77 #define SADB_X_SPDEXPIRE 21 78 #define SADB_X_SPDDELETE2 22 /* by policy id */ 79 #define SADB_MAX 22 80 81 struct sadb_msg { 82 u_int8_t sadb_msg_version; 83 u_int8_t sadb_msg_type; 84 u_int8_t sadb_msg_errno; 85 u_int8_t sadb_msg_satype; 86 u_int16_t sadb_msg_len; 87 u_int16_t sadb_msg_reserved; 88 u_int32_t sadb_msg_seq; 89 u_int32_t sadb_msg_pid; 90 }; 91 92 struct sadb_ext { 93 u_int16_t sadb_ext_len; 94 u_int16_t sadb_ext_type; 95 }; 96 97 struct sadb_sa { 98 u_int16_t sadb_sa_len; 99 u_int16_t sadb_sa_exttype; 100 u_int32_t sadb_sa_spi; 101 u_int8_t sadb_sa_replay; 102 u_int8_t sadb_sa_state; 103 u_int8_t sadb_sa_auth; 104 u_int8_t sadb_sa_encrypt; 105 u_int32_t sadb_sa_flags; 106 }; 107 108 struct sadb_lifetime { 109 u_int16_t sadb_lifetime_len; 110 u_int16_t sadb_lifetime_exttype; 111 u_int32_t sadb_lifetime_allocations; 112 u_int64_t sadb_lifetime_bytes; 113 u_int64_t sadb_lifetime_addtime; 114 u_int64_t sadb_lifetime_usetime; 115 }; 116 117 struct sadb_address { 118 u_int16_t sadb_address_len; 119 u_int16_t sadb_address_exttype; 120 u_int8_t sadb_address_proto; 121 u_int8_t sadb_address_prefixlen; 122 u_int16_t sadb_address_reserved; 123 }; 124 125 struct sadb_key { 126 u_int16_t sadb_key_len; 127 u_int16_t sadb_key_exttype; 128 u_int16_t sadb_key_bits; 129 u_int16_t sadb_key_reserved; 130 }; 131 132 struct sadb_ident { 133 u_int16_t sadb_ident_len; 134 u_int16_t sadb_ident_exttype; 135 u_int16_t sadb_ident_type; 136 u_int16_t sadb_ident_reserved; 137 u_int64_t sadb_ident_id; 138 }; 139 140 struct sadb_sens { 141 u_int16_t sadb_sens_len; 142 u_int16_t sadb_sens_exttype; 143 u_int32_t sadb_sens_dpd; 144 u_int8_t sadb_sens_sens_level; 145 u_int8_t sadb_sens_sens_len; 146 u_int8_t sadb_sens_integ_level; 147 u_int8_t sadb_sens_integ_len; 148 u_int32_t sadb_sens_reserved; 149 }; 150 151 struct sadb_prop { 152 u_int16_t sadb_prop_len; 153 u_int16_t sadb_prop_exttype; 154 u_int8_t sadb_prop_replay; 155 u_int8_t sadb_prop_reserved[3]; 156 }; 157 158 struct sadb_comb { 159 u_int8_t sadb_comb_auth; 160 u_int8_t sadb_comb_encrypt; 161 u_int16_t sadb_comb_flags; 162 u_int16_t sadb_comb_auth_minbits; 163 u_int16_t sadb_comb_auth_maxbits; 164 u_int16_t sadb_comb_encrypt_minbits; 165 u_int16_t sadb_comb_encrypt_maxbits; 166 u_int32_t sadb_comb_reserved; 167 u_int32_t sadb_comb_soft_allocations; 168 u_int32_t sadb_comb_hard_allocations; 169 u_int64_t sadb_comb_soft_bytes; 170 u_int64_t sadb_comb_hard_bytes; 171 u_int64_t sadb_comb_soft_addtime; 172 u_int64_t sadb_comb_hard_addtime; 173 u_int64_t sadb_comb_soft_usetime; 174 u_int64_t sadb_comb_hard_usetime; 175 }; 176 177 struct sadb_supported { 178 u_int16_t sadb_supported_len; 179 u_int16_t sadb_supported_exttype; 180 u_int32_t sadb_supported_reserved; 181 }; 182 183 struct sadb_alg { 184 u_int8_t sadb_alg_id; 185 u_int8_t sadb_alg_ivlen; 186 u_int16_t sadb_alg_minbits; 187 u_int16_t sadb_alg_maxbits; 188 u_int16_t sadb_alg_reserved; 189 }; 190 191 struct sadb_spirange { 192 u_int16_t sadb_spirange_len; 193 u_int16_t sadb_spirange_exttype; 194 u_int32_t sadb_spirange_min; 195 u_int32_t sadb_spirange_max; 196 u_int32_t sadb_spirange_reserved; 197 }; 198 199 struct sadb_x_kmprivate { 200 u_int16_t sadb_x_kmprivate_len; 201 u_int16_t sadb_x_kmprivate_exttype; 202 u_int32_t sadb_x_kmprivate_reserved; 203 }; 204 205 /* 206 * XXX Additional SA Extension. 207 * mode: tunnel or transport 208 * reqid: to make SA unique nevertheless the address pair of SA are same. 209 * Mainly it's for VPN. 210 */ 211 struct sadb_x_sa2 { 212 u_int16_t sadb_x_sa2_len; 213 u_int16_t sadb_x_sa2_exttype; 214 u_int8_t sadb_x_sa2_mode; 215 u_int8_t sadb_x_sa2_reserved1; 216 u_int16_t sadb_x_sa2_reserved2; 217 u_int32_t sadb_x_sa2_sequence; /* lowermost 32bit of sequence number */ 218 u_int32_t sadb_x_sa2_reqid; 219 }; 220 221 /* XXX Policy Extension */ 222 struct sadb_x_policy { 223 u_int16_t sadb_x_policy_len; 224 u_int16_t sadb_x_policy_exttype; 225 u_int16_t sadb_x_policy_type; /* See policy type of ipsec.h */ 226 u_int8_t sadb_x_policy_dir; /* direction, see ipsec.h */ 227 u_int8_t sadb_x_policy_scope; /* scope, see ipsec.h */ 228 u_int32_t sadb_x_policy_id; 229 u_int32_t sadb_x_policy_priority; 230 #define sadb_x_policy_reserved sadb_x_policy_scope 231 /* Policy with ifnet scope uses priority field to store ifindex */ 232 #define sadb_x_policy_ifindex sadb_x_policy_priority 233 }; 234 _Static_assert(sizeof(struct sadb_x_policy) == 16, "struct size mismatch"); 235 236 /* 237 * When policy_type == IPSEC, it is followed by some of 238 * the ipsec policy request. 239 * [total length of ipsec policy requests] 240 * = (sadb_x_policy_len * sizeof(uint64_t) - sizeof(struct sadb_x_policy)) 241 */ 242 243 /* XXX IPsec Policy Request Extension */ 244 /* 245 * This structure is aligned 8 bytes. 246 */ 247 struct sadb_x_ipsecrequest { 248 u_int16_t sadb_x_ipsecrequest_len; /* structure length in 64 bits. */ 249 u_int16_t sadb_x_ipsecrequest_proto; /* See ipsec.h */ 250 u_int8_t sadb_x_ipsecrequest_mode; /* See IPSEC_MODE_XX in ipsec.h. */ 251 u_int8_t sadb_x_ipsecrequest_level; /* See IPSEC_LEVEL_XX in ipsec.h */ 252 u_int16_t sadb_x_ipsecrequest_reqid; /* See ipsec.h */ 253 254 /* 255 * followed by source IP address of SA, and immediately followed by 256 * destination IP address of SA. These encoded into two of sockaddr 257 * structure without any padding. Must set each sa_len exactly. 258 * Each of length of the sockaddr structure are not aligned to 64bits, 259 * but sum of x_request and addresses is aligned to 64bits. 260 */ 261 }; 262 263 /* NAT-Traversal type, see RFC 3948 (and drafts). */ 264 struct sadb_x_nat_t_type { 265 u_int16_t sadb_x_nat_t_type_len; 266 u_int16_t sadb_x_nat_t_type_exttype; 267 u_int8_t sadb_x_nat_t_type_type; 268 u_int8_t sadb_x_nat_t_type_reserved[3]; 269 }; 270 _Static_assert(sizeof(struct sadb_x_nat_t_type) == 8, "struct size mismatch"); 271 272 /* NAT-Traversal source or destination port. */ 273 struct sadb_x_nat_t_port { 274 u_int16_t sadb_x_nat_t_port_len; 275 u_int16_t sadb_x_nat_t_port_exttype; 276 u_int16_t sadb_x_nat_t_port_port; 277 u_int16_t sadb_x_nat_t_port_reserved; 278 }; 279 _Static_assert(sizeof(struct sadb_x_nat_t_port) == 8, "struct size mismatch"); 280 281 /* ESP fragmentation size. */ 282 struct sadb_x_nat_t_frag { 283 u_int16_t sadb_x_nat_t_frag_len; 284 u_int16_t sadb_x_nat_t_frag_exttype; 285 u_int16_t sadb_x_nat_t_frag_fraglen; 286 u_int16_t sadb_x_nat_t_frag_reserved; 287 }; 288 _Static_assert(sizeof(struct sadb_x_nat_t_frag) == 8, "struct size mismatch"); 289 290 /* Additional large replay window support 291 */ 292 struct sadb_x_sa_replay { 293 u_int16_t sadb_x_sa_replay_len; 294 u_int16_t sadb_x_sa_replay_exttype; 295 u_int32_t sadb_x_sa_replay_replay; /* in packets */ 296 }; 297 _Static_assert(sizeof(struct sadb_x_sa_replay) == 8, "struct size mismatch"); 298 299 #define SADB_EXT_RESERVED 0 300 #define SADB_EXT_SA 1 301 #define SADB_EXT_LIFETIME_CURRENT 2 302 #define SADB_EXT_LIFETIME_HARD 3 303 #define SADB_EXT_LIFETIME_SOFT 4 304 #define SADB_EXT_ADDRESS_SRC 5 305 #define SADB_EXT_ADDRESS_DST 6 306 #define SADB_EXT_ADDRESS_PROXY 7 307 #define SADB_EXT_KEY_AUTH 8 308 #define SADB_EXT_KEY_ENCRYPT 9 309 #define SADB_EXT_IDENTITY_SRC 10 310 #define SADB_EXT_IDENTITY_DST 11 311 #define SADB_EXT_SENSITIVITY 12 312 #define SADB_EXT_PROPOSAL 13 313 #define SADB_EXT_SUPPORTED_AUTH 14 314 #define SADB_EXT_SUPPORTED_ENCRYPT 15 315 #define SADB_EXT_SPIRANGE 16 316 #define SADB_X_EXT_KMPRIVATE 17 317 #define SADB_X_EXT_POLICY 18 318 #define SADB_X_EXT_SA2 19 319 #define SADB_X_EXT_NAT_T_TYPE 20 320 #define SADB_X_EXT_NAT_T_SPORT 21 321 #define SADB_X_EXT_NAT_T_DPORT 22 322 #define SADB_X_EXT_NAT_T_OA 23 /* Deprecated. */ 323 #define SADB_X_EXT_NAT_T_OAI 23 /* Peer's NAT_OA for src of SA. */ 324 #define SADB_X_EXT_NAT_T_OAR 24 /* Peer's NAT_OA for dst of SA. */ 325 #define SADB_X_EXT_NAT_T_FRAG 25 /* Manual MTU override. */ 326 #define SADB_X_EXT_SA_REPLAY 26 /* Replay window override. */ 327 #define SADB_X_EXT_NEW_ADDRESS_SRC 27 328 #define SADB_X_EXT_NEW_ADDRESS_DST 28 329 #define SADB_EXT_MAX 28 330 331 #define SADB_SATYPE_UNSPEC 0 332 #define SADB_SATYPE_AH 2 333 #define SADB_SATYPE_ESP 3 334 #define SADB_SATYPE_RSVP 5 335 #define SADB_SATYPE_OSPFV2 6 336 #define SADB_SATYPE_RIPV2 7 337 #define SADB_SATYPE_MIP 8 338 #define SADB_X_SATYPE_IPCOMP 9 339 /*#define SADB_X_SATYPE_POLICY 10 obsolete, do not reuse */ 340 #define SADB_X_SATYPE_TCPSIGNATURE 11 341 #define SADB_SATYPE_MAX 12 342 343 #define SADB_SASTATE_LARVAL 0 344 #define SADB_SASTATE_MATURE 1 345 #define SADB_SASTATE_DYING 2 346 #define SADB_SASTATE_DEAD 3 347 #define SADB_SASTATE_MAX 3 348 349 #define SADB_SAFLAGS_PFS 1 350 /* SADB_X_SAFLAGS_ESN was defined in sys/net/pfkeyv2.h in OpenBSD sources */ 351 #define SADB_X_SAFLAGS_ESN 0x400 352 353 /* 354 * Though some of these numbers (both _AALG and _EALG) appear to be 355 * IKEv2 numbers and others original IKE numbers, they have no meaning. 356 * These are constants that the various IKE daemons use to tell the kernel 357 * what cipher to use. 358 * 359 * Do not use these constants directly to decide which Transformation ID 360 * to send. You are responsible for mapping them yourself. 361 */ 362 #define SADB_AALG_NONE 0 363 #define SADB_AALG_MD5HMAC 2 364 #define SADB_AALG_SHA1HMAC 3 365 #define SADB_AALG_MAX 252 366 #define SADB_X_AALG_SHA2_256 5 367 #define SADB_X_AALG_SHA2_384 6 368 #define SADB_X_AALG_SHA2_512 7 369 #define SADB_X_AALG_RIPEMD160HMAC 8 370 #define SADB_X_AALG_AES_XCBC_MAC 9 /* RFC3566 */ 371 #define SADB_X_AALG_AES128GMAC 11 /* RFC4543 + Errata1821 */ 372 #define SADB_X_AALG_AES192GMAC 12 373 #define SADB_X_AALG_AES256GMAC 13 374 #define SADB_X_AALG_CHACHA20POLY1305 14 375 #define SADB_X_AALG_MD5 249 /* Keyed MD5 */ 376 #define SADB_X_AALG_SHA 250 /* Keyed SHA */ 377 #define SADB_X_AALG_NULL 251 /* null authentication */ 378 #define SADB_X_AALG_TCP_MD5 252 /* Keyed TCP-MD5 (RFC2385) */ 379 380 #define SADB_EALG_NONE 0 381 #define SADB_EALG_DESCBC 2 382 #define SADB_EALG_3DESCBC 3 383 #define SADB_X_EALG_CAST128CBC 6 384 #define SADB_X_EALG_BLOWFISHCBC 7 385 #define SADB_EALG_NULL 11 386 #define SADB_X_EALG_RIJNDAELCBC 12 387 #define SADB_X_EALG_AES 12 388 #define SADB_X_EALG_AESCBC 12 389 #define SADB_X_EALG_AESCTR 13 390 #define SADB_X_EALG_CHACHA20POLY1305 15 391 #define SADB_X_EALG_AESGCM8 18 /* RFC4106 */ 392 #define SADB_X_EALG_AESGCM12 19 393 #define SADB_X_EALG_AESGCM16 20 394 #define SADB_X_EALG_CAMELLIACBC 22 395 #define SADB_X_EALG_AESGMAC 23 /* RFC4543 + Errata1821 */ 396 #define SADB_EALG_MAX 23 /* !!! keep updated !!! */ 397 398 /* private allocations - based on RFC2407/IANA assignment */ 399 #define SADB_X_CALG_NONE 0 400 #define SADB_X_CALG_OUI 1 401 #define SADB_X_CALG_DEFLATE 2 402 #define SADB_X_CALG_LZS 3 403 #define SADB_X_CALG_MAX 4 404 405 #define SADB_IDENTTYPE_RESERVED 0 406 #define SADB_IDENTTYPE_PREFIX 1 407 #define SADB_IDENTTYPE_FQDN 2 408 #define SADB_IDENTTYPE_USERFQDN 3 409 #define SADB_X_IDENTTYPE_ADDR 4 410 #define SADB_IDENTTYPE_MAX 4 411 412 /* `flags' in sadb_sa structure holds followings */ 413 #define SADB_X_EXT_NONE 0x0000 /* i.e. new format. */ 414 #define SADB_X_EXT_OLD 0x0001 /* old format. */ 415 416 #define SADB_X_EXT_IV4B 0x0010 /* IV length of 4 bytes in use */ 417 #define SADB_X_EXT_DERIV 0x0020 /* DES derived */ 418 #define SADB_X_EXT_CYCSEQ 0x0040 /* allowing to cyclic sequence. */ 419 420 /* three of followings are exclusive flags each them */ 421 #define SADB_X_EXT_PSEQ 0x0000 /* sequencial padding for ESP */ 422 #define SADB_X_EXT_PRAND 0x0100 /* random padding for ESP */ 423 #define SADB_X_EXT_PZERO 0x0200 /* zero padding for ESP */ 424 #define SADB_X_EXT_PMASK 0x0300 /* mask for padding flag */ 425 426 #if 1 427 #define SADB_X_EXT_RAWCPI 0x0080 /* use well known CPI (IPComp) */ 428 #endif 429 430 #define SADB_KEY_FLAGS_MAX 0x0fff 431 432 /* SPI size for PF_KEYv2 */ 433 #define PFKEY_SPI_SIZE sizeof(u_int32_t) 434 435 /* Identifier for member of lifetime structure */ 436 #define SADB_X_LIFETIME_ALLOCATIONS 0 437 #define SADB_X_LIFETIME_BYTES 1 438 #define SADB_X_LIFETIME_ADDTIME 2 439 #define SADB_X_LIFETIME_USETIME 3 440 441 /* The rate for SOFT lifetime against HARD one. */ 442 #define PFKEY_SOFT_LIFETIME_RATE 80 443 444 /* Utilities */ 445 #define PFKEY_ALIGN8(a) (1 + (((a) - 1) | (8 - 1))) 446 #define PFKEY_EXTLEN(msg) \ 447 PFKEY_UNUNIT64(((struct sadb_ext *)(msg))->sadb_ext_len) 448 #define PFKEY_ADDR_PREFIX(ext) \ 449 (((struct sadb_address *)(ext))->sadb_address_prefixlen) 450 #define PFKEY_ADDR_PROTO(ext) \ 451 (((struct sadb_address *)(ext))->sadb_address_proto) 452 #define PFKEY_ADDR_SADDR(ext) \ 453 ((struct sockaddr *)((caddr_t)(ext) + sizeof(struct sadb_address))) 454 455 /* in 64bits */ 456 #define PFKEY_UNUNIT64(a) ((a) << 3) 457 #define PFKEY_UNIT64(a) ((a) >> 3) 458 459 #endif /* __PFKEY_V2_H */ 460 461 #endif /* _NET_PFKEYV2_H_ */ 462