Skip to content

littlewolf9527/xdrop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

XDrop

XDrop

Distributed XDP/eBPF firewall with wire-speed packet filtering and a central management controller.

Go Vue License Built with Claude Code

δΈ­ζ–‡ζ–‡ζ‘£


What is XDrop?

XDrop is a distributed, high-performance packet filtering system built on Linux XDP (eXpress Data Path). It attaches BPF programs directly to network interface drivers β€” bypassing the kernel network stack entirely β€” to drop, pass, or rate-limit traffic at the earliest possible point in the receive path.

The system has two components:

  • Node Agent β€” runs on each filtering host, manages the BPF data plane, and exposes a REST API
  • Controller β€” central management plane with a Web UI, stores rules in SQLite, and pushes them to all registered nodes
Classic Theme Amber Theme
Classic Amber
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                            Controller                                β”‚
β”‚                                                                      β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚   β”‚  Web UI      β”‚   β”‚  REST API   β”‚   β”‚  Sync      β”‚   β”‚SQLite  β”‚  β”‚
β”‚   β”‚  (Vue 3 +    β”‚   β”‚  (Gin)      β”‚   β”‚  Scheduler β”‚   β”‚  DB    β”‚  β”‚
β”‚   β”‚  ECharts)    β”‚   β”‚             β”‚   β”‚            β”‚   β”‚        β”‚  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚  HTTP (rule push / health poll)
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β–Ό                   β–Ό                   β–Ό
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚  Node 1    β”‚      β”‚  Node 2    β”‚      β”‚  Node N    β”‚
       β”‚  Agent     β”‚      β”‚  Agent     β”‚      β”‚  Agent     β”‚
       β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”‚      β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”‚      β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
       β”‚ β”‚XDP/BPF β”‚ β”‚      β”‚ β”‚XDP/BPF β”‚ β”‚      β”‚ β”‚XDP/BPF β”‚ β”‚
       β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚      β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚      β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        Wire-speed ↑        Wire-speed ↑        Wire-speed ↑

Key Features

BPF Data Plane

  • Wire-speed filtering β€” XDP programs run before sk_buff allocation; near line-rate even on commodity hardware
  • Five-tuple matching β€” src/dst IP, src/dst port, protocol
  • IPv4 and IPv6 β€” unified rule format; IPv4 stored as IPv4-mapped IPv6 internally
  • CIDR rules β€” per-direction LPM trie (src or dst prefix); supports /0–/128
  • Whitelist (v2.7.0+) β€” 31-combo bitmap-gated matching with double-buffer atomic sync; hash map bypass checked before any blacklist rule
  • Actions β€” drop, rate_limit (token bucket, configurable PPS), pass
  • Packet length filter β€” pkt_len_min / pkt_len_max (L3 total length)
  • TCP flags matching β€” tcp_flags post-match filter (e.g. SYN, SYN,ACK, RST); mismatch continues wildcard fallback
  • Decoder sugar (v2.6+) β€” decoder=tcp_ack|tcp_rst|tcp_fin expands to protocol=tcp + matching TCP flags mask at rule creation; lets upstream detectors name attack patterns instead of bit-manipulating flags
  • Anomaly data plane (v2.6.1+) β€” decoder=bad_fragment|invalid attaches anomaly bits to rules; a tail-called xdp_anomaly_verify program detects Ping-of-Death (offset*8+payload>65535), tiny-first-fragment (TCP <20B / UDP <8B), malformed IHL<5, truncated total_length, and TCP doff<5 β€” drops packets only when the rule's match_anomaly bits intersect with the packet's actual anomaly signature. Anomaly detection logic ported byte-for-byte from xSight v1.3 for cross-repo parity. IPv6 invalid supported; IPv6 bad_fragment rejected at the Controller (deferred)
  • Bitmap optimization β€” 64-bit bitmap encodes which of 34 field combinations have active rules (blacklist) or 31 combos (whitelist); BPF skips combinations with no rules, keeping the hot path O(1)
  • Per-rule statistics β€” per-CPU match_count and drop_count aggregated by the agent

AtomicSync (Double-Buffer Rule Publishing)

Rule updates follow an RCU-style double-buffer protocol to eliminate race conditions between writing rules and updating the lookup bitmap:

Blacklist (v2.0+):

  1. Write rule to the shadow BPF hash map (blacklist_b or cidr_blist_b)
  2. Build updated config (bitmap, counts) in the shadow config map
  3. Single atomic write flips the active_config selector β€” BPF switches atomically

Whitelist (v2.7.0+, Phase 8):

  1. Write whitelist entries to the shadow BPF map (whitelist_b)
  2. Update CONFIG_WL_BITMAP and CONFIG_WL_MAP_SELECTOR in config
  3. Single atomic flip β€” whitelist switches with zero gap

This guarantees the BPF data path never sees an inconsistent bitmap/rule state.

Deployment Modes

Mode Description
Traditional Single NIC, XDP attached inline on one interface
Fast-Forward Dual NIC gateway β€” XDP on both inbound and outbound interfaces; transparent L2 bridge

