2004-04-02 19:25:27 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: pflog
|
2014-11-30 12:34:48 +00:00
|
|
|
# REQUIRE: FILESYSTEMS netif
|
2004-10-07 13:55:26 +00:00
|
|
|
# KEYWORD: nojail
|
2004-04-02 19:25:27 +00:00
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="pflog"
|
2016-04-23 16:10:54 +00:00
|
|
|
desc="Packet filter logging interface"
|
2012-01-14 02:18:41 +00:00
|
|
|
rcvar="pflog_enable"
|
2005-10-02 15:54:26 +00:00
|
|
|
command="/sbin/pflogd"
|
|
|
|
pidfile="/var/run/pflogd.pid"
|
2004-04-02 19:25:27 +00:00
|
|
|
start_precmd="pflog_prestart"
|
2005-10-02 15:54:26 +00:00
|
|
|
stop_postcmd="pflog_poststop"
|
|
|
|
extra_commands="reload resync"
|
|
|
|
|
|
|
|
# for backward compatibility
|
2004-04-02 19:25:27 +00:00
|
|
|
resync_cmd="pflog_resync"
|
|
|
|
|
|
|
|
pflog_prestart()
|
|
|
|
{
|
2006-12-31 10:37:18 +00:00
|
|
|
load_kld pflog || return 1
|
2004-04-02 19:25:27 +00:00
|
|
|
|
2015-04-05 17:09:58 +00:00
|
|
|
# create pflog_dev interface if needed
|
|
|
|
if ! ifconfig $pflog_dev > /dev/null 2>&1; then
|
|
|
|
if ! ifconfig $pflog_dev create; then
|
|
|
|
warn "could not create $pflog_dev."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-11-13 03:50:31 +00:00
|
|
|
# set pflog_dev interface to up state
|
|
|
|
if ! ifconfig $pflog_dev up; then
|
|
|
|
warn "could not bring up $pflog_dev."
|
2004-04-02 19:25:27 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2015-04-06 19:23:45 +00:00
|
|
|
# -p flag requires stripping pidfile's leading /var/run and trailing .pid
|
2015-04-05 17:09:58 +00:00
|
|
|
pidfile=$(echo $pidfile | sed -e 's|/var/run/||' -e 's|.pid$||')
|
|
|
|
|
2005-10-02 15:54:26 +00:00
|
|
|
# prepare the command line for pflogd
|
2015-04-05 17:09:58 +00:00
|
|
|
rc_flags="-p $pidfile -f $pflog_logfile -i $pflog_dev $rc_flags"
|
2004-04-02 19:25:27 +00:00
|
|
|
|
2005-10-02 15:54:26 +00:00
|
|
|
# report we're ready to run pflogd
|
|
|
|
return 0
|
2004-04-02 19:25:27 +00:00
|
|
|
}
|
|
|
|
|
2005-10-02 15:54:26 +00:00
|
|
|
pflog_poststop()
|
2004-04-02 19:25:27 +00:00
|
|
|
{
|
2013-11-13 03:50:31 +00:00
|
|
|
if ! ifconfig $pflog_dev down; then
|
|
|
|
warn "could not bring down $pflog_dev."
|
2005-10-02 15:54:26 +00:00
|
|
|
return 1
|
2004-04-02 19:25:27 +00:00
|
|
|
fi
|
2013-11-13 03:50:31 +00:00
|
|
|
|
|
|
|
if [ "$pflog_instances" ] && [ -n "$pflog_instances" ]; then
|
|
|
|
rm $pidfile
|
|
|
|
fi
|
|
|
|
|
2005-10-02 15:54:26 +00:00
|
|
|
return 0
|
2004-04-02 19:25:27 +00:00
|
|
|
}
|
|
|
|
|
2005-10-02 15:54:26 +00:00
|
|
|
# for backward compatibility
|
|
|
|
pflog_resync()
|
2004-04-02 19:25:27 +00:00
|
|
|
{
|
2005-10-02 15:54:26 +00:00
|
|
|
run_rc_command reload
|
2004-04-02 19:25:27 +00:00
|
|
|
}
|
|
|
|
|
2005-10-02 15:54:26 +00:00
|
|
|
load_rc_config $name
|
2013-11-13 03:50:31 +00:00
|
|
|
|
2015-04-05 17:09:58 +00:00
|
|
|
# Check if spawning multiple pflogd and told what to spawn
|
|
|
|
if [ -n "$2" ]; then
|
|
|
|
# Set required variables
|
|
|
|
eval pflog_dev=\$pflog_${2}_dev
|
|
|
|
eval pflog_logfile=\$pflog_${2}_logfile
|
|
|
|
eval pflog_flags=\$pflog_${2}_flags
|
|
|
|
# Check that required vars have non-zero length, warn if not.
|
|
|
|
if [ -z $pflog_dev ]; then
|
|
|
|
warn "pflog_dev not set"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [ -z $pflog_logfile ]; then
|
|
|
|
warn "pflog_logfile not set"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Provide a unique pidfile name for pflogd -p <pidfile> flag
|
|
|
|
pidfile="/var/run/pflogd.$2.pid"
|
|
|
|
|
|
|
|
# Override service name and execute command
|
|
|
|
name=$pflog_dev
|
|
|
|
run_rc_command "$1"
|
|
|
|
# Check if spawning multiple pflogd and not told what to spawn
|
|
|
|
elif [ "$pflog_instances" ] && [ -n "$pflog_instances" ]; then
|
2013-11-13 03:50:31 +00:00
|
|
|
# Interate through requested instances.
|
|
|
|
for i in $pflog_instances; do
|
2015-04-05 17:09:58 +00:00
|
|
|
/etc/rc.d/pflog $1 $i
|
2013-11-13 03:50:31 +00:00
|
|
|
done
|
|
|
|
else
|
|
|
|
# Typical case, spawn single instance only.
|
|
|
|
pflog_dev=${pflog_dev:-"pflog0"}
|
|
|
|
run_rc_command "$1"
|
|
|
|
fi
|