Ticket #11796: bridge

File bridge, 1.8 KB (added by Tim Tassonis, 8 years ago)

adjusted version of blfs/services/bridge, to allow for bridges without pre-defined interfaces

Line 
1#!/bin/sh
2########################################################################
3# Begin /lib/services/bridge
4#
5# Description : Bridge Boot Script
6#
7# Authors : Nathan Coulson - nathan@linuxfromscratch.org
8# Bruce Dubbs - bdubbs@linuxfromscratch.org
9#
10# Version : LFS-7.2
11#
12########################################################################
13
14. /lib/lsb/init-functions
15. ${IFCONFIG}
16
17# Make compatible with older versions of init-functions
18unset is_true
19
20is_true()
21{
22 [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] ||
23 [ "$1" = "y" ] || [ "$1" = "t" ]
24}
25
26if [ -z "${INTERFACE_COMPONENTS}" ]; then
27 log_warning_msg "INTERFACE_COMPONENTS variable missing from ${IFCONFIG}"
28fi
29
30case "${2}" in
31 up)
32 log_info_msg2 "\n"
33 log_info_msg "Creating the ${1} interface..."
34 brctl addbr ${1}
35 evaluate_retval
36
37 if [ -n "${INTERFACE_COMPONENTS}" ]; then
38
39 for I in ${INTERFACE_COMPONENTS}; do
40 log_info_msg "Adding ${I} to ${1}..."
41 brctl addif ${1} ${I}
42 evaluate_retval
43 done
44
45 fi
46
47 if is_true ${STP}; then
48 brctl stp ${1} on
49 log_success_msg "Setting spanning tree protocol"
50 fi
51
52 if is_true ${IP_FORWARD}; then
53 sysctl -w net.ipv4.ip_forward=1 > /dev/null
54 log_success_msg "Setting net.ipv4.ip_forward = 1"
55 fi
56 ;;
57
58 down)
59 if [ -n "${INTERFACE_COMPONENTS}" ]; then
60
61 for I in ${INTERFACE_COMPONENTS}; do
62 log_info_msg "Removing ${I} from ${1}..."
63 ip link set ${I} down &&
64 brctl delif ${1} ${I}
65 evaluate_retval
66 done
67
68 fi
69 log_info_msg "Bringing down the ${1} interface..."
70 ip link set ${1} down
71 brctl delbr ${1}
72 evaluate_retval
73 ;;
74
75 *)
76 echo "Usage: ${0} [interface] {up|down}"
77 exit 1
78 ;;
79esac
80
81# End /lib/services/bridge
82