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