Gentoo Archives: gentoo-dev

From: Stroller <GentooGimp@×××××××××.com>
To: gentoo-dev@g.o
Subject: [gentoo-dev] init.d net scripts & Bash wierdness - idiot in distress
Date: Sat, 22 Mar 2003 21:31:03
Message-Id: 51175.192.168.1.70.1048368929.squirrel@gentoo.lan
1 I'm hoping someone can take a look at the attached scripts & give me
2 some pointers, becuase I'm clearly doing something extremely dumb.
3
4 I'm trying to run a transparent bridge for my home network, much as
5 discussed in the FAQs & tutorials at
6 http://www.sparkle-cc.co.uk/firewall/firewall.html &
7 http://www.tldp.org/HOWTO/Ethernet-Bridge-netfilter-HOWTO.html
8
9 I thought I'd be clever & elegant & create a new runlevel for this, so
10 that my /etc/init.d/net.br0 script is started instead of eth0 & eth1.
11 It's largely working very well & I've been very impressed by Gentoo's
12 run-levels system.
13
14 I initially implemented this with a very simple script in which all
15 variables, IPs & interface names are static. This is attached as
16 net.br0.old - if I copy this to /etc/init.d/net.br0 everything works
17 perfectly. All I do is type `rc bridge` and all the other services
18 shutdown before eth0 & eth1 do, then nothing happens for a moment & then
19 my bridge device finishes initialising and up everything comes again.
20
21 I then decided to be "clever" and edit a copy of the
22 /etc/init.d/net.eth0 script, and so my new net.br0 (or net.br1 or
23 whatever) script takes the name of it's ${IFACE} from its own filename &
24 gets it's other parameters from /etc/config.d/net.br0 (or br1 &c).
25
26 Unfortunately, for some reason my new script doesn't seem to read the
27 gateway="br0/192.168.1.1" line from the config.d file, and I can't work
28 out why not. If I use my dumb script the gateway is allocated correctly,
29 but not when I try to read parameters from file.
30
31 You can see where I've tried `echo "foo"` and `echo "wibble"` for
32 debugging purposes. When I use this script as /etc/init.d/net.br0 & type
33 `rc bridge` the "foo" & "bar" are displayed, but not the "wibble".
34 Clearly the `if [ -n "${gateway}" ]...` line is not being returning
35 true; yet I do not understand why, as my script seems to be just the
36 same as the standard net.eth0 script in this respect, and my config file
37 (also attached) seems the same.
38
39 If anyone can explain what I'm doing wrong, I would be eternally
40 grateful.
41
42 Whilst I have your attention, I would also ideally like to have a list
43 of physical interfaces to be included in the config file. I think the
44 startup file would need a while loop to read them, as the bridge
45 interface can bridge any number of physical interfaces, as long as there
46 are at least 2 of them. Then the startup script needs to perform a
47 couple of loops through, ifconfig'ing each physical interface to IP
48 0.0.0.0 before adding it to the bridge device using the `brtcl add ...`
49 command.
50
51 I would guess that the list of physical devices might be stored in an
52 array, or read from a list, but I am completely inexperienced at Bash
53 scripting, so have no idea how to implement this. I found the Advanced
54 Bash Scripting Guide a bit too advanced for me - can anyone recommend an
55 alternative..? Is the O'Reilly Bash in a Nutshell any good..? I usually
56 like their books.
57
58 I do hope I've explained myself clearly,
59 Thanks for any pointers,
60
61 Stroller.

Attachments

File name MIME type
net.br0.old application/octet-stream
net.br0 application/octet-stream
conf.d-net.br0 application/octet-stream

Replies