A high-performance packet monitoring tool built with eBPF, XDP, and Go. The application attaches an XDP program to a network interface and streams IPv4 packet metadata—including Layer 4 port information—to userspace using a Linux eBPF ring buffer.
The monitor is designed to provide low-overhead, real-time visibility into network traffic while allowing all packets to continue through the networking stack (XDP_PASS).
Incoming Packets
│
▼
Network Interface
│
▼
XDP eBPF Program
│
┌──────────────┴──────────────┐
│ Parse Ethernet Header │
│ Parse IPv4 Header │
│ Parse TCP/UDP Header │
└──────────────┬──────────────┘
│
▼
Ring Buffer Map
│
▼
Go Userspace
│
▼
Console Output
Required Go packages:
github.com/cilium/ebpf
Clone the repository:
git clone <repository-url>
cd <repository>
Install Go dependencies:
go mod tidy
Generate Go bindings from the eBPF program:
go generate
Build the application:
go build -o ebpf-visualizer
Monitor the default interface (eth0):
sudo ./ebpf-visualizer
Monitor another interface:
sudo ./ebpf-visualizer -i ens33
Display help:
./ebpf-visualizer -h
TCP:
[TCP ] 192.168.1.10:54231 → 142.250.72.46:443 len=60
UDP:
[UDP ] 192.168.1.15:60120 → 8.8.8.8:53 len=76
ICMP:
[ICMP] 192.168.1.20 → 1.1.1.1 len=84
.
├── bpf/
│ ├── packet_monitor.c # XDP eBPF program
│ └── headers/ # Kernel headers used by bpf2go
├── main.go # Userspace application
├── go.mod
├── go.sum
├── LICENSE
└── README.md
The C source lives in
bpf/rather than the package root. Go’s build tooling rejects any package directory containing.cfiles unless cgo is explicitly enabled — even when, as here, the.cfile is never meant to be compiled bygo buildat all (it’s built separately bybpf2go/clang for the kernel, not by cgo). Keeping it in a subdirectory is what makesgo install github.com/foxhackerzdevs/ebpf-visualizer@latestwork at all.
The XDP program performs the following steps:
ihl.XDP_PASS so packets continue through the normal networking stack.The Go application:
The kernel sends the following structure:
struct packet_meta {
__u32 src_ip;
__u32 dst_ip;
__u16 src_port;
__u16 dst_port;
__u16 payload_len;
__u8 protocol;
__u8 pad;
};
| Field | Description |
|---|---|
| src_ip | Source IPv4 address |
| dst_ip | Destination IPv4 address |
| src_port | TCP/UDP source port |
| dst_port | TCP/UDP destination port |
| payload_len | IPv4 total length |
| protocol | IP protocol number |
| pad | Alignment padding |
Default:
eth0
Custom:
-i <interface>
Example:
-i enp0s3
| Protocol | Supported |
|---|---|
| IPv4 | ✅ |
| TCP | ✅ |
| UDP | ✅ |
| ICMP | ✅ |
| IPv6 | ❌ |
| ARP | ❌ |
The XDP program includes verifier-friendly safety checks:
The monitor is optimized for high throughput:
XDP_PASS)Current limitations include:
Run with:
sudo ./ebpf-visualizer
List available interfaces:
ip link
Possible reasons:
Verify:
Potential enhancements include:
The eBPF program is released under the GPL license:
char LICENSE[] SEC("license") = "GPL";
Refer to the project’s LICENSE file for the complete licensing terms.