o Update dd(1) to accept capital letters (B, K, M, G) as size modifiers.
[dragonfly.git] / etc / rc.d / ipfilter
blob6615c438a51f59a2e8e84d9840304401a609a0be
1 #!/bin/sh
3 # $NetBSD: ipfilter,v 1.10 2001/02/28 17:03:50 lukem Exp $
4 # $FreeBSD: src/etc/rc.d/ipfilter,v 1.10 2003/04/30 02:54:17 mtm Exp $
5 # $DragonFly: src/etc/rc.d/ipfilter,v 1.7 2008/01/08 15:30:34 matthias Exp $
8 # PROVIDE: ipfilter
9 # REQUIRE: root mountcritlocal tty ipmon
10 # BEFORE: netif
11 # KEYWORD: nojail
13 . /etc/rc.subr
15 name="ipfilter"
16 rcvar=`set_rcvar`
17 load_rc_config $name
18 stop_precmd="test -f ${ipfilter_rules} -o -f ${ipv6_ipfilter_rules}"
20 start_precmd="ipfilter_prestart"
21 start_cmd="ipfilter_start"
22 stop_cmd="ipfilter_stop"
23 reload_precmd="$stop_precmd"
24 reload_cmd="ipfilter_reload"
25 resync_precmd="$stop_precmd"
26 resync_cmd="ipfilter_resync"
27 status_precmd="$stop_precmd"
28 status_cmd="ipfilter_status"
29 extra_commands="reload resync status"
31 ipfilter_loaded()
33 if [ `kldstat -q -m "ipl"` -eq 1 ]; then
34 return 1
35 else
36 return 0
40 ipfilter_prestart()
42 # load ipfilter kernel module if needed
43 if ! ipfilter_loaded; then
44 if kldload ipl; then
45 info 'IP-filter module loaded.'
46 else
47 err 1 'IP-filter module failed to load.'
51 # check for ipfilter rules
52 if [ ! -r "${ipfilter_rules}" ] && [ ! -r "${ipv6_ipfilter_rules}" ]
53 then
54 warn 'IP-filter: NO IPF RULES'
55 return 1
57 return 0
60 ipfilter_start()
62 echo "Enabling ipfilter."
63 if [ `sysctl -n net.inet.ipf.fr_running` -eq 0 ]; then
64 ${ipfilter_program:-/sbin/ipf} -E
66 ${ipfilter_program:-/sbin/ipf} -Fa
67 if [ -r "${ipfilter_rules}" ]; then
68 ${ipfilter_program:-/sbin/ipf} \
69 -f "${ipfilter_rules}" ${ipfilter_flags}
71 ${ipfilter_program:-/sbin/ipf} -6 -Fa
72 if [ -r "${ipv6_ipfilter_rules}" ]; then
73 ${ipfilter_program:-/sbin/ipf} -6 \
74 -f "${ipv6_ipfilter_rules}" ${ipfilter_flags}
78 ipfilter_stop()
80 # XXX - The ipf -D command is not effective for 'lkm's
81 if [ `sysctl -n net.inet.ipf.fr_running` -eq 1 ]; then
82 echo "Saving firewall state tables"
83 ${ipfs_program:-/sbin/ipfs} -W ${ipfs_flags}
84 echo "Disabling ipfilter."
85 ${ipfilter_program:-/sbin/ipf} -D
89 ipfilter_reload()
91 echo "Reloading ipfilter rules."
93 ${ipfilter_program:-/sbin/ipf} -I -Fa
94 if [ -r "${ipfilter_rules}" ]; then
95 ${ipfilter_program:-/sbin/ipf} -I \
96 -f "${ipfilter_rules}" ${ipfilter_flags}
98 ${ipfilter_program:-/sbin/ipf} -I -6 -Fa
99 if [ -r "${ipv6_ipfilter_rules}" ]; then
100 ${ipfilter_program:-/sbin/ipf} -I -6 \
101 -f "${ipv6_ipfilter_rules}" ${ipfilter_flags}
103 ${ipfilter_program:-/sbin/ipf} -s
107 ipfilter_resync()
109 # Don't resync if ipfilter is not loaded
110 if ! ipfilter_loaded; then
111 return
113 ${ipfilter_program:-/sbin/ipf} -y ${ipfilter_flags}
116 ipfilter_status()
118 ${ipfilter_program:-/sbin/ipf} -V
121 run_rc_command "$1"