INET(4)

πŸ’– INET(4) πŸ’– β€” the Internet protocol family, bestie edition

okay so welcome to inet(4), from the Kernel Interfaces Manual section, and no cap this one is a whole vibe. it's the Internet protocol family. let's get into it 🫢


✨ SYNOPSIS ✨

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

🌈 DESCRIPTION 🌈

so the Internet protocol family is literally a whole collection of protocols, right? and they're all layered on top of the Internet Protocol (IP) transport layer, using the Internet address format. that's the whole thing. that's the assignment and she ATE πŸ’…

the Internet family gives you protocol support for the SOCK_STREAM, SOCK_DGRAM, and SOCK_RAW socket types β€” and the SOCK_RAW interface is the one that gives you access to the IP protocol itself. main character energy fr fr πŸ”₯


πŸŽ€ ADDRESSING πŸŽ€

Internet addresses are four byte quantities, stored in network standard format. and heads up, on little endian machines β€” like the alpha, amd64 and i386 β€” these are word and byte reversed. so like, mind the gap bestie 😭

the include file <netinet/in.h> defines this address as a discriminated union.

sockets bound to the Internet protocol family use this addressing structure, and yes we're pasting it exactly, do not come for me:

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

so you can create sockets with the local address INADDR_ANY to get that β€œwildcard” matching on incoming messages β€” it's giving "I'll take whatever shows up" ✨

and the address in a connect(2) or sendto(2) call can also be given as INADDR_ANY, which in that context means β€œthis host”. same girl, different outfit πŸ’œ

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. conditional queen πŸ‘‘


⭐ PROTOCOLS ⭐

the Internet protocol family is comprised of:

  • the IP network protocol
  • Internet Control Message Protocol (ICMP)
  • Internet Group Management Protocol (IGMP)
  • Transmission Control Protocol (TCP)
  • User Datagram Protocol (UDP)

TCP is what supports the SOCK_STREAM abstraction, while UDP supports the SOCK_DGRAM abstraction. a raw interface to IP is available by creating an Internet socket of type SOCK_RAW. and the ICMP message protocol is accessible from a raw socket. periodt πŸ’…

the inet address on an interface consists of the address itself, the netmask, and either the broadcast address (in case of a broadcast interface) or the peer's address (in case of a point-to-point interface).

the following ioctl(2) commands are provided for a datagram socket in the Internet domain β€” presenting the lineup 🌸:

  • SIOCAIFADDR β€” Add address to an interface. The command requires struct in_aliasreq as argument.
  • SIOCDIFADDR β€” Delete address from an interface. The command requires struct ifreq as argument.
  • SIOCGIFADDR
  • SIOCGIFBRDADDR
  • SIOCGIFDSTADDR
  • SIOCGIFNETMASK β€” Return address information from interface. The returned value is in struct ifreq. This way of address information retrieval is obsoleted, and a preferred way is to use the getifaddrs(3) API.
ok so real talk: those last four are obsoleted, bestie. they still work, but the glow-up is getifaddrs(3). don't be the last one at the party 🫢

πŸ¦‹ MIB Variables πŸ¦‹

a number of variables are implemented in the net.inet branch of the sysctl(3) MIB. and besides the variables supported by the transport protocols (for those, go consult the respective manual pages, iykyk), the following general variables are defined:

  • IPCTL_FORWARDING (ip.forwarding) β€” Boolean: enable/disable forwarding of IP packets. Defaults to off.
  • IPCTL_SENDREDIRECTS (ip.redirect) β€” Boolean: enable/disable 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.
  • IPCTL_DEFTTL (ip.ttl) β€” Integer: default time-to-live (β€œTTL”) to use for outgoing IP packets.
  • IPCTL_ACCEPTSOURCEROUTE (ip.accept_sourceroute) β€” Boolean: enable/disable accepting of source-routed IP packets (default false).
  • IPCTL_SOURCEROUTE (ip.sourceroute) β€” Boolean: enable/disable forwarding of source-routed IP packets (default false).
  • ip.process_options β€” Integer: control IP options processing.
    • set it to 0 β†’ all IP options in the incoming packets will be ignored, and the packets will be passed unmodified.
    • set it to 1 β†’ IP options in the incoming packets will be processed accordingly.
    • set it to 2 β†’ 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. so like, both, bestie.
  • ip.rfc6864 β€” Boolean: control 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. ✨
  • ip.random_id β€” Boolean: control IP IDs generation behaviour. Setting this sysctl(8) to 1 causes the ID field in non-atomic IP datagrams (or all IP datagrams, if ip.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).
    • IPv6 flow IDs and fragment IDs are always random. no cap.
  • ip.maxfrags β€” Integer: maximum number of fragments the host will accept and simultaneously hold across all reassembly queues in all VNETs.
    • 0 β†’ reassembly is disabled.
    • -1 β†’ this limit is not applied.
    • This limit is recalculated when the number of mbuf clusters is changed.
    • This is a global limit.
  • ip.maxfragpackets β€” Integer: maximum number of fragmented packets the host will accept and simultaneously hold in the reassembly queue for a particular VNET.
    • 0 β†’ the host will not accept any fragmented packets for that VNET.
    • -1 β†’ 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.
  • ip.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 ip.maxfragpackets changes.
    • This is a per-VNET limit.
  • ip.maxfragsperpacket β€” Integer: maximum number of fragments the host will accept and hold in the reassembly queue for a packet.
    • 0 β†’ the host will not accept any fragmented packets for the VNET.
    • This is a per-VNET limit.

πŸ‘‘ SEE ALSO πŸ‘‘

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

β€œ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. and the β€œprotocol cloning” code appeared in FreeBSD 2.1. vintage but make it iconic πŸ’…


πŸ’€ CAVEATS πŸ’€

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.

like, do NOT get attached to implementation details bestie, she's a moving target 😭


and that's the whole page!! πŸŽ€ this one came from the Debian crew, dated August 14, 2018, filed under INET(4) β€” stay safe out there, and remember: read the docs, love yourself, and never trust an undocumented limit. mwah πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from