Gentoo Archives: gentoo-dev

From: Stroller <GentooGimp@×××××××××.com>
To: gentoo-dev@g.o
Subject: Re: [gentoo-dev] init.d net scripts & Bash wierdness
Date: Mon, 24 Mar 2003 09:13:37
Message-Id: 52380.192.168.1.70.1048497424.squirrel@gentoo.lan
1 Many thanks to the list for the excellent help with my
2 /etc/init.d/net.br0 script.
3
4 I'm disproportionately proud of myself for implementing the list's
5 suggestions successfully. Many thanks to Sylvain for teaching me how to
6 traverse lists in Bash scripts. I'm sure my script could do with error
7 trapping (and a little tidying, see below), but I'm wondering if it would
8 be worth distributing something like this as part of the bridge-utils
9 ebuild. Is it worth me getting in touch with the maintainer..?
10
11
12 On Saturday, March 22, 2003, at 10:54 pm, Martin Schlemmer wrote:
13 > On Sat, 2003-03-22 at 23:35, Stroller wrote:
14 >
15 >> Unfortunately, for some reason my new script doesn't seem to read the
16 >> gateway="br0/192.168.1.1" line from the config.d file, and I can't
17 >> work
18 >> out why not. If I use my dumb script the gateway is allocated
19 >> correctly,
20 >> but not when I try to read parameters from file.
21 >
22 > My best bet from looking at it quickly, is that you still have
23 > 'gateway'
24 > set in /etc/conf.d/net. If you look at /sbin/runscript.sh, you will
25 > see:
26 > ---------------------------------------------------------------- #
27 > Source configuration files.
28 > # (1) Source /etc/conf.d/basic to get common configuration.
29 > # (2) Source /etc/conf.d/${myservice} to get initscript-specific #
30 > configuration (if it exists).
31 > # (3) Source /etc/conf.d/net if it is a net.* service
32 > # (4) Source /etc/rc.conf to pick up potentially overriding
33 > # configuration, if the system administrator chose to put it #
34 > there (if it exists).
35 >
36 > [ -e /etc/conf.d/basic ] && source /etc/conf.d/basic
37 >
38 > [ -e "/etc/conf.d/${myservice}" ] && source
39 > "/etc/conf.d/${myservice}"
40 >
41 > [ -e /etc/conf.d/net ] && \
42 > [ "${myservice%%.*}" = "net" ] && \
43 > [ "${myservice##*.}" != "${myservice}" ] && source /etc/conf.d/net
44 >
45 > [ -e /etc/rc.conf ] && source /etc/rc.conf
46 > -----------------------------------------------------------------
47 >
48 > Thus, it sources your /etc/conf.d/net.br0, and then sources
49 > /etc/conf.d/net, which resets 'gateway' again, and makes the
50 > '[ "${gateway%/*}" = "${IFACE}" ]' bit always fail.
51 >
52 > As I see it, you have two simple choices (other than hacking
53 > things to pieces):
54 >
55 > 1) Use something other than 'gateway' for the br0 script.
56 >
57 > 2) Do not set gateway in /etc/conf.d/net
58
59 Well, I've hacked things to pieces ;-]
60
61 Then I reread you posting, and I see how I could have done things
62 differently.
63
64 You see, I've done this:
65 for gateway in ${gateways}
66 do
67 if [ -n "${gateway}" ] && [ "${gateway%/*}" = "${IFACE}" ]
68 then
69 ebegin " Setting default gateway"
70 /sbin/route add default gw ${gateway#*/} dev ${gateway%/*} \
71 netmask 0.0.0.0 metric 1 >/dev/null || {
72 local error=$?
73 ifconfig ${IFACE} down &>/dev/null
74 eend ${error} "Failed to bring ${IFACE} up"
75 stop
76 return ${error}
77 }
78 eend 0
79 fi
80 done
81
82 Then changed /etc/conf.d/net :
83 # For setting the default gateway
84 #gateway="eth0/192.168.1.1"
85 #gateway="br0/192.168.1.1"
86 # The above settings don't work, because Gentoo's init.d scripts will
87 # only read the last default gateway entry hence this naffs up the
88 # eth0 entry
89 gateways="br0/192.168.1.1 eth0/192.168.1.1"
90
91 Now, as I understand it, it would probably be tidier if I had proceeded
92 differently:
93 - rename the standard /etc/conf.d/net to /etc/conf.d/net.eth0
94 - symlink that to /etc/conf.d/net.eth1
95 - create a new file called conf.d/net.br0 & put the `gateway="br0/...`
96 line (and IP address &c for br0) in there.
97
98 That way the two `gateway="ethX/...` lines can co-exist without
99 interfering with each other. I'll probably rearrange this shortly, as
100 that seems neater than rewriting Gentoo's default rc-srcipts & because
101 I want to diverge from the Gentoo out-of-the-box configuration as
102 little as possible.
103
104 Now, I can see (although I had to think about it) that init.d/net.*
105 files only read one default gateway for a Good Reason (tm). What I
106 don't understand is why not make the default configuration file to be
107 /etc/conf.d/net.eth0 in the first place..? Why have a /etc/conf.d/net
108 at all..?
109
110 As I understand it (someone will undoubtedly correct me if I'm wrong
111 B-] ), the naming convention of ethX is strictly arbitrary - you could
112 name your first interface as eth7. There's been some talk here recently
113 of folks having one network configuration for home, and another for
114 work: as I understand it you could have ethX & ethY as different
115 run-levels for the same physical network card, each with a different
116 set of settings in /etc/conf.d/. In this case the same problem would be
117 encountered as I have, and the user would have to configure
118 /etc/conf.d/net.ethX & /etc/conf.d/net.ethY and have no /etc/conf.d/net.
119
120 This probably sounds like I'm whinging because it took me a while to
121 figure it out: "it was a hassle for me, so you should change the whole
122 Gentoo distribution!" I don't mean it like that, but I'd be interested
123 to hear if there's a really good reason for having /etc/conf.d/net out
124 of the box, instead of /etc/conf.d/net.eth0. The default configuration
125 is slightly easier if you add a 2nd NIC & want to use both together on
126 different subnets (admittedly the common way), but users could easily
127 copy conf.d/net.eth0 to conf.d/net.eth1 & edit, the same as they copy
128 /init.d/net.eth0.
129
130 At present there aren't even any comments in the header to say that
131 conf.d/net overrides any conf.d/net.XXX scripts. Am I just being
132 dumb..? Should users know that the source lines in /sbin/runscript.sh
133 behave this way..?
134
135 Many thanks to anyone who can aid my understanding. Sorry for such a
136 long posting - I seem to have the -v flag permanently set.
137
138 Stroller.
139
140
141
142
143 --
144 gentoo-dev@g.o mailing list