]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/system/static-routes
suricata: Change midstream policy to "pass-flow"
[ipfire-2.x.git] / src / initscripts / system / static-routes
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 . /etc/sysconfig/rc
23 . ${rc_functions}
24
25
26 function init_table() {
27 # Check if table does already exist. If not we add it.
28 if (ip rule | grep -q "static" >/dev/null 2>&1); then
29 return
30 fi
31
32 ip rule add table static
33 }
34
35 function create_all_routes() {
36 local file=${1}
37 shift
38
39 # Remote all routes.
40 ip route flush table static >/dev/null 2>&1
41
42 local status
43 local network
44 local gateway
45 local remark
46
47 # Read all routes from the configuration file and add the enabled ones
48 # immediately.
49 while IFS=, read status network gateway remark; do
50 [ "${status}" = "on" ] || continue
51
52 if [ -z "${network}" -o -z "${gateway}" ]; then
53 # Silently skipping invalid routes.
54 continue
55 fi
56
57 ip route add ${network} via ${gateway} table static proto static
58 done < ${file}
59 }
60
61 CONFIGFILE="/var/ipfire/main/routing"
62
63 case "${1}" in
64 start|reload)
65 boot_mesg "Adding static routes..."
66
67 # First, initialize the table
68 init_table
69
70 # Add all routes
71 create_all_routes ${CONFIGFILE}
72
73 evaluate_retval
74 ;;
75
76 stop)
77 boot_mesg "Removing static routes..."
78 ip route flush table static >/dev/null 2>&1
79 evaluate_retval
80 ;;
81
82 *)
83 echo "Usage: ${0} {start|stop|reload}"
84 exit 1
85 ;;
86 esac