Skip to content

Commit

Permalink
use oxnet::{ IpNet, Ipv4Net, Ipv6Net } (#5810)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahl authored May 24, 2024
1 parent 4090983 commit 8975897
Show file tree
Hide file tree
Showing 84 changed files with 666 additions and 1,015 deletions.
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" }
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 {
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

0 comments on commit 8975897

Please sign in to comment.