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 ################################################################################
9 CONFIG_FILE=/etc/grml/routersetup
10 . /etc/grml/lsb-functions
11 . /etc/grml/script-functions
15 if ! [ -r "$CONFIG_FILE" ] ; then
16 eerror "$CONFIG_FILE could not be read."
22 if [ -z "$BRIDGE_DEVICES" ] ; then
23 eerror "Bridge devices (\$BRIDGE_DEVICES) not set in $CONFIG_FILE"
27 [ -n "$BRCTL" ] || BRCTL=brctl
28 [ -n "$STP" ] || STP=on
29 [ -n "$BRIDGE_NAME" ] || BRIDGE_NAME=br0
31 check4progs $BRCTL || exit 1
35 einfo "Starting bridge"
37 einfo "Creating bridge device"
38 brctl addbr "$BRIDGE_NAME"
44 einfo "Setting Spanning-Tree Protocol (STP) to status $STP"
45 brctl stp "$BRIDGE_NAME" $STP
50 einfo "Bringing network device up: "
52 for i in $BRIDGE_DEVICES ; do
54 ifconfig "$i" 0.0.0.0 up ; eend $?
58 einfo "Enabling promiscuous mode on: "
60 for i in $BRIDGE_DEVICES ; do
62 ip link set "$i" promisc on ; eend $?
66 einfo "Adding network devices to $BRIDGE_NAME: "
68 for i in $BRIDGE_DEVICES ; do
70 brctl addif "$BRIDGE_NAME" $i ; eend $?
74 einfo "Bringing bridge $BRIDGE_NAME up"
75 ip link set "$BRIDGE_NAME" up ; eend $?
77 case $BRIDGE_CONFIG in
79 einfo "starting dhclient for $BRIDGE_NAME"
80 dhclient -pf /var/run/dhclient.$BRIDGE_NAME.pid -lf /var/run/dhclient.$BRIDGE_NAME.leases $BRIDGE_NAME
83 einfo "Setting IP for $BRIDGE_NAME to $BRIDGE_IP"
84 ip a a $BRIDGE_IP dev $BRIDGE_NAME
87 einfo "Leaving $BRIDGE_NAME unconfigured"
95 einfo "Stopping bridge"
97 if [ $BRIDGE_CONFIG = DHCP ]; then
98 einfo "Terminating dhclient for $BRIDGE_NAME"
99 if [ -r "/var/run/dhclient.$BRIDGE_NAME.pid" ] ; then
100 kill "$(cat /var/run/dhclient.$BRIDGE_NAME.pid)" || /bin/true
103 einfo "Removing network devices from $BRIDGE_NAME: "
106 for i in $BRIDGE_DEVICES ; do
108 brctl delif "$BRIDGE_NAME" $i ; eend $?
112 einfo "Disabling promiscuous mode on: "
114 for i in $BRIDGE_DEVICES ; do
116 ip link set "$i" promisc off ; eend $?
120 einfo "Bringing bridge: $BRIDGE_NAME down"
121 ip link set "$BRIDGE_NAME" down; eend $?
123 einfo "Removing bridge device"
124 ifconfig "$BRIDGE_NAME" down || /bin/true
125 brctl delbr "$BRIDGE_NAME"
137 einfo "$0 - script which turns on basic bridging capabilities"
138 einfo "Configure via $CONFIG_FILE" ; eend 0
143 $BRCTL show ; eend $?
147 echo "Usage: $0 {start|stop|restart|status|info}"
152 ## END OF FILE #################################################################
153 # vim: ft=sh expandtab ai