aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/bbfw.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/bbfw.in')
-rwxr-xr-xsrc/bbfw.in222
1 files changed, 169 insertions, 53 deletions
diff --git a/src/bbfw.in b/src/bbfw.in
index 00c45b9..40fdcb8 100755
--- a/src/bbfw.in
+++ b/src/bbfw.in
@@ -82,6 +82,10 @@ FW_PREFIX=@sysconfdir@/firewall.d/
82FW_CONF=@sysconfdir@/bbfw.conf 82FW_CONF=@sysconfdir@/bbfw.conf
83FW_QUIET=no 83FW_QUIET=no
84FW_VERBOSE=no 84FW_VERBOSE=no
85FW_ORDER_PRE="global apps cluster local"
86FW_ORDER_POST="global apps cluster local"
87FW_ORDER_IPSETS="global apps cluster local"
88FW_ORDER_IPTABLES="apps local cluster global"
85 89
86 90
87########### 91###########
@@ -218,70 +222,159 @@ load()
218# Function to start the network: 222# Function to start the network:
219start() { 223start() {
220 # run pre-hooks 224 # run pre-hooks
221 run_hook start ${FW_PREFIX}/global.d/pre-hook "running global pre-hook start ..." 225 for LEVEL in ${FW_ORDER_PRE};do
222 for FILE in $( find_appfile pre-hook );do 226 case "${LEVEL}" in
223 run_hook start ${FILE} "running app pre-hook start (App: $(name_appfile ${FILE})) ..." 227 global)
228 run_hook start ${FW_PREFIX}/global.d/pre-hook "running global pre-hook start ..."
229 ;;
230
231 apps)
232 for FILE in $( find_appfile pre-hook );do
233 run_hook start ${FILE} "running app pre-hook start (App: $(name_appfile ${FILE})) ..."
234 done
235 ;;
236
237 cluster)
238 run_hook start ${FW_PREFIX}/cluster.d/pre-hook "running cluster pre-hook start ..."
239 ;;
240
241 local)
242 run_hook start ${FW_PREFIX}/pre-hook "running local pre-hook start ..."
243 ;;
244
245 *)
246 echo "Unknown pre-hook order \"${LEVEL}\""
247 ;;
248 esac
224 done 249 done
225 run_hook start ${FW_PREFIX}/cluster.d/pre-hook "running cluster pre-hook start ..."
226 run_hook start ${FW_PREFIX}/pre-hook "running local pre-hook start ..."
227 250
228 # create IP sets 251 # create IP sets
229 load ipset ${FW_PREFIX}/global.d/ipsets "adding global IP sets" 252 for LEVEL in ${FW_ORDER_IPSETS};do
230 for FILE in $( find_appfile ipsets );do 253 case "${LEVEL}" in
231 load ipset ${FILE} "adding IP sets (App: $(name_appfile ${FILE})) ..." 254 global)
255 load ipset ${FW_PREFIX}/global.d/ipsets "adding global IP sets"
256 ;;
257
258 apps)
259 for FILE in $( find_appfile ipsets );do
260 load ipset ${FILE} "adding IP sets (App: $(name_appfile ${FILE})) ..."
261 done
262 ;;
263
264 cluster)
265 load ipset ${FW_PREFIX}/cluster.d/ipsets "adding cluster IP sets"
266 ;;
267
268 local)
269 load ipset ${FW_PREFIX}/ipsets "adding local IP sets"
270 ;;
271
272 *)
273 echo "Unknown ipsets order \"${LEVEL}\""
274 ;;
275 esac
232 done 276 done
233 load ipset ${FW_PREFIX}/cluster.d/ipsets "adding cluster IP sets"
234 load ipset ${FW_PREFIX}/ipsets "adding local IP sets"
235 277
236 # Application rules 278 # loads iptables/ip6tables
237 for FILE in $( find_appfile rules4 );do 279 for LEVEL in ${FW_ORDER_IPTABLES};do
238 load iptables ${FILE} "adding IPv4 rules (App: $(name_appfile ${FILE})) ..." 280 case "${LEVEL}" in
281 apps)
282 for FILE in $( find_appfile rules4 );do
283 load iptables ${FILE} "adding IPv4 rules (App: $(name_appfile ${FILE})) ..."
284 done
285 for FILE in $( find_appfile rules6 );do
286 load ip6tables ${FILE} "adding IPv6 rules (App: $(name_appfile ${FILE})) ..."
287 done
288 for FILE in $( find_appfile rules );do
289 load iptables ${FILE} "adding IPv4/IPv6 rules (App: $(name_appfile ${FILE})) ..."
290 load ip6tables ${FILE}
291 done
292 ;;
293
294 local)
295 load iptables ${FW_PREFIX}/rules4 "adding IPv4 local rules"
296 load ip6tables ${FW_PREFIX}/rules6 "adding IPv6 local rules"
297 load iptables ${FW_PREFIX}/rules "adding IPv4/IPv6 local rules"
298 load ip6tables ${FW_PREFIX}/rules
299 ;;
300
301 cluster)
302 load iptables ${FW_PREFIX}/cluster.d/rules4 "adding IPv4 cluster rules"
303 load ip6tables ${FW_PREFIX}/cluster.d/rules6 "adding IPv6 cluster rules"
304 load iptables ${FW_PREFIX}/cluster.d/rules "adding IPv4/IPv6 cluster rules"
305 load ip6tables ${FW_PREFIX}/cluster.d/rules
306 ;;
307
308 global)
309 load iptables ${FW_PREFIX}/global.d/rules4 "adding IPv4 global rules"
310 load ip6tables ${FW_PREFIX}/global.d/rules6 "adding IPv6 global rules"
311 load iptables ${FW_PREFIX}/global.d/rules "adding IPv4/IPv6 global rules"
312 load ip6tables ${FW_PREFIX}/global.d/rules
313 ;;
314
315 *)
316 echo "Unknown iptables order \"${LEVEL}\""
317 ;;
318 esac
239 done 319 done
240 for FILE in $( find_appfile rules6 );do
241 load ip6tables ${FILE} "adding IPv6 rules (App: $(name_appfile ${FILE})) ..."
242 done
243 for FILE in $( find_appfile rules );do
244 load iptables ${FILE} "adding IPv4/IPv6 rules (App: $(name_appfile ${FILE})) ..."
245 load ip6tables ${FILE}
246 done
247
248 # apply host specific firewall rules
249 load iptables ${FW_PREFIX}/rules4 "adding IPv4 local rules"
250 load ip6tables ${FW_PREFIX}/rules6 "adding IPv6 local rules"
251 load iptables ${FW_PREFIX}/rules "adding IPv4/IPv6 local rules"
252 load ip6tables ${FW_PREFIX}/rules
253
254 # apply cluster specific firewall rules
255 load iptables ${FW_PREFIX}/cluster.d/rules4 "adding IPv4 cluster rules"
256 load ip6tables ${FW_PREFIX}/cluster.d/rules6 "adding IPv6 cluster rules"
257 load iptables ${FW_PREFIX}/cluster.d/rules "adding IPv4/IPv6 cluster rules"
258 load ip6tables ${FW_PREFIX}/cluster.d/rules
259
260 # apply company policy for firewall rules
261 load iptables ${FW_PREFIX}/global.d/rules4 "adding IPv4 global rules"
262 load ip6tables ${FW_PREFIX}/global.d/rules6 "adding IPv6 global rules"
263 load iptables ${FW_PREFIX}/global.d/rules "adding IPv4/IPv6 global rules"
264 load ip6tables ${FW_PREFIX}/global.d/rules
265 320
266 # run post-hooks 321 # run post-hooks
267 run_hook start ${FW_PREFIX}/global.d/post-hook "running global post-hook start ..." 322 for LEVEL in ${FW_ORDER_POST};do
268 for FILE in $( find_appfile post-hook );do 323 case "${LEVEL}" in
269 run_hook start ${FILE} "running app post-hook start (App: $(name_appfile ${FILE})) ..." 324 global)
325 run_hook start ${FW_PREFIX}/global.d/post-hook "running global post-hook start ..."
326 ;;
327
328 apps)
329 for FILE in $( find_appfile post-hook );do
330 run_hook start ${FILE} "running app post-hook start (App: $(name_appfile ${FILE})) ..."
331 done
332 ;;
333
334 cluster)
335 run_hook start ${FW_PREFIX}/cluster.d/post-hook "running cluster post-hook start ..."
336 ;;
337
338 local)
339 run_hook start ${FW_PREFIX}/post-hook "running local post-hook start ..."
340 ;;
341
342 *)
343 echo "Unknown post-hook order \"${LEVEL}\""
344 ;;
345 esac
270 done 346 done
271 run_hook start ${FW_PREFIX}/cluster.d/post-hook "running cluster post-hook start ..."
272 run_hook start ${FW_PREFIX}/post-hook "running local post-hook start ..."
273} 347}
274 348
275 349
276# Function to stop the network: 350# Function to stop the network:
277stop() { 351stop() {
278 # run pre-hooks 352 # run pre-hooks
279 run_hook stop ${FW_PREFIX}/global.d/pre-hook "running global pre-hook stop ..." 353 for LEVEL in ${FW_ORDER_PRE};do
280 for FILE in $( find_appfile pre-hook );do 354 case "${LEVEL}" in
281 run_hook stop ${FILE} "running app pre-hook stop (App: $(name_appfile ${FILE})) ..." 355 global)
356 run_hook stop ${FW_PREFIX}/global.d/pre-hook "running global pre-hook stop ..."
357 ;;
358
359 apps)
360 for FILE in $( find_appfile pre-hook );do
361 run_hook stop ${FILE} "running app pre-hook stop (App: $(name_appfile ${FILE})) ..."
362 done
363 ;;
364
365 cluster)
366 run_hook stop ${FW_PREFIX}/cluster.d/pre-hook "running cluster pre-hook stop ..."
367 ;;
368
369 local)
370 run_hook stop ${FW_PREFIX}/pre-hook "running local pre-hook stop ..."
371 ;;
372
373 *)
374 echo "Unknown pre-hook order \"${LEVEL}\""
375 ;;
376 esac
282 done 377 done
283 run_hook stop ${FW_PREFIX}/cluster.d/pre-hook "running cluster pre-hook stop ..."
284 run_hook stop ${FW_PREFIX}/pre-hook "running local pre-hook stop ..."
285 378
286 # flushes iptables 379 # flushes iptables
287 for TABLE in $(iptables-save |grep '^*' |sed -e 's/^*//g' |sort);do 380 for TABLE in $(iptables-save |grep '^*' |sed -e 's/^*//g' |sort);do
@@ -323,12 +416,31 @@ stop() {
323 done 416 done
324 417
325 # run post-hooks 418 # run post-hooks
326 run_hook stop ${FW_PREFIX}/global.d/post-hook "running global post-hook stop ..." 419 for LEVEL in ${FW_ORDER_POST};do
327 for FILE in $( find_appfile post-hook );do 420 case "${LEVEL}" in
328 run_hook stop ${FILE} "running app post-hook stop (App: $(name_appfile ${FILE})) ..." 421 global)
422 run_hook stop ${FW_PREFIX}/global.d/post-hook "running global post-hook stop ..."
423 ;;
424
425 apps)
426 for FILE in $( find_appfile post-hook );do
427 run_hook stop ${FILE} "running app post-hook stop (App: $(name_appfile ${FILE})) ..."
428 done
429 ;;
430
431 cluster)
432 run_hook stop ${FW_PREFIX}/cluster.d/post-hook "running cluster post-hook stop ..."
433 ;;
434
435 local)
436 run_hook stop ${FW_PREFIX}/post-hook "running local post-hook stop ..."
437 ;;
438
439 *)
440 echo "Unknown post-hook order \"${LEVEL}\""
441 ;;
442 esac
329 done 443 done
330 run_hook stop ${FW_PREFIX}/cluster.d/post-hook "running cluster post-hook stop ..."
331 run_hook stop ${FW_PREFIX}/post-hook "running local post-hook stop ..."
332} 444}
333 445
334 446
@@ -340,6 +452,10 @@ stop() {
340FW_PREFIX="$( config_option firewall_dir "${FW_PREFIX}" )" 452FW_PREFIX="$( config_option firewall_dir "${FW_PREFIX}" )"
341FW_QUIET="$( config_option quiet "${FW_QUIET}" A-Z a-z )" 453FW_QUIET="$( config_option quiet "${FW_QUIET}" A-Z a-z )"
342FW_VERBOSE="$( config_option verbose "${FW_VERBOSE}" A-Z a-z )" 454FW_VERBOSE="$( config_option verbose "${FW_VERBOSE}" A-Z a-z )"
455FW_ORDER_PRE="$( config_option order_prehook "${FW_ORDER_PRE}" A-Z a-z )"
456FW_ORDER_POST="$( config_option order_posthook "${FW_ORDER_POST}" A-Z a-z )"
457FW_ORDER_IPTABLES="$( config_option order_iptables "${FW_ORDER_IPTABLES}" A-Z a-z )"
458FW_ORDER_IPSETS="$( config_option order_ipsets "${FW_ORDER_IPSETS}" A-Z a-z )"
343 459
344 460
345# checks and normalizes options 461# checks and normalizes options