ipv4-static-route 2.0 KB

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