Re: Parsing /proc/net/route

From: Andi Kleen (ak@suse.de)
Date: Thu Sep 14 2000 - 10:17:43 EST


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

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



This archive was generated by hypermail 2b29 : Fri Sep 15 2000 - 21:00:29 EST