summaryrefslogtreecommitdiffstats
path: root/etc/rc.d/ipnat
blob: 9285348d6f104fe210cc7e65fe62cb89af781238 (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
#!/bin/sh
#
# $NetBSD: ipnat,v 1.6 2000/09/19 13:04:38 lukem Exp $
# $FreeBSD$
#

# PROVIDE: ipnat
# REQUIRE: ipfilter
# BEFORE:  DAEMON netif
# KEYWORD: FreeBSD NetBSD

. /etc/rc.subr

name="ipnat"
rcvar=`set_rcvar`
load_rc_config $name

case ${OSTYPE} in
NetBSD)
	ipnat_flags=
	ipnat_rules="/etc/ipnat.conf"
	ipnat_program="/usr/sbin/ipnat"
	;;
esac

start_precmd="ipnat_precmd"
start_cmd="ipnat_start"
stop_cmd="${ipnat_program} -F -C"
reload_cmd="${ipnat_program} -F -C -f ${ipnat_rules}"
extra_commands="reload"

ipnat_precmd()
{
	case ${OSTYPE} in
	NetBSD)
		if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then	
			echo "Enabling ipfilter for NAT."
			/sbin/ipf -E -Fa
		fi
		return 0
		;;
	esac

	# Make sure ipfilter is loaded before continuing
	if ! ${SYSCTL} net.inet.ipf.fr_pass >/dev/null 2>&1; then
		if kldload ipl; then
			info 'IP-filter module loaded.'
		else
			err 1 'IP-filter module failed to load.'
		fi
	fi
	return 0
}

ipnat_start()
{
	if [ ! -f ${ipnat_rules} ]; then
		warn 'NO IPNAT RULES'
		return 0
	fi
	echo -n "Installing NAT rules."
	${ipnat_program} -CF -f ${ipnat_rules} ${ipnat_flags}
}

run_rc_command "$1"
OpenPOWER on IntegriCloud