Blame SOURCES/ebtables-helper

05e71a
#!/bin/bash
05e71a
05e71a
# compat for removed initscripts dependency
05e71a
05e71a
success() {
05e71a
       echo "[  OK  ]"
05e71a
       return 0
05e71a
}
05e71a
05e71a
failure() {
05e71a
       echo "[FAILED]"
05e71a
       return 1
05e71a
}
05e71a
05e71a
# internal variables
05e71a
EBTABLES_CONFIG=/etc/sysconfig/ebtables-config
05e71a
EBTABLES_DATA=/etc/sysconfig/ebtables
05e71a
EBTABLES_TABLES="filter nat"
05e71a
if ebtables --version | grep -q '(legacy)'; then
05e71a
	EBTABLES_TABLES+=" broute"
05e71a
fi
05e71a
VAR_SUBSYS_EBTABLES=/var/lock/subsys/ebtables
05e71a
05e71a
# ebtables-config defaults
05e71a
EBTABLES_SAVE_ON_STOP="no"
05e71a
EBTABLES_SAVE_ON_RESTART="no"
05e71a
EBTABLES_SAVE_COUNTER="no"
05e71a
05e71a
# load config if existing
05e71a
[ -f "$EBTABLES_CONFIG" ] && . "$EBTABLES_CONFIG"
05e71a
05e71a
initialize() {
05e71a
	local ret=0
05e71a
	for table in $EBTABLES_TABLES; do
05e71a
		ebtables -t $table --init-table || ret=1
05e71a
	done
05e71a
	return $ret
05e71a
}
05e71a
05e71a
sanitize_dump() {
05e71a
	local drop=false
05e71a
05e71a
	export EBTABLES_TABLES
05e71a
05e71a
	cat $1 | while read line; do
05e71a
		case $line in
05e71a
		\**)
05e71a
			drop=false
05e71a
			local table="${line#\*}"
05e71a
			local found=false
05e71a
			for t in $EBTABLES_TABLES; do
05e71a
				if [[ $t == $table ]]; then
05e71a
					found=true
05e71a
					break
05e71a
				fi
05e71a
			done
05e71a
			$found || drop=true
05e71a
			;;
05e71a
		esac
05e71a
		$drop || echo "$line"
05e71a
	done
05e71a
}
05e71a
05e71a
start() {
05e71a
	if [ -f $EBTABLES_DATA ]; then
05e71a
		echo -n $"ebtables: loading ruleset from $EBTABLES_DATA: "
05e71a
		sanitize_dump $EBTABLES_DATA | ebtables-restore
05e71a
	else
05e71a
		echo -n $"ebtables: no stored ruleset, initializing empty tables: "
05e71a
		initialize
05e71a
	fi
05e71a
	local ret=$?
05e71a
	touch $VAR_SUBSYS_EBTABLES
05e71a
	return $ret
05e71a
}
05e71a
05e71a
save() {
05e71a
	echo -n $"ebtables: saving active ruleset to $EBTABLES_DATA: "
05e71a
	export EBTABLES_SAVE_COUNTER
05e71a
	ebtables-save >$EBTABLES_DATA && success || failure
05e71a
}
05e71a
05e71a
case $1 in
05e71a
	start)
05e71a
		[ -f "$VAR_SUBSYS_EBTABLES" ] && exit 0
05e71a
		start && success || failure
05e71a
		RETVAL=$?
05e71a
		;;
05e71a
	stop)
05e71a
		[ "x$EBTABLES_SAVE_ON_STOP" = "xyes" ] && save
05e71a
		echo -n $"ebtables: stopping firewall: "
05e71a
		initialize && success || failure
05e71a
		RETVAL=$?
05e71a
		rm -f $VAR_SUBSYS_EBTABLES
05e71a
		;;
05e71a
	save)
05e71a
		save
05e71a
		;;
05e71a
	*)
05e71a
		echo "usage: ${0##*/} {start|stop|save}" >&2
05e71a
		RETVAL=2
05e71a
		;;
05e71a
esac
05e71a
05e71a
exit $RETVAL