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