2002-06-13 22:14:37 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: ipfw
|
2009-06-26 01:04:50 +00:00
|
|
|
# REQUIRE: ppp
|
2013-05-19 04:10:34 +00:00
|
|
|
# KEYWORD: nojailvnet
|
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"
|
2016-04-23 16:10:54 +00:00
|
|
|
desc="Firewall, traffic shaper, packet scheduler, in-kernel NAT"
|
2002-06-13 22:14:37 +00:00
|
|
|
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"
|
2017-07-13 13:32:23 +00:00
|
|
|
status_cmd="ipfw_status"
|
2006-12-31 10:37:18 +00:00
|
|
|
required_modules="ipfw"
|
2017-07-13 13:32:23 +00:00
|
|
|
extra_commands="status"
|
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
|
2012-10-29 06:31:51 +00:00
|
|
|
if checkyesno natd_enable; then
|
|
|
|
required_modules="$required_modules ipdivert"
|
|
|
|
fi
|
2009-03-30 21:31:52 +00:00
|
|
|
if checkyesno firewall_nat_enable; then
|
2012-10-29 06:31:51 +00:00
|
|
|
required_modules="$required_modules ipfw_nat"
|
2010-05-14 04:53:57 +00:00
|
|
|
fi
|
2019-03-23 15:41:32 +00:00
|
|
|
if checkyesno firewall_nat64_enable; then
|
|
|
|
required_modules="$required_modules ipfw_nat64"
|
|
|
|
fi
|
|
|
|
if checkyesno firewall_nptv6_enable; then
|
|
|
|
required_modules="$required_modules ipfw_nptv6"
|
|
|
|
fi
|
|
|
|
if checkyesno firewall_pmod_enable; then
|
|
|
|
required_modules="$required_modules ipfw_pmod"
|
|
|
|
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
|
|
|
|
|
2018-02-22 08:25:39 +00:00
|
|
|
if [ -n "${1}" ]; then
|
|
|
|
_firewall_type=$1
|
|
|
|
else
|
|
|
|
_firewall_type=${firewall_type}
|
|
|
|
fi
|
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' \
|
2020-07-13 13:44:54 +00:00
|
|
|
'firewall rules are not enabled.'
|
2002-06-13 22:14:37 +00:00
|
|
|
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.'
|
2017-05-03 08:10:03 +00:00
|
|
|
${SYSCTL} net.inet.ip.fw.verbose=1 >/dev/null
|
2003-03-30 15:52:18 +00:00
|
|
|
fi
|
2012-07-09 07:16:19 +00:00
|
|
|
if checkyesno firewall_logif; then
|
|
|
|
ifconfig ipfw0 create
|
|
|
|
echo 'Firewall logging pseudo-interface (ipfw0) created.'
|
|
|
|
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
|
|
|
|
#
|
2017-05-03 08:10:03 +00:00
|
|
|
if ! ${SYSCTL} net.inet.ip.fw.enable=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
|
2017-05-03 08:10:03 +00:00
|
|
|
if ! ${SYSCTL} net.inet6.ip6.fw.enable=1 >/dev/null 2>&1
|
2009-12-02 15:05:26 +00:00
|
|
|
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
|
|
|
|
#
|
2017-05-03 08:10:03 +00:00
|
|
|
${SYSCTL} net.inet.ip.fw.enable=0 >/dev/null
|
2009-12-02 15:05:26 +00:00
|
|
|
if afexists inet6; then
|
2017-05-03 08:10:03 +00:00
|
|
|
${SYSCTL} net.inet6.ip6.fw.enable=0 >/dev/null
|
2009-12-02 15:05:26 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-07-13 13:32:23 +00:00
|
|
|
ipfw_status()
|
|
|
|
{
|
2018-06-07 13:16:53 +00:00
|
|
|
status=$(sysctl -i -n net.inet.ip.fw.enable)
|
2020-01-21 17:16:02 +00:00
|
|
|
: ${status:=0}
|
2020-01-21 17:02:57 +00:00
|
|
|
if afexists inet6; then
|
2020-01-21 17:16:02 +00:00
|
|
|
status=$((${status} + $(sysctl -i -n net.inet6.ip6.fw.enable)))
|
2020-01-21 17:02:57 +00:00
|
|
|
fi
|
2020-01-21 17:16:02 +00:00
|
|
|
if [ ${status} -eq 0 ]; then
|
2018-06-07 13:14:09 +00:00
|
|
|
echo "ipfw is not enabled"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "ipfw is enabled"
|
|
|
|
exit 0
|
|
|
|
fi
|
2017-07-13 13:32:23 +00:00
|
|
|
}
|
|
|
|
|
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 $*
|