RTENTRY(9)

πŸ¦‹ rtentry(9) β€” kernel developer's manual, but make it a vibe ✨

okay bestie, buckle up, because we're about to read the manual page for rtentry β€” the structure of an entry in the kernel routing table πŸ’– it's giving kernel-dev realness, and honestly? it ate.


🌸 NAME 🌸

rtentry β€” structure of an entry in the kernel routing table πŸ—ΊοΈβœ¨


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/types.h>
#include <sys/socket.h>
#include <net/route.h>

that's it, that's the whole synopsis, no cap 🫢


πŸ’… DESCRIPTION πŸ’…

so the kernel has this whole common mechanism where literally every protocol can store and retrieve entries from one central table of routes πŸ‘‘ parts of that mechanism also get used to talk to user-level processes through a socket in the route(4) pseudo-protocol family. and the <net/route.h> header file is the main character here β€” it defines all the structures and manifest constants this facility uses ✨

🧚 the basic structure

the basic structure of a route is defined by struct rtentry, and it includes these fields, bestie:

  • struct radix_node rt_nodes[2]; β€” glue used by the radix-tree routines 🧡 and not me pointing out that these members also include in their substructure the key (i.e., destination address) and mask used when the route was created. you can pull that info out with the rt_key(rt) and rt_mask(rt) macros, given a struct rtentry *, and it comes back in the form of a struct sockaddr * πŸ’«
  • struct sockaddr *rt_gateway; β€” the "target" of the route 🎯 which can either represent a destination in its own right (some protocols will put a link-layer address here), or some intermediate stop on the way to that destination (if the RTF_GATEWAY flag is set).
  • int rt_flags; β€” see below ⬇️ and heads up: if the RTF_UP flag is not present, the rtfree() function will delete the route from the radix tree when the last reference drops 😭
  • int rt_refcnt; β€” route entries are reference-counted, and this field is the number of external (to the radix tree) references πŸ”’
  • struct ifnet *rt_ifp;
  • struct ifaddr *rt_ifa; β€” these two fields together are, as it were, the "answer" to the question a route lookup asks πŸ₯Ή like, they name the interface and interface address to be used when sending a packet to the destination (or set of destinations) that this route represents.
  • u_long rt_mtu; β€” see the description of rmx_mtu below πŸ‘€
  • u_long rt_weight; β€” see the description of rmx_weight below πŸ‘€
  • u_long rt_expire; β€” see the description of rmx_expire below πŸ‘€
  • counter64_t rt_pksent; β€” see the description of rmx_pksent below πŸ‘€
  • struct rtentry *rt_gwroute; β€” this member is a reference to a route whose destination is rt_gateway πŸ›£οΈ it's only used for RTF_GATEWAY routes.
  • struct mtx rt_mtx; β€” mutex to lock this routing entry πŸ”’

🌈 the flag bits, defined

  • RTF_UP β€” the route is not deleted. it lives ✨
  • RTF_GATEWAY β€” the route points to an intermediate destination and not the ultimate recipient; the rt_gateway and rt_gwroute fields name that destination 🚏
  • RTF_HOST β€” this is a host route 🏠
  • RTF_REJECT β€” the destination is presently unreachable πŸ™… this should result in an EHOSTUNREACH error from output routines.
  • RTF_DYNAMIC β€” this route was created dynamically by rtredirect() 🌱
  • RTF_MODIFIED β€” this route was modified by rtredirect() ✏️
  • RTF_DONE β€” used only in the route(4) protocol, indicating that the request was executed βœ…
  • RTF_XRESOLVE β€” when this route is returned as a result of a lookup, send a report on the route(4) interface requesting that an external process perform resolution for this route πŸ“£
  • RTF_STATIC β€” indicates that this route was manually added by means of the route(8) command ✍️
  • RTF_BLACKHOLE β€” requests that output sent via this route be discarded πŸ•³οΈ bye!
  • RTF_PROTO1
  • RTF_PROTO2
  • RTF_PROTO3 β€” protocol-specific πŸ”¬
  • RTF_PINNED β€” indicates that this route is immutable to a routing protocol πŸ“Œ
  • RTF_LOCAL β€” indicates that the destination of this route is an address configured as belonging to this system πŸ’»
  • RTF_BROADCAST β€” indicates that the destination is a broadcast address πŸ“‘
  • RTF_MULTICAST β€” indicates that the destination is a multicast address πŸŽ‰ (multicast, not multilevel, ok?)

πŸ“ the metrics

several metrics get supplied in struct rt_metrics, passed along with routing control messages via the route(4) API πŸ“¨ currently only rmx_mtu, rmx_expire, and rmx_pksent metrics are supplied. all others are ignored πŸ«₯ (yes, ignored. the disrespect.)

the following metrics are defined by struct rt_metrics:

  • u_long rmx_locks; β€” flag bits indicating which metrics the kernel is not permitted to dynamically modify πŸ”
  • u_long rmx_mtu; β€” MTU for this path πŸ“
  • u_long rmx_hopcount; β€” number of intermediate systems on the path to this destination πŸͺœ
  • u_long rmx_expire; β€” the time (a la time(3)) at which this route should expire, or zero if it should never expire ⏰ and it is the responsibility of individual protocol suites to ensure that routes are actually deleted once they expire. so like, somebody has to do it, and it's not gonna be the kernel's problem.
  • u_long rmx_recvpipe; β€” nominally, the bandwidth-delay product for the path from the destination to this system πŸ“Ά in practice, this value is used to set the size of the receive buffer (and thus the window in sliding-window protocols like TCP).
  • u_long rmx_sendpipe; β€” as before, but in the opposite direction πŸ”
  • u_long rmx_ssthresh; β€” the slow-start threshold used in TCP congestion-avoidance 🚦
  • u_long rmx_rtt; β€” the round-trip time to this destination, in units of RMX_RTTUNIT per second ⏱️
  • u_long rmx_rttvar; β€” the average deviation of the round-trip time to this destination, in units of RMX_RTTUNIT per second πŸ“‰
  • u_long rmx_pksent; β€” a count of packets successfully sent via this route πŸ“¦
  • u_long rmx_filler[4]; β€” empty space available for protocol-specific information πŸ«™

πŸ”₯ SEE ALSO πŸ”₯

go read them, iykyk πŸ’–


πŸ‘‘ HISTORY πŸ‘‘

the rtentry structure first appeared in 4.2BSD πŸ•°οΈ the radix-tree representation of the routing table and the rt_metrics structure first appeared in 4.3BSD-Reno πŸŒ‰


🌸 AUTHORS 🌸

this manual page was written by Garrett Wollman 🫢 ty king


πŸ’€ BUGS πŸ’€

there are a number of historical relics remaining in this interface 🏺 like, fossils. the rt_gateway and rmx_filler fields could be named better πŸ’€ fr fr, we said it.


and that's the whole page, bestie πŸ’œ this one's from the Debian crew, dated March 5, 2014 β€” so it's a classic, and yes it still slays. mwah πŸ’…βœ¨

πŸ“¦ where this page comes from