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