xref: /freebsd/libexec/rc/rc.d/pflog (revision a259b98fa211ed87bfee58c575de4e2de94ee0fa)
1#!/bin/sh
2#
3#
4
5# PROVIDE: pflog
6# REQUIRE: FILESYSTEMS netif
7# KEYWORD: nojailvnet
8
9. /etc/rc.subr
10
11name="pflog"
12desc="Packet filter logging interface"
13rcvar="pflog_enable"
14command="/sbin/pflogd"
15pidfile="/var/run/pflogd.pid"
16start_precmd="pflog_prestart"
17stop_postcmd="pflog_poststop"
18extra_commands="reload resync"
19
20# no svcj options needed
21: ${pflog_svcj_options:=""}
22
23# for backward compatibility
24resync_cmd="pflog_resync"
25
26pflog_prestart()
27{
28	load_kld pflog || return 1
29
30	# Do we need to create more devices?
31	unit=${pflog_dev#pflog}
32	max=$(sysctl -n net.pflog.if_count)
33	if [ "$unit" -ge "$max" ]; then
34		sysctl net.pflog.if_count=$(expr ${unit} + 1)
35	fi
36
37	# -p flag requires stripping pidfile's leading /var/run and trailing .pid
38	pidfile=$(echo $pidfile | sed -e 's|/var/run/||' -e 's|.pid$||')
39
40	# prepare the command line for pflogd
41	rc_flags="-p $pidfile -f $pflog_logfile -i $pflog_dev $rc_flags"
42
43	# report we're ready to run pflogd
44	return 0
45}
46
47pflog_poststop()
48{
49	if [ "$pflog_instances" ] && [ -n "$pflog_instances" ]; then
50		rm $pidfile
51	fi
52
53	return 0
54}
55
56# for backward compatibility
57pflog_resync()
58{
59	run_rc_command reload
60}
61
62load_rc_config $name
63
64# precmd is not compatible with svcj
65pflog_svcj="NO"
66
67# Check if spawning multiple pflogd and told what to spawn
68if [ -n "$2" ]; then
69	# Set required variables
70	eval pflog_dev=\$pflog_${2}_dev
71	eval pflog_logfile=\$pflog_${2}_logfile
72	eval pflog_flags=\$pflog_${2}_flags
73	# Check that required vars have non-zero length, warn if not.
74	if [ -z $pflog_dev ]; then
75		warn "pflog_dev not set"
76		continue
77	fi
78	if [ -z $pflog_logfile ]; then
79		warn "pflog_logfile not set"
80		continue
81	fi
82
83	# Provide a unique pidfile name for pflogd -p <pidfile> flag
84	pidfile="/var/run/pflogd.$2.pid"
85
86	# Override service name and execute command
87	name=$pflog_dev
88	run_rc_command "$1"
89# Check if spawning multiple pflogd and not told what to spawn
90elif [ "$pflog_instances" ] && [ -n "$pflog_instances" ]; then
91	# Interate through requested instances.
92	for i in $pflog_instances; do
93		/etc/rc.d/pflog $1 $i
94	done
95else
96	# Typical case, spawn single instance only.
97	pflog_dev=${pflog_dev:-"pflog0"}
98	run_rc_command "$1"
99fi
100