2005-02-28 13:34:58 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: ng_ipacct
|
|
|
|
# REQUIRE: LOGIN abi
|
|
|
|
# BEFORE: securelevel
|
|
|
|
# KEYWORD: shutdown
|
|
|
|
|
|
|
|
#
|
|
|
|
# Define these ng_ipacct_* variables in one of these files:
|
|
|
|
#
|
|
|
|
# /etc/rc.conf
|
|
|
|
# /etc/rc.conf.local
|
|
|
|
# /etc/rc.conf.d/ng_ipacct
|
|
|
|
# %%PREFIX%%/etc/ng_ipacct.conf
|
|
|
|
#
|
|
|
|
# Add the following line to enable `ng_ipacct':
|
|
|
|
#
|
2009-07-15 18:56:10 +02:00
|
|
|
# ng_ipacct_enable="YES"
|
|
|
|
# ng_ipacct_flags="<set as needed>"
|
2005-02-28 13:34:58 +01:00
|
|
|
#
|
|
|
|
# See %%PREFIX%%/etc/ng_ipacct.conf for futher reference.
|
|
|
|
|
2010-03-27 01:15:24 +01:00
|
|
|
. /etc/rc.subr
|
2005-02-28 13:34:58 +01:00
|
|
|
|
|
|
|
name="ng_ipacct"
|
|
|
|
rcvar=`set_rcvar`
|
|
|
|
|
|
|
|
# for debugging purpose you can append flag "-d" to these cmds
|
|
|
|
# or even use dumb stubs.
|
|
|
|
ngctl="/usr/sbin/ngctl"
|
|
|
|
ngctl_batch="/usr/sbin/ngctl -f-"
|
|
|
|
#ngctl_batch="cat"
|
|
|
|
ipacctctl="%%PREFIX%%/sbin/ipacctctl"
|
|
|
|
#ipacctctl="echo %%PREFIX%%/sbin/ipacctctl"
|
|
|
|
sed="/usr/bin/sed"
|
|
|
|
|
2005-04-02 18:34:45 +02:00
|
|
|
extra_commands="checkpoint"
|
2005-02-28 13:34:58 +01:00
|
|
|
start_cmd="start_cmd"
|
|
|
|
stop_cmd="stop_cmd"
|
2005-04-02 18:34:45 +02:00
|
|
|
checkpoint_cmd="checkpoint_cmd"
|
2005-02-28 13:34:58 +01:00
|
|
|
|
|
|
|
bool2int()
|
|
|
|
{
|
|
|
|
eval _value=\$${1}
|
|
|
|
case $_value in
|
|
|
|
# "yes", "true", "on", or "1"
|
|
|
|
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
|
|
|
|
eval $1=1
|
|
|
|
;;
|
|
|
|
# "no", "false", "off", or "0"
|
|
|
|
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
|
|
|
|
eval $1=0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "\$${1} is not set properly - see rc.conf(5)."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
start_cmd()
|
|
|
|
{
|
|
|
|
if checkyesno ng_ipacct_modules_load; then
|
|
|
|
debug "Load kld modules '${ng_ipacct_modules_list}'"
|
|
|
|
local module
|
|
|
|
for module in ${ng_ipacct_modules_list}; do
|
|
|
|
if ! /sbin/kldstat -n ${module} >/dev/null 2>&1; then
|
|
|
|
if ! /sbin/kldload ${module} >/dev/null; then
|
|
|
|
warn "can not load kld module ${module}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
local iface
|
|
|
|
|
|
|
|
for iface in ${ng_ipacct_interfaces}; do
|
|
|
|
debug "start ng_ipacct interface ${iface}"
|
|
|
|
local dlt threshold verbose saveuid savetime start_script
|
|
|
|
|
|
|
|
eval dlt=\$ng_ipacct_${iface}_dlt
|
|
|
|
if [ -z "$dlt" ]; then
|
|
|
|
echo " you must define 'ng_ipacct_${iface}_dlt'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
eval start_script=\$ng_ipacct_${iface}_start
|
|
|
|
if [ -z "$start_script" ]; then
|
|
|
|
echo " you must define 'ng_ipacct_${iface}_start'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
eval threshold=\${ng_ipacct_${iface}_threshold:-"5000"}
|
|
|
|
|
|
|
|
eval verbose=\${ng_ipacct_${iface}_verbose:-"yes"}
|
|
|
|
bool2int verbose
|
|
|
|
|
|
|
|
eval saveuid=\${ng_ipacct_${iface}_saveuid:-"no"}
|
|
|
|
bool2int saveuid
|
|
|
|
|
|
|
|
eval savetime=\${ng_ipacct_${iface}_savetime:-"no"}
|
|
|
|
bool2int savetime
|
|
|
|
|
|
|
|
${sed} "s!%%iface%%!${iface}!g" <<-EOF | ${ngctl_batch}
|
|
|
|
$start_script
|
|
|
|
EOF
|
|
|
|
if ! ${ngctl} show ${iface}_ip_acct: >/dev/null 2>&1; then
|
|
|
|
warn "netgraph node '${iface}_ip_acct' did not created!"
|
|
|
|
else
|
2005-04-02 18:34:45 +02:00
|
|
|
${ipacctctl} ${iface}_ip_acct:${iface} dlt ${dlt}
|
2005-02-28 13:34:58 +01:00
|
|
|
${ipacctctl} ${iface}_ip_acct:${iface} threshold ${threshold}
|
|
|
|
${ipacctctl} ${iface}_ip_acct:${iface} verbose ${verbose}
|
|
|
|
${ipacctctl} ${iface}_ip_acct:${iface} saveuid ${saveuid}
|
|
|
|
${ipacctctl} ${iface}_ip_acct:${iface} savetime ${savetime}
|
2006-09-03 21:41:45 +02:00
|
|
|
|
|
|
|
eval afterstart_script=\$ng_ipacct_${iface}_afterstart_script
|
|
|
|
if [ -n "${afterstart_script}" ]; then
|
|
|
|
(set -T
|
|
|
|
trap 'exit 1' 2
|
|
|
|
${afterstart_script} ${iface})
|
|
|
|
fi
|
2005-02-28 13:34:58 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2005-04-02 18:34:45 +02:00
|
|
|
checkpoint_cmd()
|
|
|
|
{
|
|
|
|
local iface
|
|
|
|
|
|
|
|
for iface in ${ng_ipacct_interfaces}; do
|
|
|
|
debug "checlpoint ng_ipacct interface ${iface}"
|
|
|
|
eval checkpoint_script=\$ng_ipacct_${iface}_checkpoint_script
|
|
|
|
|
|
|
|
if [ -n "${checkpoint_script}" ]; then
|
|
|
|
(set -T
|
|
|
|
trap 'exit 1' 2
|
|
|
|
${checkpoint_script})
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2005-02-28 13:34:58 +01:00
|
|
|
stop_cmd()
|
|
|
|
{
|
|
|
|
local iface
|
|
|
|
|
|
|
|
for iface in ${ng_ipacct_interfaces}; do
|
|
|
|
debug "stop ng_ipacct interface ${iface}"
|
|
|
|
|
|
|
|
local stop_script
|
|
|
|
eval stop_script=\$ng_ipacct_${iface}_stop
|
2005-04-02 18:34:45 +02:00
|
|
|
eval checkpoint_script=\$ng_ipacct_${iface}_checkpoint_script
|
2005-02-28 13:34:58 +01:00
|
|
|
|
|
|
|
if ${ngctl} show ${iface}_ip_acct: >/dev/null 2>&1; then
|
2005-04-02 18:34:45 +02:00
|
|
|
if [ -n "${checkpoint_script}" ]; then
|
|
|
|
(set -T
|
|
|
|
trap 'exit 1' 2
|
|
|
|
${checkpoint_script})
|
|
|
|
fi
|
|
|
|
|
2006-09-03 21:41:45 +02:00
|
|
|
${sed} "s!%%iface%%!${iface}!g" <<-EOF | ${ngctl_batch}
|
|
|
|
$stop_script
|
|
|
|
EOF
|
|
|
|
|
2005-02-28 13:34:58 +01:00
|
|
|
if ${ngctl} show ${iface}_ip_acct: >/dev/null 2>&1; then
|
|
|
|
warn "netgraph node '${iface}_ip_acct' did not destroyed!"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if checkyesno ng_ipacct_modules_load; then
|
|
|
|
debug "Unload kld module 'ng_ipacct'"
|
|
|
|
local module
|
|
|
|
for module in ng_ipacct; do
|
|
|
|
if /sbin/kldstat -n ${module} >/dev/null 2>&1; then
|
|
|
|
/sbin/kldunload ${module}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# read settings, set default values
|
|
|
|
if [ -f %%PREFIX%%/etc/${name}.conf ]; then
|
|
|
|
debug "Sourcing %%PREFIX%%/etc/${name}.conf"
|
|
|
|
. %%PREFIX%%/etc/${name}.conf
|
|
|
|
fi
|
|
|
|
|
|
|
|
load_rc_config $name
|
|
|
|
|
|
|
|
: ${ng_ipacct_enable="NO"}
|
|
|
|
|
|
|
|
run_rc_command "$1"
|