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