summaryrefslogtreecommitdiffstats
path: root/etc/rc.d/ipfw
blob: dd7ab55a400bf6f7a4030ba47c4f3335d1551f05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: ipfw
# REQUIRE: ppp
# KEYWORD: nojail

. /etc/rc.subr
. /etc/network.subr

name="ipfw"
rcvar="firewall_enable"
start_cmd="ipfw_start"
start_precmd="ipfw_prestart"
stop_cmd="ipfw_stop"
required_modules="ipfw"

set_rcvar_obsolete ipv6_firewall_enable

ipfw_prestart()
{
	if checkyesno dummynet_enable; then
		required_modules="$required_modules dummynet"
	fi

	if checkyesno firewall_nat_enable; then
		if ! checkyesno natd_enable; then
			required_modules="$required_modules ipfw_nat"
		fi
	fi 
}

ipfw_start()
{
	local   _firewall_type

	_firewall_type=$1 

	# set the firewall rules script if none was specified
	[ -z "${firewall_script}" ] && firewall_script=/etc/rc.firewall

	if [ -r "${firewall_script}" ]; then
		if [ -f /etc/rc.d/natd ] ; then
			/etc/rc.d/natd quietstart
		fi
		/bin/sh "${firewall_script}" "${_firewall_type}"
		echo 'Firewall rules loaded.'
	elif [ "`ipfw list 65535`" = "65535 deny ip from any to any" ]; then
		echo 'Warning: kernel has firewall functionality, but' \
		    ' firewall rules are not enabled.'
		echo '           All ip services are disabled.'
	fi

	# Firewall logging
	#
	if checkyesno firewall_logging; then
		echo 'Firewall logging enabled.'
		sysctl net.inet.ip.fw.verbose=1 >/dev/null
	fi

	# Enable the firewall
	#
	if ! ${SYSCTL_W} net.inet.ip.fw.enable=1 1>/dev/null 2>&1; then
		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
	fi
}

ipfw_stop()
{
	# Disable the firewall
	#
	${SYSCTL_W} net.inet.ip.fw.enable=0
	if afexists inet6; then
		${SYSCTL_W} net.inet6.ip6.fw.enable=0
	fi
	if [ -f /etc/rc.d/natd ] ; then
		/etc/rc.d/natd quietstop
	fi
}

load_rc_config $name
run_rc_command $*
OpenPOWER on IntegriCloud