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