Skip to content

server: use configured local address for nexthop when set#3420

Draft
sergei-ilisavskii wants to merge 1 commit into
osrg:masterfrom
sergei-ilisavskii:fix/local-address-override
Draft

server: use configured local address for nexthop when set#3420
sergei-ilisavskii wants to merge 1 commit into
osrg:masterfrom
sergei-ilisavskii:fix/local-address-override

Conversation

@sergei-ilisavskii
Copy link
Copy Markdown
Contributor

Summary

When Transport.Config.LocalAddress is set to a specific (non-wildcard) address, override Transport.State.LocalAddress with it instead of using the TCP connection's local address. This ensures the configured address is advertised as the BGP nexthop.

This is needed for deployments where the BGP listener binds to an internal address (e.g., VRFs over GENEVE tunnels) but the configured local address is what should be advertised as the nexthop. Without this fix, the TCP connection's local address (the listener's bind address) is used, resulting in incorrect nexthop advertisement.

Background

This issue was originally addressed in #2827 and #2839 (both closed). The fix was applied to downstream forks and evolved with IPv6 improvements, but was inadvertently removed during two upstream refactoring commits:

  • 075aab46 ("convert PeerInfo to use netip instead of net", Aug 2025) removed the override from handleFSMMessage
  • 0c74e9c6 ("server: remove access to fsm.conn in server", Oct 2025) removed the override from toConfig

Approach

Rather than re-adding the override in two separate locations in server.go as the original PRs did, this fix applies the override in fsm.stateChange() — the single point where Transport.State.LocalAddress is written when a session reaches ESTABLISHED. All downstream consumers (NewPeerInfo, prePolicyFilterpath/nexthop rewrite, watch events) read from Transport.State and automatically get the correct value.

The override only applies when the configured address is valid and non-unspecified (not 0.0.0.0 or ::). IPv6 zone information is stripped since BGP nexthop attributes cannot carry zone info.

Test plan

  • Added TestStateChangeLocalAddressOverride with 6 sub-tests covering:
    • Wildcard IPv4/IPv6 (no override)
    • Zero value config address (no override)
    • Specific IPv4/IPv6 (override applied)
    • IPv6 with zone index (zone stripped on override)
  • go build ./... passes
  • go vet ./pkg/server/... passes
  • Existing tests unaffected

🤖 Generated with Claude Code

When Transport.Config.LocalAddress is set to a specific (non-wildcard)
address, override Transport.State.LocalAddress with it instead of using
the TCP connection's local address. This is needed for deployments
where the BGP listener binds to an internal address (e.g. VRFs over
GENEVE tunnels) but the configured address should be advertised as
the nexthop.

The override is applied in fsm.stateChange() when the session reaches
ESTABLISHED, which is the single point where Transport.State.LocalAddress
is written. All downstream consumers (PeerInfo, nexthop rewrite, watch
events) read from Transport.State and automatically get the correct value.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sergei-ilisavskii sergei-ilisavskii marked this pull request as draft May 11, 2026 17:15
@sergei-ilisavskii
Copy link
Copy Markdown
Contributor Author

I need to do additional tests, will come back with results soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant