xref: /titanic_53/usr/src/uts/common/inet/ip6.h (revision ff550d0e264b51131fb34e9e83163b348d916640)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_INET_IP6_H
287c478bd9Sstevel@tonic-gate #define	_INET_IP6_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
397c478bd9Sstevel@tonic-gate /* icmp6_t is used in the prototype of icmp_inbound_error_fanout_v6() */
407c478bd9Sstevel@tonic-gate #include <netinet/icmp6.h>
417c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /* version number for IPv6 - hard to get this one wrong! */
447c478bd9Sstevel@tonic-gate #define	IPV6_VERSION		6
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #define	IPV6_HDR_LEN		40
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #define	IPV6_ADDR_LEN		16
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * IPv6 address scopes.  The values of these enums also match the scope
527c478bd9Sstevel@tonic-gate  * field of multicast addresses.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate typedef enum {
557c478bd9Sstevel@tonic-gate 	IP6_SCOPE_INTFLOCAL = 1,	/* Multicast addresses only */
567c478bd9Sstevel@tonic-gate 	IP6_SCOPE_LINKLOCAL,
577c478bd9Sstevel@tonic-gate 	IP6_SCOPE_SUBNETLOCAL,		/* Multicast addresses only */
587c478bd9Sstevel@tonic-gate 	IP6_SCOPE_ADMINLOCAL,		/* Multicast addresses only */
597c478bd9Sstevel@tonic-gate 	IP6_SCOPE_SITELOCAL,
607c478bd9Sstevel@tonic-gate 	IP6_SCOPE_GLOBAL
617c478bd9Sstevel@tonic-gate } in6addr_scope_t;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * Private header used between the transports and IP to carry the content
677c478bd9Sstevel@tonic-gate  * of the options IPV6_PKTINFO/IPV6_RECVPKTINFO (the interface index only)
687c478bd9Sstevel@tonic-gate  * and IPV6_NEXTHOP.
697c478bd9Sstevel@tonic-gate  * Also used to specify that raw sockets do not want the UDP/TCP transport
707c478bd9Sstevel@tonic-gate  * checksums calculated in IP (akin to IP_HDR_INCLUDED) and provide for
717c478bd9Sstevel@tonic-gate  * IPV6_CHECKSUM on the transmit side (using ip6i_checksum_off).
727c478bd9Sstevel@tonic-gate  *
737c478bd9Sstevel@tonic-gate  * When this header is used it must be the first header in the packet i.e.
747c478bd9Sstevel@tonic-gate  * before the real ip6 header. The use of a next header value of 255
757c478bd9Sstevel@tonic-gate  * (IPPROTO_RAW) in this header indicates its presence. Note that
767c478bd9Sstevel@tonic-gate  * ip6_nxt = IPPROTO_RAW indicates that "this" header is ip6_info - the
777c478bd9Sstevel@tonic-gate  * next header is always IPv6.
787c478bd9Sstevel@tonic-gate  *
797c478bd9Sstevel@tonic-gate  * Note that ip6i_nexthop is at the same offset as ip6_dst so that
807c478bd9Sstevel@tonic-gate  * this header can be kept in the packet while the it passes through
817c478bd9Sstevel@tonic-gate  * ip_newroute* and the ndp code. Those routines will use ip6_dst for
827c478bd9Sstevel@tonic-gate  * resolution.
837c478bd9Sstevel@tonic-gate  *
847c478bd9Sstevel@tonic-gate  * Implementation offset assumptions about ip6_info_t and ip6_t fields
857c478bd9Sstevel@tonic-gate  * and their alignments shown in figure below
867c478bd9Sstevel@tonic-gate  *
877c478bd9Sstevel@tonic-gate  * ip6_info (Private headers from transports to IP) header below
887c478bd9Sstevel@tonic-gate  * _______________________________________________________________ _ _ _ _ _
897c478bd9Sstevel@tonic-gate  * | .... | ip6i_nxt (255)| ......................|ip6i_nexthop| ...ip6_t.
907c478bd9Sstevel@tonic-gate  * --------------------------------------------------------------- - - - - -
917c478bd9Sstevel@tonic-gate  *        ^                                       ^
927c478bd9Sstevel@tonic-gate  * <---- >| same offset for {ip6i_nxt,ip6_nxt}    ^
937c478bd9Sstevel@tonic-gate  *        ^                                       ^
947c478bd9Sstevel@tonic-gate  * <------^-------------------------------------->| same offset for
957c478bd9Sstevel@tonic-gate  *        ^                                       ^ {ip6i_nxthop,ip6_dst}
967c478bd9Sstevel@tonic-gate  * _______________________________________________________________ _ _ _
977c478bd9Sstevel@tonic-gate  * | .... | ip6_nxt       | ......................|ip6_dst     | .other hdrs...
987c478bd9Sstevel@tonic-gate  * --------------------------------------------------------------- - - -
997c478bd9Sstevel@tonic-gate  * ip6_t (IPv6 protocol) header above
1007c478bd9Sstevel@tonic-gate  */
1017c478bd9Sstevel@tonic-gate struct ip6_info {
1027c478bd9Sstevel@tonic-gate 	union {
1037c478bd9Sstevel@tonic-gate 		struct ip6_info_ctl {
1047c478bd9Sstevel@tonic-gate 			uint32_t	ip6i_un1_flow;
1057c478bd9Sstevel@tonic-gate 			uint16_t	ip6i_un1_plen;   /* payload length */
1067c478bd9Sstevel@tonic-gate 			uint8_t		ip6i_un1_nxt;    /* next header */
1077c478bd9Sstevel@tonic-gate 			uint8_t		ip6i_un1_hlim;   /* hop limit */
1087c478bd9Sstevel@tonic-gate 		} ip6i_un1;
1097c478bd9Sstevel@tonic-gate 	} ip6i_ctlun;
1107c478bd9Sstevel@tonic-gate 	int		ip6i_flags;	/* See below */
1117c478bd9Sstevel@tonic-gate 	int		ip6i_ifindex;
1127c478bd9Sstevel@tonic-gate 	int		ip6i_checksum_off;
1137c478bd9Sstevel@tonic-gate 	int		ip6i_pad;
1147c478bd9Sstevel@tonic-gate 	in6_addr_t	ip6i_nexthop;	/* Same offset as ip6_dst */
1157c478bd9Sstevel@tonic-gate };
1167c478bd9Sstevel@tonic-gate typedef struct ip6_info	ip6i_t;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #define	ip6i_flow	ip6i_ctlun.ip6i_un1.ip6i_un1_flow
1197c478bd9Sstevel@tonic-gate #define	ip6i_vcf	ip6i_flow		/* Version, class, flow */
1207c478bd9Sstevel@tonic-gate #define	ip6i_nxt	ip6i_ctlun.ip6i_un1.ip6i_un1_nxt
1217c478bd9Sstevel@tonic-gate #define	ip6i_hops	ip6i_ctlun.ip6i_un1.ip6i_un1_hlim
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /* ip6_info flags */
1247c478bd9Sstevel@tonic-gate #define	IP6I_IFINDEX	0x1	/* ip6i_ifindex is set (to nonzero value) */
1257c478bd9Sstevel@tonic-gate #define	IP6I_NEXTHOP	0x2	/* ip6i_nexthop is different than ip6_dst */
1267c478bd9Sstevel@tonic-gate #define	IP6I_NO_ULP_CKSUM	0x4
1277c478bd9Sstevel@tonic-gate 			/*
1287c478bd9Sstevel@tonic-gate 			 * Do not generate TCP/UDP/SCTP transport checksum.
1297c478bd9Sstevel@tonic-gate 			 * Used by raw sockets. Does not affect the
1307c478bd9Sstevel@tonic-gate 			 * generation of transport checksums for ICMPv6
1317c478bd9Sstevel@tonic-gate 			 * since such packets always arrive through
1327c478bd9Sstevel@tonic-gate 			 * a raw socket.
1337c478bd9Sstevel@tonic-gate 			 */
1347c478bd9Sstevel@tonic-gate #define	IP6I_UNSPEC_SRC	0x8
1357c478bd9Sstevel@tonic-gate 			/* Used to carry conn_unspec_src through ip_newroute* */
1367c478bd9Sstevel@tonic-gate #define	IP6I_RAW_CHECKSUM	0x10
1377c478bd9Sstevel@tonic-gate 			/* Compute checksum and stuff in ip6i_checksum_off */
1387c478bd9Sstevel@tonic-gate #define	IP6I_VERIFY_SRC	0x20	/* Verify ip6_src. Used when IPV6_PKTINFO */
1397c478bd9Sstevel@tonic-gate #define	IP6I_ATTACH_IF	0x40	/* Bind to no failover address or BOUND_PIF. */
1407c478bd9Sstevel@tonic-gate #define	IP6I_DROP_IFDELAYED	0x80
1417c478bd9Sstevel@tonic-gate 			/* Drop the packet if delayed in ndp resolver */
1427c478bd9Sstevel@tonic-gate #define	IP6I_ND_DELAYED 0x100	/* Packet was delayed in ndp resolver */
1437c478bd9Sstevel@tonic-gate #define	IP6I_DONTFRAG	0x200	/* Don't fragment this packet */
1447c478bd9Sstevel@tonic-gate #define	IP6I_HOPLIMIT	0x400	/* hoplimit has been set by the sender */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /*
1477c478bd9Sstevel@tonic-gate  * These constants refer to the IPV6_USE_MIN_MTU API.  The
1487c478bd9Sstevel@tonic-gate  * actually values used in the API are these values shifted down
1497c478bd9Sstevel@tonic-gate  * 10 bits minus 2 [-1, 1].  0 (-2 after conversion) is considered
1507c478bd9Sstevel@tonic-gate  * the same as the default (-1).  IP6I_API_USE_MIN_MTU(f, x) returns
1517c478bd9Sstevel@tonic-gate  * the flags field updated with min mtu.  IP6I_USE_MIN_MTU_API takes the
1527c478bd9Sstevel@tonic-gate  * field and returns the API value (+ the -2 value).
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate #define	IP6I_USE_MIN_MTU_UNICAST	0x400
1557c478bd9Sstevel@tonic-gate #define	IP6I_USE_MIN_MTU_ALWAYS		0x800
1567c478bd9Sstevel@tonic-gate #define	IP6I_USE_MIN_MTU_NEVER		0xC00
1577c478bd9Sstevel@tonic-gate #define	IP6I_USE_MIN_MTU_API(x)		((((x) & 0xC00) >> 10) - 2)
1587c478bd9Sstevel@tonic-gate #define	IP6I_API_USE_MIN_MTU(f, x)	(((f) & ~0xC00) &\
1597c478bd9Sstevel@tonic-gate 					((((x) + 2) & 0x3) << 11))
1607c478bd9Sstevel@tonic-gate #define	IPV6_USE_MIN_MTU_DEFAULT	-2
1617c478bd9Sstevel@tonic-gate #define	IPV6_USE_MIN_MTU_UNICAST	-1
1627c478bd9Sstevel@tonic-gate #define	IPV6_USE_MIN_MTU_ALWAYS		0
1637c478bd9Sstevel@tonic-gate #define	IPV6_USE_MIN_MTU_NEVER		1
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate /* Extract the scope from a multicast address */
1667c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
1677c478bd9Sstevel@tonic-gate #define	IN6_ADDR_MC_SCOPE(addr) \
1687c478bd9Sstevel@tonic-gate 	(((addr)->s6_addr32[0] & 0x000f0000) >> 16)
1697c478bd9Sstevel@tonic-gate #else
1707c478bd9Sstevel@tonic-gate #define	IN6_ADDR_MC_SCOPE(addr) \
1717c478bd9Sstevel@tonic-gate 	(((addr)->s6_addr32[0] & 0x00000f00) >> 8)
1727c478bd9Sstevel@tonic-gate #endif
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate /* Default IPv4 TTL for IPv6-in-IPv4 encapsulated packets */
1757c478bd9Sstevel@tonic-gate #define	IPV6_DEFAULT_HOPS	60	/* XXX What should it be? */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate /* Max IPv6 TTL */
1787c478bd9Sstevel@tonic-gate #define	IPV6_MAX_HOPS	255
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate /* Minimum IPv6 MTU from rfc2460 */
1817c478bd9Sstevel@tonic-gate #define	IPV6_MIN_MTU		1280
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate /* EUI-64 based token length */
1847c478bd9Sstevel@tonic-gate #define	IPV6_TOKEN_LEN		64
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate /* Length of an advertised IPv6 prefix */
1877c478bd9Sstevel@tonic-gate #define	IPV6_PREFIX_LEN		64
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate /* Default and maximum tunnel encapsulation limits.  See RFC 2473. */
1907c478bd9Sstevel@tonic-gate #define	IPV6_DEFAULT_ENCAPLIMIT	4
1917c478bd9Sstevel@tonic-gate #define	IPV6_MAX_ENCAPLIMIT	255
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate  * Minimum and maximum extension header lengths for IPv6.  The 8-bit
1957c478bd9Sstevel@tonic-gate  * length field of each extension header (see rfc2460) specifies the
1967c478bd9Sstevel@tonic-gate  * number of 8 octet units of data in the header not including the
1977c478bd9Sstevel@tonic-gate  * first 8 octets.  A value of 0 would indicate 8 bytes (0 * 8 + 8),
1987c478bd9Sstevel@tonic-gate  * and 255 would indicate 2048 bytes (255 * 8 + 8).
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate #define	MIN_EHDR_LEN		8
2017c478bd9Sstevel@tonic-gate #define	MAX_EHDR_LEN		2048
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate  * The high-order bit of the version field is used by the transports to
2057c478bd9Sstevel@tonic-gate  * indicate a rechability confirmation to IP.
2067c478bd9Sstevel@tonic-gate  */
2077c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
2087c478bd9Sstevel@tonic-gate #define	IPV6_DEFAULT_VERS_AND_FLOW	0x60000000
2097c478bd9Sstevel@tonic-gate #define	IPV6_VERS_AND_FLOW_MASK		0xF0000000
2107c478bd9Sstevel@tonic-gate #define	IP_FORWARD_PROG			0x80000000
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate #define	V6_MCAST			0xFF000000
2137c478bd9Sstevel@tonic-gate #define	V6_LINKLOCAL			0xFE800000
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate #define	IPV6_FLOW_TCLASS(x)		(((x) & IPV6_FLOWINFO_TCLASS) >> 20)
2167c478bd9Sstevel@tonic-gate #define	IPV6_TCLASS_FLOW(f, c)		(((f) & ~IPV6_FLOWINFO_TCLASS) |\
2177c478bd9Sstevel@tonic-gate 					((c) << 20))
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate #else
2207c478bd9Sstevel@tonic-gate #define	IPV6_DEFAULT_VERS_AND_FLOW	0x00000060
2217c478bd9Sstevel@tonic-gate #define	IPV6_VERS_AND_FLOW_MASK		0x000000F0
2227c478bd9Sstevel@tonic-gate #define	IP_FORWARD_PROG			0x00000080
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate #define	V6_MCAST			0x000000FF
2257c478bd9Sstevel@tonic-gate #define	V6_LINKLOCAL			0x000080FE
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate #define	IPV6_FLOW_TCLASS(x)		((((x) & 0xf000U) >> 12) |\
2287c478bd9Sstevel@tonic-gate 					(((x) & 0xf) << 4))
2297c478bd9Sstevel@tonic-gate #define	IPV6_TCLASS_FLOW(f, c)		(((f) & ~IPV6_FLOWINFO_TCLASS) |\
2307c478bd9Sstevel@tonic-gate 					((((c) & 0xf) << 12) |\
2317c478bd9Sstevel@tonic-gate 					(((c) & 0xf0) >> 4)))
2327c478bd9Sstevel@tonic-gate #endif
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate /*
2357c478bd9Sstevel@tonic-gate  * UTILITY MACROS FOR ADDRESSES.
2367c478bd9Sstevel@tonic-gate  */
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate /*
2397c478bd9Sstevel@tonic-gate  * Convert an IPv4 address mask to an IPv6 mask.   Pad with 1-bits.
2407c478bd9Sstevel@tonic-gate  */
2417c478bd9Sstevel@tonic-gate #define	V4MASK_TO_V6(v4, v6)	((v6).s6_addr32[0] = 0xffffffffUL,	\
2427c478bd9Sstevel@tonic-gate 				(v6).s6_addr32[1] = 0xffffffffUL,	\
2437c478bd9Sstevel@tonic-gate 				(v6).s6_addr32[2] = 0xffffffffUL,	\
2447c478bd9Sstevel@tonic-gate 				(v6).s6_addr32[3] = (v4))
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate /*
2477c478bd9Sstevel@tonic-gate  * Convert aligned IPv4-mapped IPv6 address into an IPv4 address.
2487c478bd9Sstevel@tonic-gate  * Note: We use "v6" here in definition of macro instead of "(v6)"
2497c478bd9Sstevel@tonic-gate  * Not possible to use "(v6)" here since macro is used with struct
2507c478bd9Sstevel@tonic-gate  * field names as arguments.
2517c478bd9Sstevel@tonic-gate  */
2527c478bd9Sstevel@tonic-gate #define	V4_PART_OF_V6(v6)	v6.s6_addr32[3]
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
2557c478bd9Sstevel@tonic-gate #define	V6_OR_V4_INADDR_ANY(a)	((a).s6_addr32[3] == 0 &&		\
2567c478bd9Sstevel@tonic-gate 				((a).s6_addr32[2] == 0xffffU ||	\
2577c478bd9Sstevel@tonic-gate 				(a).s6_addr32[2] == 0) &&		\
2587c478bd9Sstevel@tonic-gate 				(a).s6_addr32[1] == 0 &&		\
2597c478bd9Sstevel@tonic-gate 				(a).s6_addr32[0] == 0)
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate #else
2627c478bd9Sstevel@tonic-gate #define	V6_OR_V4_INADDR_ANY(a)	((a).s6_addr32[3] == 0 && 		\
2637c478bd9Sstevel@tonic-gate 				((a).s6_addr32[2] == 0xffff0000U ||	\
2647c478bd9Sstevel@tonic-gate 				(a).s6_addr32[2] == 0) &&		\
2657c478bd9Sstevel@tonic-gate 				(a).s6_addr32[1] == 0 &&		\
2667c478bd9Sstevel@tonic-gate 				(a).s6_addr32[0] == 0)
2677c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate /* IPv4-mapped CLASSD addresses */
2707c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
2717c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_V4MAPPED_CLASSD(addr) \
2727c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[2] == 0x0000ffff) && \
2737c478bd9Sstevel@tonic-gate 	(CLASSD((addr)->_S6_un._S6_u32[3])) && \
2747c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[1] == 0) && \
2757c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[0] == 0))
2767c478bd9Sstevel@tonic-gate #else  /* _BIG_ENDIAN */
2777c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_V4MAPPED_CLASSD(addr) \
2787c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[2] == 0xffff0000U) && \
2797c478bd9Sstevel@tonic-gate 	(CLASSD((addr)->_S6_un._S6_u32[3])) && \
2807c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[1] == 0) && \
2817c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[0] == 0))
2827c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate /* Clear an IPv6 addr */
2857c478bd9Sstevel@tonic-gate #define	V6_SET_ZERO(a)		((a).s6_addr32[0] = 0,			\
2867c478bd9Sstevel@tonic-gate 				(a).s6_addr32[1] = 0,			\
2877c478bd9Sstevel@tonic-gate 				(a).s6_addr32[2] = 0,			\
2887c478bd9Sstevel@tonic-gate 				(a).s6_addr32[3] = 0)
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate /* Mask comparison: is IPv6 addr a, and'ed with mask m, equal to addr b? */
2917c478bd9Sstevel@tonic-gate #define	V6_MASK_EQ(a, m, b)						\
2927c478bd9Sstevel@tonic-gate 	((((a).s6_addr32[0] & (m).s6_addr32[0]) == (b).s6_addr32[0]) &&	\
2937c478bd9Sstevel@tonic-gate 	(((a).s6_addr32[1] & (m).s6_addr32[1]) == (b).s6_addr32[1]) &&	\
2947c478bd9Sstevel@tonic-gate 	(((a).s6_addr32[2] & (m).s6_addr32[2]) == (b).s6_addr32[2]) &&	\
2957c478bd9Sstevel@tonic-gate 	(((a).s6_addr32[3] & (m).s6_addr32[3]) == (b).s6_addr32[3]))
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate #define	V6_MASK_EQ_2(a, m, b)						\
2987c478bd9Sstevel@tonic-gate 	((((a).s6_addr32[0] & (m).s6_addr32[0]) ==			\
2997c478bd9Sstevel@tonic-gate 	    ((b).s6_addr32[0]  & (m).s6_addr32[0])) &&			\
3007c478bd9Sstevel@tonic-gate 	(((a).s6_addr32[1] & (m).s6_addr32[1]) ==			\
3017c478bd9Sstevel@tonic-gate 	    ((b).s6_addr32[1]  & (m).s6_addr32[1])) &&			\
3027c478bd9Sstevel@tonic-gate 	(((a).s6_addr32[2] & (m).s6_addr32[2]) ==			\
3037c478bd9Sstevel@tonic-gate 	    ((b).s6_addr32[2]  & (m).s6_addr32[2])) &&			\
3047c478bd9Sstevel@tonic-gate 	(((a).s6_addr32[3] & (m).s6_addr32[3]) ==			\
3057c478bd9Sstevel@tonic-gate 	    ((b).s6_addr32[3]  & (m).s6_addr32[3])))
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate /* Copy IPv6 address (s), logically and'ed with mask (m), into (d) */
3087c478bd9Sstevel@tonic-gate #define	V6_MASK_COPY(s, m, d)						\
3097c478bd9Sstevel@tonic-gate 	((d).s6_addr32[0] = (s).s6_addr32[0] & (m).s6_addr32[0],	\
3107c478bd9Sstevel@tonic-gate 	(d).s6_addr32[1] = (s).s6_addr32[1] & (m).s6_addr32[1],		\
3117c478bd9Sstevel@tonic-gate 	(d).s6_addr32[2] = (s).s6_addr32[2] & (m).s6_addr32[2],		\
3127c478bd9Sstevel@tonic-gate 	(d).s6_addr32[3] = (s).s6_addr32[3] & (m).s6_addr32[3])
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate #define	ILL_FRAG_HASH_V6(v6addr, i)					\
3157c478bd9Sstevel@tonic-gate 	((ntohl((v6addr).s6_addr32[3]) ^ (i ^ (i >> 8))) % 		\
3167c478bd9Sstevel@tonic-gate 						ILL_FRAG_HASH_TBL_COUNT)
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate /*
3197c478bd9Sstevel@tonic-gate  * GLOBAL EXTERNALS
3207c478bd9Sstevel@tonic-gate  */
3217c478bd9Sstevel@tonic-gate extern uint_t ipv6_ire_default_count;	/* Number of IPv6 IRE_DEFAULT entries */
3227c478bd9Sstevel@tonic-gate extern uint_t ipv6_ire_default_index;	/* Walking IPv6 index used to mod in */
3237c478bd9Sstevel@tonic-gate extern int ipv6_ire_cache_cnt;	/* Number of IPv6 IRE_CACHE entries */
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate extern const in6_addr_t	ipv6_all_ones;
3267c478bd9Sstevel@tonic-gate extern const in6_addr_t	ipv6_all_zeros;
3277c478bd9Sstevel@tonic-gate extern const in6_addr_t	ipv6_loopback;
3287c478bd9Sstevel@tonic-gate extern const in6_addr_t	ipv6_all_hosts_mcast;
3297c478bd9Sstevel@tonic-gate extern const in6_addr_t	ipv6_all_rtrs_mcast;
3307c478bd9Sstevel@tonic-gate extern const in6_addr_t	ipv6_all_v2rtrs_mcast;
3317c478bd9Sstevel@tonic-gate extern const in6_addr_t	ipv6_solicited_node_mcast;
3327c478bd9Sstevel@tonic-gate extern const in6_addr_t	ipv6_unspecified_group;
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate /*
3357c478bd9Sstevel@tonic-gate  * IPv6 mibs when the interface (ill) is not known.
3367c478bd9Sstevel@tonic-gate  * When the ill is known the per-interface mib in the ill is used.
3377c478bd9Sstevel@tonic-gate  */
3387c478bd9Sstevel@tonic-gate extern mib2_ipv6IfStatsEntry_t	ip6_mib;
3397c478bd9Sstevel@tonic-gate extern mib2_ipv6IfIcmpEntry_t	icmp6_mib;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate /*
3427c478bd9Sstevel@tonic-gate  * FUNCTION PROTOTYPES
3437c478bd9Sstevel@tonic-gate  */
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate struct ipsec_out_s;
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate extern void	convert2ascii(char *buf, const in6_addr_t *addr);
3487c478bd9Sstevel@tonic-gate extern char	*inet_ntop(int, const void *, char *, int);
3497c478bd9Sstevel@tonic-gate extern int	inet_pton(int, char *, void *);
3507c478bd9Sstevel@tonic-gate extern void	icmp_time_exceeded_v6(queue_t *, mblk_t *, uint8_t,
3517c478bd9Sstevel@tonic-gate 		    boolean_t, boolean_t);
3527c478bd9Sstevel@tonic-gate extern void	icmp_unreachable_v6(queue_t *, mblk_t *, uint8_t,
3537c478bd9Sstevel@tonic-gate 		    boolean_t, boolean_t);
3547c478bd9Sstevel@tonic-gate extern void	icmp_inbound_error_fanout_v6(queue_t *, mblk_t *, ip6_t *,
3557c478bd9Sstevel@tonic-gate 		    icmp6_t *, ill_t *, boolean_t, zoneid_t);
3567c478bd9Sstevel@tonic-gate extern boolean_t conn_wantpacket_v6(conn_t *, ill_t *, ip6_t *, int, zoneid_t);
3577c478bd9Sstevel@tonic-gate extern mblk_t	*ip_add_info_v6(mblk_t *, ill_t *, const in6_addr_t *);
3587c478bd9Sstevel@tonic-gate extern in6addr_scope_t	ip_addr_scope_v6(const in6_addr_t *);
3597c478bd9Sstevel@tonic-gate extern mblk_t	*ip_bind_v6(queue_t *, mblk_t *, conn_t *, ip6_pkt_t *);
3607c478bd9Sstevel@tonic-gate extern void	ip_build_hdrs_v6(uchar_t *, uint_t, ip6_pkt_t *, uint8_t);
3617c478bd9Sstevel@tonic-gate extern void	ip_deliver_local_v6(queue_t *, mblk_t *, ill_t *, uint8_t,
3627c478bd9Sstevel@tonic-gate 		    uint_t, uint_t);
3637c478bd9Sstevel@tonic-gate extern int	ip_fanout_send_icmp_v6(queue_t *, mblk_t *, uint_t,
3647c478bd9Sstevel@tonic-gate 		    uint_t, uint8_t, uint_t, boolean_t, zoneid_t);
3657c478bd9Sstevel@tonic-gate extern int	ip_find_hdr_v6(mblk_t *, ip6_t *, ip6_pkt_t *, uint8_t *);
3667c478bd9Sstevel@tonic-gate extern in6_addr_t ip_get_dst_v6(ip6_t *, boolean_t *);
3677c478bd9Sstevel@tonic-gate extern ip6_rthdr_t	*ip_find_rthdr_v6(ip6_t *, uint8_t *);
3687c478bd9Sstevel@tonic-gate extern int	ip_hdr_complete_v6(ip6_t *, zoneid_t);
3697c478bd9Sstevel@tonic-gate extern boolean_t	ip_hdr_length_nexthdr_v6(mblk_t *, ip6_t *,
3707c478bd9Sstevel@tonic-gate 		    uint16_t *, uint8_t **);
3717c478bd9Sstevel@tonic-gate extern int	ip_hdr_length_v6(mblk_t *, ip6_t *);
3727c478bd9Sstevel@tonic-gate extern uint32_t	ip_massage_options_v6(ip6_t *, ip6_rthdr_t *);
373*ff550d0eSmasputra extern void	ip_wput_frag_v6(mblk_t *, ire_t *, uint_t, conn_t *, int, int);
3747c478bd9Sstevel@tonic-gate extern void 	ip_wput_ipsec_out_v6(queue_t *, mblk_t *, ip6_t *, ill_t *,
3757c478bd9Sstevel@tonic-gate     ire_t *);
3767c478bd9Sstevel@tonic-gate extern int	ip_total_hdrs_len_v6(ip6_pkt_t *);
3777c478bd9Sstevel@tonic-gate extern int	ipsec_ah_get_hdr_size_v6(mblk_t *, boolean_t);
3787c478bd9Sstevel@tonic-gate extern void	ip_wput_local_v6(queue_t *, ill_t *, ip6_t *, mblk_t *,
3797c478bd9Sstevel@tonic-gate 		    ire_t *, int);
3807c478bd9Sstevel@tonic-gate extern void	ip_wput_md_v6(queue_t *, mblk_t *, conn_t *);
3817c478bd9Sstevel@tonic-gate extern void	ip_output_v6(void *, mblk_t *, void *, int);
3827c478bd9Sstevel@tonic-gate extern void	ip_xmit_v6(mblk_t *, ire_t *, uint_t, conn_t *, int,
3837c478bd9Sstevel@tonic-gate 			struct ipsec_out_s *);
3847c478bd9Sstevel@tonic-gate extern void	ip_rput_data_v6(queue_t *, ill_t *, mblk_t *, ip6_t *,
3857c478bd9Sstevel@tonic-gate 		    uint_t, mblk_t *);
3867c478bd9Sstevel@tonic-gate extern void	mld_input(queue_t *, mblk_t *, ill_t *);
3877c478bd9Sstevel@tonic-gate extern void	mld_joingroup(ilm_t *);
3887c478bd9Sstevel@tonic-gate extern void	mld_leavegroup(ilm_t *);
3897c478bd9Sstevel@tonic-gate extern void	mld_timeout_handler(void *);
3907c478bd9Sstevel@tonic-gate extern void	mld_timeout_start(int);
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate extern void	pr_addr_dbg(char *, int, const void *);
3937c478bd9Sstevel@tonic-gate extern ipif_t	*ip_newroute_get_src_ipif_v6(ipif_t *, boolean_t,
3947c478bd9Sstevel@tonic-gate 		const in6_addr_t *);
3957c478bd9Sstevel@tonic-gate extern int	ip_multirt_apply_membership_v6(int (*fn)(conn_t *, boolean_t,
3967c478bd9Sstevel@tonic-gate 		const in6_addr_t *, int, mcast_record_t, const in6_addr_t *,
3977c478bd9Sstevel@tonic-gate 		mblk_t *), ire_t *, conn_t *, boolean_t, const in6_addr_t *,
3987c478bd9Sstevel@tonic-gate 		mcast_record_t, const in6_addr_t *, mblk_t *);
3997c478bd9Sstevel@tonic-gate extern void	ip_newroute_ipif_v6(queue_t *, mblk_t *, ipif_t *,
4007c478bd9Sstevel@tonic-gate 		in6_addr_t, int, zoneid_t);
4017c478bd9Sstevel@tonic-gate extern void	ip_newroute_v6(queue_t *, mblk_t *, const in6_addr_t *,
4027c478bd9Sstevel@tonic-gate 		const in6_addr_t *, ill_t *, zoneid_t);
4037c478bd9Sstevel@tonic-gate extern void	ip6_kstat_init(void);
4047c478bd9Sstevel@tonic-gate extern size_t	ip6_get_src_preferences(conn_t *, uint32_t *);
4057c478bd9Sstevel@tonic-gate extern int	ip6_set_src_preferences(conn_t *, uint32_t);
4067c478bd9Sstevel@tonic-gate extern int	ip6_set_pktinfo(cred_t *, conn_t *, struct in6_pktinfo *,
4077c478bd9Sstevel@tonic-gate     mblk_t *);
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate #endif
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate #endif	/* _INET_IP6_H */
416