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 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _INET_IP6_H 27 #define _INET_IP6_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #include <sys/isa_defs.h> 34 35 #ifdef _KERNEL 36 /* icmp6_t is used in the prototype of icmp_inbound_error_fanout_v6() */ 37 #include <netinet/icmp6.h> 38 #endif /* _KERNEL */ 39 40 /* version number for IPv6 - hard to get this one wrong! */ 41 #define IPV6_VERSION 6 42 43 #define IPV6_HDR_LEN 40 44 45 #define IPV6_ADDR_LEN 16 46 47 /* 48 * IPv6 address scopes. The values of these enums also match the scope 49 * field of multicast addresses. 50 */ 51 typedef enum { 52 IP6_SCOPE_INTFLOCAL = 1, /* Multicast addresses only */ 53 IP6_SCOPE_LINKLOCAL, 54 IP6_SCOPE_SUBNETLOCAL, /* Multicast addresses only */ 55 IP6_SCOPE_ADMINLOCAL, /* Multicast addresses only */ 56 IP6_SCOPE_SITELOCAL, 57 IP6_SCOPE_GLOBAL 58 } in6addr_scope_t; 59 60 #ifdef _KERNEL 61 62 /* 63 * Private header used between the transports and IP to carry the content 64 * of the options IPV6_PKTINFO/IPV6_RECVPKTINFO (the interface index only) 65 * and IPV6_NEXTHOP. 66 * Also used to specify that raw sockets do not want the UDP/TCP transport 67 * checksums calculated in IP (akin to IP_HDR_INCLUDED) and provide for 68 * IPV6_CHECKSUM on the transmit side (using ip6i_checksum_off). 69 * 70 * When this header is used it must be the first header in the packet i.e. 71 * before the real ip6 header. The use of a next header value of 255 72 * (IPPROTO_RAW) in this header indicates its presence. Note that 73 * ip6_nxt = IPPROTO_RAW indicates that "this" header is ip6_info - the 74 * next header is always IPv6. 75 * 76 * Note that ip6i_nexthop is at the same offset as ip6_dst so that 77 * this header can be kept in the packet while the it passes through 78 * ip_newroute* and the ndp code. Those routines will use ip6_dst for 79 * resolution. 80 * 81 * Implementation offset assumptions about ip6_info_t and ip6_t fields 82 * and their alignments shown in figure below 83 * 84 * ip6_info (Private headers from transports to IP) header below 85 * _______________________________________________________________ _ _ _ _ _ 86 * | .... | ip6i_nxt (255)| ......................|ip6i_nexthop| ...ip6_t. 87 * --------------------------------------------------------------- - - - - - 88 * ^ ^ 89 * <---- >| same offset for {ip6i_nxt,ip6_nxt} ^ 90 * ^ ^ 91 * <------^-------------------------------------->| same offset for 92 * ^ ^ {ip6i_nxthop,ip6_dst} 93 * _______________________________________________________________ _ _ _ 94 * | .... | ip6_nxt | ......................|ip6_dst | .other hdrs... 95 * --------------------------------------------------------------- - - - 96 * ip6_t (IPv6 protocol) header above 97 */ 98 struct ip6_info { 99 union { 100 struct ip6_info_ctl { 101 uint32_t ip6i_un1_flow; 102 uint16_t ip6i_un1_plen; /* payload length */ 103 uint8_t ip6i_un1_nxt; /* next header */ 104 uint8_t ip6i_un1_hlim; /* hop limit */ 105 } ip6i_un1; 106 } ip6i_ctlun; 107 int ip6i_flags; /* See below */ 108 int ip6i_ifindex; 109 int ip6i_checksum_off; 110 int ip6i_pad; 111 in6_addr_t ip6i_nexthop; /* Same offset as ip6_dst */ 112 }; 113 typedef struct ip6_info ip6i_t; 114 115 #define ip6i_flow ip6i_ctlun.ip6i_un1.ip6i_un1_flow 116 #define ip6i_vcf ip6i_flow /* Version, class, flow */ 117 #define ip6i_nxt ip6i_ctlun.ip6i_un1.ip6i_un1_nxt 118 #define ip6i_hops ip6i_ctlun.ip6i_un1.ip6i_un1_hlim 119 120 /* ip6_info flags */ 121 #define IP6I_IFINDEX 0x1 /* ip6i_ifindex is set (to nonzero value) */ 122 #define IP6I_NEXTHOP 0x2 /* ip6i_nexthop is different than ip6_dst */ 123 #define IP6I_NO_ULP_CKSUM 0x4 124 /* 125 * Do not generate TCP/UDP/SCTP transport checksum. 126 * Used by raw sockets. Does not affect the 127 * generation of transport checksums for ICMPv6 128 * since such packets always arrive through 129 * a raw socket. 130 */ 131 #define IP6I_UNSPEC_SRC 0x8 132 /* Used to carry conn_unspec_src through ip_newroute* */ 133 #define IP6I_RAW_CHECKSUM 0x10 134 /* Compute checksum and stuff in ip6i_checksum_off */ 135 #define IP6I_VERIFY_SRC 0x20 /* Verify ip6_src. Used when IPV6_PKTINFO */ 136 #define IP6I_ATTACH_IF 0x40 /* Bind to no failover address or BOUND_PIF. */ 137 #define IP6I_DROP_IFDELAYED 0x80 138 /* Drop the packet if delayed in ndp resolver */ 139 #define IP6I_ND_DELAYED 0x100 /* Packet was delayed in ndp resolver */ 140 #define IP6I_DONTFRAG 0x200 /* Don't fragment this packet */ 141 #define IP6I_HOPLIMIT 0x400 /* hoplimit has been set by the sender */ 142 143 /* 144 * These constants refer to the IPV6_USE_MIN_MTU API. The 145 * actually values used in the API are these values shifted down 146 * 10 bits minus 2 [-1, 1]. 0 (-2 after conversion) is considered 147 * the same as the default (-1). IP6I_API_USE_MIN_MTU(f, x) returns 148 * the flags field updated with min mtu. IP6I_USE_MIN_MTU_API takes the 149 * field and returns the API value (+ the -2 value). 150 */ 151 #define IP6I_USE_MIN_MTU_UNICAST 0x400 152 #define IP6I_USE_MIN_MTU_ALWAYS 0x800 153 #define IP6I_USE_MIN_MTU_NEVER 0xC00 154 #define IP6I_USE_MIN_MTU_API(x) ((((x) & 0xC00) >> 10) - 2) 155 #define IP6I_API_USE_MIN_MTU(f, x) (((f) & ~0xC00) &\ 156 ((((x) + 2) & 0x3) << 11)) 157 #define IPV6_USE_MIN_MTU_DEFAULT -2 158 #define IPV6_USE_MIN_MTU_UNICAST -1 159 #define IPV6_USE_MIN_MTU_ALWAYS 0 160 #define IPV6_USE_MIN_MTU_NEVER 1 161 162 /* Extract the scope from a multicast address */ 163 #ifdef _BIG_ENDIAN 164 #define IN6_ADDR_MC_SCOPE(addr) \ 165 (((addr)->s6_addr32[0] & 0x000f0000) >> 16) 166 #else 167 #define IN6_ADDR_MC_SCOPE(addr) \ 168 (((addr)->s6_addr32[0] & 0x00000f00) >> 8) 169 #endif 170 171 /* Default IPv4 TTL for IPv6-in-IPv4 encapsulated packets */ 172 #define IPV6_DEFAULT_HOPS 60 /* XXX What should it be? */ 173 174 /* Max IPv6 TTL */ 175 #define IPV6_MAX_HOPS 255 176 177 /* Minimum IPv6 MTU from rfc2460 */ 178 #define IPV6_MIN_MTU 1280 179 180 /* EUI-64 based token length */ 181 #define IPV6_TOKEN_LEN 64 182 183 /* Length of an advertised IPv6 prefix */ 184 #define IPV6_PREFIX_LEN 64 185 186 /* Default and maximum tunnel encapsulation limits. See RFC 2473. */ 187 #define IPV6_DEFAULT_ENCAPLIMIT 4 188 #define IPV6_MAX_ENCAPLIMIT 255 189 190 /* 191 * Minimum and maximum extension header lengths for IPv6. The 8-bit 192 * length field of each extension header (see rfc2460) specifies the 193 * number of 8 octet units of data in the header not including the 194 * first 8 octets. A value of 0 would indicate 8 bytes (0 * 8 + 8), 195 * and 255 would indicate 2048 bytes (255 * 8 + 8). 196 */ 197 #define MIN_EHDR_LEN 8 198 #define MAX_EHDR_LEN 2048 199 200 /* 201 * The high-order bit of the version field is used by the transports to 202 * indicate a reachability confirmation to IP. 203 */ 204 #define IP_FORWARD_PROG_BIT 0x8 205 206 #ifdef _BIG_ENDIAN 207 #define IPV6_DEFAULT_VERS_AND_FLOW 0x60000000 208 #define IPV6_VERS_AND_FLOW_MASK 0xF0000000 209 #define IP_FORWARD_PROG ((uint32_t)IP_FORWARD_PROG_BIT << 28) 210 #define V6_MCAST 0xFF000000 211 #define V6_LINKLOCAL 0xFE800000 212 213 #define IPV6_FLOW_TCLASS(x) (((x) & IPV6_FLOWINFO_TCLASS) >> 20) 214 #define IPV6_TCLASS_FLOW(f, c) (((f) & ~IPV6_FLOWINFO_TCLASS) |\ 215 ((c) << 20)) 216 217 #else 218 #define IPV6_DEFAULT_VERS_AND_FLOW 0x00000060 219 #define IPV6_VERS_AND_FLOW_MASK 0x000000F0 220 #define IP_FORWARD_PROG ((uint32_t)IP_FORWARD_PROG_BIT << 4) 221 222 #define V6_MCAST 0x000000FF 223 #define V6_LINKLOCAL 0x000080FE 224 225 #define IPV6_FLOW_TCLASS(x) ((((x) & 0xf000U) >> 12) |\ 226 (((x) & 0xf) << 4)) 227 #define IPV6_TCLASS_FLOW(f, c) (((f) & ~IPV6_FLOWINFO_TCLASS) |\ 228 ((((c) & 0xf) << 12) |\ 229 (((c) & 0xf0) >> 4))) 230 #endif 231 232 /* 233 * UTILITY MACROS FOR ADDRESSES. 234 */ 235 236 /* 237 * Convert an IPv4 address mask to an IPv6 mask. Pad with 1-bits. 238 */ 239 #define V4MASK_TO_V6(v4, v6) ((v6).s6_addr32[0] = 0xffffffffUL, \ 240 (v6).s6_addr32[1] = 0xffffffffUL, \ 241 (v6).s6_addr32[2] = 0xffffffffUL, \ 242 (v6).s6_addr32[3] = (v4)) 243 244 /* 245 * Convert aligned IPv4-mapped IPv6 address into an IPv4 address. 246 * Note: We use "v6" here in definition of macro instead of "(v6)" 247 * Not possible to use "(v6)" here since macro is used with struct 248 * field names as arguments. 249 */ 250 #define V4_PART_OF_V6(v6) v6.s6_addr32[3] 251 252 #ifdef _BIG_ENDIAN 253 #define V6_OR_V4_INADDR_ANY(a) ((a).s6_addr32[3] == 0 && \ 254 ((a).s6_addr32[2] == 0xffffU || \ 255 (a).s6_addr32[2] == 0) && \ 256 (a).s6_addr32[1] == 0 && \ 257 (a).s6_addr32[0] == 0) 258 259 #else 260 #define V6_OR_V4_INADDR_ANY(a) ((a).s6_addr32[3] == 0 && \ 261 ((a).s6_addr32[2] == 0xffff0000U || \ 262 (a).s6_addr32[2] == 0) && \ 263 (a).s6_addr32[1] == 0 && \ 264 (a).s6_addr32[0] == 0) 265 #endif /* _BIG_ENDIAN */ 266 267 /* IPv4-mapped CLASSD addresses */ 268 #ifdef _BIG_ENDIAN 269 #define IN6_IS_ADDR_V4MAPPED_CLASSD(addr) \ 270 (((addr)->_S6_un._S6_u32[2] == 0x0000ffff) && \ 271 (CLASSD((addr)->_S6_un._S6_u32[3])) && \ 272 ((addr)->_S6_un._S6_u32[1] == 0) && \ 273 ((addr)->_S6_un._S6_u32[0] == 0)) 274 #else /* _BIG_ENDIAN */ 275 #define IN6_IS_ADDR_V4MAPPED_CLASSD(addr) \ 276 (((addr)->_S6_un._S6_u32[2] == 0xffff0000U) && \ 277 (CLASSD((addr)->_S6_un._S6_u32[3])) && \ 278 ((addr)->_S6_un._S6_u32[1] == 0) && \ 279 ((addr)->_S6_un._S6_u32[0] == 0)) 280 #endif /* _BIG_ENDIAN */ 281 282 /* Clear an IPv6 addr */ 283 #define V6_SET_ZERO(a) ((a).s6_addr32[0] = 0, \ 284 (a).s6_addr32[1] = 0, \ 285 (a).s6_addr32[2] = 0, \ 286 (a).s6_addr32[3] = 0) 287 288 /* Mask comparison: is IPv6 addr a, and'ed with mask m, equal to addr b? */ 289 #define V6_MASK_EQ(a, m, b) \ 290 ((((a).s6_addr32[0] & (m).s6_addr32[0]) == (b).s6_addr32[0]) && \ 291 (((a).s6_addr32[1] & (m).s6_addr32[1]) == (b).s6_addr32[1]) && \ 292 (((a).s6_addr32[2] & (m).s6_addr32[2]) == (b).s6_addr32[2]) && \ 293 (((a).s6_addr32[3] & (m).s6_addr32[3]) == (b).s6_addr32[3])) 294 295 #define V6_MASK_EQ_2(a, m, b) \ 296 ((((a).s6_addr32[0] & (m).s6_addr32[0]) == \ 297 ((b).s6_addr32[0] & (m).s6_addr32[0])) && \ 298 (((a).s6_addr32[1] & (m).s6_addr32[1]) == \ 299 ((b).s6_addr32[1] & (m).s6_addr32[1])) && \ 300 (((a).s6_addr32[2] & (m).s6_addr32[2]) == \ 301 ((b).s6_addr32[2] & (m).s6_addr32[2])) && \ 302 (((a).s6_addr32[3] & (m).s6_addr32[3]) == \ 303 ((b).s6_addr32[3] & (m).s6_addr32[3]))) 304 305 /* Copy IPv6 address (s), logically and'ed with mask (m), into (d) */ 306 #define V6_MASK_COPY(s, m, d) \ 307 ((d).s6_addr32[0] = (s).s6_addr32[0] & (m).s6_addr32[0], \ 308 (d).s6_addr32[1] = (s).s6_addr32[1] & (m).s6_addr32[1], \ 309 (d).s6_addr32[2] = (s).s6_addr32[2] & (m).s6_addr32[2], \ 310 (d).s6_addr32[3] = (s).s6_addr32[3] & (m).s6_addr32[3]) 311 312 #define ILL_FRAG_HASH_V6(v6addr, i) \ 313 ((ntohl((v6addr).s6_addr32[3]) ^ (i ^ (i >> 8))) % \ 314 ILL_FRAG_HASH_TBL_COUNT) 315 316 317 /* 318 * GLOBAL EXTERNALS 319 */ 320 extern const in6_addr_t ipv6_all_ones; 321 extern const in6_addr_t ipv6_all_zeros; 322 extern const in6_addr_t ipv6_loopback; 323 extern const in6_addr_t ipv6_all_hosts_mcast; 324 extern const in6_addr_t ipv6_all_rtrs_mcast; 325 extern const in6_addr_t ipv6_all_v2rtrs_mcast; 326 extern const in6_addr_t ipv6_solicited_node_mcast; 327 extern const in6_addr_t ipv6_unspecified_group; 328 329 /* 330 * FUNCTION PROTOTYPES 331 */ 332 333 struct ipsec_out_s; 334 335 extern void convert2ascii(char *buf, const in6_addr_t *addr); 336 extern char *inet_ntop(int, const void *, char *, int); 337 extern int inet_pton(int, char *, void *); 338 extern void icmp_time_exceeded_v6(queue_t *, mblk_t *, uint8_t, 339 boolean_t, boolean_t, zoneid_t, ip_stack_t *); 340 extern void icmp_unreachable_v6(queue_t *, mblk_t *, uint8_t, 341 boolean_t, boolean_t, zoneid_t, ip_stack_t *); 342 extern void icmp_inbound_error_fanout_v6(queue_t *, mblk_t *, ip6_t *, 343 icmp6_t *, ill_t *, boolean_t, zoneid_t); 344 extern boolean_t conn_wantpacket_v6(conn_t *, ill_t *, ip6_t *, int, zoneid_t); 345 extern mblk_t *ip_add_info_v6(mblk_t *, ill_t *, const in6_addr_t *); 346 extern in6addr_scope_t ip_addr_scope_v6(const in6_addr_t *); 347 extern mblk_t *ip_bind_v6(queue_t *, mblk_t *, conn_t *, ip6_pkt_t *); 348 extern void ip_build_hdrs_v6(uchar_t *, uint_t, ip6_pkt_t *, uint8_t); 349 extern int ip_fanout_send_icmp_v6(queue_t *, mblk_t *, uint_t, 350 uint_t, uint8_t, uint_t, boolean_t, zoneid_t, ip_stack_t *); 351 extern int ip_find_hdr_v6(mblk_t *, ip6_t *, ip6_pkt_t *, uint8_t *); 352 extern in6_addr_t ip_get_dst_v6(ip6_t *, boolean_t *); 353 extern ip6_rthdr_t *ip_find_rthdr_v6(ip6_t *, uint8_t *); 354 extern int ip_hdr_complete_v6(ip6_t *, zoneid_t, ip_stack_t *); 355 extern boolean_t ip_hdr_length_nexthdr_v6(mblk_t *, ip6_t *, 356 uint16_t *, uint8_t **); 357 extern int ip_hdr_length_v6(mblk_t *, ip6_t *); 358 extern int ip_check_v6_mblk(mblk_t *, ill_t *); 359 extern uint32_t ip_massage_options_v6(ip6_t *, ip6_rthdr_t *, netstack_t *); 360 extern void ip_wput_frag_v6(mblk_t *, ire_t *, uint_t, conn_t *, int, int); 361 extern void ip_wput_ipsec_out_v6(queue_t *, mblk_t *, ip6_t *, ill_t *, 362 ire_t *); 363 extern int ip_total_hdrs_len_v6(ip6_pkt_t *); 364 extern int ipsec_ah_get_hdr_size_v6(mblk_t *, boolean_t); 365 extern void ip_wput_v6(queue_t *, mblk_t *); 366 extern void ip_wput_local_v6(queue_t *, ill_t *, ip6_t *, mblk_t *, 367 ire_t *, int, zoneid_t); 368 extern void ip_output_v6(void *, mblk_t *, void *, int); 369 extern void ip_xmit_v6(mblk_t *, ire_t *, uint_t, conn_t *, int, 370 struct ipsec_out_s *); 371 extern void ip_rput_v6(queue_t *, mblk_t *); 372 extern void ip_rput_data_v6(queue_t *, ill_t *, mblk_t *, ip6_t *, 373 uint_t, mblk_t *, mblk_t *); 374 extern void mld_input(queue_t *, mblk_t *, ill_t *); 375 extern void mld_joingroup(ilm_t *); 376 extern void mld_leavegroup(ilm_t *); 377 extern void mld_timeout_handler(void *); 378 379 extern void pr_addr_dbg(char *, int, const void *); 380 extern int ip_multirt_apply_membership_v6(int (*fn)(conn_t *, boolean_t, 381 const in6_addr_t *, int, mcast_record_t, const in6_addr_t *, mblk_t *), 382 ire_t *, conn_t *, boolean_t, const in6_addr_t *, mcast_record_t, 383 const in6_addr_t *, mblk_t *); 384 extern void ip_newroute_ipif_v6(queue_t *, mblk_t *, ipif_t *, 385 in6_addr_t, int, zoneid_t); 386 extern void ip_newroute_v6(queue_t *, mblk_t *, const in6_addr_t *, 387 const in6_addr_t *, ill_t *, zoneid_t, ip_stack_t *); 388 extern void *ip6_kstat_init(netstackid_t, ip6_stat_t *); 389 extern void ip6_kstat_fini(netstackid_t, kstat_t *); 390 extern size_t ip6_get_src_preferences(conn_t *, uint32_t *); 391 extern int ip6_set_src_preferences(conn_t *, uint32_t); 392 extern int ip6_set_pktinfo(cred_t *, conn_t *, struct in6_pktinfo *, 393 mblk_t *); 394 extern int ip_proto_bind_laddr_v6(conn_t *, mblk_t **, uint8_t, 395 const in6_addr_t *, uint16_t, boolean_t); 396 extern int ip_proto_bind_connected_v6(conn_t *, mblk_t **, 397 uint8_t, in6_addr_t *, uint16_t, const in6_addr_t *, ip6_pkt_t *, 398 uint16_t, boolean_t, boolean_t); 399 400 #endif /* _KERNEL */ 401 402 #ifdef __cplusplus 403 } 404 #endif 405 406 #endif /* _INET_IP6_H */ 407