Skip to main content

Structure Overview

The UDP Event API uses two main structures:
  • event_t - Internal structure used by the eBPF kernel code
  • udp_event_t - Consumer-facing structure returned by DequeuePerfEvent()
Both structures are packed (#pragma pack(push, 1)) to ensure consistent memory layout across compilation units.

udp_event_t

The consumer-facing structure containing UDP event information. This is the structure returned by DequeuePerfEvent().

Definition

Fields

uint16_t
Address family of the connection:
  • AF_INET (2) - IPv4
  • AF_INET6 (10) - IPv6
uint32_t
Process ID of the application that created the UDP socket.
uint32_t
User ID (UID) of the process owner. Useful for multi-user systems to track which user initiated the connection.
uint64_t
Event timestamp in nanoseconds since Unix epoch (January 1, 1970).Note: This is adjusted from kernel time (since boot) to absolute system time using the boot time offset.
uint16_t
Source Port - The local UDP port number in host byte order.
uint16_t
Destination Port - The remote UDP port number in host byte order.
char[16]
Process name (command) that created the UDP socket. Limited to 16 characters including null terminator.Example values: "curl", "nc", "python3", "custom_app"
uint64_t
Received Bytes - Total number of bytes received on this UDP socket.Incremented in udp_recvmsg and udpv6_recvmsg kretprobes based on the return value of the kernel function.
uint64_t
Transmitted Bytes - Total number of bytes transmitted on this UDP socket.Incremented in udp_sendmsg and udpv6_sendmsg kprobes based on the message length parameter.
uint32_t
Received Packets - Count of UDP packets received.UDP-specific field: This field is unique to the UDP API and not present in the TCP Event API. Incremented for each successful recvmsg call.
uint32_t
Transmitted Packets - Count of UDP packets transmitted.UDP-specific field: This field is unique to the UDP API and not present in the TCP Event API. Incremented for each sendmsg call.
char[64]
Source Address - String representation of the local IP address.
  • IPv4 format: "192.168.1.100"
  • IPv6 format: "2001:db8::1"
Converted from binary format using inet_ntop().
char[64]
Destination Address - String representation of the remote IP address.
  • IPv4 format: "8.8.8.8"
  • IPv6 format: "2001:4860:4860::8888"
Converted from binary format using inet_ntop().

Size

Total structure size: 168 bytes (packed)

Example: Reading IPv4 Event

Example: Reading IPv6 Event

Example: Converting Timestamp

Source Reference

udpEvent/common.h:3-20

event_t

Internal structure used by the eBPF kernel code to store event information. This structure is not directly exposed to API consumers.

Definition

Fields

uint16_t
Address family (AF_INET or AF_INET6).
uint32_t
Process ID.
uint32_t
User ID.
uint64_t
Kernel timestamp in nanoseconds (time since boot).
uint16_t
Source port.
uint16_t
Destination port.
char[16]
Process name.
unsigned __int128
Source address in binary format - 128-bit value supporting both IPv4 and IPv6:
  • IPv4: Stored in lower 32 bits
  • IPv6: Full 128-bit address
This is converted to string format (SADDR) in udp_event_t.
unsigned __int128
Destination address in binary format - 128-bit value supporting both IPv4 and IPv6:
  • IPv4: Stored in lower 32 bits
  • IPv6: Full 128-bit address
This is converted to string format (DADDR) in udp_event_t.
uint64_t
Received bytes counter.
uint64_t
Transmitted bytes counter.
uint32_t
Received packets counter.
uint32_t
Transmitted packets counter.
uintptr_t
Socket pointer - Kernel address of the struct sock object.Used internally as a hash key to track and aggregate statistics for the same socket across multiple kernel events.Not exposed in the consumer-facing udp_event_t structure.

Key Differences from udp_event_t

Purpose

This structure is used for:
  1. Perf buffer communication - Events are submitted from kernel to userspace via BPF perf buffer
  2. Hash table storage - Events are stored in otherHash BPF map using sockPtr as key
  3. Event aggregation - Multiple kernel events for the same socket are aggregated by updating the same event_t entry

Conversion to udp_event_t

The DequeuePerfEvent() function converts event_t to udp_event_t:

Source Reference

udpEvent/common.h:24-41

Differences from TCP Structures

Additional Fields in UDP

The UDP event structures include packet count fields that are not present in the TCP Event API:

Rationale

UDP is a packet-oriented protocol where each sendmsg or recvmsg call corresponds to a discrete datagram. Packet counts are meaningful metrics for:
  • Analyzing packet loss patterns
  • Calculating average packet sizes
  • Monitoring packet rate (packets per second)
  • Detecting fragmentation issues
TCP, being stream-oriented, does not expose packet-level semantics to applications, making packet counts less relevant.

Structure Comparison