Blame SOURCES/arptables-helper

c42007
#!/bin/sh
c42007
# config: /etc/sysconfig/arptables
c42007
c42007
# Source 'em up
c42007
. /etc/init.d/functions
c42007
c42007
ARPTABLES_CONFIG=/etc/sysconfig/arptables
c42007
c42007
arp_table() {
c42007
	if fgrep -qsx $1 /proc/net/arp_tables_names; then
c42007
		arptables -t "$@"
c42007
	fi
c42007
}
c42007
c42007
flush_delete_chains() {
c42007
	chains=$(cat /proc/net/arp_tables_names 2>/dev/null)
c42007
	echo -n $"Flushing all chains:"
c42007
	let ret=0
c42007
	for i in $chains; do arptables -t $i -F; let ret+=$?; done
c42007
	arptables -F; let ret+=$?
c42007
	if [ $ret -eq 0 ]; then
c42007
		success
c42007
	else
c42007
		failure
c42007
	fi
c42007
	echo
c42007
c42007
	echo -n $"Removing user defined chains:"
c42007
	let ret=0
c42007
	for i in $chains; do arptables -t $i -X; let ret+=$?; done
c42007
	arptables -X; let ret+=$?
c42007
	if [ $ret -eq 0 ]; then
c42007
		success
c42007
	else
c42007
		failure
c42007
	fi
c42007
	echo
c42007
}
c42007
c42007
start() {
c42007
	if [ ! -x /usr/sbin/arptables ]; then
c42007
		exit 4
c42007
	fi
c42007
c42007
	# don't do squat if we don't have the config file
c42007
	if [ -f $ARPTABLES_CONFIG ]; then
c42007
		# If we don't clear these first, we might be adding to
c42007
		# pre-existing rules.
c42007
                flush_delete_chains
c42007
c42007
		for i in $(cat /proc/net/arp_tables_names 2>/dev/null); do
c42007
			arptables -t $i -Z;
c42007
		done
c42007
c42007
		echo -n $"Applying arptables firewall rules: "
c42007
		/usr/sbin/arptables-restore < $ARPTABLES_CONFIG && \
c42007
			success || \
c42007
			failure
c42007
		echo
c42007
		touch /var/lock/subsys/arptables
c42007
	else
c42007
		failure
c42007
		echo
c42007
		echo $"Configuration file /etc/sysconfig/arptables missing"
c42007
		exit 6
c42007
	fi
c42007
}
c42007
c42007
stop() {
c42007
        flush_delete_chains
c42007
	echo -n $"Resetting built-in chains to the default ACCEPT policy:"
c42007
	arp_table filter -P INPUT ACCEPT && \
c42007
		arp_table filter -P OUTPUT ACCEPT && \
c42007
		success || \
c42007
		failure
c42007
	echo
c42007
	rm -f /var/lock/subsys/arptables
c42007
}
c42007
c42007
case "$1" in
c42007
start)
c42007
	start
c42007
	;;
c42007
c42007
stop)
c42007
	stop
c42007
	;;
c42007
c42007
restart|reload)
c42007
	# "restart" is really just "start" as this isn't a daemon,
c42007
	# and "start" clears any pre-defined rules anyway.
c42007
	# This is really only here to make those who expect it happy
c42007
	start
c42007
	;;
c42007
c42007
condrestart|try-restart|force-reload)
c42007
	[ -e /var/lock/subsys/arptables ] && start
c42007
	;;
c42007
c42007
*)
c42007
	exit 2
c42007
esac
c42007
c42007
exit 0