INET6(4)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’– inet6 β€” Internet protocol version 6 family πŸ’–

okay so this is the inet6(4) page from the Kernel Interfaces Manual, and bestie, we are gonna get through it together. it's long, it's iconic, it's literally the whole IPv6 family. buckle up πŸŽ€


✨ NAME ✨

inet6 β€” the Internet protocol version 6 family. yes, THE family. the whole vibe. πŸ‘‘


🌸 SYNOPSIS 🌸

#include <sys/types.h>
#include <netinet/in.h>

like, you gotta include both. no cap. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the inet6 family is basically an updated version of the inet(4) family β€” glow-up edition. the way that inet(4) implements Internet Protocol version 4, inet6 implements Internet Protocol version 6. slay. ✨

inet6 is a collection of protocols layered atop the Internet Protocol version 6 (IPv6) transport layer, and utilizing the IPv6 address format. it's giving layered. it's giving stacked. 🧚

the inet6 family provides protocol support for the SOCK_STREAM, SOCK_DGRAM, and SOCK_RAW socket types β€” and the SOCK_RAW interface gives you access to the IPv6 protocol itself. main character energy fr fr. πŸ”₯


πŸ’… ADDRESSING πŸ’…

IPv6 addresses are 16 byte quantities, stored in network standard byteorder. periodt. the include file <netinet/in.h> defines this address as a discriminated union. fancy, i know. πŸŽ€

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;
};

look at her. six fields. absolutely ate. πŸ’œ

sockets may be created with the local address β€œ::” (which is equal to IPv6 address 0:0:0:0:0:0:0:0) to effect β€œwildcard” matching on incoming messages. it's the "i'll take whatever" of addresses. πŸ™ˆ


okay so now we gotta talk about scoped addresses and bestie, this is the part where things get a little unhinged. 😭

the IPv6 specification defines scoped addresses, like link-local or site-local addresses. a scoped address is ambiguous to the kernel if it is specified without a scope identifier. like, the kernel is standing there going "which one?? which interface??" 🫠

to manipulate scoped addresses properly from the userland, programs must use the advanced API defined in RFC2292. a compact description of the advanced API is available in ip6(4). so like, go read that one too, iykyk. πŸ“š

if a scoped address is specified without an explicit scope, the kernel may raise an error. so heads up. and note that scoped addresses are not for daily use at this moment, both from a specification and an implementation point of view. like, they're lowkey not ready for the group chat yet. πŸ’€


⭐ collect this: 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”. that little %de0 is doing SO much work.

this notation is supported by getaddrinfo(3) and getnameinfo(3). some of normal userland programs, such as telnet(1) or ftp(1), are able to use this notation. with special programs like ping(8), you can specify the outgoing interface by an extra command line option to disambiguate scoped addresses. see, they thought of everything 🌈


🧚 scoped addresses in 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 that on the wire. it's giving "same girl different outfit" honestly. πŸ’…

the embedded index will become visible through a PF_ROUTE socket, kernel memory accesses via kvm(3) and on some other occasions.

HOWEVER β€” and bestie i need you to hear me β€” users should never use the embedded form. like, don't. do NOT. i'm not kidding. 🚨

for details please consult IMPLEMENTATION supplied with KAME kit.


okay that's where part 1 wraps but we're literally not done, more is coming πŸ‘€ stay tuned πŸ’–

🌐 PROTOCOLS 🌐

okay so the inet6 family is like a little squad of protocols and here's the lineup πŸ’… the IPv6 network protocol itself, Internet Control Message Protocol version 6 (ICMPv6), Transmission Control Protocol (TCP), and User Datagram Protocol (UDP). TCP is the one holding up the SOCK_STREAM abstraction while UDP carries the SOCK_DGRAM abstraction, iconic behavior honestly 🫢 and like β€” heads up bestie β€” TCP and UDP are common to both inet(4) and inet6. You can also get a raw interface to IPv6 by creating an Internet socket of type SOCK_RAW, and the ICMPv6 message protocol is accessible from a raw socket. slay πŸ”₯

