INET(4)

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

🌐 INET(4) β€” Internet protocol family 🌐

okay bestie, this is inet(4) from the Kernel Interfaces Manual, and it's literally the blueprint for how the whole Internet protocol family fits together. buckle up πŸ’–


✨ NAME ✨

inet β€” the Internet protocol family, periodt πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

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

yes, both of them, in that order, don't @ me πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So the Internet protocol family is basically a whole squad of protocols stacked on top of the Internet Protocol (IP) transport layer, and they all speak in Internet address format 🌈. That's the vibe.

The Internet family has protocol support for these socket types:

  • SOCK_STREAM
  • SOCK_DGRAM
  • SOCK_RAW

and the SOCK_RAW interface is the main character that gives you direct access to the IP protocol πŸ”₯. iykyk.


πŸ’œ ADDRESSING πŸ’œ

Internet addresses are four byte quantities, stored in network standard format β€” and on little endian machines (like the alpha, amd64 and i386) those are word and byte reversed πŸ™ˆ. The include file <netinet/in.h> defines this address as a discriminated union ✨.

Sockets bound to the Internet protocol family use this addressing structure, exactly this one:

struct sockaddr_in {
        uint8_t         sin_len;
        sa_family_t     sin_family;
        in_port_t       sin_port;
        struct in_addr  sin_addr;
        char            sin_zero[8];
};

Sockets may be created with the local address INADDR_ANY to affect "wildcard" matching on incoming messages 🎯. And the address in a connect(2) or sendto(2) call may be given as INADDR_ANY to mean "this host" 🫢.

Also, the distinguished address INADDR_BROADCAST is allowed as a shorthand for the broadcast address on the primary network β€” but only if the first network configured supports broadcast πŸ“‘. so like, conditional slay. πŸ’€

πŸ¦‹ PROTOCOLS πŸ¦‹

okay so the Internet protocol family is literally a whole friend group πŸ’– and it's made up of the IP network protocol, the Internet Control Message Protocol (ICMP), the Internet Group Management Protocol (IGMP), the Transmission Control Protocol (TCP), and the User Datagram Protocol (UDP). And like, they each have their role, no cap:

  • TCP is the one holding up the SOCK_STREAM abstraction 🫢
  • UDP is the one holding up the SOCK_DGRAM abstraction πŸŽ€
  • and if you want a raw interface to IP? bestie you can just create an Internet socket of type SOCK_RAW ✨

Also the ICMP message protocol is accessible from a raw socket. iykyk.

The inet address on an interface consists of the address itself, the netmask, and then either the broadcast address in the case of a broadcast interface or the peers address in the case of a point-to-point interface. Like, it's giving "full package deal" πŸ’…

The following ioctl(2) commands are provided for a datagram socket in the Internet domain:

  • SIOCAIFADDR β€” adds an address to an interface. The command requires struct in_aliasreq as its argument.
  • SIOCDIFADDR β€” deletes an address from an interface. The command requires struct ifreq as its argument.
  • SIOCGIFADDR
  • SIOCGIFBRDADDR
  • SIOCGIFDSTADDR
  • SIOCGIFNETMASK β€” these four return address information from an interface. The returned value is in struct ifreq. ngl this way of retrieving address info is obsoleted, and the preferred way is to use the getifaddrs(3) API 🌸

🌸 MIB (sysctl) Variables 🌸

