fix: XDP unsafe loader + Redis sync; enforce 250-line/4-file layout limits
- xdp: CString for if_nametoindex (was UB), real detach via prog fd (fabricated borrow_raw(-1) silently never detached), SAFETY comments, saturating expiry math; +5 unit tests - redis: real pubsub reconnect with exponential backoff (was sleep+return); KEYS -> SCAN in heartbeat sweep - ci: cargo test --all-features, repo-gates job — module size gate (scripts/check_module_size.sh, ratchet baseline) + default-secrets grep - refactor src/ to <=250 LOC/file, <=4 .rs/dir without behavior change; thin bins (rampart.rs 330 -> 6 LOC), new app/, subnet/, intel/, profile/, prefix/, challenge/, filter/, probe/, inventory/, metrics/, node/ - docs: TODO v5.0 (status refresh, new rules, findings backlog), README quickstart now matches real binaries - verify: fmt/clippy -D warnings/test --all-features (164 tests)/clang XDP green
This commit is contained in:
parent
7545b3d3ad
commit
bf6d34c882
64 changed files with 2052 additions and 1408 deletions
|
|
@ -1,53 +0,0 @@
|
|||
use anyhow::{Context, Result};
|
||||
use prometheus::{IntGauge, register};
|
||||
|
||||
use super::XdpStats;
|
||||
|
||||
pub struct XdpMetrics {
|
||||
total: IntGauge,
|
||||
tcp: IntGauge,
|
||||
whitelist: IntGauge,
|
||||
blacklist: IntGauge,
|
||||
syn_throttle: IntGauge,
|
||||
passed: IntGauge,
|
||||
dropped: IntGauge,
|
||||
udp: IntGauge,
|
||||
rate_limit: IntGauge,
|
||||
}
|
||||
|
||||
impl XdpMetrics {
|
||||
fn new_gauge(name: &str, help: &str) -> Result<IntGauge> {
|
||||
let gauge = IntGauge::new(name, help)?;
|
||||
register(Box::new(gauge.clone())).context(format!("failed to register {name}"))?;
|
||||
Ok(gauge)
|
||||
}
|
||||
|
||||
pub fn register() -> Result<Self> {
|
||||
let m = Self {
|
||||
total: Self::new_gauge("rampart_xdp_total", "Total XDP packets processed")?,
|
||||
tcp: Self::new_gauge("rampart_xdp_tcp", "TCP packets processed")?,
|
||||
whitelist: Self::new_gauge("rampart_xdp_whitelist", "Whitelisted packets")?,
|
||||
blacklist: Self::new_gauge("rampart_xdp_blacklist", "Blacklisted packets")?,
|
||||
syn_throttle: Self::new_gauge("rampart_xdp_syn_throttle", "SYN packets rate-limited")?,
|
||||
passed: Self::new_gauge("rampart_xdp_passed", "Packets passed to upper layers")?,
|
||||
dropped: Self::new_gauge("rampart_xdp_dropped", "Packets dropped by filter")?,
|
||||
udp: Self::new_gauge("rampart_xdp_udp", "UDP packets processed")?,
|
||||
rate_limit: Self::new_gauge("rampart_xdp_rate_limit", "Packets rate-limited by window counter")?,
|
||||
};
|
||||
tracing::info!("XDP Prometheus metrics registered");
|
||||
Ok(m)
|
||||
}
|
||||
|
||||
pub fn update(&self, stats: &XdpStats) {
|
||||
self.total.set(stats.total as i64);
|
||||
self.tcp.set(stats.tcp as i64);
|
||||
self.whitelist.set(stats.whitelist as i64);
|
||||
self.blacklist.set(stats.blacklist as i64);
|
||||
self.syn_throttle.set(stats.syn_throttle as i64);
|
||||
self.passed.set(stats.passed as i64);
|
||||
self.dropped.set(stats.dropped as i64);
|
||||
self.udp.set(stats.udp as i64);
|
||||
self.rate_limit.set(stats.rate_limit as i64);
|
||||
tracing::debug!("XDP metrics updated");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue