summaryrefslogtreecommitdiffstats
path: root/etc/rc.d/ipfw_netflow
blob: b9523db9eb5a9074238e802435b2bb5a7668ffee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/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 $*
OpenPOWER on IntegriCloud