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