diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-10-06 00:48:03 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-06 00:48:03 +0000 |
commit | 59e33bcbd084b65db7ccb870f844db307dadbfc0 (patch) | |
tree | 07ec14d6ec31eae19765c2f76fc2f21fc2a30e03 /src/sys | |
parent | 7e46b95057b0d8e391c3fb72fdec08f3a4689631 (diff) | |
parent | c5739567a36fd37190743a49c3027616ce3d79a7 (diff) | |
download | nix-59e33bcbd084b65db7ccb870f844db307dadbfc0.zip |
Merge #1301
1301: Support vsock on Android as well as Linux. r=asomers a=qwandor-google
This change depends on rust-lang/libc#1905 so can't be merged until that is merged and released.
Co-authored-by: Andrew Walbran <qwandor@google.com>
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/socket/addr.rs | 20 | ||||
-rw-r--r-- | src/sys/socket/mod.rs | 4 |
2 files changed, 12 insertions, 12 deletions
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 24b23102..8784a37b 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -23,7 +23,7 @@ use crate::sys::socket::addr::sys_control::SysControlAddr; target_os = "netbsd", target_os = "openbsd"))] pub use self::datalink::LinkAddr; -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use self::vsock::VsockAddr; /// These constants specify the protocol family to be used @@ -115,7 +115,7 @@ pub enum AddressFamily { Alg = libc::AF_ALG, #[cfg(target_os = "linux")] Nfc = libc::AF_NFC, - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] Vsock = libc::AF_VSOCK, #[cfg(any(target_os = "dragonfly", target_os = "freebsd", @@ -242,7 +242,7 @@ impl AddressFamily { target_os = "netbsd", target_os = "openbsd"))] libc::AF_LINK => Some(AddressFamily::Link), - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] libc::AF_VSOCK => Some(AddressFamily::Vsock), _ => None } @@ -647,7 +647,7 @@ pub enum SockAddr { target_os = "netbsd", target_os = "openbsd"))] Link(LinkAddr), - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] Vsock(VsockAddr), } @@ -675,7 +675,7 @@ impl SockAddr { SysControlAddr::from_name(sockfd, name, unit).map(|a| SockAddr::SysControl(a)) } - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn new_vsock(cid: u32, port: u32) -> SockAddr { SockAddr::Vsock(VsockAddr::new(cid, port)) } @@ -700,7 +700,7 @@ impl SockAddr { target_os = "netbsd", target_os = "openbsd"))] SockAddr::Link(..) => AddressFamily::Link, - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] SockAddr::Vsock(..) => AddressFamily::Vsock, } } @@ -751,7 +751,7 @@ impl SockAddr { Some(SockAddr::Link(ether_addr)) } }, - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] Some(AddressFamily::Vsock) => Some(SockAddr::Vsock( VsockAddr(*(addr as *const libc::sockaddr_vm)))), // Other address families are currently not supported and simply yield a None @@ -837,7 +837,7 @@ impl SockAddr { }, mem::size_of_val(addr) as libc::socklen_t ), - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] SockAddr::Vsock(VsockAddr(ref sa)) => ( // This cast is always allowed in C unsafe { @@ -869,7 +869,7 @@ impl fmt::Display for SockAddr { target_os = "netbsd", target_os = "openbsd"))] SockAddr::Link(ref ether_addr) => ether_addr.fmt(f), - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] SockAddr::Vsock(ref svm) => svm.fmt(f), } } @@ -1204,7 +1204,7 @@ mod datalink { } } -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "android", target_os = "linux"))] pub mod vsock { use crate::sys::socket::addr::AddressFamily; use libc::{sa_family_t, sockaddr_vm}; diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 1f6b179d..31183fe8 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -33,7 +33,7 @@ pub use self::addr::{ pub use crate::sys::socket::addr::netlink::NetlinkAddr; #[cfg(any(target_os = "android", target_os = "linux"))] pub use crate::sys::socket::addr::alg::AlgAddr; -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "android", target_os = "linux"))] pub use crate::sys::socket::addr::vsock::VsockAddr; pub use libc::{ @@ -1737,7 +1737,7 @@ pub fn sockaddr_storage_to_addr( }; Ok(SockAddr::Alg(AlgAddr(salg))) } - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] libc::AF_VSOCK => { use libc::sockaddr_vm; let svm = unsafe { |