RTREQUEST(9)
π RTREQUEST(9) β like, the routing table's personal assistant
okay so this one's from the Kernel Developer's Manual, and honestly? it's giving "backstage pass to the kernel" energy. rtrequest is the function that adds or removes entries from a routing table β the person doing the actual heavy lifting while everyone else gets the credit. main character energy fr.
β¨ SYNOPSIS β¨
first you gotta pull in the header files, no cap:
#include <sys/types.h>
#include <net/route.h>
int
rtrequest(int req, struct rt_addrinfo *info, u_int8_t prio,
struct rtentry **rtp, u_int rtableid);
struct rt_addrinfo {
int rti_addrs;
struct sockaddr *rti_info[RTAX_MAX];
int rti_flags;
struct ifaddr *rti_ifa;
struct rt_msghdr *rti_rtm;
u_char rti_mpls;
};
#define RTAX_DST 0 /* destination sockaddr present */
#define RTAX_GATEWAY 1 /* gateway sockaddr present */
#define RTAX_NETMASK 2 /* netmask sockaddr present */
#define RTAX_IFP 4 /* interface name sockaddr present */
#define RTAX_IFA 5 /* interface addr sockaddr present */
#define RTAX_AUTHOR 6 /* sockaddr for author of redirect */
#define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest */
#define RTAX_SRC 8 /* source sockaddr present */
#define RTAX_SRCMASK 9 /* source netmask present */
#define RTAX_LABEL 10 /* route label present */
#define RTAX_MAX 11 /* size of array to allocate */
yeah that's a lot of defines, but they're all RTAX_* friends and they're all iconic in their own way π
π DESCRIPTION π
rtrequest() is the function you call when you want to add or remove entries from a specific routing table. like, you point at one table and you're like "hi bestie, changes please."
it takes these args, and here's the whole rundown:
reqβ one of these actions, pick your fighter:RTM_ADDβ add an entry to a given routing table. slay.RTM_DELETEβ remove an entry from a given routing table. and heads up: in the case of a cloning entry, all of its children get deleted too. the whole family. π no survivors.RTM_RESOLVEβ add a cloned entry, based on the parent cloning entry thatrtppoints to, into a given routing table.
infoβ describes the routing entry you're adding or removing. it's the little description card, basically.prioβ specifies the priority of the routing entry described byinfo. and here's the cute part: if it's0and the requested action isRTM_ADD, then a default priority based on the priority of the associated interface gets chosen for you. king behavior honestly πrtpβ must point to the cloning entry if the action isRTM_RESOLVE. in all cases where no error is returned and it's notNULL, a pointer to the deleted or added entry gets placed there. and bestie, listen β the caller has to take care of releasing that returned reference by callingrtfree(9). don't leave it hanging, that's rude π«Άrtableidβ the ID of the routing table you want to modify. that's it. that's the whole thing.
π¦ CONTEXT π¦
rtrequest() can be called during autoconf, from process context, or from interrupt context. three whole vibes, and it's flexible enough for all of them π
π₯ RETURN VALUES π₯
rtrequest() may fail with any of these, so buckle up:
[EAFNOSUPPORT]β the routing table with ID ofrtableiddoesn't exist, or it doesn't support the protocol specified ininfo.[ESRCH]β no routing entry corresponding toinfocould be found.[ESRCH]β multipath routing entry with no gateway provided ininfo. like, you forgot the gateway, bestie.[ESRCH]β the entry could not be found in the routing table of IDrtableid. specified. (yes there's a little dangling "specified" there at the end β the original page has it too, we don't know either π)[EINVAL]β the entry pointed to byrtpis not valid, or doesn't point to a cloning entry in theRTM_RESOLVEcase.[EEXIST]β multipath routing entry conflicts with an existing one. drama.[EEXIST]β the entry could not be entered into the routing table.[ENOMEM]β space for MPLS protocol data could not be allocated.[ENOBUFS]β space for a new routing entry could not be allocated. no room, no entry, that's the rule π[ENETUNREACH]β an interface address corresponding to the routing entry described byinfocould not be found.
okay so notice some of these errno values show up twice with different meanings β that's not a typo on my end, the page literally lists them that way.ESRCHthree times andEEXISTtwice. it's giving "same word, different context," iykyk.
π SEE ALSO π
rtfree(9)β go free your references, bestie, that's the whole point π§
β so yeah, that's the page! it's from Debian, dated July 12, 2019 β vintage but still serving looks. go add those routes, free those references, and remember: the kernel is counting on you πβ¨
π¦ where this page comes from
- nixpkgs unstable: cvs-export
- Copyright (c) 2011 Bret S. Lambert <blambert@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms