blob: b6848f14257e8a87f09d009a7def4ddf1c935612 [file] [log] [blame]
Bart De Schuymere8b0a252005-06-14 19:20:43 +00001#!/bin/bash
2#
3# init script for the Ethernet Bridge filter tables
4#
Bart De Schuymer50441e92005-08-30 21:20:55 +00005# Written by Dag Wieers <dag@wieers.com>
6# Modified by Rok Papez <rok.papez@arnes.si>
7# Bart De Schuymer <bdschuym@pandora.be>
Bart De Schuymere8b0a252005-06-14 19:20:43 +00008#
9# chkconfig: - 15 85
10# description: Ethernet Bridge filtering tables
11#
Bart De Schuymer50441e92005-08-30 21:20:55 +000012# config: __SYSCONFIG__/ebtables (text)
13# __SYSCONFIG__/ebtables.<table> (binary)
Bart De Schuymere8b0a252005-06-14 19:20:43 +000014
15source /etc/init.d/functions
16source /etc/sysconfig/network
17
18# Check that networking is up.
19[ ${NETWORKING} = "no" ] && exit 0
20
Bart De Schuymer50441e92005-08-30 21:20:55 +000021[ -x __EXEC_PATH__/ebtables ] || exit 1
22[ -x __EXEC_PATH__/ebtables-save ] || exit 1
23[ -x __EXEC_PATH__/ebtables-restore ] || exit 1
Bart De Schuymere8b0a252005-06-14 19:20:43 +000024
25RETVAL=0
26prog="ebtables"
27desc="Ethernet bridge filtering"
Bart De Schuymer9d1e3ff2005-11-12 22:22:39 +000028umask 0077
Bart De Schuymere8b0a252005-06-14 19:20:43 +000029
Bart De Schuymer50441e92005-08-30 21:20:55 +000030#default configuration
31EBTABLES_TEXT_FORMAT="yes"
32EBTABLES_BINARY_FORMAT="yes"
33EBTABLES_MODULES_UNLOAD="yes"
34EBTABLES_SAVE_ON_STOP="no"
35EBTABLES_SAVE_ON_RESTART="no"
36EBTABLES_SAVE_COUNTER="no"
37
38config=__SYSCONFIG__/$prog-config
39[ -f "$config" ] && . "$config"
40
Bart De Schuymere8b0a252005-06-14 19:20:43 +000041start() {
42 echo -n $"Starting $desc ($prog): "
Bart De Schuymer50441e92005-08-30 21:20:55 +000043 if [ "$EBTABLES_BINARY_FORMAT" = "yes" ]; then
Bart De Schuymerf8a68cb2008-02-03 19:55:26 +000044 for table in $(ls __SYSCONFIG__/ebtables.* 2>/dev/null | sed -e 's/.*ebtables\.//' -e '/save/d' ); do
Bart De Schuymer17b3f092005-10-25 18:08:09 +000045 __EXEC_PATH__/ebtables -t $table --atomic-file __SYSCONFIG__/ebtables.$table --atomic-commit || RETVAL=1
Bart De Schuymer50441e92005-08-30 21:20:55 +000046 done
47 else
48 __EXEC_PATH__/ebtables-restore < /etc/sysconfig/ebtables || RETVAL=1
49 fi
Bart De Schuymere8b0a252005-06-14 19:20:43 +000050
51 if [ $RETVAL -eq 0 ]; then
52 success "$prog startup"
53 rm -f /var/lock/subsys/$prog
54 else
55 failure "$prog startup"
56 fi
Bart De Schuymere8b0a252005-06-14 19:20:43 +000057 echo
Bart De Schuymere8b0a252005-06-14 19:20:43 +000058}
59
60stop() {
61 echo -n $"Stopping $desc ($prog): "
Bart De Schuymerf8a68cb2008-02-03 19:55:26 +000062 for table in $(grep '^ebtable_' /proc/modules | sed -e 's/ebtable_\([^ ]*\).*/\1/'); do
Bart De Schuymer50441e92005-08-30 21:20:55 +000063 __EXEC_PATH__/ebtables -t $table --init-table || RETVAL=1
Bart De Schuymere8b0a252005-06-14 19:20:43 +000064 done
65
Bart De Schuymer17b3f092005-10-25 18:08:09 +000066 if [ "$EBTABLES_MODULES_UNLOAD" = "yes" ]; then
Bart De Schuymer50441e92005-08-30 21:20:55 +000067 for mod in $(grep -E '^(ebt|ebtable)_' /proc/modules | cut -f1 -d' ') ebtables; do
Bart De Schuymerf8a95ce2005-10-25 18:36:11 +000068 rmmod $mod 2> /dev/null
Bart De Schuymer50441e92005-08-30 21:20:55 +000069 done
70 fi
71
Bart De Schuymere8b0a252005-06-14 19:20:43 +000072 if [ $RETVAL -eq 0 ]; then
73 success "$prog shutdown"
Bart De Schuymer28fa0902005-10-25 17:53:18 +000074 rm -f /var/lock/subsys/$prog
Bart De Schuymere8b0a252005-06-14 19:20:43 +000075 else
76 failure "$prog shutdown"
77 fi
Bart De Schuymere8b0a252005-06-14 19:20:43 +000078 echo
Bart De Schuymere8b0a252005-06-14 19:20:43 +000079}
80
81restart() {
82 stop
83 start
84}
85
86save() {
87 echo -n $"Saving $desc ($prog): "
Bart De Schuymer50441e92005-08-30 21:20:55 +000088 if [ "$EBTABLES_TEXT_FORMAT" = "yes" ]; then
Bart De Schuymer9d1e3ff2005-11-12 22:22:39 +000089 if [ -e __SYSCONFIG__/ebtables ]; then
90 chmod 0600 __SYSCONFIG__/ebtables
91 mv -f __SYSCONFIG__/ebtables __SYSCONFIG__/ebtables.save
92 fi
93 __EXEC_PATH__/ebtables-save > __SYSCONFIG__/ebtables || RETVAL=1
Bart De Schuymer50441e92005-08-30 21:20:55 +000094 fi
95 if [ "$EBTABLES_BINARY_FORMAT" = "yes" ]; then
Bart De Schuymer9d1e3ff2005-11-12 22:22:39 +000096 rm -f __SYSCONFIG__/ebtables.*.save
Bart De Schuymerf8a68cb2008-02-03 19:55:26 +000097 for oldtable in $(ls __SYSCONFIG__/ebtables.* 2>/dev/null | grep -vF 'ebtables.save'); do
98 chmod 0600 $oldtable
99 mv -f $oldtable $oldtable.save
Bart De Schuymer9d1e3ff2005-11-12 22:22:39 +0000100 done
Bart De Schuymerf8a68cb2008-02-03 19:55:26 +0000101 for table in $(grep '^ebtable_' /proc/modules | sed -e 's/ebtable_\([^ ]*\).*/\1/'); do
Bart De Schuymer17b3f092005-10-25 18:08:09 +0000102 __EXEC_PATH__/ebtables -t $table --atomic-file __SYSCONFIG__/ebtables.$table --atomic-save || RETVAL=1
Bart De Schuymer50441e92005-08-30 21:20:55 +0000103 if [ "$EBTABLES_SAVE_COUNTER" = "no" ]; then
Bart De Schuymer17b3f092005-10-25 18:08:09 +0000104 __EXEC_PATH__/ebtables -t $table --atomic-file __SYSCONFIG__/ebtables.$table -Z || RETVAL=1
Bart De Schuymer50441e92005-08-30 21:20:55 +0000105 fi
106 done
107 fi
Bart De Schuymere8b0a252005-06-14 19:20:43 +0000108
109 if [ $RETVAL -eq 0 ]; then
110 success "$prog saved"
111 else
112 failure "$prog saved"
113 fi
114 echo
115}
116
117case "$1" in
118 start)
119 start
120 ;;
121 stop)
Bart De Schuymerf8a68cb2008-02-03 19:55:26 +0000122 [ "$EBTABLES_SAVE_ON_STOP" = "yes" ] && save
Bart De Schuymere8b0a252005-06-14 19:20:43 +0000123 stop
124 ;;
125 restart|reload)
Bart De Schuymerf8a68cb2008-02-03 19:55:26 +0000126 [ "$EBTABLES_SAVE_ON_RESTART" = "yes" ] && save
Bart De Schuymere8b0a252005-06-14 19:20:43 +0000127 restart
128 ;;
129 condrestart)
130 [ -e /var/lock/subsys/$prog ] && restart
131 RETVAL=$?
132 ;;
133 save)
134 save
135 ;;
136 status)
Bart De Schuymer50441e92005-08-30 21:20:55 +0000137 __EXEC_PATH__/ebtables-save
Bart De Schuymere8b0a252005-06-14 19:20:43 +0000138 RETVAL=$?
139 ;;
140 *)
141 echo $"Usage $0 {start|stop|restart|condrestart|save|status}"
142 RETVAL=1
143esac
144
145exit $RETVAL