aboutsummaryrefslogtreecommitdiffstats
path: root/clfs/services/bridge
blob: 1750fca35e123a06d011e323e1810c0a4231fdbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
########################################################################
# Begin /lib/services/bridge
#
# Description : Bridge Boot Script
#
# Authors     : Nathan Coulson - nathan@linuxfromscratch.org
#               Bruce Dubbs - bdubbs@linuxfromscratch.org
#
# Version     : LFS-7.2
#
########################################################################

. /lib/lsb/init-functions
. ${IFCONFIG}

# Make compatible with older versions of init-functions
unset is_true

is_true()
{
   [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] ||  
   [ "$1" = "y" ] || [ "$1" = "t"   ]
}

if [ -z "${INTERFACE_COMPONENTS}" ]; then
   log_failure_msg "INTERFACE_COMPONENTS variable missing from ${IFCONFIG}"
   exit 1
fi

case "${2}" in
   up)
      log_info_msg2 "\n"
      log_info_msg "Creating the ${1} interface..."
      brctl addbr ${1}
      evaluate_retval

      for I in ${INTERFACE_COMPONENTS}; do
         log_info_msg "Adding ${I} to ${1}..."
         brctl addif ${1} ${I}
         evaluate_retval
      done

      if is_true ${STP}; then
        brctl stp ${1} on
        log_success_msg "Setting spanning tree protocol"
      fi

      if is_true ${IP_FORWARD}; then
        sysctl -w net.ipv4.ip_forward=1 > /dev/null
        log_success_msg "Setting net.ipv4.ip_forward = 1"
      fi
   ;;
   
   down)
      for I in ${INTERFACE_COMPONENTS}; do
         log_info_msg "Removing ${I} from ${1}..."
         ip link set ${I} down &&
         brctl delif ${1} ${I}
         evaluate_retval
      done

      log_info_msg "Bringing down the ${1} interface..."
      ip link set ${1} down
      brctl delbr ${1}
      evaluate_retval
   ;;
   
   *)
      echo "Usage: ${0} [interface] {up|down}"
      exit 1
   ;;
esac

# End /lib/services/bridge