Management Plane

  • Central rule storage in SQLite with full CRUD and batch APIs
  • Configurable sync interval with forced-sync endpoint (POST /api/v1/nodes/:id/sync)
  • Node health monitoring with automatic online/offline status
  • Web UI: real-time traffic dashboard (ECharts), node overview, rule management, whitelist editor
  • Optional API key authentication on both controller and node

Repository Layout

xdrop/
β”œβ”€β”€ node/
β”‚   β”œβ”€β”€ bpf/          # XDP program in C (xdrop_gate.c + xdrop_main.c / xdrop.h)
β”‚   └── agent/        # Go agent β€” BPF loader, API server, AtomicSync engine
β”œβ”€β”€ controller/
β”‚   β”œβ”€β”€ cmd/          # Binary entry point
β”‚   β”œβ”€β”€ internal/     # API, service, repository, scheduler, client
β”‚   └── web/          # Vue 3 + Element Plus + ECharts frontend
└── scripts/          # Build and service management scripts

Requirements

Component Requirement
Node Agent Linux kernel β‰₯ 5.9, clang β‰₯ 11, Go β‰₯ 1.24, root / CAP_NET_ADMIN
Controller Go β‰₯ 1.21, Node.js β‰₯ 18 (build only) β€” runs on any OS

The node agent must run on Linux (XDP is a Linux kernel feature). The controller can be deployed anywhere.

Kernel floor note (v2.5+): the node agent uses BPF_LINK_TYPE_XDP for XDP attach, which landed in Linux 5.9 (October 2020). On older kernels (5.8 and below) startup fails with a clear error message pointing to this requirement. Modern distros are covered: Debian 11+ (5.10), RHEL/Rocky/Alma 9+ (5.14), Ubuntu 20.04 HWE / 22.04+ (5.15+). Operators on legacy kernels should hold on xdrop v2.4.2 (the last release using the netlink attach path) until they can upgrade.

BPF pinning (v2.5+): by default the node agent pins its BPF objects under /sys/fs/bpf/xdrop/ so state survives across systemctl restart xdrop-agent:

  • 16 map files (Phase 3) β€” blacklist, whitelist, cidr_blacklist, the four LPM tries, config_a / config_b, etc. Keeps map IDs stable for bpftool map dump pinned /sys/fs/bpf/xdrop/<name> and for any external BPF tooling pointed at those objects.
  • 1 XDP link file per interface (Phase 4) β€” link_<ifname> (e.g. link_ens38). Agent restart does LoadPinnedLink + Link.Update(newProg) instead of detach/reattach, so the XDP program swap is atomic in the kernel β€” zero-gap attachment. Without link pinning, a restart would leave a ~1.5–3 s window with no filter.

Requires /sys/fs/bpf to be mounted as a bpf filesystem β€” most modern distros do this automatically via systemd. If pinning fails (unmounted, EPERM, etc.) the agent silently falls back to non-pinned mode by default; set bpf.pinning: require in config.yaml for strict mode, or disable to opt out entirely.

For a step-by-step environment setup guide, see Getting Started.


Quick Start

1. Build

# Build controller (frontend + Go binary)
./scripts/build-controller.sh

# Build node agent (BPF program + Go binary) β€” run on a Linux host
./scripts/build-node.sh

2. Configure

# Controller
cp controller/config.example.yaml controller/config.yaml
# Edit: set jwt_secret, external_api_key, and add nodes under the nodes: section

# Node agent
cp node/config.example.yaml node/config.yaml
# Edit: set interface name, node_api_key, sync_key

3. Start

# Controller (no root required)
./scripts/controller.sh start

# Node agent (requires root β€” XDP needs CAP_NET_ADMIN)
sudo ./scripts/node.sh start

# Check status
./scripts/controller.sh status
sudo ./scripts/node.sh status

The Web UI is available at http://<controller-host>:8000 by default.


API Overview

Both the controller and the node expose a versioned REST API at /api/v1/.

Resource Endpoint Notes
Rules GET/POST /api/v1/rules Pagination: ?page=&limit=
Rule GET/PUT/DELETE /api/v1/rules/:id
Batch rules POST/DELETE /api/v1/rules/batch
Whitelist GET/POST/DELETE /api/v1/whitelist
Stats GET /api/v1/stats PPS, drop counts, XDP info
Nodes GET/POST /api/v1/nodes Controller only
Force sync POST /api/v1/nodes/:id/sync Controller only

Node API requires X-API-Key header. Controller API key is optional (configurable).


License

MIT β€” see LICENSE.

BPF/C kernel programs (node/bpf/) are licensed under GPL-2.0 as required by the Linux kernel BPF subsystem.


Sponsors

Hytron Β Β Β Β  Yecaoyun

Built entirely with Claude Code β€” including the XDP/BPF kernel program, Go concurrency, and Vue frontend.

About

Distributed XDP/eBPF firewall with wire-speed packet filtering and a central management controller.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors