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 |
|
---|
15 | . /lib/lsb/init-functions
|
---|
16 | . ${IFCONFIG}
|
---|
17 |
|
---|
18 | case "${TYPE}" in
|
---|
19 | ("" | "network")
|
---|
20 | need_ip=1
|
---|
21 | need_gateway=1
|
---|
22 | ;;
|
---|
23 |
|
---|
24 | ("default")
|
---|
25 | need_gateway=1
|
---|
26 | args="${args} default"
|
---|
27 | desc="default"
|
---|
28 | ;;
|
---|
29 |
|
---|
30 | ("host")
|
---|
31 | need_ip=1
|
---|
32 | ;;
|
---|
33 |
|
---|
34 | ("unreachable")
|
---|
35 | need_ip=1
|
---|
36 | args="${args} unreachable"
|
---|
37 | desc="unreachable "
|
---|
38 | ;;
|
---|
39 |
|
---|
40 | (*)
|
---|
41 | log_failure_msg "Unknown route type (${TYPE}) in ${IFCONFIG}, cannot continue."
|
---|
42 | exit 1
|
---|
43 | ;;
|
---|
44 | esac
|
---|
45 |
|
---|
46 | if [ -n "${GATEWAY}" ]; then
|
---|
47 | MSG="The GATEWAY variable cannot be set in ${IFCONFIG} for static routes.\n"
|
---|
48 | log_failure_msg "$MSG Use STATIC_GATEWAY only, cannot continue"
|
---|
49 | exit 1
|
---|
50 | fi
|
---|
51 |
|
---|
52 | if [ -n "${need_ip}" ]; then
|
---|
53 | if [ -z "${IP}" ]; then
|
---|
54 | log_failure_msg "IP variable missing from ${IFCONFIG}, cannot continue."
|
---|
55 | exit 1
|
---|
56 | fi
|
---|
57 |
|
---|
58 | if [ -z "${PREFIX}" ]; then
|
---|
59 | log_failure_msg "PREFIX variable missing from ${IFCONFIG}, cannot continue."
|
---|
60 | exit 1
|
---|
61 | fi
|
---|
62 |
|
---|
63 | args="${args} ${IP}/${PREFIX}"
|
---|
64 | desc="${desc}${IP}/${PREFIX}"
|
---|
65 | fi
|
---|
66 |
|
---|
67 | if [ -n "${need_gateway}" ]; then
|
---|
68 | if [ -z "${STATIC_GATEWAY}" ]; then
|
---|
69 | log_failure_msg "STATIC_GATEWAY variable missing from ${IFCONFIG}, cannot continue."
|
---|
70 | exit 1
|
---|
71 | fi
|
---|
72 | args="${args} via ${STATIC_GATEWAY}"
|
---|
73 | fi
|
---|
74 |
|
---|
75 | if [ -n "${SOURCE}" ]; then
|
---|
76 | args="${args} src ${SOURCE}"
|
---|
77 | fi
|
---|
78 |
|
---|
79 | case "${2}" in
|
---|
80 | up)
|
---|
81 | log_info_msg "Adding '${desc}' route to the ${1} interface..."
|
---|
82 | ip route add ${args} dev ${1}
|
---|
83 | evaluate_retval
|
---|
84 | ;;
|
---|
85 |
|
---|
86 | down)
|
---|
87 | log_info_msg "Removing '${desc}' route from the ${1} interface..."
|
---|
88 | ip route del ${args} dev ${1}
|
---|
89 | evaluate_retval
|
---|
90 | ;;
|
---|
91 |
|
---|
92 | *)
|
---|
93 | echo "Usage: ${0} [interface] {up|down}"
|
---|
94 | exit 1
|
---|
95 | ;;
|
---|
96 | esac
|
---|
97 |
|
---|
98 | # End /lib/services/ipv4-static-route
|
---|