]>
Commit | Line | Data |
---|---|---|
3b11dff3 JR |
1 | #!/bin/sh |
2 | # | |
3 | # init script for the Ethernet Bridge filter tables | |
4 | # | |
5 | # chkconfig: - 15 85 | |
6 | # description: Ethernet Bridge filtering tables | |
7 | # | |
8 | # config: /etc/sysconfig/ebtables (text) | |
9 | # /etc/sysconfig/ebtables.<table> (binary) | |
10 | ||
11 | EBTABLES_CONFIG=/etc/sysconfig/ebtables | |
12 | if [ ! -f $EBTABLES_CONFIG ]; then | |
13 | case "$1" in | |
14 | start|restart|force-reload) | |
15 | exit 0 | |
16 | ;; | |
17 | esac | |
18 | fi | |
19 | ||
20 | # Source 'em up | |
21 | . /etc/rc.d/init.d/functions | |
22 | ||
23 | #default configuration | |
24 | EBTABLES_TEXT_FORMAT="yes" | |
25 | EBTABLES_BINARY_FORMAT="yes" | |
26 | EBTABLES_SAVE_ON_STOP="no" | |
27 | EBTABLES_SAVE_ON_RESTART="no" | |
28 | EBTABLES_SAVE_COUNTER="no" | |
29 | [ -f /etc/sysconfig/ebtables-config ] && . /etc/sysconfig/ebtables-config | |
30 | ||
31 | start() { | |
32 | # don't do squat if we don't have the config file | |
33 | if [ -f $EBTABLES_CONFIG ]; then | |
34 | show "Starting Ethernet bridge filtering (ebtables)" | |
35 | if is_yes "$EBTABLES_BINARY_FORMAT"; then | |
36 | for table in $(ls /etc/sysconfig/ebtables.* 2>/dev/null | sed -e 's/.*ebtables\.//' -e '/save/d' ); do | |
37 | /usr/sbin/ebtables -t $table --atomic-file /etc/sysconfig/ebtables.$table --atomic-commit || RETVAL=1 | |
38 | done | |
39 | else | |
40 | /usr/sbin/ebtables-restore < /etc/sysconfig/ebtables || RETVAL=1 | |
41 | fi | |
42 | ||
43 | if [ $RETVAL -eq 0 ]; then | |
44 | ok | |
45 | touch /var/lock/subsys/ebtables | |
46 | else | |
47 | fail | |
48 | fi | |
49 | fi | |
50 | } | |
51 | ||
52 | stop() { | |
53 | show "Stopping Ethernet bridge filtering (ebtables)" | |
54 | for table in $(grep '^ebtable_' /proc/modules | sed -e 's/ebtable_\([^ ]*\).*/\1/'); do | |
55 | /usr/sbin/ebtables -t $table --init-table || RETVAL=1 | |
56 | done | |
57 | ||
58 | if [ $RETVAL -eq 0 ]; then | |
59 | ok | |
60 | rm -f /var/lock/subsys/ebtables | |
61 | else | |
62 | fail | |
63 | fi | |
64 | } | |
65 | ||
66 | restart() { | |
67 | stop | |
68 | start | |
69 | } | |
70 | ||
71 | save() { | |
72 | show "Saving Ethernet bridge filtering (ebtables)" | |
73 | if is_yes "$EBTABLES_TEXT_FORMAT"; then | |
74 | if [ -e /etc/sysconfig/ebtables ]; then | |
75 | chmod 0600 /etc/sysconfig/ebtables | |
76 | mv -f /etc/sysconfig/ebtables /etc/sysconfig/ebtables.save | |
77 | fi | |
78 | /usr/sbin/ebtables-save > /etc/sysconfig/ebtables || RETVAL=1 | |
79 | fi | |
80 | if is_yes "$EBTABLES_BINARY_FORMAT"; then | |
81 | rm -f /etc/sysconfig/ebtables.*.save | |
82 | for oldtable in $(ls /etc/sysconfif/ebtables.* 2>/dev/null | grep -vF 'ebtables.save'); do | |
83 | chmod 0600 $oldtable | |
84 | mv -f $oldtable $oldtable.save | |
85 | done | |
86 | for table in $(grep '^ebtable_' /proc/modules | sed -e 's/ebtable_\([^ ]*\).*/\1/'); do | |
87 | /usr/sbin/ebtables -t $table --atomic-file /etc/sysconfig/ebtables.$table --atomic-save || RETVAL=1 | |
88 | if [ "$EBTABLES_SAVE_COUNTER" = "no" ]; then | |
89 | /usr/sbin/ebtables -t $table --atomic-file /etc/sysconfig/ebtables.$table -Z || RETVAL=1 | |
90 | fi | |
91 | done | |
92 | fi | |
93 | ||
94 | if [ $RETVAL -eq 0 ]; then | |
95 | ok | |
96 | else | |
97 | fail | |
98 | fi | |
99 | } | |
100 | ||
101 | case "$1" in | |
102 | start) | |
103 | start | |
104 | ;; | |
105 | stop) | |
106 | is_yes "$EBTABLES_SAVE_ON_STOP" && save | |
107 | stop | |
108 | ;; | |
109 | restart|reload) | |
110 | is_yes "$EBTABLES_SAVE_ON_RESTART" && save | |
111 | restart | |
112 | ;; | |
113 | condrestart) | |
114 | [ -e /var/lock/subsys/ebtables ] && restart | |
115 | RETVAL=$? | |
116 | ;; | |
117 | save) | |
118 | save | |
119 | ;; | |
120 | status) | |
121 | for table in $(grep '^ebtable_' /proc/modules | sed -e 's/ebtable_\([^ ]*\).*/\1/'); do | |
122 | /usr/sbin/ebtables -t $table --list | |
123 | done | |
124 | ;; | |
125 | *) | |
126 | echo $"Usage $0 {start|stop|restart|condrestart|save|status}" | |
127 | RETVAL=1 | |
128 | esac | |
129 | ||
130 | exit $RETVAL |