softflowd.8 14 KB

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