1.\" $KAME: inet6.4,v 1.21 2001/04/05 01:00:18 itojun Exp $ 2.\" 3.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the project nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.Dd January 31, 2026 31.Dt INET6 4 32.Os 33.Sh NAME 34.Nm inet6 35.Nd Internet protocol version 6 family 36.Sh SYNOPSIS 37.In sys/types.h 38.In netinet/in.h 39.Sh DESCRIPTION 40The 41.Nm 42family is an updated version of 43.Xr inet 4 44family. 45While 46.Xr inet 4 47implements Internet Protocol version 4, 48.Nm 49implements Internet Protocol version 6. 50.Pp 51.Nm 52is a collection of protocols layered atop the 53.Em Internet Protocol version 6 54.Pq Tn IPv6 55transport layer, and utilizing the IPv6 address format. 56The 57.Nm 58family provides protocol support for the 59.Dv SOCK_STREAM , SOCK_DGRAM , 60and 61.Dv SOCK_RAW 62socket types; the 63.Dv SOCK_RAW 64interface provides access to the 65.Tn IPv6 66protocol. 67.Sh ADDRESSING 68IPv6 addresses are 16 byte quantities, stored in network standard byteorder. 69The include file 70.In netinet/in.h 71defines this address 72as a discriminated union. 73.Pp 74Sockets bound to the 75.Nm 76family utilize the following addressing structure: 77.Bd -literal -offset indent 78struct sockaddr_in6 { 79 uint8_t sin6_len; 80 sa_family_t sin6_family; 81 in_port_t sin6_port; 82 uint32_t sin6_flowinfo; 83 struct in6_addr sin6_addr; 84 uint32_t sin6_scope_id; 85}; 86.Ed 87.Pp 88Sockets may be created with the local address 89.Dq Dv :: 90(which is equal to IPv6 address 91.Dv 0:0:0:0:0:0:0:0 ) 92to effect 93.Dq wildcard 94matching on incoming messages. 95.Pp 96The IPv6 specification defines scoped addresses, 97like link-local or site-local addresses. 98A scoped address is ambiguous to the kernel, 99if it is specified without a scope identifier. 100To manipulate scoped addresses properly from the userland, 101programs must use the advanced API defined in RFC2292. 102A compact description of the advanced API is available in 103.Xr ip6 4 . 104If a scoped address is specified without an explicit scope, 105the kernel may raise an error. 106Note that scoped addresses are not for daily use at this moment, 107both from a specification and an implementation point of view. 108.Pp 109The KAME implementation supports an extended numeric IPv6 address notation 110for link-local addresses, 111like 112.Dq Li fe80::1%de0 113to specify 114.Do 115.Li fe80::1 116on 117.Li de0 118interface 119.Dc . 120This notation is supported by 121.Xr getaddrinfo 3 122and 123.Xr getnameinfo 3 . 124Some of normal userland programs, such as 125.Xr telnet 1 126or 127.Xr ftp 1 , 128are able to use this notation. 129With special programs 130like 131.Xr ping 8 , 132you can specify the outgoing interface by an extra command line option 133to disambiguate scoped addresses. 134.Pp 135Scoped addresses are handled specially in the kernel. 136In kernel structures like routing tables or interface structures, 137a scoped address will have its interface index embedded into the address. 138Therefore, 139the address in some kernel structures is not the same as that on the wire. 140The embedded index will become visible through a 141.Dv PF_ROUTE 142socket, kernel memory accesses via 143.Xr kvm 3 144and on some other occasions. 145HOWEVER, users should never use the embedded form. 146For details please consult 147.Pa IMPLEMENTATION 148supplied with KAME kit. 149.Sh PROTOCOLS 150The 151.Nm 152family is comprised of the 153.Tn IPv6 154network protocol, Internet Control 155Message Protocol version 6 156.Pq Tn ICMPv6 , 157Transmission Control Protocol 158.Pq Tn TCP , 159and User Datagram Protocol 160.Pq Tn UDP . 161.Tn TCP 162is used to support the 163.Dv SOCK_STREAM 164abstraction while 165.Tn UDP 166is used to support the 167.Dv SOCK_DGRAM 168abstraction. 169Note that 170.Tn TCP 171and 172.Tn UDP 173are common to 174.Xr inet 4 175and 176.Nm . 177A raw interface to 178.Tn IPv6 179is available 180by creating an Internet socket of type 181.Dv SOCK_RAW . 182The 183.Tn ICMPv6 184message protocol is accessible from a raw socket. 185.Ss MIB Variables 186A number of variables are implemented in the 187.Va net.inet6 188branch of the 189.Xr sysctl 3 190MIB. 191In addition to the variables supported by the transport protocols 192(for which the respective manual pages may be consulted), 193the following general variables are defined: 194.Bl -tag -width IPV6CTL_MAXFRAGPACKETS 195.It Dv IPV6CTL_FORWARDING 196.Pq ip6.forwarding 197Boolean: enable/disable forwarding of 198.Tn IPv6 199packets. 200Also, identify if the node is acting as a router. 201Defaults to off. 202.It Dv IPV6CTL_SENDREDIRECTS 203.Pq ip6.redirect 204Boolean: enable/disable sending of 205.Tn ICMPv6 206redirects in response to unforwardable 207.Tn IPv6 208packets. 209This option is ignored unless the node is routing 210.Tn IPv6 211packets, 212and should normally be enabled on all systems. 213Defaults to on. 214.It Dv IPV6CTL_DEFHLIM 215.Pq ip6.hlim 216Integer: default hop limit value to use for outgoing 217.Tn IPv6 218packets. 219This value applies to all the transport protocols on top of 220.Tn IPv6 . 221There are APIs to override the value. 222.It Dv IPV6CTL_MAXFRAGS 223.Pq ip6.maxfrags 224Integer: maximum number of fragments the host will accept and simultaneously 225hold across all reassembly queues in all VNETs. 226If set to 0, fragment reassembly is disabled. 227If set to -1, this limit is not applied. 228This limit is recalculated when the number of mbuf clusters is changed. 229This is a global limit. 230.It Dv IPV6CTL_MAXFRAGPACKETS 231.Pq ip6.maxfragpackets 232Integer: maximum number of fragmented packets the node will accept and 233simultaneously hold in the reassembly queue for a particular VNET. 2340 means that the node will not accept any fragmented packets for that VNET. 235-1 means that the node will not apply this limit for that VNET. 236This limit is recalculated when the number of mbuf clusters is changed. 237This is a per-VNET limit. 238.It Dv IPV6CTL_MAXFRAGBUCKETSIZE 239.Pq ip6.maxfragbucketsize 240Integer: maximum number of reassembly queues per bucket. 241Fragmented packets are hashed to buckets. 242Each bucket has a list of reassembly queues. 243The system must compare the incoming packets to the existing reassembly queues 244in the bucket to find a matching reassembly queue. 245To preserve system resources, the system limits the number of reassembly 246queues allowed in each bucket. 247This limit is recalculated when the number of mbuf clusters is changed or 248when the value of 249.Va ip6.maxfragpackets 250changes. 251This is a per-VNET limit. 252.It Dv IPV6CTL_MAXFRAGSPERPACKET 253.Pq ip6.maxfragsperpacket 254Integer: maximum number of fragments the host will accept and hold in the 255ressembly queue for a packet. 256This is a per-VNET limit. 257.It Dv IPV6CTL_ACCEPT_RTADV 258.Pq ip6.accept_rtadv 259Boolean: the default value of a per-interface flag to 260enable/disable receiving of 261.Tn ICMPv6 262router advertisement packets, 263and autoconfiguration of address prefixes and default routers. 264The node must be a host 265(not a router) 266for the option to be meaningful. 267Defaults to off. 268.It Dv IPV6CTL_AUTO_LINKLOCAL 269.Pq ip6.auto_linklocal 270Boolean: the default value of a per-interface flag to 271enable/disable performing automatic link-local address configuration. 272Defaults to on. 273.It Dv IPV6CTL_LOG_INTERVAL 274.Pq ip6.log_interval 275Integer: default interval between 276.Tn IPv6 277packet forwarding engine log output 278(in seconds). 279.It Dv IPV6CTL_HDRNESTLIMIT 280.Pq ip6.hdrnestlimit 281Integer: default number of the maximum 282.Tn IPv6 283extension headers 284permitted on incoming 285.Tn IPv6 286packets. 287If set to 0, the node will accept as many extension headers as possible. 288.It Dv IPV6CTL_DAD_COUNT 289.Pq ip6.dad_count 290Integer: default number of 291.Tn IPv6 292DAD 293.Pq duplicated address detection 294probe packets. 295The packets will be generated when 296.Tn IPv6 297interface addresses are configured. 298.It Dv IPV6CTL_GRAND_COUNT 299.Pq ip6.grand_count 300Integer: default number of 301.Tn IPv6 302GRAND 303.Pq gratuitous neighbor discovery 304unsolicited NA packets. 305The packets will be generated when 306.Tn IPv6 307interface addresses are configured or when there are changes to 308link-layer interface addresses. 309.It Dv IPV6CTL_AUTO_FLOWLABEL 310.Pq ip6.auto_flowlabel 311Boolean: enable/disable automatic filling of 312.Tn IPv6 313flowlabel field, for outstanding connected transport protocol packets. 314The field might be used by intermediate routers to identify packet flows. 315Defaults to on. 316.It Dv IPV6CTL_DEFMCASTHLIM 317.Pq ip6.defmcasthlim 318Integer: default hop limit value for an 319.Tn IPv6 320multicast packet sourced by the node. 321This value applies to all the transport protocols on top of 322.Tn IPv6 . 323There are APIs to override the value as documented in 324.Xr ip6 4 . 325.It Dv IPV6CTL_GIF_HLIM 326.Pq ip6.gifhlim 327Integer: default maximum hop limit value for an 328.Tn IPv6 329packet generated by 330.Xr gif 4 331tunnel interface. 332.It Dv IPV6CTL_KAME_VERSION 333.Pq ip6.kame_version 334String: identifies the version of KAME 335.Tn IPv6 336stack implemented in the kernel. 337.It Dv IPV6CTL_USE_DEPRECATED 338.Pq ip6.use_deprecated 339Boolean: enable/disable use of deprecated address, 340specified in RFC2462 5.5.4. 341Defaults to on. 342.It Dv IPV6CTL_RR_PRUNE 343.Pq ip6.rr_prune 344Integer: default interval between 345.Tn IPv6 346router renumbering prefix babysitting, in seconds. 347.It Dv IPV6CTL_V6ONLY 348.Pq ip6.v6only 349Boolean: enable/disable the prohibited use of 350.Tn IPv4 351mapped address on 352.Dv AF_INET6 353sockets. 354Defaults to on. 355.It Va ip6.log_cannot_forward 356Boolean: log packets that can't be forwarded because of unspecified source 357address or destination address beyond the scope of the source address as 358described in RFC4443. 359Enabled by default. 360.It Va ip6.source_address_validation 361Boolean: perform source address validation for packets destined for the local 362host. 363Consider this as following Section 3.2 of RFC3704/BCP84, where we treat local 364host as our own infrastructure. 365This has no effect on packets to be forwarded, so don't consider it as 366anti-spoof feature for a router. 367Enabled by default. 368.El 369.Ss Interaction between IPv4/v6 sockets 370By default, 371.Fx 372does not route IPv4 traffic to 373.Dv AF_INET6 374sockets. 375The default behavior intentionally violates RFC2553 for security reasons. 376Listen to two sockets if you want to accept both IPv4 and IPv6 traffic. 377IPv4 traffic may be routed with certain 378per-socket/per-node configuration, however, it is not recommended to do so. 379Consult 380.Xr ip6 4 381for details. 382.Pp 383The behavior of 384.Dv AF_INET6 385TCP/UDP socket is documented in RFC2553. 386Basically, it says this: 387.Bl -bullet -compact 388.It 389A specific bind on an 390.Dv AF_INET6 391socket 392.Xr ( bind 2 393with an address specified) 394should accept IPv6 traffic to that address only. 395.It 396If you perform a wildcard bind 397on an 398.Dv AF_INET6 399socket 400.Xr ( bind 2 401to IPv6 address 402.Li :: ) , 403and there is no wildcard bind 404.Dv AF_INET 405socket on that TCP/UDP port, IPv6 traffic as well as IPv4 traffic 406should be routed to that 407.Dv AF_INET6 408socket. 409IPv4 traffic should be seen as if it came from an IPv6 address like 410.Li ::ffff:10.1.1.1 . 411This is called an IPv4 mapped address. 412.It 413If there are both a wildcard bind 414.Dv AF_INET 415socket and a wildcard bind 416.Dv AF_INET6 417socket on one TCP/UDP port, they should behave separately. 418IPv4 traffic should be routed to the 419.Dv AF_INET 420socket and IPv6 should be routed to the 421.Dv AF_INET6 422socket. 423.El 424.Pp 425However, RFC2553 does not define the ordering constraint between calls to 426.Xr bind 2 , 427nor how IPv4 TCP/UDP port numbers and IPv6 TCP/UDP port numbers 428relate to each other 429(should they be integrated or separated). 430Implemented behavior is very different from kernel to kernel. 431Therefore, it is unwise to rely too much upon the behavior of 432.Dv AF_INET6 433wildcard bind sockets. 434It is recommended to listen to two sockets, one for 435.Dv AF_INET 436and another for 437.Dv AF_INET6 , 438when you would like to accept both IPv4 and IPv6 traffic. 439.Pp 440It should also be noted that 441malicious parties can take advantage of the complexity presented above, 442and are able to bypass access control, 443if the target node routes IPv4 traffic to 444.Dv AF_INET6 445socket. 446Users are advised to take care handling connections 447from IPv4 mapped address to 448.Dv AF_INET6 449sockets. 450.Sh SEE ALSO 451.Xr ioctl 2 , 452.Xr socket 2 , 453.Xr sysctl 3 , 454.Xr icmp6 4 , 455.Xr intro 4 , 456.Xr ip6 4 , 457.Xr tcp 4 , 458.Xr udp 4 459.Rs 460.%A A. Conta 461.%A S. Deering 462.%A M. Gupta 463.%T "Internet Control Message Protocol (ICMPv6) for the Internet" \ 464 "Protocol Version 6 (IPv6) Specification" 465.%R RFC 4443 466.%D March 2006 467.Re 468.Sh STANDARDS 469.Rs 470.%A Tatsuya Jinmei 471.%A Atsushi Onoe 472.%T "An Extension of Format for IPv6 Scoped Addresses" 473.%R internet draft 474.%D June 2000 475.%N draft-ietf-ipngwg-scopedaddr-format-02.txt 476.%O work in progress material 477.Re 478.Sh HISTORY 479The 480.Nm 481protocol interfaces are defined in RFC2553 and RFC2292. 482The implementation described herein appeared in the WIDE/KAME project. 483.Sh BUGS 484The IPv6 support is subject to change as the Internet protocols develop. 485Users should not depend on details of the current implementation, 486but rather the services exported. 487.Pp 488Users are suggested to implement 489.Dq version independent 490code as much as possible, as you will need to support both 491.Xr inet 4 492and 493.Nm . 494