updated on Thu Jan 19 20:01:47 UTC 2012
[aur-mirror.git] / ebtables / ebtables.rc
blob3a889b9149ebd0ca5b477b0b12819692e6af162a
1 #!/bin/bash
3 # Credits to:
4 # Sebastien Luttringer <seblu+arch@seblu.net>
5 # Bart De Schuymer <bdschuym@pandora.be>
6 # Rok Papez <rok.papez@arnes.si>
7 # Dag Wieers <dag@wieers.com>
9 . /etc/rc.conf
10 . /etc/rc.d/functions
12 #default configuration:
13 EBTABLES_TEXT_FORMAT="yes"
14 EBTABLES_BINARY_FORMAT="yes"
15 EBTABLES_MODULES_UNLOAD="yes"
16 EBTABLES_SAVE_ON_STOP="no"
17 EBTABLES_SAVE_ON_RESTART="no"
18 EBTABLES_SAVE_COUNTER="no"
20 [[ -r "/etc/conf.d/ebtables" ]] && . "/etc/conf.d/ebtables"
22 RETVAL=0
24 start() {
25 stat_busy "Starting ebtables"
26 ! ck_daemon ebtables && stat_done && RETVAL=0 && return
27 if [[ "$EBTABLES_BINARY_FORMAT" = yes ]]; then
28 for table in $(ls /etc/ebtables/ebtables.* 2>/dev/null | sed -e 's/.*ebtables\.//' -e '/save/d' ); do
29 /usr/sbin/ebtables -t ${table} --atomic-file /etc/ebtables/ebtables.${table} --atomic-commit || RETVAL=1
30 done
31 elif [[ "$EBTABLES_TEXT_FORMAT" = "yes" ]]; then
32 [[ ! -r /etc/ebtables/ebtables ]] && :>/etc/ebtables/ebtables
33 /usr/sbin/ebtables-restore </etc/ebtables/ebtables || RETVAL=1
34 else
35 RETVAL=1
38 if (( RETVAL == 0 )); then
39 stat_done
40 add_daemon ebtables
41 else
42 stat_fail
46 stop() {
47 stat_busy "Stopping ebtables"
48 ck_daemon ebtables && stat_done && RETVAL=0 && return
49 for table in $(grep '^ebtable_' /proc/modules | sed -e 's/ebtable_\([^ ]*\).*/\1/'); do
50 /usr/sbin/ebtables -t $table --init-table || RETVAL=1
51 done
53 if [[ "$EBTABLES_MODULES_UNLOAD" = yes ]]; then
54 for mod in $(grep -E '^(ebt|ebtable)_' /proc/modules | cut -f1 -d' ') ebtables; do
55 /sbin/rmmod $mod 2> /dev/null
56 done
59 if (( RETVAL == 0 )); then
60 rm_daemon ebtables
61 stat_done
62 else
63 stat_fail
67 restart() {
68 stop
69 sleep 1
70 start
73 save() {
74 stat_busy "Saving ebtables"
75 if [[ "$EBTABLES_TEXT_FORMAT" = yes ]]; then
76 if [[ -r /etc/ebtables/ebtables ]]; then
77 mv -f /etc/ebtables/ebtables /etc/ebtables/ebtables.save
79 /usr/sbin/ebtables-save >/etc/ebtables/ebtables || RETVAL=1
81 if [[ "$EBTABLES_BINARY_FORMAT" = yes ]]; then
82 rm -f /etc/ebtables/ebtables.*.save
83 for oldtable in $(ls /etc/ebtables/ebtables.* 2>/dev/null | grep -vF 'ebtables.save'); do
84 mv -f $oldtable $oldtable.save
85 done
86 for table in $(grep '^ebtable_' /proc/modules | sed -e 's/ebtable_\([^ ]*\).*/\1/'); do
87 :> /etc/ebtables/ebtables.$table
88 /usr/sbin/ebtables -t $table --atomic-file /etc/ebtables/ebtables.$table --atomic-save || RETVAL=1
89 if [[ "$EBTABLES_SAVE_COUNTER" = no ]]; then
90 /usr/sbin/ebtables -t $table --atomic-file /etc/ebtables/ebtables.$table -Z || RETVAL=1
92 done
95 (( RETVAL == 0 )) && stat_done || stat_fail
98 case "$1" in
99 start)
100 start
102 stop)
103 [[ "$EBTABLES_SAVE_ON_STOP" = yes ]] && save
104 stop
106 restart|reload)
107 [[ "$EBTABLES_SAVE_ON_RESTART" = yes ]] && save
108 restart
110 condrestart)
111 ! ck_daemon ebtables && restart
112 RETVAL=$?
114 save)
115 save
117 status)
118 /usr/sbin/ebtables-save
119 RETVAL=$?
122 echo "Usage $0 {start|stop|restart|condrestart|save|status}"
123 RETVAL=1
124 esac
126 exit $RETVAL
128 # vim:set ts=2 sw=2 ft=sh noet: