Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 19695 - no designated way to add static routes in gentoo(/etc/conf.d/local.start is kludgy)
Summary: no designated way to add static routes in gentoo(/etc/conf.d/local.start is k...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Unspecified (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Aron Griffis (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 44184
  Show dependency tree
 
Reported: 2003-04-20 17:40 UTC by David Bryson (RETIRED)
Modified: 2004-04-21 12:06 UTC (History)
10 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
adds static routes support to the net interface (patch.net,888 bytes, patch)
2003-04-26 16:19 UTC, David Bryson (RETIRED)
Details | Diff
patch adds possibility to define static routes to net.ethN (gentoo_sr.patch,767 bytes, patch)
2003-06-09 16:16 UTC, Jukka Salmi
Details | Diff
/etc/conf.d/router (router,569 bytes, text/plain)
2003-10-14 07:45 UTC, Michael Locher
Details
/etc/init.d/router (router,784 bytes, text/plain)
2003-10-14 07:47 UTC, Michael Locher
Details
replacement net.eth0 script (net.eth0,7.99 KB, text/plain)
2004-03-08 12:26 UTC, Aron Griffis (RETIRED)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Bryson (RETIRED) gentoo-dev 2003-04-20 17:40:46 UTC
debian has the following format for adding routes on bringing up an interface in
the /etc/network/interfaces file

iface eth1 inet static
        address 10.1.1.1
        netmask 255.255.255.0
        up route add -net 10.2.1.0 netmask 255.255.255.0 gw 10.1.1.2
        up route add -net 10.3.1.0 netmask 255.255.255.0 gw 10.1.1.2

I wrote a patch that uses a similar format for adding route information in
/etc/conf.d/net
I will email patch on response to this bug.

Reproducible: Always
Steps to Reproduce:
1.
2.
3.
Comment 1 Martin Holzer (RETIRED) gentoo-dev 2003-04-24 16:59:20 UTC
please attach the patch here
Comment 2 David Bryson (RETIRED) gentoo-dev 2003-04-26 16:19:51 UTC
Created attachment 11196 [details, diff]
adds static routes support to the net interface

The method for adding a route to network interface is as follows

 route_eth0="add -net 10.2.1.0 netmask 255.255.255.0 gw 10.1.1.2"

 very similar to debian ;-)  although debian's system is a bit more flexible
with being able to add keywords at the beginning of the line like
up,down,pre-up,post-down.  For denoting when the following command should be
executed.
 At any rate i have a preliminary patch, but couldn't figure out a clean way to
add more than one route, i thought about

 route0_eth0="add -net 10.2.1.0 netmask 255.255.255.0 gw 10.1.1.2"
 route1_eth0="add -net 10.3.1.0 netmask 255.255.255.0 gw 10.1.1.2"

but that didn't lend itself well to neat code.	this patch at least starts
thing s in a good direction
Comment 3 Wout Mertens (RETIRED) gentoo-dev 2003-04-26 16:42:23 UTC
I'll try to handle this in the soon-to-come gentoo-net, but I'm going on vacation next week. No 
telling if I will work on it or not :) 
 
In the mean time, it could be added to the regular boot scripts? 
 
Comment 4 Steve Arnold gentoo-dev 2003-06-07 13:43:51 UTC
Well?  It's been over a month with no updates on this.  I was going to file a bug (which is now this comment instead) on nfsmount being called before local.start (which was the recommended place to add static routes).

So has there been any action?
Comment 5 David Bryson (RETIRED) gentoo-dev 2003-06-07 14:19:33 UTC
Well, the patch _is_ sitting there, I could try to come up with a different way of doing it.  I was told that the network layer was going to be re-written, but that hasn't happened yet either.  Would it be possible to either commit this patch, or add a similar one that maybe handles more than route per interface ?
i'll see if I can whip something up
Comment 6 Wout Mertens (RETIRED) gentoo-dev 2003-06-09 14:59:45 UTC
I would really like to work on this, but I really don't have time until August. I'll reassign it until August, when I do have time.

Wout.
Comment 7 Jukka Salmi 2003-06-09 16:16:27 UTC
Created attachment 13013 [details, diff]
patch adds possibility to define static routes to net.ethN

with this patch it's possible to add more than 1 static route. config syntax:

stroutes_$IFACE="target/mask_gateway [...]"

if /mask is not present it's treated like /32
Comment 8 Steve Arnold gentoo-dev 2003-06-09 22:35:14 UTC
The first patch didn't work for me.  Everything looks right, but it just gives:

 * Bringing eth0 down...                                                  [ ok ]
 * Bringing eth0 up...                                                    [ ok ]
 *   Setting default gateway...                                           [ ok ]
 *   Setting static routes......
 * Failed to add static routes on eth0                                    [ !! ]

I'll try this new one.
Comment 9 Richard Stevens 2003-09-03 19:17:57 UTC
Any news on this? 
 
How about simply allowing pre and post configs? 
 
We now have /etc/conf.d/net with the usual syntax and functionality wich is enough 
for most people. The /etc/init.d/net.ethX script could easily be modified to honour 
/etc/conf.d/net_ethX_pre and net_ethX_post files if and only if they are present. 
Something like this would also be useful for people using wlan since one could put 
pre and post config stuff for wlan cards in there, too, and not just static routes. 
Comment 10 David Bryson (RETIRED) gentoo-dev 2003-09-03 19:33:37 UTC
Actually I was thinking about this the other night.  Maybe a 'routes' init script, that would set everything after 'net' is configured.  Although your idea of some kind of dynamic interface up/down would be nice as well.  Maybe add both ?
Comment 11 Rajiv Aaron Manglani (RETIRED) gentoo-dev 2003-09-25 22:15:34 UTC
see also bug #26811.
Comment 12 Michael Locher 2003-10-14 07:45:23 UTC
Created attachment 19219 [details]
/etc/conf.d/router

support for device independant init.d/router script which should be started
right after the net.XXX scripts

this is a protype for the config file
Comment 13 Michael Locher 2003-10-14 07:47:14 UTC
Created attachment 19220 [details]
/etc/init.d/router

support for device independant init.d/router script which should be started
right after the net.XXX scripts

this is a protype for the init.d file
Comment 14 Aron Griffis (RETIRED) gentoo-dev 2004-03-08 12:26:16 UTC
Created attachment 27047 [details]
replacement net.eth0 script

Regarding the attempts in this bug so far:

- /etc/init.d/router is not the right solution because routes need to
  be recreated when an interface is restarted.

- David's patch in comment 2 isn't flexible enough

I have rewritten the net.eth0 script to provide full static route
configuration, enhanced output, and a better configuration syntax.
Please give this a try and report back in this bug.

Here are the nitty-gritty details.  eth0 is used for example but of
course could be any interface.

- Specify routes as an array per interface, for example:

    routes_eth0=(
	"-net 10.1.0.0 netmask 255.255.0.0 gw 10.0.0.5"
	"-net 10.2.0.0 netmask 255.255.0.0 gw 10.0.0.6"
	"-host 10.3.0.1 dev eth0"
    )

- You can optionally use the gateway variable or just put the
    default route in the routes variable.  The following two are
    REDUNDANT:

    routes_eth0=(
	"default gw 10.0.0.5"
    )

    gateway="eth0/10.0.0.5"

- Old configuration variables in /etc/conf.d/net are fully supported
  and used transparently if ifconfig_eth0 is missing.  In other words,
  this new script is fully backward-compatible.  However you can get
  rid of iface_eth0, alias_eth0, broadcast_eth0 and netmask_eth0 if
  you want by using the new syntax:

    ifconfig_eth0=(
	"10.0.0.6 broadcast 10.0.255.255 netmask 255.255.0.0"
	"192.168.1.1 netmask 255.255.255.0"
	"123.456.789.1"
    )

- Additionally many small bugs in the old script were fixed.

Please respond in this bug!  I have tested this extensively, but your testing
will grease the skids to get this into baselayout ASAP.
Comment 15 Aron Griffis (RETIRED) gentoo-dev 2004-03-08 12:46:51 UTC
Here is a non-exhaustive list of features added and/or bugs fixed by
this rewrite:

- Full backward compatibility so no danger to screwing up users
  relying on existing /etc/conf.d/net setup

- NET_DEBUG can be set in the environment for copious debugging output

- Deprecate [ ] in favor of [[ ]] which has fewer quoting issues and
  better functionality (and is even slightly faster)

- Properly localize all variables, including variables returned by
  setup_vars

- Allow full options for every ifconfig command, both base address and
  aliases via ifconfig_eth0, replacing the convoluted and
  less-functional iface_eth0, alias_eth0, broadcast_eth0, netmask_eth0

- Provide full support for static routes via routes_eth0

- Fix potential quoting problems in setup_vars by using better eval
  syntax instead of eval echo

- Display IP addresses while configuring, both DHCP-retrieved and
  statically set addresses

- Collapse redundant caching of $? since eend returns $? again

- Report when keeping kernel configuration for an interface along with
  IP address gleaned

- Don't reset the default gateway if it is already set correctly

- Don't bind default gateway to particular interface when /sbin/route
  is called so that it can survive if there is more than one interface
  on the required subnet.  (Old behavior can be obtained by setting
  routes_eth0="default gw 1.2.3.4 dev eth0" if you really want it)

- Don't bomb if default gateway can't be set since that doesn't
  necessarily mean that the interface configuration is invalid.
  (Old behavior was completely broken, but commented section
  demonstrates how to do it right if necessary)

- iface_stop no longer relies on configuration in /etc/conf.d/net AT
  ALL.  This is very good because it means you can put new
  configuration in /etc/conf.d/net, then restart the interface and the
  old configuration will be properly shut down.

- iface_stop reports when it is releasing the DHCP lease
Comment 16 Aron Griffis (RETIRED) gentoo-dev 2004-03-08 15:46:09 UTC
The very latest version of this can be found at http://gentoo.org/~agriffis/net.eth0 with extremely minor changes.  I'm not updating the attachment since the changes are not substantial:

- report IP address of default gateway
- use grep instead of egrep in one spot
- localize "counter"
Comment 17 Jeff Shirley 2004-03-10 17:49:06 UTC
Aron,
The rewrite looks great and I tested it as you requested. It seems to work flawlessly for me in almost all respects and addresses virtually every complaint I've had about the network scripts in the past.
However, I did run into one small issue, although it seems relatively minor and may be specific to my setup. I get this (100% of the time) when I bring the interface down with your new script.

luna init.d # /etc/init.d/net.eth0 stop 
 * Bringing eth0 down
 *   Releasing DHCP lease for eth0...
 * Timed out                                                                                          [ !! ]

 *   Stopping eth0...                                                                                 [ ok ]

I only have one interface, eth0, on this laptop. The script does work successfully at configuring everything and brings the interface down regardless, including the static route. In that sense this seems to be mostly cosmetic for me but might be symptomatic of some bug or difficulty.
Comment 18 Aron Griffis (RETIRED) gentoo-dev 2004-03-10 19:20:42 UTC
Thanks for the feedback, Jeff.  I've fixed the problem and updated the version at http://dev.gentoo.org/~agriffis/net.eth0
Comment 19 Aron Griffis (RETIRED) gentoo-dev 2004-04-21 12:06:27 UTC
I guess I forgot to close this.  It's fixed in recent baselayouts, for example baselayout-1.8.11