bridge 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. . /lib/lsb/init-functions
  14. . ${IFCONFIG}
  15. # Make compatible with older versions of init-functions
  16. unset is_true
  17. is_true()
  18. {
  19. [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] ||
  20. [ "$1" = "y" ] || [ "$1" = "t" ]
  21. }
  22. if [ -z "${INTERFACE_COMPONENTS}" ]; then
  23. log_failure_msg "INTERFACE_COMPONENTS variable missing from ${IFCONFIG}"
  24. exit 1
  25. fi
  26. case "${2}" in
  27. up)
  28. log_info_msg2 "\n"
  29. log_info_msg "Creating the ${1} interface..."
  30. brctl addbr ${1}
  31. evaluate_retval
  32. for I in ${INTERFACE_COMPONENTS}; do
  33. log_info_msg "Adding ${I} to ${1}..."
  34. brctl addif ${1} ${I}
  35. evaluate_retval
  36. done
  37. if is_true ${STP}; then
  38. brctl stp ${1} on
  39. log_success_msg "Setting spanning tree protocol"
  40. fi
  41. if is_true ${IP_FORWARD}; then
  42. sysctl -w net.ipv4.ip_forward=1 > /dev/null
  43. log_success_msg "Setting net.ipv4.ip_forward = 1"
  44. fi
  45. ;;
  46. down)
  47. for I in ${INTERFACE_COMPONENTS}; do
  48. log_info_msg "Removing ${I} from ${1}..."
  49. ip link set ${I} down &&
  50. brctl delif ${1} ${I}
  51. evaluate_retval
  52. done
  53. log_info_msg "Bringing down the ${1} interface..."
  54. ip link set ${1} down
  55. brctl delbr ${1}
  56. evaluate_retval
  57. ;;
  58. *)
  59. echo "Usage: ${0} [interface] {up|down}"
  60. exit 1
  61. ;;
  62. esac
  63. # End /lib/services/bridge