Add separate script for natd. This fixes race condition with "ipfw restart"

(when new natd is started before old natd died) and allows to manage natd
without touching ipfw.

natd should probably be killed with SIGKILL when stopping natd.
This commit is contained in:
Max Khon 2004-04-05 16:29:45 +00:00
parent 299b2a180b
commit a3e34d6908
3 changed files with 45 additions and 28 deletions

View File

@ -21,7 +21,7 @@ FILES= DAEMON LOGIN NETWORKING SERVERS \
ldconfig local localpkg lomac lpd \
mixer motd mountcritlocal mountcritremote \
mountd moused mroute6d mrouted msgs \
named netif netoptions \
named natd netif netoptions \
network_ipv6 nfsclient nfsd \
nfslocking nfsserver nisdomain ntpd ntpdate \
othermta \

View File

@ -37,31 +37,7 @@ ipfw_start()
if [ -r "${firewall_script}" ]; then
. "${firewall_script}"
echo -n 'Firewall rules loaded, starting divert daemons:'
# Network Address Translation daemon
#
if checkyesno natd_enable; then
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}
fi
/etc/rc.d/natd start
elif [ "`ipfw l 65535`" = "65535 deny ip from any to any" ]; then
echo 'Warning: kernel has firewall functionality, but' \
' firewall rules are not enabled.'
@ -86,8 +62,7 @@ ipfw_stop()
# Disable the firewall
#
${SYSCTL_W} net.inet.ip.fw.enable=0
killall natd;
sleep 2;
/etc/rc.d/natd stop
}
load_rc_config $name

42
etc/rc.d/natd Normal file
View File

@ -0,0 +1,42 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: natd
# KEYWORD: FreeBSD nostart nojail
. /etc/rc.subr
. /etc/network.subr
name="natd"
rcvar=`set_rcvar`
command="/sbin/${name}"
start_cmd="natd_start"
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"