aboutsummaryrefslogtreecommitdiff
path: root/net-mgmt/ng_ipacct/files/ng_ipacct.conf
blob: d02a42b0b9f960a5d1a5cb59d746a259eaa50ce2 (plain) (blame)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# $FreeBSD$
#
# Please read and meditate on netgraph(4), ipacctctl(8) and ngctl(8).

# Enable ng_ipacct (i.e. enable run startup script "ng_ipacct.sh")
#ng_ipacct_enable="YES"

# Enable kernel modules loading.
# On "ng_ipacct.sh start" all kernel modules specified
# in ${ng_ipacct_modules_list} will be loaded.
# Note: on "ng_ipacct.sh stop" only "ng_ipacct" will be unloaded.
ng_ipacct_modules_load="YES"

# Netgraph can load required ng_* modules automatically on the hook creation
# - except for "ng_ether". Generally, preloading modules is recommended.
# Do not add to this list modules which are statically compiled into kernel.
#ng_ipacct_modules_list="netgraph ng_ether ng_cisco ng_socket ng_tee ng_ipacct"
ng_ipacct_modules_list="netgraph ng_ether ng_ipacct"

# List of monitored interfaces. For each interface additional vars must be
# specified in corresponding variables 'ng_ipacct_IFACE_*'.
# See examples below.
#ng_ipacct_interfaces="xl0 cx0 vpn0"

# Default start/stop scripts.
#
# Single quotes is required to preserve newlines.
# '%%iface%%' will be automatically expanded with relevant interface.
# This feature should be applied to reuse indentical rules
# for similar interfaces.
ng_ipacct_default_ether_start='
	mkpeer %%iface%%: tee lower right
	name %%iface%%:lower %%iface%%_tee
	connect %%iface%%: lower upper left

	mkpeer %%iface%%_tee: ipacct right2left %%iface%%_in
	name %%iface%%_tee:right2left %%iface%%_ip_acct
	connect %%iface%%_tee: %%iface%%_ip_acct: left2right %%iface%%_out
'

ng_ipacct_default_ether_stop='
	shutdown %%iface%%_ip_acct:
	shutdown %%iface%%_tee:
	shutdown %%iface%%:
'

ng_ipacct_bpf_ether_start='
	mkpeer %%iface%%: tee lower right
	name %%iface%%:lower %%iface%%_tee
	connect %%iface%%: lower upper left

	mkpeer %%iface%%_tee: bpf right2left %%iface%%_in
	name %%iface%%_tee:right2left %%iface%%_bpf
	connect %%iface%%_tee: right2left left2right %%iface%%_out
	
	mkpeer %%iface%%_bpf: ipacct %%iface%%_match_in %%iface%%_in
	name %%iface%%_bpf:%%iface%%_match_in %%iface%%_ip_acct
	connect %%iface%%_bpf: %%iface%%_ip_acct: %%iface%%_match_out %%iface%%_out
'

ng_ipacct_bpf_ether_stop='
	shutdown %%iface%%_ip_acct:
	shutdown %%iface%%_bpf:
	shutdown %%iface%%_tee:
	shutdown %%iface%%:
'

# EXAMPLE 1. Ethernet interface

#        +-------------------------------+
#        |                               |
#      (upper)              (left2right)-----------(xl0_in)
#        |                      |        |             |
#       xl0         +--(left)-xl0_tee-(right)     xl0_ip_acct
#        |          |           |                      |
#      (lower)      |       (right2left)-----------(xl0_out)
#        |          |
#        +----------+
#
# xl0           - ng_ether
# xl0_tee       - ng_tee
# xl0_ip_acct   - ng_ipacct

# Configuration for 'xl0_ip_acct' node:

ng_ipacct_xl0_dlt="EN10MB"	# required line; see ipacctctl(8)
ng_ipacct_xl0_threshold="15000"	# '5000' by default
ng_ipacct_xl0_verbose="yes"	# 'yes' by default
ng_ipacct_xl0_saveuid="yes"	# 'no' by default
ng_ipacct_xl0_savetime="no"	# 'no' by default
ng_ipacct_xl0_start=${ng_ipacct_default_ether_start}
ng_ipacct_xl0_stop=${ng_ipacct_default_ether_stop}
ng_ipacct_xl0_checkpoint_script="path/to/your/script --checkpoint-and-save xl0"
			# this script is called on stop (to save accumulated 
			# data) or via "rc.d/ng_ipacct.sh checkpoint"

# EXAMPLE 2. Cronyx Sigma WAN adapter with HDLC encapsulation 

