1/* $NetBSD: in6.h,v 1.101 2021/07/31 10:12:04 andvar 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 _NETINET6_IN6_H_ 65#define _NETINET6_IN6_H_ 66 67#include <sys/featuretest.h> 68 69#ifndef __KAME_NETINET_IN_H_INCLUDED_ 70#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553" 71#endif 72 73#include <sys/socket.h> 74#include <sys/endian.h> /* ntohl */ 75 76/* 77 * Identification of the network protocol stack 78 * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE 79 * has the table of implementation/integration differences. 80 */ 81#define __KAME__ 82#define __KAME_VERSION "NetBSD-current" 83 84/* 85 * Local port number conventions: 86 * 87 * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root), 88 * unless a kernel is compiled with IPNOPRIVPORTS defined. 89 * 90 * When a user does a bind(2) or connect(2) with a port number of zero, 91 * a non-conflicting local port address is chosen. 92 * 93 * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although 94 * that is settable by sysctl(3); net.inet.ip.anonportmin and 95 * net.inet.ip.anonportmax respectively. 96 * 97 * A user may set the IPPROTO_IP option IP_PORTRANGE to change this 98 * default assignment range. 99 * 100 * The value IP_PORTRANGE_DEFAULT causes the default behavior. 101 * 102 * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT, 103 * and exists only for FreeBSD compatibility purposes. 104 * 105 * The value IP_PORTRANGE_LOW changes the range to the "low" are 106 * that is (by convention) restricted to privileged processes. 107 * This convention is based on "vouchsafe" principles only. 108 * It is only secure if you trust the remote host to restrict these ports. 109 * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX. 110 */ 111 112#if defined(_NETBSD_SOURCE) 113#define IPV6PORT_RESERVED 1024 114#define IPV6PORT_ANONMIN 49152 115#define IPV6PORT_ANONMAX 65535 116#define IPV6PORT_RESERVEDMIN 600 117#define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1) 118#endif 119 120/* 121 * IPv6 address 122 */ 123struct in6_addr { 124 union { 125 __uint8_t __u6_addr8[16]; 126 __uint16_t __u6_addr16[8]; 127 uint32_t __u6_addr32[4]; 128 } __u6_addr; /* 128-bit IP6 address */ 129}; 130 131#define s6_addr __u6_addr.__u6_addr8 132#ifdef _KERNEL /* XXX nonstandard */ 133#define s6_addr8 __u6_addr.__u6_addr8 134#define s6_addr16 __u6_addr.__u6_addr16 135#define s6_addr32 __u6_addr.__u6_addr32 136#endif 137 138#define INET6_ADDRSTRLEN 46 139 140/* 141 * Socket address for IPv6 142 */ 143#if defined(_NETBSD_SOURCE) 144#define SIN6_LEN 145#endif 146struct sockaddr_in6 { 147 uint8_t sin6_len; /* length of this struct(socklen_t)*/ 148 sa_family_t sin6_family; /* AF_INET6 (sa_family_t) */ 149 in_port_t sin6_port; /* Transport layer port */ 150 uint32_t sin6_flowinfo; /* IP6 flow information */ 151 struct in6_addr sin6_addr; /* IP6 address */ 152 uint32_t sin6_scope_id; /* scope zone index */ 153}; 154 155/* 156 * Local definition for masks 157 */ 158#ifdef _KERNEL /* XXX nonstandard */ 159#define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}} 160#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \ 161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 162#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 163 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 164#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 165 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}} 166#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ 167 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}} 168#endif 169 170#ifdef _KERNEL 171extern const struct sockaddr_in6 sa6_any; 172 173extern const struct in6_addr in6mask0; 174extern const struct in6_addr in6mask32; 175extern const struct in6_addr in6mask64; 176extern const struct in6_addr in6mask96; 177extern const struct in6_addr in6mask128; 178#endif /* _KERNEL */ 179 180/* 181 * Macros started with IPV6_ADDR is KAME local 182 */ 183#ifdef _KERNEL /* XXX nonstandard */ 184#if BYTE_ORDER == BIG_ENDIAN 185#define IPV6_ADDR_INT32_ONE 1 186#define IPV6_ADDR_INT32_TWO 2 187#define IPV6_ADDR_INT32_MNL 0xff010000 188#define IPV6_ADDR_INT32_MLL 0xff020000 189#define IPV6_ADDR_INT32_SMP 0x0000ffff 190#define IPV6_ADDR_INT16_ULL 0xfe80 191#define IPV6_ADDR_INT16_USL 0xfec0 192#define IPV6_ADDR_INT16_MLL 0xff02 193#elif BYTE_ORDER == LITTLE_ENDIAN 194#define IPV6_ADDR_INT32_ONE 0x01000000 195#define IPV6_ADDR_INT32_TWO 0x02000000 196#define IPV6_ADDR_INT32_MNL 0x000001ff 197#define IPV6_ADDR_INT32_MLL 0x000002ff 198#define IPV6_ADDR_INT32_SMP 0xffff0000 199#define IPV6_ADDR_INT16_ULL 0x80fe 200#define IPV6_ADDR_INT16_USL 0xc0fe 201#define IPV6_ADDR_INT16_MLL 0x02ff 202#endif 203#endif 204 205/* 206 * Definition of some useful macros to handle IP6 addresses 207 */ 208#define IN6ADDR_ANY_INIT \ 209 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 211#define IN6ADDR_LOOPBACK_INIT \ 212 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 214#define IN6ADDR_NODELOCAL_ALLNODES_INIT \ 215 {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 217#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \ 218 {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 220#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \ 221 {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}} 223 224extern const struct in6_addr in6addr_any; 225extern const struct in6_addr in6addr_loopback; 226extern const struct in6_addr in6addr_nodelocal_allnodes; 227extern const struct in6_addr in6addr_linklocal_allnodes; 228extern const struct in6_addr in6addr_linklocal_allrouters; 229 230#define IN6_ARE_ADDR_EQUAL(a, b) \ 231 (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 232 233/* 234 * Unspecified 235 */ 236#define IN6_IS_ADDR_UNSPECIFIED(a) \ 237 ((a)->__u6_addr.__u6_addr32[0] == 0 && \ 238 (a)->__u6_addr.__u6_addr32[1] == 0 && \ 239 (a)->__u6_addr.__u6_addr32[2] == 0 && \ 240 (a)->__u6_addr.__u6_addr32[3] == 0) 241 242/* 243 * Loopback 244 */ 245#define IN6_IS_ADDR_LOOPBACK(a) \ 246 ((a)->__u6_addr.__u6_addr32[0] == 0 && \ 247 (a)->__u6_addr.__u6_addr32[1] == 0 && \ 248 (a)->__u6_addr.__u6_addr32[2] == 0 && \ 249 (a)->__u6_addr.__u6_addr32[3] == ntohl(1)) 250 251/* 252 * IPv4 compatible 253 */ 254#define IN6_IS_ADDR_V4COMPAT(a) \ 255 ((a)->__u6_addr.__u6_addr32[0] == 0 && \ 256 (a)->__u6_addr.__u6_addr32[1] == 0 && \ 257 (a)->__u6_addr.__u6_addr32[2] == 0 && \ 258 (a)->__u6_addr.__u6_addr32[3] != 0 && \ 259 (a)->__u6_addr.__u6_addr32[3] != ntohl(1)) 260 261/* 262 * Mapped 263 */ 264#define IN6_IS_ADDR_V4MAPPED(a) \ 265 ((a)->__u6_addr.__u6_addr32[0] == 0 && \ 266 (a)->__u6_addr.__u6_addr32[1] == 0 && \ 267 (a)->__u6_addr.__u6_addr32[2] == ntohl(0x0000ffff)) 268 269/* 270 * KAME Scope Values 271 */ 272 273#ifdef _KERNEL /* XXX nonstandard */ 274#define IPV6_ADDR_SCOPE_NODELOCAL 0x01 275#define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 276#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02 277#define IPV6_ADDR_SCOPE_SITELOCAL 0x05 278#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 279#define IPV6_ADDR_SCOPE_GLOBAL 0x0e 280#else 281#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01 282#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02 283#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 284#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ 285#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e 286#endif 287 288/* 289 * Unicast Scope 290 * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373). 291 */ 292#define IN6_IS_ADDR_LINKLOCAL(a) \ 293 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) 294#define IN6_IS_ADDR_SITELOCAL(a) \ 295 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) 296 297/* 298 * Multicast 299 */ 300#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) 301 302#ifdef _KERNEL /* XXX nonstandard */ 303#define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 304#else 305#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 306#endif 307 308/* 309 * Multicast Scope 310 */ 311#ifdef _KERNEL /* refers nonstandard items */ 312#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 313 (IN6_IS_ADDR_MULTICAST(a) && \ 314 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL)) 315#define IN6_IS_ADDR_MC_INTFACELOCAL(a) \ 316 (IN6_IS_ADDR_MULTICAST(a) && \ 317 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL)) 318#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 319 (IN6_IS_ADDR_MULTICAST(a) && \ 320 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL)) 321#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 322 (IN6_IS_ADDR_MULTICAST(a) && \ 323 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL)) 324#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 325 (IN6_IS_ADDR_MULTICAST(a) && \ 326 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL)) 327#define IN6_IS_ADDR_MC_GLOBAL(a) \ 328 (IN6_IS_ADDR_MULTICAST(a) && \ 329 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL)) 330#else 331#define IN6_IS_ADDR_MC_NODELOCAL(a) \ 332 (IN6_IS_ADDR_MULTICAST(a) && \ 333 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL)) 334#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ 335 (IN6_IS_ADDR_MULTICAST(a) && \ 336 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL)) 337#define IN6_IS_ADDR_MC_SITELOCAL(a) \ 338 (IN6_IS_ADDR_MULTICAST(a) && \ 339 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) 340#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 341 (IN6_IS_ADDR_MULTICAST(a) && \ 342 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) 343#define IN6_IS_ADDR_MC_GLOBAL(a) \ 344 (IN6_IS_ADDR_MULTICAST(a) && \ 345 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL)) 346#endif 347 348#ifdef _KERNEL /* nonstandard */ 349/* 350 * KAME Scope 351 */ 352#define IN6_IS_SCOPE_LINKLOCAL(a) \ 353 ((IN6_IS_ADDR_LINKLOCAL(a)) || \ 354 (IN6_IS_ADDR_MC_LINKLOCAL(a))) 355 356#define IN6_IS_SCOPE_EMBEDDABLE(__a) \ 357 (IN6_IS_SCOPE_LINKLOCAL(__a) || IN6_IS_ADDR_MC_INTFACELOCAL(__a)) 358 359#define IFA6_IS_DEPRECATED(a) \ 360 ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \ 361 (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \ 362 (a)->ia6_lifetime.ia6t_pltime) 363#define IFA6_IS_INVALID(a) \ 364 ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \ 365 (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \ 366 (a)->ia6_lifetime.ia6t_vltime) 367#endif 368 369/* 370 * Options for use with [gs]etsockopt at the IPV6 level. 371 * First word of comment is data type; bool is stored in int. 372 */ 373/* no hdrincl */ 374#if 0 375/* These are deprecated non-standard options which are no longer supported. */ 376#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */ 377#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */ 378#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */ 379#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */ 380#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */ 381#endif 382#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */ 383#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ 384#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */ 385#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */ 386#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */ 387/* The join and leave membership option numbers need to match with the v4 ones */ 388#define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */ 389#define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */ 390#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */ 391#if defined(_NETBSD_SOURCE) 392#define IPV6_PORTALGO 17 /* int; port selection algo (rfc6056) */ 393#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */ 394#endif 395/* RFC2292 options */ 396#ifdef _KERNEL 397#define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */ 398#define IPV6_2292HOPLIMIT 20 /* bool; hop limit */ 399#define IPV6_2292NEXTHOP 21 /* bool; next hop addr */ 400#define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */ 401#define IPV6_2292DSTOPTS 23 /* bool; destination option */ 402#define IPV6_2292RTHDR 24 /* bool; routing header */ 403#define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */ 404#endif 405#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */ 406#define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */ 407 408#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */ 409#define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */ 410 411/* new socket options introduced in RFC3542 */ 412#define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */ 413 414#define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */ 415#define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */ 416#define IPV6_RECVRTHDR 38 /* bool; recv routing header */ 417#define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */ 418#define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */ 419#ifdef _KERNEL 420#define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */ 421#endif 422#define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */ 423#define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */ 424#define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt), 425 4 bytes int; MTU notification (cmsg) */ 426 427/* more new socket options introduced in RFC3542 */ 428#define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */ 429#define IPV6_HOPLIMIT 47 /* int; send hop limit */ 430#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */ 431#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */ 432#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option before rthdr */ 433#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */ 434 435#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */ 436#ifdef _KERNEL 437#define IPV6_OTCLASS 58 /* u_int8_t; send traffic class value */ 438#endif 439 440#define IPV6_TCLASS 61 /* int; send traffic class value */ 441#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */ 442#define IPV6_PREFER_TEMPADDR 63 /* int; prefer temporary address as 443 * the source address */ 444#define IPV6_BINDANY 64 /* bool: allow bind to any address */ 445/* to define items, should talk with KAME guys first, for *BSD compatibility */ 446 447#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */ 448#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */ 449#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ 450 451/* 452 * Defaults and limits for options 453 */ 454#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ 455#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 456 457/* 458 * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. 459 */ 460struct ipv6_mreq { 461 struct in6_addr ipv6mr_multiaddr; 462 unsigned int ipv6mr_interface; 463}; 464 465/* 466 * IPV6_PKTINFO: Packet information(RFC2292 sec 5) 467 */ 468struct in6_pktinfo { 469 struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 470 unsigned int ipi6_ifindex; /* send/recv interface index */ 471}; 472 473/* 474 * Control structure for IPV6_RECVPATHMTU socket option. 475 */ 476struct ip6_mtuinfo { 477 struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */ 478 uint32_t ip6m_mtu; 479}; 480 481/* 482 * Argument for IPV6_PORTRANGE: 483 * - which range to search when port is unspecified at bind() or connect() 484 */ 485#define IPV6_PORTRANGE_DEFAULT 0 /* default range */ 486#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 487#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 488 489#if defined(_NETBSD_SOURCE) 490/* 491 * Definitions for inet6 sysctl operations. 492 * 493 * Third level is protocol number. 494 * Fourth level is desired variable within that protocol. 495 */ 496/* 497 * Names for IP sysctl objects 498 */ 499#define IPV6CTL_FORWARDING 1 /* act as router */ 500#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/ 501#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */ 502/* IPV6CTL_DEFMTU=4, never implemented */ 503#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */ 504#define IPV6CTL_STATS 6 /* stats */ 505#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */ 506#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */ 507#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */ 508#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */ 509#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimum logging interval */ 510/* 12 was IPV6CTL_ACCEPT_RTADV */ 511#define IPV6CTL_KEEPFAITH 13 512#define IPV6CTL_LOG_INTERVAL 14 513#define IPV6CTL_HDRNESTLIMIT 15 514#define IPV6CTL_DAD_COUNT 16 515#define IPV6CTL_AUTO_FLOWLABEL 17 516#define IPV6CTL_DEFMCASTHLIM 18 517#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */ 518#define IPV6CTL_KAME_VERSION 20 519#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */ 520/* 22 was IPV6CTL_RR_PRUNE */ 521/* 23: reserved */ 522#define IPV6CTL_V6ONLY 24 523/* 25 to 27: reserved */ 524#define IPV6CTL_ANONPORTMIN 28 /* minimum ephemeral port */ 525#define IPV6CTL_ANONPORTMAX 29 /* maximum ephemeral port */ 526#define IPV6CTL_LOWPORTMIN 30 /* minimum reserved port */ 527#define IPV6CTL_LOWPORTMAX 31 /* maximum reserved port */ 528/* 32 to 34: reserved */ 529#define IPV6CTL_AUTO_LINKLOCAL 35 /* automatic link-local addr assign */ 530/* 36 to 37: reserved */ 531#define IPV6CTL_ADDRCTLPOLICY 38 /* get/set address selection policy */ 532#define IPV6CTL_USE_DEFAULTZONE 39 /* use default scope zone */ 533/* 40: reserved */ 534#define IPV6CTL_MAXFRAGS 41 /* max fragments */ 535#define IPV6CTL_IFQ 42 /* IPv6 packet input queue */ 536/* 43 was IPV6CTL_RTADV_MAXROUTES */ 537/* 44 was IPV6CTL_RTADV_NUMROUTES */ 538#define IPV6CTL_GIF_PMTU 45 /* gif(4) Path MTU setting */ 539#define IPV6CTL_IPSEC_HLIM 46 /* default HLIM for ipsecif encap packet */ 540#define IPV6CTL_IPSEC_PMTU 47 /* ipsecif(4) Path MTU setting */ 541#endif /* _NETBSD_SOURCE */ 542 543#ifdef _KERNEL 544struct cmsghdr; 545 546/* 547 * in6_cksum_phdr: 548 * 549 * Compute significant parts of the IPv6 checksum pseudo-header 550 * for use in a delayed TCP/UDP checksum calculation. 551 * 552 * Args: 553 * 554 * src Source IPv6 address 555 * dst Destination IPv6 address 556 * len htonl(proto-hdr-len) 557 * nxt htonl(next-proto-number) 558 * 559 * NOTE: We expect the src and dst addresses to be 16-bit 560 * aligned! 561 */ 562static __inline u_int16_t __unused 563in6_cksum_phdr(const struct in6_addr *src, const struct in6_addr *dst, 564 u_int32_t len, u_int32_t nxt) 565{ 566 u_int32_t sum = 0; 567 const u_int16_t *w; 568 569 /*LINTED*/ 570 w = (const u_int16_t *) src; 571 sum += w[0]; 572 if (!IN6_IS_SCOPE_LINKLOCAL(src)) 573 sum += w[1]; 574 sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5]; 575 sum += w[6]; sum += w[7]; 576 577 /*LINTED*/ 578 w = (const u_int16_t *) dst; 579 sum += w[0]; 580 if (!IN6_IS_SCOPE_LINKLOCAL(dst)) 581 sum += w[1]; 582 sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5]; 583 sum += w[6]; sum += w[7]; 584 585 sum += (u_int16_t)(len >> 16) + (u_int16_t)(len /*& 0xffff*/); 586 587 sum += (u_int16_t)(nxt >> 16) + (u_int16_t)(nxt /*& 0xffff*/); 588 589 sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/); 590 591 if (sum > 0xffff) 592 sum -= 0xffff; 593 594 return (sum); 595} 596 597struct mbuf; 598struct ifnet; 599int sockaddr_in6_cmp(const struct sockaddr *, const struct sockaddr *); 600struct sockaddr *sockaddr_in6_externalize(struct sockaddr *, socklen_t, 601 const struct sockaddr *); 602int in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t); 603int in6_localaddr(const struct in6_addr *); 604int in6_addrscope(const struct in6_addr *); 605struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *); 606extern void in6_if_link_up(struct ifnet *); 607extern void in6_if_link_down(struct ifnet *); 608extern void in6_if_link_state_change(struct ifnet *, int); 609extern void in6_if_up(struct ifnet *); 610extern void in6_if_down(struct ifnet *); 611extern void addrsel_policy_init(void); 612extern u_char ip6_protox[]; 613 614struct ip6_hdr; 615int in6_tunnel_validate(const struct ip6_hdr *, const struct in6_addr *, 616 const struct in6_addr *); 617 618#define satosin6(sa) ((struct sockaddr_in6 *)(sa)) 619#define satocsin6(sa) ((const struct sockaddr_in6 *)(sa)) 620#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) 621#define sin6tocsa(sin6) ((const struct sockaddr *)(sin6)) 622#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa)) 623 624static __inline void 625sockaddr_in6_init1(struct sockaddr_in6 *sin6, const struct in6_addr *addr, 626 in_port_t port, uint32_t flowinfo, uint32_t scope_id) 627{ 628 sin6->sin6_port = port; 629 sin6->sin6_flowinfo = flowinfo; 630 sin6->sin6_addr = *addr; 631 sin6->sin6_scope_id = scope_id; 632} 633 634static __inline void 635sockaddr_in6_init(struct sockaddr_in6 *sin6, const struct in6_addr *addr, 636 in_port_t port, uint32_t flowinfo, uint32_t scope_id) 637{ 638 sin6->sin6_family = AF_INET6; 639 sin6->sin6_len = sizeof(*sin6); 640 sockaddr_in6_init1(sin6, addr, port, flowinfo, scope_id); 641} 642 643static __inline struct sockaddr * 644sockaddr_in6_alloc(const struct in6_addr *addr, in_port_t port, 645 uint32_t flowinfo, uint32_t scope_id, int flags) 646{ 647 struct sockaddr *sa; 648 649 if ((sa = sockaddr_alloc(AF_INET6, sizeof(struct sockaddr_in6), 650 flags)) == NULL) 651 return NULL; 652 653 sockaddr_in6_init1(satosin6(sa), addr, port, flowinfo, scope_id); 654 655 return sa; 656} 657#endif /* _KERNEL */ 658 659#if defined(_NETBSD_SOURCE) 660 661#include <machine/ansi.h> 662 663#ifdef _BSD_SIZE_T_ 664typedef _BSD_SIZE_T_ size_t; 665#define _SIZE_T 666#undef _BSD_SIZE_T_ 667#endif 668 669#include <sys/cdefs.h> 670 671__BEGIN_DECLS 672struct cmsghdr; 673 674void in6_in_2_v4mapin6(const struct in_addr *, struct in6_addr *); 675void in6_sin6_2_sin(struct sockaddr_in *, struct sockaddr_in6 *); 676void in6_sin_2_v4mapsin6(const struct sockaddr_in *, struct sockaddr_in6 *); 677void in6_sin6_2_sin_in_sock(struct sockaddr *); 678void in6_sin_2_v4mapsin6_in_sock(struct sockaddr **); 679 680#define INET6_IS_ADDR_LINKLOCAL 1 681#define INET6_IS_ADDR_MC_LINKLOCAL 2 682#define INET6_IS_ADDR_SITELOCAL 4 683void inet6_getscopeid(struct sockaddr_in6 *, int); 684void inet6_putscopeid(struct sockaddr_in6 *, int); 685 686extern int inet6_option_space(int); 687extern int inet6_option_init(void *, struct cmsghdr **, int); 688extern int inet6_option_append(struct cmsghdr *, const uint8_t *, 689 int, int); 690extern uint8_t *inet6_option_alloc(struct cmsghdr *, int, int, int); 691extern int inet6_option_next(const struct cmsghdr *, uint8_t **); 692extern int inet6_option_find(const struct cmsghdr *, uint8_t **, int); 693 694extern size_t inet6_rthdr_space(int, int); 695extern struct cmsghdr *inet6_rthdr_init(void *, int); 696extern int inet6_rthdr_add(struct cmsghdr *, const struct in6_addr *, 697 unsigned int); 698extern int inet6_rthdr_lasthop(struct cmsghdr *, unsigned int); 699#if 0 /* not implemented yet */ 700extern int inet6_rthdr_reverse(const struct cmsghdr *, struct cmsghdr *); 701#endif 702extern int inet6_rthdr_segments(const struct cmsghdr *); 703extern struct in6_addr *inet6_rthdr_getaddr(struct cmsghdr *, int); 704extern int inet6_rthdr_getflags(const struct cmsghdr *, int); 705 706extern int inet6_opt_init(void *, socklen_t); 707extern int inet6_opt_append(void *, socklen_t, int, uint8_t, 708 socklen_t, uint8_t, void **); 709extern int inet6_opt_finish(void *, socklen_t, int); 710extern int inet6_opt_set_val(void *, int, void *, socklen_t); 711 712extern int inet6_opt_next(void *, socklen_t, int, uint8_t *, 713 socklen_t *, void **); 714extern int inet6_opt_find(void *, socklen_t, int, uint8_t, 715 socklen_t *, void **); 716extern int inet6_opt_get_val(void *, int, void *, socklen_t); 717extern socklen_t inet6_rth_space(int, int); 718extern void *inet6_rth_init(void *, socklen_t, int, int); 719extern int inet6_rth_add(void *, const struct in6_addr *); 720extern int inet6_rth_reverse(const void *, void *); 721extern int inet6_rth_segments(const void *); 722extern struct in6_addr *inet6_rth_getaddr(const void *, int); 723__END_DECLS 724#endif /* _NETBSD_SOURCE */ 725 726#if defined(_KERNEL) || defined(_TEST) 727int in6_print(char *, size_t, const struct in6_addr *); 728#define IN6_PRINT(b, a) (in6_print((b), sizeof(b), (a)), (b)) 729int sin6_print(char *, size_t, const void *); 730#endif 731 732#endif /* !_NETINET6_IN6_H_ */ 733