2

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
10.21.58.0     0.0.0.0         255.255.254.0   U     0      0        0 eth0
0.0.0.0         10.21.58.1     0.0.0.0         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?

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

3 Answers 3

5

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.

0
3

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.

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

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .