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 Okt 11 23:02:51 CEST 2006 [moemoe]
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"
49 brctl stp "$BRIDGE_NAME" $STP
54 einfo "Enabling promiscous mode on: "
56 for i in $BRIDGE_DEVICES ; do
58 ip link set "$i" promisc on ; eend $?
62 einfo "Adding network devices to $BRIDGE_NAME: "
64 for i in $BRIDGE_DEVICES ; do
66 brctl addif "$BRIDGE_NAME" $i ; eend $?
70 einfo "Bringing bridge $BRIDGE_NAME up"
71 ip link set "$BRIDGE_NAME" up ; eend $?
73 case $BRIDGE_CONFIG in
75 einfo "starting dhclient for $BRIDGE_NAME"
76 dhclient -e -pf /var/run/dhclient.$BRIDGE_NAME.pid -lf /var/run/dhclient.$BRIDGE_NAME.leases $BRIDGE_NAME
79 einfo "Setting IP for $BRIDGE_NAME to $BRIDGE_IP"
80 ip a a $BRIDGE_IP dev $BRIDGE_NAME
83 einfo "Leaving $BRIDGE_NAME uconfigured"
91 einfo "Stopping bridge"
93 if [ $BRIDGE_CONFIG = DHCP ]; then
94 einfo "Terminating dhclient for $BRIDGE_NAME"
95 kill $(cat /var/run/dhclient.$BRIDGE_NAME.pid);
97 einfo "Removing network devices from $BRIDGE_NAME: "
100 for i in $BRIDGE_DEVICES ; do
102 brctl delif "$BRIDGE_NAME" $i ; eend $?
106 einfo "Disabling promiscous mode on: "
108 for i in $BRIDGE_DEVICES ; do
110 ip link set "$i" promisc off ; eend $?
114 einfo "Bringing bridge: $BRIDGE_NAME down"
115 ip link set "$BRIDGE_NAME" down; eend $?
117 einfo "Removing bridge device"
118 brctl delbr "$BRIDGE_NAME"
130 einfo "$0 - script which turns on basic bridging capabilities"
131 einfo "Configure via $CONFIG_FILE" ; eend 0
136 $BRCTL show ; eend $?
140 echo "Usage: $0 {start|stop|restart|status|info}"
145 ## END OF FILE #################################################################
146 # vim: ft=sh expandtab ai