1.\" $OpenBSD: inet6.4,v 1.29 2009/12/13 15:48:21 sobrado Exp $ 2.\" $KAME: inet6.4,v 1.19 2000/11/24 10:13:18 itojun Exp $ 3.\" 4.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the project nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.Dd $Mdocdate: December 13 2009 $ 32.Dt INET6 4 33.Os 34.Sh NAME 35.Nm inet6 36.Nd Internet protocol version 6 family 37.Sh SYNOPSIS 38.Fd #include <sys/types.h> 39.Fd #include <netinet/in.h> 40.Sh DESCRIPTION 41The 42.Nm 43family is an updated version of the 44.Xr inet 4 45family. 46While 47.Xr inet 4 48implements Internet Protocol version 4, 49.Nm 50implements Internet Protocol version 6. 51.Pp 52.Nm 53is a collection of protocols layered atop the 54.Em Internet Protocol version 6 55.Pq Tn IPv6 56transport layer, and utilizing the IPv6 address format. 57The 58.Nm 59family provides protocol support for the 60.Dv SOCK_STREAM , 61.Dv SOCK_DGRAM , 62and 63.Dv SOCK_RAW 64socket types; the 65.Dv SOCK_RAW 66interface provides access to the 67.Tn IPv6 68protocol. 69.Sh ADDRESSING 70IPv6 addresses are 16 byte quantities, stored in network standard byteorder. 71The include file 72.Aq Pa netinet/in.h 73defines this address 74as a discriminated union. 75.Pp 76Sockets bound to the 77.Nm 78family utilize the following addressing structure: 79.Bd -literal -offset indent 80struct sockaddr_in6 { 81 u_int8_t sin6_len; 82 sa_family_t sin6_family; 83 in_port_t sin6_port; 84 u_int32_t sin6_flowinfo; 85 struct in6_addr sin6_addr; 86 u_int32_t sin6_scope_id; 87}; 88.Ed 89.Pp 90Sockets may be created with the local address 91.Dq Dv :: 92.Po 93which is equal to IPv6 address 94.Dv 0:0:0:0:0:0:0:0 95.Pc 96to effect 97.Dq wildcard 98matching on incoming messages. 99.Pp 100The IPv6 specification defines scoped address, 101like link-local or site-local address. 102A scoped address is ambiguous to the kernel, 103if it is specified without a scope identifier. 104To manipulate scoped addresses properly from userland, 105programs must use the advanced API defined in RFC 2292. 106A compact description of the advanced API is available in 107.Xr ip6 4 . 108If scoped addresses are specified without explicit scope, 109the kernel may raise an error. 110Note that scoped addresses are not for daily use at this moment, 111both from a specification and an implementation point of view. 112.Pp 113KAME implementation supports extended numeric IPv6 address notation 114for link-local addresses, 115like 116.Dq Li fe80::1%de0 117to specify 118.Do 119.Li fe80::1 120on 121.Li de0 122interface 123.Dc . 124The notation is supported by 125.Xr getaddrinfo 3 126and 127.Xr getnameinfo 3 . 128Some normal userland programs, such as 129.Xr telnet 1 130or 131.Xr ftp 1 , 132are able to use the notation. 133With special programs 134like 135.Xr ping6 8 , 136an outgoing interface can be specified with an extra command line option 137to disambiguate scoped addresses. 138.Pp 139Scoped addresses are handled specially in the kernel. 140In the kernel structures like routing tables or interface structure, 141scoped addresses will have their interface index embedded into the address. 142Therefore, 143the address on some of the kernel structure is not the same as that on the wire. 144The embedded index will become visible on 145.Dv PF_ROUTE 146socket, kernel memory accesses via 147.Xr kvm 3 148and some other occasions. 149HOWEVER, users should never use the embedded form. 150For details please consult 151.Pa http://www.kame.net/dev/cvsweb2.cgi/kame/IMPLEMENTATION . 152Note that the above URL describes the situation with the latest KAME tree, 153not the 154.Ox 155tree. 156.Sh PROTOCOLS 157The 158.Nm 159family is comprised of the 160.Tn IPv6 161network protocol, Internet Control 162Message Protocol version 6 163.Pq Tn ICMPv6 , 164Transmission Control Protocol 165.Pq Tn TCP , 166and User Datagram Protocol 167.Pq Tn UDP . 168.Tn TCP 169is used to support the 170.Dv SOCK_STREAM 171abstraction while 172.Tn UDP 173is used to support the 174.Dv SOCK_DGRAM 175abstraction. 176Note that 177.Tn TCP 178and 179.Tn UDP 180are common to 181.Xr inet 4 182and 183.Nm inet6 . 184A raw interface to 185.Tn IPv6 186is available 187by creating an Internet socket of type 188.Dv SOCK_RAW . 189The 190.Tn ICMPv6 191message protocol is accessible from a raw socket. 192.\" .Pp 193.\" The 128-bit IPv6 address contains both network and host parts. 194.\" However, direct examination of addresses is discouraged. 195.\" For those programs which absolutely need to break addresses 196.\" into their component parts, the following 197.\" .Xr ioctl 2 198.\" commands are provided for a datagram socket in the 199.\" .Nm 200.\" domain; they have the same form as the 201.\" .Dv SIOCIFADDR 202.\" command (see 203.\" .Xr intro 4 ) . 204.\" .Pp 205.\" .Bl -tag -width SIOCSIFNETMASK 206.\" .It Dv SIOCSIFNETMASK 207.\" Set interface network mask. 208.\" The network mask defines the network part of the address; 209.\" if it contains more of the address than the address type would indicate, 210.\" then subnets are in use. 211.\" .It Dv SIOCGIFNETMASK 212.\" Get interface network mask. 213.\" .El 214.Ss Interaction between IPv4/v6 sockets 215.Ox 216does not route IPv4 traffic to an 217.Dv AF_INET6 218socket, 219for security reasons. 220If both IPv4 and IPv6 traffic need to be accepted, listen on two sockets. 221.Pp 222The behavior of 223.Dv AF_INET6 224TCP/UDP socket is documented in RFC 2553. 225Basically, it says the following: 226.Pp 227.Bl -bullet -compact 228.It 229A specific bind to an 230.Dv AF_INET6 231socket 232.Po 233.Xr bind 2 234with address specified 235.Pc 236should accept IPv6 traffic to that address only. 237.It 238If a wildcard bind is performed on an 239.Dv AF_INET6 240socket 241.Po 242.Xr bind 2 243to IPv6 address 244.Li :: 245.Pc , 246and there is no wildcard bind 247.Dv AF_INET 248socket on that TCP/UDP port, IPv6 traffic as well as IPv4 traffic 249should be routed to that 250.Dv AF_INET6 251socket. 252IPv4 traffic should be seen as if it came from IPv6 address like 253.Li ::ffff:10.1.1.1 . 254This is called IPv4 mapped address. 255.It 256If there are both wildcard bind 257.Dv AF_INET 258socket and wildcard bind 259.Dv AF_INET6 260socket on one TCP/UDP port, they should behave separately. 261IPv4 traffic should be routed to 262.Dv AF_INET 263socket and IPv6 should be routed to 264.Dv AF_INET6 265socket. 266.El 267.Pp 268However, RFC 2553 does not define the constraint between the order of 269.Xr bind 2 , 270nor how IPv4 TCP/UDP port numbers and IPv6 TCP/UDP port numbers 271relate to each other 272.Po 273should they be integrated or separated 274.Pc . 275Implemented behavior is very different from kernel to kernel. 276Therefore, it is unwise to rely too much upon the behavior of 277.Dv AF_INET6 278wildcard bind socket. 279It is recommended to listen to two sockets, one for 280.Dv AF_INET 281and another for 282.Dv AF_INET6 , 283if both IPv4 and IPv6 traffic are to be accepted. 284.Pp 285It should also be noted that 286malicious parties can take advantage of the complexity presented above, 287and are able to bypass access control, 288if the target node routes IPv4 traffic to 289.Dv AF_INET6 290socket. 291Caution should be taken when handling connections 292from IPv4 mapped addresses to 293.Dv AF_INET6 294sockets. 295.Sh SEE ALSO 296.Xr ioctl 2 , 297.Xr socket 2 , 298.Xr sysctl 3 , 299.Xr icmp6 4 , 300.Xr intro 4 , 301.Xr ip6 4 , 302.Xr tcp 4 , 303.Xr udp 4 304.Sh STANDARDS 305.Rs 306.%A Tatsuya Jinmei 307.%A Atsushi Onoe 308.%T "An Extension of Format for IPv6 Scoped Addresses" 309.%R internet draft 310.%D June 2000 311.%N draft-ietf-ipngwg-scopedaddr-format-02.txt 312.%O work in progress material 313.Re 314.Sh HISTORY 315The 316.Nm 317protocol interface is defined in RFC 2553 and RFC 2292. 318The implementation described herein appeared in WIDE/KAME project. 319.Sh BUGS 320The IPv6 support is subject to change as the Internet protocols develop. 321Users should not depend on details of the current implementation, 322but rather the services exported. 323.Pp 324.Dq Version independent 325code should be implemented as much as possible in order to support both 326.Xr inet 4 327and 328.Nm inet6 . 329