1
0

ipv4-static-route 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "${GATEWAY}" ]; then
  40. MSG="The GATEWAY variable cannot be set in ${IFCONFIG} for static routes.\n"
  41. log_failure_msg "$MSG Use STATIC_GATEWAY only, cannot continue"
  42. exit 1
  43. fi
  44. if [ -n "${need_ip}" ]; then
  45. if [ -z "${IP}" ]; then
  46. log_failure_msg "IP variable missing from ${IFCONFIG}, cannot continue."
  47. exit 1
  48. fi
  49. if [ -z "${PREFIX}" ]; then
  50. log_failure_msg "PREFIX variable missing from ${IFCONFIG}, cannot continue."
  51. exit 1
  52. fi
  53. args="${args} ${IP}/${PREFIX}"
  54. desc="${desc}${IP}/${PREFIX}"
  55. fi
  56. if [ -n "${need_gateway}" ]; then
  57. if [ -z "${STATIC_GATEWAY}" ]; then
  58. log_failure_msg "STATIC_GATEWAY variable missing from ${IFCONFIG}, cannot continue."
  59. exit 1
  60. fi
  61. args="${args} via ${STATIC_GATEWAY}"
  62. fi
  63. if [ -n "${SOURCE}" ]; then
  64. args="${args} src ${SOURCE}"
  65. fi
  66. case "${2}" in
  67. up)
  68. log_info_msg "Adding '${desc}' route to the ${1} interface..."
  69. ip route add ${args} dev ${1}
  70. evaluate_retval
  71. ;;
  72. down)
  73. log_info_msg "Removing '${desc}' route from the ${1} interface..."
  74. ip route del ${args} dev ${1}
  75. evaluate_retval
  76. ;;
  77. *)
  78. echo "Usage: ${0} [interface] {up|down}"
  79. exit 1
  80. ;;
  81. esac
  82. # End /lib/services/ipv4-static-route