✨ MIB Variables ✨

There's a whole bunch of variables living in the net.inet6 branch of the sysctl(3) MIB 🌸 and besides the variables that the transport protocols support (go read their respective manual pages for those, iykyk), these general variables are defined:

  • IPV6CTL_FORWARDING (ip6.forwarding) β€” Boolean, bestie: enables/disables forwarding of IPv6 packets. It also identifies whether the node is acting as a router. Defaults to off.
  • IPV6CTL_SENDREDIRECTS (ip6.redirect) β€” Boolean: enables/disables sending of ICMPv6 redirects in response to unforwardable IPv6 packets. This option is ignored unless the node is routing IPv6 packets, and should normally be enabled on all systems. Defaults to on.
  • IPV6CTL_DEFHLIM (ip6.hlim) β€” Integer: the 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: the maximum number of fragments the host will accept and simultaneously hold across all reassembly queues in all VNETs. If set to 0, 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: the maximum number of fragmented packets the node will accept and simultaneously hold in the reassembly queue for a particular VNET. 0 means the node will not accept any fragmented packets for that VNET. -1 means 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: the maximum number of reassembly queues per bucket. Fragmented packets are hashed to buckets, and each bucket has a list of reassembly queues. The system has to 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 of ip6.maxfragpackets changes. This is a per-VNET limit.
  • IPV6CTL_MAXFRAGSPERPACKET (ip6.maxfragsperpacket) β€” Integer: the maximum number of fragments the host will accept and hold in the ressembly queue for a packet. This is a per-VNET limit. (yes "ressembly" β€” that's literally how it's spelled, we don't gatekeep 😭)
  • IPV6CTL_ACCEPT_RTADV (ip6.accept_rtadv) β€” Boolean: the default value of a per-interface flag to enable/disable receiving of ICMPv6 router 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: the default interval between IPv6 packet forwarding engine log output (in seconds).
  • IPV6CTL_HDRNESTLIMIT (ip6.hdrnestlimit) β€” Integer: the default number of the maximum IPv6 extension headers permitted on incoming IPv6 packets. If set to 0, the node will accept as many extension headers as possible.
  • IPV6CTL_DAD_COUNT (ip6.dad_count) β€” Integer: the default number of IPv6 DAD (duplicated address detection) probe packets. These packets get generated when IPv6 interface addresses are configured.
  • IPV6CTL_AUTO_FLOWLABEL (ip6.auto_flowlabel) β€” Boolean: enables/disables automatic filling of the IPv6 flowlabel field, for outstanding connected transport protocol packets. Intermediate routers might use the field to identify packet flows. Defaults to on.
  • IPV6CTL_DEFMCASTHLIM (ip6.defmcasthlim) β€” Integer: the 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 in ip6(4).
  • IPV6CTL_GIF_HLIM (ip6.gifhlim) β€” Integer: the default maximum hop limit value for an IPv6 packet generated by the gif(4) tunnel interface.
  • IPV6CTL_KAME_VERSION (ip6.kame_version) β€” String: identifies the version of the KAME IPv6 stack implemented in the kernel. vintage πŸ’…
  • IPV6CTL_USE_DEPRECATED (ip6.use_deprecated) β€” Boolean: enables/disables use of deprecated address, specified in RFC2462 5.5.4. Defaults to on.
  • IPV6CTL_RR_PRUNE (ip6.rr_prune) β€” Integer: the default interval between IPv6 router renumbering prefix babysitting, in seconds. literally babysitting, no cap 🍼
  • IPV6CTL_V6ONLY (ip6.v6only) β€” Boolean: enables/disables the prohibited use of IPv4 mapped address on AF_INET6 sockets. Defaults to on.
  • ip6.log_cannot_forward β€” Boolean: log packets that can't be forwarded because of unspecified source address or destination address beyond the scope of the source address, as described in RFC4443. Enabled by default.
  • ip6.source_address_validation β€” Boolean: perform source address validation for packets destined for the local host. Think of this as following Section 3.2 of RFC3704/BCP84, where we treat the local host as our own infrastructure. This has no effect on packets to be forwarded, so don't go considering it an anti-spoof feature for a router, bestie, that's not the vibe. Enabled by default.

πŸ¦‹ Interaction between IPv4/v6 sockets πŸ¦‹

By default, FreeBSD does not route IPv4 traffic to AF_INET6 sockets. And the default behavior intentionally violates RFC2553 for security reasons β€” yes, on purpose, main character energy πŸ‘‘ so listen to two sockets if you want to accept both IPv4 and IPv6 traffic. IPv4 traffic may be routed with certain per-socket/per-node configuration, but ngl it is not recommended to do so. Consult ip6(4) for the deets.

The behavior of an AF_INET6 TCP/UDP socket is documented in RFC2553. Basically it says this:

  • A specific bind on an AF_INET6 socket (bind(2) with an address specified) should accept IPv6 traffic to that address only.
  • If you perform a wildcard bind on an AF_INET6 socket (bind(2) to IPv6 address ::), and there is no wildcard bind AF_INET socket on that TCP/UDP port, IPv6 traffic as well as IPv4 traffic should be routed to that AF_INET6 socket. 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. cute ✨
  • If there are both a wildcard bind AF_INET socket and a wildcard bind AF_INET6 socket on one TCP/UDP port, they should behave separately. IPv4 traffic should be routed to the AF_INET socket and IPv6 should be routed to the AF_INET6 socket.

However β€” and this is the part that matters 😭 β€” 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?). Implemented behavior is very different from kernel to kernel. Therefore it is unwise to rely too much upon the behavior of AF_INET6 wildcard bind sockets. The recommendation: listen to two sockets, one for AF_INET and another for AF_INET6, when you would like to accept both IPv4 and IPv6 traffic. do that, bestie 🫢

