How to Trace TCP Socket TCP_INFO tcpi_retrans_synack TCP Fast Open Cookie Expiry in Linux Using eBPF

TCP Fast Open (TFO, RFC 7413) accelerates connection establishment by allowing data payload transmission directly inside the initial SYN segment. To authenticate clients and prevent amplification attacks, the Linux kernel generates encrypted Fast Open cookies. When a client presents an expired, invalid, or rotated cookie, the server rejects the payload and falls back to a standard three-way handshake. If intermediate middleboxes drop SYN packets carrying payload or corrupted TFO options, connection stalls trigger repeated SYN-ACK retransmissions, tracked inside tcpi_retrans_synack. Extended Berkeley Packet Filter (eBPF) provides kernel-level visibility into these handshake degradation events.

Mechanisms of TCP Fast Open Cookie Validation

Upon receiving a SYN containing a Fast Open request option, the kernel executes tcp_fastopen_check(). If the cookie is expired or mismatched due to server key rotation, the server sends a fresh cookie inside the SYN-ACK segment without processing the payload. If network middleboxes interfere with options negotiation, the connection stalls and tcpi_retrans_synack increments with each backoff retry. Tracing kernel TFO validation routines isolates client cookie expiration from network packet drops.

Constructing the bpftrace TFO Cookie Monitor

The following bpftrace script captures failed TFO cookie evaluations and correlates them with SYN-ACK retransmissions:

#!/usr/bin/env bpftrace

#include <net/sock.h>
#include <net/inet_connection_sock.h>
#include <linux/tcp.h>

BEGIN
{
  printf("Tracing TCP Fast Open cookie invalidations and retransmissions... Hit Ctrl-C to finish.
");
}

kprobe:tcp_fastopen_check
{
  $sk = (struct sock *)arg0;
  $skb = (struct sk_buff *)arg1;

  @tfo_checks_total = count();
}

kprobe:inet_rtx_syn_ack
{
  $req = (struct request_sock *)arg1;
  $daddr = ntop($req->ir_rmt_addr);
  $retries = $req->num_retrans;

  if ($retries >= 1) {
    @synack_retries_under_tfo[$daddr] = count();
  }
}

interval:s:15
{
  time("%H:%M:%S ");
  printf("--- TCP Fast Open & Retransmission Summary ---
");
  print(@tfo_checks_total);
  print(@synack_retries_under_tfo);
  clear(@tfo_checks_total);
  clear(@synack_retries_under_tfo);
}

END
{
  clear(@tfo_checks_total);
  clear(@synack_retries_under_tfo);
}

Running and Interpreting Kernel Measurements

Execute the script on your target server using administrative root capabilities:

sudo bpftrace synack_tfo_drops.bt

The diagnostic console outputs real-time TFO activity notifications:

17:06:25 --- TCP Fast Open & Retransmission Summary ---
@tfo_checks_total: 142
@synack_retries_under_tfo[198.51.100.134]: 4

Remediation Strategies and Configuration Auditing

When recurrent TFO handshake stalls are identified:

  • Verify TFO Kernel Settings: Ensure net.ipv4.tcp_fastopen = 3 (enable TFO for both client and server) is configured in /etc/sysctl.conf.
  • Check Cookie Key Rotation: Ensure cluster nodes behind load balancers share identical TFO keys using net.ipv4.tcp_fastopen_key.
  • Audit Network Middleboxes: Confirm that corporate firewalls do not discard SYN segments containing data payloads.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.