]> git.ipfire.org Git - people/ms/network.git/blame - hooks/bridge
network: ipv4-static: Set gateway only on nonlocal connections.
[people/ms/network.git] / hooks / bridge
CommitLineData
1848564d
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. /lib/network/header-zone
23
24HOOK_SETTINGS="HOOK STP STP_FORWARD_DELAY STP_HELLO STP_MAXAGE MAC MTU"
25
26# Default values
27MAC=$(mac_generate)
28MTU=1500
29STP="on"
30STP_FORWARD_DELAY=0
31STP_HELLO=2
32STP_MAXAGE=20
33
34function _check() {
35 assert ismac MAC
36 assert isbool STP
37 assert isinteger STP_HELLO
38 assert isinteger STP_FORWARD_DELAY
39 assert isinteger MTU
40}
41
42function _parse_cmdline() {
43 while [ $# -gt 0 ]; do
44 case "${1}" in
45 --stp=*)
46 STP=${1#--stp=}
47 ;;
48 --stp-hello=*)
49 STP_HELLO=${1#--stp-hello=}
50 ;;
51 --stp-forward-delay=*)
52 STP_FORWARD_DELAY=${1#--stp-forward-delay=}
53 ;;
54 --mtu=*)
55 MTU=${1#--mtu=}
56 ;;
57 --mac=*)
58 MAC=${1#--mac=}
59 ;;
60 *)
61 warning "Ignoring unknown option '${1}'"
62 ;;
63 esac
64 shift
65 done
66}
67
68function _up() {
69 local zone=${1}
70 shift
71
72 config_read ${ZONE_DIR}/${zone}/settings
73
74 if ! device_exists ${zone}; then
75 brctl addbr ${zone}
76 fi
77
7cbea20d 78 [ -n "${MAC}" ] && device_set_address ${zone} ${MAC}
1848564d
MT
79 [ -n "${MTU}" ] && device_set_mtu ${zone} ${MTU}
80
81 # Enable STP
82 if enabled STP; then
83 brctl stp ${zone} on
84
85 if [ -n "${STP_FORWARD_DELAY}" ]; then
86 brctl setfd ${zone} ${STP_FORWARD_DELAY}
87 fi
88
89 if [ -n "${STP_HELLO}" ]; then
90 brctl sethello ${zone} ${STP_HELLO}
91 fi
92
93 if [ -n "${STP_MAXAGE}" ]; then
94 brctl setmaxage ${zone} ${STP_MAXAGE}
95 fi
96 else
97 brctl stp ${zone} off
98 fi
99
100 device_set_up ${zone}
101
102 # Bring all ports up
103 zone_ports_up ${zone}
104
105 # XXX Do we need this?
106 # Wait until bridge is forwarding
107 # which is needed by dhcp client
108 #if enabled STP; then
109 # bridge_is_forwarding ${zone}
110 #fi
111
112 zone_configs_up ${zone}
113
114 event_interface_up ${zone}
115
116 exit $?
117}
118
119function _down() {
120 local zone=${1}
121 shift
122
123 if ! device_is_up ${zone}; then
124 warning "Zone '${zone}' is not up"
125 exit ${EXIT_OK}
126 fi
127
128 event_interface_down ${zone}
129
130 zone_configs_down ${zone}
131 zone_ports_down ${zone}
132
133 device_set_down ${zone}
134 brctl delbr ${zone}
135
136 exit $?
137}
138
139function _addport() {
140 local zone=${1}
141 local hook=${2}
142 shift 2
143
144 if ! hook_exists port ${hook}; then
145 error "Hook does not exist '${hook}'"
146 exit ${EXIT_ERROR}
147 fi
148
149 port_hook ${hook} add ${zone}
150}
151
152run $@