1#!/bin/sh 2#
| 1#!/bin/sh 2#
|
3# $NetBSD: ipnat,v 1.5 2000/08/21 23:33:50 lukem Exp $
| 3# $NetBSD: ipnat,v 1.6 2000/09/19 13:04:38 lukem Exp $ 4# $FreeBSD: head/etc/rc.d/ipnat 98184 2002-06-13 22:14:37Z gordon $
|
4# 5 6# PROVIDE: ipnat 7# REQUIRE: ipfilter mountcritremote
| 5# 6 7# PROVIDE: ipnat 8# REQUIRE: ipfilter mountcritremote
|
| 9# BEFORE: DAEMON 10# KEYWORD: FreeBSD NetBSD
|
8 9. /etc/rc.subr 10 11name="ipnat"
| 11 12. /etc/rc.subr 13 14name="ipnat"
|
12rcvar=$name 13config="/etc/ipnat.conf"
| 15rcvar=`set_rcvar` 16 17case `${CMD_OSTYPE}` in 18FreeBSD) 19 IPNATDIR="/sbin" 20 start_precmd="ipnat_precmd" 21 reload_cmd="ipnat_start" 22 ;; 23NetBSD) 24 IPNATDIR="/usr/sbin" 25 config="/etc/ipnat.conf" 26 reload_cmd="/usr/sbin/ipnat -F -C -f ${config}" 27 start_precmd= 28 ;; 29esac 30
|
14start_cmd="ipnat_start"
| 31start_cmd="ipnat_start"
|
15stop_cmd="/usr/sbin/ipnat -F -C" 16reload_cmd="/usr/sbin/ipnat -F -C -f ${config}"
| 32stop_cmd="${ipnat_program:-${IPNATDIR}/${name}} -F -C"
|
17extra_commands="reload" 18
| 33extra_commands="reload" 34
|
19ipnat_start()
| 35ipnat_precmd()
|
20{
| 36{
|
21 if [ ! -f ${config} ]; then 22 return 0
| 37 # Make sure ipfilter is loaded before continuing 38 if ! ${SYSCTL} net.inet.ipf.fr_pass >/dev/null 2>&1 ; then 39 err 'ipnat requires ipfilter be loaded' 40 return 1
|
23 fi
| 41 fi
|
24 if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then 25 echo "Enabling ipfilter for NAT." 26 /sbin/ipf -E -Fa 27 fi 28 echo -n "Installing NAT rules ... " 29 /usr/sbin/ipnat -F -f ${config}
| 42 return 0
|
30} 31
| 43} 44
|
| 45ipnat_start() 46{ 47 case `${CMD_OSTYPE}` in 48 FreeBSD) 49 echo -n 'Installing NAT rules ... ' 50 if [ -r "${ipnat_rules}" ]; then 51 ${ipnat_program:-/sbin/ipnat} -CF -f \ 52 "${ipnat_rules}" ${ipnat_flags} 53 else 54 echo -n ' NO IPNAT RULES' 55 fi 56 echo '.' 57 58 # restore filter/NAT state tables after loading the rules 59 if checkyesno ipfs_enable ; then 60 if [ -r "/var/db/ipf/ipstate.ipf" ]; then 61 echo -n ' ipfs' 62 ${ipfs_program:-/sbin/ipfs} -R ${ipfs_flags} 63 # remove files to avoid reloading old state 64 # after an ungraceful shutdown 65 rm -f /var/db/ipf/ipstate.ipf 66 rm -f /var/db/ipf/ipnat.ipf 67 fi 68 fi 69 ;; 70 NetBSD) 71 if [ ! -f ${config} ]; then 72 return 0 73 fi 74 if ! checkyesno ipfilter || [ ! -f /etc/ipf.conf ]; then 75 echo "Enabling ipfilter for NAT." 76 /sbin/ipf -E -Fa 77 fi 78 echo -n "Installing NAT rules ... " 79 /usr/sbin/ipnat -F -f ${config} 80 ;; 81 esac 82} 83
|
32load_rc_config $name 33run_rc_command "$1"
| 84load_rc_config $name 85run_rc_command "$1"
|