2 # Filename: grml-bridge
3 # Purpose: set up your box as bridge
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 # Latest change: Mit Mär 26 23:02:52 CET 2008 [mika]
8 ################################################################################
13 CONFIG_FILE=/etc/grml/routersetup
14 . /etc/grml/lsb-functions
15 . /etc/grml/script-functions
19 if ! [ -r "$CONFIG_FILE" ] ; then
20 eerror "$CONFIG_FILE could not be read."
26 if [ -z "$BRIDGE_DEVICES" ] ; then
27 eerror "Bridge devices (\$BRIDGE_DEVICES) not set in $CONFIG_FILE"
31 [ -n "$BRCTL" ] || BRCTL=brctl
32 [ -n "$STP" ] || STP=on
33 [ -n "$BRIDGE_NAME" ] || BRIDGE_NAME=br0
35 check4progs $BRCTL || exit 1
39 einfo "Starting bridge"
41 einfo "Creating bridge device"
42 brctl addbr "$BRIDGE_NAME"
48 einfo "Setting Spanning-Tree Protocol (STP) to status $STP"
49 brctl stp "$BRIDGE_NAME" $STP
54 einfo "Bringing network device up: "
56 for i in $BRIDGE_DEVICES ; do
58 ifconfig "$i" 0.0.0.0 up ; eend $?
62 einfo "Enabling promiscous mode on: "
64 for i in $BRIDGE_DEVICES ; do
66 ip link set "$i" promisc on ; eend $?
70 einfo "Adding network devices to $BRIDGE_NAME: "
72 for i in $BRIDGE_DEVICES ; do
74 brctl addif "$BRIDGE_NAME" $i ; eend $?
78 einfo "Bringing bridge $BRIDGE_NAME up"
79 ip link set "$BRIDGE_NAME" up ; eend $?
81 case $BRIDGE_CONFIG in
83 einfo "starting dhclient for $BRIDGE_NAME"
84 dhclient -pf /var/run/dhclient.$BRIDGE_NAME.pid -lf /var/run/dhclient.$BRIDGE_NAME.leases $BRIDGE_NAME
87 einfo "Setting IP for $BRIDGE_NAME to $BRIDGE_IP"
88 ip a a $BRIDGE_IP dev $BRIDGE_NAME
91 einfo "Leaving $BRIDGE_NAME uconfigured"
99 einfo "Stopping bridge"
101 if [ $BRIDGE_CONFIG = DHCP ]; then
102 einfo "Terminating dhclient for $BRIDGE_NAME"
103 if [ -r "/var/run/dhclient.$BRIDGE_NAME.pid" ] ; then
104 kill "$(cat /var/run/dhclient.$BRIDGE_NAME.pid)" || /bin/true
107 einfo "Removing network devices from $BRIDGE_NAME: "
110 for i in $BRIDGE_DEVICES ; do
112 brctl delif "$BRIDGE_NAME" $i ; eend $?
116 einfo "Disabling promiscous mode on: "
118 for i in $BRIDGE_DEVICES ; do
120 ip link set "$i" promisc off ; eend $?
124 einfo "Bringing bridge: $BRIDGE_NAME down"
125 ip link set "$BRIDGE_NAME" down; eend $?
127 einfo "Removing bridge device"
128 ifconfig "$BRIDGE_NAME" down || /bin/true
129 brctl delbr "$BRIDGE_NAME"
141 einfo "$0 - script which turns on basic bridging capabilities"
142 einfo "Configure via $CONFIG_FILE" ; eend 0
147 $BRCTL show ; eend $?
151 echo "Usage: $0 {start|stop|restart|status|info}"
156 ## END OF FILE #################################################################
157 # vim: ft=sh expandtab ai