2002-06-13 22:14:37 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: ipfw
|
2009-06-26 01:04:50 +00:00
|
|
|
# REQUIRE: ppp
|
2004-10-07 13:55:26 +00:00
|
|
|
# KEYWORD: nojail
|
2002-06-13 22:14:37 +00:00
|
|
|
|
|
|
|
. /etc/rc.subr
|
2003-07-27 20:34:30 +00:00
|
|
|
. /etc/network.subr
|
2002-06-13 22:14:37 +00:00
|
|
|
|
|
|
|
name="ipfw"
|
|
|
|
rcvar="firewall_enable"
|
|
|
|
start_cmd="ipfw_start"
|
2008-01-27 15:15:12 +00:00
|
|
|
start_precmd="ipfw_prestart"
|
2010-02-08 18:51:24 +00:00
|
|
|
start_postcmd="ipfw_poststart"
|
2003-03-30 15:52:18 +00:00
|
|
|
stop_cmd="ipfw_stop"
|
2006-12-31 10:37:18 +00:00
|
|
|
required_modules="ipfw"
|
2002-06-13 22:14:37 +00:00
|
|
|
|
2009-12-02 15:05:26 +00:00
|
|
|
set_rcvar_obsolete ipv6_firewall_enable
|
|
|
|
|
2008-01-27 15:15:12 +00:00
|
|
|
ipfw_prestart()
|
|
|
|
{
|
|
|
|
if checkyesno dummynet_enable; then
|
|
|
|
required_modules="$required_modules dummynet"
|
|
|
|
fi
|
2009-03-30 21:31:52 +00:00
|
|
|
|
|
|
|
if checkyesno firewall_nat_enable; then
|
|
|
|
if ! checkyesno natd_enable; then
|
|
|
|
required_modules="$required_modules ipfw_nat"
|
|
|
|
fi
|
2010-05-14 04:53:57 +00:00
|
|
|
fi
|
2008-01-27 15:15:12 +00:00
|
|
|
}
|
|
|
|
|
2002-06-13 22:14:37 +00:00
|
|
|
ipfw_start()
|
|
|
|
{
|
2009-03-30 21:31:52 +00:00
|
|
|
local _firewall_type
|
|
|
|
|
2010-05-14 04:53:57 +00:00
|
|
|
_firewall_type=$1
|
2009-03-30 21:31:52 +00:00
|
|
|
|
2002-06-13 22:14:37 +00:00
|
|
|
# set the firewall rules script if none was specified
|
|
|
|
[ -z "${firewall_script}" ] && firewall_script=/etc/rc.firewall
|
|
|
|
|
|
|
|
if [ -r "${firewall_script}" ]; then
|
2009-03-30 21:31:52 +00:00
|
|
|
/bin/sh "${firewall_script}" "${_firewall_type}"
|
2006-07-25 17:28:18 +00:00
|
|
|
echo 'Firewall rules loaded.'
|
2006-02-26 16:45:29 +00:00
|
|
|
elif [ "`ipfw list 65535`" = "65535 deny ip from any to any" ]; then
|
2002-06-13 22:14:37 +00:00
|
|
|
echo 'Warning: kernel has firewall functionality, but' \
|
|
|
|
' firewall rules are not enabled.'
|
|
|
|
echo ' All ip services are disabled.'
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Firewall logging
|
|
|
|
#
|
2003-03-30 15:52:18 +00:00
|
|
|
if checkyesno firewall_logging; then
|
2006-07-25 17:28:18 +00:00
|
|
|
echo 'Firewall logging enabled.'
|
2003-03-30 15:52:18 +00:00
|
|
|
sysctl net.inet.ip.fw.verbose=1 >/dev/null
|
|
|
|
fi
|
2010-02-08 18:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ipfw_poststart()
|
|
|
|
{
|
|
|
|
local _coscript
|
|
|
|
|
|
|
|
# Start firewall coscripts
|
|
|
|
#
|
|
|
|
for _coscript in ${firewall_coscripts} ; do
|
|
|
|
if [ -f "${_coscript}" ]; then
|
|
|
|
${_coscript} quietstart
|
|
|
|
fi
|
|
|
|
done
|
2003-03-30 15:52:18 +00:00
|
|
|
|
|
|
|
# Enable the firewall
|
|
|
|
#
|
2008-07-05 15:27:39 +00:00
|
|
|
if ! ${SYSCTL_W} net.inet.ip.fw.enable=1 1>/dev/null 2>&1; then
|
2009-12-02 15:05:26 +00:00
|
|
|
warn "failed to enable IPv4 firewall"
|
|
|
|
fi
|
|
|
|
if afexists inet6; then
|
|
|
|
if ! ${SYSCTL_W} net.inet6.ip6.fw.enable=1 1>/dev/null 2>&1
|
|
|
|
then
|
|
|
|
warn "failed to enable IPv6 firewall"
|
|
|
|
fi
|
2008-07-05 15:27:39 +00:00
|
|
|
fi
|
2003-03-30 15:52:18 +00:00
|
|
|
}
|
2002-06-13 22:14:37 +00:00
|
|
|
|
2003-03-30 15:52:18 +00:00
|
|
|
ipfw_stop()
|
|
|
|
{
|
2010-02-08 18:51:24 +00:00
|
|
|
local _coscript
|
|
|
|
|
2003-03-30 15:52:18 +00:00
|
|
|
# Disable the firewall
|
|
|
|
#
|
|
|
|
${SYSCTL_W} net.inet.ip.fw.enable=0
|
2009-12-02 15:05:26 +00:00
|
|
|
if afexists inet6; then
|
|
|
|
${SYSCTL_W} net.inet6.ip6.fw.enable=0
|
|
|
|
fi
|
2010-02-08 18:51:24 +00:00
|
|
|
|
|
|
|
# Stop firewall coscripts
|
|
|
|
#
|
|
|
|
for _coscript in `reverse_list ${firewall_coscripts}` ; do
|
|
|
|
if [ -f "${_coscript}" ]; then
|
|
|
|
${_coscript} quietstop
|
|
|
|
fi
|
|
|
|
done
|
2002-06-13 22:14:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
load_rc_config $name
|
2010-02-08 18:51:24 +00:00
|
|
|
firewall_coscripts="/etc/rc.d/natd ${firewall_coscripts}"
|
|
|
|
|
2009-03-30 21:31:52 +00:00
|
|
|
run_rc_command $*
|