Watch
0
0
Fork
You've already forked hyperhive
0

hive-egress: the spoof log line says which check failed

Each refused frame now goes through its own chain, spoof_<reason>, whose log prefix names the check that refused it (mac, vlan, dhcp, v4, v6, arp). The unmetered log lines of all reasons share one named limit, spoof_unmetered, so the budget stays one for all ports and reasons.
This commit is contained in:
atlas 2026-11-19 14:52:16 +01:00 • committed by mara
commit 96334845f0

View file

@ -1647,9 +1647,10 @@ let
}
{
# The bridge table drops what a port sends from an address that is not
# its own, and logs it. The ruleset is read as text: the spoof chain
# ends every path in `drop`, and the accepts that remain are the ones that
# let the leased source through, which is the presence arm.
# its own, and logs it. The ruleset is read as text: each `spoof_<reason>`
# chain logs and goes to `spoof`, which ends every path in `drop`, and the
# accepts that remain are the ones that let the leased source through,
# which is the presence arm.
name = "egress.antiSpoof drop renders the bridge table that drops frames whose source is not the port's own";
ok =
let
@ -1659,22 +1660,46 @@ let
name: lib.head (lib.splitString "chain" (lib.last (lib.splitString "chain ${name} {" bridgeText)));
spoof = lib.filter (l: l != "" && l != "}") (map lib.trim (lib.splitString "\n" (section "spoof")));
ip4 = section "l3_v4";
reasons = [
"mac"
"vlan"
"dhcp"
"v4"
"v6"
"arp"
];
reasonLines =
r: lib.filter (l: l != "" && l != "}") (map lib.trim (lib.splitString "\n" (section "spoof_${r}")));
in
egressForwardAccept.services.hyperhive.deploy.hive-controller.egress.antiSpoof == "drop"
&& lib.hasInfix "hook prerouting priority -300" bridgeText
&& lib.hasInfix ''meta ibrname != "hive-br0" accept'' bridgeText
&& lib.hasInfix "iifname . ether saddr != @port_mac goto spoof" bridgeText
&& lib.hasInfix "ether type { 8021q, 8021ad } goto spoof" bridgeText
&& lib.hasInfix "udp dport 67 iifname . @th,288,48 != @port_chaddr goto spoof" bridgeText
&& lib.hasInfix "iifname . ether saddr != @port_mac goto spoof_mac" bridgeText
&& lib.hasInfix "ether type { 8021q, 8021ad } goto spoof_vlan" bridgeText
&& lib.hasInfix "udp dport 67 iifname . @th,288,48 != @port_chaddr goto spoof_dhcp" bridgeText
&& lib.hasInfix "ether saddr . ip saddr @lease_v4 accept" bridgeText
&& lib.hasInfix "ip6 saddr fe80::/10 accept" bridgeText
&& lib.hasInfix "arp saddr ether . arp saddr ip @lease_v4 accept" bridgeText
&& lib.hasInfix ''log prefix "hive-egress-spoof "'' bridgeText
&& lib.hasInfix ''log prefix "hive-egress-spoof-unmetered "'' bridgeText
&& lib.hasInfix "update @spoof_ports { iifname limit rate 1/second burst 20 packets }" bridgeText
&& lib.length spoof == 3
&& lib.all (
r:
lib.hasInfix ''log prefix "hive-egress-spoof ${r} "'' (section "spoof_${r}")
&& lib.hasInfix ''log prefix "hive-egress-spoof-unmetered ${r} "'' (section "spoof_${r}")
&& lib.hasInfix ''limit name "spoof_unmetered" counter log prefix "hive-egress-spoof-unmetered ${r} "'' (
section "spoof_${r}"
)
&& lib.hasInfix "update @spoof_ports { iifname limit rate 1/second burst 20 packets }" (
section "spoof_${r}"
)
&& lib.length (reasonLines r) == 3
&& lib.all (l: lib.hasSuffix " goto spoof" l) (reasonLines r)
) reasons
&& lib.hasInfix "limit spoof_unmetered { rate 5/second burst 50 packets }" bridgeText
&& lib.length (lib.splitString "limit spoof_unmetered {" bridgeText) == 2
&& lib.length spoof == 1
&& lib.all (l: lib.hasSuffix " drop" l) spoof
&& lib.hasInfix "goto spoof" ip4;
&& lib.hasInfix "goto spoof_v4" ip4
&& lib.hasInfix "goto spoof_v6" (section "l3_v6")
&& lib.hasInfix "goto spoof_arp" (section "l3_arp");
}
{
# `log`, the default, renders the same chains with `accept` where `drop`
@ -1695,9 +1720,9 @@ let
logged = spoofOf bare;
in
bare.services.hyperhive.deploy.hive-controller.egress.antiSpoof == "log"
&& lib.length logged == 3
&& lib.length logged == 1
&& lib.all (l: lib.hasSuffix " accept" l) logged
&& lib.hasInfix ''log prefix "hive-egress-spoof "'' (textOf bare)
&& lib.hasInfix ''log prefix "hive-egress-spoof mac "'' (textOf bare)
&& !(lib.any (l: lib.hasSuffix " drop" l) logged)
&& lib.all (l: lib.hasSuffix " drop" l) (spoofOf egressForwardAccept);
}