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