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