]> git.ipfire.org Git - people/stevee/network.git/blame - header-zone
network: Handle pppd ip-up and ip-down events sober in hook.
[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
138 if ! hook_exists ${hook_zone}; then
139 error "Hook '${hook}' does not exist."
140 exit ${EXIT_ERROR}
141 fi
142
143 if ! hook_port_exists ${hook_zone} ${hook_port}; then
144 error "Hook '${hook_port}' is not supported for zone '${zone}'."
145 exit ${EXIT_ERROR}
146 fi
147
148 hook_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} $@
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
197 if ! hook_exists ${hook_zone}; then
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
207 hook_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} $@
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
MT
226# These tree functions exit silently
227function _ppp-ip-pre-up() {
228 exit ${EXIT_OK}
229}
230
231function _ppp-ip-up() {
232 exit ${EXIT_OK}
233}
234
235function _ppp-ip-down() {
236 exit ${EXIT_OK}
237}
238
1848564d
MT
239function run() {
240 case "${action}" in
241 create|discover|down|edit|info|rem|status|up)
242 _${action} $@
243 ;;
244
245 port)
246 if ! hook_has_ports ${HOOK}; then
247 error "Hook '${HOOK}' does not support ports."
248 exit ${EXIT_ERROR}
249 fi
250
251 _port $@
252 ;;
253
254 config)
255 if ! hook_has_configs ${HOOK}; then
256 error "Hook '${HOOK}' does not support configurations."
257 exit ${EXIT_ERROR}
258 fi
259
260 _config $@
261 ;;
262
b4038eca
MT
263 ppp-ip-pre-up|ppp-ip-up|ppp-ip-down)
264 _${action} $@
265 ;;
266
1848564d
MT
267 esac
268
269 error "Hook did not exit properly."
270 exit ${EXIT_ERROR}
271}