INET6(4)
π inet6 β the Internet protocol version 6 family π
okay bestie, welcome to inet6(4) β this is the kernel interfaces manual page for the Internet protocol version 6 family, and honestly? she's iconic, she's carrying the entire future of the internet on her back, and we're gonna read her together. grab a strawberry π, sit down, let's go.
β¨ SYNOPSIS β¨
#include <sys/types.h>
#include <netinet/in.h>
that's it. that's the whole vibe. two includes and you're in. π¦
π DESCRIPTION π
So. inet6 is the glow-up version of the inet(4) family β like, same family, but she went to the gym, got a new wardrobe, and came back with 128-bit energy. inet(4) does Internet Protocol version 4, and inet6 does Internet Protocol version 6. periodt. π
inet6 is a whole collection of protocols layered on top of the Internet Protocol version 6 (IPv6) transport layer, and it's out here utilizing the IPv6 address format. the way that it just... stacks protocols on the transport layer... obsessed.
The inet6 family provides protocol support for the SOCK_STREAM, SOCK_DGRAM, and SOCK_RAW socket types β and lowkey the SOCK_RAW interface is the VIP pass, because it gives you access to the IPv6 protocol itself. π
πΈ ADDRESSING πΈ
Okay so here's the tea. IPv6 addresses are 16 byte quantities, stored in network standard byteorder. sixteen. bytes. not four like her little sister. she's big, she's grown, she's fr fr.
The include file <netinet/in.h> defines this address as a discriminated union β yes, that's the actual technical term, no cap. π
Sockets bound to the inet6 family utilize the following addressing structure:
struct sockaddr_in6 {
uint8_t sin6_len;
sa_family_t sin6_family;
in_port_t sin6_port;
uint32_t sin6_flowinfo;
struct in6_addr sin6_addr;
uint32_t sin6_scope_id;
};
six fields. she's got range. memorize her, bestie, she WILL come up. β¨
π¦ wildcard energy
Sockets may be created with the local address :: β which is equal to the IPv6 address 0:0:0:0:0:0:0:0 β to affect βwildcardβ matching on incoming messages. so basically "i'll take anything, no preferences, i'm flexible like that." π
π₯ scoped addresses (the complicated ones)
So the IPv6 specification defines scoped addresses, like link-local or site-local addresses. And here's the thing β a scoped address is ambiguous to the kernel if it's specified without a scope identifier. like, the kernel is just sitting there going "which interface, babe? WHICH ONE?" π
To manipulate scoped addresses properly from the userland, programs must use the advanced API defined in RFC2292. There's a compact description of that advanced API available in ip6(4) β go read it, it's the lore.
If a scoped address is specified without an explicit scope, the kernel may raise an error. and honestly? fair.
β οΈ Note that scoped addresses are not for daily use at this moment, both from a specification and an implementation point of view. β translation: she's not ready for prime time yet, she's still in her experimental era. π§
π the KAME extended notation
The KAME implementation supports an extended numeric IPv6 address notation for link-local addresses β like fe80::1%de0 to specify βfe80::1 on de0 interfaceβ. the percent sign is doing SO much heavy lifting there, she's the main character. π
This notation is supported by getaddrinfo(3) and getnameinfo(3). and some of the normal userland programs β such as telnet(1) or ftp(1) β are able to use this notation too. slay.
With special programs like ping6(8), you can specify the outgoing interface by an extra command line option to disambiguate scoped addresses. so like, if the % notation isn't hitting, you've got options. π
π scoped addresses inside the kernel
Scoped addresses are handled specially in the kernel. In kernel structures like routing tables or interface structures, a scoped address will have its interface index embedded into the address. so the address in some kernel structures is not the same as the one on the wire. it's giving... transformation. π¦
That embedded index will become visible through:
- a
PF_ROUTEsocket - kernel memory accesses via
kvm(3) - and on some other occasions
π¨ HOWEVER β users should never use the embedded form. do not. i'm serious. put it down. π ββοΈ
For details please consult IMPLEMENTATION supplied with the KAME kit. it's the extended lore, you gotta read it in the source material. π
π PROTOCOLS π
okay so the inet6 family is literally a whole friend group π and it's made up of: the IPv6 network protocol, Internet Control Message Protocol version 6 (ICMPv6), Transmission Control Protocol (TCP), and User Datagram Protocol (UDP). no cap.
TCP is the one that shows up for the SOCK_STREAM abstraction, and UDP is the one holding it down for SOCK_DGRAM. heads up bestie π β TCP and UDP are common to both inet(4) and inet6. they're shared, they're not gatekeeping.
want a raw interface to IPv6? make an Internet socket of type SOCK_RAW and you're in π₯. and the ICMPv6 message protocol is reachable from a raw socket. slay.
π MIB Variables π
there's a whole bunch of variables chillin' in the net.inet6 branch of the sysctl(3) MIB. on top of the variables the transport protocols support (go read their own man pages for those, i'm not doing their homework), these general ones are defined:
IPV6CTL_FORWARDING(ip6.forwarding) β Boolean: enable/disable forwarding of IPv6 packets. it also identifies whether the node is acting as a router. defaults to off.IPV6CTL_SENDREDIRECTS(ip6.redirect) β Boolean: enable/disable sending ofICMPv6redirects in response to unforwardable IPv6 packets. this option is ignored unless the node is routing IPv6 packets, and it should normally be enabled on all systems. defaults to on.IPV6CTL_DEFHLIM(ip6.hlim) β Integer: default hop limit value to use for outgoing IPv6 packets. this value applies to all the transport protocols on top of IPv6. there are APIs to override the value.IPV6CTL_MAXFRAGS(ip6.maxfrags) β Integer: maximum number of fragments the host will accept and simultaneously hold across all reassembly queues in all VNETs. if set to0, fragment reassembly is disabled. if set to-1, this limit is not applied. this limit is recalculated when the number of mbuf clusters is changed. this is a global limit.IPV6CTL_MAXFRAGPACKETS(ip6.maxfragpackets) β Integer: maximum number of fragmented packets the node will accept and simultaneously hold in the reassembly queue for a particular VNET.0means the node will not accept any fragmented packets for that VNET.-1means the node will not apply this limit for that VNET. this limit is recalculated when the number of mbuf clusters is changed. this is a per-VNET limit.IPV6CTL_MAXFRAGBUCKETSIZE(ip6.maxfragbucketsize) β Integer: maximum number of reassembly queues per bucket. fragmented packets are hashed to buckets, and each bucket has a list of reassembly queues. the system must compare incoming packets to the existing reassembly queues in the bucket to find a matching reassembly queue. to preserve system resources, the system limits the number of reassembly queues allowed in each bucket. this limit is recalculated when the number of mbuf clusters is changed or when the value ofip6.maxfragpacketschanges. this is a per-VNET limit.IPV6CTL_MAXFRAGSPERPACKET(ip6.maxfragsperpacket) β Integer: maximum number of fragments the host will accept and hold in the ressembly queue for a packet. this is a per-VNET limit.IPV6CTL_ACCEPT_RTADV(ip6.accept_rtadv) β Boolean: the default value of a per-interface flag to enable/disable receiving ofICMPv6router advertisement packets, and autoconfiguration of address prefixes and default routers. the node must be a host (not a router) for the option to be meaningful. defaults to off.IPV6CTL_AUTO_LINKLOCAL(ip6.auto_linklocal) β Boolean: the default value of a per-interface flag to enable/disable performing automatic link-local address configuration. defaults to on.IPV6CTL_LOG_INTERVAL(ip6.log_interval) β Integer: default interval between IPv6 packet forwarding engine log output (in seconds).IPV6CTL_HDRNESTLIMIT(ip6.hdrnestlimit) β Integer: default number of the maximum IPv6 extension headers permitted on incoming IPv6 packets. if set to0, the node will accept as many extension headers as possible.IPV6CTL_DAD_COUNT(ip6.dad_count) β Integer: default number of IPv6DAD(duplicated address detection) probe packets. the packets will be generated when IPv6 interface addresses are configured.IPV6CTL_AUTO_FLOWLABEL(ip6.auto_flowlabel) β Boolean: enable/disable automatic filling of IPv6 flowlabel field, for outstanding connected transport protocol packets. the field might be used by intermediate routers to identify packet flows. defaults to on.IPV6CTL_DEFMCASTHLIM(ip6.defmcasthlim) β Integer: default hop limit value for an IPv6 multicast packet sourced by the node. this value applies to all the transport protocols on top of IPv6. there are APIs to override the value as documented inip6(4).IPV6CTL_GIF_HLIM(ip6.gifhlim) β Integer: default maximum hop limit value for an IPv6 packet generated bygif(4)tunnel interface.IPV6CTL_KAME_VERSION(ip6.kame_version) β String: identifies the version ofKAMEIPv6 stack implemented in the kernel.IPV6CTL_USE_DEPRECATED(ip6.use_deprecated) β Boolean: enable/disable use of deprecated address, specified inRFC24625.5.4. defaults to on.IPV6CTL_RR_PRUNE(ip6.rr_prune) β Integer: default interval between IPv6 router renumbering prefix babysitting, in seconds.IPV6CTL_V6ONLY(ip6.v6only) β Boolean: enable/disable the prohibited use of IPv4 mapped address onAF_INET6sockets. defaults to on.
π Interaction between IPv4/v6 sockets π
so by default, FreeBSD does not route IPv4 traffic to AF_INET6 sockets. and bestie, this default behavior intentionally violates RFC2553, for security reasons π«Ά. if you wanna accept both IPv4 and IPv6 traffic, you listen to two sockets, okay? IPv4 traffic may be routed with certain per-socket/per-node configuration, but lowkey it is not recommended to do so. consult ip6(4) for the details.
the behavior of AF_INET6 TCP/UDP socket is documented in RFC2553. basically, it says this:
- A specific bind on an
AF_INET6socket (bind(2)with an address specified) should accept IPv6 traffic to that address only. - If you perform a wildcard bind on an
AF_INET6socket (bind(2)to IPv6 address::), and there is no wildcard bindAF_INETsocket on thatTCP/UDPport, IPv6 traffic as well as IPv4 traffic should be routed to thatAF_INET6socket. IPv4 traffic should be seen as if it came from an IPv6 address like::ffff:10.1.1.1. this is called an IPv4 mapped address β¨. - If there are both a wildcard bind
AF_INETsocket and a wildcard bindAF_INET6socket on oneTCP/UDPport, they should behave separately. IPv4 traffic should be routed to theAF_INETsocket and IPv6 should be routed to theAF_INET6socket.
however π β RFC2553 does not define the ordering constraint between calls to bind(2), nor how IPv4 TCP/UDP port numbers and IPv6 TCP/UDP port numbers relate to each other (should they be integrated or separated?). the implemented behavior is very different from kernel to kernel. so it is unwise to rely too much upon the behavior of AF_INET6 wildcard bind sockets. it is recommended to listen to two sockets, one for AF_INET and another for AF_INET6, when you would like to accept both IPv4 and IPv6 traffic. periodt.
it should also be noted that malicious parties can take advantage of the complexity presented above, and are able to bypass access control, if the target node routes IPv4 traffic toAF_INET6socket. users are advised to take care handling connections from IPv4 mapped address toAF_INET6sockets. π stay safe out there.
π SEE ALSO π
ioctl(2), socket(2), sysctl(3), icmp6(4), intro(4), ip6(4), tcp(4), udp(4)
π STANDARDS π
Tatsuya Jinmei and Atsushi Onoe, An Extension of Format for IPv6 Scoped Addresses, internet draft, draft-ietf-ipngwg-scopedaddr-format-02.txt, June 2000, work in progress material.
π¦ HISTORY π¦
the inet6 protocol interfaces are defined in RFC2553 and RFC2292. the implementation described herein appeared in the WIDE/KAME project. iconic behavior honestly π
π BUGS π
the IPv6 support is subject to change as the Internet protocols develop. users should not depend on details of the current implementation, but rather the services exported. fr fr.
users are suggested to implement βversion independentβ code as much as possible, as you will need to support both inet(4) and inet6. iykyk π
and that's a wrap on the whole page, bestie π this one came from the Debian folks, dated August 14, 2018, and it's the INET6(4) manual page β go forth and configure responsibly πβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms