HardenedBSD/libexec/rc/rc.d/ipfw_netflow
Alexander Leidinger f99f0ee14e rc.d: add a service jails config to all base system services
This gives more permissions to services (e.g. network access to
services which require this) when they are started as an automatic
service jail.

The sshd patch is important for the sshd-related functionality as
described in the man-page in the service jails part.

The location of the added env vars is supposed to allow overriding them
in rc.conf, and to hard-disable the use of svcj for some parts where it
doesn't make sense or will not work.

Only a subset of all of the services are fully tested (I'm running this
since more than a year with various services started as service jails).
The untested parts should be most of the time ok, in some edge-cases
more permissions are needed inside the service jail.
Differential Revision:	https://reviews.freebsd.org/D40371
2024-05-22 15:41:49 +02:00

80 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
#
#
# 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
# doesn't make sense to run in a svcj: config setting
ipfw_netflow_svcj="NO"
run_rc_command $*