]> git.ipfire.org Git - people/stevee/network.git/blob - src/header-zone
Add hotplugging for zones (and ports of those)
[people/stevee/network.git] / src / header-zone
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 function hook_info() {
23 echo "HOOK=\"${HOOK}\""
24 }
25
26 function hook_hotplug() {
27 # If the hook does not handle the hotplug event, it
28 # must return EXIT_NOT_HANDLED.
29 exit ${EXIT_NOT_HANDLED}
30 }
31
32 function hook_create() {
33 local zone="${1}"
34 assert isset zone
35 shift
36
37 settings_read $(zone_dir ${zone})/settings
38
39 hook_parse_cmdline $@
40
41 settings_write $(zone_dir ${zone})/settings ${HOOK_SETTINGS}
42
43 exit ${EXIT_OK}
44 }
45
46 function hook_edit() {
47 hook_create $@
48 }
49
50 function hook_remove() {
51 cmd_not_implemented
52 }
53
54 function hook_status() {
55 local zone="${1}"
56 assert isset zone
57
58 if device_is_up ${zone}; then
59 exit ${STATUS_UP}
60 fi
61
62 exit ${STATUS_DOWN}
63 }
64
65 function hook_up() {
66 cmd_not_implemented
67 }
68
69 function hook_down() {
70 cmd_not_implemented
71 }
72
73 function hook_discover() {
74 # This hook does not support a discovery
75 exit ${DISCOVER_NOT_SUPPORTED}
76 }
77
78 # Do nothing
79 function hook_parse_cmdline() {
80 return ${EXIT_OK}
81 }
82
83 function hook_port() {
84 local zone="${1}"
85 assert isset zone
86
87 local action="${2}"
88 shift 2
89
90 local ret
91 case "${action}" in
92 add|create|edit|rem|show)
93 hook_port_${action} "${zone}" $@
94 ret=$?
95 ;;
96 *)
97 error "Unrecognized argument: '${action}'"
98 exit ${EXIT_ERROR}
99 ;;
100 esac
101
102 exit ${ret}
103 }
104
105 function hook_port_add() {
106 return ${EXIT_NOT_SUPPORTED}
107 }
108
109 function hook_port_edit() {
110 return ${EXIT_NOT_SUPPORTED}
111 }
112
113 function hook_port_remove() {
114 return ${EXIT_NOT_SUPPORTED}
115 }
116
117 function hook_port_show() {
118 cmd_not_implemented
119 }
120
121 function hook_port_status() {
122 return ${EXIT_NOT_SUPPORTED}
123 }
124
125 function hook_port_up() {
126 cmd_not_implemented
127 }
128
129 function hook_port_down() {
130 cmd_not_implemented
131 }
132
133 function hook_config() {
134 local zone="${1}"
135 assert isset zone
136
137 local action="${2}"
138 assert isset action
139 shift 2
140
141 local ret
142 case "${action}" in
143 create|edit|rem|show)
144 hook_config_${action} "${zone}" "$@"
145 exit $?
146 ;;
147 *)
148 error "Unrecognized argument: '${action}'"
149 exit ${EXIT_ERROR}
150 ;;
151 esac
152 }
153
154 function hook_config_cmd() {
155 local cmd="${1}"
156 assert isset cmd
157
158 local zone="${2}"
159 assert isset zone
160
161 local hook_config="${3}"
162 assert isset hook_config
163
164 shift 3
165
166 local hook_zone="$(zone_get_hook "${zone}")"
167 if ! hook_zone_exists "${hook_zone}"; then
168 log ERROR "Hook '${hook}' does not exist."
169 exit ${EXIT_ERROR}
170 fi
171
172 #if ! hook_config_exists "${hook_zone}" "${hook_config}"; then
173 # log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'."
174 # exit ${EXIT_ERROR}
175 #fi
176
177 hook_config_exec "${hook_config}" "${cmd}" "${zone}" "$@"
178 }
179
180 function hook_config_create() {
181 assert [ $# -gt 2 ]
182
183 hook_config_cmd "create" "$@"
184 }
185
186 function hook_config_edit() {
187 hook_config_cmd "edit" "$@"
188 }
189
190 function hook_config_remove() {
191 hook_config_cmd "remove" "$@"
192 }
193
194 function hook_config_show() {
195 cmd_not_implemented
196 }
197
198 function hook_ppp_write_config() {
199 cmd_not_implemented
200
201 # Arguments: <zone> <filename>
202 }
203
204 function hook_ppp_ip_pre_up() {
205 local zone="${1}"
206 assert isset zone
207 shift
208
209 if ! zone_exists "${zone}"; then
210 log ERROR "Zone '${zone}' does not exist."
211 exit ${EXIT_ERROR}
212 fi
213
214 ppp_common_ip_pre_up "${zone}" "$@"
215 exit $?
216 }
217
218 function hook_ppp_ipv4_up() {
219 local zone="${1}"
220 assert isset zone
221 shift
222
223 if ! zone_exists "${zone}"; then
224 log ERROR "Zone '${zone}' does not exist."
225 exit ${EXIT_ERROR}
226 fi
227
228 ppp_common_ipv4_up "${zone}" "$@"
229 exit $?
230 }
231
232 function hook_ppp_ipv4_down() {
233 local zone="${1}"
234 assert isset zone
235 shift
236
237 if ! zone_exists "${zone}"; then
238 log ERROR "Zone '${zone}' does not exist."
239 exit ${EXIT_ERROR}
240 fi
241
242 ppp_common_ipv4_down "${zone}" "$@"
243 exit $?
244 }
245
246 function hook_ppp_ipv6_up() {
247 local zone="${1}"
248 assert isset zone
249 shift
250
251 if ! zone_exists "${zone}"; then
252 error "Zone '${zone}' does not exist."
253 exit ${EXIT_ERROR}
254 fi
255
256 ppp_common_ipv6_up "${zone}" "$@"
257 exit $?
258 }
259
260 function hook_ppp_ipv6_down() {
261 local zone="${1}"
262 assert isset zone
263 shift
264
265 if ! zone_exists "${zone}"; then
266 error "Zone '${zone}' does not exist."
267 exit ${EXIT_ERROR}
268 fi
269
270 ppp_common_ipv6_down "${zone}" "$@"
271 exit $?
272 }