SETFIB(2)

πŸ’– SETFIB(2) β€” the "which routing table am I, bestie?" system call πŸ’–

okay so before we even get into it: this is a page from the System Calls Manual, and it's all about the FreeBSD setfib syscall. It lives in the Standard C Library (libc, -lc). Yes, that libc. The one you already link against. 🫢


✨ SYNOPSIS ✨

#include <sys/socket.h>

int
setfib(int fib);

🌸 DESCRIPTION 🌸

So here's the tea. The setfib() system call sets the associated fib for all sockets opened after you call it β€” like, every socket that comes into existence subsequent to the call gets the fib you passed in as the fib argument. It's giving "set the vibe for everything that comes next". πŸ‘‘

Now the rules for that argument, no cap:

  • fib must be greater than or equal to 0
  • and it must be less than the current system maximum

And how do you find out that maximum? You retrieve it with the net.fibs sysctl. Slay.

The system maximum itself gets set in the kernel configuration file like this:

options ROUTETABLES=N

or, alternatively, in /boot/loader.conf like this:

net.fibs="N"

where N is an integer. πŸŽ€

⚠️ Real talk: this maximum is capped at 65536, because the implementation stores the fib number in a 16-bit field in the mbuf(9) packet header. So like, that's the ceiling, physically.

But β€” and this is the important bit β€” it is not suggested that one use such a large number, because:

  • memory is allocated for every FIB regardless of whether it is used πŸ’€
  • and there are places where all FIBs are iterated over

So yeah. Big number, big sadness. Don't do it. πŸ™ˆ

Also, one more thing about how the default fib behaves: the default fib of the process will be applied to all protocol families that support multiple fibs, and it's ignored by those that do not. So if a protocol family doesn't do multiple fibs, it's just gonna look at you like 🧚 and move on.

Oh, and the default fib for a process may be overridden for a socket with the use of the SO_SETFIB socket option. So you've got per-socket power if you want it. Iconic.


⭐ RETURN VALUES ⭐

  • The setfib() function returns the value 0 if successful πŸŽ‰
  • otherwise the value -1 is returned, and the global variable errno is set to indicate the error 😭

🚨 ERRORS 🚨

The setfib() system call will fail, and no action will be taken, and it returns EINVAL if the fib argument is greater than the current system maximum.

That's the one. That's the whole list. Periodt.


πŸ‘€ SEE ALSO πŸ‘€


🌈 STANDARDS 🌈

The setfib() system call is a FreeBSD extension β€” however, similar extensions have been added to many other Unix style kernels. So like, it's a FreeBSD thing but it's not only a FreeBSD thing, iykyk. πŸ’…


πŸ“œ HISTORY πŸ“œ

The setfib() function appeared in FreeBSD 7.1. Baby's got history. πŸ’œ


and that's the whole page bestie, mwah πŸ’– this was Debian's rendering, dated March 19, 2012, and the footer said SETFIB(2) β€” so go forth, set your fibs, and remember: stay under the max, or EINVAL will humble you. πŸ¦‹βœ¨

πŸ“¦ where this page comes from