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