]> git.ipfire.org Git - network.git/blame - src/header-zone
ipv4-static: create hook_parse_cmdline function
[network.git] / src / 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###############################################################################
1848564d 21
1c6a4e30 22hook_info() {
1848564d
MT
23 echo "HOOK=\"${HOOK}\""
24}
25
1c6a4e30 26hook_hotplug() {
2a969c27
MT
27 # If the hook does not handle the hotplug event, it
28 # must return EXIT_NOT_HANDLED.
29 exit ${EXIT_NOT_HANDLED}
30}
31
1c6a4e30 32hook_new() {
2181765d
MT
33 local zone="${1}"
34 assert isset zone
1848564d
MT
35 shift
36
1e6f187e 37 zone_settings_read "${zone}"
1848564d 38
2181765d 39 hook_parse_cmdline $@
1848564d 40
1e6f187e 41 zone_settings_write "${zone}"
1848564d
MT
42
43 exit ${EXIT_OK}
44}
45
1c6a4e30 46hook_edit() {
1e6f187e 47 hook_new $@
1848564d
MT
48}
49
1c6a4e30 50hook_remove() {
2181765d 51 cmd_not_implemented
1848564d
MT
52}
53
1c6a4e30 54hook_status() {
2181765d
MT
55 local zone="${1}"
56 assert isset zone
1848564d
MT
57
58 if device_is_up ${zone}; then
59 exit ${STATUS_UP}
60 fi
61
62 exit ${STATUS_DOWN}
63}
64
1c6a4e30 65hook_up() {
2181765d 66 cmd_not_implemented
1848564d
MT
67}
68
1c6a4e30 69hook_down() {
2181765d 70 cmd_not_implemented
1848564d
MT
71}
72
1c6a4e30 73hook_discover() {
1848564d
MT
74 # This hook does not support a discovery
75 exit ${DISCOVER_NOT_SUPPORTED}
76}
77
78# Do nothing
1c6a4e30 79hook_parse_cmdline() {
1848564d
MT
80 return ${EXIT_OK}
81}
82
1c6a4e30 83hook_port() {
2181765d
MT
84 local zone="${1}"
85 assert isset zone
86
87 local action="${2}"
1848564d
MT
88 shift 2
89
90 local ret
1848564d 91 case "${action}" in
e5f78859 92 add|create|edit|rem|show)
2181765d 93 hook_port_${action} "${zone}" $@
1848564d
MT
94 ret=$?
95 ;;
96 *)
97 error "Unrecognized argument: '${action}'"
98 exit ${EXIT_ERROR}
99 ;;
100 esac
101
102 exit ${ret}
103}
104
1c6a4e30 105hook_port_attach() {
828eb94a 106 return ${EXIT_NOT_SUPPORTED}
e5f78859
MT
107}
108
1c6a4e30 109hook_port_detach() {
828eb94a 110 return ${EXIT_NOT_SUPPORTED}
e5f78859
MT
111}
112
1c6a4e30 113hook_port_edit() {
828eb94a 114 return ${EXIT_NOT_SUPPORTED}
e5f78859
MT
115}
116
1c6a4e30 117hook_port_status() {
828eb94a 118 return ${EXIT_NOT_SUPPORTED}
1848564d
MT
119}
120
1c6a4e30 121hook_default_port_create() {
1ba6a2bb
MT
122 assert [ $# -ge 2 ]
123
124 local zone="${1}"
125 local port="${2}"
126
127 port_create "${port}"
128}
129
1c6a4e30 130hook_port_create() {
1ba6a2bb
MT
131 hook_default_port_create $@
132}
133
1c6a4e30 134hook_default_port_remove() {
1ba6a2bb
MT
135 assert [ $# -ge 2 ]
136
137 local zone="${1}"
138 local port="${2}"
139
140 port_remove "${port}"
141}
142
1c6a4e30 143hook_port_remove() {
1ba6a2bb
MT
144 hook_default_port_remove $@
145}
146
1c6a4e30 147hook_port_up() {
828eb94a 148 cmd_not_implemented
1848564d
MT
149}
150
1c6a4e30 151hook_port_down() {
828eb94a 152 cmd_not_implemented
1848564d
MT
153}
154
1c6a4e30 155hook_config() {
2181765d
MT
156 local zone="${1}"
157 assert isset zone
158
159 local action="${2}"
160 assert isset action
1848564d
MT
161 shift 2
162
163 local ret
1848564d 164 case "${action}" in
2a6b2397 165 new|destroy|edit|show)
2181765d
MT
166 hook_config_${action} "${zone}" "$@"
167 exit $?
1848564d
MT
168 ;;
169 *)
170 error "Unrecognized argument: '${action}'"
171 exit ${EXIT_ERROR}
172 ;;
173 esac
1848564d
MT
174}
175
1c6a4e30 176hook_config_cmd() {
2181765d
MT
177 local cmd="${1}"
178 assert isset cmd
1848564d 179
2181765d
MT
180 local zone="${2}"
181 assert isset zone
1848564d 182
2181765d
MT
183 local hook_config="${3}"
184 assert isset hook_config
185
186 shift 3
187
188 local hook_zone="$(zone_get_hook "${zone}")"
189 if ! hook_zone_exists "${hook_zone}"; then
190 log ERROR "Hook '${hook}' does not exist."
1848564d
MT
191 exit ${EXIT_ERROR}
192 fi
193
ea699552
MT
194 #if ! hook_config_exists "${hook_zone}" "${hook_config}"; then
195 # log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'."
196 # exit ${EXIT_ERROR}
197 #fi
1848564d 198
ea699552 199 hook_config_exec "${hook_config}" "${cmd}" "${zone}" "$@"
1848564d
MT
200}
201
2a6b2397 202hook_config_new() {
51492358 203 assert [ $# -ge 2 ]
a5ebb169 204
2a6b2397 205 hook_config_cmd "new" "$@"
1848564d
MT
206}
207
2a6b2397 208hook_config_destroy() {
6002aef1
JS
209 assert [ $# -eq 2 ]
210 local zone=${1}
211 # The id must be the id and not the hid.
212 local id=${2}
213
214 shift 2
215
216 # Check if we get a valid id
217 if ! zone_config_id_is_valid ${zone} ${id}; then
218 log ERROR "ID: ${id} is not a valid id for zone ${zone}"
219 fi
220
221 local hook=$(zone_config_get_hook_from_id ${zone} ${id})
222 assert isset hook
223
224 hook_config_cmd "destroy" "${zone}" "${hook}" "${hook}.${id}" "$@"
1848564d
MT
225}
226
2a6b2397 227hook_config_edit() {
15be9d69 228 assert [ $# -ge 2 ]
9ee04d82
JS
229 local zone=${1}
230 # The id must be the id and not the hid.
231 local id=${2}
232
233 shift 2
234
235 # Check if we get a valid id
236 if ! zone_config_id_is_valid ${zone} ${id}; then
237 log ERROR "ID: ${id} is not a valid id for zone ${zone}"
238 fi
239
240 local hook=$(zone_config_get_hook_from_id ${zone} ${id})
241 assert isset hook
242
243 hook_config_cmd "edit" "${zone}" "${hook}" "${hook}.${id}" "$@"
1848564d
MT
244}
245
1c6a4e30 246hook_config_show() {
2181765d 247 cmd_not_implemented
1848564d
MT
248}
249
1c6a4e30 250hook_ppp_write_config() {
2181765d 251 cmd_not_implemented
97cb552e
MT
252
253 # Arguments: <zone> <filename>
254}
255
1c6a4e30 256hook_ppp_ip_pre_up() {
2181765d
MT
257 local zone="${1}"
258 assert isset zone
c7ad7801
MT
259 shift
260
2181765d
MT
261 if ! zone_exists "${zone}"; then
262 log ERROR "Zone '${zone}' does not exist."
c7ad7801
MT
263 exit ${EXIT_ERROR}
264 fi
265
2181765d 266 ppp_common_ip_pre_up "${zone}" "$@"
c7ad7801 267 exit $?
b4038eca
MT
268}
269
1c6a4e30 270hook_ppp_ipv4_up() {
2181765d
MT
271 local zone="${1}"
272 assert isset zone
c7ad7801
MT
273 shift
274
2181765d
MT
275 if ! zone_exists "${zone}"; then
276 log ERROR "Zone '${zone}' does not exist."
c7ad7801
MT
277 exit ${EXIT_ERROR}
278 fi
279
2181765d 280 ppp_common_ipv4_up "${zone}" "$@"
c7ad7801 281 exit $?
b4038eca
MT
282}
283
1c6a4e30 284hook_ppp_ipv4_down() {
2181765d
MT
285 local zone="${1}"
286 assert isset zone
c7ad7801
MT
287 shift
288
2181765d
MT
289 if ! zone_exists "${zone}"; then
290 log ERROR "Zone '${zone}' does not exist."
c7ad7801
MT
291 exit ${EXIT_ERROR}
292 fi
293
2181765d 294 ppp_common_ipv4_down "${zone}" "$@"
c7ad7801 295 exit $?
b4038eca
MT
296}
297
1c6a4e30 298hook_ppp_ipv6_up() {
2181765d
MT
299 local zone="${1}"
300 assert isset zone
201b7dff
MT
301 shift
302
2181765d 303 if ! zone_exists "${zone}"; then
201b7dff
MT
304 error "Zone '${zone}' does not exist."
305 exit ${EXIT_ERROR}
306 fi
307
2181765d 308 ppp_common_ipv6_up "${zone}" "$@"
201b7dff
MT
309 exit $?
310}
311
1c6a4e30 312hook_ppp_ipv6_down() {
2181765d
MT
313 local zone="${1}"
314 assert isset zone
201b7dff
MT
315 shift
316
2181765d 317 if ! zone_exists "${zone}"; then
201b7dff
MT
318 error "Zone '${zone}' does not exist."
319 exit ${EXIT_ERROR}
320 fi
321
2181765d 322 ppp_common_ipv6_down "${zone}" "$@"
201b7dff
MT
323 exit $?
324}