]> git.ipfire.org Git - ipfire-2.x.git/blame - src/initscripts/system/static-routes
suricata: Change midstream policy to "pass-flow"
[ipfire-2.x.git] / src / initscripts / system / static-routes
CommitLineData
bfd77eaf 1#!/bin/bash
66c36198
PM
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###############################################################################
bfd77eaf
MT
21
22. /etc/sysconfig/rc
23. ${rc_functions}
24
25
26function init_table() {
27 # Check if table does already exist. If not we add it.
aba9ac59 28 if (ip rule | grep -q "static" >/dev/null 2>&1); then
bfd77eaf
MT
29 return
30 fi
31
32 ip rule add table static
33}
34
aba9ac59
MT
35function 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
5d2c8f5d 57 ip route add ${network} via ${gateway} table static proto static
aba9ac59
MT
58 done < ${file}
59}
60
61CONFIGFILE="/var/ipfire/main/routing"
bfd77eaf
MT
62
63case "${1}" in
b8fdc739 64 start|reload)
aba9ac59 65 boot_mesg "Adding static routes..."
bfd77eaf
MT
66
67 # First, initialize the table
aba9ac59 68 init_table
bfd77eaf 69
aba9ac59
MT
70 # Add all routes
71 create_all_routes ${CONFIGFILE}
bfd77eaf
MT
72
73 evaluate_retval
aba9ac59 74 ;;
bfd77eaf 75
aba9ac59
MT
76 stop)
77 boot_mesg "Removing static routes..."
78 ip route flush table static >/dev/null 2>&1
bfd77eaf 79 evaluate_retval
aba9ac59 80 ;;
bfd77eaf 81
aba9ac59 82 *)
b8fdc739 83 echo "Usage: ${0} {start|stop|reload}"
aba9ac59
MT
84 exit 1
85 ;;
bfd77eaf 86esac