fix: never ban a trusted proxy network from any ban source

The gateway already refused to ban addresses from proxy_protocol.trusted_cidrs,
but the traffic-intelligence auto-ban and the subnet monitor still did, so a
trusted load balancer living inside a banned /24 (or below the reputation
threshold) could be knocked out together with its clients.

- TrustedProxyCidr moved to src/config/trusted.rs (the edge section file hit
  the 250-line gate) and gained `overlaps_prefix`: a ban is suppressed when the
  banned prefix intersects a trusted network.
- TrafficHook::with_trusted suppresses reputation and offender bans; its ban()
  now reports whether the ban was installed so `ban_offenders` counts real
  bans.
- The subnet monitor takes a MonitorSetup bundle (spawn had 8 arguments) and
  suppresses both userspace CIDR bans and XDP prefix bans that overlap a
  trusted network, logging a warning instead.
- IPv4-mapped addresses are normalised in `contains` too.
- Tests: overlap maths (v4/v6, /0 rejected), tracker suppression vs unrelated
  networks, and auto-ban skipping a trusted range while still banning public
  offenders.
This commit is contained in:
Loki 2026-11-16 13:03:50 +01:00
parent 72c1f45d62
commit bcae8901c6
Signed by: boba
GPG key ID: 6CDE87BC9A778D97
11 changed files with 300 additions and 106 deletions

View file

@ -237,3 +237,25 @@ async fn plain_connection_uses_the_transport_peer() {
let outcome = handle_plain(&gateway, peer).await;
assert_eq!(outcome.client_ip, Some(peer.ip()));
}
#[test]
fn trusted_network_overlap_checks_prefix_intersection() {
let net: TrustedProxyCidr = "10.0.0.0/8".parse().expect("cidr");
assert!(net.overlaps_prefix("10.1.2.0".parse().expect("ip"), 24), "same range");
assert!(
net.overlaps_prefix("10.0.0.0".parse().expect("ip"), 7),
"wider prefix overlaps"
);
assert!(
!net.overlaps_prefix("11.0.0.0".parse().expect("ip"), 8),
"sibling range"
);
assert!(
!net.overlaps_prefix("10.0.0.0".parse().expect("ip"), 0),
"/0 is rejected"
);
let v6: TrustedProxyCidr = "fd00::/8".parse().expect("cidr");
assert!(v6.overlaps_prefix("fd12::".parse().expect("ip"), 16));
assert!(!v6.overlaps_prefix("2001:db8::".parse().expect("ip"), 32));
}