1 /* $OpenBSD: in.h,v 1.78 2008/12/24 07:41:59 dlg Exp $ */ 2 /* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */ 3 4 /* 5 * Copyright (c) 1982, 1986, 1990, 1993 6 * The Regents of the University of California. 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 University 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 REGENTS 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 REGENTS 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 * @(#)in.h 8.3 (Berkeley) 1/3/94 33 */ 34 35 /* 36 * Constants and structures defined by the internet system, 37 * Per RFC 790, September 1981, and numerous additions. 38 */ 39 40 #ifndef _NETINET_IN_H_ 41 #define _NETINET_IN_H_ 42 43 /* 44 * Protocols 45 */ 46 #define IPPROTO_IP 0 /* dummy for IP */ 47 #define IPPROTO_HOPOPTS IPPROTO_IP /* Hop-by-hop option header */ 48 #define IPPROTO_ICMP 1 /* control message protocol */ 49 #define IPPROTO_IGMP 2 /* group mgmt protocol */ 50 #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ 51 #define IPPROTO_IPIP 4 /* IP inside IP */ 52 #define IPPROTO_IPV4 IPPROTO_IPIP /* IP inside IP */ 53 #define IPPROTO_TCP 6 /* tcp */ 54 #define IPPROTO_EGP 8 /* exterior gateway protocol */ 55 #define IPPROTO_PUP 12 /* pup */ 56 #define IPPROTO_UDP 17 /* user datagram protocol */ 57 #define IPPROTO_IDP 22 /* xns idp */ 58 #define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ 59 #define IPPROTO_IPV6 41 /* IPv6 in IPv6 */ 60 #define IPPROTO_ROUTING 43 /* Routing header */ 61 #define IPPROTO_FRAGMENT 44 /* Fragmentation/reassembly header */ 62 #define IPPROTO_RSVP 46 /* resource reservation */ 63 #define IPPROTO_GRE 47 /* GRE encap, RFCs 1701/1702 */ 64 #define IPPROTO_ESP 50 /* Encap. Security Payload */ 65 #define IPPROTO_AH 51 /* Authentication header */ 66 #define IPPROTO_MOBILE 55 /* IP Mobility, RFC 2004 */ 67 #define IPPROTO_ICMPV6 58 /* ICMP for IPv6 */ 68 #define IPPROTO_NONE 59 /* No next header */ 69 #define IPPROTO_DSTOPTS 60 /* Destination options header */ 70 #define IPPROTO_EON 80 /* ISO cnlp */ 71 #define IPPROTO_ETHERIP 97 /* Ethernet in IPv4 */ 72 #define IPPROTO_ENCAP 98 /* encapsulation header */ 73 #define IPPROTO_PIM 103 /* Protocol indep. multicast */ 74 #define IPPROTO_IPCOMP 108 /* IP Payload Comp. Protocol */ 75 #define IPPROTO_CARP 112 /* CARP */ 76 #define IPPROTO_PFSYNC 240 /* PFSYNC */ 77 #define IPPROTO_RAW 255 /* raw IP packet */ 78 79 #define IPPROTO_MAX 256 80 81 /* 82 * From FreeBSD: 83 * 84 * Local port number conventions: 85 * 86 * When a user does a bind(2) or connect(2) with a port number of zero, 87 * a non-conflicting local port address is chosen. 88 * The default range is IPPORT_RESERVED through 89 * IPPORT_USERRESERVED, although that is settable by sysctl. 90 * 91 * A user may set the IPPROTO_IP option IP_PORTRANGE to change this 92 * default assignment range. 93 * 94 * The value IP_PORTRANGE_DEFAULT causes the default behavior. 95 * 96 * The value IP_PORTRANGE_HIGH changes the range of candidate port numbers 97 * into the "high" range. These are reserved for client outbound connections 98 * which do not want to be filtered by any firewalls. 99 * 100 * The value IP_PORTRANGE_LOW changes the range to the "low" are 101 * that is (by convention) restricted to privileged processes. This 102 * convention is based on "vouchsafe" principles only. It is only secure 103 * if you trust the remote host to restrict these ports. 104 * 105 * The default range of ports and the high range can be changed by 106 * sysctl(3). (net.inet.ip.port{hi}{first,last}) 107 * 108 * Changing those values has bad security implications if you are 109 * using a a stateless firewall that is allowing packets outside of that 110 * range in order to allow transparent outgoing connections. 111 * 112 * Such a firewall configuration will generally depend on the use of these 113 * default values. If you change them, you may find your Security 114 * Administrator looking for you with a heavy object. 115 */ 116 117 /* 118 * Ports < IPPORT_RESERVED are reserved for 119 * privileged processes (e.g. root). 120 * Ports > IPPORT_USERRESERVED are reserved 121 * for servers, not necessarily privileged. 122 */ 123 #define IPPORT_RESERVED 1024 124 #define IPPORT_USERRESERVED 49151 125 126 /* 127 * Default local port range to use by setting IP_PORTRANGE_HIGH 128 */ 129 #define IPPORT_HIFIRSTAUTO 49152 130 #define IPPORT_HILASTAUTO 65535 131 132 /* 133 * IP Version 4 Internet address (a structure for historical reasons) 134 */ 135 struct in_addr { 136 in_addr_t s_addr; 137 }; 138 139 /* last return value of *_input(), meaning "all job for this pkt is done". */ 140 #define IPPROTO_DONE 257 141 142 /* 143 * Definitions of bits in internet address integers. 144 * On subnets, the decomposition of addresses to host and net parts 145 * is done according to subnet mask, not the masks here. 146 * 147 * By byte-swapping the constants, we avoid ever having to byte-swap IP 148 * addresses inside the kernel. Unfortunately, user-level programs rely 149 * on these macros not doing byte-swapping. 150 */ 151 #ifdef _KERNEL 152 #define __IPADDR(x) ((u_int32_t) htonl((u_int32_t)(x))) 153 #else 154 #define __IPADDR(x) ((u_int32_t)(x)) 155 #endif 156 157 #define IN_CLASSA(i) (((u_int32_t)(i) & __IPADDR(0x80000000)) == \ 158 __IPADDR(0x00000000)) 159 #define IN_CLASSA_NET __IPADDR(0xff000000) 160 #define IN_CLASSA_NSHIFT 24 161 #define IN_CLASSA_HOST __IPADDR(0x00ffffff) 162 #define IN_CLASSA_MAX 128 163 164 #define IN_CLASSB(i) (((u_int32_t)(i) & __IPADDR(0xc0000000)) == \ 165 __IPADDR(0x80000000)) 166 #define IN_CLASSB_NET __IPADDR(0xffff0000) 167 #define IN_CLASSB_NSHIFT 16 168 #define IN_CLASSB_HOST __IPADDR(0x0000ffff) 169 #define IN_CLASSB_MAX 65536 170 171 #define IN_CLASSC(i) (((u_int32_t)(i) & __IPADDR(0xe0000000)) == \ 172 __IPADDR(0xc0000000)) 173 #define IN_CLASSC_NET __IPADDR(0xffffff00) 174 #define IN_CLASSC_NSHIFT 8 175 #define IN_CLASSC_HOST __IPADDR(0x000000ff) 176 177 #define IN_CLASSD(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \ 178 __IPADDR(0xe0000000)) 179 /* These ones aren't really net and host fields, but routing needn't know. */ 180 #define IN_CLASSD_NET __IPADDR(0xf0000000) 181 #define IN_CLASSD_NSHIFT 28 182 #define IN_CLASSD_HOST __IPADDR(0x0fffffff) 183 #define IN_MULTICAST(i) IN_CLASSD(i) 184 185 #define IN_EXPERIMENTAL(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \ 186 __IPADDR(0xf0000000)) 187 #define IN_BADCLASS(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \ 188 __IPADDR(0xf0000000)) 189 190 #define IN_LOCAL_GROUP(i) (((u_int32_t)(i) & __IPADDR(0xffffff00)) == \ 191 __IPADDR(0xe0000000)) 192 193 #define INADDR_ANY __IPADDR(0x00000000) 194 #define INADDR_LOOPBACK __IPADDR(0x7f000001) 195 #define INADDR_BROADCAST __IPADDR(0xffffffff) /* must be masked */ 196 #ifndef _KERNEL 197 #define INADDR_NONE __IPADDR(0xffffffff) /* -1 return */ 198 #endif 199 200 #define INADDR_UNSPEC_GROUP __IPADDR(0xe0000000) /* 224.0.0.0 */ 201 #define INADDR_ALLHOSTS_GROUP __IPADDR(0xe0000001) /* 224.0.0.1 */ 202 #define INADDR_ALLROUTERS_GROUP __IPADDR(0xe0000002) /* 224.0.0.2 */ 203 #define INADDR_CARP_GROUP __IPADDR(0xe0000012) /* 224.0.0.18 */ 204 #define INADDR_PFSYNC_GROUP __IPADDR(0xe00000f0) /* 224.0.0.240 */ 205 #define INADDR_MAX_LOCAL_GROUP __IPADDR(0xe00000ff) /* 224.0.0.255 */ 206 207 #define IN_LOOPBACKNET 127 /* official! */ 208 209 /* 210 * IP Version 4 socket address. 211 */ 212 struct sockaddr_in { 213 u_int8_t sin_len; 214 sa_family_t sin_family; 215 in_port_t sin_port; 216 struct in_addr sin_addr; 217 int8_t sin_zero[8]; 218 }; 219 220 /* 221 * Structure used to describe IP options. 222 * Used to store options internally, to pass them to a process, 223 * or to restore options retrieved earlier. 224 * The ip_dst is used for the first-hop gateway when using a source route 225 * (this gets put into the header proper). 226 */ 227 struct ip_opts { 228 struct in_addr ip_dst; /* first hop, 0 w/o src rt */ 229 #if defined(__cplusplus) 230 int8_t Ip_opts[40]; /* cannot have same name as class */ 231 #else 232 int8_t ip_opts[40]; /* actually variable in size */ 233 #endif 234 }; 235 236 /* 237 * Options for use with [gs]etsockopt at the IP level. 238 * First word of comment is data type; bool is stored in int. 239 */ 240 #define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */ 241 #define IP_HDRINCL 2 /* int; header is included with data */ 242 #define IP_TOS 3 /* int; IP type of service and preced. */ 243 #define IP_TTL 4 /* int; IP time to live */ 244 #define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */ 245 #define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */ 246 #define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */ 247 #define IP_RETOPTS 8 /* ip_opts; set/get IP options */ 248 #define IP_MULTICAST_IF 9 /* in_addr; set/get IP multicast i/f */ 249 #define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */ 250 #define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */ 251 #define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */ 252 #define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */ 253 254 /* 14-17 left empty for future compatibility with FreeBSD */ 255 256 #define IP_PORTRANGE 19 /* int; range to choose for unspec port */ 257 #define IP_AUTH_LEVEL 20 /* int; authentication used */ 258 #define IP_ESP_TRANS_LEVEL 21 /* int; transport encryption */ 259 #define IP_ESP_NETWORK_LEVEL 22 /* int; full-packet encryption */ 260 #define IP_IPSEC_LOCAL_ID 23 /* buf; IPsec local ID */ 261 #define IP_IPSEC_REMOTE_ID 24 /* buf; IPsec remote ID */ 262 #define IP_IPSEC_LOCAL_CRED 25 /* buf; IPsec local credentials */ 263 #define IP_IPSEC_REMOTE_CRED 26 /* buf; IPsec remote credentials */ 264 #define IP_IPSEC_LOCAL_AUTH 27 /* buf; IPsec local auth material */ 265 #define IP_IPSEC_REMOTE_AUTH 28 /* buf; IPsec remote auth material */ 266 #define IP_IPCOMP_LEVEL 29 /* int; compression used */ 267 #define IP_RECVIF 30 /* bool; receive reception if w/dgram */ 268 #define IP_RECVTTL 31 /* bool; receive IP TTL w/dgram */ 269 #define IP_MINTTL 32 /* minimum TTL for packet or drop */ 270 #define IP_RECVDSTPORT 33 /* bool; receive IP dst port w/dgram */ 271 272 /* 273 * Security levels - IPsec, not IPSO 274 */ 275 276 #define IPSEC_LEVEL_BYPASS 0x00 /* Bypass policy altogether */ 277 #define IPSEC_LEVEL_NONE 0x00 /* Send clear, accept any */ 278 #define IPSEC_LEVEL_AVAIL 0x01 /* Send secure if SA available */ 279 #define IPSEC_LEVEL_USE 0x02 /* Send secure, accept any */ 280 #define IPSEC_LEVEL_REQUIRE 0x03 /* Require secure inbound, also use */ 281 #define IPSEC_LEVEL_UNIQUE 0x04 /* Use outbound SA that is unique */ 282 #define IPSEC_LEVEL_DEFAULT IPSEC_LEVEL_AVAIL 283 284 #define IPSEC_AUTH_LEVEL_DEFAULT IPSEC_LEVEL_DEFAULT 285 #define IPSEC_ESP_TRANS_LEVEL_DEFAULT IPSEC_LEVEL_DEFAULT 286 #define IPSEC_ESP_NETWORK_LEVEL_DEFAULT IPSEC_LEVEL_DEFAULT 287 #define IPSEC_IPCOMP_LEVEL_DEFAULT IPSEC_LEVEL_DEFAULT 288 289 /* 290 * Defaults and limits for options 291 */ 292 #define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ 293 #define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 294 /* 295 * The imo_membership vector for each socket starts at IP_MIN_MEMBERSHIPS 296 * and is dynamically allocated at run-time, bounded by IP_MAX_MEMBERSHIPS, 297 * and is reallocated when needed, sized according to a power-of-two increment. 298 */ 299 #define IP_MIN_MEMBERSHIPS 15 300 #define IP_MAX_MEMBERSHIPS 4095 301 302 /* 303 * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. 304 */ 305 struct ip_mreq { 306 struct in_addr imr_multiaddr; /* IP multicast address of group */ 307 struct in_addr imr_interface; /* local IP address of interface */ 308 }; 309 310 /* 311 * Argument for IP_PORTRANGE: 312 * - which range to search when port is unspecified at bind() or connect() 313 */ 314 #define IP_PORTRANGE_DEFAULT 0 /* default range */ 315 #define IP_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 316 #define IP_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 317 318 /* 319 * Buffer lengths for strings containing printable IP addresses 320 */ 321 #define INET_ADDRSTRLEN 16 322 323 /* 324 * Definitions for inet sysctl operations. 325 * 326 * Third level is protocol number. 327 * Fourth level is desired variable within that protocol. 328 */ 329 #define IPPROTO_MAXID (IPPROTO_PFSYNC + 1) /* don't list to IPPROTO_MAX */ 330 331 #define CTL_IPPROTO_NAMES { \ 332 { "ip", CTLTYPE_NODE }, \ 333 { "icmp", CTLTYPE_NODE }, \ 334 { "igmp", CTLTYPE_NODE }, \ 335 { "ggp", CTLTYPE_NODE }, \ 336 { "ipip", CTLTYPE_NODE }, \ 337 { 0, 0 }, \ 338 { "tcp", CTLTYPE_NODE }, \ 339 { 0, 0 }, \ 340 { "egp", CTLTYPE_NODE }, \ 341 { 0, 0 }, \ 342 { 0, 0 }, \ 343 { 0, 0 }, \ 344 { "pup", CTLTYPE_NODE }, \ 345 { 0, 0 }, \ 346 { 0, 0 }, \ 347 { 0, 0 }, \ 348 { 0, 0 }, \ 349 { "udp", CTLTYPE_NODE }, \ 350 { 0, 0 }, \ 351 { 0, 0 }, \ 352 { 0, 0 }, \ 353 { 0, 0 }, \ 354 { 0, 0 }, \ 355 { 0, 0 }, \ 356 { 0, 0 }, \ 357 { 0, 0 }, \ 358 { 0, 0 }, \ 359 { 0, 0 }, \ 360 { 0, 0 }, \ 361 { 0, 0 }, \ 362 { 0, 0 }, \ 363 { 0, 0 }, \ 364 { 0, 0 }, \ 365 { 0, 0 }, \ 366 { 0, 0 }, \ 367 { 0, 0 }, \ 368 { 0, 0 }, \ 369 { 0, 0 }, \ 370 { 0, 0 }, \ 371 { 0, 0 }, \ 372 { 0, 0 }, \ 373 { 0, 0 }, \ 374 { 0, 0 }, \ 375 { 0, 0 }, \ 376 { 0, 0 }, \ 377 { 0, 0 }, \ 378 { 0, 0 }, \ 379 { "gre", CTLTYPE_NODE }, \ 380 { 0, 0 }, \ 381 { 0, 0 }, \ 382 { "esp", CTLTYPE_NODE }, \ 383 { "ah", CTLTYPE_NODE }, \ 384 { 0, 0 }, \ 385 { 0, 0 }, \ 386 { 0, 0 }, \ 387 { "mobileip", CTLTYPE_NODE }, \ 388 { 0, 0 }, \ 389 { 0, 0 }, \ 390 { 0, 0 }, \ 391 { 0, 0 }, \ 392 { 0, 0 }, \ 393 { 0, 0 }, \ 394 { 0, 0 }, \ 395 { 0, 0 }, \ 396 { 0, 0 }, \ 397 { 0, 0 }, \ 398 { 0, 0 }, \ 399 { 0, 0 }, \ 400 { 0, 0 }, \ 401 { 0, 0 }, \ 402 { 0, 0 }, \ 403 { 0, 0 }, \ 404 { 0, 0 }, \ 405 { 0, 0 }, \ 406 { 0, 0 }, \ 407 { 0, 0 }, \ 408 { 0, 0 }, \ 409 { 0, 0 }, \ 410 { 0, 0 }, \ 411 { 0, 0 }, \ 412 { 0, 0 }, \ 413 { 0, 0 }, \ 414 { 0, 0 }, \ 415 { 0, 0 }, \ 416 { 0, 0 }, \ 417 { 0, 0 }, \ 418 { 0, 0 }, \ 419 { 0, 0 }, \ 420 { 0, 0 }, \ 421 { 0, 0 }, \ 422 { 0, 0 }, \ 423 { 0, 0 }, \ 424 { 0, 0 }, \ 425 { 0, 0 }, \ 426 { 0, 0 }, \ 427 { 0, 0 }, \ 428 { 0, 0 }, \ 429 { "etherip", CTLTYPE_NODE }, \ 430 { 0, 0 }, \ 431 { 0, 0 }, \ 432 { 0, 0 }, \ 433 { 0, 0 }, \ 434 { 0, 0 }, \ 435 { "pim", CTLTYPE_NODE }, \ 436 { 0, 0 }, \ 437 { 0, 0 }, \ 438 { 0, 0 }, \ 439 { 0, 0 }, \ 440 { "ipcomp", CTLTYPE_NODE }, \ 441 { 0, 0 }, \ 442 { 0, 0 }, \ 443 { 0, 0 }, \ 444 { "carp", CTLTYPE_NODE }, \ 445 { 0, 0 }, \ 446 { 0, 0 }, \ 447 { 0, 0 }, \ 448 { 0, 0 }, \ 449 { 0, 0 }, \ 450 { 0, 0 }, \ 451 { 0, 0 }, \ 452 { 0, 0 }, \ 453 { 0, 0 }, \ 454 { 0, 0 }, \ 455 { 0, 0 }, \ 456 { 0, 0 }, \ 457 { 0, 0 }, \ 458 { 0, 0 }, \ 459 { 0, 0 }, \ 460 { 0, 0 }, \ 461 { 0, 0 }, \ 462 { 0, 0 }, \ 463 { 0, 0 }, \ 464 { 0, 0 }, \ 465 { 0, 0 }, \ 466 { 0, 0 }, \ 467 { 0, 0 }, \ 468 { 0, 0 }, \ 469 { 0, 0 }, \ 470 { 0, 0 }, \ 471 { 0, 0 }, \ 472 { 0, 0 }, \ 473 { 0, 0 }, \ 474 { 0, 0 }, \ 475 { 0, 0 }, \ 476 { 0, 0 }, \ 477 { 0, 0 }, \ 478 { 0, 0 }, \ 479 { 0, 0 }, \ 480 { 0, 0 }, \ 481 { 0, 0 }, \ 482 { 0, 0 }, \ 483 { 0, 0 }, \ 484 { 0, 0 }, \ 485 { 0, 0 }, \ 486 { 0, 0 }, \ 487 { 0, 0 }, \ 488 { 0, 0 }, \ 489 { 0, 0 }, \ 490 { 0, 0 }, \ 491 { 0, 0 }, \ 492 { 0, 0 }, \ 493 { 0, 0 }, \ 494 { 0, 0 }, \ 495 { 0, 0 }, \ 496 { 0, 0 }, \ 497 { 0, 0 }, \ 498 { 0, 0 }, \ 499 { 0, 0 }, \ 500 { 0, 0 }, \ 501 { 0, 0 }, \ 502 { 0, 0 }, \ 503 { 0, 0 }, \ 504 { 0, 0 }, \ 505 { 0, 0 }, \ 506 { 0, 0 }, \ 507 { 0, 0 }, \ 508 { 0, 0 }, \ 509 { 0, 0 }, \ 510 { 0, 0 }, \ 511 { 0, 0 }, \ 512 { 0, 0 }, \ 513 { 0, 0 }, \ 514 { 0, 0 }, \ 515 { 0, 0 }, \ 516 { 0, 0 }, \ 517 { 0, 0 }, \ 518 { 0, 0 }, \ 519 { 0, 0 }, \ 520 { 0, 0 }, \ 521 { 0, 0 }, \ 522 { 0, 0 }, \ 523 { 0, 0 }, \ 524 { 0, 0 }, \ 525 { 0, 0 }, \ 526 { 0, 0 }, \ 527 { 0, 0 }, \ 528 { 0, 0 }, \ 529 { 0, 0 }, \ 530 { 0, 0 }, \ 531 { 0, 0 }, \ 532 { 0, 0 }, \ 533 { 0, 0 }, \ 534 { 0, 0 }, \ 535 { 0, 0 }, \ 536 { 0, 0 }, \ 537 { 0, 0 }, \ 538 { 0, 0 }, \ 539 { 0, 0 }, \ 540 { 0, 0 }, \ 541 { 0, 0 }, \ 542 { 0, 0 }, \ 543 { 0, 0 }, \ 544 { 0, 0 }, \ 545 { 0, 0 }, \ 546 { 0, 0 }, \ 547 { 0, 0 }, \ 548 { 0, 0 }, \ 549 { 0, 0 }, \ 550 { 0, 0 }, \ 551 { 0, 0 }, \ 552 { 0, 0 }, \ 553 { 0, 0 }, \ 554 { 0, 0 }, \ 555 { 0, 0 }, \ 556 { 0, 0 }, \ 557 { 0, 0 }, \ 558 { 0, 0 }, \ 559 { 0, 0 }, \ 560 { 0, 0 }, \ 561 { 0, 0 }, \ 562 { 0, 0 }, \ 563 { 0, 0 }, \ 564 { 0, 0 }, \ 565 { 0, 0 }, \ 566 { 0, 0 }, \ 567 { 0, 0 }, \ 568 { 0, 0 }, \ 569 { 0, 0 }, \ 570 { 0, 0 }, \ 571 { 0, 0 }, \ 572 { "pfsync", CTLTYPE_NODE }, \ 573 } 574 575 /* 576 * Names for IP sysctl objects 577 */ 578 #define IPCTL_FORWARDING 1 /* act as router */ 579 #define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */ 580 #define IPCTL_DEFTTL 3 /* default TTL */ 581 #ifdef notyet 582 #define IPCTL_DEFMTU 4 /* default MTU */ 583 #endif 584 #define IPCTL_SOURCEROUTE 5 /* may perform source routes */ 585 #define IPCTL_DIRECTEDBCAST 6 /* default broadcast behavior */ 586 #define IPCTL_IPPORT_FIRSTAUTO 7 587 #define IPCTL_IPPORT_LASTAUTO 8 588 #define IPCTL_IPPORT_HIFIRSTAUTO 9 589 #define IPCTL_IPPORT_HILASTAUTO 10 590 #define IPCTL_IPPORT_MAXQUEUE 11 591 #define IPCTL_ENCDEBUG 12 592 #ifdef notdef /*obsolete*/ 593 #define IPCTL_GIF_TTL 13 /* default TTL for gif encap packet */ 594 #endif 595 #define IPCTL_IPSEC_EXPIRE_ACQUIRE 14 /* How long to wait for key mgmt. */ 596 #define IPCTL_IPSEC_EMBRYONIC_SA_TIMEOUT 15 /* new SA lifetime */ 597 #define IPCTL_IPSEC_REQUIRE_PFS 16 598 #define IPCTL_IPSEC_SOFT_ALLOCATIONS 17 599 #define IPCTL_IPSEC_ALLOCATIONS 18 600 #define IPCTL_IPSEC_SOFT_BYTES 19 601 #define IPCTL_IPSEC_BYTES 20 602 #define IPCTL_IPSEC_TIMEOUT 21 603 #define IPCTL_IPSEC_SOFT_TIMEOUT 22 604 #define IPCTL_IPSEC_SOFT_FIRSTUSE 23 605 #define IPCTL_IPSEC_FIRSTUSE 24 606 #define IPCTL_IPSEC_ENC_ALGORITHM 25 607 #define IPCTL_IPSEC_AUTH_ALGORITHM 26 608 #define IPCTL_MTUDISC 27 /* allow path MTU discovery */ 609 #define IPCTL_MTUDISCTIMEOUT 28 /* allow path MTU discovery */ 610 #define IPCTL_IPSEC_IPCOMP_ALGORITHM 29 611 #define IPCTL_IFQUEUE 30 612 #define IPCTL_MFORWARDING 31 613 #define IPCTL_MULTIPATH 32 614 #define IPCTL_STATS 33 /* IP statistics */ 615 #define IPCTL_MRTPROTO 34 /* type of multicast */ 616 #define IPCTL_MRTSTATS 35 617 #define IPCTL_ARPQUEUED 36 618 #define IPCTL_MAXID 37 619 620 #define IPCTL_NAMES { \ 621 { 0, 0 }, \ 622 { "forwarding", CTLTYPE_INT }, \ 623 { "redirect", CTLTYPE_INT }, \ 624 { "ttl", CTLTYPE_INT }, \ 625 /* { "mtu", CTLTYPE_INT }, */ { 0, 0 }, \ 626 { "sourceroute", CTLTYPE_INT }, \ 627 { "directed-broadcast", CTLTYPE_INT }, \ 628 { "portfirst", CTLTYPE_INT }, \ 629 { "portlast", CTLTYPE_INT }, \ 630 { "porthifirst", CTLTYPE_INT }, \ 631 { "porthilast", CTLTYPE_INT }, \ 632 { "maxqueue", CTLTYPE_INT }, \ 633 { "encdebug", CTLTYPE_INT }, \ 634 { 0, 0 }, \ 635 { "ipsec-expire-acquire", CTLTYPE_INT }, \ 636 { "ipsec-invalid-life", CTLTYPE_INT }, \ 637 { "ipsec-pfs", CTLTYPE_INT }, \ 638 { "ipsec-soft-allocs", CTLTYPE_INT }, \ 639 { "ipsec-allocs", CTLTYPE_INT }, \ 640 { "ipsec-soft-bytes", CTLTYPE_INT }, \ 641 { "ipsec-bytes", CTLTYPE_INT }, \ 642 { "ipsec-timeout", CTLTYPE_INT }, \ 643 { "ipsec-soft-timeout", CTLTYPE_INT }, \ 644 { "ipsec-soft-firstuse", CTLTYPE_INT }, \ 645 { "ipsec-firstuse", CTLTYPE_INT }, \ 646 { "ipsec-enc-alg", CTLTYPE_STRING }, \ 647 { "ipsec-auth-alg", CTLTYPE_STRING }, \ 648 { "mtudisc", CTLTYPE_INT }, \ 649 { "mtudisctimeout", CTLTYPE_INT }, \ 650 { "ipsec-comp-alg", CTLTYPE_STRING }, \ 651 { "ifq", CTLTYPE_NODE }, \ 652 { "mforwarding", CTLTYPE_INT }, \ 653 { "multipath", CTLTYPE_INT }, \ 654 { "stats", CTLTYPE_STRUCT }, \ 655 { "mrtproto", CTLTYPE_INT }, \ 656 { "mrtstats", CTLTYPE_STRUCT }, \ 657 { "arpqueued", CTLTYPE_INT }, \ 658 } 659 #define IPCTL_VARS { \ 660 NULL, \ 661 &ipforwarding, \ 662 &ipsendredirects, \ 663 &ip_defttl, \ 664 NULL, \ 665 NULL, \ 666 &ip_directedbcast, \ 667 &ipport_firstauto, \ 668 &ipport_lastauto, \ 669 &ipport_hifirstauto, \ 670 &ipport_hilastauto, \ 671 &ip_maxqueue, \ 672 &encdebug, \ 673 NULL, \ 674 &ipsec_expire_acquire, \ 675 &ipsec_keep_invalid, \ 676 &ipsec_require_pfs, \ 677 &ipsec_soft_allocations, \ 678 &ipsec_exp_allocations, \ 679 &ipsec_soft_bytes, \ 680 &ipsec_exp_bytes, \ 681 &ipsec_exp_timeout, \ 682 &ipsec_soft_timeout, \ 683 &ipsec_soft_first_use, \ 684 &ipsec_exp_first_use, \ 685 NULL, \ 686 NULL, \ 687 NULL, \ 688 NULL, \ 689 NULL, \ 690 NULL, \ 691 &ipmforwarding, \ 692 &ipmultipath, \ 693 NULL, \ 694 NULL, \ 695 NULL, \ 696 &la_hold_total \ 697 } 698 699 /* INET6 stuff */ 700 #define __KAME_NETINET_IN_H_INCLUDED_ 701 #include <netinet6/in6.h> 702 #undef __KAME_NETINET_IN_H_INCLUDED_ 703 704 #ifndef _KERNEL 705 706 #include <sys/cdefs.h> 707 708 __BEGIN_DECLS 709 int bindresvport(int, struct sockaddr_in *); 710 struct sockaddr; 711 int bindresvport_sa(int, struct sockaddr *); 712 __END_DECLS 713 714 #else 715 /* 716 * in_cksum_phdr: 717 * 718 * Compute significant parts of the IPv4 checksum pseudo-header 719 * for use in a delayed TCP/UDP checksum calculation. 720 * 721 * Args: 722 * 723 * src Source IP address 724 * dst Destination IP address 725 * lenproto htons(proto-hdr-len + proto-number) 726 */ 727 static __inline u_int16_t __attribute__((__unused__)) 728 in_cksum_phdr(u_int32_t src, u_int32_t dst, u_int32_t lenproto) 729 { 730 u_int32_t sum; 731 732 sum = lenproto + 733 (u_int16_t)(src >> 16) + 734 (u_int16_t)(src /*& 0xffff*/) + 735 (u_int16_t)(dst >> 16) + 736 (u_int16_t)(dst /*& 0xffff*/); 737 738 sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/); 739 740 if (sum > 0xffff) 741 sum -= 0xffff; 742 743 return (sum); 744 } 745 746 /* 747 * in_cksum_addword: 748 * 749 * Add the two 16-bit network-order values, carry, and return. 750 */ 751 static __inline u_int16_t __attribute__((__unused__)) 752 in_cksum_addword(u_int16_t a, u_int16_t b) 753 { 754 u_int32_t sum = a + b; 755 756 if (sum > 0xffff) 757 sum -= 0xffff; 758 759 return (sum); 760 } 761 762 extern struct in_addr zeroin_addr; 763 764 int in_broadcast(struct in_addr, struct ifnet *); 765 int in_canforward(struct in_addr); 766 int in_cksum(struct mbuf *, int); 767 int in4_cksum(struct mbuf *, u_int8_t, int, int); 768 void in_delayed_cksum(struct mbuf *); 769 int in_localaddr(struct in_addr); 770 void in_socktrim(struct sockaddr_in *); 771 char *inet_ntoa(struct in_addr); 772 773 #define in_hosteq(s,t) ((s).s_addr == (t).s_addr) 774 #define in_nullhost(x) ((x).s_addr == INADDR_ANY) 775 776 #define satosin(sa) ((struct sockaddr_in *)(sa)) 777 #define sintosa(sin) ((struct sockaddr *)(sin)) 778 #define ifatoia(ifa) ((struct in_ifaddr *)(ifa)) 779 #endif /* _KERNEL */ 780 #endif /* _NETINET_IN_H_ */ 781