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