summaryrefslogtreecommitdiffstats
path: root/share/man/man4/ng_netflow.4
blob: 40aa557c2edabe127945b399eb64054b6ad38ad9 (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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
.\" Copyright (c) 2004-2005 Gleb Smirnoff <glebius@FreeBSD.org>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd May 11, 2005
.Os
.Dt NG_NETFLOW 4
.Sh NAME
.Nm ng_netflow
.Nd Cisco's NetFlow implementation
.Sh SYNOPSIS
.In sys/types.h
.In netinet/in.h
.In netgraph/netflow/ng_netflow.h
.Sh DESCRIPTION
The
.Nm
node implements Cisco's NetFlow export protocol on a router running
.Fx .
The
.Nm
node listens for incoming traffic and identifies unique flows in it.
Flows are distinguished by endpoint IP addresses, TCP/UDP port numbers,
ToS and input interface.
Expired flows are exported out of the node in NetFlow version 5 UDP datagrams.
Expiration reason can be one of the following:
.Bl -dash
.It
RST or FIN TCP segment.
.It
Active timeout.
Flows cannot live more than the specified period of time.
The default is 1800 seconds (30 minutes).
.It
Inactive timeout.
A flow was inactive for the specified period of time.
The default is 15 seconds.
.El
.Pp
Export information is stored in NetFlow version 5 datagrams.
.Sh HOOKS
This node type supports up to
.Dv NG_NETFLOW_MAXIFACES
hooks named
.Va iface0 , iface1 ,
etc.,
and the same number of hooks named
.Va out0 , out1 ,
etc.,
plus a single hook named
.Va export .
The node does NetFlow accounting of data received on
.Va iface*
hooks.
If corresponding
.Va out
hook is connected, unmodified data is bypassed to it, otherwise data is freed.
If data is received on
.Va out
hook, it is bypassed to corresponding
.Va iface
hook without any processing.
When full export datagram is built it is sent to the
.Va export
hook.
In normal operation, the
.Va export
hook is connected to the
.Va inet/dgram/udp
hook of the
.Xr ng_ksocket 4
node.
.Sh CONTROL MESSAGES
This node type supports the generic control messages, plus the following:
.Bl -tag -width indent
.It Dv NGM_NETFLOW_INFO
Returns some node statistics and the current timeout values in a
.Vt "struct ng_netflow_info" .
.It Dv NGM_NETFLOW_IFINFO
Returns information about the
.Va iface Ns Ar N
hook.
The hook number is passed as an argument.
.It Dv NGM_NETFLOW_SETDLT
Sets data link type on the
.Va iface Ns Ar N
hook.
Currently, supported types are raw IP datagrams and Ethernet.
This messsage type uses
.Vt "struct ng_netflow_setdlt"
as an argument:
.Bd -literal -offset 4n
struct ng_netflow_setdlt {
	uint16_t iface;		/* which iface to operate on */
	uint8_t  dlt;		/* DLT_XXX from bpf.h */
};
.Ed
.Pp
The requested
.Va iface Ns Ar N
hook must already be connected, otherwise message send operation will
return an error.
.It Dv NGM_NETFLOW_SETIFINDEX
In some cases,
.Nm
may be unable to determine the input interface index of a packet.
This can happen if traffic enters the
.Nm
node before it comes to the system interface's input queue.
An example of such a setup is capturing a traffic
.Em between
synchronous data line and
.Xr ng_iface 4 .
In this case, the input index should be associated with a given hook.
The interface's index can be determined via
.Xr if_nametoindex 3
from userland.
This message requires
.Vt "struct ng_netflow_setifindex"
as an argument:
.Bd -literal -offset 4n
struct ng_netflow_setifindex {
	u_int16_t iface;	/* which iface to operate on */
	u_int16_t index;	/* new index */
};
.Ed
.Pp
The requested
.Va iface Ns Ar N
hook must already be connected, otherwise the message
send operation will return an error.
.It Dv NGM_NETFLOW_SETTIMEOUTS
Sets values in seconds for NetFlow active/inactive timeouts.
This message requires
.Vt "struct ng_netflow_settimeouts"
as an argument:
.Bd -literal -offset 4n
struct ng_netflow_settimeouts {
	uint32_t	inactive_timeout;
	uint32_t	active_timeout;
};
.Ed
.It Dv NGM_NETFLOW_SHOW
This control message asks a node to dump the entire contents of the flow cache.
It is called from
.Xr flowctl 8 ,
not directly from
.Xr ngctl 8 .
See also
.Sx BUGS
section.
.El
.Sh ASCII CONTROL MESSAGES
Most binary control messages have an
.Tn ASCII
equivalent.
The supported
.Tn ASCII
commands are:
.Pp
.Bl -tag -width ".Dv NGM_NETFLOW_SETTIMEOUTS" -compact
.It Dv NGM_NETFLOW_INFO
.Qq Li info
.It Dv NGM_NETFLOW_IFINFO
.Qq Li "ifinfo %u"
.It Dv NGM_NETFLOW_SETDLT
.Qq Li "setdlt { iface = %u dlt = %u }"
.It Dv NGM_NETFLOW_SETIFINDEX
.Qq Li "setifindex { iface = %u index = %u }"
.It Dv NGM_NETFLOW_SETTIMEOUTS
.Qq Li "settimeouts { inactive = %u active = %u }"
.El
.Sh SHUTDOWN
This node shuts down upon receipt of a
.Dv NGM_SHUTDOWN
control message, or when all hooks have been disconnected.
.Sh EXAMPLES
The simplest possible configuration is one Ethernet interface, where
flow collecting is enabled.
.Bd -literal -offset indent
/usr/sbin/ngctl -f- <<-SEQ
	mkpeer fxp0: netflow lower iface0
	name fxp0:lower netflow
	connect fxp0: netflow: upper out0
	mkpeer netflow: ksocket export inet/dgram/udp
	msg netflow:export connect inet/10.0.0.1:4444
SEQ
.Ed
.Pp
This is a more complicated example of a router with 2 NetFlow-enabled
interfaces
.Li fxp0
and
.Li ng0 .
Note that the
.Va ng0:
node in this example is connected to
.Xr ng_tee 4 .
The latter sends us a copy of IP packets, which we analyze and free.
On
.Va fxp0:
we do not use tee, but send packets back to ether node.
.Bd -literal -offset indent
/usr/sbin/ngctl -f- <<-SEQ
	# connect ng0's tee to iface0 hook
	mkpeer ng0:inet netflow right2left iface0
	name ng0:inet.right2left netflow
	# set DLT to raw mode
	msg netflow: setdlt { iface=0 dlt=12 }
	# set interface index (5 in this example)
	msg netflow: setifindex { iface=0 index=5 }

	# Connect fxp0: to iface1 and out1 hook
	connect fxp0: netflow: lower iface1
	connect fxp0: netflow: upper out1

	# Create ksocket node on export hook, and configure it
	# to send exports to proper destination
	mkpeer netflow: ksocket export inet/dgram/udp
	msg netflow:export connect inet/10.0.0.1:4444
SEQ
.Ed
.Sh SEE ALSO
.Xr netgraph 4 ,
.Xr ng_ether 4 ,
.Xr ng_iface 4 ,
.Xr ng_ksocket 4 ,
.Xr ng_tee 4 ,
.Xr flowctl 8 ,
.Xr ngctl 8
.Pp
.Pa http://www.cisco.com/warp/public/cc/pd/iosw/ioft/neflct/tech/napps_wp.htm
.Sh AUTHORS
.An -nosplit
The
.Nm
node type was written by
.An Gleb Smirnoff Aq glebius@FreeBSD.org ,
based on
.Nm ng_ipacct
written by
.An Roman V. Palagin Aq romanp@unshadow.net .
.Sh BUGS
Cache snapshot obtained via
.Dv NGM_NETFLOW_SHOW
command may lack some percentage of entries under severe load.
.Pp
The
.Nm
node type does not fill in AS numbers.
This is due to the lack of necessary information in the kernel routing table.
However, this information can be injected into the kernel from a routing daemon
such as GNU Zebra.
This functionality may become available in future releases.
OpenPOWER on IntegriCloud