Also should be noted: malicious parties can take advantage of the complexity presented above and are able to bypass access control if the target node routes IPv4 traffic to an AF_INET6 socket. Users are advised to take care handling connections from an IPv4 mapped address to AF_INET6 sockets. Not me warning you twice πŸ’€

🌈 SEE ALSO 🌈

ioctl(2), socket(2), sysctl(3), icmp6(4), intro(4), ip6(4), tcp(4), udp(4)

A. Conta, S. Deering, and M. Gupta, Internet Control Message Protocol (ICMPv6) for the Internet Protocol Version 6 (IPv6) Specification, RFC 4443, March 2006. πŸ“š

⭐ 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. (work in progress, so like… don't quote me πŸ˜…)

πŸŽ€ HISTORY πŸŽ€

The inet6 protocol interfaces are defined in RFC2553 and RFC2292. The implementation described herein appeared in the WIDE/KAME project. iconic origin story fr fr πŸ’–

πŸ› BUGS πŸ›

okay bestie, gather round, we gotta talk about the fine print πŸ’…

  • The IPv6 support is subject to change as the Internet protocols develop. literally the internet is a living organism and this code is riding the wave 🌊 no cap.
  • Users should not depend on details of the current implementation β€” depend on the services exported instead, mmkay? The internals are giving "main character who redecorates every week" πŸŽ€
  • Users are suggested to implement "version independent" code as much as possible, because bestie you will need to support both inet(4) and inet6. Both. Not one, not the other. Both. 😭 it's giving group project where you have to do double the work πŸ”₯
ngl this is the "plan ahead" section. Write it portable now so you're not crying in six months when the protocols shift on you πŸ™ˆβœ¨

okay that's the whole page, no more scroll 🫢 it's from the Debian source, dated February 22, 2023, and the page is literally called INET6(4) β€” go forth and dual-stack, icon πŸ‘‘πŸ’–

πŸ“¦ where this page comes from