]>
Commit | Line | Data |
---|---|---|
bfd77eaf MT |
1 | #!/bin/bash |
2 | ||
3 | . /etc/sysconfig/rc | |
4 | . ${rc_functions} | |
5 | ||
6 | ||
7 | function init_table() { | |
8 | # Check if table does already exist. If not we add it. | |
aba9ac59 | 9 | if (ip rule | grep -q "static" >/dev/null 2>&1); then |
bfd77eaf MT |
10 | return |
11 | fi | |
12 | ||
13 | ip rule add table static | |
14 | } | |
15 | ||
aba9ac59 MT |
16 | function create_all_routes() { |
17 | local file=${1} | |
18 | shift | |
19 | ||
20 | # Remote all routes. | |
21 | ip route flush table static >/dev/null 2>&1 | |
22 | ||
23 | local status | |
24 | local network | |
25 | local gateway | |
26 | local remark | |
27 | ||
28 | # Read all routes from the configuration file and add the enabled ones | |
29 | # immediately. | |
30 | while IFS=, read status network gateway remark; do | |
31 | [ "${status}" = "on" ] || continue | |
32 | ||
33 | if [ -z "${network}" -o -z "${gateway}" ]; then | |
34 | # Silently skipping invalid routes. | |
35 | continue | |
36 | fi | |
37 | ||
5d2c8f5d | 38 | ip route add ${network} via ${gateway} table static proto static |
aba9ac59 MT |
39 | done < ${file} |
40 | } | |
41 | ||
42 | CONFIGFILE="/var/ipfire/main/routing" | |
bfd77eaf MT |
43 | |
44 | case "${1}" in | |
45 | start) | |
aba9ac59 | 46 | boot_mesg "Adding static routes..." |
bfd77eaf MT |
47 | |
48 | # First, initialize the table | |
aba9ac59 | 49 | init_table |
bfd77eaf | 50 | |
aba9ac59 MT |
51 | # Add all routes |
52 | create_all_routes ${CONFIGFILE} | |
bfd77eaf MT |
53 | |
54 | evaluate_retval | |
aba9ac59 | 55 | ;; |
bfd77eaf | 56 | |
aba9ac59 MT |
57 | stop) |
58 | boot_mesg "Removing static routes..." | |
59 | ip route flush table static >/dev/null 2>&1 | |
bfd77eaf | 60 | evaluate_retval |
aba9ac59 | 61 | ;; |
bfd77eaf | 62 | |
aba9ac59 MT |
63 | *) |
64 | echo "Usage: ${0} {start|stop}" | |
65 | exit 1 | |
66 | ;; | |
bfd77eaf | 67 | esac |