ipv4-static-route 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin /lib/network-services/ipv4-static-route
  4. #
  5. # Description : IPV4 Static Route Script
  6. #
  7. # Authors : Kevin P. Fleming - kpfleming@linuxfromscratch.org
  8. #
  9. # Version : 00.00
  10. #
  11. # Notes :
  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. boot_mesg "Unknown route type (${TYPE}) in ${IFCONFIG}, cannot continue." ${FAILURE}
  36. echo_failure
  37. exit 1
  38. ;;
  39. esac
  40. if [ -n "${need_ip}" ]; then
  41. if [ -z "${IP}" ]; then
  42. boot_mesg "IP variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
  43. echo_failure
  44. exit 1
  45. fi
  46. if [ -z "${PREFIX}" ]; then
  47. boot_mesg "PREFIX variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
  48. echo_failure
  49. exit 1
  50. fi
  51. args="${args} ${IP}/${PREFIX}"
  52. desc="${desc}${IP}/${PREFIX}"
  53. fi
  54. if [ -n "${need_gateway}" ]; then
  55. if [ -z "${GATEWAY}" ]; then
  56. boot_mesg "GATEWAY variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
  57. echo_failure
  58. exit 1
  59. fi
  60. args="${args} via ${GATEWAY}"
  61. fi
  62. case "${2}" in
  63. up)
  64. boot_mesg "Adding '${desc}' route to the ${1} interface..."
  65. ip route add ${args} dev ${1}
  66. evaluate_retval
  67. ;;
  68. down)
  69. boot_mesg "Removing '${desc}' route from the ${1} interface..."
  70. ip route del ${args} dev ${1}
  71. evaluate_retval
  72. ;;
  73. *)
  74. echo "Usage: ${0} [interface] {up|down}"
  75. exit 1
  76. ;;
  77. esac
  78. # End /lib/network-services/ipv4-static-route