ipv4-static-route 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin $network_devices/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. . /etc/sysconfig/rc
  15. . ${rc_functions}
  16. . ${IFCONFIG}
  17. case "${TYPE}" in
  18. ("" | "network")
  19. need_ip=1
  20. need_gateway=1
  21. ;;
  22. ("default")
  23. need_gateway=1
  24. args="${args} default"
  25. desc="default"
  26. ;;
  27. ("host")
  28. need_ip=1
  29. ;;
  30. ("unreachable")
  31. need_ip=1
  32. args="${args} unreachable"
  33. desc="unreachable "
  34. ;;
  35. (*)
  36. boot_mesg "Unknown route type (${TYPE}) in ${IFCONFIG}, cannot continue." ${FAILURE}
  37. echo_failure
  38. exit 1
  39. ;;
  40. esac
  41. if [ -n "${need_ip}" ]; then
  42. if [ -z "${IP}" ]; then
  43. boot_mesg "IP variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
  44. echo_failure
  45. exit 1
  46. fi
  47. if [ -z "${PREFIX}" ]; then
  48. boot_mesg "PREFIX variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
  49. echo_failure
  50. exit 1
  51. fi
  52. args="${args} ${IP}/${PREFIX}"
  53. desc="${desc}${IP}/${PREFIX}"
  54. fi
  55. if [ -n "${need_gateway}" ]; then
  56. if [ -z "${GATEWAY}" ]; then
  57. boot_mesg "GATEWAY variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
  58. echo_failure
  59. exit 1
  60. fi
  61. args="${args} via ${GATEWAY}"
  62. fi
  63. if [ -n "${SOURCE}" ]; then
  64. args="${args} src ${SOURCE}"
  65. fi
  66. case "${2}" in
  67. up)
  68. boot_mesg "Adding '${desc}' route to the ${1} interface..."
  69. ip route add ${args} dev ${1}
  70. evaluate_retval
  71. ;;
  72. down)
  73. boot_mesg "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 $network_devices/services/ipv4-static-route