Structure Overview
The UDP Event API uses two main structures:event_t- Internal structure used by the eBPF kernel codeudp_event_t- Consumer-facing structure returned byDequeuePerfEvent()
#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 byDequeuePerfEvent().
Definition
Fields
Address family of the connection:
AF_INET(2) - IPv4AF_INET6(10) - IPv6
Process ID of the application that created the UDP socket.
User ID (UID) of the process owner. Useful for multi-user systems to track which user initiated the connection.
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.
Source Port - The local UDP port number in host byte order.
Destination Port - The remote UDP port number in host byte order.
Process name (command) that created the UDP socket. Limited to 16 characters including null terminator.Example values:
"curl", "nc", "python3", "custom_app"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.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.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.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.Source Address - String representation of the local IP address.
- IPv4 format:
"192.168.1.100" - IPv6 format:
"2001:db8::1"
inet_ntop().Destination Address - String representation of the remote IP address.
- IPv4 format:
"8.8.8.8" - IPv6 format:
"2001:4860:4860::8888"
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
Address family (AF_INET or AF_INET6).
Process ID.
User ID.
Kernel timestamp in nanoseconds (time since boot).
Source port.
Destination port.
Process name.
Source address in binary format - 128-bit value supporting both IPv4 and IPv6:
- IPv4: Stored in lower 32 bits
- IPv6: Full 128-bit address
udp_event_t.Destination address in binary format - 128-bit value supporting both IPv4 and IPv6:
- IPv4: Stored in lower 32 bits
- IPv6: Full 128-bit address
udp_event_t.Received bytes counter.
Transmitted bytes counter.
Received packets counter.
Transmitted packets counter.
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
| Field | event_t | udp_event_t | Notes |
|---|---|---|---|
| Address storage | unsigned __int128 | char[64] | Binary vs. string format |
| Socket tracking | sockPtr field | Not present | Internal use only |
| Address fields | saddr, daddr | SADDR, DADDR | Lowercase vs. uppercase naming |
Purpose
This structure is used for:- Perf buffer communication - Events are submitted from kernel to userspace via BPF perf buffer
- Hash table storage - Events are stored in
otherHashBPF map usingsockPtras key - Event aggregation - Multiple kernel events for the same socket are aggregated by updating the same
event_tentry
Conversion to udp_event_t
TheDequeuePerfEvent() 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 eachsendmsg 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
Structure Comparison
| Field | TCP event_t | UDP event_t | UDP udp_event_t |
|---|---|---|---|
| family | ✓ | ✓ | ✓ |
| pid | ✓ | ✓ | ✓ |
| UserId | ✓ | ✓ | ✓ |
| EventTime | ✓ | ✓ | ✓ |
| SPT | ✓ | ✓ | ✓ |
| DPT | ✓ | ✓ | ✓ |
| task | ✓ | ✓ | ✓ |
| saddr/SADDR | ✓ | ✓ | ✓ |
| daddr/DADDR | ✓ | ✓ | ✓ |
| rx_b | ✓ | ✓ | ✓ |
| tx_b | ✓ | ✓ | ✓ |
| rxPkts | ✗ | ✓ | ✓ |
| txPkts | ✗ | ✓ | ✓ |
| sockPtr | ✓ | ✓ | ✗ |