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:
parent
c9e6cd2e61
commit
96334845f0
1 changed files with 93 additions and 39 deletions
|
|
@ -190,8 +190,8 @@ let
|
|||
|
||||
# The bridge table. A frame of a port goes through `prerouting` in this
|
||||
# order: the port must be bound to the frame's source MAC, then the frame's
|
||||
# protocol decides which source address it may carry. Everything else ends in
|
||||
# `spoof`, which logs and then drops or, with `antiSpoof = "log"`, accepts.
|
||||
# protocol decides which source address it may carry. Everything else logs in
|
||||
# `spoof_<reason>`, then `spoof` drops it (`antiSpoof = "log"`: accepts).
|
||||
#
|
||||
# - `port_mac` and `port_chaddr` hold the bound (port, MAC) pairs, the second
|
||||
# as the 48 bits that sit at the `chaddr` field of a DHCP message. A port
|
||||
|
|
@ -215,9 +215,31 @@ let
|
|||
# Logging is per ingress port, in the style of the forward chain: a burst of
|
||||
# 20 lines, then one a second, and a port is forgotten after a minute. A
|
||||
# packet its port cannot log (over its rate, or the set is full) falls to the
|
||||
# unmetered line, which has one budget for all ports. It logs
|
||||
# packets, not flows: the bridge hook has no connection tracking.
|
||||
# unmetered line, which has one budget for all ports and reasons: the named
|
||||
# limit `spoof_unmetered`. It logs packets, not flows: the bridge hook has no
|
||||
# connection tracking.
|
||||
spoofVerdict = if egressCfg.antiSpoof == "drop" then "drop" else "accept";
|
||||
|
||||
# The log prefix names the check that refused the frame: `mac` (the port is
|
||||
# not bound to the source MAC), `vlan`, `dhcp` (the `chaddr` is not the
|
||||
# port's), `v4`, `v6`, and `arp` (the ARP sender's MAC or address is not the
|
||||
# port's). Each reason has its own chain and counters; `spoof` holds the
|
||||
# verdict and one counter for every refused frame.
|
||||
spoofReasons = [
|
||||
"mac"
|
||||
"vlan"
|
||||
"dhcp"
|
||||
"v4"
|
||||
"v6"
|
||||
"arp"
|
||||
];
|
||||
spoofChain = reason: ''
|
||||
chain spoof_${reason} {
|
||||
update @spoof_ports { iifname limit rate ${logRate} } counter log prefix "hive-egress-spoof ${reason} " goto spoof
|
||||
limit name "spoof_unmetered" counter log prefix "hive-egress-spoof-unmetered ${reason} " goto spoof
|
||||
counter goto spoof
|
||||
}
|
||||
'';
|
||||
bridgeTable = ''
|
||||
table bridge hive_egress {
|
||||
set port_mac { type ifname . ether_addr; }
|
||||
|
|
@ -225,37 +247,39 @@ let
|
|||
set lease_v4 { type ether_addr . ipv4_addr; flags timeout; size 65536; }
|
||||
set spoof_ports { type ifname; flags dynamic; timeout 1m; size 4096; }
|
||||
|
||||
limit spoof_unmetered { rate ${unmeteredRate} }
|
||||
|
||||
chain spoof {
|
||||
update @spoof_ports { iifname limit rate ${logRate} } counter log prefix "hive-egress-spoof " ${spoofVerdict}
|
||||
limit rate ${unmeteredRate} counter log prefix "hive-egress-spoof-unmetered " ${spoofVerdict}
|
||||
counter ${spoofVerdict}
|
||||
}
|
||||
|
||||
${lib.concatMapStringsSep "\n" spoofChain spoofReasons}
|
||||
|
||||
chain l3_v4 {
|
||||
udp dport 67 iifname . @th,288,48 != @port_chaddr goto spoof
|
||||
udp dport 67 iifname . @th,288,48 != @port_chaddr goto spoof_dhcp
|
||||
ip daddr { 255.255.255.255, ${cfg.bridgeIp} } udp sport 68 udp dport 67 accept
|
||||
ether saddr . ip saddr @lease_v4 accept
|
||||
goto spoof
|
||||
goto spoof_v4
|
||||
}
|
||||
|
||||
chain l3_v6 {
|
||||
ip6 saddr fe80::/10 accept
|
||||
ip6 saddr :: icmpv6 type { nd-neighbor-solicit, mld2-listener-report } accept
|
||||
goto spoof
|
||||
goto spoof_v6
|
||||
}
|
||||
|
||||
chain l3_arp {
|
||||
iifname . arp saddr ether != @port_mac goto spoof
|
||||
iifname . arp saddr ether != @port_mac goto spoof_arp
|
||||
arp saddr ip 0.0.0.0 accept
|
||||
arp saddr ether . arp saddr ip @lease_v4 accept
|
||||
goto spoof
|
||||
goto spoof_arp
|
||||
}
|
||||
|
||||
chain prerouting {
|
||||
type filter hook prerouting priority -300; policy accept;
|
||||
meta ibrname != "${br}" accept
|
||||
iifname . ether saddr != @port_mac goto spoof
|
||||
ether type { 8021q, 8021ad } goto spoof
|
||||
iifname . ether saddr != @port_mac goto spoof_mac
|
||||
ether type { 8021q, 8021ad } goto spoof_vlan
|
||||
ether type ip goto l3_v4
|
||||
ether type ip6 goto l3_v6
|
||||
ether type arp goto l3_arp
|
||||
|
|
@ -347,12 +371,14 @@ in
|
|||
sources (and `::` in neighbour discovery and listener reports).
|
||||
|
||||
- `drop`: the frame is dropped and logged with the prefix
|
||||
`hive-egress-spoof `, rate limited per port. A packet the per-port limit
|
||||
cannot log gets a line with the prefix `hive-egress-spoof-unmetered `
|
||||
from a limit shared by all ports. A container sending from its leased
|
||||
address is unaffected while its (MAC, IP) pair is in the lease set; a
|
||||
lost pair, as after a host suspend/resume, cuts the container off until
|
||||
it leases again.
|
||||
`hive-egress-spoof <reason> `, rate limited per port; the reason is the
|
||||
check that failed: `mac`, `vlan`, `dhcp`, `v4`, `v6` or `arp`. A packet
|
||||
the per-port limit cannot log gets a line with the prefix
|
||||
`hive-egress-spoof-unmetered <reason> `, from one limit shared by all
|
||||
ports and reasons. A container sending from its leased address is
|
||||
unaffected while its (MAC, IP) pair is in the lease set; a lost pair,
|
||||
as after a host suspend/resume, cuts the container off until it leases
|
||||
again.
|
||||
- `log` (the default): the same lines and counters, and the frame goes
|
||||
through. For finding out why a legitimate container is refused on a
|
||||
live hive. It is the default because the lease set does not yet survive
|
||||
|
|
|
|||
Loading…
Reference in a new issue