2001-06-16 07:16:14 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2002-06-13 22:14:37 +00:00
|
|
|
# $NetBSD: ipfilter,v 1.10 2001/02/28 17:03:50 lukem Exp $
|
|
|
|
# $FreeBSD$
|
2001-06-16 07:16:14 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: ipfilter
|
2003-07-30 18:53:59 +00:00
|
|
|
# REQUIRE: root beforenetlkm mountcritlocal ipmon
|
2003-04-24 08:20:47 +00:00
|
|
|
# BEFORE: netif
|
2002-06-13 22:14:37 +00:00
|
|
|
# KEYWORD: FreeBSD NetBSD
|
2001-06-16 07:16:14 +00:00
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="ipfilter"
|
2002-06-13 22:14:37 +00:00
|
|
|
rcvar=`set_rcvar`
|
|
|
|
load_rc_config $name
|
|
|
|
|
2002-09-06 16:18:05 +00:00
|
|
|
case ${OSTYPE} in
|
2002-06-13 22:14:37 +00:00
|
|
|
FreeBSD)
|
2002-11-02 08:21:26 +00:00
|
|
|
stop_precmd="test -f ${ipfilter_rules} -o -f ${ipv6_ipfilter_rules}"
|
2002-06-13 22:14:37 +00:00
|
|
|
;;
|
|
|
|
NetBSD)
|
|
|
|
stop_precmd="test -f /etc/ipf.conf -o -f /etc/ipf6.conf"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2001-06-16 07:16:14 +00:00
|
|
|
start_precmd="ipfilter_prestart"
|
|
|
|
start_cmd="ipfilter_start"
|
|
|
|
stop_cmd="ipfilter_stop"
|
|
|
|
reload_precmd="$stop_precmd"
|
|
|
|
reload_cmd="ipfilter_reload"
|
2002-06-13 22:14:37 +00:00
|
|
|
resync_precmd="$stop_precmd"
|
|
|
|
resync_cmd="ipfilter_resync"
|
2001-06-16 07:16:14 +00:00
|
|
|
status_precmd="$stop_precmd"
|
|
|
|
status_cmd="ipfilter_status"
|
2002-06-13 22:14:37 +00:00
|
|
|
extra_commands="reload resync status"
|
2001-06-16 07:16:14 +00:00
|
|
|
|
|
|
|
ipfilter_prestart()
|
|
|
|
{
|
2002-09-06 16:18:05 +00:00
|
|
|
case ${OSTYPE} in
|
2002-06-13 22:14:37 +00:00
|
|
|
FreeBSD)
|
|
|
|
# load ipfilter kernel module if needed
|
2003-09-27 13:50:47 +00:00
|
|
|
if ! kldstat -v | grep "IP Filter" > /dev/null 2>&1; then
|
2002-10-12 10:31:31 +00:00
|
|
|
if kldload ipl; then
|
2003-04-30 02:54:17 +00:00
|
|
|
info 'IP-filter module loaded.'
|
2002-06-13 22:14:37 +00:00
|
|
|
else
|
2003-04-24 08:20:47 +00:00
|
|
|
err 1 'IP-filter module failed to load.'
|
2002-06-13 22:14:37 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check for ipfilter rules
|
2002-11-02 08:21:26 +00:00
|
|
|
if [ ! -r "${ipfilter_rules}" ] && [ ! -r "${ipv6_ipfilter_rules}" ]
|
|
|
|
then
|
2002-06-13 22:14:37 +00:00
|
|
|
warn 'IP-filter: NO IPF RULES'
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
NetBSD)
|
2001-06-16 07:16:14 +00:00
|
|
|
if [ ! -f /etc/ipf.conf ] && [ ! -f /etc/ipf6.conf ]; then
|
|
|
|
warn "/etc/ipf*.conf not readable; ipfilter start aborted."
|
|
|
|
#
|
|
|
|
# If booting directly to multiuser, send SIGTERM to
|
|
|
|
# the parent (/etc/rc) to abort the boot
|
|
|
|
#
|
|
|
|
if [ "$autoboot" = yes ]; then
|
|
|
|
echo "ERROR: ABORTING BOOT (sending SIGTERM to parent)!"
|
|
|
|
kill -TERM $$
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
fi
|
2002-06-13 22:14:37 +00:00
|
|
|
;;
|
|
|
|
esac
|
2001-06-16 07:16:14 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
ipfilter_start()
|
|
|
|
{
|
|
|
|
echo "Enabling ipfilter."
|
2002-09-06 16:18:05 +00:00
|
|
|
case ${OSTYPE} in
|
2002-06-13 22:14:37 +00:00
|
|
|
FreeBSD)
|
2003-09-27 13:50:47 +00:00
|
|
|
if [ `sysctl -n net.inet.ipf.fr_running` -eq 0 ]; then
|
|
|
|
${ipfilter_program:-/sbin/ipf} -E
|
2003-10-13 08:20:55 +00:00
|
|
|
fi
|
2003-09-27 13:50:47 +00:00
|
|
|
${ipfilter_program:-/sbin/ipf} -Fa
|
2002-11-02 08:21:26 +00:00
|
|
|
if [ -r "${ipfilter_rules}" ]; then
|
|
|
|
${ipfilter_program:-/sbin/ipf} \
|
|
|
|
-f "${ipfilter_rules}" ${ipfilter_flags}
|
|
|
|
fi
|
2003-09-27 13:50:47 +00:00
|
|
|
${ipfilter_program:-/sbin/ipf} -6 -Fa
|
2002-11-02 08:21:26 +00:00
|
|
|
if [ -r "${ipv6_ipfilter_rules}" ]; then
|
|
|
|
${ipfilter_program:-/sbin/ipf} -6 \
|
|
|
|
-f "${ipv6_ipfilter_rules}" ${ipfilter_flags}
|
|
|
|
fi
|
2002-06-13 22:14:37 +00:00
|
|
|
;;
|
|
|
|
NetBSD)
|
|
|
|
/sbin/ipf -E -Fa
|
|
|
|
if [ -f /etc/ipf.conf ]; then
|
|
|
|
/sbin/ipf -f /etc/ipf.conf
|
|
|
|
fi
|
|
|
|
if [ -f /etc/ipf6.conf ]; then
|
|
|
|
/sbin/ipf -6 -f /etc/ipf6.conf
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2001-06-16 07:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ipfilter_stop()
|
|
|
|
{
|
2003-09-27 13:50:47 +00:00
|
|
|
# XXX - The ipf -D command is not effective for 'lkm's
|
|
|
|
if [ `sysctl -n net.inet.ipf.fr_running` -eq 1 ]; then
|
|
|
|
case ${OSTYPE} in
|
|
|
|
FreeBSD)
|
|
|
|
echo "Saving firewall state tables"
|
|
|
|
${ipfs_program:-/sbin/ipfs} -W ${ipfs_flags}
|
|
|
|
echo "Disabling ipfilter."
|
|
|
|
${ipfilter_program:-/sbin/ipf} -D
|
|
|
|
;;
|
|
|
|
NetBSD)
|
|
|
|
echo "Disabling ipfilter."
|
|
|
|
/sbin/ipf -D
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2001-06-16 07:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ipfilter_reload()
|
|
|
|
{
|
|
|
|
echo "Reloading ipfilter rules."
|
|
|
|
|
2002-09-06 16:18:05 +00:00
|
|
|
case ${OSTYPE} in
|
2002-06-13 22:14:37 +00:00
|
|
|
FreeBSD)
|
2002-11-02 08:21:26 +00:00
|
|
|
${ipfilter_program:-/sbin/ipf} -I -Fa
|
|
|
|
if [ -r "${ipfilter_rules}" ]; then
|
|
|
|
${ipfilter_program:-/sbin/ipf} -I \
|
|
|
|
-f "${ipfilter_rules}" ${ipfilter_flags}
|
|
|
|
fi
|
2003-03-05 17:16:22 +00:00
|
|
|
${ipfilter_program:-/sbin/ipf} -I -6 -Fa
|
2002-11-02 08:21:26 +00:00
|
|
|
if [ -r "${ipv6_ipfilter_rules}" ]; then
|
|
|
|
${ipfilter_program:-/sbin/ipf} -I -6 \
|
|
|
|
-f "${ipv6_ipfilter_rules}" ${ipfilter_flags}
|
|
|
|
fi
|
2003-03-22 14:53:23 +00:00
|
|
|
${ipfilter_program:-/sbin/ipf} -s
|
2002-06-13 22:14:37 +00:00
|
|
|
;;
|
|
|
|
NetBSD)
|
|
|
|
/sbin/ipf -I -Fa
|
|
|
|
if [ -f /etc/ipf.conf ] && ! /sbin/ipf -I -f /etc/ipf.conf; then
|
|
|
|
err 1 "reload of ipf.conf failed; not swapping to" \
|
|
|
|
" new ruleset."
|
|
|
|
fi
|
|
|
|
if [ -f /etc/ipf6.conf ] && \
|
|
|
|
! /sbin/ipf -I -6 -f /etc/ipf6.conf; then
|
|
|
|
err 1 "reload of ipf6.conf failed; not swapping to" \
|
|
|
|
" new ruleset."
|
|
|
|
fi
|
|
|
|
/sbin/ipf -s
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ipfilter_resync()
|
|
|
|
{
|
2002-09-06 16:18:05 +00:00
|
|
|
case ${OSTYPE} in
|
2002-06-13 22:14:37 +00:00
|
|
|
FreeBSD)
|
|
|
|
# Don't resync if ipfilter is not loaded
|
2003-10-03 11:57:43 +00:00
|
|
|
if ! kldstat -v | grep "IP Filter" > /dev/null 2>&1; then
|
|
|
|
return
|
|
|
|
fi
|
2002-06-13 22:14:37 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
${ipfilter_program:-/sbin/ipf} -y ${ipfilter_flags}
|
2001-06-16 07:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ipfilter_status()
|
|
|
|
{
|
2002-06-13 22:14:37 +00:00
|
|
|
${ipfilter_program:-/sbin/ipf} -V
|
2001-06-16 07:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
run_rc_command "$1"
|