Re: Parsing /proc/net/route

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 14, 2000 at 11:06:33AM -0400, Tony Willoughby wrote:
> 
> Are there any known issues with /proc/net/route?  It seems that
> reading /proc/net/route doesn't always return all of the routes in the
> routing table.
> 
> I'm writing a user-space program (that runs as root) that will go
> through the routing table and delete routes with a specific gateway.
> It opens /proc/net/route and reads each line by calling fgets() in a
> loop until fgets() returns NULL. 
> 
> Almost always, when there are several (more than 30 or so), routes in
> the table fgets() returns NULL before all of the routes have been
> read.  Subsequent executions of this program will delete some (or all)
> of the remaining routes.  If the program is run enough times all of
> the desired routes will be deleted.
> 
> The algorithm for reading/parsing the contents of /proc/net/route is
> loosely based on netstat.c from net-tools-1.53.
> 
> I'm running 2.2.14-12.  A Red Hat distribution.
> 
> Is anyone aware of any problems with /proc/net/route?

Read all routes in first and then delete them in a single go.  Background: 
/proc works with 4K buffers. When you read an offset >4K it computes
the old route and just doesn't supply the routes that would end < your
seek offset. When you're deleting routes inbetween the routes will shift
down in the list and you're effectively skipping routes when you cross
a 4K boundary.

This is a fundamental design problem in /proc and probably not fixable.

Note that /proc/net/route does not display the full routing table anyways,
if you want all the details you need to use netlink/rtnetlink (see their
man pages). rtnetlink still has the same problem though, because real
cursors for the FIB would be too complex to manage.


-Andi 

-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux