1 /* $OpenBSD: in6.h,v 1.106 2020/06/24 22:03:44 cheloha Exp $ */ 2 /* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */ 3 4 /* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the project nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 /* 34 * Copyright (c) 1982, 1986, 1990, 1993 35 * The Regents of the University of California. All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 2. Redistributions in binary form must reproduce the above copyright 43 * notice, this list of conditions and the following disclaimer in the 44 * documentation and/or other materials provided with the distribution. 45 * 3. Neither the name of the University nor the names of its contributors 46 * may be used to endorse or promote products derived from this software 47 * without specific prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 * 61 * @(#)in.h 8.3 (Berkeley) 1/3/94 62 */ 63 64 #ifndef __KAME_NETINET_IN_H_INCLUDED_ 65 #error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553" 66 #endif 67 68 #ifndef _NETINET6_IN6_H_ 69 #define _NETINET6_IN6_H_ 70 71 /* 72 * Identification of the network protocol stack 73 * for *BSD-current/release: http://www.kame.net/dev/cvsweb2.cgi/kame/COVERAGE 74 * has the table of implementation/integration differences. 75 */ 76 #define __KAME__ 77 78 /* 79 * IPv6 address 80 */ 81 struct in6_addr { 82 union { 83 u_int8_t __u6_addr8[16]; 84 u_int16_t __u6_addr16[8]; 85 u_int32_t __u6_addr32[4]; 86 } __u6_addr; /* 128-bit IP6 address */ 87 }; 88 89 #define s6_addr __u6_addr.__u6_addr8 90 #ifdef _KERNEL /* XXX nonstandard */ 91 #define s6_addr8 __u6_addr.__u6_addr8 92 #define s6_addr16 __u6_addr.__u6_addr16 93 #define s6_addr32 __u6_addr.__u6_addr32 94 #endif 95 96 #ifndef INET6_ADDRSTRLEN 97 #define INET6_ADDRSTRLEN 46 98 #endif 99 100 /* 101 * Socket address for IPv6 102 */ 103 #if __BSD_VISIBLE 104 #define SIN6_LEN /* Indicates sockaddr_in6 has a sin6_len field */ 105 #endif /* __BSD_VISIBLE */ 106 struct sockaddr_in6 { 107 u_int8_t sin6_len; /* length of this struct(sa_family_t)*/ 108 sa_family_t sin6_family; /* AF_INET6 (sa_family_t) */ 109 in_port_t sin6_port; /* Transport layer port # (in_port_t)*/ 110 u_int32_t sin6_flowinfo; /* IP6 flow information */ 111 struct in6_addr sin6_addr; /* IP6 address */ 112 u_int32_t sin6_scope_id; /* intface scope id */ 113 }; 114 115 116 /* 117 * Local definition for masks 118 */ 119 #ifdef _KERNEL /* XXX nonstandard */ 120 #define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}} 121 #define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \ 122 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 123 #define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 125 #define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 126 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}} 127 #define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 128 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}} 129 130 extern const struct sockaddr_in6 sa6_any; 131 132 extern const struct in6_addr in6mask0; 133 extern const struct in6_addr in6mask32; 134 extern const struct in6_addr in6mask64; 135 extern const struct in6_addr in6mask96; 136 extern const struct in6_addr in6mask128; 137 #endif /* _KERNEL */ 138 139 /* Both kernel and libc define these for use */ 140 extern const struct in6_addr in6addr_any; 141 extern const struct in6_addr in6addr_loopback; 142 extern const struct in6_addr in6addr_intfacelocal_allnodes; 143 extern const struct in6_addr in6addr_linklocal_allnodes; 144 extern const struct in6_addr in6addr_linklocal_allrouters; 145 146 #if __BSD_VISIBLE 147 /* 148 * IPv6 route structure 149 */ 150 struct route_in6 { 151 struct rtentry *ro_rt; 152 u_long ro_tableid; /* padded to long for alignment */ 153 struct sockaddr_in6 ro_dst; 154 }; 155 156 /* 157 * Definition of some useful macros to handle IP6 addresses 158 */ 159 #define IN6ADDR_ANY_INIT \ 160 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 162 #define IN6ADDR_LOOPBACK_INIT \ 163 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 164 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 165 #define IN6ADDR_NODELOCAL_ALLNODES_INIT \ 166 {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 167 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 168 #define IN6ADDR_INTFACELOCAL_ALLNODES_INIT \ 169 {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 170 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 171 #define IN6ADDR_LINKLOCAL_ALLNODES_INIT \ 172 {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 174 #define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \ 175 {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}} 177 178 #define IN6_ARE_ADDR_EQUAL(a, b) \ 179 (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 180 181 #endif /* __BSD_VISIBLE */ 182 183 /* 184 * Macros started with IPV6_ADDR is KAME local 185 */ 186 #define __IPV6_ADDR_INT32_ONE htonl(1) 187 #define __IPV6_ADDR_INT32_TWO htonl(2) 188 #define __IPV6_ADDR_INT32_MNL htonl(0xff010000) 189 #define __IPV6_ADDR_INT32_MLL htonl(0xff020000) 190 #define __IPV6_ADDR_INT32_SMP htonl(0x0000ffff) 191 #define __IPV6_ADDR_INT16_ULL htons(0xfe80) 192 #define __IPV6_ADDR_INT16_USL htons(0xfec0) 193 #define __IPV6_ADDR_INT16_MLL htons(0xff02) 194 195 /* 196 * Unspecified 197 */ 198 #define IN6_IS_ADDR_UNSPECIFIED(a) \ 199 ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 200 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 201 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 202 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0)) 203 204 /* 205 * Loopback 206 */ 207 #define IN6_IS_ADDR_LOOPBACK(a) \ 208 ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 209 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 210 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 211 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == __IPV6_ADDR_INT32_ONE)) 212 213 /* 214 * IPv4 compatible 215 */ 216 #define IN6_IS_ADDR_V4COMPAT(a) \ 217 ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 218 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 219 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 220 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \ 221 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != __IPV6_ADDR_INT32_ONE)) 222 223 /* 224 * Mapped 225 */ 226 #define IN6_IS_ADDR_V4MAPPED(a) \ 227 ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 228 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 229 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == __IPV6_ADDR_INT32_SMP)) 230 231 /* 232 * Unicast Scope 233 * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373). 234 */ 235 #define IN6_IS_ADDR_LINKLOCAL(a) \ 236 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) 237 #define IN6_IS_ADDR_SITELOCAL(a) \ 238 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) 239 240 /* 241 * Multicast 242 */ 243 #define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 244 #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) 245 246 #define __IPV6_ADDR_SCOPE_NODELOCAL 0x01 247 #define __IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 248 #define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02 249 #define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 250 #define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 251 #define __IPV6_ADDR_SCOPE_GLOBAL 0x0e 252 253 #define IN6_IS_ADDR_MC_NODELOCAL(a) \ 254 (IN6_IS_ADDR_MULTICAST(a) && \ 255 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL)) 256 #define IN6_IS_ADDR_MC_INTFACELOCAL(a) \ 257 (IN6_IS_ADDR_MULTICAST(a) && \ 258 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_INTFACELOCAL)) 259 #define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 260 (IN6_IS_ADDR_MULTICAST(a) && \ 261 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL)) 262 #define IN6_IS_ADDR_MC_SITELOCAL(a) \ 263 (IN6_IS_ADDR_MULTICAST(a) && \ 264 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) 265 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 266 (IN6_IS_ADDR_MULTICAST(a) && \ 267 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) 268 #define IN6_IS_ADDR_MC_GLOBAL(a) \ 269 (IN6_IS_ADDR_MULTICAST(a) && \ 270 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL)) 271 272 #ifdef _KERNEL 273 #define IN6_IS_SCOPE_LINKLOCAL(a) \ 274 ((IN6_IS_ADDR_LINKLOCAL(a)) || \ 275 (IN6_IS_ADDR_MC_LINKLOCAL(a))) 276 #define IN6_IS_SCOPE_EMBED(a) \ 277 ((IN6_IS_ADDR_LINKLOCAL(a)) || \ 278 (IN6_IS_ADDR_MC_LINKLOCAL(a)) || \ 279 (IN6_IS_ADDR_MC_INTFACELOCAL(a))) 280 281 #define IFA6_IS_DEPRECATED(a) \ 282 ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \ 283 (u_int32_t)((getuptime() - (a)->ia6_updatetime)) > \ 284 (a)->ia6_lifetime.ia6t_pltime) 285 #define IFA6_IS_INVALID(a) \ 286 ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \ 287 (u_int32_t)((getuptime() - (a)->ia6_updatetime)) > \ 288 (a)->ia6_lifetime.ia6t_vltime) 289 290 #endif /* _KERNEL */ 291 292 /* 293 * Options for use with [gs]etsockopt at the IPV6 level. 294 * First word of comment is data type; bool is stored in int. 295 */ 296 #define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ 297 #define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */ 298 #define IPV6_MULTICAST_HOPS 10 /* u_int; set/get IP6 multicast hops */ 299 #define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */ 300 #define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */ 301 #define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */ 302 #define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */ 303 #if __BSD_VISIBLE 304 #define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */ 305 #endif 306 307 #define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */ 308 #define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */ 309 310 /* new socket options introduced in RFC3542 */ 311 #define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */ 312 313 #define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */ 314 #define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */ 315 #define IPV6_RECVRTHDR 38 /* bool; recv routing header */ 316 #define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */ 317 #define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */ 318 319 #define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */ 320 #define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */ 321 322 #define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt), 323 4 bytes int; MTU notification (cmsg) */ 324 325 /* More new socket options introduced in RFC3542 */ 326 #define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */ 327 #define IPV6_HOPLIMIT 47 /* int; send hop limit */ 328 #define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */ 329 #define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */ 330 #define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */ 331 #define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */ 332 333 #define IPV6_AUTH_LEVEL 53 /* int; authentication used */ 334 #define IPV6_ESP_TRANS_LEVEL 54 /* int; transport encryption */ 335 #define IPV6_ESP_NETWORK_LEVEL 55 /* int; full-packet encryption */ 336 #if __BSD_VISIBLE 337 #define IPSEC6_OUTSA 56 /* set the outbound SA for a socket */ 338 #endif 339 #define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */ 340 341 #define IPV6_AUTOFLOWLABEL 59 /* bool; attach flowlabel automagically */ 342 #define IPV6_IPCOMP_LEVEL 60 /* int; compression */ 343 344 #define IPV6_TCLASS 61 /* int; send traffic class value */ 345 #define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */ 346 #define IPV6_PIPEX 63 /* bool; using PIPEX */ 347 348 #define IPV6_RECVDSTPORT 64 /* bool; receive IP dst port w/dgram */ 349 #define IPV6_MINHOPCOUNT 65 /* int; minimum recv hop limit */ 350 351 #define IPV6_RTABLE 0x1021 /* int; routing table, see SO_RTABLE */ 352 353 /* to define items, should talk with KAME guys first, for *BSD compatibility */ 354 #define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor */ 355 #define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ 356 357 /* 358 * Defaults and limits for options 359 */ 360 #define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ 361 #define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 362 363 /* 364 * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. 365 */ 366 struct ipv6_mreq { 367 struct in6_addr ipv6mr_multiaddr; 368 unsigned int ipv6mr_interface; 369 }; 370 371 /* 372 * IPV6_PKTINFO: Packet information(RFC3542 sec 6) 373 */ 374 struct in6_pktinfo { 375 struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 376 unsigned int ipi6_ifindex; /* send/recv interface index */ 377 }; 378 379 /* 380 * Control structure for IPV6_RECVPATHMTU socket option. 381 * XXX Not allowed here by POSIX, but required by RFC 3542, so go 382 * XXX with the code on the pavement. 383 */ 384 struct ip6_mtuinfo { 385 struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */ 386 u_int32_t ip6m_mtu; 387 }; 388 389 /* 390 * Argument for IPV6_PORTRANGE: 391 * - which range to search when port is unspecified at bind() or connect() 392 */ 393 #define IPV6_PORTRANGE_DEFAULT 0 /* default range */ 394 #define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 395 #define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 396 397 #ifdef __BSD_VISIBLE 398 399 #ifndef _SOCKLEN_T_DEFINED_ 400 #define _SOCKLEN_T_DEFINED_ 401 typedef __socklen_t socklen_t; /* length type for network syscalls */ 402 #endif 403 404 #endif /* __BSD_VISIBLE */ 405 406 #ifdef _KERNEL 407 extern const u_char inet6ctlerrmap[]; 408 extern const struct in6_addr zeroin6_addr; 409 410 struct mbuf; 411 struct sockaddr; 412 struct sockaddr_in6; 413 struct ifaddr; 414 struct in6_ifaddr; 415 struct ifnet; 416 417 void ipv6_input(struct ifnet *, struct mbuf *); 418 419 int in6_cksum(struct mbuf *, uint8_t, uint32_t, uint32_t); 420 void in6_proto_cksum_out(struct mbuf *, struct ifnet *); 421 int in6_localaddr(struct in6_addr *); 422 int in6_addrscope(struct in6_addr *); 423 struct in6_ifaddr *in6_ifawithscope(struct ifnet *, struct in6_addr *, u_int); 424 int in6_mask2len(struct in6_addr *, u_char *); 425 int in6_nam2sin6(const struct mbuf *, struct sockaddr_in6 **); 426 int in6_sa2sin6(struct sockaddr *, struct sockaddr_in6 **); 427 428 struct inpcb; 429 430 int in6_embedscope(struct in6_addr *, const struct sockaddr_in6 *, 431 struct inpcb *); 432 void in6_recoverscope(struct sockaddr_in6 *, const struct in6_addr *); 433 void in6_clearscope(struct in6_addr *); 434 435 /* 436 * Convert between address family specific and general structs. 437 * Inline functions check the source type and are stricter than 438 * casts or defines. 439 */ 440 441 static inline struct sockaddr_in6 * 442 satosin6(struct sockaddr *sa) 443 { 444 return ((struct sockaddr_in6 *)(sa)); 445 } 446 447 static inline struct sockaddr * 448 sin6tosa(struct sockaddr_in6 *sin6) 449 { 450 return ((struct sockaddr *)(sin6)); 451 } 452 453 static inline struct in6_ifaddr * 454 ifatoia6(struct ifaddr *ifa) 455 { 456 return ((struct in6_ifaddr *)(ifa)); 457 } 458 459 #endif /* _KERNEL */ 460 461 #if __BSD_VISIBLE 462 /* 463 * Definitions for inet6 sysctl operations. 464 * 465 * Third level is protocol number. 466 * Fourth level is desired variable within that protocol. 467 */ 468 #define IPV6PROTO_MAXID (IPPROTO_DIVERT + 1) /* don't list to IPV6PROTO_MAX */ 469 470 #define CTL_IPV6PROTO_NAMES { \ 471 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 472 { 0, 0 }, \ 473 { "tcp6", CTLTYPE_NODE }, \ 474 { 0, 0 }, \ 475 { 0, 0 }, \ 476 { 0, 0 }, \ 477 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 478 { 0, 0 }, \ 479 { 0, 0 }, \ 480 { "udp6", CTLTYPE_NODE }, \ 481 { 0, 0 }, \ 482 { 0, 0 }, \ 483 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 484 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 485 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 486 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 487 { 0, 0 }, \ 488 { "ip6", CTLTYPE_NODE }, \ 489 { 0, 0 }, \ 490 { 0, 0 }, \ 491 { 0, 0 }, \ 492 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 493 { 0, 0 }, \ 494 { "ipsec6", CTLTYPE_NODE }, \ 495 { 0, 0 }, \ 496 { 0, 0 }, \ 497 { 0, 0 }, \ 498 { 0, 0 }, \ 499 { 0, 0 }, \ 500 { 0, 0 }, \ 501 { "icmp6", CTLTYPE_NODE }, \ 502 { 0, 0 }, \ 503 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 504 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 505 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 506 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 507 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 508 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 509 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 510 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 511 { 0, 0 }, \ 512 { 0, 0 }, \ 513 { 0, 0 }, \ 514 { 0, 0 }, \ 515 { 0, 0 }, \ 516 { 0, 0 }, \ 517 { 0, 0 }, \ 518 { 0, 0 }, \ 519 { 0, 0 }, \ 520 { 0, 0 }, \ 521 /*110*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 522 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 523 /*120*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 524 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 525 /*130*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 526 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 527 /*140*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 528 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 529 /*150*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 530 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 531 /*160*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 532 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 533 /*170*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 534 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 535 /*180*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 536 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 537 /*190*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 538 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 539 /*200*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 540 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 541 /*210*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 542 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 543 /*220*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 544 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 545 /*230*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 546 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 547 /*240*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 548 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 549 /*250*/ { 0, 0 }, \ 550 { 0, 0 }, \ 551 { 0, 0 }, \ 552 { 0, 0 }, \ 553 { 0, 0 }, \ 554 { 0, 0 }, \ 555 { 0, 0 }, \ 556 { 0, 0 }, \ 557 { "divert", CTLTYPE_NODE }, \ 558 } 559 560 /* 561 * Names for IP sysctl objects 562 */ 563 #define IPV6CTL_FORWARDING 1 /* act as router */ 564 #define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/ 565 #define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */ 566 #define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */ 567 #define IPV6CTL_STATS 6 /* stats */ 568 #define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */ 569 #define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */ 570 #define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */ 571 #define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */ 572 #define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */ 573 #define IPV6CTL_ACCEPT_RTADV 12 574 #define IPV6CTL_LOG_INTERVAL 14 575 #define IPV6CTL_HDRNESTLIMIT 15 576 #define IPV6CTL_DAD_COUNT 16 577 #define IPV6CTL_AUTO_FLOWLABEL 17 578 #define IPV6CTL_DEFMCASTHLIM 18 579 #define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */ 580 /* 24 to 40: reserved */ 581 #define IPV6CTL_MAXFRAGS 41 /* max fragments */ 582 #define IPV6CTL_MFORWARDING 42 583 #define IPV6CTL_MULTIPATH 43 584 #define IPV6CTL_MCAST_PMTU 44 /* path MTU discovery for multicast */ 585 #define IPV6CTL_NEIGHBORGCTHRESH 45 586 #define IPV6CTL_MAXDYNROUTES 48 587 #define IPV6CTL_DAD_PENDING 49 588 #define IPV6CTL_MTUDISCTIMEOUT 50 589 #define IPV6CTL_IFQUEUE 51 590 #define IPV6CTL_MRTMIF 52 591 #define IPV6CTL_MRTMFC 53 592 #define IPV6CTL_SOIIKEY 54 593 #define IPV6CTL_MAXID 55 594 595 /* New entries should be added here from current IPV6CTL_MAXID value. */ 596 /* to define items, should talk with KAME guys first, for *BSD compatibility */ 597 598 #define IPV6CTL_NAMES { \ 599 { 0, 0 }, \ 600 { "forwarding", CTLTYPE_INT }, \ 601 { "redirect", CTLTYPE_INT }, \ 602 { "hlim", CTLTYPE_INT }, \ 603 { 0, 0 }, \ 604 { "forwsrcrt", CTLTYPE_INT }, \ 605 { 0, 0 }, \ 606 { 0, 0 }, \ 607 { "mrtproto", CTLTYPE_INT }, \ 608 { "maxfragpackets", CTLTYPE_INT }, \ 609 { "sourcecheck", CTLTYPE_INT }, \ 610 { "sourcecheck_logint", CTLTYPE_INT }, \ 611 { 0, 0 }, \ 612 { 0, 0 }, \ 613 { "log_interval", CTLTYPE_INT }, \ 614 { "hdrnestlimit", CTLTYPE_INT }, \ 615 { "dad_count", CTLTYPE_INT }, \ 616 { "auto_flowlabel", CTLTYPE_INT }, \ 617 { "defmcasthlim", CTLTYPE_INT }, \ 618 { 0, 0 }, \ 619 { 0, 0 }, \ 620 { "use_deprecated", CTLTYPE_INT }, \ 621 { 0, 0 }, \ 622 { 0, 0 }, \ 623 { 0, 0 }, \ 624 { 0, 0 }, \ 625 { 0, 0 }, \ 626 { 0, 0 }, \ 627 { 0, 0 }, \ 628 { 0, 0 }, \ 629 { 0, 0 }, \ 630 { 0, 0 }, \ 631 { 0, 0 }, \ 632 { 0, 0 }, \ 633 { 0, 0 }, \ 634 { 0, 0 }, \ 635 { 0, 0 }, \ 636 { 0, 0 }, \ 637 { 0, 0 }, \ 638 { 0, 0 }, \ 639 { 0, 0 }, \ 640 { "maxfrags", CTLTYPE_INT }, \ 641 { "mforwarding", CTLTYPE_INT }, \ 642 { "multipath", CTLTYPE_INT }, \ 643 { "multicast_mtudisc", CTLTYPE_INT }, \ 644 { "neighborgcthresh", CTLTYPE_INT }, \ 645 { 0, 0 }, \ 646 { 0, 0 }, \ 647 { "maxdynroutes", CTLTYPE_INT }, \ 648 { "dad_pending", CTLTYPE_INT }, \ 649 { "mtudisctimeout", CTLTYPE_INT }, \ 650 { "ifq", CTLTYPE_NODE }, \ 651 { "mrtmif", CTLTYPE_STRUCT }, \ 652 { "mrtmfc", CTLTYPE_STRUCT }, \ 653 { "soiikey", CTLTYPE_STRING }, /* binary string */ \ 654 } 655 656 #define IPV6CTL_VARS { \ 657 NULL, \ 658 &ip6_forwarding, \ 659 &ip6_sendredirects, \ 660 &ip6_defhlim, \ 661 NULL, \ 662 NULL, \ 663 NULL, \ 664 NULL, \ 665 NULL, \ 666 &ip6_maxfragpackets, \ 667 NULL, \ 668 NULL, \ 669 NULL, \ 670 NULL, \ 671 &ip6_log_interval, \ 672 &ip6_hdrnestlimit, \ 673 &ip6_dad_count, \ 674 &ip6_auto_flowlabel, \ 675 &ip6_defmcasthlim, \ 676 NULL, \ 677 NULL, \ 678 &ip6_use_deprecated, \ 679 NULL, \ 680 NULL, \ 681 NULL, \ 682 NULL, \ 683 NULL, \ 684 NULL, \ 685 NULL, \ 686 NULL, \ 687 NULL, \ 688 NULL, \ 689 NULL, \ 690 NULL, \ 691 NULL, \ 692 NULL, \ 693 NULL, \ 694 NULL, \ 695 NULL, \ 696 NULL, \ 697 NULL, \ 698 &ip6_maxfrags, \ 699 &ip6_mforwarding, \ 700 &ip6_multipath, \ 701 &ip6_mcast_pmtu, \ 702 &ip6_neighborgcthresh, \ 703 NULL, \ 704 NULL, \ 705 &ip6_maxdynroutes, \ 706 NULL, \ 707 NULL, \ 708 NULL, \ 709 NULL, \ 710 NULL, \ 711 } 712 713 __BEGIN_DECLS 714 struct cmsghdr; 715 716 extern int inet6_opt_init(void *, socklen_t); 717 extern int inet6_opt_append(void *, socklen_t, int, u_int8_t, 718 socklen_t, u_int8_t, void **); 719 extern int inet6_opt_finish(void *, socklen_t, int); 720 extern int inet6_opt_set_val(void *, int, void *, socklen_t); 721 722 extern int inet6_opt_next(void *, socklen_t, int, u_int8_t *, 723 socklen_t *, void **); 724 extern int inet6_opt_find(void *, socklen_t, int, u_int8_t, 725 socklen_t *, void **); 726 extern int inet6_opt_get_val(void *, int, void *, socklen_t); 727 728 extern socklen_t inet6_rth_space(int, int); 729 extern void *inet6_rth_init(void *, socklen_t, int, int); 730 extern int inet6_rth_add(void *, const struct in6_addr *); 731 extern int inet6_rth_reverse(const void *, void *); 732 extern int inet6_rth_segments(const void *); 733 extern struct in6_addr *inet6_rth_getaddr(const void *, int); 734 __END_DECLS 735 #endif /* __BSD_VISIBLE */ 736 737 #endif /* !_NETINET6_IN6_H_ */ 738