Skip to content

Commit

Permalink
Restrict vsock for unix only
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Mar 15, 2024
1 parent 2a18834 commit 5023803
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 6 additions & 6 deletions io/zenoh-link/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ use zenoh_link_unixpipe::{
LinkManagerUnicastPipe, UnixPipeConfigurator, UnixPipeLocatorInspector, UNIXPIPE_LOCATOR_PREFIX,
};

#[cfg(feature = "transport_vsock")]
#[cfg(all(feature = "transport_vsock", target_family = "unix"))]
pub use zenoh_link_vsock as vsock;
#[cfg(feature = "transport_vsock")]
#[cfg(all(feature = "transport_vsock", target_family = "unix"))]
use zenoh_link_vsock::{LinkManagerUnicastVsock, VsockLocatorInspector, VSOCK_LOCATOR_PREFIX};

pub use zenoh_link_commons::*;
Expand All @@ -97,7 +97,7 @@ pub const PROTOCOLS: &[&str] = &[
serial::SERIAL_LOCATOR_PREFIX,
#[cfg(feature = "transport_unixpipe")]
unixpipe::UNIXPIPE_LOCATOR_PREFIX,
#[cfg(feature = "transport_vsock")]
#[cfg(all(feature = "transport_vsock", target_family = "unix"))]
vsock::VSOCK_LOCATOR_PREFIX,
];

Expand All @@ -119,7 +119,7 @@ pub struct LocatorInspector {
serial_inspector: SerialLocatorInspector,
#[cfg(feature = "transport_unixpipe")]
unixpipe_inspector: UnixPipeLocatorInspector,
#[cfg(feature = "transport_vsock")]
#[cfg(all(feature = "transport_vsock", target_family = "unix"))]
vsock_inspector: VsockLocatorInspector,
}
impl LocatorInspector {
Expand All @@ -146,7 +146,7 @@ impl LocatorInspector {
SERIAL_LOCATOR_PREFIX => self.serial_inspector.is_multicast(locator).await,
#[cfg(feature = "transport_unixpipe")]
UNIXPIPE_LOCATOR_PREFIX => self.unixpipe_inspector.is_multicast(locator).await,
#[cfg(feature = "transport_vsock")]
#[cfg(all(feature = "transport_vsock", target_family = "unix"))]
VSOCK_LOCATOR_PREFIX => self.vsock_inspector.is_multicast(locator).await,
_ => bail!("Unsupported protocol: {}.", protocol),
}
Expand Down Expand Up @@ -237,7 +237,7 @@ impl LinkManagerBuilderUnicast {
UNIXPIPE_LOCATOR_PREFIX => {
Ok(std::sync::Arc::new(LinkManagerUnicastPipe::new(_manager)))
}
#[cfg(feature = "transport_vsock")]
#[cfg(all(feature = "transport_vsock", target_family = "unix"))]
VSOCK_LOCATOR_PREFIX => Ok(std::sync::Arc::new(LinkManagerUnicastVsock::new(_manager))),
_ => bail!("Unicast not supported for {} protocol", protocol),
}
Expand Down
10 changes: 7 additions & 3 deletions io/zenoh-links/zenoh-link-vsock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@
//! [Click here for Zenoh's documentation](../zenoh/index.html)
use async_trait::async_trait;
use libc::VMADDR_PORT_ANY;
use tokio_vsock::{
VsockAddr, VMADDR_CID_ANY, VMADDR_CID_HOST, VMADDR_CID_HYPERVISOR, VMADDR_CID_LOCAL,
};
use zenoh_core::zconfigurable;
use zenoh_link_commons::LocatorInspector;
use zenoh_protocol::core::{endpoint::Address, Locator};
use zenoh_result::{bail, ZResult};

#[cfg(target_family = "unix")]
use tokio_vsock::{
VsockAddr, VMADDR_CID_ANY, VMADDR_CID_HOST, VMADDR_CID_HYPERVISOR, VMADDR_CID_LOCAL,
};

#[cfg(target_family = "unix")]
mod unicast;
#[cfg(target_family = "unix")]
pub use unicast::*;

pub const VSOCK_LOCATOR_PREFIX: &str = "vsock";
Expand Down

0 comments on commit 5023803

Please sign in to comment.