freebsd-dev/libexec/rc/rc.d/ipfw_netflow
Bjoern A. Zeeb 0696600c41 Move the rc framework out of sbin/init into libexec/rc.
The reasons for this are forward looking to pkgbase:
 * /sbin/init is a special binary; try not to replace it with
   every package update because an rc script was touched.
   (a follow-up commit will make init its own package)
 * having rc in its own place will allow more easy replacement
   of the rc framework with alternatives, such as openrc.

Discussed with:		brd (during BSDCam), kmoore
Requested by:		cem, bz
PR:			231522
Approved by:		re (gjb)
2018-10-17 16:49:11 +00:00

78 lines
1.9 KiB
Bash
Executable File

#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: ipfw_netflow
# REQUIRE: ipfw
# KEYWORD: nojailvnet
. /etc/rc.subr
. /etc/network.subr
name="ipfw_netflow"
desc="firewall, ipfw, netflow"
rcvar="${name}_enable"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
start_precmd="${name}_test"
status_cmd="${name}_status"
required_modules="ipfw ng_netflow ng_ipfw"
extra_commands="status"
: ${ipfw_netflow_hook:=9995}
: ${ipfw_netflow_rule:=01000}
: ${ipfw_netflow_ip:=127.0.0.1}
: ${ipfw_netflow_port:=9995}
: ${ipfw_netflow_version:=}
ipfw_netflow_test()
{
if [ "${ipfw_netflow_version}" != "" ] && [ "${ipfw_netflow_version}" != 9 ]; then
err 1 "Unknown netflow version \'${ipfw_netflow_version}\'"
fi
case "${ipfw_netflow_hook}" in
[!0-9]*)
err 1 "Bad value \"${ipfw_netflow_hook}\": Hook must be numerical"
esac
case "${ipfw_netflow_rule}" in
[!0-9]*)
err 1 "Bad value \"${ipfw_netflow_rule}\": Rule number must be numerical"
esac
}
ipfw_netflow_is_running()
{
ngctl show netflow: > /dev/null 2>&1 && return 0 || return 1
}
ipfw_netflow_status()
{
ipfw_netflow_is_running && echo "ipfw_netflow is active" || echo "ipfw_netflow is not active"
}
ipfw_netflow_start()
{
ipfw_netflow_is_running && err 1 "ipfw_netflow is already active"
ipfw add ${ipfw_netflow_rule} ngtee ${ipfw_netflow_hook} ip from any to any ${ipfw_netflow_fib:+fib ${ipfw_netflow_fib}}
ngctl -f - <<-EOF
mkpeer ipfw: netflow ${ipfw_netflow_hook} iface0
name ipfw:${ipfw_netflow_hook} netflow
mkpeer netflow: ksocket export${ipfw_netflow_version} inet/dgram/udp
msg netflow: setdlt {iface=0 dlt=12}
name netflow:export${ipfw_netflow_version} netflow_export
msg netflow:export${ipfw_netflow_version} connect inet/${ipfw_netflow_ip}:${ipfw_netflow_port}
EOF
}
ipfw_netflow_stop()
{
ipfw_netflow_is_running || err 1 "ipfw_netflow is not active"
ngctl shutdown netflow:
ipfw delete ${ipfw_netflow_rule}
}
load_rc_config $name
run_rc_command $*