You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stronger types for BGP unnumbered peer addressing #9832
(This is followup from review comments on #9570 that can be deferred to after R18, but I think we should consider it tech debt that we should pay down as soon as is reasonable. I believe addressing it is blocked by #9801.)
#9570 introduces support for BGP unnumbered peers, which have no address. This is mostly expressed by using an unspecified address (0.0.0.0 or ::, depending ipv4/ipv6) to mean "no address". In some spots we use an Option<IpAddr> instead, where None means "no address", but the inconsistency is unfortunate:
If the address isn't optional, any user of the address that needs to consider this now needs to check whether the address is unspecified. I'll propose that this seems easy to forget. b211fc9 is an example of the kind of thing I'm worried about; this adds a check to tread unspecified addresses specially, and it seems quite difficult to know (a) whether we've updated all sites that need to be updated and (b) that we'll have confidence that we continue to do so in the future.
If the address is optional, what does Some(addr) mean if addr is itself unspecified?
The datastore model types use Option<IpNetwork>, but then convert to an unspecified address as a sentinel value in the database, which has all the typical "sentinel value" issues (in particular: we have to correctly convert them at every insertion and query).
This is definitely not my area of expertise, but I'd tentatively propose something shaped sort of like this, with more clear names from someone who knows the domain better:
where SpecifiedIpAddr is a newtype around IpAddr similar to NonZeroU8 and friends (i.e., it validates that the IP address it wraps is not unspecified).
Another spot where this came up in testing #9570; we should make sure whatever we do here would've caught this one: acd95fb. I think using a stronger type in UplinkAddressConfig would've forced us to consider this case in the display impl.
Some notes from chatting with @internet-diglett - at a couple spots when inserting switch port settings into the db, we build an in-memory map keyed by the peer address, and we convert None to Ipv4Addr::UNSPECIFIED; e.g.,
I asked if it was possible to have multiple unnumbered peers, and the answer is that it shouldn't be (each port can have at most one unnumbered peer). This ought to be enforced by these db constraints:
However, IIUC, those constraints allow as many as three "unnumbered" peer rows to exist for a given port: 0.0.0.0, ::, and NULL. I'm a little surprised we were using Ipv4Addr::UNSPECIFIED here when we've used Ipv6Addr::UNSPECIFIED in other places, so I'm not sure if this is a purely theoretical potential problem or an actual one we haven't noticed yet.
#10082 introduces stronger Rust types as described in the parent issue, but doesn't tackle any of the database issues. I tried to take a lay of the land of what's going on there, and came up with this.
I think there are four tables that store a BGP peer address that need to be able to represent "unnumbered":
switch_port_settings_bgp_peer_config.addr properties (these also apply to bgp_peer_view.addr, which is a view over this table):
column is NULLable
"unnumbered" is represented as NULL
has separate indices with WHERE addr IS NOT NULL / WHERE addr IS NULL for numbered / unnumbered peers; latter tries to enforce "at most one unnumbered peer per interface"
no CHECK constraints that we don't have 0.0.0.0- or ::-valued columns. If we did, those would go into the "numbered" index (because they're not NULL), but the Rust code that consumes this table would treat them as "unnumbered", allowing us to have up to three "unnumbered" addresses for any given interface
switch_port_settings_bgp_peer_config_communities.addr, switch_port_settings_bgp_peer_config_allow_import.addr, switch_port_settings_bgp_peer_config_allow_export.addr all have the same properties:
column is NOT NULL
column is part of the composite primary key of its table
unnumbered peers are expected to be represented as Ipv4Addr::UNSPECIFIED (0.0.0.0)
datastore methods that operate on this table work on Option<IpNetwork> and convert None -> Ipv4Addr::UNSPECIFIED
no CHECK constraints that we don't have ::-valued columns
if someone called these methods with Some(Ipv6Addr::UNSPECIFIED), I'm not sure what would happen - probably we would insert this (and then could have two unnumbered addresses for a given interface), but it would also have to be queried with Some(Ipv6Addr::UNSPECIFIED) to find it?
I only found one table where we store an UplinkAddressConfig::address, which has to be able to represent "link-local". I'm confused about this one though (the last bullet here):
switch_port_settings_address_config.address
column doesn't have a NOT NULL annotation, but is implicitly NOT NULL because it's part of the table's composite primary key, although a TODO comment in the schema references Establish conventions for network resource primary keys in Nexus #3013 (maybe switching to synthetic id keys)
external API requests create these with arbitrary values, so I think we could have either 0.0.0.0 or ::
I don't actually understand how we could insert unspecified addresses at all: inserts go through address_lot::try_reserve_block(), which looks like it will reject any address that isn't covered by an address lot block. Does that mean if we have link-local uplink addresses, we also have an address lot block that includes the unspecified address? Or do these inserts bypass this check in some way I don't understand?
For the four BGP tables, my high level proposal is "pick one representation for unnumbered, use it consistently, and enforce that the other representations are rejected via CHECK constraints". The obvious options for the representation we pick are NULL, Ipv4Addr::UNSPECIFIED, or Ipv6Addr::UNSPECIFIED. Aesthetically I have a preference for NULL, but that's maybe the most awkward choice to use in practice, because it would require reworking the three tables above in which addr has a NOT NULL constraint because it's part of the primary key of the table. Maybe we should instead use Ipv4Addr::UNSPECIFIED, because that would involve the least db schema migration work and churn? If we did, I think the changes would be:
For the three tables in which addr is already NOT NULL, add a CHECK constraint that rejects Ipv6Addr::UNSPECIFIED. Applying this migration requires that the table not have any rows containing that value; the easiest thing to do where would be DELETE FROM ... WHERE addr = "::", if we don't expect any of those to actually exist. A more complicated thing we could try is "convert :: to 0.0.0.0, but only if there isn't already another row on this interface with an address of 0.0.0.0"?
For switch_port_settings_bgp_peer_config:
Update the table, converting any NULL addrs to 0.0.0.0
Make the column NOT NULL
Add a CHECK constraint rejecting :: (as above, this would need to either delete or convert any existing rows containing ::)
Change the unnumbered / numbered unique indices to split on "addr does or does not equal 0.0.0.0" instead of "addr is or is not NULL"
I'd make a similar high-level proposal for tightening up switch_port_settings_address_config.address, but don't understand enough about how that's working today to list out anything concrete.
I don't actually understand how we could insert unspecified addresses at all: inserts go through address_lot::try_reserve_block(), which looks like it will reject any address that isn't covered by an address lot block. Does that mean if we have link-local uplink addresses, we also have an address lot block that includes the unspecified address? Or do these inserts bypass this check in some way I don't understand?
I could certainly be holding it wrong, but I haven't been able to get past this check in some testing. I tried adding this dummy port to RSS on madrid (which doesn't have a transceiver in switch0/qsfp10):
I made it through timesync via the other, correct ports, but sled-agent to Nexus handoff failed with:
15:42:24.452Z INFO SledAgent (RSS): Failed to handoff to nexus: Error Response: status: 400 Bad Request; headers: {"content-type": "application/json", "x-request-id": "357f9d5c-bd0b-4959-b9d0-6ba5b8f43c7e", "content-length": "127", "date": "Thu, 19 Mar 2026 15:42:24 GMT"}; value: Error { error_code: Some("InvalidRequest"), message: "address not in lot", request_id: "357f9d5c-bd0b-4959-b9d0-6ba5b8f43c7e" }
file = sled-agent/src/rack_setup/service.rs:1073
I also tried to add a link-local address to an already-set-up racklette. The external API takes a non-optional IpAddr, so I tried ::/128, and got the same address lot error:
% oxide system networking addr add --rack $rack --switch switch1 --port qsfp10 --addr ::/128 --lot initial-infra
Error Response: status: 400 Bad Request; headers: {"content-type": "application/json", "x-request-id": "2d90ac26-b707-4584-bec5-f67eb5e495f4", "date": "Thu, 19 Mar 2026 15:23:36 GMT", "content-length": "127"}; value: Error { error_code: Some("InvalidRequest"), message: "address not in lot", request_id: "2d90ac26-b707-4584-bec5-f67eb5e495f4" }
Edit: this works if we have an address lot containing ::. More in #10103.
For the four BGP tables, my high level proposal is "pick one representation for unnumbered, use it consistently, and enforce that the other representations are rejected via CHECK constraints". The obvious options for the representation we pick are NULL, Ipv4Addr::UNSPECIFIED, or Ipv6Addr::UNSPECIFIED. Aesthetically I have a preference for NULL, but that's maybe the most awkward choice to use in practice, because it would require reworking the three tables above in which addr has a NOT NULL constraint because it's part of the primary key of the table.
Chatted about this with @internet-diglett today. His first choice was also to use NULL consistently everywhere, and to do the work to add synthetic id primary keys to the tables that need it (so we can make their addr columns nullable). I'll pursue this path unless I bump into something that makes it untenable.
Activity
jgallagher commentedon Feb 13, 2026
Another spot where this came up in testing #9570; we should make sure whatever we do here would've caught this one: acd95fb. I think using a stronger type in
UplinkAddressConfigwould've forced us to consider this case in the display impl.jgallagher commentedon Feb 13, 2026
Some notes from chatting with @internet-diglett - at a couple spots when inserting switch port settings into the db, we build an in-memory map keyed by the peer address, and we convert
NonetoIpv4Addr::UNSPECIFIED; e.g.,omicron/nexus/db-queries/src/db/datastore/switch_port.rs
Lines 1407 to 1411 in 72e1f85
I asked if it was possible to have multiple unnumbered peers, and the answer is that it shouldn't be (each port can have at most one unnumbered peer). This ought to be enforced by these db constraints:
omicron/schema/crdb/dbinit.sql
Lines 3695 to 3703 in 72e1f85
However, IIUC, those constraints allow as many as three "unnumbered" peer rows to exist for a given port:
0.0.0.0,::, andNULL. I'm a little surprised we were usingIpv4Addr::UNSPECIFIEDhere when we've usedIpv6Addr::UNSPECIFIEDin other places, so I'm not sure if this is a purely theoretical potential problem or an actual one we haven't noticed yet.Use an enum instead of `TEXT` when storing `SwitchLocation` in CRDB (#…
`LldpAdminStatus`: Remove `Display` and `FromStr` impls (#10010)
`UplinkAddressConfig`: Remove `Display` and `FromStr` impls (#10020)
jgallagher commentedon Mar 18, 2026
#10082 introduces stronger Rust types as described in the parent issue, but doesn't tackle any of the database issues. I tried to take a lay of the land of what's going on there, and came up with this.
I think there are four tables that store a BGP peer address that need to be able to represent "unnumbered":
switch_port_settings_bgp_peer_config.addrproperties (these also apply tobgp_peer_view.addr, which is a view over this table):WHERE addr IS NOT NULL/WHERE addr IS NULLfor numbered / unnumbered peers; latter tries to enforce "at most one unnumbered peer per interface"0.0.0.0- or::-valued columns. If we did, those would go into the "numbered" index (because they're not NULL), but the Rust code that consumes this table would treat them as "unnumbered", allowing us to have up to three "unnumbered" addresses for any given interfaceswitch_port_settings_bgp_peer_config_communities.addr,switch_port_settings_bgp_peer_config_allow_import.addr,switch_port_settings_bgp_peer_config_allow_export.addrall have the same properties:Ipv4Addr::UNSPECIFIED(0.0.0.0)Option<IpNetwork>and convertNone->Ipv4Addr::UNSPECIFIED::-valued columnsSome(Ipv6Addr::UNSPECIFIED), I'm not sure what would happen - probably we would insert this (and then could have two unnumbered addresses for a given interface), but it would also have to be queried withSome(Ipv6Addr::UNSPECIFIED)to find it?I only found one table where we store an
UplinkAddressConfig::address, which has to be able to represent "link-local". I'm confused about this one though (the last bullet here):switch_port_settings_address_config.addressNOT NULLannotation, but is implicitlyNOT NULLbecause it's part of the table's composite primary key, although a TODO comment in the schema references Establish conventions for network resource primary keys in Nexus #3013 (maybe switching to syntheticidkeys)Ipv6Addr::UNSPECIFIED(::)0.0.0.0or::address_lot::try_reserve_block(), which looks like it will reject any address that isn't covered by an address lot block. Does that mean if we have link-local uplink addresses, we also have an address lot block that includes the unspecified address? Or do these inserts bypass this check in some way I don't understand?For the four BGP tables, my high level proposal is "pick one representation for
unnumbered, use it consistently, and enforce that the other representations are rejected via CHECK constraints". The obvious options for the representation we pick areNULL,Ipv4Addr::UNSPECIFIED, orIpv6Addr::UNSPECIFIED. Aesthetically I have a preference forNULL, but that's maybe the most awkward choice to use in practice, because it would require reworking the three tables above in whichaddrhas aNOT NULLconstraint because it's part of the primary key of the table. Maybe we should instead useIpv4Addr::UNSPECIFIED, because that would involve the least db schema migration work and churn? If we did, I think the changes would be:addris alreadyNOT NULL, add aCHECKconstraint that rejectsIpv6Addr::UNSPECIFIED. Applying this migration requires that the table not have any rows containing that value; the easiest thing to do where would beDELETE FROM ... WHERE addr = "::", if we don't expect any of those to actually exist. A more complicated thing we could try is "convert::to0.0.0.0, but only if there isn't already another row on this interface with an address of0.0.0.0"?switch_port_settings_bgp_peer_config:NULLaddrs to0.0.0.0NOT NULLCHECKconstraint rejecting::(as above, this would need to either delete or convert any existing rows containing::)0.0.0.0" instead of "addr is or is not NULL"I'd make a similar high-level proposal for tightening up
switch_port_settings_address_config.address, but don't understand enough about how that's working today to list out anything concrete.DataStore: replace `BgpPeerConfig` with `BgpPeerFromDb`
jgallagher commentedon Mar 19, 2026
I could certainly be holding it wrong, but I haven't been able to get past this check in some testing. I tried adding this dummy port to RSS on madrid (which doesn't have a transceiver in switch0/qsfp10):
I made it through timesync via the other, correct ports, but sled-agent to Nexus handoff failed with:
I also tried to add a link-local address to an already-set-up racklette. The external API takes a non-optional
IpAddr, so I tried::/128, and got the same address lot error:Edit: this works if we have an address lot containing
::. More in #10103.jgallagher commentedon Mar 19, 2026
Chatted about this with @internet-diglett today. His first choice was also to use
NULLconsistently everywhere, and to do the work to add syntheticidprimary keys to the tables that need it (so we can make theiraddrcolumns nullable). I'll pursue this path unless I bump into something that makes it untenable.nexus-db-queries: replace `BgpPeerConfig` with `BgpPeerFromDb` (#10086)
Introduce stronger types for link-local addresses and unnumbered peers (
ahl commentedon Apr 19, 2026
How would we imagine this manifesting in the CLI: https://docs.oxide.computer/cli/system/networking/bgp/peer/delete
jgallagher commentedon Apr 20, 2026
I'd propose something like a mutually-exclusive pair of arguments: