1 /* 2 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 * 5 * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 6 * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. 7 */ 8 /* 9 * Copyright (c) 1982, 1986 Regents of the University of California. 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms are permitted 13 * provided that this notice is preserved and that due credit is given 14 * to the University of California at Berkeley. The name of the University 15 * may not be used to endorse or promote products derived from this 16 * software without specific prior written permission. This software 17 * is provided ``as is'' without express or implied warranty. 18 */ 19 20 /* 21 * Constants and structures defined by the internet system, 22 * according to following documents 23 * 24 * Internet ASSIGNED NUMBERS (RFC1700) and its successors: 25 * http://www.iana.org/assignments/protocol-numbers 26 * http://www.iana.org/assignments/port-numbers 27 * Basic Socket Interface Extensions for IPv6 (RFC2133 and its successors) 28 * 29 */ 30 31 #ifndef _NETINET_IN_H 32 #define _NETINET_IN_H 33 34 #include <sys/feature_tests.h> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #include <sys/types.h> 41 42 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 43 #include <sys/socket_impl.h> 44 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 45 46 #ifndef _SOCKLEN_T 47 #define _SOCKLEN_T 48 49 /* 50 * The socklen definitions are reproduced here from sys/socket.h so as to 51 * not introduce that namespace into existing users of netinet/in.h. 52 */ 53 #if defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) 54 typedef size_t socklen_t; 55 #else 56 typedef uint32_t socklen_t; 57 #endif /* defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) */ 58 59 #if defined(_XPG4_2) || defined(_BOOT) 60 typedef socklen_t *Psocklen_t; 61 #else 62 typedef void *Psocklen_t; 63 #endif /* defined(_XPG4_2) || defined(_BOOT) */ 64 65 #endif /* _SOCKLEN_T */ 66 67 /* 68 * Symbols such as htonl() are required to be exposed through this file, 69 * per XNS Issue 5. This is achieved by inclusion of <sys/byteorder.h> 70 */ 71 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) || defined(_XPG5) 72 #include <sys/byteorder.h> 73 #endif 74 75 #ifndef _IN_PORT_T 76 #define _IN_PORT_T 77 typedef uint16_t in_port_t; 78 #endif 79 80 /* 81 * Note: IPv4 address data structures usage conventions. 82 * The "in_addr_t" type below (required by Unix standards) 83 * is NOT a typedef of "struct in_addr" and violates the usual 84 * conventions where "struct <name>" and <name>_t are corresponding 85 * typedefs. 86 * To minimize confusion, kernel data structures/usage prefers use 87 * of "ipaddr_t" as atomic uint32_t type and avoid using "in_addr_t" 88 * The user level APIs continue to follow the historic popular 89 * practice of using "struct in_addr". 90 */ 91 #ifndef _IN_ADDR_T 92 #define _IN_ADDR_T 93 typedef uint32_t in_addr_t; 94 #endif 95 96 #ifndef _IPADDR_T 97 #define _IPADDR_T 98 typedef uint32_t ipaddr_t; 99 #endif 100 101 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) 102 103 struct in6_addr { 104 union { 105 /* 106 * Note: Static initalizers of "union" type assume 107 * the constant on the RHS is the type of the first member 108 * of union. 109 * To make static initializers (and efficient usage) work, 110 * the order of members exposed to user and kernel view of 111 * this data structure is different. 112 * User environment sees specified uint8_t type as first 113 * member whereas kernel sees most efficient type as 114 * first member. 115 */ 116 #ifdef _KERNEL 117 uint32_t _S6_u32[4]; /* IPv6 address */ 118 uint16_t _S6_u16[8]; /* IPv6 address */ 119 uint8_t _S6_u8[16]; /* IPv6 address */ 120 #else 121 uint8_t _S6_u8[16]; /* IPv6 address */ 122 uint16_t _S6_u16[8]; /* IPv6 address */ 123 uint32_t _S6_u32[4]; /* IPv6 address */ 124 #endif 125 uint32_t __S6_align; /* Align on 32 bit boundary */ 126 } _S6_un; 127 }; 128 #define s6_addr _S6_un._S6_u8 129 130 #ifdef _KERNEL 131 #define s6_addr8 _S6_un._S6_u8 132 #define s6_addr16 _S6_un._S6_u16 133 #define s6_addr32 _S6_un._S6_u32 134 #endif 135 136 typedef struct in6_addr in6_addr_t; 137 138 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */ 139 140 #ifndef _SA_FAMILY_T 141 #define _SA_FAMILY_T 142 typedef uint16_t sa_family_t; 143 #endif 144 145 /* 146 * Protocols 147 * 148 * Some of these constant names are copied for the DTrace IP provider in 149 * usr/src/lib/libdtrace/common/{ip.d.in, ip.sed.in}, which should be kept 150 * in sync. 151 */ 152 #define IPPROTO_IP 0 /* dummy for IP */ 153 #define IPPROTO_HOPOPTS 0 /* Hop by hop header for IPv6 */ 154 #define IPPROTO_ICMP 1 /* control message protocol */ 155 #define IPPROTO_IGMP 2 /* group control protocol */ 156 #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ 157 #define IPPROTO_ENCAP 4 /* IP in IP encapsulation */ 158 #define IPPROTO_TCP 6 /* tcp */ 159 #define IPPROTO_EGP 8 /* exterior gateway protocol */ 160 #define IPPROTO_PUP 12 /* pup */ 161 #define IPPROTO_UDP 17 /* user datagram protocol */ 162 #define IPPROTO_IDP 22 /* xns idp */ 163 #define IPPROTO_IPV6 41 /* IPv6 encapsulated in IP */ 164 #define IPPROTO_ROUTING 43 /* Routing header for IPv6 */ 165 #define IPPROTO_FRAGMENT 44 /* Fragment header for IPv6 */ 166 #define IPPROTO_RSVP 46 /* rsvp */ 167 #define IPPROTO_ESP 50 /* IPsec Encap. Sec. Payload */ 168 #define IPPROTO_AH 51 /* IPsec Authentication Hdr. */ 169 #define IPPROTO_ICMPV6 58 /* ICMP for IPv6 */ 170 #define IPPROTO_NONE 59 /* No next header for IPv6 */ 171 #define IPPROTO_DSTOPTS 60 /* Destination options */ 172 #define IPPROTO_HELLO 63 /* "hello" routing protocol */ 173 #define IPPROTO_ND 77 /* UNOFFICIAL net disk proto */ 174 #define IPPROTO_EON 80 /* ISO clnp */ 175 #define IPPROTO_OSPF 89 /* OSPF */ 176 #define IPPROTO_PIM 103 /* PIM routing protocol */ 177 #define IPPROTO_SCTP 132 /* Stream Control */ 178 /* Transmission Protocol */ 179 180 #define IPPROTO_RAW 255 /* raw IP packet */ 181 #define IPPROTO_MAX 256 182 183 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 184 #define PROTO_SDP 257 /* Sockets Direct Protocol */ 185 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 186 187 /* 188 * Port/socket numbers: network standard functions 189 * 190 * Entries should exist here for each port number compiled into an ON 191 * component, such as snoop. 192 */ 193 #define IPPORT_ECHO 7 194 #define IPPORT_DISCARD 9 195 #define IPPORT_SYSTAT 11 196 #define IPPORT_DAYTIME 13 197 #define IPPORT_NETSTAT 15 198 #define IPPORT_CHARGEN 19 199 #define IPPORT_FTP 21 200 #define IPPORT_TELNET 23 201 #define IPPORT_SMTP 25 202 #define IPPORT_TIMESERVER 37 203 #define IPPORT_NAMESERVER 42 204 #define IPPORT_WHOIS 43 205 #define IPPORT_DOMAIN 53 206 #define IPPORT_MDNS 5353 207 #define IPPORT_MTP 57 208 209 /* 210 * Port/socket numbers: host specific functions 211 */ 212 #define IPPORT_BOOTPS 67 213 #define IPPORT_BOOTPC 68 214 #define IPPORT_TFTP 69 215 #define IPPORT_RJE 77 216 #define IPPORT_FINGER 79 217 #define IPPORT_HTTP 80 218 #define IPPORT_HTTP_ALT 8080 219 #define IPPORT_TTYLINK 87 220 #define IPPORT_SUPDUP 95 221 #define IPPORT_NTP 123 222 #define IPPORT_NETBIOS_NS 137 223 #define IPPORT_NETBIOS_DGM 138 224 #define IPPORT_NETBIOS_SSN 139 225 #define IPPORT_LDAP 389 226 #define IPPORT_SLP 427 227 #define IPPORT_MIP 434 228 #define IPPORT_SMB 445 /* a.k.a. microsoft-ds */ 229 #define IPPORT_VXLAN 4789 230 231 /* 232 * Internet Key Exchange (IKE) ports 233 */ 234 #define IPPORT_IKE 500 235 #define IPPORT_IKE_NATT 4500 236 237 /* 238 * UNIX TCP sockets 239 */ 240 #define IPPORT_EXECSERVER 512 241 #define IPPORT_LOGINSERVER 513 242 #define IPPORT_CMDSERVER 514 243 #define IPPORT_PRINTER 515 244 #define IPPORT_EFSSERVER 520 245 246 /* 247 * UNIX UDP sockets 248 */ 249 #define IPPORT_BIFFUDP 512 250 #define IPPORT_WHOSERVER 513 251 #define IPPORT_SYSLOG 514 252 #define IPPORT_TALK 517 253 #define IPPORT_ROUTESERVER 520 254 #define IPPORT_RIPNG 521 255 256 /* 257 * DHCPv6 UDP ports 258 */ 259 #define IPPORT_DHCPV6C 546 260 #define IPPORT_DHCPV6S 547 261 262 #define IPPORT_SOCKS 1080 263 264 /* 265 * Ports < IPPORT_RESERVED are reserved for 266 * privileged processes (e.g. root). 267 * Ports > IPPORT_USERRESERVED are reserved 268 * for servers, not necessarily privileged. 269 */ 270 #define IPPORT_RESERVED 1024 271 #define IPPORT_USERRESERVED 5000 272 273 #ifdef _KERNEL 274 #define IPPORT_DYNAMIC_MIN 49152 275 #define IPPORT_DYNAMIC_MAX 65535 276 #endif 277 278 /* 279 * Link numbers 280 */ 281 #define IMPLINK_IP 155 282 #define IMPLINK_LOWEXPER 156 283 #define IMPLINK_HIGHEXPER 158 284 285 /* 286 * IPv4 Internet address 287 * This definition contains obsolete fields for compatibility 288 * with SunOS 3.x and 4.2bsd. The presence of subnets renders 289 * divisions into fixed fields misleading at best. New code 290 * should use only the s_addr field. 291 */ 292 293 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 294 #define _S_un_b S_un_b 295 #define _S_un_w S_un_w 296 #define _S_addr S_addr 297 #define _S_un S_un 298 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 299 300 struct in_addr { 301 union { 302 struct { uint8_t s_b1, s_b2, s_b3, s_b4; } _S_un_b; 303 struct { uint16_t s_w1, s_w2; } _S_un_w; 304 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 305 uint32_t _S_addr; 306 #else 307 in_addr_t _S_addr; 308 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 309 } _S_un; 310 #define s_addr _S_un._S_addr /* should be used for all code */ 311 #define s_host _S_un._S_un_b.s_b2 /* OBSOLETE: host on imp */ 312 #define s_net _S_un._S_un_b.s_b1 /* OBSOLETE: network */ 313 #define s_imp _S_un._S_un_w.s_w2 /* OBSOLETE: imp */ 314 #define s_impno _S_un._S_un_b.s_b4 /* OBSOLETE: imp # */ 315 #define s_lh _S_un._S_un_b.s_b3 /* OBSOLETE: logical host */ 316 }; 317 318 /* 319 * Definitions of bits in internet address integers. 320 * On subnets, the decomposition of addresses to host and net parts 321 * is done according to subnet mask, not the masks here. 322 * 323 * Note that with the introduction of CIDR, IN_CLASSA, IN_CLASSB, 324 * IN_CLASSC, IN_CLASSD and IN_CLASSE macros have become "de-facto 325 * obsolete". IN_MULTICAST macro should be used to test if a address 326 * is a multicast address. 327 */ 328 #define IN_CLASSA(i) (((i) & 0x80000000U) == 0) 329 #define IN_CLASSA_NET 0xff000000U 330 #define IN_CLASSA_NSHIFT 24 331 #define IN_CLASSA_HOST 0x00ffffffU 332 #define IN_CLASSA_MAX 128 333 334 #define IN_CLASSB(i) (((i) & 0xc0000000U) == 0x80000000U) 335 #define IN_CLASSB_NET 0xffff0000U 336 #define IN_CLASSB_NSHIFT 16 337 #define IN_CLASSB_HOST 0x0000ffffU 338 #define IN_CLASSB_MAX 65536 339 340 #define IN_CLASSC(i) (((i) & 0xe0000000U) == 0xc0000000U) 341 #define IN_CLASSC_NET 0xffffff00U 342 #define IN_CLASSC_NSHIFT 8 343 #define IN_CLASSC_HOST 0x000000ffU 344 345 #define IN_CLASSD(i) (((i) & 0xf0000000U) == 0xe0000000U) 346 #define IN_CLASSD_NET 0xf0000000U /* These aren't really */ 347 #define IN_CLASSD_NSHIFT 28 /* net and host fields, but */ 348 #define IN_CLASSD_HOST 0x0fffffffU /* routing needn't know */ 349 350 #define IN_CLASSE(i) (((i) & 0xf0000000U) == 0xf0000000U) 351 #define IN_CLASSE_NET 0xffffffffU 352 353 #define IN_MULTICAST(i) IN_CLASSD(i) 354 355 /* 356 * We have removed CLASS E checks from the kernel 357 * But we preserve these defines for userland in order 358 * to avoid compile breakage of some 3rd party piece of software 359 */ 360 #ifndef _KERNEL 361 #define IN_EXPERIMENTAL(i) (((i) & 0xe0000000U) == 0xe0000000U) 362 #define IN_BADCLASS(i) (((i) & 0xf0000000U) == 0xf0000000U) 363 #endif 364 365 #define INADDR_ANY 0x00000000U 366 #define INADDR_LOOPBACK 0x7F000001U 367 #define INADDR_BROADCAST 0xffffffffU /* must be masked */ 368 #define INADDR_NONE 0xffffffffU 369 370 #define INADDR_UNSPEC_GROUP 0xe0000000U /* 224.0.0.0 */ 371 #define INADDR_ALLHOSTS_GROUP 0xe0000001U /* 224.0.0.1 */ 372 #define INADDR_ALLRTRS_GROUP 0xe0000002U /* 224.0.0.2 */ 373 #define INADDR_ALLRPTS_GROUP 0xe0000016U /* 224.0.0.22, IGMPv3 */ 374 #define INADDR_MAX_LOCAL_GROUP 0xe00000ffU /* 224.0.0.255 */ 375 376 /* Scoped IPv4 prefixes (in host byte-order) */ 377 #define IN_AUTOCONF_NET 0xa9fe0000U /* 169.254/16 */ 378 #define IN_AUTOCONF_MASK 0xffff0000U 379 #define IN_PRIVATE8_NET 0x0a000000U /* 10/8 */ 380 #define IN_PRIVATE8_MASK 0xff000000U 381 #define IN_PRIVATE12_NET 0xac100000U /* 172.16/12 */ 382 #define IN_PRIVATE12_MASK 0xfff00000U 383 #define IN_PRIVATE16_NET 0xc0a80000U /* 192.168/16 */ 384 #define IN_PRIVATE16_MASK 0xffff0000U 385 386 /* RFC 3927 IPv4 link local address (i in host byte-order) */ 387 #define IN_LINKLOCAL(i) (((i) & IN_AUTOCONF_MASK) == IN_AUTOCONF_NET) 388 389 /* Well known 6to4 Relay Router Anycast address defined in RFC 3068 */ 390 #if !defined(_XPG4_2) || !defined(__EXTENSIONS__) 391 #define INADDR_6TO4RRANYCAST 0xc0586301U /* 192.88.99.1 */ 392 #endif /* !defined(_XPG4_2) || !defined(__EXTENSIONS__) */ 393 394 #define IN_LOOPBACKNET 127 /* official! */ 395 396 /* 397 * Define a macro to stuff the loopback address into an Internet address 398 */ 399 #if !defined(_XPG4_2) || !defined(__EXTENSIONS__) 400 #define IN_SET_LOOPBACK_ADDR(a) \ 401 { (a)->sin_addr.s_addr = htonl(INADDR_LOOPBACK); \ 402 (a)->sin_family = AF_INET; } 403 #endif /* !defined(_XPG4_2) || !defined(__EXTENSIONS__) */ 404 405 /* 406 * IPv4 Socket address. 407 */ 408 struct sockaddr_in { 409 sa_family_t sin_family; 410 in_port_t sin_port; 411 struct in_addr sin_addr; 412 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 413 char sin_zero[8]; 414 #else 415 unsigned char sin_zero[8]; 416 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 417 }; 418 419 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) 420 /* 421 * IPv6 socket address. 422 */ 423 struct sockaddr_in6 { 424 sa_family_t sin6_family; 425 in_port_t sin6_port; 426 uint32_t sin6_flowinfo; 427 struct in6_addr sin6_addr; 428 uint32_t sin6_scope_id; /* Depends on scope of sin6_addr */ 429 uint32_t __sin6_src_id; /* Impl. specific - UDP replies */ 430 }; 431 432 /* 433 * Macros for accessing the traffic class and flow label fields from 434 * sin6_flowinfo. 435 * These are designed to be applied to a 32-bit value. 436 */ 437 #ifdef _BIG_ENDIAN 438 439 /* masks */ 440 #define IPV6_FLOWINFO_FLOWLABEL 0x000fffffU 441 #define IPV6_FLOWINFO_TCLASS 0x0ff00000U 442 443 #else /* _BIG_ENDIAN */ 444 445 /* masks */ 446 #define IPV6_FLOWINFO_FLOWLABEL 0xffff0f00U 447 #define IPV6_FLOWINFO_TCLASS 0x0000f00fU 448 449 #endif /* _BIG_ENDIAN */ 450 451 /* 452 * Note: Macros IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT are for 453 * use as RHS of Static initializers of "struct in6_addr" (or in6_addr_t) 454 * only. They need to be different for User/Kernel versions because union 455 * component data structure is defined differently (it is identical at 456 * binary representation level). 457 * 458 * const struct in6_addr IN6ADDR_ANY_INIT; 459 * const struct in6_addr IN6ADDR_LOOPBACK_INIT; 460 */ 461 462 463 #ifdef _KERNEL 464 #define IN6ADDR_ANY_INIT { 0, 0, 0, 0 } 465 466 #ifdef _BIG_ENDIAN 467 #define IN6ADDR_LOOPBACK_INIT { 0, 0, 0, 0x00000001U } 468 #else /* _BIG_ENDIAN */ 469 #define IN6ADDR_LOOPBACK_INIT { 0, 0, 0, 0x01000000U } 470 #endif /* _BIG_ENDIAN */ 471 472 #else 473 474 #define IN6ADDR_ANY_INIT { 0, 0, 0, 0, \ 475 0, 0, 0, 0, \ 476 0, 0, 0, 0, \ 477 0, 0, 0, 0 } 478 479 #define IN6ADDR_LOOPBACK_INIT { 0, 0, 0, 0, \ 480 0, 0, 0, 0, \ 481 0, 0, 0, 0, \ 482 0, 0, 0, 0x1U } 483 #endif /* _KERNEL */ 484 485 /* 486 * RFC 2553 specifies the following macros. Their type is defined 487 * as "int" in the RFC but they only have boolean significance 488 * (zero or non-zero). For the purposes of our comment notation, 489 * we assume a hypothetical type "bool" defined as follows to 490 * write the prototypes assumed for macros in our comments better. 491 * 492 * typedef int bool; 493 */ 494 495 /* 496 * IN6 macros used to test for special IPv6 addresses 497 * (Mostly from spec) 498 * 499 * bool IN6_IS_ADDR_UNSPECIFIED (const struct in6_addr *); 500 * bool IN6_IS_ADDR_LOOPBACK (const struct in6_addr *); 501 * bool IN6_IS_ADDR_MULTICAST (const struct in6_addr *); 502 * bool IN6_IS_ADDR_LINKLOCAL (const struct in6_addr *); 503 * bool IN6_IS_ADDR_SITELOCAL (const struct in6_addr *); 504 * bool IN6_IS_ADDR_V4MAPPED (const struct in6_addr *); 505 * bool IN6_IS_ADDR_V4MAPPED_ANY(const struct in6_addr *); -- Not from RFC2553 506 * bool IN6_IS_ADDR_V4COMPAT (const struct in6_addr *); 507 * bool IN6_IS_ADDR_MC_RESERVED (const struct in6_addr *); -- Not from RFC2553 508 * bool IN6_IS_ADDR_MC_NODELOCAL(const struct in6_addr *); 509 * bool IN6_IS_ADDR_MC_LINKLOCAL(const struct in6_addr *); 510 * bool IN6_IS_ADDR_MC_SITELOCAL(const struct in6_addr *); 511 * bool IN6_IS_ADDR_MC_ORGLOCAL (const struct in6_addr *); 512 * bool IN6_IS_ADDR_MC_GLOBAL (const struct in6_addr *); 513 * bool IN6_IS_ADDR_6TO4 (const struct in6_addr *); -- Not from RFC2553 514 * bool IN6_ARE_6TO4_PREFIX_EQUAL(const struct in6_addr *, 515 * const struct in6_addr *); -- Not from RFC2553 516 * bool IN6_IS_ADDR_LINKSCOPE (const struct in6addr *); -- Not from RFC2553 517 */ 518 519 #define IN6_IS_ADDR_UNSPECIFIED(addr) \ 520 (((addr)->_S6_un._S6_u32[3] == 0) && \ 521 ((addr)->_S6_un._S6_u32[2] == 0) && \ 522 ((addr)->_S6_un._S6_u32[1] == 0) && \ 523 ((addr)->_S6_un._S6_u32[0] == 0)) 524 525 #ifdef _BIG_ENDIAN 526 #define IN6_IS_ADDR_LOOPBACK(addr) \ 527 (((addr)->_S6_un._S6_u32[3] == 0x00000001) && \ 528 ((addr)->_S6_un._S6_u32[2] == 0) && \ 529 ((addr)->_S6_un._S6_u32[1] == 0) && \ 530 ((addr)->_S6_un._S6_u32[0] == 0)) 531 #else /* _BIG_ENDIAN */ 532 #define IN6_IS_ADDR_LOOPBACK(addr) \ 533 (((addr)->_S6_un._S6_u32[3] == 0x01000000) && \ 534 ((addr)->_S6_un._S6_u32[2] == 0) && \ 535 ((addr)->_S6_un._S6_u32[1] == 0) && \ 536 ((addr)->_S6_un._S6_u32[0] == 0)) 537 #endif /* _BIG_ENDIAN */ 538 539 #ifdef _BIG_ENDIAN 540 #define IN6_IS_ADDR_MULTICAST(addr) \ 541 (((addr)->_S6_un._S6_u32[0] & 0xff000000) == 0xff000000) 542 #else /* _BIG_ENDIAN */ 543 #define IN6_IS_ADDR_MULTICAST(addr) \ 544 (((addr)->_S6_un._S6_u32[0] & 0x000000ff) == 0x000000ff) 545 #endif /* _BIG_ENDIAN */ 546 547 #ifdef _BIG_ENDIAN 548 #define IN6_IS_ADDR_LINKLOCAL(addr) \ 549 (((addr)->_S6_un._S6_u32[0] & 0xffc00000) == 0xfe800000) 550 #else /* _BIG_ENDIAN */ 551 #define IN6_IS_ADDR_LINKLOCAL(addr) \ 552 (((addr)->_S6_un._S6_u32[0] & 0x0000c0ff) == 0x000080fe) 553 #endif /* _BIG_ENDIAN */ 554 555 #ifdef _BIG_ENDIAN 556 #define IN6_IS_ADDR_SITELOCAL(addr) \ 557 (((addr)->_S6_un._S6_u32[0] & 0xffc00000) == 0xfec00000) 558 #else /* _BIG_ENDIAN */ 559 #define IN6_IS_ADDR_SITELOCAL(addr) \ 560 (((addr)->_S6_un._S6_u32[0] & 0x0000c0ff) == 0x0000c0fe) 561 #endif /* _BIG_ENDIAN */ 562 563 #ifdef _BIG_ENDIAN 564 #define IN6_IS_ADDR_V4MAPPED(addr) \ 565 (((addr)->_S6_un._S6_u32[2] == 0x0000ffff) && \ 566 ((addr)->_S6_un._S6_u32[1] == 0) && \ 567 ((addr)->_S6_un._S6_u32[0] == 0)) 568 #else /* _BIG_ENDIAN */ 569 #define IN6_IS_ADDR_V4MAPPED(addr) \ 570 (((addr)->_S6_un._S6_u32[2] == 0xffff0000U) && \ 571 ((addr)->_S6_un._S6_u32[1] == 0) && \ 572 ((addr)->_S6_un._S6_u32[0] == 0)) 573 #endif /* _BIG_ENDIAN */ 574 575 /* 576 * IN6_IS_ADDR_V4MAPPED - A IPv4 mapped INADDR_ANY 577 * Note: This macro is currently NOT defined in RFC2553 specification 578 * and not a standard macro that portable applications should use. 579 */ 580 #ifdef _BIG_ENDIAN 581 #define IN6_IS_ADDR_V4MAPPED_ANY(addr) \ 582 (((addr)->_S6_un._S6_u32[3] == 0) && \ 583 ((addr)->_S6_un._S6_u32[2] == 0x0000ffff) && \ 584 ((addr)->_S6_un._S6_u32[1] == 0) && \ 585 ((addr)->_S6_un._S6_u32[0] == 0)) 586 #else /* _BIG_ENDIAN */ 587 #define IN6_IS_ADDR_V4MAPPED_ANY(addr) \ 588 (((addr)->_S6_un._S6_u32[3] == 0) && \ 589 ((addr)->_S6_un._S6_u32[2] == 0xffff0000U) && \ 590 ((addr)->_S6_un._S6_u32[1] == 0) && \ 591 ((addr)->_S6_un._S6_u32[0] == 0)) 592 #endif /* _BIG_ENDIAN */ 593 594 /* Exclude loopback and unspecified address */ 595 #ifdef _BIG_ENDIAN 596 #define IN6_IS_ADDR_V4COMPAT(addr) \ 597 (((addr)->_S6_un._S6_u32[2] == 0) && \ 598 ((addr)->_S6_un._S6_u32[1] == 0) && \ 599 ((addr)->_S6_un._S6_u32[0] == 0) && \ 600 !((addr)->_S6_un._S6_u32[3] == 0) && \ 601 !((addr)->_S6_un._S6_u32[3] == 0x00000001)) 602 603 #else /* _BIG_ENDIAN */ 604 #define IN6_IS_ADDR_V4COMPAT(addr) \ 605 (((addr)->_S6_un._S6_u32[2] == 0) && \ 606 ((addr)->_S6_un._S6_u32[1] == 0) && \ 607 ((addr)->_S6_un._S6_u32[0] == 0) && \ 608 !((addr)->_S6_un._S6_u32[3] == 0) && \ 609 !((addr)->_S6_un._S6_u32[3] == 0x01000000)) 610 #endif /* _BIG_ENDIAN */ 611 612 /* 613 * Note: 614 * IN6_IS_ADDR_MC_RESERVED macro is currently NOT defined in RFC2553 615 * specification and not a standard macro that portable applications 616 * should use. 617 */ 618 #ifdef _BIG_ENDIAN 619 #define IN6_IS_ADDR_MC_RESERVED(addr) \ 620 (((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff000000) 621 622 #else /* _BIG_ENDIAN */ 623 #define IN6_IS_ADDR_MC_RESERVED(addr) \ 624 (((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000000ff) 625 #endif /* _BIG_ENDIAN */ 626 627 #ifdef _BIG_ENDIAN 628 #define IN6_IS_ADDR_MC_NODELOCAL(addr) \ 629 (((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff010000) 630 #else /* _BIG_ENDIAN */ 631 #define IN6_IS_ADDR_MC_NODELOCAL(addr) \ 632 (((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000001ff) 633 #endif /* _BIG_ENDIAN */ 634 635 #ifdef _BIG_ENDIAN 636 #define IN6_IS_ADDR_MC_LINKLOCAL(addr) \ 637 (((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff020000) 638 #else /* _BIG_ENDIAN */ 639 #define IN6_IS_ADDR_MC_LINKLOCAL(addr) \ 640 (((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000002ff) 641 #endif /* _BIG_ENDIAN */ 642 643 #ifdef _BIG_ENDIAN 644 #define IN6_IS_ADDR_MC_SITELOCAL(addr) \ 645 (((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff050000) 646 #else /* _BIG_ENDIAN */ 647 #define IN6_IS_ADDR_MC_SITELOCAL(addr) \ 648 (((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000005ff) 649 #endif /* _BIG_ENDIAN */ 650 651 #ifdef _BIG_ENDIAN 652 #define IN6_IS_ADDR_MC_ORGLOCAL(addr) \ 653 (((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff080000) 654 #else /* _BIG_ENDIAN */ 655 #define IN6_IS_ADDR_MC_ORGLOCAL(addr) \ 656 (((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000008ff) 657 #endif /* _BIG_ENDIAN */ 658 659 #ifdef _BIG_ENDIAN 660 #define IN6_IS_ADDR_MC_GLOBAL(addr) \ 661 (((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff0e0000) 662 #else /* _BIG_ENDIAN */ 663 #define IN6_IS_ADDR_MC_GLOBAL(addr) \ 664 (((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x00000eff) 665 #endif /* _BIG_ENDIAN */ 666 667 /* 668 * The IN6_IS_ADDR_MC_SOLICITEDNODE macro is not defined in any standard or 669 * RFC, and shouldn't be used by portable applications. It is used to see 670 * if an address is a solicited-node multicast address, which is prefixed 671 * with ff02:0:0:0:0:1:ff00::/104. 672 */ 673 #ifdef _BIG_ENDIAN 674 #define IN6_IS_ADDR_MC_SOLICITEDNODE(addr) \ 675 (((addr)->_S6_un._S6_u32[0] == 0xff020000) && \ 676 ((addr)->_S6_un._S6_u32[1] == 0x00000000) && \ 677 ((addr)->_S6_un._S6_u32[2] == 0x00000001) && \ 678 (((addr)->_S6_un._S6_u32[3] & 0xff000000) == 0xff000000)) 679 #else 680 #define IN6_IS_ADDR_MC_SOLICITEDNODE(addr) \ 681 (((addr)->_S6_un._S6_u32[0] == 0x000002ff) && \ 682 ((addr)->_S6_un._S6_u32[1] == 0x00000000) && \ 683 ((addr)->_S6_un._S6_u32[2] == 0x01000000) && \ 684 (((addr)->_S6_un._S6_u32[3] & 0x000000ff) == 0x000000ff)) 685 #endif 686 687 /* 688 * Macros to a) test for 6to4 IPv6 address, and b) to test if two 689 * 6to4 addresses have the same /48 prefix, and, hence, are from the 690 * same 6to4 site. 691 */ 692 693 #ifdef _BIG_ENDIAN 694 #define IN6_IS_ADDR_6TO4(addr) \ 695 (((addr)->_S6_un._S6_u32[0] & 0xffff0000) == 0x20020000) 696 #else /* _BIG_ENDIAN */ 697 #define IN6_IS_ADDR_6TO4(addr) \ 698 (((addr)->_S6_un._S6_u32[0] & 0x0000ffff) == 0x00000220) 699 #endif /* _BIG_ENDIAN */ 700 701 #define IN6_ARE_6TO4_PREFIX_EQUAL(addr1, addr2) \ 702 (((addr1)->_S6_un._S6_u32[0] == (addr2)->_S6_un._S6_u32[0]) && \ 703 ((addr1)->_S6_un._S6_u8[4] == (addr2)->_S6_un._S6_u8[4]) && \ 704 ((addr1)->_S6_un._S6_u8[5] == (addr2)->_S6_un._S6_u8[5])) 705 706 /* 707 * IN6_IS_ADDR_LINKSCOPE 708 * Identifies an address as being either link-local, link-local multicast or 709 * node-local multicast. All types of addresses are considered to be unique 710 * within the scope of a given link. 711 */ 712 #define IN6_IS_ADDR_LINKSCOPE(addr) \ 713 (IN6_IS_ADDR_LINKLOCAL(addr) || IN6_IS_ADDR_MC_LINKLOCAL(addr) || \ 714 IN6_IS_ADDR_MC_NODELOCAL(addr)) 715 716 /* 717 * Useful utility macros for operations with IPv6 addresses 718 * Note: These macros are NOT defined in the RFC2553 or any other 719 * standard specification and are not standard macros that portable 720 * applications should use. 721 */ 722 723 /* 724 * IN6_V4MAPPED_TO_INADDR 725 * IN6_V4MAPPED_TO_IPADDR 726 * Assign a IPv4-Mapped IPv6 address to an IPv4 address. 727 * Note: These macros are NOT defined in RFC2553 or any other standard 728 * specification and are not macros that portable applications should 729 * use. 730 * 731 * void IN6_V4MAPPED_TO_INADDR(const in6_addr_t *v6, struct in_addr *v4); 732 * void IN6_V4MAPPED_TO_IPADDR(const in6_addr_t *v6, ipaddr_t v4); 733 * 734 */ 735 #define IN6_V4MAPPED_TO_INADDR(v6, v4) \ 736 ((v4)->s_addr = (v6)->_S6_un._S6_u32[3]) 737 #define IN6_V4MAPPED_TO_IPADDR(v6, v4) \ 738 ((v4) = (v6)->_S6_un._S6_u32[3]) 739 740 /* 741 * IN6_INADDR_TO_V4MAPPED 742 * IN6_IPADDR_TO_V4MAPPED 743 * Assign a IPv4 address address to an IPv6 address as a IPv4-mapped 744 * address. 745 * Note: These macros are NOT defined in RFC2553 or any other standard 746 * specification and are not macros that portable applications should 747 * use. 748 * 749 * void IN6_INADDR_TO_V4MAPPED(const struct in_addr *v4, in6_addr_t *v6); 750 * void IN6_IPADDR_TO_V4MAPPED(const ipaddr_t v4, in6_addr_t *v6); 751 * 752 */ 753 #ifdef _BIG_ENDIAN 754 #define IN6_INADDR_TO_V4MAPPED(v4, v6) \ 755 ((v6)->_S6_un._S6_u32[3] = (v4)->s_addr, \ 756 (v6)->_S6_un._S6_u32[2] = 0x0000ffff, \ 757 (v6)->_S6_un._S6_u32[1] = 0, \ 758 (v6)->_S6_un._S6_u32[0] = 0) 759 #define IN6_IPADDR_TO_V4MAPPED(v4, v6) \ 760 ((v6)->_S6_un._S6_u32[3] = (v4), \ 761 (v6)->_S6_un._S6_u32[2] = 0x0000ffff, \ 762 (v6)->_S6_un._S6_u32[1] = 0, \ 763 (v6)->_S6_un._S6_u32[0] = 0) 764 #else /* _BIG_ENDIAN */ 765 #define IN6_INADDR_TO_V4MAPPED(v4, v6) \ 766 ((v6)->_S6_un._S6_u32[3] = (v4)->s_addr, \ 767 (v6)->_S6_un._S6_u32[2] = 0xffff0000U, \ 768 (v6)->_S6_un._S6_u32[1] = 0, \ 769 (v6)->_S6_un._S6_u32[0] = 0) 770 #define IN6_IPADDR_TO_V4MAPPED(v4, v6) \ 771 ((v6)->_S6_un._S6_u32[3] = (v4), \ 772 (v6)->_S6_un._S6_u32[2] = 0xffff0000U, \ 773 (v6)->_S6_un._S6_u32[1] = 0, \ 774 (v6)->_S6_un._S6_u32[0] = 0) 775 #endif /* _BIG_ENDIAN */ 776 777 /* 778 * IN6_6TO4_TO_V4ADDR 779 * Extract the embedded IPv4 address from the prefix to a 6to4 IPv6 780 * address. 781 * Note: This macro is NOT defined in RFC2553 or any other standard 782 * specification and is not a macro that portable applications should 783 * use. 784 * Note: we don't use the IPADDR form of the macro because we need 785 * to do a bytewise copy; the V4ADDR in the 6to4 address is not 786 * 32-bit aligned. 787 * 788 * void IN6_6TO4_TO_V4ADDR(const in6_addr_t *v6, struct in_addr *v4); 789 * 790 */ 791 #define IN6_6TO4_TO_V4ADDR(v6, v4) \ 792 ((v4)->_S_un._S_un_b.s_b1 = (v6)->_S6_un._S6_u8[2], \ 793 (v4)->_S_un._S_un_b.s_b2 = (v6)->_S6_un._S6_u8[3], \ 794 (v4)->_S_un._S_un_b.s_b3 = (v6)->_S6_un._S6_u8[4], \ 795 (v4)->_S_un._S_un_b.s_b4 = (v6)->_S6_un._S6_u8[5]) 796 797 /* 798 * IN6_V4ADDR_TO_6TO4 799 * Given an IPv4 address and an IPv6 address for output, a 6to4 address 800 * will be created from the IPv4 Address. 801 * Note: This method for creating 6to4 addresses is not standardized 802 * outside of Solaris. The newly created 6to4 address will be of the form 803 * 2002:<V4ADDR>:<SUBNETID>::<HOSTID>, where SUBNETID will equal 0 and 804 * HOSTID will equal 1. 805 * 806 * void IN6_V4ADDR_TO_6TO4(const struct in_addr *v4, in6_addr_t *v6) 807 * 808 */ 809 #ifdef _BIG_ENDIAN 810 #define IN6_V4ADDR_TO_6TO4(v4, v6) \ 811 ((v6)->_S6_un._S6_u8[0] = 0x20, \ 812 (v6)->_S6_un._S6_u8[1] = 0x02, \ 813 (v6)->_S6_un._S6_u8[2] = (v4)->_S_un._S_un_b.s_b1, \ 814 (v6)->_S6_un._S6_u8[3] = (v4)->_S_un._S_un_b.s_b2, \ 815 (v6)->_S6_un._S6_u8[4] = (v4)->_S_un._S_un_b.s_b3, \ 816 (v6)->_S6_un._S6_u8[5] = (v4)->_S_un._S_un_b.s_b4, \ 817 (v6)->_S6_un._S6_u8[6] = 0, \ 818 (v6)->_S6_un._S6_u8[7] = 0, \ 819 (v6)->_S6_un._S6_u32[2] = 0, \ 820 (v6)->_S6_un._S6_u32[3] = 0x00000001U) 821 #else 822 #define IN6_V4ADDR_TO_6TO4(v4, v6) \ 823 ((v6)->_S6_un._S6_u8[0] = 0x20, \ 824 (v6)->_S6_un._S6_u8[1] = 0x02, \ 825 (v6)->_S6_un._S6_u8[2] = (v4)->_S_un._S_un_b.s_b1, \ 826 (v6)->_S6_un._S6_u8[3] = (v4)->_S_un._S_un_b.s_b2, \ 827 (v6)->_S6_un._S6_u8[4] = (v4)->_S_un._S_un_b.s_b3, \ 828 (v6)->_S6_un._S6_u8[5] = (v4)->_S_un._S_un_b.s_b4, \ 829 (v6)->_S6_un._S6_u8[6] = 0, \ 830 (v6)->_S6_un._S6_u8[7] = 0, \ 831 (v6)->_S6_un._S6_u32[2] = 0, \ 832 (v6)->_S6_un._S6_u32[3] = 0x01000000U) 833 #endif /* _BIG_ENDIAN */ 834 835 /* 836 * IN6_ARE_ADDR_EQUAL (defined in RFC2292) 837 * Compares if IPv6 addresses are equal. 838 * Note: Compares in order of high likelyhood of a miss so we minimize 839 * compares. (Current heuristic order, compare in reverse order of 840 * uint32_t units) 841 * 842 * bool IN6_ARE_ADDR_EQUAL(const struct in6_addr *, 843 * const struct in6_addr *); 844 */ 845 #define IN6_ARE_ADDR_EQUAL(addr1, addr2) \ 846 (((addr1)->_S6_un._S6_u32[3] == (addr2)->_S6_un._S6_u32[3]) && \ 847 ((addr1)->_S6_un._S6_u32[2] == (addr2)->_S6_un._S6_u32[2]) && \ 848 ((addr1)->_S6_un._S6_u32[1] == (addr2)->_S6_un._S6_u32[1]) && \ 849 ((addr1)->_S6_un._S6_u32[0] == (addr2)->_S6_un._S6_u32[0])) 850 851 /* 852 * IN6_ARE_PREFIXEDADDR_EQUAL (not defined in RFCs) 853 * Compares if prefixed parts of IPv6 addresses are equal. 854 * 855 * uint32_t IN6_MASK_FROM_PREFIX(int, int); 856 * bool IN6_ARE_PREFIXEDADDR_EQUAL(const struct in6_addr *, 857 * const struct in6_addr *, 858 * int); 859 */ 860 #define IN6_MASK_FROM_PREFIX(qoctet, prefix) \ 861 ((((qoctet) + 1) * 32 < (prefix)) ? 0xFFFFFFFFu : \ 862 ((((qoctet) * 32) >= (prefix)) ? 0x00000000u : \ 863 0xFFFFFFFFu << (((qoctet) + 1) * 32 - (prefix)))) 864 865 #define IN6_ARE_PREFIXEDADDR_EQUAL(addr1, addr2, prefix) \ 866 (((ntohl((addr1)->_S6_un._S6_u32[0]) & \ 867 IN6_MASK_FROM_PREFIX(0, prefix)) == \ 868 (ntohl((addr2)->_S6_un._S6_u32[0]) & \ 869 IN6_MASK_FROM_PREFIX(0, prefix))) && \ 870 ((ntohl((addr1)->_S6_un._S6_u32[1]) & \ 871 IN6_MASK_FROM_PREFIX(1, prefix)) == \ 872 (ntohl((addr2)->_S6_un._S6_u32[1]) & \ 873 IN6_MASK_FROM_PREFIX(1, prefix))) && \ 874 ((ntohl((addr1)->_S6_un._S6_u32[2]) & \ 875 IN6_MASK_FROM_PREFIX(2, prefix)) == \ 876 (ntohl((addr2)->_S6_un._S6_u32[2]) & \ 877 IN6_MASK_FROM_PREFIX(2, prefix))) && \ 878 ((ntohl((addr1)->_S6_un._S6_u32[3]) & \ 879 IN6_MASK_FROM_PREFIX(3, prefix)) == \ 880 (ntohl((addr2)->_S6_un._S6_u32[3]) & \ 881 IN6_MASK_FROM_PREFIX(3, prefix)))) 882 883 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */ 884 885 886 /* 887 * Options for use with [gs]etsockopt at the IP level. 888 * 889 * Note: Some of the IP_ namespace has conflict with and 890 * and is exposed through <xti.h>. (It also requires exposing 891 * options not implemented). The options with potential 892 * for conflicts use #ifndef guards. 893 */ 894 #ifndef IP_OPTIONS 895 #define IP_OPTIONS 1 /* set/get IP per-packet options */ 896 #endif 897 898 #define IP_HDRINCL 2 /* int; header is included with data (raw) */ 899 900 #ifndef IP_TOS 901 #define IP_TOS 3 /* int; IP type of service and precedence */ 902 #endif 903 904 #ifndef IP_TTL 905 #define IP_TTL 4 /* int; IP time to live */ 906 #endif 907 908 #define IP_RECVOPTS 0x5 /* int; receive all IP options w/datagram */ 909 #define IP_RECVRETOPTS 0x6 /* int; receive IP options for response */ 910 #define IP_RECVDSTADDR 0x7 /* int; receive IP dst addr w/datagram */ 911 #define IP_RETOPTS 0x8 /* ip_opts; set/get IP per-packet options */ 912 #define IP_RECVIF 0x9 /* int; receive the inbound interface index */ 913 #define IP_RECVSLLA 0xa /* sockaddr_dl; get source link layer address */ 914 #define IP_RECVTTL 0xb /* uint8_t; get TTL for inbound packet */ 915 #define IP_RECVTOS 0xc /* uint8_t; get TOS for inbound packet */ 916 917 #define IP_MULTICAST_IF 0x10 /* set/get IP multicast interface */ 918 #define IP_MULTICAST_TTL 0x11 /* set/get IP multicast timetolive */ 919 #define IP_MULTICAST_LOOP 0x12 /* set/get IP multicast loopback */ 920 #define IP_ADD_MEMBERSHIP 0x13 /* add an IP group membership */ 921 #define IP_DROP_MEMBERSHIP 0x14 /* drop an IP group membership */ 922 #define IP_BLOCK_SOURCE 0x15 /* block mcast pkts from source */ 923 #define IP_UNBLOCK_SOURCE 0x16 /* unblock mcast pkts from source */ 924 #define IP_ADD_SOURCE_MEMBERSHIP 0x17 /* add mcast group/source pair */ 925 #define IP_DROP_SOURCE_MEMBERSHIP 0x18 /* drop mcast group/source pair */ 926 #define IP_NEXTHOP 0x19 /* send directly to next hop */ 927 /* 928 * IP_PKTINFO and IP_RECVPKTINFO have same value. Size of argument passed in 929 * is used to differentiate b/w the two. 930 */ 931 #define IP_PKTINFO 0x1a /* specify src address and/or index */ 932 #define IP_RECVPKTINFO 0x1a /* recv dest/matched addr and index */ 933 #define IP_DONTFRAG 0x1b /* don't fragment packets */ 934 935 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 936 /* 937 * Different preferences that can be requested from IPSEC protocols. 938 */ 939 #define IP_SEC_OPT 0x22 /* Used to set IPSEC options */ 940 #define IPSEC_PREF_NEVER 0x01 941 #define IPSEC_PREF_REQUIRED 0x02 942 #define IPSEC_PREF_UNIQUE 0x04 943 /* 944 * This can be used with the setsockopt() call to set per socket security 945 * options. When the application uses per-socket API, we will reflect 946 * the request on both outbound and inbound packets. 947 */ 948 949 typedef struct ipsec_req { 950 uint_t ipsr_ah_req; /* AH request */ 951 uint_t ipsr_esp_req; /* ESP request */ 952 uint_t ipsr_self_encap_req; /* Self-Encap request */ 953 uint8_t ipsr_auth_alg; /* Auth algs for AH */ 954 uint8_t ipsr_esp_alg; /* Encr algs for ESP */ 955 uint8_t ipsr_esp_auth_alg; /* Auth algs for ESP */ 956 } ipsec_req_t; 957 958 /* 959 * MCAST_* options are protocol-independent. The actual definitions 960 * are with the v6 options below; this comment is here to note the 961 * namespace usage. 962 * 963 * #define MCAST_JOIN_GROUP 0x29 964 * #define MCAST_LEAVE_GROUP 0x2a 965 * #define MCAST_BLOCK_SOURCE 0x2b 966 * #define MCAST_UNBLOCK_SOURCE 0x2c 967 * #define MCAST_JOIN_SOURCE_GROUP 0x2d 968 * #define MCAST_LEAVE_SOURCE_GROUP 0x2e 969 */ 970 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 971 972 /* 973 * SunOS private (potentially not portable) IP_ option names 974 */ 975 #define IP_BOUND_IF 0x41 /* bind socket to an ifindex */ 976 #define IP_UNSPEC_SRC 0x42 /* use unspecified source address */ 977 #define IP_BROADCAST_TTL 0x43 /* use specific TTL for broadcast */ 978 /* can be reused 0x44 */ 979 #define IP_DHCPINIT_IF 0x45 /* accept all unicast DHCP traffic */ 980 981 /* 982 * Option values and names (when !_XPG5) shared with <xti_inet.h> 983 */ 984 #ifndef IP_REUSEADDR 985 #define IP_REUSEADDR 0x104 986 #endif 987 988 #ifndef IP_DONTROUTE 989 #define IP_DONTROUTE 0x105 990 #endif 991 992 #ifndef IP_BROADCAST 993 #define IP_BROADCAST 0x106 994 #endif 995 996 /* 997 * The following option values are reserved by <xti_inet.h> 998 * 999 * T_IP_OPTIONS 0x107 - IP per-packet options 1000 * T_IP_TOS 0x108 - IP per packet type of service 1001 */ 1002 1003 /* 1004 * Default value constants for multicast attributes controlled by 1005 * IP*_MULTICAST_LOOP and IP*_MULTICAST_{TTL,HOPS} options. 1006 */ 1007 #define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ 1008 #define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 1009 1010 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 1011 /* 1012 * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. 1013 */ 1014 struct ip_mreq { 1015 struct in_addr imr_multiaddr; /* IP multicast address of group */ 1016 struct in_addr imr_interface; /* local IP address of interface */ 1017 }; 1018 1019 /* 1020 * Argument structure for IP_BLOCK_SOURCE, IP_UNBLOCK_SOURCE, 1021 * IP_ADD_SOURCE_MEMBERSHIP, and IP_DROP_SOURCE_MEMBERSHIP. 1022 */ 1023 struct ip_mreq_source { 1024 struct in_addr imr_multiaddr; /* IP address of group */ 1025 struct in_addr imr_sourceaddr; /* IP address of source */ 1026 struct in_addr imr_interface; /* IP address of interface */ 1027 }; 1028 1029 /* 1030 * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP on 1031 * IPv6 addresses. 1032 */ 1033 struct ipv6_mreq { 1034 struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast addr */ 1035 unsigned int ipv6mr_interface; /* interface index */ 1036 }; 1037 1038 /* 1039 * Use #pragma pack() construct to force 32-bit alignment on amd64. 1040 * This is needed to keep the structure size and offsets consistent 1041 * between a 32-bit app and the 64-bit amd64 kernel in structures 1042 * where 64-bit alignment would create gaps (in this case, structures 1043 * which have a uint32_t followed by a struct sockaddr_storage). 1044 */ 1045 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 1046 #pragma pack(4) 1047 #endif 1048 1049 /* 1050 * Argument structure for MCAST_JOIN_GROUP and MCAST_LEAVE_GROUP. 1051 */ 1052 struct group_req { 1053 uint32_t gr_interface; /* interface index */ 1054 struct sockaddr_storage gr_group; /* group address */ 1055 }; 1056 1057 /* 1058 * Argument structure for MCAST_BLOCK_SOURCE, MCAST_UNBLOCK_SOURCE, 1059 * MCAST_JOIN_SOURCE_GROUP, MCAST_LEAVE_SOURCE_GROUP. 1060 */ 1061 struct group_source_req { 1062 uint32_t gsr_interface; /* interface index */ 1063 struct sockaddr_storage gsr_group; /* group address */ 1064 struct sockaddr_storage gsr_source; /* source address */ 1065 }; 1066 1067 /* 1068 * Argument for SIOC[GS]MSFILTER ioctls 1069 */ 1070 struct group_filter { 1071 uint32_t gf_interface; /* interface index */ 1072 struct sockaddr_storage gf_group; /* multicast address */ 1073 uint32_t gf_fmode; /* filter mode */ 1074 uint32_t gf_numsrc; /* number of sources */ 1075 struct sockaddr_storage gf_slist[1]; /* source address */ 1076 }; 1077 1078 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 1079 #pragma pack() 1080 #endif 1081 1082 #define GROUP_FILTER_SIZE(numsrc) \ 1083 (sizeof (struct group_filter) - sizeof (struct sockaddr_storage) \ 1084 + (numsrc) * sizeof (struct sockaddr_storage)) 1085 1086 /* 1087 * Argument for SIOC[GS]IPMSFILTER ioctls (IPv4-specific) 1088 */ 1089 struct ip_msfilter { 1090 struct in_addr imsf_multiaddr; /* IP multicast address of group */ 1091 struct in_addr imsf_interface; /* local IP address of interface */ 1092 uint32_t imsf_fmode; /* filter mode */ 1093 uint32_t imsf_numsrc; /* number of sources in src_list */ 1094 struct in_addr imsf_slist[1]; /* start of source list */ 1095 }; 1096 1097 #define IP_MSFILTER_SIZE(numsrc) \ 1098 (sizeof (struct ip_msfilter) - sizeof (struct in_addr) \ 1099 + (numsrc) * sizeof (struct in_addr)) 1100 1101 /* 1102 * Multicast source filter manipulation functions in libsocket; 1103 * defined in RFC 3678. 1104 */ 1105 int setsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, uint32_t, 1106 uint_t, struct sockaddr_storage *); 1107 1108 int getsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, uint32_t *, 1109 uint_t *, struct sockaddr_storage *); 1110 1111 int setipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t, 1112 uint32_t, struct in_addr *); 1113 1114 int getipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t *, 1115 uint32_t *, struct in_addr *); 1116 1117 /* 1118 * Definitions needed for [gs]etsourcefilter(), [gs]etipv4sourcefilter() 1119 */ 1120 #define MCAST_INCLUDE 1 1121 #define MCAST_EXCLUDE 2 1122 1123 /* 1124 * Argument struct for IP_PKTINFO option 1125 */ 1126 typedef struct in_pktinfo { 1127 unsigned int ipi_ifindex; /* send/recv interface index */ 1128 struct in_addr ipi_spec_dst; /* matched source address */ 1129 struct in_addr ipi_addr; /* src/dst address in IP hdr */ 1130 } in_pktinfo_t; 1131 1132 /* 1133 * Argument struct for IPV6_PKTINFO option 1134 */ 1135 struct in6_pktinfo { 1136 struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 1137 unsigned int ipi6_ifindex; /* send/recv interface index */ 1138 }; 1139 1140 /* 1141 * Argument struct for IPV6_MTUINFO option 1142 */ 1143 struct ip6_mtuinfo { 1144 struct sockaddr_in6 ip6m_addr; /* dst address including zone ID */ 1145 uint32_t ip6m_mtu; /* path MTU in host byte order */ 1146 }; 1147 1148 /* 1149 * IPv6 routing header types 1150 */ 1151 #define IPV6_RTHDR_TYPE_0 0 1152 1153 extern socklen_t inet6_rth_space(int type, int segments); 1154 extern void *inet6_rth_init(void *bp, socklen_t bp_len, int type, int segments); 1155 extern int inet6_rth_add(void *bp, const struct in6_addr *addr); 1156 extern int inet6_rth_reverse(const void *in, void *out); 1157 extern int inet6_rth_segments(const void *bp); 1158 extern struct in6_addr *inet6_rth_getaddr(const void *bp, int index); 1159 1160 extern int inet6_opt_init(void *extbuf, socklen_t extlen); 1161 extern int inet6_opt_append(void *extbuf, socklen_t extlen, int offset, 1162 uint8_t type, socklen_t len, uint_t align, void **databufp); 1163 extern int inet6_opt_finish(void *extbuf, socklen_t extlen, int offset); 1164 extern int inet6_opt_set_val(void *databuf, int offset, void *val, 1165 socklen_t vallen); 1166 extern int inet6_opt_next(void *extbuf, socklen_t extlen, int offset, 1167 uint8_t *typep, socklen_t *lenp, void **databufp); 1168 extern int inet6_opt_find(void *extbufp, socklen_t extlen, int offset, 1169 uint8_t type, socklen_t *lenp, void **databufp); 1170 extern int inet6_opt_get_val(void *databuf, int offset, void *val, 1171 socklen_t vallen); 1172 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 1173 1174 /* 1175 * Argument structure for IP_ADD_PROXY_ADDR. 1176 * Note that this is an unstable, experimental interface. It may change 1177 * later. Don't use it unless you know what it is. 1178 */ 1179 typedef struct { 1180 struct in_addr in_prefix_addr; 1181 unsigned int in_prefix_len; 1182 } in_prefix_t; 1183 1184 1185 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) 1186 /* 1187 * IPv6 options 1188 */ 1189 #define IPV6_UNICAST_HOPS 0x5 /* hop limit value for unicast */ 1190 /* packets. */ 1191 /* argument type: uint_t */ 1192 #define IPV6_MULTICAST_IF 0x6 /* outgoing interface for */ 1193 /* multicast packets. */ 1194 /* argument type: struct in6_addr */ 1195 #define IPV6_MULTICAST_HOPS 0x7 /* hop limit value to use for */ 1196 /* multicast packets. */ 1197 /* argument type: uint_t */ 1198 #define IPV6_MULTICAST_LOOP 0x8 /* enable/disable delivery of */ 1199 /* multicast packets on same socket. */ 1200 /* argument type: uint_t */ 1201 #define IPV6_JOIN_GROUP 0x9 /* join an IPv6 multicast group. */ 1202 /* argument type: struct ipv6_mreq */ 1203 #define IPV6_LEAVE_GROUP 0xa /* leave an IPv6 multicast group */ 1204 /* argument type: struct ipv6_mreq */ 1205 1206 /* 1207 * Other XPG6 constants. 1208 */ 1209 #define INET_ADDRSTRLEN 16 /* max len IPv4 addr in ascii dotted */ 1210 /* decimal notation. */ 1211 #define INET6_ADDRSTRLEN 46 /* max len of IPv6 addr in ascii */ 1212 /* standard colon-hex notation. */ 1213 1214 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */ 1215 1216 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 1217 1218 /* 1219 * IPV6_ADD_MEMBERSHIP and IPV6_DROP_MEMBERSHIP are being kept 1220 * for backward compatibility. They have the same meaning as IPV6_JOIN_GROUP 1221 * and IPV6_LEAVE_GROUP respectively. 1222 */ 1223 #define IPV6_ADD_MEMBERSHIP 0x9 /* join an IPv6 multicast group. */ 1224 /* argument type: struct ipv6_mreq */ 1225 #define IPV6_DROP_MEMBERSHIP 0xa /* leave an IPv6 multicast group */ 1226 /* argument type: struct ipv6_mreq */ 1227 1228 #define IPV6_PKTINFO 0xb /* addr plus interface index */ 1229 /* arg type: "struct in6_pktingo" - */ 1230 #define IPV6_HOPLIMIT 0xc /* hoplimit for datagram */ 1231 #define IPV6_NEXTHOP 0xd /* next hop address */ 1232 #define IPV6_HOPOPTS 0xe /* hop by hop options */ 1233 #define IPV6_DSTOPTS 0xf /* destination options - after */ 1234 /* the routing header */ 1235 #define IPV6_RTHDR 0x10 /* routing header */ 1236 #define IPV6_RTHDRDSTOPTS 0x11 /* destination options - before */ 1237 /* the routing header */ 1238 #define IPV6_RECVPKTINFO 0x12 /* enable/disable IPV6_PKTINFO */ 1239 #define IPV6_RECVHOPLIMIT 0x13 /* enable/disable IPV6_HOPLIMIT */ 1240 #define IPV6_RECVHOPOPTS 0x14 /* enable/disable IPV6_HOPOPTS */ 1241 1242 /* 1243 * This options exists for backwards compatability and should no longer be 1244 * used. Use IPV6_RECVDSTOPTS instead. 1245 */ 1246 #define _OLD_IPV6_RECVDSTOPTS 0x15 1247 1248 #define IPV6_RECVRTHDR 0x16 /* enable/disable IPV6_RTHDR */ 1249 1250 /* 1251 * enable/disable IPV6_RTHDRDSTOPTS. Now obsolete. IPV6_RECVDSTOPTS enables 1252 * the receipt of both headers. 1253 */ 1254 #define IPV6_RECVRTHDRDSTOPTS 0x17 1255 1256 #define IPV6_CHECKSUM 0x18 /* Control checksum on raw sockets */ 1257 #define IPV6_RECVTCLASS 0x19 /* enable/disable IPV6_TCLASS */ 1258 #define IPV6_USE_MIN_MTU 0x20 /* send packets with minimum MTU */ 1259 #define IPV6_DONTFRAG 0x21 /* don't fragment packets */ 1260 #define IPV6_SEC_OPT 0x22 /* Used to set IPSEC options */ 1261 #define IPV6_SRC_PREFERENCES 0x23 /* Control socket's src addr select */ 1262 #define IPV6_RECVPATHMTU 0x24 /* receive PMTU info */ 1263 #define IPV6_PATHMTU 0x25 /* get the PMTU */ 1264 #define IPV6_TCLASS 0x26 /* traffic class */ 1265 #define IPV6_V6ONLY 0x27 /* v6 only socket option */ 1266 1267 /* 1268 * enable/disable receipt of both both IPV6_DSTOPTS headers. 1269 */ 1270 #define IPV6_RECVDSTOPTS 0x28 1271 1272 /* 1273 * protocol-independent multicast membership options. 1274 */ 1275 #define MCAST_JOIN_GROUP 0x29 /* join group for all sources */ 1276 #define MCAST_LEAVE_GROUP 0x2a /* leave group */ 1277 #define MCAST_BLOCK_SOURCE 0x2b /* block specified source */ 1278 #define MCAST_UNBLOCK_SOURCE 0x2c /* unblock specified source */ 1279 #define MCAST_JOIN_SOURCE_GROUP 0x2d /* join group for specified source */ 1280 #define MCAST_LEAVE_SOURCE_GROUP 0x2e /* leave source/group pair */ 1281 1282 /* 32Bit field for IPV6_SRC_PREFERENCES */ 1283 #define IPV6_PREFER_SRC_HOME 0x00000001 1284 #define IPV6_PREFER_SRC_COA 0x00000002 1285 #define IPV6_PREFER_SRC_PUBLIC 0x00000004 1286 #define IPV6_PREFER_SRC_TMP 0x00000008 1287 #define IPV6_PREFER_SRC_NONCGA 0x00000010 1288 #define IPV6_PREFER_SRC_CGA 0x00000020 1289 1290 #define IPV6_PREFER_SRC_MIPMASK (IPV6_PREFER_SRC_HOME | IPV6_PREFER_SRC_COA) 1291 #define IPV6_PREFER_SRC_MIPDEFAULT IPV6_PREFER_SRC_HOME 1292 #define IPV6_PREFER_SRC_TMPMASK (IPV6_PREFER_SRC_PUBLIC | IPV6_PREFER_SRC_TMP) 1293 #define IPV6_PREFER_SRC_TMPDEFAULT IPV6_PREFER_SRC_PUBLIC 1294 #define IPV6_PREFER_SRC_CGAMASK (IPV6_PREFER_SRC_NONCGA | IPV6_PREFER_SRC_CGA) 1295 #define IPV6_PREFER_SRC_CGADEFAULT IPV6_PREFER_SRC_NONCGA 1296 1297 #define IPV6_PREFER_SRC_MASK (IPV6_PREFER_SRC_MIPMASK |\ 1298 IPV6_PREFER_SRC_TMPMASK | IPV6_PREFER_SRC_CGAMASK) 1299 1300 #define IPV6_PREFER_SRC_DEFAULT (IPV6_PREFER_SRC_MIPDEFAULT |\ 1301 IPV6_PREFER_SRC_TMPDEFAULT | IPV6_PREFER_SRC_CGADEFAULT) 1302 1303 /* 1304 * SunOS private (potentially not portable) IPV6_ option names 1305 */ 1306 #define IPV6_BOUND_IF 0x41 /* bind to an ifindex */ 1307 #define IPV6_UNSPEC_SRC 0x42 /* source of packets set to */ 1308 /* unspecified (all zeros) */ 1309 1310 /* 1311 * Miscellaneous IPv6 constants. 1312 */ 1313 #define IPV6_PAD1_OPT 0 /* pad byte in IPv6 extension hdrs */ 1314 1315 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 1316 1317 /* 1318 * Extern declarations for pre-defined global const variables 1319 */ 1320 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) 1321 #ifndef _KERNEL 1322 #ifdef __STDC__ 1323 extern const struct in6_addr in6addr_any; 1324 extern const struct in6_addr in6addr_loopback; 1325 #else 1326 extern struct in6_addr in6addr_any; 1327 extern struct in6_addr in6addr_loopback; 1328 #endif 1329 #endif 1330 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */ 1331 1332 #ifdef __cplusplus 1333 } 1334 #endif 1335 1336 #endif /* _NETINET_IN_H */ 1337