When I execute
route -n, from where exactly (from which
structs) is the information displayed retrieved?
I tried executing
strace route -n but I didn't help me finding the right place it's stored.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
route or the
ip utility get their information from a pseudo filesystem called
procfs. It is normally mounted under
/proc. There is a file called
/proc/net/route, where you can see the kernel's IP routing table. You can print the routing table with
cat instead, but the route utility formats the output human readable, because the IP adresses are stored in hex.
That file is not just a normal file. It is always generated at exactly the moment when opening it with an attempt to read, as all files in the proc filesystem.
I you are interessted how that file is written, then you need to look at the kernel sources:
That function outputs the routeing table. You see at line 2510, the header of the routing table is printed. The routing table appears to be mostly in the struct
fib_info that is defined in the header file ip_fib.h, line 98.