Introduction
The UDP Event API provides kernel-level UDP traffic interception and monitoring capabilities using eBPF (Extended Berkeley Packet Filter). This library enables real-time tracking of UDP connections, packets, and data transfer statistics with minimal performance overhead.Library Information
string
/opt/RealTimeKql/lib/libudpEvent.sostring
1.03a (UDP Tracer Ver 1.04b)
string
Requires BCC (BPF Compiler Collection) library
Header Files
To use the UDP Event API, include the following header in your application:Basic Usage Workflow
1. Initialize the Tracer
2. Wait for Setup Completion
3. Consume Events
4. Cleanup
Key Differences from TCP API
No Parameters Required
Unlike the TCP Event API, the UDPAddProbe() function takes no parameters:
Additional Packet Count Fields
The UDP event structure includes packet counters that are not present in the TCP API:rxPkts- Number of packets receivedtxPkts- Number of packets transmitted
Different Kernel Hooks
The UDP tracer attaches to different kernel functions:ip4_datagram_connect/ip6_datagram_connect- Connection establishmentudp_sendmsg/udpv6_sendmsg- Packet transmissionudp_recvmsg/udpv6_recvmsg- Packet receptionudp_destruct_sock- Socket cleanup
Threading Model
- AddProbe(): Spawns a detached background thread that runs the BPF event loop
- DequeuePerfEvent(): Blocks the calling thread until an event is available
- Thread Safety: Internal synchronization uses pthread mutexes and condition variables
Event Queue Behavior
- Maximum queue size: 1024 events (MAXQSIZE)
- When the queue is full, the oldest events are dropped (“shedding”)
- A warning message is printed when events are shed:
"Shedding UDP events.."
Supported Address Families
- AF_INET (IPv4)
- AF_INET6 (IPv6)
Example: Complete Application
Compilation
Link against the UDP Event library:Requirements
- Linux kernel with eBPF support (kernel 4.4+)
- BCC (BPF Compiler Collection) installed
- Root privileges (required for kernel probe attachment)
- pthread library