summaryrefslogtreecommitdiffstats
path: root/main/ebtables/ebtables.initd
blob: 7ec96b6ee7670d90181db5e25a8e36c8d28400b5 (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
#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-firewall/ebtables/files/ebtables.initd,v 1.2 2007/09/28 19:22:14 pva Exp $

extra_commands="save reload"
extra_started_commands="panic"

ebtables_bin="/sbin/ebtables"
ebtables_save=${EBTABLES_SAVE}
ebtables_tables=$(grep -E '^ebtable_' /proc/modules | cut -f1 -d' ' | sed s/ebtable_//)
if [ "$ebtables_tables" == "" ] ; then
	ebtables_tables=${TABLE_NAMES}
fi

depend() {
	before net
	use logger
}

set_table_policy() {
	local chains table=$1 policy=$2
	case ${table} in
		nat)    chains="PREROUTING POSTROUTING OUTPUT";;
		broute) chains="BROUTING";;
		filter) chains="INPUT FORWARD OUTPUT";;
		*)      chains="";;
	esac
	local chain
	for chain in ${chains} ; do
		${ebtables_bin} -t ${table} -P ${chain} ${policy}
	done
}

checkconfig() {
	if [ ! -f ${ebtables_save} ] ; then
		eerror "Not starting ebtables.  First create some rules then run:"
		eerror "/etc/init.d/ebtables save"
		return 1
	fi
	return 0
}

start() {
	checkconfig || return 1
	ebegin "Loading ebtables state and starting bridge firewall"
	${ebtables_bin}-restore ${SAVE_RESTORE_OPTIONS} < "${ebtables_save}"
	eend $?
}

stop() {
	if [ "${SAVE_ON_STOP}" = "yes" ] ; then
		save || return 1
	fi
	ebegin "Stopping bridge firewall"
	local a
	for a in ${ebtables_tables}; do
		set_table_policy $a ACCEPT

		${ebtables_bin} -t $a -F
		${ebtables_bin} -t $a -X
	done
	eend $?
}

reload() {
	ebegin "Flushing bridge firewall"
	local a
	for a in ${ebtables_tables}; do
		${ebtables_bin} -t $a -F
		${ebtables_bin} -t $a -X
	done
	eend $?

	start
}

save() {
	ebegin "Saving ebtables state"
	touch "${ebtables_save}"
	chmod 0600 "${ebtables_save}"
	${ebtables_bin}-save ${ebtables_tables} ${SAVE_RESTORE_OPTIONS} > "${ebtables_save}"
	eend $?
}

panic() {
	service_started ebtables && svc_stop

	local a
	ebegin "Dropping all packets forwarded on bridges"
	for a in ${ebtables_tables}; do
		${ebtables_bin} -t $a -F
		${ebtables_bin} -t $a -X

		set_table_policy $a DROP
	done
	eend $?
}