]> git.ipfire.org Git - people/stevee/network.git/blame - header-zone
network: Initialize bonding at start.
[people/stevee/network.git] / header-zone
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# Notes:
23# - All functions in this scope must start with an underline (_) to not
24# conflict with any functions that were defined somewhere else.
25#
26
27. /lib/network/functions
28
29HOOK=$(basename ${0})
30
31while [ $# -gt 0 ]; do
32 case "${1}" in
33 -*)
34 error "Unrecognized option: ${1}"
35 exit ${EXIT_ERROR}
36 ;;
37 *)
38 action=${1}
39 ;;
40 esac
41 shift
42
43 # If action argument was given, we will exit.
44 [ -n "${action}" ] && break
45done
46
47# _notimplemented
48# Returns a soft error if a function was not implemented, yet.
49#
50function _notimplemented() {
51 warning "'$@' was not implemented."
52 exit ${EXIT_CONF_ERROR}
53}
54
55function _info() {
56 echo "HOOK=\"${HOOK}\""
57}
58
59function _create() {
60 local zone=${1}
61 shift
62
63 config_read ${ZONE_DIR}/${zone}/settings
64
65 _parse_cmdline $@
66
67 config_write ${ZONE_DIR}/${zone}/settings ${HOOK_SETTINGS}
68
69 exit ${EXIT_OK}
70}
71
72function _edit() {
73 _create $@
74}
75
76function _rem() {
77 _notimplemented _rem
78}
79
80function _status() {
81 local zone=${1}
82
83 if device_is_up ${zone}; then
84 exit ${STATUS_UP}
85 fi
86
87 exit ${STATUS_DOWN}
88}
89
90function _up() {
91 _notimplemented _up
92}
93
94function _down() {
95 _notimplemented _down
96}
97
98function _discover() {
99 # This hook does not support a discovery
100 exit ${DISCOVER_NOT_SUPPORTED}
101}
102
103# Do nothing
104function _parse_cmdline() {
105 return ${EXIT_OK}
106}
107
108function _port() {
109 local zone=${1}
110 local action=${2}
111 shift 2
112
113 local ret
114
115 case "${action}" in
116 create|edit|rem|show)
117 _port_${action} ${zone} $@
118 ret=$?
119 ;;
120 *)
121 error "Unrecognized argument: '${action}'"
122 exit ${EXIT_ERROR}
123 ;;
124 esac
125
126 exit ${ret}
127}
128
129# This function is not a public one
130function __portcmd() {
131 local cmd=${1}
132 local zone=${2}
133 local hook_port=${3}
134 shift 3
135
136 local hook_zone=$(zone_get_hook ${zone})
137
d61a01d4 138 if ! hook_zone_exists ${hook_zone}; then
1848564d
MT
139 error "Hook '${hook}' does not exist."
140 exit ${EXIT_ERROR}
141 fi
142
d61a01d4 143 if ! hook_zone_port_exists ${hook_zone} ${hook_port}; then
1848564d
MT
144 error "Hook '${hook_port}' is not supported for zone '${zone}'."
145 exit ${EXIT_ERROR}
146 fi
147
d61a01d4 148 hook_zone_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} $@
1848564d
MT
149}
150
151function _port_create() {
152 __portcmd create $@
153}
154
155function _port_edit() {
156 __portcmd edit $@
157}
158
159function _port_rem() {
160 _notimplemented _port_rem
161}
162
163function _port_show() {
164 _notimplemented _port_show
165}
166
167function _config() {
168 local zone=${1}
169 local action=${2}
170 shift 2
171
172 local ret
173
174 case "${action}" in
175 create|edit|rem|show)
176 _config_${action} ${zone} $@
177 ret=$?
178 ;;
179 *)
180 error "Unrecognized argument: '${action}'"
181 exit ${EXIT_ERROR}
182 ;;
183 esac
184
185 exit ${ret}
186}
187
188# This function is not a public one
189function __configcmd() {
190 local cmd=${1}
191 local zone=${2}
192 local hook_config=${3}
193 shift 3
194
195 local hook_zone=$(zone_get_hook ${zone})
196
d61a01d4 197 if ! hook_zone_exists ${hook_zone}; then
1848564d
MT
198 error "Hook '${hook}' does not exist."
199 exit ${EXIT_ERROR}
200 fi
201
202 if ! hook_config_exists ${hook_zone} ${hook_config}; then
203 error "Hook '${hook_config}' is not supported for zone '${zone}'."
204 exit ${EXIT_ERROR}
205 fi
206
d61a01d4 207 hook_zone_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} $@
1848564d
MT
208}
209
210function _config_create() {
211 __configcmd create $@
212}
213
214function _config_edit() {
215 __configcmd edit $@
216}
217
218function _config_rem() {
219 _notimplemented _config_rem
220}
221
222function _config_show() {
223 _notimplemented _config_show
224}
225
b4038eca 226function _ppp-ip-pre-up() {
c7ad7801
MT
227 local zone=${1}
228 shift
229
230 if ! zone_exists ${zone}; then
231 error "Zone '${zone}' does not exist."
232 exit ${EXIT_ERROR}
233 fi
234
235 ppp_common_ip_pre_up ${zone} $@
236
237 exit $?
b4038eca
MT
238}
239
240function _ppp-ip-up() {
c7ad7801
MT
241 local zone=${1}
242 shift
243
244 if ! zone_exists ${zone}; then
245 error "Zone '${zone}' does not exist."
246 exit ${EXIT_ERROR}
247 fi
248
249 ppp_common_ip_up ${zone} $@
250
251 exit $?
b4038eca
MT
252}
253
254function _ppp-ip-down() {
c7ad7801
MT
255 local zone=${1}
256 shift
257
258 if ! zone_exists ${zone}; then
259 error "Zone '${zone}' does not exist."
260 exit ${EXIT_ERROR}
261 fi
262
263 ppp_common_ip_down ${zone} $@
264
265 exit $?
b4038eca
MT
266}
267
1848564d
MT
268function run() {
269 case "${action}" in
270 create|discover|down|edit|info|rem|status|up)
271 _${action} $@
272 ;;
273
274 port)
d61a01d4 275 if ! hook_zone_has_ports ${HOOK}; then
1848564d
MT
276 error "Hook '${HOOK}' does not support ports."
277 exit ${EXIT_ERROR}
278 fi
279
280 _port $@
281 ;;
282
283 config)
d61a01d4 284 if ! hook_zone_has_configs ${HOOK}; then
1848564d
MT
285 error "Hook '${HOOK}' does not support configurations."
286 exit ${EXIT_ERROR}
287 fi
288
289 _config $@
290 ;;
291
b4038eca
MT
292 ppp-ip-pre-up|ppp-ip-up|ppp-ip-down)
293 _${action} $@
294 ;;
295
1848564d
MT
296 esac
297
298 error "Hook did not exit properly."
299 exit ${EXIT_ERROR}
300}