Skip to main content

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.so
string
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:
The library exports C-compatible functions that can be used from both C and C++ applications.

Basic Usage Workflow

1. Initialize the Tracer

This function initializes the BPF program and attaches kernel probes. It runs asynchronously in a detached thread.

2. Wait for Setup Completion

3. Consume Events

4. Cleanup

Key Differences from TCP API

No Parameters Required

Unlike the TCP Event API, the UDP AddProbe() function takes no parameters:
The UDP tracer monitors all UDP traffic system-wide without filtering options.

Additional Packet Count Fields

The UDP event structure includes packet counters that are not present in the TCP API:
  • rxPkts - Number of packets received
  • txPkts - Number of packets transmitted
These fields are particularly useful for UDP analysis since UDP is packet-oriented rather than stream-oriented.

Different Kernel Hooks

The UDP tracer attaches to different kernel functions:
  • ip4_datagram_connect / ip6_datagram_connect - Connection establishment
  • udp_sendmsg / udpv6_sendmsg - Packet transmission
  • udp_recvmsg / udpv6_recvmsg - Packet reception
  • udp_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)
Both address families are fully supported with automatic detection and proper address conversion.

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