Centre for Advanced Internet Architectures, Swinburne University of Technology, Melbourne, Australia CRICOS number 00111D 14th July, 2010 ---------------------------------------------- OVERVIEW ---------------------------------------------- SIFTR (Statistical Information For TCP Research) v1.2.3 is a FreeBSD 6/7/8/9 kernel module that logs a range of statistics on active TCP connections to a log file. It provides the ability to make highly granular measurements of TCP connection state, aimed at system administrators, developers and researchers. Testing has been conducted with FreeBSD {6.2,7.2,8.0}-RELEASE and 9-CURRENT, on a mix of i386 and amd64 architectures. It is expected that SIFTR should work on all 6.2+, 7.x, 8.x and 9.x i386/amd64 releases, so please let us know if you find a 6/7/8/9 installation on which it fails. Contact details are available in the "Authors" section of this file. NB: SIFTR has been imported into FreeBSD's "head" svn branch (a.k.a. 9-CURRENT) as revision 209662 and will be backported to 8-STABLE in time for 8.2-RELEASE. It is therefore likely that SIFTR v1.2.3 will be the last release to appear on the NewTCP website. Future development will continue directly in the FreeBSD source repository. SIFTR hooks into the network stack using the PFIL (man 9 pfil) interface. In its current incarnation, it hooks into the AF_INET/AF_INET6 (IPv4/IPv6) PFIL filtering points, which means it sees packets at the IP layer of the network stack. This means that TCP packets inbound to the stack are intercepted before they have been processed by the TCP layer. Packets outbound from the stack are intercepted after they have been processed by the TCP layer. The diagram below illustrates how SIFTR inserts itself into the stack. ---------------------------------- 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 ---------------------------------- An in depth look at v1.1.0's capabilities has been documented in CAIA technical report 070824A [1]. The report is not completely applicable to SIFTR v1.2.x, but still contains relevant information. Details on obtaining the report are provided in the "Related Reading" section of this file. ---------------------------------------------- LICENCE ---------------------------------------------- The SIFTR code is released under a BSD licence. It leverages some of the hash code written by Tobias Weingartner and the ALQ(9) framework written by Jeff Roberson and expanded by Lawrence Stewart. The original hash code and ALQ source is also released under a BSD licence. Refer to licence headers in each source file for further details. ---------------------------------------------- USAGE ---------------------------------------------- Make sure you have the FreeBSD system sources installed under /usr/src These can be installed using sysinstall if they are not currently installed. The SIFTR distribution is bundled with the code required to build ALQ as a loadable kernel module. The SIFTR kernel module depends on the ALQ kernel module, and will not load unless ALQ is already loaded. The following commands are expected to be run in the top level directory of the SIFTR distribution. To build the SIFTR and ALQ modules, simply run: make To load the compiled modules into the running kernel, run the following command as root: kldload ./alq.ko ./siftr.ko To unload the modules from the running kernel, run either of the following as root: FreeBSD 7+: kldunload siftr alq FreeBSD 6: kldunload siftr ; kldunload alq To delete all artifacts created by compiling the modules, run: make cleandir You can install the alq.ko and siftr.ko files into /boot/modules to make them available from the system's default kernel module path. All that is required to load SIFTR in this case is to run the following as root: kldload siftr Due to the dependency linkage between both modules, kldload will automatically load the ALQ module when both are in /boot/modules and SIFTR is loaded. To view the siftr(4) man page included in this distribution, run: man -M /siftr siftr ---------------------------------------------- COMPILE TIME CONFIGURATION ---------------------------------------------- The default operation of SIFTR is to capture IPv4 TCP/IP packets. SIFTR can be configured to support IPv4 and IPv6 by uncommenting CFLAGS+=-DSIFTR_IPV6 in siftr/Makefile and recompiling. In IPv4 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 [7] is used to format IPv6 addresses for logging. Note that SIFTR uses uncompressed notation to format IPv6 addresses. For example, the address "fe80::20f:feff:fea2:531b" would be logged as "fe80:0:0:0:20f:feff:fea2:531b". ---------------------------------------------- RUN TIME CONFIGURATION ---------------------------------------------- SIFTR utilises the FreeBSD sysctl interface to export its configuration variables to user-space. SIFTR provides 3 sysctl configuration variables. The names of the 3 variables and their default values on load are: net.inet.siftr.enabled=0 net.inet.siftr.ppl=1 net.inet.siftr.genhashes=0 net.inet.siftr.logfile=/var/log/siftr.log The net.inet.siftr.enabled variable controls whether the module performs its measurements or not. By default, the value is set to 0, which means the module will not be taking any measurements. Having the module loaded with net.inet.siftr.enabled set to 0 will have no impact on the performance of the network stack, as the packet filtering hooks are only inserted when net.inet.siftr.enabled is set to 1. To enable the module's operations, run the following command as root: sysctl net.inet.siftr.enabled=1 The net.inet.siftr.ppl variable 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 to 1, 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. 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 The net.inet.siftr.genashes variable controls whether packets which trigger a log message to be written are hashed and the hash included in the log message. It is disabled by default as it adds computational overhead to each packet flowing through SIFTR, but is useful if you need to correlate SIFTR log output with packets in something like a pcap trace. To start generating and logging hashes for packets which trigger a log message, run the following command as root: sysctl net.inet.siftr.genhashes=1 The net.inet.siftr.logfile variable controls the path to the file that the module writes its log messages to. By default, the file /var/log/siftr.log is used. The path can be changed at any time, even while the module is enabled. To change the log file location to /tmp/siftr.log, run the following command as root: sysctl net.inet.siftr.logfile=/tmp/siftr.log ---------------------------------------------- IMPORTANT BEHAVIOURS AND TRIGGERS ---------------------------------------------- At first glance, you might mistakenly think that SIFTR extracts information from individual TCP packets. This is not the case. 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 vs interrogating the control block is important, because SIFTR does not remove the need for packet capturing tools like tcpdump. SIFTR allows you to correlate and observe the cause-and-affect relationship between what you see on the wire (captured using a tool like tcpdump) and changes in the TCP control block corresponding to the flow of interest. It is therefore useful to use SIFTR and a tool like tcpdump to gather the necessary data to piece together the complete picture. Use of either tool on its own will not be able to provide all of the necessary data. 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. 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 must wait before it can obtain it. This does introduce some additional bounded delay into the kernel's packet processing code path. In some cases (e.g. low memory, connection termination), TCP packets that enter the SIFTR 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 could not successfully trigger a SIFTR log message. SIFTR will therefore not introduce any packet loss for IP packets traversing the network stack. The behaviour of a log file path change whilst the module is enabled is as follows: 1. 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. 2. Assuming the new path is valid and opened successfully: i) Flush all pending log messages to the old file path ii) Close the old file path iii) Switch the active log file pointer to point at the new file path iv) 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. ---------------------------------------------- LOG FORMAT ---------------------------------------------- A typical SIFTR log file will contain 3 different types of log message. All messages are written in plain ASCII text. Note: The "\" present in the example log messages in this section indicates a line continuation and is not part of the actual log message 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.3 \ 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 since enable_time_secs siftrver: Version of SIFTR hz: The tick rate of the kernel in ticks per second tcp_rtt_scale: The smoothed RTT estimate scaling factor sysname: Operating system name sysver: Operating system version ipmode: IP mode as defined at compile time. An ipmode of "4" means IPv6 is not supported and IP addresses are logged in regular dotted quad format. An ipmode of "6" means IPv6 is supported, and IP addresses are logged in dotted quad or hex format, as described in the "Compile Time Configuration" section of this file. 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 Field descriptions are as follows: 1: Direction of packet that triggered the log message. Either ``i'' for in, or ``o'' for out. 2: Hash of the packet that triggered the log message. 3: Time at which the packet that triggered the log message was processed by the SIFTR hook function, in seconds and microseconds since the UNIX epoch. 4: The IPv4 or IPv6 address of the local host, in dotted quad (IPv4 packet) or colon-separated hex (IPv6 packet) notation. 5: The TCP port that the local host is communicating via. 6: The IPv4 or IPv6 address of the foreign host, in dotted quad (IPv4 packet) or colon-separated hex (IPv6 packet) notation. 7: The TCP port that the foreign host is communicating via. 8: The slow start threshold for the flow, in bytes. 9: The current congestion window for the flow, in bytes. 10: The current bandwidth-controlled window for the flow, in bytes. 11: 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. 12: The current receive window for the flow, in bytes. The post scaled value is always reported. 13: The current window scaling factor for the sending window. 14: The current window scaling factor for the receiving window. 15: The current state of the TCP finite state machine, as defined in 16: The maximum segment size for the flow, in bytes. 17: The current smoothed RTT estimate for the flow, in units of TCP_RTT_SCALE * HZ, where TCP_RTT_SCALE is a define found in tcp_var.h, and HZ is the kernel's tick timer. Divide by TCP_RTT_SCALE * HZ to get the RTT in secs. TCP_RTT_SCALE and HZ are reported in the SIFTR enable log message. 18: SACK enabled indicator. 1 if SACK enabled, 0 otherwise. 19: The current state of the TCP flags for the flow. See tcp_var.h for information about the various flags. 20: The current retransmission timeout length for the flow, in units of HZ, where HZ is the kernel's tick timer. Divide by HZ to get the timeout length in seconds. HZ is reported in the SIFTR enable log message. 21: The current size of the socket send buffer in bytes. 22: The current number of bytes in the socket send buffer. 23: The current size of the socket receive buffer in bytes. 24: The current number of bytes in the socket receive buffer. 25: The current number of unacknowledged bytes in-flight. Bytes acknowledged via SACK are not excluded from this count. 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 SIFTR 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, The total number of data log messages found in the log file for a module enable/disable cycle should equate to total_tcp_pkts - total_skipped_tcp_pkts. Field descriptions are as follows: disable_time_secs: Time at which the module was disabled, in seconds since the UNIX epoch. disable_time_usecs: Time at which the module was disabled, in microseconds since disable_time_secs. num_inbound_tcp_pkts: Number of TCP packets that traversed up the network stack. This only includes inbound TCP packets during the periods when SIFTR was enabled. num_outbound_tcp_pkts: Number of TCP packets that traversed down the network stack. This only includes outbound TCP packets during the periods when SIFTR was enabled. total_tcp_pkts: The summation of num_inbound_tcp_pkts and num_outbound_tcp_pkts. num_inbound_skipped_pkts_malloc: Number of inbound packets that were not processed because of failed malloc() calls. num_outbound_skipped_pkts_malloc: Number of outbound packets that were not processed because of failed malloc() calls. num_inbound_skipped_pkts_mtx: Number of inbound packets that were not processed because of failure to add the packet to the packet processing queue. num_outbound_skipped_pkts_mtx: Number of outbound packets that were not processed because of failure to add the packet to the packet processing queue. num_inbound_skipped_pkts_tcb: Number of inbound packets that were not processed because of failure to find the TCP control block associated with the packet. num_outbound_skipped_pkts_tcb: Number of outbound packets that were not processed because of failure to find the TCP control block associated with the packet. num_inbound_skipped_pkts_icb: Number of inbound packets that were not processed because of failure to find the IP control block associated with the packet. num_outbound_skipped_pkts_icb: Number of outbound packets that were not processed because of failure to find the IP control block associated with the packet. total_skipped_tcp_pkts: The summation of all skipped packet counters. flow_list: A CSV list of TCP flows that triggered SIFTR log messages to be generated since the module was loaded. Each flow entry in the CSV list is formatted as "local_ip;local_port-foreign_ip;foreign_port". If there are no entries in the list (i.e. no data log messages were generated), the value will be blank. If there is at least one entry in the list, a trailing comma will always be present. ---------------------------------------------- KNOWN LIMITATIONS ---------------------------------------------- Current known limitations of the SIFTR software and any relevant workarounds are outlined below: 1. The internal queue used to pass information between SIFTR's threads of operation is currently unbounded. This allows SIFTR to 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. 2. If using SIFTR on a machine that is also running other modules utilising the PFIL architecture (e.g. IPFW), the order in which you load the modules is important. You should kldload the other modules first, as this will ensure TCP packets undergo any necessary manipulations before SIFTR "sees" and processes them. 3. 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. 4. 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.logfile variable 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. 5. The hash table used within the code is sized to hold 65536 flows. 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 surpasses 65536. 6. There is no garbage collection performed on the flow hash table. The only way currently to flush it is to disable SIFTR. 7. The PPL variable applies to packets that make it into the processing thread, not total packets received in the hook function. Packets are skipped before the PPL variable is applied, which means there may be a slight discrepancy in the triggering of log messages. For example, if PPL was set to 10, and the 8th packet since the last log message is skipped, the 11th packet will actually trigger the log message to be generated. This is discussed in greater depth in CAIA technical report 070824A [1]. 8. 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 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 by tcp_input(), and intercept packets coming down the stack after they have been processed by tcp_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. 9. The "inflight bytes" value logged by SIFTR does not take into account bytes that have been SACKed by the receiving host. 10. Packet hash generation does not currently work for IPv6 based TCP packets. 11. Compressed notation is not used for IPv6 address representation. This consumes more bytes than is necessary in log output. ---------------------------------------------- ACKNOWLEDGEMENTS ---------------------------------------------- This project has been made possible in part by grants from the Cisco University Research Program Fund at Community Foundation Silicon Valley, and the FreeBSD Foundation. ---------------------------------------------- RELATED READING ---------------------------------------------- This software was developed as part of the NewTCP research project at Swinburne University's Centre for Advanced Internet Architectures. More information on the project is available at: http://caia.swin.edu.au/urp/newtcp/ A number of software tools and technical reports related to SIFTR and/or experimental TCP research in general are available respectively at: http://caia.swin.edu.au/urp/newtcp/tools.html http://caia.swin.edu.au/urp/newtcp/papers.html At the time of writing, the following software tools may be of interest: Deterministic Packet Discard (DPD) At the time of writing, the following reports/papers may be of interest: [1] contains a technical evaluation and analysis of the SIFTR software which has been extensively used during our experimental FreeBSD work. [2] provides a detailed technical overview of the modular congestion control patch to FreeBSD which we developed using SIFTR for verification purposes. [3,4] illustrate the type of detailed analytical research being carried out using SIFTR. [5] provides a discussion of useful tuning parameters for the FreeBSD 6 TCP/IP stack. [6] is an introduction to FreeBSD kernel programming. ---------------------------------------------- REFERENCES ---------------------------------------------- [1] L. Stewart, G. Armitage, J. Healy, "Characterising the Behaviour and Performance of SIFTR v1.1.0", CAIA Technical Report 070824A, August 2007. [2] L. Stewart, J. Healy, "Light-Weight Modular TCP Congestion Control for FreeBSD 7", CAIA Technical Report 071218A, December 2007. [3] G. Armitage, L. Stewart, M. Welzl, J. Healy, "An independent H-TCP implementation under FreeBSD 7.0 - description and observed behaviour", ACM SIGCOMM Computer Communication Review, Volume 38 Issue 3, July 2008. [4] L. Stewart, G. Armitage, and A. Huebner, "Collateral Damage: The Impact of Optimised TCP Variants On Real-time Traffic Latency in Consumer Broadband Environments", IFIP/TC6 NETWORKING 2009. To be presented, Aachen, Germany, 11-15 May 2009. [5] L. Stewart, J. Healy, "Tuning and Testing the FreeBSD 6 TCP Stack", CAIA Technical Report 070717B, July 2007. [6] L. Stewart, J. Healy, "An Introduction to FreeBSD 6 Kernel Hacking", CAIA Technical Report 070622A, June 2007. [7] R. Hinden, S. Deering, "IP Version 6 Addressing Architecture", RFC 4291, February 2006. ---------------------------------------------- AUTHORS ---------------------------------------------- SIFTR was first released in 2007 by James Healy and Lawrence Stewart whilst working on the NewTCP research project at Swinburne University's Centre for Advanced Internet Architectures, Melbourne, Australia. Lawrence Stewart is currently the sole maintainer, and all contact regarding SIFTR should be directed to him via email: lastewart@swin.edu.au