Merge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly
[dragonfly.git] / etc / rc.d / ipnat
1 #!/bin/sh
2 #
3 # $NetBSD: ipnat,v 1.6 2000/09/19 13:04:38 lukem Exp $
4 # $FreeBSD: src/etc/rc.d/ipnat,v 1.8 2003/04/30 02:54:17 mtm Exp $
5 # $DragonFly: src/etc/rc.d/ipnat,v 1.3 2005/11/19 21:47:32 swildner Exp $
6 #
7
8 # PROVIDE: ipnat
9 # REQUIRE: ipfilter
10 # BEFORE:  DAEMON netif
11
12 . /etc/rc.subr
13
14 name="ipnat"
15 rcvar=`set_rcvar`
16 load_rc_config $name
17
18
19 start_precmd="ipnat_precmd"
20 start_cmd="ipnat_start"
21 stop_cmd="${ipnat_program} -F -C"
22 reload_cmd="${ipnat_program} -F -C -f ${ipnat_rules}"
23 extra_commands="reload"
24
25 ipnat_precmd()
26 {
27
28         # Make sure ipfilter is loaded before continuing
29         if ! ${SYSCTL} net.inet.ipf.fr_pass >/dev/null 2>&1; then
30                 if kldload ipl; then
31                         info 'IP-filter module loaded.'
32                 else
33                         err 1 'IP-filter module failed to load.'
34                 fi
35         fi
36         return 0
37 }
38
39 ipnat_start()
40 {
41         if [ ! -f ${ipnat_rules} ]; then
42                 warn 'NO IPNAT RULES'
43                 return 0
44         fi
45         echo -n "Installing NAT rules."
46         ${ipnat_program} -CF -f ${ipnat_rules} ${ipnat_flags}
47 }
48
49 run_rc_command "$1"