Skip to content

Nexus external API: Use stronger types for BgpPeer addresses#10122

Merged
jgallagher merged 29 commits intomainfrom
john/stronger-unnumbered-types-2
Apr 17, 2026
Merged

Nexus external API: Use stronger types for BgpPeer addresses#10122
jgallagher merged 29 commits intomainfrom
john/stronger-unnumbered-types-2

Conversation

@jgallagher
Copy link
Copy Markdown
Contributor

@jgallagher jgallagher commented Mar 23, 2026

This is a followup to #10082, and extends the stronger RouterPeerType out from the internal API to the Nexus external API. The primary changes here are:

  • Change fields of BgpPeer to give stronger guarantees:
    • BgpPeer::addr is now RouterPeerType instead of Option<IpAddr> (which permitted three distinct representations of "unnumbered": None, Some(0.0.0.0), and Some(::)).
    • BgpPeer::router_lifetime moved from being a top-level field to being nested inside the RouterPeerType::Unnumbered variant, and its type is now RouterLifetimeConfig instead of u16, adding enforcement of bounds.
  • Remove BgpPeer::interface_name (closes BgpPeer::interface_name isn't faithfully persisted in the db - we should remove it #10104).
  • Define new versions of types that transitively include BgpPeer:
    • BgpPeerConfig
    • SwitchPortSettings
    • SwitchPortSettingsCreate

The bulk of the diff is defining new versions of all these types and unit tests for the conversions they implement. The rest is fallout where these types touch other areas (e.g., datastore methods and bg tasks) and should be relatively straightforward.

Base automatically changed from john/stronger-unnumbered-types-1 to main March 24, 2026 01:21
@jgallagher jgallagher force-pushed the john/stronger-unnumbered-types-2 branch from 9f59688 to 56e7ddf Compare March 24, 2026 01:27
Copy link
Copy Markdown
Contributor

@internet-diglett internet-diglett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I primarily have one burning question, but otherwise this looks pretty good!

ReserveBlockError::AddressNotInLot,
) => Error::invalid_request("address not in lot"),
}
Error::from(err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

)]
ValueTooLarge,
#[error(
"max path value must be an integer between {} and {}",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, pretty sure this was me 😂

Comment on lines +1455 to +1457
// Track peers for policy lookup.
peer_by_addr
.insert(p.addr.ip_squashing_unnumbered_to_sentinel(), &p);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I feel like I'm missing something... or I'm forgetting a conversation that was had before but...

In the event that a SwitchPortSettingsCreate struct contains multiple unnumbered peer configurations, wouldn't indexing them by their address cause all-but-one of them to get clobbered?

(if this is indeed a bug, the previous implementation also did the same thing)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and yes it is a bug! I noticed the same thing while I was here and filed #10151. It's fixed in the followup PR (#10155).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is noted on #10151, but: this isn't as bad as it seems at a glance. We don't use this map for database insertion; it's only used to assemble the in-memory return value. Still a bug, but it only affects the value we return from the initial insert - the stored data is correct.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

Comment thread nexus/types/versions/src/stronger_bgp_unnumbered_types/networking.rs Outdated
@jgallagher jgallagher merged commit 00f5b0a into main Apr 17, 2026
17 checks passed
@jgallagher jgallagher deleted the john/stronger-unnumbered-types-2 branch April 17, 2026 16:23
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.

BgpPeer::interface_name isn't faithfully persisted in the db - we should remove it

2 participants