Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 366677

Summary: sys-apps/openrc: network routes set up (net-tools) fails if routes_ has whitespace
Product: Gentoo Hosted Projects Reporter: Andrew Maltsev <am>
Component: OpenRCAssignee: OpenRC Team <openrc>
Status: RESOLVED FIXED    
Severity: normal CC: am
Priority: Normal Keywords: InVCS
Version: unspecified   
Hardware: All   
OS: Linux   
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=930f4021b1904b9c46c41c70b99d6e0620a1b59d
Whiteboard: openrc:oldnet
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 382299    
Attachments: Crude patch using sed
Same sed based patch in unified format
Config that does not work
emerge --info, per request.

Description Andrew Maltsev 2011-05-10 01:19:20 UTC
If /etc/conf.d/net has routes formatted like this:

routes_eth0="
        default via X.X.X.X
"

then net.eth0 assumes this is a "-host" routing failing to set up the proper default. This happens because of the whitespace in front of the command that prevents a case block from matching it.

Reproducible: Always

Steps to Reproduce:
1. Format your routes_eth0 like in the description
2. Run /etc/init.d/net.eth0 restart
3. Run netstat -rn and see that the route is not a network default
Actual Results:  
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         64.81.40.1      255.255.255.255 UGH       0 0          0 eth0


Expected Results:  
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
...
0.0.0.0         64.81.40.1      0.0.0.0         UG        0 0          0 eth0


It's a non-obvious bug that can easily happen as a result of translating old array format ( "..." "..." ) into the new baselayout-2 format.

It happens because in this case block:

                case ${cmd} in
                        -net" "*|-host" "*);;
                        *" "netmask" "*)                   cmd="-net ${cmd}";;
                        *.*.*.*/32*)                       cmd="-host ${cmd}";;
                        *.*.*.*/*|0.0.0.0|0.0.0.0" "*)     cmd="-net ${cmd}";;
                        default|default" "*)               cmd="-net ${cmd}";;
                        *)                                 cmd="-host ${cmd}";;
                esac

... the line does not match anything and falls into *, getting -host in front of it.
Comment 1 Andrew Maltsev 2011-05-10 01:58:02 UTC
Created attachment 272693 [details, diff]
Crude patch using sed

Not sure if it's a good idea to call an external process, but can't think of anything better right now. May be adding a "trim" command of some sort into runscript?
Comment 2 William Hubbs gentoo-dev 2011-05-12 22:25:06 UTC
Comment on attachment 272693 [details, diff]
Crude patch using sed

This patch is not in a unified diff format, so I am unable to apply it.

Can you please re-post this in a unified diff format?
Comment 3 Andrew Maltsev 2011-05-12 22:43:23 UTC
Created attachment 272993 [details, diff]
Same sed based patch in unified format

Patch reposted in unified format.
Comment 4 Christian Ruppert (idl0r) gentoo-dev 2011-09-18 16:27:05 UTC
I can't reproduce your problem, works fine for me.
Comment 5 Andrew Maltsev 2011-09-19 19:26:13 UTC
Christian, did you test with the exact format I described (whitespace in front of "default via")? I still see the bug in openrc 0.8.3. It's minor, I agree, but it is easy to put a space in front of "default" by mistake which would show no error and would set up incorrect routes. The fix is trivial. I don't see any reason not to apply it.
Comment 6 Christian Ruppert (idl0r) gentoo-dev 2011-09-19 19:33:44 UTC
Yeah, I also tried it with spaces as well as tabs and also with space/tab at the end of the route.
Looks good here.
Can you please attach your conf.d/net, so that I can test it again?
Comment 7 Andrew Maltsev 2011-09-19 19:45:48 UTC
Created attachment 287049 [details]
Config that does not work
Comment 8 Andrew Maltsev 2011-09-19 19:48:30 UTC
If I add an output below line 624 of /etc/init.d/net.lo then I get this on the attached config:

 * Caching service dependencies                   [ ok ]
 * Bringing up interface eth0
 *   192.168.0.205/24                             [ ok ]
 *   Adding routes
 *     default via 192.168.0.1 ...
 *     <<<<-host 	default via 192.168.0.1>>>>

Notice "-host" in the cmd? It should be "-net" if not for the whitespace.
Comment 9 Christian Ruppert (idl0r) gentoo-dev 2011-09-19 20:01:18 UTC
# /etc/conf.d/net
modules="iproute2"

config_eth0="
	192.168.1.200/24
"

routes_eth0="
	default via 192.168.1.160
"


# /etc/init.d/net.eth0 restart
 * Bringing down interface eth0
 * Bringing up interface eth0
 *   192.168.1.200/24 ...            [ ok ]
 *   Adding routes
 *     default via 192.168.1.160 ... [ ok ]

# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.160   0.0.0.0         UG        0 0          0 eth0
127.0.0.0       127.0.0.1       255.0.0.0       UG        0 0          0 lo
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
Comment 10 Christian Ruppert (idl0r) gentoo-dev 2011-09-19 20:09:22 UTC
Oh, btw. I use the latest git revision of openrc, so currently rc (OpenRC) 0.9.3git-645bbf (Gentoo Linux). iputils 20100418-r1 (Shouldn't matter but anyway..)
Comment 11 Andrew Maltsev 2011-09-19 20:23:42 UTC
I don't know about the git version, but the latest in portage (0.9.3-r1) still has this problem, I just checked.

...and looking at the git version (without actually installing it) I don't see it fixed there either.
Comment 12 Christian Ruppert (idl0r) gentoo-dev 2011-09-19 20:31:33 UTC
Can't reproduce it with 0.9.3-r1 either.
Please also attach emerge --info.
Comment 13 Andrew Maltsev 2011-09-19 20:35:27 UTC
Created attachment 287059 [details]
emerge --info, per request.
Comment 14 Christian Ruppert (idl0r) gentoo-dev 2011-09-20 00:02:01 UTC
Ok, this happens if you use net-tools instead of iproute2.
Comment 15 William Hubbs gentoo-dev 2011-09-20 02:18:40 UTC
(In reply to comment #14)
> Ok, this happens if you use net-tools instead of iproute2.

In that case, can we take a look at ifconfig.sh.Linux.in and see if we should fix something in there instead of in net.lo.in?
Comment 16 Andrew Maltsev 2011-09-20 02:30:03 UTC
No. The problem is determining the right parameters to call _add_route with, whichever module provides it.

Iproute works because it ignores both -host and -net as the first parameter.
Comment 17 Christian Ruppert (idl0r) gentoo-dev 2011-09-20 22:33:13 UTC
This should be fixed by commit 930f402.

You can apply the patch by:
# wget 'http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=patch;h=930f4021b1904b9c46c41c70b99d6e0620a1b59d' -O /tmp/net.lo.patch
# patch /etc/init.d/net.lo < /tmp/net.lo.patch