This project provides an XDP/eBPF DDoS protection filter with:
- IPv4 and IPv6 source tracking
- Per-IP, subnet, and per-port policy rules (pass, adaptive, or drop)
- Adaptive baseline learning (no fixed static pps/bps limits)
- Heuristic packet inspection for:
- DNS amplification-like response floods
- NTP/SSDP/CLDAP/Memcached/Chargen reflection-like UDP floods
- ACK-only TCP flood signatures
- TCP RST spam and SYN-heavy flood signatures
- ICMP flood behavior
- TCP weird-flag/null-scan style traffic spikes
- Random UDP spray patterns
- Port-scan-like destination spread
- Automatic mitigation (temporary auto-block after repeated suspicious windows)
- High-confidence mitigation gates (minimum score and multi-signal confirmation before block)
- Driver-mode XDP attachment (native mode)
- Runtime stats, monitoring, and structured log streaming
- REST API service for dashboard integration
- SQLite-backed persistent control plane state
- Conservative auto-learning loop with trust/suspicion tracking
src/xdp_ddos_kern.c:- XDP data path logic
- Per-source-IP adaptive state tracking with 1-second windows
- IPv4 and IPv6 parsing
- L4 signal extraction (TCP/UDP feature counters)
- Suspicion scoring + auto-mitigation via timed blocks
- Ring buffer security event emission
src/xdp_ddos_user.c:- Load/unload XDP in driver mode
- Configure adaptive defaults and IP/subnet/port policies
- Parse optional rule file
- Read and monitor stats
- Show top source talkers (pps/bps/signals)
- Persist mitigation events as JSONL logs
src/common.h: shared map/value definitionsapi/server.py: REST API wrapper for automation and UI- SQLite DB persistence for defaults/policies/learning state
- Startup replay to re-apply saved rules automatically
- Auto-learning/tuning worker for adaptive policy updates
- Linux kernel with XDP support
- Native driver-mode support on your NIC
clang,gcc,make,libbpf,libelf,zlib- Root privileges for load/unload and map access
makeLoad with defaults only:
sudo ./xdp_ddos load eth0Load with a rules file:
sudo ./xdp_ddos load eth0 configs/rules.confLoad in shared mode on multiple interfaces (single shared map set):
sudo ./xdp_ddos load-many configs/rules.conf eth0 enp6s20 enp6s21Detach then reattach on multiple interfaces (for rolling hardening updates):
sudo ./xdp_ddos reload-many configs/rules.conf eth0 enp6s20 enp6s21configs/rules.conf is intentionally defaults-only. Manage IP/subnet/port overrides dynamically via API.
Show one-shot stats:
sudo ./xdp_ddos statsMonitor stats continuously:
sudo ./xdp_ddos monitor 2Live human-readable active monitor (shows block deltas and top sources):
sudo ./xdp_ddos active 2 15Stream detection events to JSONL:
sudo ./xdp_ddos log /var/log/xdp_ddos_events.jsonl 250Unload:
sudo ./xdp_ddos unload eth0Unload from multiple interfaces:
sudo ./xdp_ddos unload-many eth0 enp6s20 enp6s21Show global defaults:
sudo ./xdp_ddos defaults showSet adaptive defaults:
sudo ./xdp_ddos defaults set 280 140 120 3 1 3 88 70 65 60 700 12 18 45 55 220 3 30 20 12 18 0Machine-readable JSON output (for API integrations):
sudo ./xdp_ddos --json stats
sudo ./xdp_ddos --json defaults show
sudo ./xdp_ddos --json state top 20Show top active sources:
sudo ./xdp_ddos state top 30Add subnet rule:
sudo ./xdp_ddos subnet add 203.0.113.0/24 adaptive 230 110 180Add per-port default profile (UDP/53):
sudo ./xdp_ddos port add udp 53 adaptive 210 100 180Add an IPv4 drop rule for 10 minutes:
sudo ./xdp_ddos policy add 198.51.100.10 drop 0 0 0 600Add an IPv6 adaptive override rule:
sudo ./xdp_ddos policy add 2001:db8::42 adaptive 220 100 180Delete a rule:
sudo ./xdp_ddos policy del 2001:db8::42List rules:
sudo ./xdp_ddos policy listSee configs/rules.conf.
Supported directives:
default anomaly_mult=<pct> score=<n> block_ttl=<sec> offenses=<n> auto=<0|1> warmup=<n> ack_ratio=<pct> rst_ratio=<pct> syn_ratio=<pct> dns_ratio=<pct> dns_min_bytes=<n> udp_spread=<n> scan_spread=<n> udp_amp_ratio=<pct> icmp_ratio=<pct> block_min_score=<n> block_min_reasons=<n> emergency_cooldown_sec=<sec> service_relax_dns_pct=<pct> service_relax_http_pct=<pct> service_relax_https_pct=<pct> service_relax_ntp_pct=<pct>ip <IPv4|IPv6> action=<pass|adaptive|drop> anomaly_mult=<pct> score=<n> block_ttl=<sec> ttl=<sec>subnet <IPv4_CIDR|IPv6_CIDR> action=<pass|adaptive|drop> anomaly_mult=<pct> score=<n> block_ttl=<sec> ttl=<sec>port <tcp|udp> <port> action=<pass|adaptive|drop> anomaly_mult=<pct> score=<n> block_ttl=<sec> ttl=<sec>
If no rules file is supplied, built-in defaults are applied automatically. If no API/CLI overrides are set, the system runs on defaults only.
The API server is intended for a web panel/control plane.
Install and run:
python3 -m venv .venv
source .venv/bin/activate
pip install -r api/requirements.txt
XDP_DDOS_CLI=./xdp_ddos XDP_DDOS_EVENT_LOG=/var/log/xdp_ddos_events.jsonl XDP_DDOS_DB=./xdp_ddos.db XDP_DDOS_AUTO_LEARN=1 python api/server.pyEnvironment options:
XDP_DDOS_DB: SQLite file path (portable state file)XDP_DDOS_AUTO_LEARN:1enable auto-learning,0disableXDP_DDOS_AUTO_LEARN_INTERVAL_SEC: learning loop interval in secondsXDP_DDOS_API_HOST,XDP_DDOS_API_PORT: bind settings
Main endpoints:
GET /api/v1/healthGET /api/v1/statsGET /api/v1/defaultsPUT /api/v1/defaultsGET /api/v1/sources/top?limit=20POST /api/v1/policies/ipDELETE /api/v1/policies/ip/<ip>POST /api/v1/policies/subnetDELETE /api/v1/policies/subnet/<cidr>POST /api/v1/policies/portDELETE /api/v1/policies/port/<proto>/<port>GET /api/v1/policies?scope=<ip|subnet|port>POST /api/v1/ip/<ip>/disable(sets pass rule with ttl)POST /api/v1/ip/<ip>/enable(removes disable/pass rule)GET /api/v1/learning/statePOST /api/v1/learning/tickGET /api/v1/attacks/recent?limit=100GET /api/v1/attacks/summary?limit=1000GET /api/v1/db/exportPOST /api/v1/db/importPOST /api/v1/replay
- Driver mode is enforced. If your NIC does not support native XDP mode, load will fail.
- Existing state is LRU-capped to prevent unbounded memory growth.
- Auto-mitigation is in-kernel, so it reacts at packet path speed.
- This is adaptive anomaly detection with packet-level heuristics, not full stream reassembly IDS.
- No single XDP program can detect literally every attack type; for full coverage combine this with upstream filtering, ACLs, and L7 controls.
- Blocking is intentionally conservative: uncertain patterns are monitored first (
monitor_only) and only high-confidence multi-signal cases are eligible for block. - An emergency guardrail path is enabled for extreme in-window floods so severe attacks are dropped immediately instead of waiting for window rollover.
- Emergency hysteresis is enabled through a cooldown period after emergency drops so immediate post-attack traffic is judged with stricter confidence thresholds.