softflowd.8 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. .\" $Id$
  2. .\"
  3. .\" Copyright (c) 2002 Damien Miller. All rights reserved.
  4. .\" Portions Copyright (c) 2001 Kevin Steves. All rights reserved.
  5. .\"
  6. .\" Redistribution and use in source and binary forms, with or without
  7. .\" modification, are permitted provided that the following conditions
  8. .\" are met:
  9. .\" 1. Redistributions of source code must retain the above copyright
  10. .\" notice, this list of conditions and the following disclaimer.
  11. .\" 2. Redistributions in binary form must reproduce the above copyright
  12. .\" notice, this list of conditions and the following disclaimer in the
  13. .\" documentation and/or other materials provided with the distribution.
  14. .\"
  15. .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. .\"
  26. .Dd October 14, 2002
  27. .Dt SOFTFLOWD 8
  28. .Os
  29. .Sh NAME
  30. .Nm softflowd
  31. .Nd Traffic flow monitoring
  32. .Sh SYNOPSIS
  33. .Nm softflowd
  34. .Op Fl 6dDh
  35. .Op Fl L Ar hoplimit
  36. .Op Fl T Ar track_level
  37. .Op Fl c Ar ctl_sock
  38. .Ek
  39. .Oo Fl i\ \&
  40. .Sm off
  41. .Oo Ar if_ndx : Oc
  42. .Ar interface
  43. .Sm on
  44. .Oc
  45. .Bk words
  46. .Op Fl m Ar max_flows
  47. .Op Fl n Ar host:port
  48. .Op Fl p Ar pidfile
  49. .Op Fl r Ar pcap_file
  50. .Op Fl t Ar timeout_name=seconds
  51. .Op Fl v Ar netflow_version
  52. .Op bpf_expression
  53. .Sh DESCRIPTION
  54. .Nm
  55. is a software implementation of a flow-based network traffic monitor.
  56. .Nm
  57. reads network traffic and gathers information about active traffic flows.
  58. A "traffic flow" is communication between two IP addresses or (if the
  59. overlying protocol is TCP or UDP) address/port tuples.
  60. .Pp
  61. The intended use of
  62. .Nm
  63. is as a software implementation of Cisco's NetFlow(tm) traffic account
  64. system.
  65. .Nm
  66. supports data export using versions 1, 5 or 9 of the NetFlow protocol.
  67. .Nm
  68. can also run in statistics-only mode, where it just collects summary
  69. information.
  70. However, too few statistics are collected to make this
  71. mode really useful for anything other than debugging.
  72. .Pp
  73. Network traffic may be obtained by listening on a promiscuous network
  74. interface or by reading stored
  75. .Xr pcap 3
  76. files, such as those written by
  77. .Xr tcpdump 8 .
  78. Traffic may be filtered with an optional
  79. .Xr bpf 4
  80. program, specified on the command-line as
  81. .Ar bpf_expression .
  82. .Nm
  83. is IPv6 capable and will track IPv6 flows if the NetFlow export protocol
  84. supports it (currently only NetFlow v.9 possesses an IPv6 export capability).
  85. .Pp
  86. .Nm
  87. tries to track only active traffic flows.
  88. When the
  89. flow has been quiescent for a period of time it is expired automatically.
  90. Flows may also be expired early if they approach their traffic counts
  91. exceed 2 Gib or if the number of flows being tracked exceeds
  92. .Ar max_flows
  93. (default: 8192).
  94. In this last case, flows are expired oldest-first.
  95. .Pp
  96. Upon expiry, the flow information is accumulated into statistics which may
  97. be viewed using
  98. .Xr softflowctl 8 .
  99. If the
  100. .Fl n
  101. option has been specified the flow information is formatted in a UDP datagram
  102. which is compatible with versions 1, 5 or 9 of Cisco's NetFlow(tm) accounting
  103. export format.
  104. These records are sent to the specified
  105. .Ar host
  106. and
  107. .Ar port .
  108. The host may represent a unicast host or a multicast group.
  109. .Pp
  110. The command-line options are as follows:
  111. .Bl -tag -width Ds
  112. .It Fl n Ar host:port
  113. Specify the
  114. .Ar host
  115. and
  116. .Ar port
  117. that the accounting datagrams are to be sent to.
  118. The host may be specified using a hostname or using a numeric IPv4 or
  119. IPv6 address.
  120. Numeric IPv6 addresses should be encosed in square brackets to avoid ambiguity
  121. between the address and the port.
  122. The destination port may be a portname listed in
  123. .Xr services 5
  124. or a numeric port.
  125. .It Fl i Xo
  126. .Sm off
  127. .Oo Ar if_ndx : Oc
  128. .Ar interface
  129. .Sm on
  130. .Xc
  131. Specify a network interface on which to listen for traffic.
  132. Either the
  133. .Fl i
  134. or the
  135. .Fl r
  136. options must be specified.
  137. .It Fl r Ar pcap_file
  138. Specify that
  139. .Nm
  140. should read from a
  141. .Xr pcap 3
  142. packet capture file (such as one created with the
  143. .Fl w
  144. option of
  145. .Xr tcpdump 8 )
  146. file rather than a network interface.
  147. .Nm
  148. processes the whole capture file and only expires flows when
  149. .Ar max_flows
  150. is exceeded.
  151. In this mode,
  152. .Nm
  153. will not fork and will automatically print summary statistics before
  154. exiting.
  155. .It Fl p Ar pidfile
  156. Specify an alternate location to store the process ID when in daemon mode.
  157. Default is
  158. .Pa /var/run/softflowd.pid
  159. .It Fl c Ar ctlsock
  160. Specify an alternate location for the remote control socket in daemon mode.
  161. Default is
  162. .Pa /var/run/softflowd.ctl
  163. .It Fl m Ar max_flows
  164. Specify the maximum number of flow to concurrently track.
  165. If this limit is exceeded, the flows which have least recently seen traffic
  166. are forcibly expired.
  167. In practice, the actual maximum may briefly exceed this limit by a
  168. small amount as expiry processing happens less frequently than traffic
  169. collection.
  170. The default is 8192 flows, which corresponds to slightly less
  171. than 800k of working data.
  172. .It Fl t Ar timeout_name=time
  173. Set the timeout names
  174. .Ar timeout_name
  175. to
  176. .Ar time
  177. Refer to the
  178. .Sx Timeouts
  179. section for the valid timeout names and their meanings.
  180. The
  181. .Ar time
  182. parameter may be specified using one of the formats explained in the
  183. .Sx Time Formats
  184. section below.
  185. .It Fl d
  186. Specify that
  187. .Nm
  188. should not fork and daemonise itself.
  189. .It Fl 6
  190. Force
  191. .Nm
  192. To track IPv6 flows even if the NetFlow export protocol does not support
  193. reporting them.
  194. This is useful for debugging and statistics gathering only.
  195. .It Fl D
  196. Places
  197. .Nm
  198. in a debugging mode.
  199. This implies the
  200. .Fl d
  201. and
  202. .Fl 6
  203. flags and turns on additional debugging output.
  204. .It Fl h
  205. Display command-line usage information.
  206. .It Fl L Ar hoplimit
  207. Set the IPv4 TTL or the IPv6 hop limit to
  208. .Ar hoplimit .
  209. .Nm
  210. will use the default system TTL when exporting flows to a unicast host.
  211. When exporting to a multicast group, the default TTL will be 1
  212. (i.e. link-local).
  213. .It Fl T Ar track_level
  214. Specify which flow elements
  215. .Nm
  216. should be used to define a flow.
  217. .Ar track_level
  218. may be one of:
  219. .Dq full
  220. (track everything in the flow, the default),
  221. .Dq proto
  222. (track source and destination addresses and protocol), or
  223. .Dq ip
  224. (only track source and destination addresses).
  225. Selecting either of the latter options will produce flows with less information
  226. in them (e.g. TCP/UDP ports will not be recorded).
  227. This will cause flows to be consolidated, reducing the quantity of output
  228. and CPU load that
  229. .Nm
  230. will place on the system at the cost of some detail being lost.
  231. .It Fl v Ar netflow_version
  232. Specify which version of the NetFlow(tm) protocol
  233. .Nm
  234. should use for export of the flow data.
  235. Supported versions are 1, 5 and 9.
  236. Default is version 5.
  237. .El
  238. .Pp
  239. Any further command-line arguments will be concatenated together and
  240. applied as a
  241. .Xr bpf 4
  242. packet filter.
  243. This filter will cause
  244. .Nm
  245. to ignore the specified traffic.
  246. .Ss Timeouts
  247. .Pp
  248. .Nm
  249. will expire quiescent flows after user-configurable periods.
  250. The exact timeout used depends on the nature of the flow.
  251. The various timeouts that may be set from the command-line (using the
  252. .Fl t
  253. option) and their meanings are:
  254. .Bl -tag -width Ds
  255. .It Ar general
  256. This is the general timeout applied to all traffic unless overridden by
  257. one of the other timeouts.
  258. .It Ar tcp
  259. This is the general TCP timeout, applied to open TCP connections.
  260. .It Ar tcp.rst
  261. This timeout is applied to a TCP connection when a RST packet has been
  262. sent by one or both endpoints.
  263. .It Ar tcp.fin
  264. This timeout is applied to a TCP connection when a FIN packet has been
  265. sent by both endpoints.
  266. .It Ar udp
  267. This is the general UDP timeout, applied to all UDP connections.
  268. .It Ar maxlife
  269. This is the maximum lifetime that a flow may exist for.
  270. All flows are forcibly expired when they pass
  271. .Ar maxlife
  272. seconds.
  273. To disable this feature, specify a
  274. .Ar maxlife
  275. of 0.
  276. .It Ar expint
  277. Specify the interval between expiry checks.
  278. Increase this to group more flows into a NetFlow packet.
  279. To disable this feature, specify a
  280. .Ar expint
  281. of 0.
  282. .El
  283. .Pp
  284. Flows may also be expired if there are not enough flow entries to hold them
  285. or if their traffic exceeds 2 Gib in either direction.
  286. .Xr softflowctl 8
  287. may be used to print information on the average lifetimes of flows and
  288. the reasons for their expiry.
  289. .Ss Time Formats
  290. .Pp
  291. .Nm
  292. command-line arguments that specify time may be expressed using a sequence
  293. of the form:
  294. .Sm off
  295. .Ar time Op Ar qualifier ,
  296. .Sm on
  297. where
  298. .Ar time
  299. is a positive integer value and
  300. .Ar qualifier
  301. is one of the following:
  302. .Pp
  303. .Bl -tag -width Ds -compact -offset indent
  304. .It Cm <none>
  305. seconds
  306. .It Cm s | Cm S
  307. seconds
  308. .It Cm m | Cm M
  309. minutes
  310. .It Cm h | Cm H
  311. hours
  312. .It Cm d | Cm D
  313. days
  314. .It Cm w | Cm W
  315. weeks
  316. .El
  317. .Pp
  318. Each member of the sequence is added together to calculate the total time value.
  319. .Pp
  320. Time format examples:
  321. .Pp
  322. .Bl -tag -width Ds -compact -offset indent
  323. .It 600
  324. 600 seconds (10 minutes)
  325. .It 10m
  326. 10 minutes
  327. .It 1h30m
  328. 1 hour 30 minutes (90 minutes)
  329. .El
  330. .Ss Run-time Control
  331. .Pp
  332. A daemonised
  333. .Nm
  334. instance may be controlled using the
  335. .Xr softflowctl 8
  336. command.
  337. This interface allows one to shut down the daemon, force expiry of
  338. all tracked flows and extract debugging and summary data.
  339. Also, upon receipt of a
  340. .Dv SIGTERM
  341. or
  342. .DV SIGINT
  343. .Nm
  344. will cause
  345. .Nm
  346. to exit, after expiring all flows (and thus sending flow export packets
  347. if
  348. .Fl n
  349. was specified on the command-line).
  350. If you do not want to export flows upon shutdown, clear them first with
  351. .Xr softflowctl 8
  352. or use
  353. .Xr softflowctl 8 's
  354. .Dq exit
  355. command.
  356. .Sh EXAMPLES
  357. .Bl -tag -width Ds
  358. .It softflowd -i fxp0
  359. This command-line will cause
  360. .Nm
  361. to listen on interface fxp0 and to run in statistics gathering mode
  362. only (i.e. no NetFlow data export).
  363. .It softflowd -i fxp0 -n 10.1.0.2:4432
  364. This command-line will cause
  365. .Nm
  366. to listen on interface fxp0 and to export NetFlow v.5 datagrams on flow
  367. expiry to a flow collector running on 10.1.0.2 port 4432.
  368. .It softflowd -v 5 -i fxp0 -n 10.1.0.2:4432 -m 65536 -t udp=1m30s
  369. This command-line increases the number of concurrent flows that
  370. .Nm
  371. will track to 65536 and increases the timeout for UDP flows to 90 seconds.
  372. .It softflowd -v 9 -i fxp0 -n 224.0.1.20:4432 -L 64
  373. This command-line will export NetFlow v.9 flows to the multicast group
  374. 224.0.1.20.
  375. The export datagrams will have their TTL set to 64, so multicast receivers
  376. can be many hops away.
  377. .It softflowd -i fxp0 -p /var/run/sfd.pid.fxp0 -c /var/run/sfd.ctl.fxp0
  378. This command-line specifies alternate locations for the control socket
  379. and pid file.
  380. Similar command-lines are useful when running multiple
  381. instances of
  382. .Nm
  383. on a single machine.
  384. .El
  385. .Sh FILES
  386. .Bl -tag -width Ds
  387. .It Pa /var/run/softflowd.pid
  388. This file stores the process ID when
  389. .Nm
  390. is in daemon mode.
  391. This location may be overridden using the
  392. .Fl p
  393. command-line option.
  394. .It Pa /var/run/softflowd.ctl
  395. This is the remote control socket.
  396. .Nm
  397. listens on this socket for commands from
  398. .Xr softflowctl 8 .
  399. This location may be overridden using the
  400. .Fl c
  401. command-line option.
  402. .El
  403. .Sh BUGS
  404. Currently
  405. .Nm
  406. does not handle maliciously fragmented packets properly, i.e. packets
  407. fragemented such that the UDP or TCP header does not fit into the first
  408. fragment.
  409. It will product correct traffic counts when presented with maliciously
  410. fragmented packets, but will not record TCP or UDP port information.
  411. .Sh AUTHORS
  412. .An Damien Miller Aq djm@mindrot.org
  413. .Sh SEE ALSO
  414. .Xr softflowctl 8 ,
  415. .Xr tcpdump 8 ,
  416. .Xr pcap 3 ,
  417. .Xr bpf 4
  418. .Bd -literal
  419. http://www.cisco.com/univercd/cc/td/doc/product/rtrmgmt/nfc/nfc_3_0/nfc_ug/nfcform.htm
  420. .Ed