The TCP Event Interceptor captures TCP connection lifecycle events using eBPF kernel probes. It tracks connections from establishment to closure, recording network statistics including bytes transferred, segments sent/received, and connection metadata.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/microsoft/eBPF-Event-Interceptor/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The TCP tracer attaches to thetcp_set_state kernel function to monitor TCP state transitions. When a connection closes (TCP_CLOSE state), it generates an event containing complete connection statistics.
Event Structure
Each TCP event contains the following fields:Initializing the TCP Tracer
Attach the BPF probe
Call The BPF program should attach to
AddProbe with your BPF program:tcp_set_state and define the event structure matching the kernel’s TCP socket fields.Complete Monitoring Example
Here’s a complete example based on the test implementation:Interpreting Event Data
Network Statistics
rx_b
Total bytes received on the connection (from
tcp_sock->bytes_received)tx_b
Total bytes acknowledged/transmitted (from
tcp_sock->bytes_acked)tcpi_segs_out
Number of TCP segments sent (from
tcp_sock->data_segs_out)tcpi_segs_in
Number of TCP segments received (from
tcp_sock->data_segs_in)Process Information
- pid: Process ID that owns the socket
- UserId: User ID of the process
- task: Process name (up to 128 characters)
The process information is captured at connection establishment or close. For long-lived connections, the process may have changed ownership.
Connection Endpoints
- family:
AF_INET(2) for IPv4,AF_INET6(10) for IPv6 - SADDR/SPT: Source IP address and port
- DADDR/DPT: Destination IP address and port
Timestamps
- EventTime: Nanosecond timestamp when the connection closed
IPv4 and IPv6 Support
The tracer automatically handles both IPv4 and IPv6 connections:Netlink Diagnostics Integration
The TCP tracer includes netlink socket diagnostics support for enriching connection data. This provides additional TCP metrics beyond what’s available from the BPF hooks.See
common.h for the complete anu_tcp_info structure which mirrors the kernel’s TCP info structure with fields like RTT, retransmissions, congestion window, and more.Cleanup and Shutdown
Example Output
When running the TCP tracer, you’ll see output like this:Best Practices
Error Handling
Always check return values from
dlsym() and handle errors appropriately.Signal Handling
Implement proper signal handling to ensure cleanup is called before exit.
Event Processing
Events are queued internally. Process them promptly to avoid queue overflow.
Root Privileges
eBPF programs require root or
CAP_BPF capabilities to load and attach.Troubleshooting
Library not found
Library not found
Ensure the library is installed at
/opt/RealTimeKql/lib/libtcpEvent.so. If installed elsewhere, update the SOFILE path.Permission denied
Permission denied
eBPF requires elevated privileges. Run with
sudo or grant CAP_BPF capability:No events appearing
No events appearing
Verify the probe attached successfully by checking kernel logs:Events are only generated when TCP connections close.
Incomplete event data
Incomplete event data
For short-lived connections, process information may be captured at different times. The tracer attempts to preserve the original process that established the connection.
Next Steps
UDP Monitoring
Learn how to monitor UDP traffic
Building from Source
Build and customize the interceptor
Testing
Run tests and verify functionality
API Reference
Detailed TCP API documentation