xref: /freebsd/share/man/man4/ng_netflow.4 (revision 0957b409)
1.\" Copyright (c) 2004-2005 Gleb Smirnoff <glebius@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd December 10, 2012
28.Dt NG_NETFLOW 4
29.Os
30.Sh NAME
31.Nm ng_netflow
32.Nd Cisco's NetFlow implementation
33.Sh SYNOPSIS
34.In sys/types.h
35.In netinet/in.h
36.In netgraph/netflow/ng_netflow.h
37.Sh DESCRIPTION
38The
39.Nm
40node implements Cisco's NetFlow export protocol on a router running
41.Fx .
42The
43.Nm
44node listens for incoming traffic and identifies unique flows in it.
45Flows are distinguished by endpoint IP addresses, TCP/UDP port numbers,
46ToS and input interface.
47Expired flows are exported out of the node in NetFlow version 5/9 UDP datagrams.
48Expiration reason can be one of the following:
49.Bl -dash
50.It
51RST or FIN TCP segment.
52.It
53Active timeout.
54Flows cannot live more than the specified period of time.
55The default is 1800 seconds (30 minutes).
56.It
57Inactive timeout.
58A flow was inactive for the specified period of time.
59The default is 15 seconds.
60.El
61.Pp
62Node supports IPv6 accounting (NetFlow v9 only) and is aware of multiple fibs.
63Different fibs are mapped to different domain_id in NetFlow V9 and different engine_id in NetFlow V5.
64.Sh HOOKS
65This node type supports up to
66.Dv NG_NETFLOW_MAXIFACES
67(default 65536) hooks named
68.Va iface0 , iface1 ,
69etc.,
70and the same number of hooks named
71.Va out0 , out1 ,
72etc.,
73plus two export hooks:
74.Va export
75(for NetFlow version 5) and
76.Va export9
77(for NetFlow version 9).
78Export can be done simultaneously for all supported export hooks.
79By default (ingress NetFlow enabled) node does NetFlow accounting of data
80received on
81.Va iface*
82hooks.
83If corresponding
84.Va out
85hook is connected, unmodified data is bypassed to it, otherwise data is freed.
86If data is received on
87.Va out
88hook, it is bypassed to corresponding
89.Va iface
90hook without any processing (egress NetFlow disabled by default).
91When full export datagram for an export protocol is built it is sent to the
92.Va export
93or
94.Va export9
95hook.
96In normal operation, one (or more) export hook is connected to the
97.Va inet/dgram/udp
98hook of the
99.Xr ng_ksocket 4
100node.
101.Sh CONTROL MESSAGES
102This node type supports the generic control messages, plus the following:
103.Bl -tag -width foo
104.It Dv NGM_NETFLOW_INFO Pq Ic info
105Returns some node statistics and the current timeout values in a
106.Vt "struct ng_netflow_info" .
107.It Dv NGM_NETFLOW_IFINFO Pq Ic ifinfo
108Returns information about the
109.Va iface Ns Ar N
110hook.
111The hook number is passed as an argument.
112.It Dv NGM_NETFLOW_SETDLT Pq Ic setdlt
113Sets data link type on the
114.Va iface Ns Ar N
115hook.
116Currently, supported types are
117.Cm DLT_RAW
118(raw IP datagrams) and
119.Cm DLT_EN10MB
120(Ethernet).
121DLT_ definitions can be found in
122.In net/bpf.h
123header.
124Currently used values are 1 for
125.Cm DLT_EN10MB
126and 12 for
127.Cm DLT_RAW .
128This message type uses
129.Vt "struct ng_netflow_setdlt"
130as an argument:
131.Bd -literal -offset 4n
132struct ng_netflow_setdlt {
133	uint16_t iface;		/* which iface dlt change */
134	uint8_t  dlt;		/* DLT_XXX from bpf.h */
135};
136.Ed
137.Pp
138The requested
139.Va iface Ns Ar N
140hook must already be connected, otherwise message send operation will
141return an error.
142.It Dv NGM_NETFLOW_SETIFINDEX Pq Ic setifindex
143In some cases,
144.Nm
145may be unable to determine the input interface index of a packet.
146This can happen if traffic enters the
147.Nm
148node before it comes to the system interface's input queue.
149An example of such a setup is capturing a traffic
150.Em between
151synchronous data line and
152.Xr ng_iface 4 .
153In this case, the input index should be associated with a given hook.
154The interface's index can be determined via
155.Xr if_nametoindex 3
156from userland.
157This message requires
158.Vt "struct ng_netflow_setifindex"
159as an argument:
160.Bd -literal -offset 4n
161struct ng_netflow_setifindex {
162	uint16_t iface;		/* which iface index change */
163	uint16_t index;		/* new index */
164};
165.Ed
166.Pp
167The requested
168.Va iface Ns Ar N
169hook must already be connected, otherwise the message
170send operation will return an error.
171.It Dv NGM_NETFLOW_SETTIMEOUTS Pq Ic settimeouts
172Sets values in seconds for NetFlow active/inactive timeouts.
173This message requires
174.Vt "struct ng_netflow_settimeouts"
175as an argument:
176.Bd -literal -offset 4n
177struct ng_netflow_settimeouts {
178	uint32_t inactive_timeout;	/* flow inactive timeout */
179	uint32_t active_timeout;	/* flow active timeout */
180};
181.Ed
182.It Dv NGM_NETFLOW_SETCONFIG Pq Ic setconfig
183Sets configuration for the specified interface.
184This message requires
185.Vt "struct ng_netflow_setconfig"
186as an argument:
187.Bd -literal -offset 4n
188struct ng_netflow_setconfig {
189	uint16_t iface;		/* which iface config change */
190	uint32_t conf;		/* new config */
191#define NG_NETFLOW_CONF_INGRESS		1
192#define NG_NETFLOW_CONF_EGRESS		2
193#define NG_NETFLOW_CONF_ONCE		4
194#define NG_NETFLOW_CONF_THISONCE	8
195#define NG_NETFLOW_CONF_NOSRCLOOKUP	16
196#define NG_NETFLOW_CONF_NODSTLOOKUP	32
197};
198.Ed
199.Pp
200Configuration is a bitmask of several options.
201Option NG_NETFLOW_CONF_INGRESS
202enabled by default enables ingress NetFlow generation (for data coming from
203ifaceX hook).
204Option
205.Va NG_NETFLOW_CONF_EGRESS
206enables egress NetFlow (for data coming from outX hook).
207Option
208.Va NG_NETFLOW_CONF_ONCE
209defines that packet should be accounted only once if it several times passes
210via netflow node.
211Option
212.Va NG_NETFLOW_CONF_THISONCE
213defines that packet should be accounted only once if it several times passes
214via exactly this netflow node.
215These two options are important to avoid duplicate accounting when both ingress
216and egress NetFlow are enabled.
217Option
218.Va NG_NETFLOW_CONF_NOSRCLOOKUP
219skips radix lookup on flow source address used to fill in network mask.
220Option
221.Va NG_NETFLOW_CONF_NODSTLOOKUP
222skips radix lookup on destination (which fills egress interface id, destination
223mask and gateway).
224If one doesn't need data provided by lookups, he/she can disable them, to reduce
225load on routers.
226.It Dv NGM_NETFLOW_SETTEMPLATE Pq Ic settemplate
227Sets various timeouts to announce data flow templates
228(NetFlow v9-specific). This message requires
229.Vt "struct ng_netflow_settemplate"
230as an argument:
231.Bd -literal -offset 4n
232struct ng_netflow_settemplate {
233	uint16_t time;		/* max time between announce */
234	uint16_t packets;	/* max packets between announce */
235};
236.Ed
237.Pp
238Value of time field represents time in seconds to re-announce data templates.
239Value of packets field represents maximum packets count between
240re-announcing data templates.
241.It Dv NGM_NETFLOW_SETMTU Pq Ic setmtu
242Sets export interface MTU to build packets of specified size (NetFlow v9-specific).
243This message requires
244.Vt "struct ng_netflow_setmtu"
245as an argument:
246.Bd -literal -offset 4n
247struct ng_netflow_setemtu {
248	uint16_t mtu;		/* MTU for packet */
249};
250.Ed
251.Pp
252Default is 1500 bytes.
253.It Dv NGM_NETFLOW_SHOW
254This control message asks a node to dump the entire contents of the flow cache.
255It is called from
256.Xr flowctl 8 ,
257not directly from
258.Xr ngctl 8 .
259.It Dv NGM_NETFLOW_V9INFO Pq Ic v9info
260Returns some NetFlow v9 related values in a
261.Bd -literal -offset 4n
262struct ng_netflow_v9info {
263    uint16_t        templ_packets;  /* v9 template packets */
264    uint16_t        templ_time;     /* v9 template time */
265    uint16_t        mtu;            /* v9 MTU */
266};
267.Ed
268.El
269.Sh SHUTDOWN
270This node shuts down upon receipt of a
271.Dv NGM_SHUTDOWN
272control message, or when all hooks have been disconnected.
273.Sh EXAMPLES
274The simplest possible configuration is one Ethernet interface, where
275flow collecting is enabled.
276.Bd -literal -offset indent
277/usr/sbin/ngctl -f- <<-SEQ
278	mkpeer fxp0: netflow lower iface0
279	name fxp0:lower netflow
280	connect fxp0: netflow: upper out0
281	mkpeer netflow: ksocket export inet/dgram/udp
282	msg netflow:export connect inet/10.0.0.1:4444
283SEQ
284.Ed
285.Pp
286This is a more complicated example of a router with 2 NetFlow-enabled
287interfaces
288.Li fxp0
289and
290.Li ng0 .
291Note that the
292.Va ng0:
293node in this example is connected to
294.Xr ng_tee 4 .
295The latter sends us a copy of IP packets, which we analyze and free.
296On
297.Va fxp0:
298we do not use tee, but send packets back to either node.
299.Bd -literal -offset indent
300/usr/sbin/ngctl -f- <<-SEQ
301	# connect ng0's tee to iface0 hook
302	mkpeer ng0:inet netflow right2left iface0
303	name ng0:inet.right2left netflow
304	# set DLT to raw mode
305	msg netflow: setdlt { iface=0 dlt=12 }
306	# set interface index (5 in this example)
307	msg netflow: setifindex { iface=0 index=5 }
308
309	# Connect fxp0: to iface1 and out1 hook
310	connect fxp0: netflow: lower iface1
311	connect fxp0: netflow: upper out1
312
313	# Create ksocket node on export hook, and configure it
314	# to send exports to proper destination
315	mkpeer netflow: ksocket export inet/dgram/udp
316	msg netflow:export connect inet/10.0.0.1:4444
317SEQ
318.Ed
319.Sh SEE ALSO
320.Xr setfib 2 ,
321.Xr netgraph 4 ,
322.Xr ng_ether 4 ,
323.Xr ng_iface 4 ,
324.Xr ng_ksocket 4 ,
325.Xr ng_tee 4 ,
326.Xr flowctl 8 ,
327.Xr ngctl 8
328.Rs
329.%A B. Claise, Ed
330.%T "Cisco Systems NetFlow Services Export Version 9"
331.%O RFC 3954
332.Re
333.Pp
334.Pa http://www.cisco.com/en/US/docs/ios/solutions_docs/netflow/nfwhite.html
335.Sh AUTHORS
336.An -nosplit
337The
338.Nm
339node type was written by
340.An Gleb Smirnoff Aq Mt glebius@FreeBSD.org ,
341.An Alexander Motin Aq Mt mav@FreeBSD.org ,
342.An Alexander Chernikov Aq Mt melifaro@ipfw.ru .
343The initial code was based on
344.Nm ng_ipacct
345written by
346.An Roman V. Palagin Aq Mt romanp@unshadow.net .
347.Sh BUGS
348Cache snapshot obtained via
349.Dv NGM_NETFLOW_SHOW
350command may lack some percentage of entries under severe load.
351.Pp
352The
353.Nm
354node type does not fill in AS numbers.
355This is due to the lack of necessary information in the kernel routing table.
356However, this information can be injected into the kernel from a routing daemon
357such as GNU Zebra.
358This functionality may become available in future releases.
359