From c87089d09fa649a3cae902ca27982c6ef68f1fff Mon Sep 17 00:00:00 2001 From: riccardom Date: Mon, 6 Jul 2026 10:58:24 +0200 Subject: [PATCH] [client] Extract peerRoutesAddr helper in toExcludedLazyPeers Pure stylistic refactor: pull the AllowedIPs match into a named peerRoutesAddr helper and document why forward-target peers are excluded from lazy connections. No behavior change; the existing address match is preserved as-is. Co-Authored-By: Claude Opus 4.8 --- client/internal/engine.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/client/internal/engine.go b/client/internal/engine.go index a08bea31b..5f10166a2 100644 --- a/client/internal/engine.go +++ b/client/internal/engine.go @@ -2561,13 +2561,13 @@ func (e *Engine) updateForwardRules(rules []*mgmProto.ForwardingRule) ([]firewal func (e *Engine) toExcludedLazyPeers(rules []firewallManager.ForwardRule, peers []*mgmProto.RemotePeerConfig) map[string]bool { excludedPeers := make(map[string]bool) + + // Ingress forward targets: inbound forwarded traffic is initiated remotely and + // cannot wake a lazy connection, so the peer routing the target must stay + // permanently connected. for _, r := range rules { - ip := r.TranslatedAddress for _, p := range peers { - for _, allowedIP := range p.GetAllowedIps() { - if allowedIP != ip.String() { - continue - } + if peerRoutesAddr(p, r.TranslatedAddress) { log.Infof("exclude forwarder peer from lazy connection: %s", p.GetWgPubKey()) excludedPeers[p.GetWgPubKey()] = true } @@ -2577,6 +2577,16 @@ func (e *Engine) toExcludedLazyPeers(rules []firewallManager.ForwardRule, peers return excludedPeers } +// peerRoutesAddr verifies if the peer is a router for a given address. +func peerRoutesAddr(p *mgmProto.RemotePeerConfig, addr netip.Addr) bool { + for _, allowedIP := range p.GetAllowedIps() { + if allowedIP == addr.String() { + return true + } + } + return false +} + // isChecksEqual checks if two slices of checks are equal. func isChecksEqual(checks1, checks2 []*mgmProto.Checks) bool { normalize := func(checks []*mgmProto.Checks) []string {