]> git.ipfire.org Git - people/stevee/network.git/blame - header-zone
netwrk: Remove unused function.
[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
e5f78859 63 config_read $(zone_dir ${zone})/settings
1848564d
MT
64
65 _parse_cmdline $@
66
e5f78859 67 config_write $(zone_dir ${zone})/settings ${HOOK_SETTINGS}
1848564d
MT
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
e5f78859 116 add|create|edit|rem|show)
1848564d
MT
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
e5f78859
MT
129function _port_add() {
130 _port_cmd add $@
131}
132
133function _port_edit() {
134 _port_cmd edit $@
135}
136
137function _port_rem() {
138 _port_cmd rem $@
139}
140
141function _port_show() {
142 _notimplemented _port_show
143}
144
145function _port_status() {
146 _port_cmd status $@
147}
148
149function _port_cmd() {
1848564d
MT
150 local cmd=${1}
151 local zone=${2}
e5f78859 152 local port=${3}
1848564d
MT
153 shift 3
154
e5f78859
MT
155 assert isset cmd
156 assert isset zone
157 assert isset port
158
1848564d 159 local hook_zone=$(zone_get_hook ${zone})
e5f78859 160 local hook_port=$(port_get_hook ${port})
1848564d 161
e5f78859
MT
162 assert isset hook_zone
163 assert isset hook_port
1848564d 164
e5f78859
MT
165 if ! listmatch ${hook_port} $(zone_get_supported_hooks ${zone}); then
166 error_log "Zone '${zone}' does not support port of type '${hook_port}'."
1848564d
MT
167 exit ${EXIT_ERROR}
168 fi
169
e5f78859 170 hook_zone_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
1848564d 171
e5f78859 172 exit $?
1848564d
MT
173}
174
e5f78859
MT
175function _port_up() {
176 _port_cmd up $@
1848564d
MT
177}
178
e5f78859
MT
179function _port_down() {
180 _port_cmd down $@
1848564d
MT
181}
182
183function _config() {
184 local zone=${1}
185 local action=${2}
186 shift 2
187
188 local ret
189
190 case "${action}" in
191 create|edit|rem|show)
192 _config_${action} ${zone} $@
193 ret=$?
194 ;;
195 *)
196 error "Unrecognized argument: '${action}'"
197 exit ${EXIT_ERROR}
198 ;;
199 esac
200
201 exit ${ret}
202}
203
204# This function is not a public one
205function __configcmd() {
206 local cmd=${1}
207 local zone=${2}
208 local hook_config=${3}
209 shift 3
210
211 local hook_zone=$(zone_get_hook ${zone})
212
d61a01d4 213 if ! hook_zone_exists ${hook_zone}; then
1848564d
MT
214 error "Hook '${hook}' does not exist."
215 exit ${EXIT_ERROR}
216 fi
217
218 if ! hook_config_exists ${hook_zone} ${hook_config}; then
219 error "Hook '${hook_config}' is not supported for zone '${zone}'."
220 exit ${EXIT_ERROR}
221 fi
222
d61a01d4 223 hook_zone_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} $@
1848564d
MT
224}
225
226function _config_create() {
227 __configcmd create $@
228}
229
230function _config_edit() {
231 __configcmd edit $@
232}
233
234function _config_rem() {
235 _notimplemented _config_rem
236}
237
238function _config_show() {
239 _notimplemented _config_show
240}
241
b4038eca 242function _ppp-ip-pre-up() {
c7ad7801
MT
243 local zone=${1}
244 shift
245
246 if ! zone_exists ${zone}; then
247 error "Zone '${zone}' does not exist."
248 exit ${EXIT_ERROR}
249 fi
250
251 ppp_common_ip_pre_up ${zone} $@
252
253 exit $?
b4038eca
MT
254}
255
256function _ppp-ip-up() {
c7ad7801
MT
257 local zone=${1}
258 shift
259
260 if ! zone_exists ${zone}; then
261 error "Zone '${zone}' does not exist."
262 exit ${EXIT_ERROR}
263 fi
264
265 ppp_common_ip_up ${zone} $@
266
267 exit $?
b4038eca
MT
268}
269
270function _ppp-ip-down() {
c7ad7801
MT
271 local zone=${1}
272 shift
273
274 if ! zone_exists ${zone}; then
275 error "Zone '${zone}' does not exist."
276 exit ${EXIT_ERROR}
277 fi
278
279 ppp_common_ip_down ${zone} $@
280
281 exit $?
b4038eca
MT
282}
283
1848564d 284function run() {
e5f78859
MT
285 # Replace all dashes by an underscore
286 #action=${action//-/_}
287
1848564d 288 case "${action}" in
e5f78859 289 create|discover|down|edit|info|rem|status|up|port_add|port_rem|port_up|port_down|port_status)
1848564d
MT
290 _${action} $@
291 ;;
292
293 port)
d61a01d4 294 if ! hook_zone_has_ports ${HOOK}; then
1848564d
MT
295 error "Hook '${HOOK}' does not support ports."
296 exit ${EXIT_ERROR}
297 fi
298
299 _port $@
300 ;;
301
302 config)
d61a01d4 303 if ! hook_zone_has_configs ${HOOK}; then
1848564d
MT
304 error "Hook '${HOOK}' does not support configurations."
305 exit ${EXIT_ERROR}
306 fi
307
308 _config $@
309 ;;
310
b4038eca
MT
311 ppp-ip-pre-up|ppp-ip-up|ppp-ip-down)
312 _${action} $@
313 ;;
314
1848564d
MT
315 esac
316
317 error "Hook did not exit properly."
318 exit ${EXIT_ERROR}
319}