server: use configured local address for nexthop when set#3420
Draft
sergei-ilisavskii wants to merge 1 commit into
Draft
server: use configured local address for nexthop when set#3420sergei-ilisavskii wants to merge 1 commit into
sergei-ilisavskii wants to merge 1 commit into
Conversation
Contributor
Author
|
I need to do additional tests, will come back with results soon |
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. The override is applied in handleFSMMessage() via ReadCopy/Update on pConf before NewPeerInfo is created, so all downstream consumers (toConfig, prePolicyFilterpath nexthop rewrite, watch events) automatically read the correct value. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1b65e1b to
88101dd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
Transport.Config.LocalAddressis set to a specific (non-wildcard) address, overrideTransport.State.LocalAddresswith 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 fromhandleFSMMessage0c74e9c6("server: remove access to fsm.conn in server", Oct 2025) removed the override fromtoConfigApproach
The override is applied in
server.go:handleFSMMessage()when a session reaches ESTABLISHED, consistent with the original PRs. It uses the standardReadCopy → modify → Updatepattern underfsm.lockto persist the overridden address topConfbeforeNewPeerInfois created. All downstream consumers (toConfig,prePolicyFilterpath/nexthop rewrite, watch events) read fromTransport.Stateand automatically get the correct value.The override only applies when the configured address is valid and non-unspecified (not
0.0.0.0or::). IPv6 zone information is stripped since BGP nexthop attributes cannot carry zone info.Test plan
TestLocalAddressOverrideintegration test with 3 sub-tests that establish a real two-server BGP session and verify the overridden address via theListPeerAPI:0.0.0.0(no override)BindInterfaceset (override applied)go build ./...passesgo vet ./pkg/server/...passesgo test -race ./pkg/server/...passes🤖 Generated with Claude Code