I can understand the output of strace route -n, but does route really read any of the files in /proc to get the routing table? Also, if the routes and IP addresses are stored under /proc, why doesn't strace show those files being accessed?

root@xxxx:/etc/postfix# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     0      0        0 eth0         UG    100    0        0 eth0

Edit, after more research:

It seems that route does read a file under /proc: specifically, /proc/net/route. How, then, did the routing information get there?

  • think about it. do you expect the kernel to read those files whenever there's a routing decision? It's in memory. – Karoly Horvath Aug 13 '11 at 15:47
  • so which program/function adds it into memory? – krisdigitx Aug 13 '11 at 15:50
  • this doesn't belong on SO, the "how" is programming related – Matt Joiner Aug 13 '11 at 17:10

The contents of files in the /proc directory, or indeed any directory on which the proc filesystem is mounted, is generated on the fly. The various filesystem related system calls are directed at the VFS layer in the Linux kernel to the proc code, which obtains the information from in-memory data structures inside the kernel memory space, formats them, masquerades them as the contents of those files.

Here is the file responsible for printing out the routing information for IPv4 in the kernel.


Yes, it does use /proc, see that part of the strace route -n output:

open("/proc/net/route", O_RDONLY)       = 3

it reads all the information from there. The source of the information is the kernel itself. The kernel offers the routing information via files in the procfs.

Files in /proc are usually generated and filled (with information) by the kernel itself. Via this interface, the kernel can safely provide internal information to userland. In most cases, that is even human-readable.

  • yeah i saw..cool..how did that info get there? – krisdigitx Aug 13 '11 at 15:50

The initial routing table is loaded from config files at boot time. Later you can manually add entries with the route command. Also, routed or gated listens on the network for routing information and dynamically updates the routing table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.