Skip to content

Migrate Prefix{,4,6} types to oxnet types#771

Open
ahl wants to merge 34 commits into
mainfrom
die-prefix-die
Open

Migrate Prefix{,4,6} types to oxnet types#771
ahl wants to merge 34 commits into
mainfrom
die-prefix-die

Conversation

@ahl

@ahl ahl commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Migrate the Prefix types to oxnet... although we still need them for backward compatibility with old versions of the API. This required a new version of the mg-admin API so I rolled in a fix for #767 while I was here.

@ahl ahl changed the title Migrae Migrate Prefix{,4,6} types to oxnet types Jun 2, 2026
ahl and others added 15 commits June 2, 2026 01:26
The frozen DDMv2 protocol types (UpdateV2, PullResponseV2,
UnderlayUpdateV2, TunnelUpdateV2, PathVectorV2, TunnelOriginV2,
IpPrefix, Ipv4Prefix, Ipv6Prefix) were scattered across
ddm-api-types, mg-common, and ddm/src/exchange/mod.rs. Collect
them all into a single dedicated module with a module-level
comment making the freeze guarantee impossible to miss.

Add an expectorate snapshot test over the JSON schema for the two
top-level message types (UpdateV2, PullResponseV2) so that any
accidental change to the frozen wire format fails loudly.

Also remove the DDMv1 conversion helpers (UpdateV1 and its From
impls) that are no longer needed.
Fixes: #764

Signed-off-by: Trey Aspelund <trey@oxidecomputer.com>
Comment thread bgp/src/messages.rs Outdated
Comment thread bgp/src/messages.rs Outdated
Comment thread falcon-lab/Cargo.toml Outdated
Comment thread mg-admin-client/src/lib.rs Outdated
}),
derives = [schemars::JsonSchema],
crates = {
"oxnet" = "0.1.5",

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.

This is slick. How do we keep this version in sync with the version that the crate/workspace depends on?

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.

It's not a big deal if it falls behind. All this version says is: don't use types that predate this version. So far, all the oxnet types are 0.1.0. If we start using a new type in oxnet we'll bump the version of the crate and need to bump this as well.

minimize use of yet another Prefix
@ahl ahl force-pushed the die-prefix-die branch from 4fed7f1 to ccbdbf6 Compare June 3, 2026 17:18
@ahl ahl requested a review from jgallagher June 4, 2026 18:28

@ahl ahl left a comment

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.

self-review; changes incoming

ahl and others added 3 commits June 4, 2026 14:06
Resolved conflicts from main's V4_OVER_V6_STATIC_ROUTES (v10) change:
- PREFIX_TO_OXNET renumbered from v10 to v11
- Added v10 to v11 shim for StaticRoute4 (nexthop IpAddr, Prefix4 to Ipv4Net)
- Added static_add/remove_v4_route_v10 endpoint shims in mg-api
- Updated mg-admin-client to use client_common instead of mg_common
- Fixed bgp/src/session.rs DEFAULT_RIB_PRIORITY_BGP import
- Regenerated v11 OpenAPI snapshot

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ahl ahl marked this pull request as ready for review June 5, 2026 00:32
@ahl ahl requested a review from rcgoodfellow June 5, 2026 00:32

@jgallagher jgallagher left a comment

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.

LGTM, mostly just nits. One nontrivial concern is about using new_unchecked() in converting from old API request versions, although switching all of those to TryFrom may be pretty annoying :-/

Comment thread bgp/src/policy.rs
.register_type_with_name::<Ipv4Net>("Prefix4")
.register_fn("within", prefix4_within_rhai)
.register_type_with_name::<Prefix6>("Prefix6")
.register_type_with_name::<oxnet::Ipv6Net>("Prefix6")

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.

Is it fine that the Rust type name doesn't match the Rhai type name anymore? (I have basically 0 context for the Rhai bits.)

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.

I assumed it was better to be backward compatible with (what I assume is) our vast library of rhai scripts. @rcgoodfellow may have thoughts.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The Rhai stuff has not made it into production interfaces yet. I don't think we need to hold this up for Rhai considerations.

Comment thread mg-api-types/versions/src/impls/rdb/prefix.rs Outdated
Comment thread mg-api-types/versions/src/initial/bgp/messages.rs Outdated
Comment thread mg-lower/src/dendrite.rs
Comment thread mgd/src/validation.rs
fn any_ipv4_prefix_strategy() -> impl Strategy<Value = Prefix4> {
fn any_ipv4_prefix_strategy() -> impl Strategy<Value = Ipv4Net> {
(any::<u32>(), 0u8..=32u8).prop_map(|(addr_bits, length)| {
// Don't use new() - we want to test both normalized and unnormalized

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'd keep this comment (and the matching ipv6 one on line 341). It's a little repetitious with the comment on the function, but this is weird enough it seems worth it

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.

The old comment had implicit in there that new would truncate/normalize the Prefix. IpNet does not do that so I thought the comment wasn't applicable.

Comment thread mg-api/src/lib.rs Outdated
asn,
prefixes: prefixes
.into_iter()
.map(|p| Ipv6Net::new_unchecked(p.value, p.length))

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.

Is new_unchecked safe here? I don't think the old Prefix* types validated their length

Edit: Same question in a bunch of other From<OldType> for NewType conversions

@ahl ahl Jun 5, 2026

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.

I believe so. It's an invariant of the Prefix* types that the length is valid; do you think it would be better to new().unwrap()?

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.

It's an invariant of the Prefix* types that the length is valid

Is it? It doesn't look like they enforce any invariants; the fields are pub and they derive Deserialize, so I think we could get any u8 value here, right?

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.

Yeah. I should have stated this differently: this use of new_unchecked preserves existing behavior. I could unwrap() or we could migrate to TryFrom. I'm not sure what would be best.

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.

Ahh, gotcha. In principle I vote for TryFrom: we're getting outside data that may not be valid, and allowing construction of an IpNet (which itself does enforce invariants, as long as nobody bypasses them with new_unchecked()) that could have an invalid length seems pretty bad?

If the TryFroms are atrocious in practice, I could see an argument for new().unwrap() under the claim that mgd only gets requests from other omicron services, which should be using progenitor clients, which means they should only be sending valid IpNets.

@rcgoodfellow rcgoodfellow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Broadly looks good to me. Since this has a bunch of API surface change associated with it let's get an associated omicron PR up to see how that goes.

Comment thread mg-api-types/versions/src/initial/rdb/prefix.rs
@ahl

ahl commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

@rcgoodfellow seems to work: oxidecomputer/omicron#10558

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.

4 participants