]>
git.ipfire.org Git - people/arne_f/network.git/blob - functions.routing
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
22 function routing_has_default
() {
23 ip route |
grep -q "^default"
26 function routing_default_update
() {
33 log INFO
"Updating default route."
35 for zone
in $
(zones_get_nonlocal
); do
36 # Skip if zone is not up
37 red_db_exists
${zone} ||
continue
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
)
43 routes
="${routes} nexthop via ${gateway}"
45 if [ -n "${weight}" ]; then
46 routes
="${routes} weight ${weight}"
49 log DEBUG
"Ignoring zone '${zone}' which is not active."
53 if [ -z "${routes}" ]; then
54 if routing_has_default
; then
60 ip route replace default
${routes}
63 function routing_table_exists
() {
66 grep -q "${zone}$" < /etc
/iproute
2/rt_tables
69 function routing_table_create
() {
72 if ! zone_is_nonlocal
${zone}; then
73 error_log
"Can only create routing tables for non-local zones."
77 if routing_table_exists
${zone}; then
81 log INFO
"Creating routing table for zone '${zone}'"
83 local id
=$
(( ${zone#red} + 1 ))
85 echo "${id} ${zone}" >> /etc
/iproute
2/rt_tables
88 function routing_table_remove
() {
89 : # XXX do we need this?