1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 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. 26 */ 27 28 #ifndef _INET_IP6_H 29 #define _INET_IP6_H 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 #include <sys/isa_defs.h> 36 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 */ 41 42 /* version number for IPv6 - hard to get this one wrong! */ 43 #define IPV6_VERSION 6 44 45 #define IPV6_HDR_LEN 40 46 47 #define IPV6_ADDR_LEN 16 48 49 /* 50 * IPv6 address scopes. The values of these enums also match the scope 51 * field of multicast addresses. 52 */ 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; 61 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 66 67 #ifdef _KERNEL 68 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 77 78 /* Default IPv4 TTL for IPv6-in-IPv4 encapsulated packets */ 79 #define IPV6_DEFAULT_HOPS 60 /* XXX What should it be? */ 80 81 /* Max IPv6 TTL */ 82 #define IPV6_MAX_HOPS 255 83 84 /* Minimum IPv6 MTU from rfc2460 */ 85 #define IPV6_MIN_MTU 1280 86 87 /* EUI-64 based token length */ 88 #define IPV6_TOKEN_LEN 64 89 90 /* Length of an advertised IPv6 prefix */ 91 #define IPV6_PREFIX_LEN 64 92 93 /* Default and maximum tunnel encapsulation limits. See RFC 2473. */ 94 #define IPV6_DEFAULT_ENCAPLIMIT 4 95 #define IPV6_MAX_ENCAPLIMIT 255 96 97 /* 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). 103 */ 104 #define MIN_EHDR_LEN 8 105 #define MAX_EHDR_LEN 2048 106 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 112 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 121 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 128 129 /* 130 * UTILITY MACROS FOR ADDRESSES. 131 */ 132 133 /* 134 * Convert an IPv4 address mask to an IPv6 mask. Pad with 1-bits. 135 */ 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)) 140 141 /* 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. 146 */ 147 #define V4_PART_OF_V6(v6) v6.s6_addr32[3] 148 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) 155 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 */ 163 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 */ 178 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) 184 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])) 191 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]))) 201 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]) 208 209 #define ILL_FRAG_HASH_V6(v6addr, i) \ 210 ((ntohl((v6addr).s6_addr32[3]) ^ (i ^ (i >> 8))) % \ 211 ILL_FRAG_HASH_TBL_COUNT) 212 213 214 /* 215 * GLOBAL EXTERNALS 216 */ 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; 225 226 /* 227 * FUNCTION PROTOTYPES 228 */ 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 *); 241 242 extern boolean_t conn_wantpacket_v6(conn_t *, ip_recv_attr_t *, ip6_t *); 243 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 *); 280 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); 286 287 #endif /* _KERNEL */ 288 289 #ifdef __cplusplus 290 } 291 #endif 292 293 #endif /* _INET_IP6_H */ 294