No description
This repository has been archived on 2026-11-06. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
  • JavaScript 77.6%
  • Go 7.6%
  • Shell 5.9%
  • Python 5.6%
  • CSS 2.8%
  • Other 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
mavotronik 19ae019af1
All checks were successful
CI / js (npm test, deploy/ui/app, ui) (push) Successful in 13s
CI / js (, deploy/analytics, analytics) (push) Successful in 7s
CI / js (npm test, deploy/detection, detection) (push) Successful in 10s
versions / tag (push) Successful in 7m22s
Обновить .github/workflows/ci.yml
2026-10-30 19:48:29 +03:00
.github Обновить .github/workflows/ci.yml 2026-10-30 19:48:29 +03:00
attic Move ipt_NETFLOW cutover, AF_XDP and host rollup timers into attic/. 2026-08-13 12:17:49 +03:00
bpf Move ipt_NETFLOW cutover, AF_XDP and host rollup timers into attic/. 2026-08-13 12:17:49 +03:00
cmd ограничение конфига коллектора 2026-10-27 21:36:34 +06:00
deploy В кабинете IX клиент подписывается service_name и номером AS, поиск идёт по этой же строке. 2026-10-30 17:34:02 +03:00
docs Порт dwdmru- считается клиентским: слово dwdm больше не исключение. 2026-10-29 15:29:39 +03:00
internal Порт dwdmru- считается клиентским: слово dwdm больше не исключение. 2026-10-29 15:29:39 +03:00
scripts grapes-attack-asn: реальные байты, трафик по типу атаки и владелец L3 2026-10-30 15:18:36 +03:00
.gitignore Обновил гитигнор 2026-10-20 16:06:26 +06:00
go.mod Move ipt_NETFLOW cutover, AF_XDP and host rollup timers into attic/. 2026-08-13 12:17:49 +03:00
go.sum Move ipt_NETFLOW cutover, AF_XDP and host rollup timers into attic/. 2026-08-13 12:17:49 +03:00
Makefile Move ipt_NETFLOW cutover, AF_XDP and host rollup timers into attic/. 2026-08-13 12:17:49 +03:00
README.md Move ipt_NETFLOW cutover, AF_XDP and host rollup timers into attic/. 2026-08-13 12:17:49 +03:00

GrapesNTA

XDP/eBPF flow collectors, ClickHouse analytics, Docker workers, and the NTAdmin UI.

Новый стенд с нуля: docs/INSTALL.txt (текст для инженера) или docs/INSTALL.md.

Repository: github.com/jzhekatroy/GrapesNTA

The rest of this README is the xdpflowd collector: build flags, NetFlow export, and the old ipt_NETFLOW cutover. Collector binaries still live here; rollups and the UI do not.

Build (Linux only): requires clang, libbpf-dev, linux-libc-dev (or kernel headers), Go 1.23+.

git clone https://github.com/jzhekatroy/GrapesNTA.git
cd GrapesNTA
go mod tidy   # first time: populate go.sum
make clean && make
# binary: ./bin/xdpflowd
# BPF object: ./bpf/xdp_flow.o

RIR country → ClickHouse: optional Python script scripts/load_rir_geo.py loads delegated statistics into geo_prefix_country and geo_country_dict via clickhouse-client. See docs/geoip_country.md.

Traffic rollups → ClickHouse: aggregate tables traffic_* are filled asynchronously by scripts/traffic_rollup_async.py (not sync MV on ingest). Schema: deploy/schema/60_traffic. Detach leftover MVs: deploy/clickhouse/detach_traffic_mvs.sql. On production, grapes-worker runs the rollups. Runbook: docs/CLICKHOUSE_DB_SETUP_RUNBOOK.md §7.

BMP collector: standalone pure-Go service cmd/bmpgrapes accepts BMP TCP sessions from routers and writes default.bmp_peers / default.bmp_route_events / default.bgp_updates_1m. Build with make build-bmp, see docs/BMPGRAPES_MVP.md and deploy/schema/30_bmp.

Run (root):

sudo ./bin/xdpflowd -iface ens18 -mode native -bpf ./bpf/xdp_flow.o

Flags

Flag Meaning
-bpf Path to compiled xdp_flow.o (default ./bpf/xdp_flow.o)
-iface Interface to attach XDP
-mode native or generic
-interval Text stats / top-N print interval
-json-out PATH Append one NDJSON line per -json-interval with stats + aggregate (+ optional flows)
-json-interval JSON dump period (default: same as -interval)
-json-include-flows Include full flows array (large)
-once Sleep one -interval, optional single JSON line, print top, exit
-top Number of lines in top flows
-nf-dst NetFlow v9 destinations, comma-separated host:port (e.g. 127.0.0.1:2055,127.0.0.1:9999). Empty = disabled.
-nf-active Active timeout — export flows older than this (default 120s)
-nf-idle Idle timeout — export flows with no packets for this long (default 15s)
-nf-template-interval Re-send NFv9 template (default 60s)
-nf-scan How often to walk the map for export (default 1s)
-nf-source-id NFv9 source_id (observation domain, default 1)
-xdp-action XDP return for accounted IP packets: pass (default, safe) or drop. Use drop only on SPAN/mirror interfaces — drops the packet from the kernel stack after accounting, saving ~30% softirq CPU on a 2.5-3 Mpps flow. Non-IP (ARP, LLDP) always passes.

