Opened 9 years ago

Closed 9 years ago

#4928 closed defect (fixed)

bug in /etc/hotplug.d/iface/10-routes

Reported by: anonymous Owned by: developers
Priority: normal Milestone: Kamikaze 8.09.1
Component: base system Version: Kamikaze 8.09
Keywords: route Cc:



I found a strange quirck in /etc/hotplug.d/iface/10-routes.

I need to add the following two routes:

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface UH        0 0          0 eth0.1         UG        0 0          0 eth0.1

This can easily be achieved by the route command:

/sbin/route add -host dev eth0.1
/sbin/route add -net default dev eth0.1 gateway

-or equivalently-

/sbin/route add -net netmask dev eth0.1
/sbin/route add -net netmask dev eth0.1 gateway

It does not seem possible to achieve the first line using openWRT.

The following in /etc/config/network:

  config route
        option interface wan
        option target
        option netmask
        option gateway

/sbin/route add -net netmask gw dev eth0.1

This is invalid syntax, and results in "route: SIOCADDRT: Invalid argument"
(you may never specify "gateway")

The alternative config in /etc/config/network:

  config route
        option interface wan
        option target
        option netmask
        option gateway ''

/sbin/route add -net netmask gw dev eth0.1

And NOT the correct:
/sbin/route add -net netmask dev eth0.1

This is due two a few very strange, and indeed plain wrong lines in /etc/hotplug.d/iface/10-routes

     [ -n "$gateway" ] || {
         config_get gateway "$interface" gateway

These lines occur twice (for IPv4 and for IPv6). Please remove them in the next release of Kamikaze, they are faulty.

Attachments (0)

Change History (5)

comment:1 Changed 9 years ago by jow

  • Resolution set to wontfix
  • Status changed from new to closed

Just leave out the netmask, then it will use:
/sbin/route add -host dev eth0.1

Busybox' route command will throw an error if you use "-net" together with a netmask of "".

Anyway, I'll change the script to use "-host" if the netmask is

comment:2 Changed 9 years ago by jow

  • Resolution wontfix deleted
  • Status changed from closed to reopened

Okay, I misreaded it, you meant the gateway part.

A little more detail:
The reasoning behind the code which reads the gateway from the interface config, is to allow defining static routes on interfaces with a dynamic ip (e.g. wan with dhcp). Since the gateway option is - in case of dhcp - written to uci state vars, it will always hold the right value. The routes code is (re-executed) each time the interface changes (e.g. obtained a new lease). This way you can define a static route on wan, ommitting the gateway and it will "magically" work the way it's expected.

Now there's the problem that the scripts which read uci data can't differentiate between empty () options and not-present options, so empty always means undefined.
My next idea was to specify the gateway as "" but /sbin/route won't accept that, so I propose a change where you can define "option gateway" in the config and the script will handle that appropriately.

See for a possible workaround.

comment:3 Changed 9 years ago by anonymous

Indeed too bad /sbin/route simply does not accept "gw"!

Somehow the word "christmas tree" came to my mind -- the code that sets the gateway to the interface tries to be smart, but ends-up wrong sometimes. To quote one good programmer, In the face of ambiguity, refuse the temptation to guess.

I think a better solution would be that:

  • leaving out the gateway in /etc/config/network also leaves out the gateway in the /sbin/route command.
  • 'option gateway interface' in /etc/config/network would do the magic trick you desribe above.

I realize that this may be a problem for backwards compatibility, but it is more obvious to users what is happening.

comment:4 Changed 9 years ago by jow

  • Milestone changed from Kamikaze to Kamikaze 8.09.1

comment:5 Changed 9 years ago by jow

  • Resolution set to fixed
  • Status changed from reopened to closed

Fix applied in r15272.

Add Comment

Modify Ticket

as closed .
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.