2001-06-16 07:16:14 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2002-06-13 22:14:37 +00:00
|
|
|
# $FreeBSD$
|
2001-06-16 07:16:14 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: ipfilter
|
2007-04-09 08:53:40 +00:00
|
|
|
# REQUIRE: FILESYSTEMS
|
2004-10-07 13:55:26 +00:00
|
|
|
# KEYWORD: nojail
|
2001-06-16 07:16:14 +00:00
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="ipfilter"
|
2012-01-14 02:18:41 +00:00
|
|
|
rcvar="ipfilter_enable"
|
2002-06-13 22:14:37 +00:00
|
|
|
load_rc_config $name
|
2004-01-17 10:40:45 +00:00
|
|
|
stop_precmd="test -f ${ipfilter_rules} -o -f ${ipv6_ipfilter_rules}"
|
2002-06-13 22:14:37 +00:00
|
|
|
|
2006-12-31 10:37:18 +00:00
|
|
|
start_precmd="$stop_precmd"
|
2001-06-16 07:16:14 +00:00
|
|
|
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"
|
2011-05-17 07:40:13 +00:00
|
|
|
extra_commands="reload resync"
|
2006-12-31 10:37:18 +00:00
|
|
|
required_modules="ipl:ipfilter"
|
2001-06-16 07:16:14 +00:00
|
|
|
|
|
|
|
ipfilter_start()
|
|
|
|
{
|
|
|
|
echo "Enabling ipfilter."
|
2013-09-10 13:48:33 +00:00
|
|
|
if ! ${ipfilter_program:-/sbin/ipf} -V | grep -q 'Running: yes'; then
|
2004-01-17 10:40:45 +00:00
|
|
|
${ipfilter_program:-/sbin/ipf} -E
|
|
|
|
fi
|
|
|
|
${ipfilter_program:-/sbin/ipf} -Fa
|
|
|
|
if [ -r "${ipfilter_rules}" ]; then
|
|
|
|
${ipfilter_program:-/sbin/ipf} \
|
|
|
|
-f "${ipfilter_rules}" ${ipfilter_flags}
|
|
|
|
fi
|
|
|
|
if [ -r "${ipv6_ipfilter_rules}" ]; then
|
|
|
|
${ipfilter_program:-/sbin/ipf} -6 \
|
|
|
|
-f "${ipv6_ipfilter_rules}" ${ipfilter_flags}
|
|
|
|
fi
|
2001-06-16 07:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ipfilter_stop()
|
|
|
|
{
|
2013-09-10 13:48:33 +00:00
|
|
|
if ${ipfilter_program:-/sbin/ipf} -V | grep -q 'Running: yes'; then
|
2004-01-17 10:40:45 +00:00
|
|
|
echo "Saving firewall state tables"
|
|
|
|
${ipfs_program:-/sbin/ipfs} -W ${ipfs_flags}
|
|
|
|
echo "Disabling ipfilter."
|
|
|
|
${ipfilter_program:-/sbin/ipf} -D
|
2003-09-27 13:50:47 +00:00
|
|
|
fi
|
2001-06-16 07:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ipfilter_reload()
|
|
|
|
{
|
|
|
|
echo "Reloading ipfilter rules."
|
|
|
|
|
2004-01-17 10:40:45 +00:00
|
|
|
${ipfilter_program:-/sbin/ipf} -I -Fa
|
|
|
|
if [ -r "${ipfilter_rules}" ]; then
|
|
|
|
${ipfilter_program:-/sbin/ipf} -I \
|
|
|
|
-f "${ipfilter_rules}" ${ipfilter_flags}
|
2006-11-11 10:48:34 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
err 1 'Load of rules into alternate set failed; aborting reload'
|
|
|
|
fi
|
2004-01-17 10:40:45 +00:00
|
|
|
fi
|
|
|
|
if [ -r "${ipv6_ipfilter_rules}" ]; then
|
|
|
|
${ipfilter_program:-/sbin/ipf} -I -6 \
|
|
|
|
-f "${ipv6_ipfilter_rules}" ${ipfilter_flags}
|
2006-11-11 10:48:34 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
err 1 'Load of IPv6 rules into alternate set failed; aborting reload'
|
|
|
|
fi
|
2004-01-17 10:40:45 +00:00
|
|
|
fi
|
|
|
|
${ipfilter_program:-/sbin/ipf} -s
|
2002-06-13 22:14:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ipfilter_resync()
|
|
|
|
{
|
|
|
|
${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"
|