On top of the variables supported by the transport protocols in net.inet (for which you should go read the respective manual pages, bestie, I'm not doing everything for you 🫢), there are a number of general variables implemented in the net.inet.ip branch of the sysctl(3) MIB, which can also be read or modified with sysctl(8). The following general variables are defined:

  • accept_sourceroute β€” Boolean: enables/disables accepting of source-routed IP packets (default false).
  • allow_net0 β€” Boolean: allows forwarding of, and ICMP responses to, packets with addresses in 0.0.0.0/8.
  • allow_net240 β€” Boolean: allows forwarding of, and ICMP responses to, packets with addresses in 240.0.0.0/4.
  • curfrags β€” Integer: the current number of IPv4 fragments across all reassembly queues in all VNETs (read-only).
  • forwarding β€” Boolean: enables/disables forwarding of IP packets. Defaults to off.
  • fragpackets β€” Integer: the current number of IPv4 fragment reassembly queue entries for the VNET (read-only).
  • fragttl β€” Integer: time to live for IPv4 packet fragments in the per-VNET reassembly queue.
  • loopback_prefixlen β€” Integer: prefix length of the address space reserved for loopback purposes. The default is 8, meaning that 127.0.0.0/8 is reserved for loopback, and cannot be sent, received, or forwarded on a non-loopback interface. Heads up: use of other values is experimental πŸ™ˆ
  • maxfragbucketsize β€” Integer: maximum number of reassembly queues per bucket. Fragmented packets are hashed to buckets. Each bucket has a list of reassembly queues. The system must compare the 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 maxfragpackets changes. This is a per-VNET limit.
  • maxfragpackets β€” Integer: maximum number of fragmented packets the host will accept and simultaneously hold in the reassembly queue for a particular VNET. 0 means that the host will not accept any fragmented packets for that VNET. -1 means that the host 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.
  • maxfrags β€” Integer: maximum number of fragments the host will accept and simultaneously hold across all reassembly queues in all VNETs. If set to 0, 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.
  • maxfragsperpacket β€” Integer: maximum number of fragments the host will accept and hold in the reassembly queue for a packet. 0 means that the host will not accept any fragmented packets for the VNET. This is a per-VNET limit.
  • mcast β€” the variables under the net.inet.ip.mcast node are documented in ip(4). go look πŸ‘€
  • no_same_prefix β€” Boolean: refuses to create same prefixes on different interfaces. This is a per-VNET value.
  • portrange β€” the variables under the net.inet.ip.portrange node control port ranges used by transport protocols; see ip(4) for details.
  • process_options β€” Integer: controls IP options processing. Setting this variable to 0 makes all IP options in the incoming packets get ignored, and the packets get passed unmodified. Setting it to 1 means IP options in the incoming packets will be processed accordingly. Setting it to 2 means an ICMP "prohibited by filter" message will be sent back in response to incoming packets with IP options. Default is 1. This sysctl(8) variable affects packets destined for a local host as well as packets forwarded to some other host πŸ”₯
  • random_id β€” Boolean: controls IP IDs generation behavior. Setting this sysctl(8) to 1 causes the ID field in non-atomic IP datagrams (or all IP datagrams, if rfc6864 is disabled) to be randomized instead of incremented by 1 with each packet generated. This closes a minor information leak which allows remote observers to determine the rate of packet generation on the machine by watching the counter. At the same time, on high-speed links, it can decrease the ID reuse cycle greatly. Default is 0 (sequential IP IDs). Also fyi: IPv6 flow IDs and fragment IDs are always random ✨
  • random_id_collisions β€” Integer: count of IP ID collisions (read-only, per-VNET).
  • random_id_period β€” Integer: size of the IP ID array, which is the number of previous packets for which the IDs are recorded. The number must be between 512 and 32768 inclusive. This is a per-VNET value.
  • random_id_total β€” Integer: count of IP IDs created (read-only, per-VNET).
  • reass_hashsize β€” number of hash slots in the IPv4 reassembly queue (loader tunable).
  • redirect β€” Boolean: enables/disables sending of ICMP redirects in response to IP packets for which a better, and for the sender directly reachable, route and next hop is known. Defaults to on.
  • rfc1122_strong_es β€” Boolean: in non-forwarding mode (i.e. forwarding is disabled), partially implements the Strong End System model per RFC1122. If a packet with a destination address that is local arrives on a different interface than the interface the address belongs to, the packet would be silently dropped. πŸ‘€ Enabling this option may break certain setups, e.g. having an alias address(es) on loopback that are expected to be reachable by outside traffic. Enabling some other network features, e.g. carp(4) or destination address rewriting pfil(4) filters, may override and bypass this check. Disabled by default.
  • rfc6864 β€” Boolean: controls IP IDs generation behaviour. A true value enables RFC6864 support, which specifies that the IP ID field of atomic datagrams can be set to any value. The FreeBSD implementation sets it to zero. Enabled by default.
  • source_address_validation β€” Boolean: performs 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. Forwarded packets are unaffected by this, and it should not be considered an anti-spoof feature for a router. Enabled by default.
  • sourceroute β€” Boolean: enables/disables forwarding of source-routed IP packets (default false).
  • ttl β€” Integer: default time-to-live ("TTL") to use for outgoing IP packets πŸ’œ

✨ SEE ALSO ✨

ioctl(2), socket(2), getifaddrs(3), sysctl(3), icmp(4), intro(4), ip(4), ipfirewall(4), route(4), tcp(4), udp(4), sysctl(8), pfil(9)

And the reading list, because she's well-read obviously πŸ“š:

  • "An Introductory 4.3 BSD Interprocess Communication Tutorial", PS1, 7.
  • "An Advanced 4.3 BSD Interprocess Communication Tutorial", PS1, 8.

πŸŽ€ HISTORY πŸŽ€

The inet protocol interface appeared in 4.2BSD. The "protocol cloning" code appeared in FreeBSD 2.1. like, she's been iconic since forever πŸ‘‘


πŸ’€ CAVEATS πŸ’€

okay bestie listen up because this one matters 🫢 The Internet protocol 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, do not build your whole personality on the internals 😭


πŸ’… and that's the whole page, you ate that. this one's from Debian, dated December 31, 2024, and it's the INET(4) page β€” go forth and configure responsibly, mwah πŸŽ€βœ¨πŸ¦‹
πŸ“¦ where this page comes from