Modify

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:

Description

Hi,

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
192.0.2.3       0.0.0.0         255.255.255.255 UH        0 0          0 eth0.1
0.0.0.0         192.0.2.3       0.0.0.0         UG        0 0          0 eth0.1

This can easily be achieved by the route command:

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

-or equivalently-

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

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 192.0.2.3
        option netmask 255.255.255.255
        option gateway 0.0.0.0

yields
/sbin/route add -net 192.0.2.3 netmask 255.255.255.255 gw 0.0.0.0 dev eth0.1

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

The alternative config in /etc/config/network:

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

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

And NOT the correct:
/sbin/route add -net 192.0.2.3 netmask 255.255.255.255 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 192.0.2.3 dev eth0.1

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

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

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 "0.0.0.0" but /sbin/route won't accept that, so I propose a change where you can define "option gateway 0.0.0.0" in the config and the script will handle that appropriately.

See http://openwrt.pastebin.com/m2e851a22 for a possible workaround.

comment:3 Changed 9 years ago by anonymous

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

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

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


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

 
Note: See TracTickets for help on using tickets.