summaryrefslogtreecommitdiffstats
path: root/etc/rc.d/natd
blob: 60e9e15f687bdf5fe0caa9231662c766b6502cb8 (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
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: natd
# KEYWORD: nostart nojail

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

name="natd"
rcvar=`set_rcvar`
command="/sbin/${name}"
start_precmd="natd_precmd"
start_cmd="natd_start"

natd_precmd()
{
	if ! ${SYSCTL} net.inet.divert > /dev/null 2>&1; then
		if ! kldload ipdivert; then
			warn unable to load IPDIVERT module.
			return 1
		fi
	fi

	return 0
}

natd_start()
{
	dhcp_list="`list_net_interfaces dhcp`"
	for ifn in ${dhcp_list}; do
		case ${natd_interface} in
		${ifn})
			natd_flags="$natd_flags -dynamic"
			;;
		*)
			;;
		esac
	done
	if [ -n "${natd_interface}" ]; then
		if echo ${natd_interface} | \
		grep -q -E '^[0-9]+(\.[0-9]+){0,3}$'; then
			natd_flags="$natd_flags -a ${natd_interface}"
		else
			natd_flags="$natd_flags -n ${natd_interface}"
		fi
	fi
	echo -n ' natd'
	${natd_program:-/sbin/natd} ${natd_flags} ${natd_ifarg}
}

load_rc_config $name
run_rc_command "$1"
OpenPOWER on IntegriCloud