8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / uts / common / inet / ip6.h
blobb7954a9a4d62109a2cc0e223bf127ea09fc5ce86
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
28 #ifndef _INET_IP6_H
29 #define _INET_IP6_H
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
35 #include <sys/isa_defs.h>
37 #ifdef _KERNEL
38 /* icmp6_t is used in the prototype of icmp_inbound_error_fanout_v6() */
39 #include <netinet/icmp6.h>
40 #endif /* _KERNEL */
42 /* version number for IPv6 - hard to get this one wrong! */
43 #define IPV6_VERSION 6
45 #define IPV6_HDR_LEN 40
47 #define IPV6_ADDR_LEN 16
50 * IPv6 address scopes. The values of these enums also match the scope
51 * field of multicast addresses.
53 typedef enum {
54 IP6_SCOPE_INTFLOCAL = 1, /* Multicast addresses only */
55 IP6_SCOPE_LINKLOCAL,
56 IP6_SCOPE_SUBNETLOCAL, /* Multicast addresses only */
57 IP6_SCOPE_ADMINLOCAL, /* Multicast addresses only */
58 IP6_SCOPE_SITELOCAL,
59 IP6_SCOPE_GLOBAL
60 } in6addr_scope_t;
62 /* From RFC 3542 - setting for IPV6_USE_MIN_MTU socket option */
63 #define IPV6_USE_MIN_MTU_MULTICAST -1 /* Default */
64 #define IPV6_USE_MIN_MTU_NEVER 0
65 #define IPV6_USE_MIN_MTU_ALWAYS 1
67 #ifdef _KERNEL
69 /* Extract the scope from a multicast address */
70 #ifdef _BIG_ENDIAN
71 #define IN6_ADDR_MC_SCOPE(addr) \
72 (((addr)->s6_addr32[0] & 0x000f0000) >> 16)
73 #else
74 #define IN6_ADDR_MC_SCOPE(addr) \
75 (((addr)->s6_addr32[0] & 0x00000f00) >> 8)
76 #endif
78 /* Default IPv4 TTL for IPv6-in-IPv4 encapsulated packets */
79 #define IPV6_DEFAULT_HOPS 60 /* XXX What should it be? */
81 /* Max IPv6 TTL */
82 #define IPV6_MAX_HOPS 255
84 /* Minimum IPv6 MTU from rfc2460 */
85 #define IPV6_MIN_MTU 1280
87 /* EUI-64 based token length */
88 #define IPV6_TOKEN_LEN 64
90 /* Length of an advertised IPv6 prefix */
91 #define IPV6_PREFIX_LEN 64
93 /* Default and maximum tunnel encapsulation limits. See RFC 2473. */
94 #define IPV6_DEFAULT_ENCAPLIMIT 4
95 #define IPV6_MAX_ENCAPLIMIT 255
98 * Minimum and maximum extension header lengths for IPv6. The 8-bit
99 * length field of each extension header (see rfc2460) specifies the
100 * number of 8 octet units of data in the header not including the
101 * first 8 octets. A value of 0 would indicate 8 bytes (0 * 8 + 8),
102 * and 255 would indicate 2048 bytes (255 * 8 + 8).
104 #define MIN_EHDR_LEN 8
105 #define MAX_EHDR_LEN 2048
107 #ifdef _BIG_ENDIAN
108 #define IPV6_DEFAULT_VERS_AND_FLOW 0x60000000
109 #define IPV6_VERS_AND_FLOW_MASK 0xF0000000
110 #define V6_MCAST 0xFF000000
111 #define V6_LINKLOCAL 0xFE800000
113 #define IPV6_FLOW_TCLASS(x) (((x) & IPV6_FLOWINFO_TCLASS) >> 20)
114 #define IPV6_TCLASS_FLOW(f, c) (((f) & ~IPV6_FLOWINFO_TCLASS) |\
115 ((c) << 20))
116 #else
117 #define IPV6_DEFAULT_VERS_AND_FLOW 0x00000060
118 #define IPV6_VERS_AND_FLOW_MASK 0x000000F0
119 #define V6_MCAST 0x000000FF
120 #define V6_LINKLOCAL 0x000080FE
122 #define IPV6_FLOW_TCLASS(x) ((((x) & 0xf000U) >> 12) |\
123 (((x) & 0xf) << 4))
124 #define IPV6_TCLASS_FLOW(f, c) (((f) & ~IPV6_FLOWINFO_TCLASS) |\
125 ((((c) & 0xf) << 12) |\
126 (((c) & 0xf0) >> 4)))
127 #endif
130 * UTILITY MACROS FOR ADDRESSES.
134 * Convert an IPv4 address mask to an IPv6 mask. Pad with 1-bits.
136 #define V4MASK_TO_V6(v4, v6) ((v6).s6_addr32[0] = 0xffffffffUL, \
137 (v6).s6_addr32[1] = 0xffffffffUL, \
138 (v6).s6_addr32[2] = 0xffffffffUL, \
139 (v6).s6_addr32[3] = (v4))
142 * Convert aligned IPv4-mapped IPv6 address into an IPv4 address.
143 * Note: We use "v6" here in definition of macro instead of "(v6)"
144 * Not possible to use "(v6)" here since macro is used with struct
145 * field names as arguments.
147 #define V4_PART_OF_V6(v6) v6.s6_addr32[3]
149 #ifdef _BIG_ENDIAN
150 #define V6_OR_V4_INADDR_ANY(a) ((a).s6_addr32[3] == 0 && \
151 ((a).s6_addr32[2] == 0xffffU || \
152 (a).s6_addr32[2] == 0) && \
153 (a).s6_addr32[1] == 0 && \
154 (a).s6_addr32[0] == 0)
156 #else
157 #define V6_OR_V4_INADDR_ANY(a) ((a).s6_addr32[3] == 0 && \
158 ((a).s6_addr32[2] == 0xffff0000U || \
159 (a).s6_addr32[2] == 0) && \
160 (a).s6_addr32[1] == 0 && \
161 (a).s6_addr32[0] == 0)
162 #endif /* _BIG_ENDIAN */
164 /* IPv4-mapped CLASSD addresses */
165 #ifdef _BIG_ENDIAN
166 #define IN6_IS_ADDR_V4MAPPED_CLASSD(addr) \
167 (((addr)->_S6_un._S6_u32[2] == 0x0000ffff) && \
168 (CLASSD((addr)->_S6_un._S6_u32[3])) && \
169 ((addr)->_S6_un._S6_u32[1] == 0) && \
170 ((addr)->_S6_un._S6_u32[0] == 0))
171 #else /* _BIG_ENDIAN */
172 #define IN6_IS_ADDR_V4MAPPED_CLASSD(addr) \
173 (((addr)->_S6_un._S6_u32[2] == 0xffff0000U) && \
174 (CLASSD((addr)->_S6_un._S6_u32[3])) && \
175 ((addr)->_S6_un._S6_u32[1] == 0) && \
176 ((addr)->_S6_un._S6_u32[0] == 0))
177 #endif /* _BIG_ENDIAN */
179 /* Clear an IPv6 addr */
180 #define V6_SET_ZERO(a) ((a).s6_addr32[0] = 0, \
181 (a).s6_addr32[1] = 0, \
182 (a).s6_addr32[2] = 0, \
183 (a).s6_addr32[3] = 0)
185 /* Mask comparison: is IPv6 addr a, and'ed with mask m, equal to addr b? */
186 #define V6_MASK_EQ(a, m, b) \
187 ((((a).s6_addr32[0] & (m).s6_addr32[0]) == (b).s6_addr32[0]) && \
188 (((a).s6_addr32[1] & (m).s6_addr32[1]) == (b).s6_addr32[1]) && \
189 (((a).s6_addr32[2] & (m).s6_addr32[2]) == (b).s6_addr32[2]) && \
190 (((a).s6_addr32[3] & (m).s6_addr32[3]) == (b).s6_addr32[3]))
192 #define V6_MASK_EQ_2(a, m, b) \
193 ((((a).s6_addr32[0] & (m).s6_addr32[0]) == \
194 ((b).s6_addr32[0] & (m).s6_addr32[0])) && \
195 (((a).s6_addr32[1] & (m).s6_addr32[1]) == \
196 ((b).s6_addr32[1] & (m).s6_addr32[1])) && \
197 (((a).s6_addr32[2] & (m).s6_addr32[2]) == \
198 ((b).s6_addr32[2] & (m).s6_addr32[2])) && \
199 (((a).s6_addr32[3] & (m).s6_addr32[3]) == \
200 ((b).s6_addr32[3] & (m).s6_addr32[3])))
202 /* Copy IPv6 address (s), logically and'ed with mask (m), into (d) */
203 #define V6_MASK_COPY(s, m, d) \
204 ((d).s6_addr32[0] = (s).s6_addr32[0] & (m).s6_addr32[0], \
205 (d).s6_addr32[1] = (s).s6_addr32[1] & (m).s6_addr32[1], \
206 (d).s6_addr32[2] = (s).s6_addr32[2] & (m).s6_addr32[2], \
207 (d).s6_addr32[3] = (s).s6_addr32[3] & (m).s6_addr32[3])
209 #define ILL_FRAG_HASH_V6(v6addr, i) \
210 ((ntohl((v6addr).s6_addr32[3]) ^ (i ^ (i >> 8))) % \
211 ILL_FRAG_HASH_TBL_COUNT)
215 * GLOBAL EXTERNALS
217 extern const in6_addr_t ipv6_all_ones;
218 extern const in6_addr_t ipv6_all_zeros;
219 extern const in6_addr_t ipv6_loopback;
220 extern const in6_addr_t ipv6_all_hosts_mcast;
221 extern const in6_addr_t ipv6_all_rtrs_mcast;
222 extern const in6_addr_t ipv6_all_v2rtrs_mcast;
223 extern const in6_addr_t ipv6_solicited_node_mcast;
224 extern const in6_addr_t ipv6_unspecified_group;
227 * FUNCTION PROTOTYPES
229 extern void icmp_param_problem_nexthdr_v6(mblk_t *, boolean_t,
230 ip_recv_attr_t *);
231 extern void icmp_pkt2big_v6(mblk_t *, uint32_t, boolean_t,
232 ip_recv_attr_t *);
233 extern void icmp_time_exceeded_v6(mblk_t *, uint8_t, boolean_t,
234 ip_recv_attr_t *);
235 extern void icmp_unreachable_v6(mblk_t *, uint8_t, boolean_t,
236 ip_recv_attr_t *);
237 extern mblk_t *icmp_inbound_v6(mblk_t *, ip_recv_attr_t *);
238 extern void icmp_inbound_error_fanout_v6(mblk_t *, icmp6_t *,
239 ip_recv_attr_t *);
240 extern void icmp_update_out_mib_v6(ill_t *, icmp6_t *);
242 extern boolean_t conn_wantpacket_v6(conn_t *, ip_recv_attr_t *, ip6_t *);
244 extern in6addr_scope_t ip_addr_scope_v6(const in6_addr_t *);
245 extern void ip_build_hdrs_v6(uchar_t *, uint_t, const ip_pkt_t *, uint8_t,
246 uint32_t);
247 extern void ip_fanout_udp_multi_v6(mblk_t *, ip6_t *, uint16_t, uint16_t,
248 ip_recv_attr_t *);
249 extern void ip_fanout_send_icmp_v6(mblk_t *, uint_t, uint8_t,
250 ip_recv_attr_t *);
251 extern void ip_fanout_proto_v6(mblk_t *, ip6_t *, ip_recv_attr_t *);
252 extern int ip_find_hdr_v6(mblk_t *, ip6_t *, boolean_t, ip_pkt_t *,
253 uint8_t *);
254 extern in6_addr_t ip_get_dst_v6(ip6_t *, const mblk_t *, boolean_t *);
255 extern ip6_rthdr_t *ip_find_rthdr_v6(ip6_t *, uint8_t *);
256 extern boolean_t ip_hdr_length_nexthdr_v6(mblk_t *, ip6_t *,
257 uint16_t *, uint8_t **);
258 extern int ip_hdr_length_v6(mblk_t *, ip6_t *);
259 extern uint32_t ip_massage_options_v6(ip6_t *, ip6_rthdr_t *, netstack_t *);
260 extern void ip_forward_xmit_v6(nce_t *, mblk_t *, ip6_t *, ip_recv_attr_t *,
261 uint32_t, uint32_t);
262 extern mblk_t *ip_fraghdr_add_v6(mblk_t *, uint32_t, ip_xmit_attr_t *);
263 extern int ip_fragment_v6(mblk_t *, nce_t *, iaflags_t, uint_t, uint32_t,
264 uint32_t, zoneid_t, zoneid_t, pfirepostfrag_t postfragfn,
265 uintptr_t *ixa_cookie);
266 extern int ip_process_options_v6(mblk_t *, ip6_t *,
267 uint8_t *, uint_t, uint8_t, ip_recv_attr_t *);
268 extern void ip_process_rthdr(mblk_t *, ip6_t *, ip6_rthdr_t *,
269 ip_recv_attr_t *);
270 extern int ip_total_hdrs_len_v6(const ip_pkt_t *);
271 extern mblk_t *ipsec_early_ah_v6(mblk_t *, ip_recv_attr_t *);
272 extern int ipsec_ah_get_hdr_size_v6(mblk_t *, boolean_t);
273 extern void ip_send_potential_redirect_v6(mblk_t *, ip6_t *, ire_t *,
274 ip_recv_attr_t *);
275 extern void ip_rput_v6(queue_t *, mblk_t *);
276 extern mblk_t *mld_input(mblk_t *, ip_recv_attr_t *);
277 extern void mld_joingroup(ilm_t *);
278 extern void mld_leavegroup(ilm_t *);
279 extern void mld_timeout_handler(void *);
281 extern void pr_addr_dbg(char *, int, const void *);
282 extern void *ip6_kstat_init(netstackid_t, ip6_stat_t *);
283 extern void ip6_kstat_fini(netstackid_t, kstat_t *);
284 extern size_t ip6_get_src_preferences(ip_xmit_attr_t *, uint32_t *);
285 extern int ip6_set_src_preferences(ip_xmit_attr_t *, uint32_t);
287 #endif /* _KERNEL */
289 #ifdef __cplusplus
291 #endif
293 #endif /* _INET_IP6_H */