summaryrefslogtreecommitdiffstats
path: root/userspace/ebtables2/ebtables.sysv
blob: 53fd0f66dfa6806ac8791cc94d81680acf124b40 (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
129
130
131
132
133
134
135
#!/bin/bash
#
# init script for the Ethernet Bridge filter tables
#
# Written by Dag Wieers <dag@wieers.com>
# Modified by Rok Papez <rok.papez@arnes.si>
#             Bart De Schuymer <bdschuym@pandora.be>
#
# chkconfig: - 15 85
# description: Ethernet Bridge filtering tables
#
# config: __SYSCONFIG__/ebtables         (text)
#         __SYSCONFIG__/ebtables.<table> (binary)

source /etc/init.d/functions
source /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x __EXEC_PATH__/ebtables ] || exit 1
[ -x __EXEC_PATH__/ebtables-save ] || exit 1
[ -x __EXEC_PATH__/ebtables-restore ] || exit 1

RETVAL=0
prog="ebtables"
desc="Ethernet bridge filtering"

#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"

config=__SYSCONFIG__/$prog-config
[ -f "$config" ] && . "$config"

start() {
	echo -n $"Starting $desc ($prog): "
	if [ "$EBTABLES_BINARY_FORMAT" = "yes" ]; then
		for table in $(ls __SYSCONFIG__/ebtables.* | sed s/*ebtables.//); do
			__EXEC_PATH__/ebtables -t $table --atomic-file __SYSCONFIG__/ebtables.filter --atomic-commit || RETVAL=1
		done
	else
		__EXEC_PATH__/ebtables-restore < /etc/sysconfig/ebtables || RETVAL=1
	fi

	if [ $RETVAL -eq 0 ]; then
		success "$prog startup"
		rm -f /var/lock/subsys/$prog
	else
		failure "$prog startup"
	fi
	echo
}

stop() {
	echo -n $"Stopping $desc ($prog): "
	for table in $(grep -E '^ebtable_' /proc/modules | cut -f1 -d' ' | sed s/ebtable_//); do
		__EXEC_PATH__/ebtables -t $table --init-table || RETVAL=1
	done

	if [ "$EBTABLES_MODULE_UNLOAD" = "yes" ]; then
		for mod in $(grep -E '^(ebt|ebtable)_' /proc/modules | cut -f1 -d' ') ebtables; do
			rmmod $mod || RETVAL=1
		done
	fi

	if [ $RETVAL -eq 0 ]; then
		success "$prog shutdown"
		rm -f %{_localstatedir}/lock/subsys/$prog
	else
		failure "$prog shutdown"
	fi
	echo
}

restart() {
	stop
	start
}

save() {
	echo -n $"Saving $desc ($prog): "
	if [ "$EBTABLES_TEXT_FORMAT" = "yes" ]; then
		__EXEC_PATH__/ebtables-save > /etc/sysconfig/ebtables || RETVAL=1
	fi
	if [ "$EBTABLES_BINARY_FORMAT" = "yes" ]; then
		for mod in $(grep -E '^ebtable_' /proc/modules | cut -f1 -d' ' | sed s/ebtable_//); do
			__EXEC_PATH__/ebtables -t $mod --atomic-file __SYSCONFIG__/ebtables.$mod --atomic-save || RETVAL=1
			if [ "$EBTABLES_SAVE_COUNTER" = "no" ]; then
				__EXEC_PATH__/ebtables -t $mod --atomic-file __SYSCONFIG__/ebtables.$mod -Z || RETVAL=1
			fi
		done
	fi

	if [ $RETVAL -eq 0 ]; then
		success "$prog saved"
	else
		failure "$prog saved"
	fi
	echo
}

case "$1" in
  start)
	start
	;;
  stop)
	[ "$IPTABLES_SAVE_ON_STOP" = "yes" ] && save
	stop
	;;
  restart|reload)
	[ "$IPTABLES_SAVE_ON_RESTART" = "yes" ] && save
	restart
	;;
  condrestart)
	[ -e /var/lock/subsys/$prog ] && restart
	RETVAL=$?
	;;
  save)
	save
	;;
  status)
	__EXEC_PATH__/ebtables-save
	RETVAL=$?
	;;
  *)
	echo $"Usage $0 {start|stop|restart|condrestart|save|status}"
	RETVAL=1
esac

exit $RETVAL