ip6.h revision 11042:2d6e217af1b4
1132718Skan/*
2169689Skan * CDDL HEADER START
390075Sobrien *
450397Sobrien * The contents of this file are subject to the terms of the
550397Sobrien * Common Development and Distribution License (the "License").
6132718Skan * You may not use this file except in compliance with the License.
750397Sobrien *
8132718Skan * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
950397Sobrien * or http://www.opensolaris.org/os/licensing.
1050397Sobrien * See the License for the specific language governing permissions
1150397Sobrien * and limitations under the License.
1250397Sobrien *
13132718Skan * When distributing Covered Code, include this CDDL HEADER in each
1450397Sobrien * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1550397Sobrien * If applicable, add the following below this CDDL HEADER, with the
1650397Sobrien * fields enclosed by brackets "[]" replaced with your own identifying
1750397Sobrien * information: Portions Copyright [yyyy] [name of copyright owner]
1850397Sobrien *
19132718Skan * CDDL HEADER END
20169689Skan */
21169689Skan/*
2250397Sobrien * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2350397Sobrien * Use is subject to license terms.
2450397Sobrien */
2550397Sobrien
2650397Sobrien#ifndef	_INET_IP6_H
2750397Sobrien#define	_INET_IP6_H
2850397Sobrien
2950397Sobrien#ifdef	__cplusplus
3096263Sobrienextern "C" {
3150397Sobrien#endif
3250397Sobrien
3350397Sobrien#include <sys/isa_defs.h>
3450397Sobrien
35169689Skan#ifdef	_KERNEL
36169689Skan/* icmp6_t is used in the prototype of icmp_inbound_error_fanout_v6() */
3750397Sobrien#include <netinet/icmp6.h>
3850397Sobrien#endif	/* _KERNEL */
3950397Sobrien
4050397Sobrien/* version number for IPv6 - hard to get this one wrong! */
4150397Sobrien#define	IPV6_VERSION		6
4250397Sobrien
4350397Sobrien#define	IPV6_HDR_LEN		40
4450397Sobrien
4550397Sobrien#define	IPV6_ADDR_LEN		16
4650397Sobrien
47132718Skan/*
4850397Sobrien * IPv6 address scopes.  The values of these enums also match the scope
4950397Sobrien * field of multicast addresses.
5050397Sobrien */
5150397Sobrientypedef enum {
5250397Sobrien	IP6_SCOPE_INTFLOCAL = 1,	/* Multicast addresses only */
5350397Sobrien	IP6_SCOPE_LINKLOCAL,
5450397Sobrien	IP6_SCOPE_SUBNETLOCAL,		/* Multicast addresses only */
5550397Sobrien	IP6_SCOPE_ADMINLOCAL,		/* Multicast addresses only */
5650397Sobrien	IP6_SCOPE_SITELOCAL,
5750397Sobrien	IP6_SCOPE_GLOBAL
5850397Sobrien} in6addr_scope_t;
5950397Sobrien
6050397Sobrien/* From RFC 3542 - setting for IPV6_USE_MIN_MTU socket option */
6150397Sobrien#define	IPV6_USE_MIN_MTU_MULTICAST	-1	/* Default */
6250397Sobrien#define	IPV6_USE_MIN_MTU_NEVER		0
6350397Sobrien#define	IPV6_USE_MIN_MTU_ALWAYS		1
6450397Sobrien
6550397Sobrien#ifdef	_KERNEL
6650397Sobrien
6750397Sobrien/* Extract the scope from a multicast address */
6896263Sobrien#ifdef _BIG_ENDIAN
6996263Sobrien#define	IN6_ADDR_MC_SCOPE(addr) \
7096263Sobrien	(((addr)->s6_addr32[0] & 0x000f0000) >> 16)
7150397Sobrien#else
7250397Sobrien#define	IN6_ADDR_MC_SCOPE(addr) \
7350397Sobrien	(((addr)->s6_addr32[0] & 0x00000f00) >> 8)
7450397Sobrien#endif
75169689Skan
76169689Skan/* Default IPv4 TTL for IPv6-in-IPv4 encapsulated packets */
77169689Skan#define	IPV6_DEFAULT_HOPS	60	/* XXX What should it be? */
78169689Skan
79169689Skan/* Max IPv6 TTL */
80169689Skan#define	IPV6_MAX_HOPS	255
81169689Skan
82169689Skan/* Minimum IPv6 MTU from rfc2460 */
8350397Sobrien#define	IPV6_MIN_MTU		1280
8450397Sobrien
8550397Sobrien/* EUI-64 based token length */
8650397Sobrien#define	IPV6_TOKEN_LEN		64
8750397Sobrien
8850397Sobrien/* Length of an advertised IPv6 prefix */
89169689Skan#define	IPV6_PREFIX_LEN		64
90169689Skan
91169689Skan/* Default and maximum tunnel encapsulation limits.  See RFC 2473. */
9250397Sobrien#define	IPV6_DEFAULT_ENCAPLIMIT	4
93169689Skan#define	IPV6_MAX_ENCAPLIMIT	255
94169689Skan
95169689Skan/*
96169689Skan * Minimum and maximum extension header lengths for IPv6.  The 8-bit
97169689Skan * length field of each extension header (see rfc2460) specifies the
98169689Skan * number of 8 octet units of data in the header not including the
99169689Skan * first 8 octets.  A value of 0 would indicate 8 bytes (0 * 8 + 8),
100169689Skan * and 255 would indicate 2048 bytes (255 * 8 + 8).
101169689Skan */
10250397Sobrien#define	MIN_EHDR_LEN		8
10350397Sobrien#define	MAX_EHDR_LEN		2048
10450397Sobrien
10550397Sobrien#ifdef _BIG_ENDIAN
10650397Sobrien#define	IPV6_DEFAULT_VERS_AND_FLOW	0x60000000
10750397Sobrien#define	IPV6_VERS_AND_FLOW_MASK		0xF0000000
10850397Sobrien#define	V6_MCAST			0xFF000000
10950397Sobrien#define	V6_LINKLOCAL			0xFE800000
11050397Sobrien
11150397Sobrien#define	IPV6_FLOW_TCLASS(x)		(((x) & IPV6_FLOWINFO_TCLASS) >> 20)
11250397Sobrien#define	IPV6_TCLASS_FLOW(f, c)		(((f) & ~IPV6_FLOWINFO_TCLASS) |\
11350397Sobrien					((c) << 20))
11450397Sobrien#else
11552284Sobrien#define	IPV6_DEFAULT_VERS_AND_FLOW	0x00000060
11652284Sobrien#define	IPV6_VERS_AND_FLOW_MASK		0x000000F0
11750397Sobrien#define	V6_MCAST			0x000000FF
11852284Sobrien#define	V6_LINKLOCAL			0x000080FE
119
120#define	IPV6_FLOW_TCLASS(x)		((((x) & 0xf000U) >> 12) |\
121					(((x) & 0xf) << 4))
122#define	IPV6_TCLASS_FLOW(f, c)		(((f) & ~IPV6_FLOWINFO_TCLASS) |\
123					((((c) & 0xf) << 12) |\
124					(((c) & 0xf0) >> 4)))
125#endif
126
127/*
128 * UTILITY MACROS FOR ADDRESSES.
129 */
130
131/*
132 * Convert an IPv4 address mask to an IPv6 mask.   Pad with 1-bits.
133 */
134#define	V4MASK_TO_V6(v4, v6)	((v6).s6_addr32[0] = 0xffffffffUL,	\
135				(v6).s6_addr32[1] = 0xffffffffUL,	\
136				(v6).s6_addr32[2] = 0xffffffffUL,	\
137				(v6).s6_addr32[3] = (v4))
138
139/*
140 * Convert aligned IPv4-mapped IPv6 address into an IPv4 address.
141 * Note: We use "v6" here in definition of macro instead of "(v6)"
142 * Not possible to use "(v6)" here since macro is used with struct
143 * field names as arguments.
144 */
145#define	V4_PART_OF_V6(v6)	v6.s6_addr32[3]
146
147#ifdef _BIG_ENDIAN
148#define	V6_OR_V4_INADDR_ANY(a)	((a).s6_addr32[3] == 0 &&		\
149				((a).s6_addr32[2] == 0xffffU ||	\
150				(a).s6_addr32[2] == 0) &&		\
151				(a).s6_addr32[1] == 0 &&		\
152				(a).s6_addr32[0] == 0)
153
154#else
155#define	V6_OR_V4_INADDR_ANY(a)	((a).s6_addr32[3] == 0 && 		\
156				((a).s6_addr32[2] == 0xffff0000U ||	\
157				(a).s6_addr32[2] == 0) &&		\
158				(a).s6_addr32[1] == 0 &&		\
159				(a).s6_addr32[0] == 0)
160#endif /* _BIG_ENDIAN */
161
162/* IPv4-mapped CLASSD addresses */
163#ifdef _BIG_ENDIAN
164#define	IN6_IS_ADDR_V4MAPPED_CLASSD(addr) \
165	(((addr)->_S6_un._S6_u32[2] == 0x0000ffff) && \
166	(CLASSD((addr)->_S6_un._S6_u32[3])) && \
167	((addr)->_S6_un._S6_u32[1] == 0) && \
168	((addr)->_S6_un._S6_u32[0] == 0))
169#else  /* _BIG_ENDIAN */
170#define	IN6_IS_ADDR_V4MAPPED_CLASSD(addr) \
171	(((addr)->_S6_un._S6_u32[2] == 0xffff0000U) && \
172	(CLASSD((addr)->_S6_un._S6_u32[3])) && \
173	((addr)->_S6_un._S6_u32[1] == 0) && \
174	((addr)->_S6_un._S6_u32[0] == 0))
175#endif /* _BIG_ENDIAN */
176
177/* Clear an IPv6 addr */
178#define	V6_SET_ZERO(a)		((a).s6_addr32[0] = 0,			\
179				(a).s6_addr32[1] = 0,			\
180				(a).s6_addr32[2] = 0,			\
181				(a).s6_addr32[3] = 0)
182
183/* Mask comparison: is IPv6 addr a, and'ed with mask m, equal to addr b? */
184#define	V6_MASK_EQ(a, m, b)						\
185	((((a).s6_addr32[0] & (m).s6_addr32[0]) == (b).s6_addr32[0]) &&	\
186	(((a).s6_addr32[1] & (m).s6_addr32[1]) == (b).s6_addr32[1]) &&	\
187	(((a).s6_addr32[2] & (m).s6_addr32[2]) == (b).s6_addr32[2]) &&	\
188	(((a).s6_addr32[3] & (m).s6_addr32[3]) == (b).s6_addr32[3]))
189
190#define	V6_MASK_EQ_2(a, m, b)						\
191	((((a).s6_addr32[0] & (m).s6_addr32[0]) ==			\
192	    ((b).s6_addr32[0]  & (m).s6_addr32[0])) &&			\
193	(((a).s6_addr32[1] & (m).s6_addr32[1]) ==			\
194	    ((b).s6_addr32[1]  & (m).s6_addr32[1])) &&			\
195	(((a).s6_addr32[2] & (m).s6_addr32[2]) ==			\
196	    ((b).s6_addr32[2]  & (m).s6_addr32[2])) &&			\
197	(((a).s6_addr32[3] & (m).s6_addr32[3]) ==			\
198	    ((b).s6_addr32[3]  & (m).s6_addr32[3])))
199
200/* Copy IPv6 address (s), logically and'ed with mask (m), into (d) */
201#define	V6_MASK_COPY(s, m, d)						\
202	((d).s6_addr32[0] = (s).s6_addr32[0] & (m).s6_addr32[0],	\
203	(d).s6_addr32[1] = (s).s6_addr32[1] & (m).s6_addr32[1],		\
204	(d).s6_addr32[2] = (s).s6_addr32[2] & (m).s6_addr32[2],		\
205	(d).s6_addr32[3] = (s).s6_addr32[3] & (m).s6_addr32[3])
206
207#define	ILL_FRAG_HASH_V6(v6addr, i)					\
208	((ntohl((v6addr).s6_addr32[3]) ^ (i ^ (i >> 8))) % 		\
209						ILL_FRAG_HASH_TBL_COUNT)
210
211
212/*
213 * GLOBAL EXTERNALS
214 */
215extern const in6_addr_t	ipv6_all_ones;
216extern const in6_addr_t	ipv6_all_zeros;
217extern const in6_addr_t	ipv6_loopback;
218extern const in6_addr_t	ipv6_all_hosts_mcast;
219extern const in6_addr_t	ipv6_all_rtrs_mcast;
220extern const in6_addr_t	ipv6_all_v2rtrs_mcast;
221extern const in6_addr_t	ipv6_solicited_node_mcast;
222extern const in6_addr_t	ipv6_unspecified_group;
223
224/*
225 * FUNCTION PROTOTYPES
226 */
227
228extern void	convert2ascii(char *buf, const in6_addr_t *addr);
229extern char	*inet_ntop(int, const void *, char *, int);
230extern int	inet_pton(int, char *, void *);
231extern void	icmp_param_problem_nexthdr_v6(mblk_t *, boolean_t,
232    ip_recv_attr_t *);
233extern void	icmp_pkt2big_v6(mblk_t *, uint32_t, boolean_t,
234    ip_recv_attr_t *);
235extern void	icmp_time_exceeded_v6(mblk_t *, uint8_t, boolean_t,
236    ip_recv_attr_t *);
237extern void	icmp_unreachable_v6(mblk_t *, uint8_t, boolean_t,
238    ip_recv_attr_t *);
239extern mblk_t	*icmp_inbound_v6(mblk_t *, ip_recv_attr_t *);
240extern void	icmp_inbound_error_fanout_v6(mblk_t *, icmp6_t *,
241    ip_recv_attr_t *);
242extern void	icmp_update_out_mib_v6(ill_t *, icmp6_t *);
243
244extern boolean_t conn_wantpacket_v6(conn_t *, ip_recv_attr_t *, ip6_t *);
245
246extern in6addr_scope_t	ip_addr_scope_v6(const in6_addr_t *);
247extern void	ip_build_hdrs_v6(uchar_t *, uint_t, const ip_pkt_t *, uint8_t,
248    uint32_t);
249extern void	ip_fanout_udp_multi_v6(mblk_t *, ip6_t *, uint16_t, uint16_t,
250    ip_recv_attr_t *);
251extern void	ip_fanout_send_icmp_v6(mblk_t *, uint_t, uint8_t,
252    ip_recv_attr_t *);
253extern void	ip_fanout_proto_v6(mblk_t *, ip6_t *, ip_recv_attr_t *);
254extern int	ip_find_hdr_v6(mblk_t *, ip6_t *, boolean_t, ip_pkt_t *,
255    uint8_t *);
256extern in6_addr_t ip_get_dst_v6(ip6_t *, const mblk_t *, boolean_t *);
257extern ip6_rthdr_t	*ip_find_rthdr_v6(ip6_t *, uint8_t *);
258extern boolean_t	ip_hdr_length_nexthdr_v6(mblk_t *, ip6_t *,
259    uint16_t *, uint8_t **);
260extern int	ip_hdr_length_v6(mblk_t *, ip6_t *);
261extern uint32_t	ip_massage_options_v6(ip6_t *, ip6_rthdr_t *, netstack_t *);
262extern void	ip_forward_xmit_v6(nce_t *, mblk_t *, ip6_t *, ip_recv_attr_t *,
263    uint32_t, uint32_t);
264extern mblk_t	*ip_fraghdr_add_v6(mblk_t *, uint32_t, ip_xmit_attr_t *);
265extern int	ip_fragment_v6(mblk_t *, nce_t *, iaflags_t, uint_t, uint32_t,
266    uint32_t, zoneid_t, zoneid_t, pfirepostfrag_t postfragfn,
267    uintptr_t *ixa_cookie);
268extern int	ip_process_options_v6(mblk_t *, ip6_t *,
269    uint8_t *, uint_t, uint8_t, ip_recv_attr_t *);
270extern void	ip_process_rthdr(mblk_t *, ip6_t *, ip6_rthdr_t *,
271    ip_recv_attr_t *);
272extern int	ip_total_hdrs_len_v6(const ip_pkt_t *);
273extern mblk_t	*ipsec_early_ah_v6(mblk_t *, ip_recv_attr_t *);
274extern int	ipsec_ah_get_hdr_size_v6(mblk_t *, boolean_t);
275extern void	ip_send_potential_redirect_v6(mblk_t *, ip6_t *, ire_t *,
276    ip_recv_attr_t *);
277extern void	ip_rput_v6(queue_t *, mblk_t *);
278extern mblk_t	*mld_input(mblk_t *, ip_recv_attr_t *);
279extern void	mld_joingroup(ilm_t *);
280extern void	mld_leavegroup(ilm_t *);
281extern void	mld_timeout_handler(void *);
282
283extern void	pr_addr_dbg(char *, int, const void *);
284extern void	*ip6_kstat_init(netstackid_t, ip6_stat_t *);
285extern void	ip6_kstat_fini(netstackid_t, kstat_t *);
286extern size_t	ip6_get_src_preferences(ip_xmit_attr_t *, uint32_t *);
287extern int	ip6_set_src_preferences(ip_xmit_attr_t *, uint32_t);
288
289#endif	/* _KERNEL */
290
291#ifdef	__cplusplus
292}
293#endif
294
295#endif	/* _INET_IP6_H */
296