2 .\" Copyright (c) 2010 The FreeBSD Foundation
4 .\" Portions of this software were developed at the Centre for Advanced
5 .\" Internet Architectures, Swinburne University of Technology, Melbourne,
6 .\" Australia by Lawrence Stewart under sponsorship from the FreeBSD
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions, and the following disclaimer,
14 .\" without modification, immediately at the beginning of the file.
15 .\" 2. The name of the author may not be used to endorse or promote products
16 .\" derived from this software without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 .\" ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .Nd Statistical Information For TCP Research
39 as a module at run-time, run the following command as root:
40 .Bd -literal -offset indent
44 Alternatively, to load
46 as a module at boot time, add the following line into the
49 .Bd -literal -offset indent
62 kernel module logs a range of statistics on active TCP connections to
64 It provides the ability to make highly granular measurements of TCP connection
65 state, aimed at system administrators, developers and researchers.
66 .Ss Compile-time Configuration
67 The default operation of
69 is to capture IPv4 TCP/IP packets.
71 can be configured to support IPv4 and IPv6 by uncommenting:
72 .Bd -literal -offset indent
77 .Aq sys/modules/siftr/Makefile
80 In the IPv4-only (default) mode, standard dotted decimal notation (e.g.
81 "136.186.229.95") is used to format IPv4 addresses for logging.
82 In IPv6 mode, standard dotted decimal notation is used to format IPv4 addresses,
83 and standard colon-separated hex notation (see RFC 4291) is used to format IPv6
84 addresses (e.g. "fd00::2") for logging.
85 .Ss Run-time Configuration
89 interface to export its configuration variables to user-space.
90 The following variables are available:
91 .Bl -tag -offset indent -width Va
92 .It Va net.inet.siftr.enabled
93 controls whether the module performs its
95 By default, the value is set to 0, which means the module
96 will not be taking any measurements.
97 Having the module loaded with
98 .Va net.inet.siftr.enabled
99 set to 0 will have no impact on the performance of the network stack, as the
100 packet filtering hooks are only inserted when
101 .Va net.inet.siftr.enabled
104 .Bl -tag -offset indent -width Va
105 .It Va net.inet.siftr.ppl
106 controls how many inbound/outbound packets for a given TCP connection will cause
107 a log message to be generated for the connection.
108 By default, the value is set to 1, which means the module will log a message for
109 every packet of every TCP connection.
110 The value can be set to any integer in the range [1,2^32], and can be changed at
111 any time, even while the module is enabled.
113 .Bl -tag -offset indent -width Va
114 .It Va net.inet.siftr.logfile
115 controls the path to the file that the module writes its log messages to.
116 By default, the file /var/log/siftr.log is used.
117 The path can be changed at any time, even while the module is enabled.
119 .Bl -tag -offset indent -width Va
120 .It Va net.inet.siftr.port_filter
121 controls on which source or destination port
124 By default, the value is set to 0, which means all ports are eligible for logging.
125 Set to any other value, only packets where either the source or destination
126 port is equal to this number are logged.
131 log file will contain 3 different types of log message.
132 All messages are written in plain ASCII text.
136 present in the example log messages in this section indicates a
137 line continuation and is not part of the actual log message.
139 The first type of log message is written to the file when the module is
140 enabled and starts collecting data from the running kernel.
141 The text below shows an example module enable log.
142 The fields are tab delimited key-value
143 pairs which describe some basic information about the system.
144 .Bd -literal -offset indent
145 enable_time_secs=1685191807 enable_time_usecs=160752 \\
146 siftrver=1.3.0 sysname=FreeBSD sysver=1400089 ipmode=4
149 Field descriptions are as follows:
150 .Bl -tag -offset indent -width Va
151 .It Va enable_time_secs
152 time at which the module was enabled, in seconds since the UNIX epoch.
154 .Bl -tag -offset indent -width Va
155 .It Va enable_time_usecs
156 time at which the module was enabled, in microseconds since enable_time_secs.
158 .Bl -tag -offset indent -width Va
163 .Bl -tag -offset indent -width Va
165 operating system name.
167 .Bl -tag -offset indent -width Va
169 operating system version.
171 .Bl -tag -offset indent -width Va
173 IP mode as defined at compile time.
174 An ipmode of "4" means IPv6 is not supported and IP addresses are logged in
175 regular dotted quad format.
176 An ipmode of "6" means IPv6 is supported, and IP addresses are logged in dotted
177 quad or hex format, as described in the
178 .Qq Compile-time Configuration
182 The second type of log message is written to the file when a data log message
184 The text below shows an example data log triggered by an IPv4
186 The data is CSV formatted.
187 .Bd -literal -offset indent
188 o,1685191814.185109,10.1.1.2,32291,10.1.1.3,5001,1073725440, \\
189 14480,2,65160,65700,7,9,4,1460,1000,1,16778209,230000,33580,0, \\
190 65700,0,0,0,86707916,130
193 Field descriptions are as follows:
194 .Bl -tag -offset indent -width Va
196 Direction of packet that triggered the log message.
203 .Bl -tag -offset indent -width Va
205 Time at which the packet that triggered the log message was processed by
208 hook function, in seconds and microseconds since the UNIX epoch.
210 .Bl -tag -offset indent -width Va
212 The IPv4 or IPv6 address of the local host, in dotted quad (IPv4 packet)
213 or colon-separated hex (IPv6 packet) notation.
215 .Bl -tag -offset indent -width Va
217 The TCP port that the local host is communicating via.
219 .Bl -tag -offset indent -width Va
221 The IPv4 or IPv6 address of the foreign host, in dotted quad (IPv4 packet)
222 or colon-separated hex (IPv6 packet) notation.
224 .Bl -tag -offset indent -width Va
226 The TCP port that the foreign host is communicating via.
228 .Bl -tag -offset indent -width Va
230 The slow start threshold for the flow, in bytes.
232 .Bl -tag -offset indent -width Va
234 The current congestion window for the flow, in bytes.
236 .Bl -tag -offset indent -width Va
238 The current state of the t_flags2 field for the flow.
240 .Bl -tag -offset indent -width Va
242 The current sending window for the flow, in bytes.
243 The post scaled value is reported.
245 .Bl -tag -offset indent -width Va
247 The current receive window for the flow, in bytes.
248 The post scaled value is always reported.
250 .Bl -tag -offset indent -width Va
252 The current window scaling factor for the sending window.
254 .Bl -tag -offset indent -width Va
256 The current window scaling factor for the receiving window.
258 .Bl -tag -offset indent -width Va
260 The current state of the TCP finite state machine, as defined
262 .Aq Pa netinet/tcp_fsm.h .
264 .Bl -tag -offset indent -width Va
266 The maximum segment size for the flow, in bytes.
268 .Bl -tag -offset indent -width Va
270 The current smoothed RTT estimate for the flow, in units of microsecond.
272 .Bl -tag -offset indent -width Va
274 SACK enabled indicator. 1 if SACK enabled, 0 otherwise.
276 .Bl -tag -offset indent -width Va
278 The current state of the TCP flags for the flow.
280 .Aq Pa netinet/tcp_var.h
281 for information about the various flags.
283 .Bl -tag -offset indent -width Va
285 The current retransmission timeout length for the flow, in units microsecond.
287 .Bl -tag -offset indent -width Va
289 The current size of the socket send buffer in bytes.
291 .Bl -tag -offset indent -width Va
293 The current number of bytes in the socket send buffer.
295 .Bl -tag -offset indent -width Va
297 The current size of the socket receive buffer in bytes.
299 .Bl -tag -offset indent -width Va
301 The current number of bytes in the socket receive buffer.
303 .Bl -tag -offset indent -width Va
305 The current number of unacknowledged bytes in-flight.
306 Bytes acknowledged via SACK are not excluded from this count.
308 .Bl -tag -offset indent -width Va
310 The current number of segments in the reassembly queue.
312 .Bl -tag -offset indent -width Va
314 Flowid for the connection.
315 A caveat: Zero '0' either represents a valid flowid or a default value when it's
317 There is no easy way to differentiate without looking at actual
318 network interface card and drivers being used.
320 .Bl -tag -offset indent -width Va
322 Flow type for the connection.
323 Flowtype defines which protocol fields are hashed to produce the flowid.
324 A complete listing is available in
330 The third type of log message is written to the file when the module is disabled
331 and ceases collecting data from the running kernel.
332 The text below shows an example module disable log.
333 The fields are tab delimited key-value pairs which provide statistics about
334 operations since the module was most recently enabled.
335 .Bd -literal -offset indent
336 disable_time_secs=1685191816 disable_time_usecs=629397 \\
337 num_inbound_tcp_pkts=10 num_outbound_tcp_pkts=10 \\
338 total_tcp_pkts=20 num_inbound_skipped_pkts_malloc=0 \\
339 num_outbound_skipped_pkts_malloc=0 num_inbound_skipped_pkts_tcpcb=2 \\
340 num_outbound_skipped_pkts_tcpcb=2 num_inbound_skipped_pkts_inpcb=0 \\
341 num_outbound_skipped_pkts_inpcb=0 total_skipped_tcp_pkts=4 \\
342 flow_list=10.1.1.2;32291-10.1.1.3;5001,10.1.1.2;58544-10.1.1.3;5001,
345 Field descriptions are as follows:
346 .Bl -tag -offset indent -width Va
347 .It Va disable_time_secs
348 Time at which the module was disabled, in seconds since the UNIX epoch.
350 .Bl -tag -offset indent -width Va
351 .It Va disable_time_usecs
352 Time at which the module was disabled, in microseconds since disable_time_secs.
354 .Bl -tag -offset indent -width Va
355 .It Va num_inbound_tcp_pkts
356 Number of TCP packets that traversed up the network stack.
357 This only includes inbound TCP packets during the periods when
361 .Bl -tag -offset indent -width Va
362 .It Va num_outbound_tcp_pkts
363 Number of TCP packets that traversed down the network stack.
364 This only includes outbound TCP packets during the periods when
368 .Bl -tag -offset indent -width Va
369 .It Va total_tcp_pkts
370 The summation of num_inbound_tcp_pkts and num_outbound_tcp_pkts.
372 .Bl -tag -offset indent -width Va
373 .It Va num_inbound_skipped_pkts_malloc
374 Number of inbound packets that were not processed because of failed
378 .Bl -tag -offset indent -width Va
379 .It Va num_outbound_skipped_pkts_malloc
380 Number of outbound packets that were not processed because of failed
384 .Bl -tag -offset indent -width Va
385 .It Va num_inbound_skipped_pkts_tcpcb
386 Number of inbound packets that were not processed because of failure to find the
387 TCP control block associated with the packet.
389 .Bl -tag -offset indent -width Va
390 .It Va num_outbound_skipped_pkts_tcpcb
391 Number of outbound packets that were not processed because of failure to find
392 the TCP control block associated with the packet.
394 .Bl -tag -offset indent -width Va
395 .It Va num_inbound_skipped_pkts_inpcb
396 Number of inbound packets that were not processed because of failure to find the
397 IP control block associated with the packet.
399 .Bl -tag -offset indent -width Va
400 .It Va num_outbound_skipped_pkts_inpcb
401 Number of outbound packets that were not processed because of failure to find
402 the IP control block associated with the packet.
404 .Bl -tag -offset indent -width Va
405 .It Va total_skipped_tcp_pkts
406 The summation of all skipped packet counters.
408 .Bl -tag -offset indent -width Va
410 A CSV list of TCP flows that triggered data log messages to be generated since
411 the module was loaded.
412 Each flow entry in the CSV list is
414 .Qq local_ip;local_port-foreign_ip;foreign_port .
415 If there are no entries in the list (i.e., no data log messages were generated),
416 the value will be blank.
417 If there is at least one entry in the list, a trailing comma will always be
421 The total number of data log messages found in the log file for a module
422 enable/disable cycle should equate to total_tcp_pkts - total_skipped_tcp_pkts.
423 .Sh IMPLEMENTATION NOTES
425 hooks into the network stack using the
428 In its current incarnation, it hooks into the AF_INET/AF_INET6 (IPv4/IPv6)
430 filtering points, which means it sees packets at the IP layer of the network
432 This means that TCP packets inbound to the stack are intercepted before
433 they have been processed by the TCP layer.
434 Packets outbound from the stack are intercepted after they have been processed
437 The diagram below illustrates how
439 inserts itself into the stack.
440 .Bd -literal -offset indent
441 ----------------------------------
443 ----------------------------------
449 ----------------------------------
458 ________| |__________
461 IPv{4/6} in IPv{4/6} out
462 ----------------------------------
466 Layer 2 in Layer 2 out
467 ----------------------------------
469 ----------------------------------
475 interface to manage writing data to disk.
477 At first glance, you might mistakenly think that
479 extracts information from
480 individual TCP packets.
481 This is not the case.
483 uses TCP packet events (inbound and outbound) for each TCP flow originating from
484 the system to trigger a dump of the state of the TCP control block for that
486 With the PPL set to 1, we are in effect sampling each TCP flow's control block
487 state as frequently as flow packets enter/leave the system.
488 For example, setting PPL to 2 halves the sampling rate i.e., every second flow
489 packet (inbound OR outbound) causes a dump of the control block state.
491 The distinction between interrogating individual packets versus interrogating the
492 control block is important, because
494 does not remove the need for packet capturing tools like
497 allows you to correlate and observe the cause-and-affect relationship between
498 what you see on the wire (captured using a tool like
500 and changes in the TCP control block corresponding to the flow of interest.
501 It is therefore useful to use
505 to gather the necessary data to piece together the complete picture.
506 Use of either tool on its own will not be able to provide all of the necessary
509 As a result of needing to interrogate the TCP control block, certain packets
510 during the lifecycle of a connection are unable to trigger a
513 The initial handshake takes place without the existence of a control block or
514 the complete initialization of the control block, and the final ACK is
515 exchanged when the connection is in the TIMEWAIT state.
518 was designed to minimise the delay introduced to packets traversing the network
520 This design called for a highly optimised and minimal hook function that
521 extracted the minimal details necessary whilst holding the packet up, and
522 passing these details to another thread for actual processing and logging.
524 This multithreaded design does introduce some contention issues when accessing
525 the data structure shared between the threads of operation.
526 When the hook function tries to place details in the structure, it must first
527 acquire an exclusive lock.
528 Likewise, when the processing thread tries to read details from the structure,
529 it must also acquire an exclusive lock to do so.
530 If one thread holds the lock, the other must wait before it can obtain it.
531 This does introduce some additional bounded delay into the kernel's packet
532 processing code path.
534 In some cases (e.g., low memory, connection termination), TCP packets that enter
538 hook function will not trigger a log message to be generated.
540 refers to this outcome as a
544 always ensures that packets are allowed to continue through the stack, even if
545 they could not successfully trigger a data log message.
547 will therefore not introduce any packet loss for TCP/IP packets traversing the
549 .Ss Important Behaviours
550 The behaviour of a log file path change whilst the module is enabled is as
554 Attempt to open the new file path for writing.
555 If this fails, the path change will fail and the existing path will continue to
558 Assuming the new path is valid and opened successfully:
561 Flush all pending log messages to the old file path.
563 Close the old file path.
565 Switch the active log file pointer to point at the new file path.
567 Commence logging to the new file.
571 During the time between the flush of pending log messages to the old file and
572 commencing logging to the new file, new log messages will still be generated and
574 As soon as the new file path is ready for writing, the accumulated log messages
575 will be written out to the file.
577 To enable the module's operations, run the following command as root:
578 sysctl net.inet.siftr.enabled=1
580 To change the granularity of log messages such that 1 log message is
581 generated for every 10 TCP packets per connection, run the following
583 sysctl net.inet.siftr.ppl=10
585 To change the log file location to /tmp/siftr.log, run the following
587 sysctl net.inet.siftr.logfile=/tmp/siftr.log
595 Development of this software was made possible in part by grants from the
596 Cisco University Research Program Fund at Community Foundation Silicon Valley,
597 and the FreeBSD Foundation.
606 was first released in 2007 by Lawrence Stewart and James Healy whilst working on
607 the NewTCP research project at Swinburne University of Technology's Centre for
608 Advanced Internet Architectures, Melbourne, Australia, which was made possible
609 in part by a grant from the Cisco University Research Program Fund at Community
610 Foundation Silicon Valley.
611 More details are available at:
613 http://caia.swin.edu.au/urp/newtcp/
617 v1.2.x was sponsored by the FreeBSD Foundation as part of
619 .Qq Enhancing the FreeBSD TCP Implementation
621 More details are available at:
623 https://www.freebsdfoundation.org/
625 http://caia.swin.edu.au/freebsd/etcp09/
630 .An Lawrence Stewart Aq Mt lstewart@FreeBSD.org
632 .An James Healy Aq Mt jimmy@deefa.com .
634 This manual page was written by
635 .An Lawrence Stewart Aq Mt lstewart@FreeBSD.org .
637 Current known limitations and any relevant workarounds are outlined below:
640 The internal queue used to pass information between the threads of operation is
644 to cope with bursty network traffic, but sustained high packet-per-second
645 traffic can cause exhaustion of kernel memory if the processing thread cannot
646 keep up with the packet rate.
650 on a machine that is also running other modules utilising the
656 the order in which you load the modules is important.
657 You should kldload the other modules first, as this will ensure TCP packets
658 undergo any necessary manipulations before
663 There is a known, harmless lock order reversal warning between the
665 mutex and tcbinfo TCP lock reported by
669 is enabled in a kernel compiled with
673 There is no way to filter which TCP flows you wish to capture data for.
674 Post processing is required to separate out data belonging to particular flows
677 The module does not detect deletion of the log file path.
678 New log messages will simply be lost if the log file being used by
680 is deleted whilst the module is set to use the file.
681 Switching to a new log file using the
682 .Em net.inet.siftr.logfile
683 variable will create the new file and allow log messages to begin being written
685 The new log file path must differ from the path to the deleted file.
687 The hash table used within the code is sized to hold 65536 flows.
689 hard limit, because chaining is used to handle collisions within the hash table
691 However, we suspect (based on analogies with other hash table performance data)
692 that the hash table look up performance (and therefore the module's packet
693 processing performance) will degrade in an exponential manner as the number of
694 unique flows handled in a module enable/disable cycle approaches and surpasses
697 There is no garbage collection performed on the flow hash table.
698 The only way currently to flush it is to disable
701 The PPL variable applies to packets that make it into the processing thread,
702 not total packets received in the hook function.
703 Packets are skipped before the PPL variable is applied, which means there may be
704 a slight discrepancy in the triggering of log messages.
705 For example, if PPL was set to 10, and the 8th packet since the last log message
706 is skipped, the 11th packet will actually trigger the log message to be
708 This is discussed in greater depth in CAIA technical report 070824A.
710 At the time of writing, there was no simple way to hook into the TCP layer
711 to intercept packets.
713 use of IP layer hook points means all IP
714 traffic will be processed by the
717 hook function, which introduces minor, but nonetheless unnecessary packet delay
718 and processing overhead on the system for non-TCP packets as well.
719 Hooking in at the IP layer is also not ideal from the data gathering point of
721 Packets traversing up the stack will be intercepted and cause a log message
722 generation BEFORE they have been processed by the TCP layer, which means we
723 cannot observe the cause-and-affect relationship between inbound events and the
724 corresponding TCP control block as precisely as could be.
727 should intercept packets after they have been processed by the TCP layer i.e.
728 intercept packets coming up the stack after they have been processed by
730 and intercept packets coming down the stack after they have been
733 The current code still gives satisfactory granularity though, as inbound events
734 tend to trigger outbound events, allowing the cause-and-effect to be observed
735 indirectly by capturing the state on outbound events as well.
741 does not take into account bytes that have been
743 by the receiving host.