XDP_DROP on SPAN/mirror

For monitoring-only ports where kernel doesn't need to process packets further, add -xdp-action drop to eliminate the skb_alloc + netfilter + routing cost per packet. This is where the real Phase 3 CPU win lives (as opposed to XDP_PASS, which adds BPF cost on top of the existing kernel path).

sudo ./bin/xdpflowd -iface enp5s0d1 -mode native -xdp-action drop \
     -nf-dst 127.0.0.1:9996 -nf-active 60s -nf-idle 15s

DO NOT use -xdp-action drop on a regular routing interface — packets will be silently dropped and forwarding will break.

NetFlow v9 export

Send flows to nfcapd / goflow2 / any NFv9 collector:

sudo ./bin/xdpflowd -iface ens18 -mode native -bpf ./bpf/xdp_flow.o \
     -nf-dst 127.0.0.1:2055,127.0.0.1:9996 \
     -nf-active 120s -nf-idle 15s -nf-template-interval 60s

Emitted fields (templates 256 = IPv4, 257 = IPv6, both in one Template FlowSet):

IN_BYTES (8), IN_PKTS (8), PROTOCOL, SRC_TOS, TCP_FLAGS, L4_SRC_PORT, IPV4_SRC_ADDR / IPV6_SRC_ADDR, INPUT_SNMP (= ingress_ifindex), L4_DST_PORT, IPV4_DST_ADDR / IPV6_DST_ADDR, FIRST_SWITCHED, LAST_SWITCHED, MIN_TTL, MAX_TTL, MIN_PKT_LNGTH, MAX_PKT_LNGTH, SRC_VLAN, IP_PROTOCOL_VERSION.

Test end-to-end with scripts/netflow_test.sh: runs xdpflowd → nfcapd → compares xdpflowd JSON totals vs nfdump aggregate.

sudo ./scripts/netflow_test.sh ens18 192.168.64.1

Accuracy / baseline (strict thresholds)

Script: scripts/accuracy_test.sh

  • Temporarily turns GRO off on the test interface (restores defaults afterward).
  • Compares delta ethtool -S rx_packets / rx_bytes vs:
    • eBPF stats[0] total_packets (XDP saw every L2 frame)
    • sum of flows map packets / bytes (IP flows only — ARP etc. will not appear in flows).

Strict pass (packets): XDP stats.total_packets delta vs ethtool rx_packets delta ≥ 99.99%.

Bytes: sum of flow bytes vs ethtool rx_bytes may diverge slightly due to non-IP frames; script warns below 99.95%.

# On the test VM (iperf3 server elsewhere):
export IPERF3_HOST=203.0.113.10
sudo -E ./scripts/accuracy_test.sh

Optional tcpreplay phase:

export PCAP_IN=/tmp/sample.pcap
sudo -E ./scripts/accuracy_test.sh

PCAP local capture + replay

scripts/pcap_replay_test.sh — captures a few seconds on IFACE, replays with tcpreplay, prints deltas.

sudo IFACE=ens18 ./scripts/pcap_replay_test.sh

Production: new stand vs old ipt_NETFLOW cutover

A new stand: docs/INSTALL.txt.

The ipt_NETFLOW A/B scripts, experimental AF_XDP daemon, and host systemd timers for rollups/geo are in attic/. Do not enable them next to grapes-worker / grapes-enrichment.

Flow fields (kernel / raw)

Per flow (see bpf/xdp_flow.c):

  • IPv4/IPv6 addresses (v4 stored in first 4 bytes of 16-byte key fields)
  • Ports (network order in map; ICMP/ICMPv6 type+code in src_port)
  • VLAN id (802.1Q / 802.1AD), protocol, IP version
  • Packets, bytes, first/last seen (ktime ns)
  • ingress_ifindex, rx_queue
  • TCP SYN/RST/FIN counts, TCP flags OR, IPv4 ToS
  • TTL min/max (IPv4 TTL / IPv6 hop limit)
  • L2 frame length min/max (pkt_len_min / pkt_len_max)
  • ip_frag_count (IPv4 MF/offset; IPv6 if Fragment header seen)

No GeoIP/ASN enrichment (by design).