Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Aug 13 '11 at 16:39

This question came from our site for professional and enthusiast programmers.

    
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
add comment

3 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
thanks Matt for the info.. –  krisdigitx Aug 14 '11 at 12:26
add comment

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.

share|improve this answer
    
yeah i saw..cool..how did that info get there? –  krisdigitx Aug 13 '11 at 15:50
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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