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
18 ewarn "Could not read $CONFIG_FILE"
21 # defaults if unconfigured
22 [ -n "$BRCTL" ] || BRCTL=brctl
23 [ -n "$BRIDGE_STP" ] || BRIDGE_STP=on
24 [ -n "$BRIDGE_NAME" ] || BRIDGE_NAME=br0
25 [ -n "$BRIDGE_DEVICES" ] || BRIDGE_DEVICES='eth0 eth1'
27 check4progs $BRCTL || exit 1
31 einfo "Starting bridge"
33 einfo "Creating bridge device"
34 brctl addbr "$BRIDGE_NAME"
40 einfo "Setting Spanning-Tree Protocol (STP) to status $BRIDGE_STP"
41 brctl stp "$BRIDGE_NAME" "$BRIDGE_STP"
46 einfo "Bringing network device up: "
48 for i in $BRIDGE_DEVICES ; do
50 ifconfig "$i" 0.0.0.0 up ; eend $?
54 einfo "Enabling promiscuous 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 -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 unconfigured"
91 einfo "Stopping bridge"
93 if [ $BRIDGE_CONFIG = DHCP ]; then
94 einfo "Terminating dhclient for $BRIDGE_NAME"
95 if [ -r "/var/run/dhclient.$BRIDGE_NAME.pid" ] ; then
96 kill "$(cat /var/run/dhclient.$BRIDGE_NAME.pid)" || /bin/true
99 einfo "Removing network devices from $BRIDGE_NAME: "
102 for i in $BRIDGE_DEVICES ; do
104 brctl delif "$BRIDGE_NAME" $i ; eend $?
108 einfo "Disabling promiscuous mode on: "
110 for i in $BRIDGE_DEVICES ; do
112 ip link set "$i" promisc off ; eend $?
116 einfo "Bringing bridge: $BRIDGE_NAME down"
117 ip link set "$BRIDGE_NAME" down; eend $?
119 einfo "Removing bridge device"
120 ifconfig "$BRIDGE_NAME" down || /bin/true
121 brctl delbr "$BRIDGE_NAME"
133 einfo "$0 - script which turns on basic bridging capabilities"
134 einfo "Configure via $CONFIG_FILE" ; eend 0
139 $BRCTL show ; eend $?
143 echo "Usage: $0 {start|stop|restart|status|info}"
148 ## END OF FILE #################################################################
149 # vim: ft=sh expandtab ai