| 4 |
- |
1 |
#!/bin/bash
|
|
|
2 |
#
|
|
|
3 |
# init script for the Ethernet Bridge filter tables
|
|
|
4 |
#
|
|
|
5 |
# Written by Dag Wieers <dag@wieers.com>
|
|
|
6 |
# Modified by Rok Papez <rok.papez@arnes.si>
|
|
|
7 |
# Bart De Schuymer <bdschuym@pandora.be>
|
|
|
8 |
#
|
|
|
9 |
# chkconfig: - 15 85
|
|
|
10 |
# description: Ethernet Bridge filtering tables
|
|
|
11 |
#
|
|
|
12 |
# config: /etc/sysconfig/ebtables (text)
|
|
|
13 |
# /etc/sysconfig/ebtables.<table> (binary)
|
|
|
14 |
|
|
|
15 |
source /etc/init.d/functions
|
|
|
16 |
source /etc/sysconfig/network
|
|
|
17 |
|
|
|
18 |
# Check that networking is up.
|
|
|
19 |
[ ${NETWORKING} = "no" ] && exit 0
|
|
|
20 |
|
|
|
21 |
[ -x /sbin/ebtables ] || exit 5
|
|
|
22 |
[ -x /sbin/ebtables-save ] || exit 5
|
|
|
23 |
[ -x /sbin/ebtables-restore ] || exit 5
|
|
|
24 |
|
|
|
25 |
RETVAL=0
|
|
|
26 |
prog="ebtables"
|
|
|
27 |
desc="Ethernet bridge filtering"
|
|
|
28 |
umask 0077
|
|
|
29 |
|
|
|
30 |
#default configuration
|
|
|
31 |
EBTABLES_TEXT_FORMAT="yes"
|
|
|
32 |
EBTABLES_BINARY_FORMAT="yes"
|
|
|
33 |
EBTABLES_MODULES_UNLOAD="yes"
|
|
|
34 |
EBTABLES_SAVE_ON_STOP="no"
|
|
|
35 |
EBTABLES_SAVE_ON_RESTART="no"
|
|
|
36 |
EBTABLES_SAVE_COUNTER="no"
|
|
|
37 |
|
|
|
38 |
config=/etc/sysconfig/$prog-config
|
|
|
39 |
[ -f "$config" ] && . "$config"
|
|
|
40 |
|
|
|
41 |
start() {
|
|
|
42 |
[ "$EUID" != "0" ] && exit 4
|
|
|
43 |
echo -n $"Starting $desc ($prog): "
|
|
|
44 |
if [ "$EBTABLES_BINARY_FORMAT" = "yes" ]; then
|
|
|
45 |
for table in $(ls /etc/sysconfig/ebtables.* 2>/dev/null | sed -e 's/.*ebtables\.//' -e '/save/d' ); do
|
|
|
46 |
/sbin/ebtables -t $table --atomic-file /etc/sysconfig/ebtables.$table --atomic-commit || RETVAL=1
|
|
|
47 |
done
|
|
|
48 |
else
|
|
|
49 |
/sbin/ebtables-restore < /etc/sysconfig/ebtables || RETVAL=1
|
|
|
50 |
fi
|
|
|
51 |
|
|
|
52 |
if [ $RETVAL -eq 0 ]; then
|
|
|
53 |
success "$prog startup"
|
|
|
54 |
touch "/var/lock/subsys/$prog"
|
|
|
55 |
else
|
|
|
56 |
failure "$prog startup"
|
|
|
57 |
fi
|
|
|
58 |
echo
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
stop() {
|
|
|
62 |
[ "$EUID" != "0" ] && exit 4
|
|
|
63 |
echo -n $"Stopping $desc ($prog): "
|
|
|
64 |
for table in $(grep '^ebtable_' /proc/modules | sed -e 's/ebtable_\([^ ]*\).*/\1/'); do
|
|
|
65 |
/sbin/ebtables -t $table --init-table || RETVAL=1
|
|
|
66 |
done
|
|
|
67 |
|
|
|
68 |
if [ "$EBTABLES_MODULES_UNLOAD" = "yes" ]; then
|
|
|
69 |
for mod in $(grep -E '^(ebt|ebtable)_' /proc/modules | cut -f1 -d' ') ebtables; do
|
|
|
70 |
rmmod $mod 2> /dev/null
|
|
|
71 |
done
|
|
|
72 |
fi
|
|
|
73 |
|
|
|
74 |
if [ $RETVAL -eq 0 ]; then
|
|
|
75 |
success "$prog shutdown"
|
|
|
76 |
rm -f "/var/lock/subsys/$prog"
|
|
|
77 |
else
|
|
|
78 |
failure "$prog shutdown"
|
|
|
79 |
fi
|
|
|
80 |
echo
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
restart() {
|
|
|
84 |
[ "$EBTABLES_SAVE_ON_RESTART" = "yes" ] && save
|
|
|
85 |
stop
|
|
|
86 |
start
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
save() {
|
|
|
90 |
[ "$EUID" != "0" ] && exit 4
|
|
|
91 |
echo -n $"Saving $desc ($prog): "
|
|
|
92 |
if [ "$EBTABLES_TEXT_FORMAT" = "yes" ]; then
|
|
|
93 |
if [ -e /etc/sysconfig/ebtables ]; then
|
|
|
94 |
chmod 0600 /etc/sysconfig/ebtables
|
|
|
95 |
mv -f /etc/sysconfig/ebtables /etc/sysconfig/ebtables.save
|
|
|
96 |
fi
|
|
|
97 |
/sbin/ebtables-save > /etc/sysconfig/ebtables || RETVAL=1
|
|
|
98 |
fi
|
|
|
99 |
if [ "$EBTABLES_BINARY_FORMAT" = "yes" ]; then
|
|
|
100 |
rm -f /etc/sysconfig/ebtables.*.save
|
|
|
101 |
for oldtable in $(ls /etc/sysconfig/ebtables.* 2>/dev/null | grep -vF 'ebtables.save'); do
|
|
|
102 |
chmod 0600 $oldtable
|
|
|
103 |
mv -f $oldtable $oldtable.save
|
|
|
104 |
done
|
|
|
105 |
for table in $(grep '^ebtable_' /proc/modules | sed -e 's/ebtable_\([^ ]*\).*/\1/'); do
|
|
|
106 |
/sbin/ebtables -t $table --atomic-file /etc/sysconfig/ebtables.$table --atomic-save || RETVAL=1
|
|
|
107 |
if [ "$EBTABLES_SAVE_COUNTER" = "no" ]; then
|
|
|
108 |
/sbin/ebtables -t $table --atomic-file /etc/sysconfig/ebtables.$table -Z || RETVAL=1
|
|
|
109 |
fi
|
|
|
110 |
done
|
|
|
111 |
fi
|
|
|
112 |
|
|
|
113 |
if [ $RETVAL -eq 0 ]; then
|
|
|
114 |
success "$prog saved"
|
|
|
115 |
else
|
|
|
116 |
failure "$prog saved"
|
|
|
117 |
fi
|
|
|
118 |
echo
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
case "$1" in
|
|
|
122 |
start)
|
|
|
123 |
[ -f "/var/lock/subsys/$prog" ] && exit 0
|
|
|
124 |
start
|
|
|
125 |
;;
|
|
|
126 |
stop)
|
|
|
127 |
[ "$EBTABLES_SAVE_ON_STOP" = "yes" ] && save
|
|
|
128 |
stop
|
|
|
129 |
;;
|
|
|
130 |
restart|force-reload)
|
|
|
131 |
restart
|
|
|
132 |
;;
|
|
|
133 |
reload)
|
|
|
134 |
[ ! -f "/var/lock/subsys/$prog" ] && exit 7
|
|
|
135 |
restart
|
|
|
136 |
;;
|
|
|
137 |
condrestart|try-restart)
|
|
|
138 |
[ ! -e "/var/lock/subsys/$prog" ] && exit 0
|
|
|
139 |
restart
|
|
|
140 |
;;
|
|
|
141 |
save)
|
|
|
142 |
save
|
|
|
143 |
;;
|
|
|
144 |
status)
|
|
|
145 |
[ -f "/var/lock/subsys/$prog" ] && RETVAL=0 || RETVAL=3
|
|
|
146 |
/sbin/ebtables-save
|
|
|
147 |
;;
|
|
|
148 |
*)
|
|
|
149 |
echo $"Usage $0 {start|stop|restart|condrestart|save|status}"
|
|
|
150 |
RETVAL=2
|
|
|
151 |
esac
|
|
|
152 |
|
|
|
153 |
exit $RETVAL
|