1 .\" Copyright (c) 2004-2005 Gleb Smirnoff <glebius@FreeBSD.org>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
32 .Nd Cisco's NetFlow implementation
36 .In netgraph/netflow/ng_netflow.h
40 node implements Cisco's NetFlow export protocol on a router running
44 node listens for incoming traffic and identifies unique flows in it.
45 Flows are distinguished by endpoint IP addresses, TCP/UDP port numbers,
46 ToS and input interface.
47 Expired flows are exported out of the node in NetFlow version 5/9 UDP datagrams.
48 Expiration reason can be one of the following:
51 RST or FIN TCP segment.
54 Flows cannot live more than the specified period of time.
55 The default is 1800 seconds (30 minutes).
58 A flow was inactive for the specified period of time.
59 The default is 15 seconds.
62 Node supports IPv6 accounting (NetFlow v9 only) and is aware of multiple fibs.
63 Different fibs are mapped to different domain_id in NetFlow V9 and different engine_id in NetFlow V5.
65 This node type supports up to
66 .Dv NG_NETFLOW_MAXIFACES
67 (default 65536) hooks named
70 and the same number of hooks named
73 plus two export hooks:
75 (for NetFlow version 5) and
77 (for NetFlow version 9). Export can be done simultaneously for all supported
78 export hooks. By default (ingress NetFlow enabled) node does NetFlow accounting of data
84 hook is connected, unmodified data is bypassed to it, otherwise data is freed.
85 If data is received on
87 hook, it is bypassed to corresponding
89 hook without any processing (egress NetFlow disabled by default).
90 When full export datagram for an export protocol is built it is sent to the
95 In normal operation, one (or more) export hook is connected to the
101 This node type supports the generic control messages, plus the following:
102 .Bl -tag -width indent
103 .It Dv NGM_NETFLOW_INFO Pq Ic info
104 Returns some node statistics and the current timeout values in a
105 .Vt "struct ng_netflow_info" .
106 .It Dv NGM_NETFLOW_IFINFO Pq Ic ifinfo
107 Returns information about the
110 The hook number is passed as an argument.
111 .It Dv NGM_NETFLOW_SETDLT Pq Ic setdlt
112 Sets data link type on the
115 Currently, supported types are raw IP datagrams and Ethernet.
116 This message type uses
117 .Vt "struct ng_netflow_setdlt"
119 .Bd -literal -offset 4n
120 struct ng_netflow_setdlt {
121 uint16_t iface; /* which iface dlt change */
122 uint8_t dlt; /* DLT_XXX from bpf.h */
128 hook must already be connected, otherwise message send operation will
130 .It Dv NGM_NETFLOW_SETIFINDEX Pq Ic setifindex
133 may be unable to determine the input interface index of a packet.
134 This can happen if traffic enters the
136 node before it comes to the system interface's input queue.
137 An example of such a setup is capturing a traffic
139 synchronous data line and
141 In this case, the input index should be associated with a given hook.
142 The interface's index can be determined via
145 This message requires
146 .Vt "struct ng_netflow_setifindex"
148 .Bd -literal -offset 4n
149 struct ng_netflow_setifindex {
150 uint16_t iface; /* which iface index change */
151 uint16_t index; /* new index */
157 hook must already be connected, otherwise the message
158 send operation will return an error.
159 .It Dv NGM_NETFLOW_SETTIMEOUTS Pq Ic settimeouts
160 Sets values in seconds for NetFlow active/inactive timeouts.
161 This message requires
162 .Vt "struct ng_netflow_settimeouts"
164 .Bd -literal -offset 4n
165 struct ng_netflow_settimeouts {
166 uint32_t inactive_timeout; /* flow inactive timeout */
167 uint32_t active_timeout; /* flow active timeout */
170 .It Dv NGM_NETFLOW_SETCONFIG Pq Ic setconfig
171 Sets configuration for the specified interface.
172 This message requires
173 .Vt "struct ng_netflow_setconfig"
175 .Bd -literal -offset 4n
176 struct ng_netflow_setconfig {
177 uint16_t iface; /* which iface config change */
178 uint32_t conf; /* new config */
179 #define NG_NETFLOW_CONF_INGRESS 1
180 #define NG_NETFLOW_CONF_EGRESS 2
181 #define NG_NETFLOW_CONF_ONCE 4
182 #define NG_NETFLOW_CONF_THISONCE 8
186 Configuration is a bitmask of several options. Option NG_NETFLOW_CONF_INGRESS
187 enabled by default enables ingress NetFlow generation (for data coming from
188 ifaceX hook). Option NG_NETFLOW_CONF_EGRESS enables egress NetFlow (for data
189 coming from outX hook). Option NG_NETFLOW_CONF_ONCE defines that packet should
190 be accounted only once if it several times passes via netflow node. Option
191 NG_NETFLOW_CONF_THISONCE defines that packet should be accounted only once
192 if it several times passes via exactly this netflow node. Last two options are
193 important to avoid duplicate accounting when both ingress and egress NetFlow
195 .It Dv NGM_NETFLOW_SETTEMPLATE Pq Ic settemplate
196 Sets various timeouts to announce data flow templates
197 (NetFlow v9-specific). This message requires
198 .Vt "struct ng_netflow_settemplate"
200 .Bd -literal -offset 4n
201 struct ng_netflow_settemplate {
202 uint16_t time; /* max time between announce */
203 uint16_t packets; /* max packets between announce */
207 Value of time field represents time in seconds to re-announce data templates.
208 Value of packets field represents maximum packets count between
209 re-announcing data templates.
210 .It Dv NGM_NETFLOW_SETMTU Pq Ic setmtu
211 Sets export interface MTU to build packets of specified size (NetFlow v9-specific).
212 This message requires
213 .Vt "struct ng_netflow_setmtu"
215 .Bd -literal -offset 4n
216 struct ng_netflow_setemtu {
217 uint16_t mtu; /* MTU for packet */
221 Default is 1500 bytes.
222 .It Dv NGM_NETFLOW_SHOW
223 This control message asks a node to dump the entire contents of the flow cache.
231 .It Dv NGM_NETFLOW_V9INFO Pq Ic v9info
232 Returns some NetFlow v9 related values in a
233 .Bd -literal -offset 4n
234 struct ng_netflow_v9info {
235 uint16_t templ_packets; /* v9 template packets */
236 uint16_t templ_time; /* v9 template time */
237 uint16_t mtu; /* v9 MTU */
242 This node shuts down upon receipt of a
244 control message, or when all hooks have been disconnected.
246 The simplest possible configuration is one Ethernet interface, where
247 flow collecting is enabled.
248 .Bd -literal -offset indent
249 /usr/sbin/ngctl -f- <<-SEQ
250 mkpeer fxp0: netflow lower iface0
251 name fxp0:lower netflow
252 connect fxp0: netflow: upper out0
253 mkpeer netflow: ksocket export inet/dgram/udp
254 msg netflow:export connect inet/10.0.0.1:4444
258 This is a more complicated example of a router with 2 NetFlow-enabled
265 node in this example is connected to
267 The latter sends us a copy of IP packets, which we analyze and free.
270 we do not use tee, but send packets back to either node.
271 .Bd -literal -offset indent
272 /usr/sbin/ngctl -f- <<-SEQ
273 # connect ng0's tee to iface0 hook
274 mkpeer ng0:inet netflow right2left iface0
275 name ng0:inet.right2left netflow
276 # set DLT to raw mode
277 msg netflow: setdlt { iface=0 dlt=12 }
278 # set interface index (5 in this example)
279 msg netflow: setifindex { iface=0 index=5 }
281 # Connect fxp0: to iface1 and out1 hook
282 connect fxp0: netflow: lower iface1
283 connect fxp0: netflow: upper out1
285 # Create ksocket node on export hook, and configure it
286 # to send exports to proper destination
287 mkpeer netflow: ksocket export inet/dgram/udp
288 msg netflow:export connect inet/10.0.0.1:4444
302 .%T "Cisco Systems NetFlow Services Export Version 9"
306 .Pa http://www.cisco.com/en/US/docs/ios/solutions_docs/netflow/nfwhite.html
311 node type was written by
312 .An Gleb Smirnoff Aq glebius@FreeBSD.org ,
313 .An Alexander Motin Aq mav@FreeBSD.org ,
314 .An Alexander Chernikov Aq melifaro@ipfw.ru .
315 The initial code was based on
318 .An Roman V. Palagin Aq romanp@unshadow.net .
320 Cache snapshot obtained via
322 command may lack some percentage of entries under severe load.
323 IPv6 flows are not shown.
327 node type does not fill in AS numbers.
328 This is due to the lack of necessary information in the kernel routing table.
329 However, this information can be injected into the kernel from a routing daemon
331 This functionality may become available in future releases.