Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use oxnet::{ IpNet, Ipv4Net, Ipv6Net } #5810

Merged
merged 24 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ omicron-certificates = { path = "certificates" }
omicron-passwords = { path = "passwords" }
omicron-workspace-hack = "0.1.0"
oxlog = { path = "dev-tools/oxlog" }
oxnet = { git = "https://github.com/oxidecomputer/oxnet", branch = "main" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we relying on the lockfile to keep this in sync? I usually don't like relying on a branch directly. Can we give it a 1.0 version tag or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now; I want to get to something resembling stable in oxnet, publish to crates.io and depend on that. We have several other branch = main deps

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, works for me.

nexus-test-interface = { path = "nexus/test-interface" }
nexus-test-utils-macros = { path = "nexus/test-utils-macros" }
nexus-test-utils = { path = "nexus/test-utils" }
Expand Down
2 changes: 1 addition & 1 deletion clients/ddm-admin-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Client {
let me = self.clone();
tokio::spawn(async move {
let prefix =
Ipv6Prefix { addr: address.net().network(), len: SLED_PREFIX };
Ipv6Prefix { addr: address.net().prefix(), len: SLED_PREFIX };
retry_notify(retry_policy_internal_service_aggressive(), || async {
info!(
me.log, "Sending prefix to ddmd for advertisement";
Expand Down
1 change: 1 addition & 0 deletions clients/nexus-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ipnetwork.workspace = true
nexus-types.workspace = true
omicron-common.workspace = true
omicron-passwords.workspace = true
oxnet.workspace = true
progenitor.workspace = true
regress.workspace = true
reqwest = { workspace = true, features = ["rustls-tls", "stream"] }
Expand Down
20 changes: 7 additions & 13 deletions clients/nexus-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,33 +419,27 @@ impl TryFrom<types::ProducerEndpoint>
}
}

impl TryFrom<&omicron_common::api::external::Ipv4Net> for types::Ipv4Net {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we planning to get rid of the generated types versions at some point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes; going to be rooting that out here and from other places like dendrite and propolis

Copy link
Contributor

Choose a reason for hiding this comment

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

Great!

impl TryFrom<&oxnet::Ipv4Net> for types::Ipv4Net {
type Error = String;

fn try_from(
net: &omicron_common::api::external::Ipv4Net,
) -> Result<Self, Self::Error> {
fn try_from(net: &oxnet::Ipv4Net) -> Result<Self, Self::Error> {
types::Ipv4Net::try_from(net.to_string()).map_err(|e| e.to_string())
}
}

impl TryFrom<&omicron_common::api::external::Ipv6Net> for types::Ipv6Net {
impl TryFrom<&oxnet::Ipv6Net> for types::Ipv6Net {
type Error = String;

fn try_from(
net: &omicron_common::api::external::Ipv6Net,
) -> Result<Self, Self::Error> {
fn try_from(net: &oxnet::Ipv6Net) -> Result<Self, Self::Error> {
types::Ipv6Net::try_from(net.to_string()).map_err(|e| e.to_string())
}
}

impl TryFrom<&omicron_common::api::external::IpNet> for types::IpNet {
impl TryFrom<&oxnet::IpNet> for types::IpNet {
type Error = String;

fn try_from(
net: &omicron_common::api::external::IpNet,
) -> Result<Self, Self::Error> {
use omicron_common::api::external::IpNet;
fn try_from(net: &oxnet::IpNet) -> Result<Self, Self::Error> {
use oxnet::IpNet;
match net {
IpNet::V4(v4) => types::Ipv4Net::try_from(v4).map(types::IpNet::V4),
IpNet::V6(v6) => types::Ipv6Net::try_from(v6).map(types::IpNet::V6),
Expand Down
1 change: 1 addition & 0 deletions clients/sled-agent-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ slog.workspace = true
uuid.workspace = true
omicron-workspace-hack.workspace = true
omicron-uuid-kinds.workspace = true
oxnet.workspace = true
serde_json.workspace = true
35 changes: 23 additions & 12 deletions clients/sled-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,24 +413,23 @@ impl From<types::DiskState> for omicron_common::api::external::DiskState {
}
}

impl From<omicron_common::api::external::Ipv4Net> for types::Ipv4Net {
fn from(n: omicron_common::api::external::Ipv4Net) -> Self {
impl From<oxnet::Ipv4Net> for types::Ipv4Net {
fn from(n: oxnet::Ipv4Net) -> Self {
Self::try_from(n.to_string()).unwrap_or_else(|e| panic!("{}: {}", n, e))
}
}

impl From<omicron_common::api::external::Ipv6Net> for types::Ipv6Net {
fn from(n: omicron_common::api::external::Ipv6Net) -> Self {
impl From<oxnet::Ipv6Net> for types::Ipv6Net {
fn from(n: oxnet::Ipv6Net) -> Self {
Self::try_from(n.to_string()).unwrap_or_else(|e| panic!("{}: {}", n, e))
}
}

impl From<omicron_common::api::external::IpNet> for types::IpNet {
fn from(s: omicron_common::api::external::IpNet) -> Self {
use omicron_common::api::external::IpNet;
impl From<oxnet::IpNet> for types::IpNet {
fn from(s: oxnet::IpNet) -> Self {
match s {
IpNet::V4(v4) => Self::V4(v4.into()),
IpNet::V6(v6) => Self::V6(v6.into()),
oxnet::IpNet::V4(v4) => Self::V4(v4.into()),
oxnet::IpNet::V6(v6) => Self::V6(v6.into()),
}
}
}
Expand All @@ -441,14 +440,20 @@ impl From<ipnetwork::Ipv4Network> for types::Ipv4Net {
}
}

impl From<types::Ipv4Net> for ipnetwork::Ipv4Network {
impl From<ipnetwork::Ipv4Network> for types::Ipv4Network {
fn from(n: ipnetwork::Ipv4Network) -> Self {
Self::try_from(n.to_string()).unwrap_or_else(|e| panic!("{}: {}", n, e))
}
}

impl From<types::Ipv4Net> for oxnet::Ipv4Net {
fn from(n: types::Ipv4Net) -> Self {
n.parse().unwrap()
}
}

impl From<ipnetwork::Ipv4Network> for types::Ipv4Network {
fn from(n: ipnetwork::Ipv4Network) -> Self {
impl From<oxnet::Ipv4Net> for types::Ipv4Network {
fn from(n: oxnet::Ipv4Net) -> Self {
Self::try_from(n.to_string()).unwrap_or_else(|e| panic!("{}: {}", n, e))
}
}
Expand Down Expand Up @@ -484,6 +489,12 @@ impl From<types::IpNet> for ipnetwork::IpNetwork {
}
}

impl From<types::Ipv4Net> for ipnetwork::Ipv4Network {
fn from(n: types::Ipv4Net) -> Self {
n.parse().unwrap()
}
}

impl From<std::net::Ipv4Addr> for types::Ipv4Net {
fn from(n: std::net::Ipv4Addr) -> Self {
Self::try_from(format!("{n}/32"))
Expand Down
1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ipnetwork.workspace = true
macaddr.workspace = true
mg-admin-client.workspace = true
omicron-uuid-kinds.workspace = true
oxnet.workspace = true
proptest = { workspace = true, optional = true }
rand.workspace = true
reqwest = { workspace = true, features = ["rustls-tls", "stream"] }
Expand Down
Loading
Loading