SIFTR(4)
SIFTR(4) π β Statistical Information For TCP Research
okay bestie, sit DOWN, because this is the kernel interfaces manual page for SIFTR, and it is literally the group chat of TCP statistics π
. Kernel Interfaces Manual, if you need the formal vibe. Let's get into it.
β¨ NAME β¨
SIFTR β Statistical Information For TCP Research π
π¦ SYNOPSIS π¦
Wanna load the driver as a module at run-time? Bestie, run this as root:
kldload siftr
Alternatively β and this is giving very "set it and forget it" main character energy β to load the driver as a module at boot time, just add this line into the loader.conf(5) file:
siftr_load="YES"
πΈ DESCRIPTION πΈ
The SIFTR (Statistical Information For TCP Research) kernel module logs a whole range of statistics on active TCP connections to a log file. No cap. It gives you the ability to make highly granular measurements of TCP connection state, and it's aimed at system administrators, developers and researchers. π
π§ Compile-time Configuration π§
By default, SIFTR captures IPv4 TCP/IP packets. That's the default operation, periodt. But if you want IPv4 and IPv6 support, uncomment:
CFLAGS+=-DSIFTR_IPV6
...inside β¨sys/modules/siftr/Makefileβ© and recompile. Slay.
So in the IPv4-only (default) mode, standard dotted decimal notation (e.g. "136.186.229.95") is used to format IPv4 addresses for logging. In IPv6 mode, standard dotted decimal notation is used to format IPv4 addresses, and standard colon-separated hex notation (see RFC 4291) is used to format IPv6 addresses for logging. π
Heads up though:SIFTRuses uncompressed notation to format IPv6 addresses. Not the cute shortened version. So for example, the address"fe80::20f:feff:fea2:531b"would be logged as"fe80:0:0:0:20f:feff:fea2:531b". Yes, all the zeroes. She's thorough. π
π Run-time Configuration π
SIFTR utilises the sysctl(8) interface to export its configuration variables to user-space. The following variables are available:
net.inet.siftr.enabledβ controls whether the module performs its measurements or not. By default, the value is set to0, which means the module will not be taking any measurements. Having the module loaded withnet.inet.siftr.enabledset to0will have no impact on the performance of the network stack, as the packet filtering hooks are only inserted whennet.inet.siftr.enabledis set to1. π₯net.inet.siftr.pplβ controls how many inbound/outbound packets for a given TCP connection will cause a log message to be generated for the connection. By default, the value is set to1, which means the module will log a message for every packet of every TCP connection. The value can be set to any integer in the range[1,2^32], and can be changed at any time, even while the module is enabled. β¨net.inet.siftr.logfileβ controls the path to the file that the module writes its log messages to. By default, the file/var/log/siftr.logis used. The path can be changed at any time, even while the module is enabled. πnet.inet.siftr.genhashesβ controls whether a hash is generated for each TCP packet seen bySIFTR. By default, the value is set to0, which means no hashes are generated. The hashes are useful to correlate which TCP packet triggered the generation of a particular log message, but calculating them adds additional computational overhead into the fast path. (So like, useful but also a lil extra. iykyk. π)net.inet.siftr.port_filterβ controls on which source or destination portsiftrshould captureSIFTR. By default, the value is set to0, which means all ports are eligible for logging. Set to any other value, only packets where either the source or destination port is equal to this number are logged. π«Ά
π Log Format π
A typical SIFTR log file will contain 3 different types of log message. All messages are written in plain ASCII text. Simple. Clean. Iconic.
Note: The "\" present in the example log messages in this section indicates a line continuation and is not part of the actual log message. Don't be confused bestie, it's just wrapping for readability. π
π The first type β module enable log π
The first type of log message is written to the file when the module is enabled and starts collecting data from the running kernel. The text below shows an example module enable log. The fields are tab delimited key-value pairs which describe some basic information about the system.
enable_time_secs=1238556193 enable_time_usecs=462104 \
siftrver=1.2.2 hz=1000 tcp_rtt_scale=32 \
sysname=FreeBSD sysver=604000 ipmode=4
Field descriptions are as follows:
enable_time_secsβ time at which the module was enabled, in seconds since the UNIX epoch.enable_time_usecsβ time at which the module was enabled, in microseconds sinceenable_time_secs.siftrverβ version ofSIFTR.hzβ tick rate of the kernel in ticks per second.tcp_rtt_scaleβ smoothed RTT estimate scaling factor.sysnameβ operating system name.sysverβ operating system version.ipmodeβ IP mode as defined at compile time. Anipmodeof"4"means IPv6 is not supported and IP addresses are logged in regular dotted quad format. Anipmodeof"6"means IPv6 is supported, and IP addresses are logged in dotted quad or hex format, as described in the "Compile-time Configuration" subsection. π
π₯ The second type β data log message π₯
The second type of log message is written to the file when a data log message is generated. The text below shows an example data log triggered by an IPv4 TCP/IP packet. The data is CSV formatted.
o,0xbec491a5,1238556193.463551,172.16.7.28,22,172.16.2.5,55931, \
1073725440,172312,6144,66560,66608,8,1,4,1448,936,1,996,255, \
33304,208,66608,0,208,0
Field descriptions are as follows:
- Direction of packet that triggered the log message. Either
"i"for in, or"o"for out. - Hash of the packet that triggered the log message.
- Time at which the packet that triggered the log message was processed by the
pfil(9)hook function, in seconds and microseconds since the UNIX epoch. - The IPv4 or IPv6 address of the local host, in dotted quad (IPv4 packet) or colon-separated hex (IPv6 packet) notation.
- The TCP port that the local host is communicating via.
- The IPv4 or IPv6 address of the foreign host, in dotted quad (IPv4 packet) or colon-separated hex (IPv6 packet) notation.
- The TCP port that the foreign host is communicating via.
- The slow start threshold for the flow, in bytes.
- The current congestion window for the flow, in bytes.
- The current bandwidth-controlled window for the flow, in bytes.
- The current sending window for the flow, in bytes. The post scaled value is reported, except during the initial handshake (first few packets), during which time the unscaled value is reported.
- The current receive window for the flow, in bytes. The post scaled value is always reported.
- The current window scaling factor for the sending window.
- The current window scaling factor for the receiving window.
- The current state of the TCP finite state machine, as defined in β¨
netinet/tcp_fsm.hβ©. - The maximum segment size for the flow, in bytes.
- The current smoothed RTT estimate for the flow, in units of
TCP_RTT_SCALE * HZ, whereTCP_RTT_SCALEis a define found intcp_var.h, andHZis the kernel's tick timer. Divide byTCP_RTT_SCALE * HZto get the RTT in secs.TCP_RTT_SCALEandHZare reported in the enable log message. - SACK enabled indicator.
1if SACK enabled,0otherwise. - The current state of the TCP flags for the flow. See β¨
netinet/tcp_var.hβ© for information about the various flags. - The current retransmission timeout length for the flow, in units of
HZ, whereHZis the kernel's tick timer. Divide byHZto get the timeout length in seconds.HZis reported in the enable log message. - The current size of the socket send buffer in bytes.
- The current number of bytes in the socket send buffer.
- The current size of the socket receive buffer in bytes.
- The current number of bytes in the socket receive buffer.
- The current number of unacknowledged bytes in-flight. Bytes acknowledged via SACK are not excluded from this count.
- The current number of segments in the reassembly queue.
- Flowid for the connection. A caveat: Zero
'0'either represents a valid flowid or a default value when it's not being set. There is no easy way to differentiate without looking at actual network interface card and drivers being used. π (this one is giving ambiguity, we love that for us) - Flow type for the connection. Flowtype defines which protocol fields are hashed to produce the flowid. A complete listing is available in
sys/mbuf.hunderM_HASHTYPE_*.
π«Ά The third type β module disable log π«Ά
The third type of log message is written to the file when the module is disabled and ceases collecting data from the running kernel. The text below shows an example module disable log. The fields are tab delimited key-value pairs which provide statistics about operations since the module was most recently enabled.
disable_time_secs=1238556197 disable_time_usecs=933607 \
num_inbound_tcp_pkts=356 num_outbound_tcp_pkts=627 \
total_tcp_pkts=983 num_inbound_skipped_pkts_malloc=0 \
num_outbound_skipped_pkts_malloc=0 num_inbound_skipped_pkts_mtx=0 \
num_outbound_skipped_pkts_mtx=0 num_inbound_skipped_pkts_tcb=0 \
num_outbound_skipped_pkts_tcb=0 num_inbound_skipped_pkts_icb=0 \
num_outbound_skipped_pkts_icb=0 total_skipped_tcp_pkts=0 \
flow_list=172.16.7.28;22-172.16.2.5;55931,
Okay so now let's go field by field, bestie, because this is the part where it all clicks π‘β¨
disable_time_secsβ the moment the module got disabled, measured in seconds since the UNIX epoch. Timestamp core fr πdisable_time_usecsβ the moment the module got disabled, in microseconds sincedisable_time_secs. Yeah it's the fancy sub-second lil garnish on top πnum_inbound_tcp_pktsβ how many TCP packets made their way up the network stack. Heads up: this only counts inbound TCP packets from the windows of time when SIFTR was actually enabled π«Άnum_outbound_tcp_pktsβ how many TCP packets traveled down the network stack. Same deal: only outbound TCP packets counted during the periods SIFTR was enabled, no cap π§total_tcp_pktsβ literally justnum_inbound_tcp_pkts+num_outbound_tcp_pkts. The math ate πnum_inbound_skipped_pkts_mallocβ inbound packets that got ghosted because amalloc()call flopped πnum_outbound_skipped_pkts_mallocβ outbound packets that got skipped for the same sad reason: failedmalloc()calls πnum_inbound_skipped_pkts_mtxβ inbound packets that weren't processed because the packet couldn't be added to the packet processing queue πnum_outbound_skipped_pkts_mtxβ outbound packets with the same tragic fate: couldn't get added to the packet processing queue π₯²num_inbound_skipped_pkts_tcbβ inbound packets that weren't processed because SIFTR couldn't find the TCP control block tied to that packet πnum_outbound_skipped_pkts_tcbβ outbound packets that weren't processed because, again, no TCP control block was found for them π§num_inbound_skipped_pkts_icbβ inbound packets that weren't processed because the IP control block for the packet could not be found π΅βπ«num_outbound_skipped_pkts_icbβ outbound packets that weren't processed because the IP control block for the packet could not be found πtotal_skipped_tcp_pktsβ the big sum of every single skipped packet counter up there. The skipped-packets main character πflow_listβ a CSV list of every TCP flow that triggered data log messages since the module got loaded. Each flow entry in that CSV is formatted like"local_ip;local_port-foreign_ip;foreign_port". If the list is empty (aka no data log messages were ever generated), the value is just blank. And if there's at least one entry in the list, there's always a trailing comma present, periodt β¨
Quick lil sanity check, bestie: the total number of data log messages you find in the log file for a module enable/disable cycle should equate to total_tcp_pkts - total_skipped_tcp_pkts. Math check incoming ππ
π IMPLEMENTATION NOTES π
SIFTR hooks into the network stack using the pfil(9) interface. In its current incarnation (so real, so current π
), it hooks into the AF_INET/AF_INET6 (IPv4/IPv6) pfil(9) filtering points, which means it's seeing packets at the IP layer of the network stack. So what does that actually mean? TCP packets inbound to the stack get intercepted before the TCP layer has processed them. Packets outbound from the stack get intercepted after the TCP layer already did its thing. Two different moments, iykyk β±οΈ
The diagram below illustrates how SIFTR inserts itself into the stack, and honestly it's giving beautiful:
----------------------------------
Upper Layers
----------------------------------
^ |
| |
| |
| v
TCP in TCP out
----------------------------------
^ |
|________ _________|
| |
| v
---------
| SIFTR |
---------
^ |
________| |__________
| |
| v
IPv{4/6} in IPv{4/6} out
----------------------------------
^ |
| |
| v
Layer 2 in Layer 2 out
----------------------------------
Physical Layer
----------------------------------
SIFTR uses the alq(9) interface to manage writing data to disk ποΈ
Now this next bit is important so listen up. At first glance, you might mistakenly think SIFTR extracts information from individual TCP packets. Not the case, bestie, absolutely not. SIFTR uses TCP packet events (inbound and outbound) for each TCP flow originating from the system to trigger a dump of the state of the TCP control block for that flow. With the PPL set to 1, we are in effect sampling each TCP flow's control block state as frequently as flow packets enter/leave the system. For example, setting PPL to 2 halves the sampling rate i.e., every second flow packet (inbound OR outbound) causes a dump of the control block state π
The distinction between interrogating individual packets versus interrogating the control block is important, because SIFTR does not remove the need for packet capturing tools like tcpdump(1). SIFTR lets you correlate and observe the cause-and-affect relationship between what you see on the wire (captured using a tool like tcpdump(1)) and changes in the TCP control block corresponding to the flow of interest. So it's genuinely useful to use SIFTR and a tool like tcpdump(1) together to gather the necessary data and piece together the complete picture. Either tool on its own will not be able to provide all of the necessary data. Teamwork makes the dream work fr π€β¨
As a result of needing to interrogate the TCP control block, certain packets during the lifecycle of a connection are unable to trigger a SIFTR log message. The initial handshake takes place without the existence of a control block, and the final ACK is exchanged when the connection is in the TIMEWAIT state. So those ones just... don't make it in π
SIFTR was designed to minimise the delay introduced to packets traversing the network stack. This design called for a highly optimised and minimal hook function that extracted the minimal details necessary whilst holding the packet up, and passing these details to another thread for actual processing and logging. Efficiency queen π
This multithreaded design does introduce some contention issues when accessing the data structure shared between the threads of operation. When the hook function tries to place details in the structure, it must first acquire an exclusive lock. Likewise, when the processing thread tries to read details from the structure, it must also acquire an exclusive lock to do so. If one thread holds the lock, the other has to wait before it can obtain it. This does introduce some additional bounded delay into the kernel's packet processing code path. Lowkey a lil traffic jam π¦
In some cases (e.g., low memory, connection termination), TCP packets that enter the SIFTR pfil(9) hook function will not trigger a log message to be generated. SIFTR refers to this outcome as a "skipped packet". Note that SIFTR always ensures that packets are allowed to continue through the stack, even if they couldn't successfully trigger a data log message. So SIFTR will therefore not introduce any packet loss for TCP/IP packets traversing the network stack. No packets harmed in the making of this log file π«Ά
π Important Behaviours π
The behaviour of a log file path change whilst the module is enabled goes like this:
- Attempt to open the new file path for writing. If this fails, the path change will fail and the existing path will continue to be used. No harm done, no swap.
- Assuming the new path is valid and opened successfully:
- Flush all pending log messages to the old file path.
- Close the old file path.
- Switch the active log file pointer to point at the new file path.
- Commence logging to the new file.
During the time between the flush of pending log messages to the old file and commencing logging to the new file, new log messages will still be generated and buffered. As soon as the new file path is ready for writing, the accumulated log messages will be written out to the file. Nothing gets dropped, it just queues up π
πΈ EXAMPLES πΈ
To enable the module's operations, run the following command as root:
sysctl net.inet.siftr.enabled=1
To change the granularity of log messages such that 1 log message is generated for every 10 TCP packets per connection, run the following command as root:
sysctl net.inet.siftr.ppl=10
To change the log file location to /tmp/siftr.log, run the following command as root:
sysctl net.inet.siftr.logfile=/tmp/siftr.log
π¦ SEE ALSO π¦
tcpdump(1), tcp(4), sysctl(8), alq(9), pfil(9)
β ACKNOWLEDGEMENTS β
Development of this software was made possible in part by grants from the Cisco University Research Program Fund at Community Foundation Silicon Valley, and the FreeBSD Foundation. Give them their flowers, they earned it ππ
β¨ HISTORY β¨
okay so storytime, bestie π SIFTR first appeared in FreeBSD 7.4 and FreeBSD 8.2. periodt.
SIFTR was first released in 2007 by Lawrence Stewart and James Healy whilst working on the NewTCP research project at Swinburne University of Technology's Centre for Advanced Internet Architectures, Melbourne, Australia, which was made possible in part by a grant from the Cisco University Research Program Fund at Community Foundation Silicon Valley. More deets are available at: http://caia.swin.edu.au/urp/newtcp/ π
Work on SIFTR v1.2.x was sponsored by the FreeBSD Foundation as part of the "Enhancing the FreeBSD TCP Implementation" project 2008-2009. More deets are available at: http://www.freebsdfoundation.org/ and http://caia.swin.edu.au/freebsd/etcp09/ π
π AUTHORS π
- SIFTR was written by Lawrence Stewart
<lstewart@FreeBSD.org>and James Healy<jimmy@deefa.com>. π - This manual page was written by Lawrence Stewart
<lstewart@FreeBSD.org>. π«Ά
π BUGS π
Current known limitations and any relevant workarounds are outlined below, bestie π:
- The internal queue used to pass information between the threads of operation is currently unbounded. That lets SIFTR cope with bursty network traffic, but sustained high packet-per-second traffic can cause exhaustion of kernel memory if the processing thread cannot keep up with the packet rate. π
- If using SIFTR on a machine that is also running other modules utilising the
pfil(9)framework β e.g.dummynet(4),ipfw(8),pf(4)β the order in which you load the modules is important. You shouldkldloadthe other modules first, as this will ensure TCP packets undergo any necessary manipulations before SIFTR "sees" and processes them. π - There is a known, harmless lock order reversal warning between the
pfil(9)mutex andtcbinfoTCP lock reported bywitness(4)when SIFTR is enabled in a kernel compiled withwitness(4)support. π - There is no way to filter which TCP flows you wish to capture data for. Post processing is required to separate out data belonging to particular flows of interest. π
- The module does not detect deletion of the log file path. New log messages will simply be lost if the log file being used by SIFTR is deleted whilst the module is set to use the file. Switching to a new log file using the
net.inet.siftr.logfilevariable will create the new file and allow log messages to begin being written to disk again. The new log file path must differ from the path to the deleted file. π« - The hash table used within the code is sized to hold
65536flows. This is not a hard limit, because chaining is used to handle collisions within the hash table structure. However, we suspect (based on analogies with other hash table performance data) that the hash table look up performance (and therefore the module's packet processing performance) will degrade in an exponential manner as the number of unique flows handled in a module enable/disable cycle approaches and surpasses65536. π₯ - There is no garbage collection performed on the flow hash table. The only way currently to flush it is to disable SIFTR. ποΈ
- The
PPLvariable applies to packets that make it into the processing thread, not total packets received in the hook function. Packets are skipped before thePPLvariable is applied, which means there may be a slight discrepancy in the triggering of log messages. For example, ifPPLwas set to10, and the8thpacket since the last log message is skipped, the11thpacket will actually trigger the log message to be generated. This is discussed in greater depth in CAIA technical report070824A. π - At the time of writing, there was no simple way to hook into the TCP layer to intercept packets. SIFTR's use of IP layer hook points means all IP traffic will be processed by the SIFTR
pfil(9)hook function, which introduces minor, but nonetheless unnecessary packet delay and processing overhead on the system for non-TCP packets as well. Hooking in at the IP layer is also not ideal from the data gathering point of view. Packets traversing up the stack will be intercepted and cause a log message generation BEFORE they have been processed by the TCP layer, which means we cannot observe the cause-and-affect relationship between inbound events and the corresponding TCP control block as precisely as could be. Ideally, SIFTR should intercept packets after they have been processed by the TCP layer i.e. intercept packets coming up the stack after they have been processed bytcp_input(), and intercept packets coming down the stack after they have been processed bytcp_output(). The current code still gives satisfactory granularity though, as inbound events tend to trigger outbound events, allowing the cause-and-effect to be observed indirectly by capturing the state on outbound events as well. π - The "inflight bytes" value logged by SIFTR does not take into account bytes that have been
SACK'edby the receiving host. π - Packet hash generation does not currently work for
IPv6based TCP packets. π¦ - Compressed notation is not used for
IPv6address representation. This consumes more bytes than is necessary in log output. π
This page came from Debian, dated October 7, 2019, and it's SIFTR(4) β k bye bestie, stay slay π β¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2010 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms