ipv4-static-route 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin /lib/services/ipv4-static-route
  4. #
  5. # Description : IPV4 Static Route Script
  6. #
  7. # Authors : Kevin P. Fleming - kpfleming@linuxfromscratch.org
  8. # DJ Lucas - dj@linuxfromscratch.org
  9. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  10. #
  11. # Version : LFS 7.0
  12. #
  13. ########################################################################
  14. . /lib/lsb/init-functions
  15. . ${IFCONFIG}
  16. case "${TYPE}" in
  17. ("" | "network")
  18. need_ip=1
  19. need_gateway=1
  20. ;;
  21. ("default")
  22. need_gateway=1
  23. args="${args} default"
  24. desc="default"
  25. ;;
  26. ("host")
  27. need_ip=1
  28. ;;
  29. ("unreachable")
  30. need_ip=1
  31. args="${args} unreachable"
  32. desc="unreachable "
  33. ;;
  34. (*)
  35. log_failure_msg "Unknown route type (${TYPE}) in ${IFCONFIG}, cannot continue."
  36. exit 1
  37. ;;
  38. esac
  39. if [ -n "${need_ip}" ]; then
  40. if [ -z "${IP}" ]; then
  41. log_failure_msg "IP variable missing from ${IFCONFIG}, cannot continue."
  42. exit 1
  43. fi
  44. if [ -z "${PREFIX}" ]; then
  45. log_failure_msg "PREFIX variable missing from ${IFCONFIG}, cannot continue."
  46. exit 1
  47. fi
  48. args="${args} ${IP}/${PREFIX}"
  49. desc="${desc}${IP}/${PREFIX}"
  50. fi
  51. if [ -n "${need_gateway}" ]; then
  52. if [ -z "${GATEWAY}" ]; then
  53. log_failure_msg "GATEWAY variable missing from ${IFCONFIG}, cannot continue."
  54. exit 1
  55. fi
  56. args="${args} via ${GATEWAY}"
  57. fi
  58. if [ -n "${SOURCE}" ]; then
  59. args="${args} src ${SOURCE}"
  60. fi
  61. case "${2}" in
  62. up)
  63. log_info_msg "Adding '${desc}' route to the ${1} interface..."
  64. ip route add ${args} dev ${1}
  65. evaluate_retval
  66. ;;
  67. down)
  68. log_info_msg "Removing '${desc}' route from the ${1} interface..."
  69. ip route del ${args} dev ${1}
  70. evaluate_retval
  71. ;;
  72. *)
  73. echo "Usage: ${0} [interface] {up|down}"
  74. exit 1
  75. ;;
  76. esac
  77. # End /lib/services/ipv4-static-route