feat(gateway): log periodic CAM refreshes

The gateway already sent periodic CAM refresh frames so the physical switch
keeps remote client MACs learned on the gateway port. Those periodic refreshes
were silent, which made the manual MVP switch-learning check harder to diagnose
after the initial peer-joined refresh had passed.

Keep the peer id and MAC attached to periodic refresh work and emit the same
structured CAM refresh log line with reason=periodic. The join-triggered
refresh still logs reason=peer_joined, so the test guide can distinguish the
immediate proof from the recurring keepalive signal.

Test Plan:
- cargo test -p lanparty-gateway cam_refresh
- cargo test -p lanparty-gateway
- cargo fmt --check
- cargo test --workspace
- cargo clippy --workspace --all-targets -- -D warnings
- git diff --check
- git diff --cached --check

Refs: MVP switch MAC-learning diagnostics
This commit is contained in:
2026-05-22 06:46:41 +02:00
parent 6b081f49c4
commit 0ad84eaaaf
3 changed files with 32 additions and 16 deletions
+20 -7
View File
@@ -458,8 +458,17 @@ impl GatewayConnection {
}
}
_ = cam_refresh_tick.tick() => {
for frame in remote_clients.refresh_frames() {
write_lan_ethernet(&packet_socket, &frame).await?;
for refresh in remote_clients.refreshes() {
write_lan_ethernet(&packet_socket, refresh.frame()).await?;
println!(
"{}",
gateway_cam_refresh_log_line(
packet_socket.get_ref().interface(),
refresh.peer_id(),
refresh.mac(),
"periodic",
)
);
}
}
_ = stats_tick.tick() => {
@@ -932,10 +941,10 @@ impl RemoteClientTable {
self.remote_clients.remove(&peer_id);
}
fn refresh_frames(&self) -> Vec<Vec<u8>> {
fn refreshes(&self) -> Vec<CamRefresh> {
self.remote_clients
.values()
.map(|source| cam_refresh_frame(*source, self.gateway_mac))
.iter()
.map(|(peer_id, mac)| CamRefresh::new(*peer_id, *mac, self.gateway_mac))
.collect()
}
@@ -1412,8 +1421,12 @@ mod tests {
assert_eq!(immediate_frame.source(), remote_mac);
assert_eq!(immediate_frame.destination(), gateway_mac);
assert_eq!(refresh.remote_mac_count(), 1);
let periodic_refreshes = refresh.refreshes();
assert_eq!(periodic_refreshes.len(), 1);
assert_eq!(periodic_refreshes[0].peer_id(), 7);
assert_eq!(periodic_refreshes[0].mac(), remote_mac);
assert_eq!(
EthernetFrame::parse(&refresh.refresh_frames()[0])
EthernetFrame::parse(periodic_refreshes[0].frame())
.unwrap()
.source(),
remote_mac
@@ -1427,7 +1440,7 @@ mod tests {
None
);
assert_eq!(refresh.remote_mac_count(), 0);
assert!(refresh.refresh_frames().is_empty());
assert!(refresh.refreshes().is_empty());
}
#[cfg(target_os = "linux")]