]>
Commit | Line | Data |
---|---|---|
ff8ec5ef MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2010 Michael Tremer & Christian Schmidt # | |
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 | function routing_has_default() { | |
23 | ip route | grep -q "^default" | |
24 | } | |
25 | ||
26 | function routing_default_update() { | |
27 | local zone | |
28 | local routes | |
29 | ||
30 | local gateway | |
31 | local weight | |
32 | ||
33 | log INFO "Updating default route." | |
34 | ||
35 | for zone in $(zones_get_nonlocal); do | |
36 | # Skip if zone is not up | |
37 | red_db_exists ${zone} || continue | |
38 | ||
39 | if [ "$(red_db_get ${zone} active)" = "1" ]; then | |
40 | gateway=$(red_db_get ${zone} remote-ip-address) | |
41 | weight=$(red_db_get ${zone} weight) | |
42 | ||
43 | routes="${routes} nexthop via ${gateway}" | |
44 | ||
45 | if [ -n "${weight}" ]; then | |
46 | routes="${routes} weight ${weight}" | |
47 | fi | |
48 | else | |
49 | log DEBUG "Ignoring zone '${zone}' which is not active." | |
50 | fi | |
51 | done | |
52 | ||
53 | if [ -z "${routes}" ]; then | |
54 | if routing_has_default; then | |
55 | ip route del default | |
56 | fi | |
57 | return ${EXIT_OK} | |
58 | fi | |
59 | ||
60 | ip route replace default ${routes} | |
61 | } | |
62 | ||
63 | function routing_table_exists() { | |
64 | local zone=${1} | |
65 | ||
66 | grep -q "${zone}$" < /etc/iproute2/rt_tables | |
67 | } | |
68 | ||
69 | function routing_table_create() { | |
70 | local zone=${1} | |
71 | ||
72 | if ! zone_is_nonlocal ${zone}; then | |
73 | error_log "Can only create routing tables for non-local zones." | |
74 | return ${EXIT_ERROR} | |
75 | fi | |
76 | ||
77 | if routing_table_exists ${zone}; then | |
78 | return ${EXIT_OK} | |
79 | fi | |
80 | ||
81 | log INFO "Creating routing table for zone '${zone}'" | |
82 | ||
83 | local id=$(( ${zone#red} + 1 )) | |
84 | ||
85 | echo "${id} ${zone}" >> /etc/iproute2/rt_tables | |
86 | } | |
87 | ||
88 | function routing_table_remove() { | |
89 | : # XXX do we need this? | |
90 | } |