]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - etc/rc.d/pflog
MFC r277675,r277726,r278070:
[FreeBSD/stable/10.git] / etc / rc.d / pflog
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5
6 # PROVIDE: pflog
7 # REQUIRE: FILESYSTEMS netif FILESYSTEMS
8 # KEYWORD: nojail
9
10 . /etc/rc.subr
11
12 name="pflog"
13 rcvar="pflog_enable"
14 command="/sbin/pflogd"
15 pidfile="/var/run/pflogd.pid"
16 start_precmd="pflog_prestart"
17 stop_postcmd="pflog_poststop"
18 extra_commands="reload resync"
19
20 # for backward compatibility
21 resync_cmd="pflog_resync"
22
23 pflog_prestart()
24 {
25         load_kld pflog || return 1
26
27         # set pflog_dev interface to up state
28         if ! ifconfig $pflog_dev up; then
29                 warn "could not bring up $pflog_dev."
30                 return 1
31         fi
32
33         # prepare the command line for pflogd
34         rc_flags="-f $pflog_logfile -i $pflog_dev $rc_flags"
35
36         # report we're ready to run pflogd
37         return 0
38 }
39
40 pflog_poststart() {
41         # Allow child pflogd to settle
42         sleep 0.10
43         # More elegant(?) method for getting a unique pid
44         if [ -f /var/run/pflogd.pid ]; then
45                 mv /var/run/pflogd.pid $pidfile
46         else
47                 warn "/var/run/pflogd.pid does not exist. Too fast."
48         fi
49 }
50
51 pflog_poststop()
52 {
53         if ! ifconfig $pflog_dev down; then
54                 warn "could not bring down $pflog_dev."
55                 return 1
56         fi
57
58         if [ "$pflog_instances" ] && [ -n "$pflog_instances" ]; then
59                 rm $pidfile
60         fi
61
62         return 0
63 }
64
65 # for backward compatibility
66 pflog_resync()
67 {
68         run_rc_command reload
69 }
70
71 load_rc_config $name
72
73 # Check if spawning multiple pflogd
74 echo "Starting pflogd: $pflog_instances"
75 if [ "$pflog_instances" ] && [ -n "$pflog_instances" ]; then
76         start_postcmd="pflog_poststart"
77         # Interate through requested instances.
78         for i in $pflog_instances; do
79                 # Set required variables
80                 eval pflog_dev=\$pflog_${i}_dev
81                 eval pflog_logfile=\$pflog_${i}_logfile
82                 eval pflog_flags=\$pflog_${i}_flags
83                 # Check that required vars have non-zero length, warn if not.
84                 if [ -z $pflog_dev ]; then
85                         warn "pflog_dev not set"
86                         continue
87                 fi
88                 if [ -z $pflog_logfile ]; then
89                         warn "pflog_logfile not set"
90                         continue
91                 fi
92                 # pflogd sets a pidfile, but the name is hardcoded. Concoct a
93                 # unique pidfile name.
94                 pidfile="/var/run/pflogd.$i.pid"
95                 run_rc_command "$1"
96         done
97 else
98         # Typical case, spawn single instance only.
99         pflog_dev=${pflog_dev:-"pflog0"}
100         run_rc_command "$1"
101 fi