2001-06-16 07:16:14 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2002-06-13 22:14:37 +00:00
|
|
|
# $NetBSD: ipnat,v 1.6 2000/09/19 13:04:38 lukem Exp $
|
|
|
|
# $FreeBSD$
|
2001-06-16 07:16:14 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: ipnat
|
2003-04-24 08:20:47 +00:00
|
|
|
# REQUIRE: ipfilter
|
|
|
|
# BEFORE: DAEMON netif
|
2002-06-13 22:14:37 +00:00
|
|
|
# KEYWORD: FreeBSD NetBSD
|
2001-06-16 07:16:14 +00:00
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="ipnat"
|
2002-06-13 22:14:37 +00:00
|
|
|
rcvar=`set_rcvar`
|
2003-04-24 08:20:47 +00:00
|
|
|
load_rc_config $name
|
2002-06-13 22:14:37 +00:00
|
|
|
|
2002-09-06 16:18:05 +00:00
|
|
|
case ${OSTYPE} in
|
2002-06-13 22:14:37 +00:00
|
|
|
NetBSD)
|
2003-04-24 08:20:47 +00:00
|
|
|
ipnat_flags=
|
|
|
|
ipnat_rules="/etc/ipnat.conf"
|
|
|
|
ipnat_program="/usr/sbin/ipnat"
|
2002-06-13 22:14:37 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2003-04-24 08:20:47 +00:00
|
|
|
start_precmd="ipnat_precmd"
|
2001-06-16 07:16:14 +00:00
|
|
|
start_cmd="ipnat_start"
|
2003-04-24 08:20:47 +00:00
|
|
|
stop_cmd="${ipnat_program} -F -C"
|
|
|
|
reload_cmd="${ipnat_program} -F -C -f ${ipnat_rules}"
|
2001-06-16 07:16:14 +00:00
|
|
|
extra_commands="reload"
|
|
|
|
|
2002-06-13 22:14:37 +00:00
|
|
|
ipnat_precmd()
|
2001-06-16 07:16:14 +00:00
|
|
|
{
|
2003-04-24 08:20:47 +00:00
|
|
|
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
|
|
|
|
|
2002-06-13 22:14:37 +00:00
|
|
|
# Make sure ipfilter is loaded before continuing
|
2002-10-12 10:31:31 +00:00
|
|
|
if ! ${SYSCTL} net.inet.ipf.fr_pass >/dev/null 2>&1; then
|
2003-04-24 08:20:47 +00:00
|
|
|
if kldload ipl; then
|
2003-04-30 02:54:17 +00:00
|
|
|
info 'IP-filter module loaded.'
|
2003-04-24 08:20:47 +00:00
|
|
|
else
|
|
|
|
err 1 'IP-filter module failed to load.'
|
|
|
|
fi
|
2001-06-16 07:16:14 +00:00
|
|
|
fi
|
2002-06-13 22:14:37 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
ipnat_start()
|
|
|
|
{
|
2003-04-24 08:20:47 +00:00
|
|
|
if [ ! -f ${ipnat_rules} ]; then
|
2003-04-30 02:54:17 +00:00
|
|
|
warn 'NO IPNAT RULES'
|
2003-04-24 08:20:47 +00:00
|
|
|
return 0
|
|
|
|
fi
|
2003-04-30 02:54:17 +00:00
|
|
|
echo -n "Installing NAT rules."
|
2003-04-24 18:14:52 +00:00
|
|
|
${ipnat_program} -CF -f ${ipnat_rules} ${ipnat_flags}
|
2001-06-16 07:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
run_rc_command "$1"
|