# cx0_hdlc-(downstream)----(rawdata)-cx0
#    |
# (inet)  (left2right)--------------------(cx0_in)
#    |      |                                |
# (left)-cx0_tee-(right)---(inet)-ng0     cx0_ip_acct
#           |                                |
#         (right2left)--------------------(cx0_out)
#
# cx0           - ng_cx
# cx0_hdlc      - ng_cisco
# cx0_tee       - ng_tee
# cx0_ip_acct   - ng_ipacct

# Configuration for 'cx0_ip_acct' node:

ng_ipacct_cx0_dlt="RAW"
ng_ipacct_cx0_start='
	mkpeer %%iface%%: cisco rawdata downstream
	name %%iface%%:rawdata %%iface%%_hdlc
	mkpeer %%iface%%_hdlc: tee inet left
	name %%iface%%_hdlc:inet %%iface%%_tee
	mkpeer %%iface%%_tee: iface right inet

	mkpeer %%iface%%_tee: ipacct right2left %%iface%%_in
	name %%iface%%_tee:right2left %%iface%%_ip_acct
	connect %%iface%%_tee: %%iface%%_ip_acct: left2right %%iface%%_out
'
ng_ipacct_cx0_stop='
	shutdown %%iface%%_ip_acct:
	shutdown %%iface%%_tee:
	shutdown %%iface%%_hdlc:
'

# EXAMPLE 3. PPTP (via mpd), divert traffic to ng_ksocket

# ipfw add tee 4001 ip from any to any via ng0 in
# ipfw add tee 4002 ip from any to any via ng0 out

#      USER-LEVEL	|	KERNEL-LEVEL
# 			|
# div4	*.4001	------>	| ----> ks_vpn0_in
#			|	    |
#			|    (inet/raw/divert)------(vpn0_in)
#			|				|
#			|			   vpn0_ip_acct
#			|				|
#			|    (inet/raw/divert)------(vpn0_out)
#			|	    |
# div4	*.4002	------>	| ----> ks_vpn0_out
#
# ks_vpn0_in	- ng_ksocket
# ks_vpn0_out	- ng_ksocket
# vpn0_ip_acct	- ng_ipacct

ng_ipacct_vpn0_dlt="RAW"
ng_ipacct_vpn0_start='
	mkpeer ipacct dummy dummy
	name .:dummy %%iface%%_ip_acct

	mkpeer %%iface%%_ip_acct: ksocket  %%iface%%_in inet/raw/divert
	name %%iface%%_ip_acct:%%iface%%_in  ks_%%iface%%_in
	msg ks_%%iface%%_in:  bind inet/0.0.0.0:4001

	mkpeer %%iface%%_ip_acct: ksocket %%iface%%_out inet/raw/divert
	name %%iface%%_ip_acct:%%iface%%_out ks_%%iface%%_out
	msg ks_%%iface%%_out: bind inet/0.0.0.0:4002

	rmhook .:dummy
'
ng_ipacct_vpn0_stop='
	shutdown %%iface%%_ip_acct:
'

# EXAMPLE 4. Ethernet interface with BPF

#   +-------------------------------+
#   |                               |
# (upper)              (left2right)-----(xl0_in) (xl0_match_in)----(xl0_in)
#   |                      |        |        |     |                    |
#  xl0         +--(left)-xl0_tee-(right)     xl0_bpf               xl0_ip_acct
#   |          |           |                 |     |                    |
# (lower)      |       (right2left)----(xl0_out) (xl0_match_out)--(xl0_out)
#   |          |
#   +----------+
#
# xl0           - ng_ether
# xl0_tee       - ng_tee
# xl0_bpf       - ng_bpf
# xl0_ip_acct   - ng_ipacct

# Configuration for 'xl0_ip_acct' node:

ng_ipacct_xl0_dlt="EN10MB"	# required line; see ipacctctl(8)
ng_ipacct_xl0_threshold="15000"	# '5000' by default
ng_ipacct_xl0_verbose="yes"	# 'yes' by default
ng_ipacct_xl0_saveuid="yes"	# 'no' by default
ng_ipacct_xl0_savetime="no"	# 'no' by default
ng_ipacct_xl0_start=${ng_ipacct_bpf_ether_start}
ng_ipacct_xl0_stop=${ng_ipacct_bpf_ether_stop}
ng_ipacct_xl0_checkpoint_script="path/to/your/script --checkpoint-and-save xl0"
			# this script is called on stop (to save accumulated 
			# data) or via "rc.d/ng_ipacct.sh checkpoint"
ng_ipacct_xl0_afterstart_script="path/to/your/script --load-bpf-filters xl0"
			# this script is called just after initialization
			# of nodes to load filters into xl0_bpf