diff --git a/networkmanager/src/device.rs b/networkmanager/src/device.rs index ff4c6db..87dae05 100644 --- a/networkmanager/src/device.rs +++ b/networkmanager/src/device.rs @@ -1,7 +1,9 @@ // SPDX-License-Identifier: MPL-2.0 pub mod bluetooth; +pub mod tun; pub mod wired; +pub mod wireguard; pub mod wireless; use crate::{ @@ -11,8 +13,8 @@ use crate::{ active_connection::ActiveConnectionProxy, config::{ip4::Ipv4ConfigProxy, ip6::Ipv6ConfigProxy}, device::{ - bluetooth::BluetoothDeviceProxy, wired::WiredDeviceProxy, - wireless::WirelessDeviceProxy, DeviceProxy, + bluetooth::BluetoothDeviceProxy, tun::TunDeviceProxy, wired::WiredDeviceProxy, + wireguard::WireGuardDeviceProxy, wireless::WirelessDeviceProxy, DeviceProxy, }, enums::{DeviceCapabilities, DeviceState, DeviceType}, }, @@ -80,6 +82,20 @@ impl<'a> Device<'a> { .await? .into(), ))), + DeviceType::TunTap => Ok(Some(SpecificDevice::TunTap( + TunDeviceProxy::builder(self.0.connection()) + .path(self.0.path())? + .build() + .await? + .into(), + ))), + DeviceType::WireGuard => Ok(Some(SpecificDevice::WireGuard( + WireGuardDeviceProxy::builder(self.0.connection()) + .path(self.0.path())? + .build() + .await? + .into(), + ))), _ => Ok(None), } } @@ -127,6 +143,8 @@ pub enum SpecificDevice<'a> { Bluetooth(bluetooth::BluetoothDevice<'a>), Wired(wired::WiredDevice<'a>), Wireless(wireless::WirelessDevice<'a>), + TunTap(tun::TunDevice<'a>), + WireGuard(wireguard::WireGuardDevice<'a>), } impl<'a> SpecificDevice<'a> { @@ -150,4 +168,18 @@ impl<'a> SpecificDevice<'a> { _ => None, } } + + pub fn into_tun(self) -> Option> { + match self { + SpecificDevice::TunTap(device) => Some(device), + _ => None, + } + } + + pub fn into_wireguard(self) -> Option> { + match self { + SpecificDevice::WireGuard(device) => Some(device), + _ => None, + } + } } diff --git a/networkmanager/src/device/tun.rs b/networkmanager/src/device/tun.rs new file mode 100644 index 0000000..b6fb6a3 --- /dev/null +++ b/networkmanager/src/device/tun.rs @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: MPL-2.0 + +use super::Device; +use crate::interface::device::{tun::TunDeviceProxy, DeviceProxy}; +use std::ops::Deref; +use zbus::Result; + +#[derive(Debug)] +pub struct TunDevice<'a>(TunDeviceProxy<'a>); + +impl<'a> TunDevice<'a> { + pub async fn upcast(&'a self) -> Result> { + DeviceProxy::builder(self.0.connection()) + .path(self.0.path())? + .build() + .await + .map(Device::from) + } + + pub async fn owner(&self) -> Result> { + let owner = self.0.owner().await?; + match owner { + -1 => Ok(None), + _ => Ok(u16::try_from(owner).ok()), + } + } +} + +impl<'a> Deref for TunDevice<'a> { + type Target = TunDeviceProxy<'a>; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl<'a> From> for TunDevice<'a> { + fn from(device: TunDeviceProxy<'a>) -> Self { + TunDevice(device) + } +} diff --git a/networkmanager/src/device/wireguard.rs b/networkmanager/src/device/wireguard.rs new file mode 100644 index 0000000..4668cc3 --- /dev/null +++ b/networkmanager/src/device/wireguard.rs @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: MPL-2.0 + +use super::Device; +use crate::interface::device::{wireguard::WireGuardDeviceProxy, DeviceProxy}; +use std::ops::Deref; +use zbus::Result; + +#[derive(Debug)] +pub struct WireGuardDevice<'a>(WireGuardDeviceProxy<'a>); + +impl<'a> WireGuardDevice<'a> { + pub async fn upcast(&'a self) -> Result> { + DeviceProxy::builder(self.0.connection()) + .path(self.0.path())? + .build() + .await + .map(Device::from) + } +} + +impl<'a> Deref for WireGuardDevice<'a> { + type Target = WireGuardDeviceProxy<'a>; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl<'a> From> for WireGuardDevice<'a> { + fn from(device: WireGuardDeviceProxy<'a>) -> Self { + WireGuardDevice(device) + } +} diff --git a/networkmanager/src/interface/device.rs b/networkmanager/src/interface/device.rs index 5164b19..e3fa403 100644 --- a/networkmanager/src/interface/device.rs +++ b/networkmanager/src/interface/device.rs @@ -21,7 +21,9 @@ //! …consequently `zbus-xmlgen` did not generate code for the above interfaces. pub mod bluetooth; +pub mod tun; pub mod wired; +pub mod wireguard; pub mod wireless; use zbus::dbus_proxy; diff --git a/networkmanager/src/interface/device/tun.rs b/networkmanager/src/interface/device/tun.rs new file mode 100644 index 0000000..754e0db --- /dev/null +++ b/networkmanager/src/interface/device/tun.rs @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: MPL-2.0 +//! # DBus interface proxy for: `org.freedesktop.NetworkManager.Device.Tun` +//! +//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data. +//! Source: `org.freedesktop.NetworkManager.Device.Tun.xml`. +//! +//! You may prefer to adapt it, instead of using it verbatim. +//! +//! More information can be found in the +//! [Writing a client proxy](https://dbus.pages.freedesktop.org/zbus/client.html) +//! section of the zbus documentation. +//! + +use zbus::dbus_proxy; + +#[dbus_proxy( + interface = "org.freedesktop.NetworkManager.Device.Tun", + default_service = "org.freedesktop.NetworkManager" +)] +pub trait TunDevice { + /// Group property + #[dbus_proxy(property)] + fn group(&self) -> zbus::Result; + + /// HwAddress property + #[dbus_proxy(property)] + fn hw_address(&self) -> zbus::Result; + + /// Mode property + #[dbus_proxy(property)] + fn mode(&self) -> zbus::Result; + + /// MultiQueue property + #[dbus_proxy(property)] + fn multi_queue(&self) -> zbus::Result; + + /// NoPi property + #[dbus_proxy(property)] + fn no_pi(&self) -> zbus::Result; + + /// Owner property + #[dbus_proxy(property)] + fn owner(&self) -> zbus::Result; + + /// VnetHdr property + #[dbus_proxy(property)] + fn vnet_hdr(&self) -> zbus::Result; +} diff --git a/networkmanager/src/interface/device/wireguard.rs b/networkmanager/src/interface/device/wireguard.rs new file mode 100644 index 0000000..de86c2d --- /dev/null +++ b/networkmanager/src/interface/device/wireguard.rs @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MPL-2.0 +//! # DBus interface proxy for: `org.freedesktop.NetworkManager.Device.WireGuard` +//! +//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data. +//! Source: `org.freedesktop.NetworkManager.Device.WireGuard.xml`. +//! +//! You may prefer to adapt it, instead of using it verbatim. +//! +//! More information can be found in the +//! [Writing a client proxy](https://dbus.pages.freedesktop.org/zbus/client.html) +//! section of the zbus documentation. +//! + +use zbus::dbus_proxy; + +#[dbus_proxy( + interface = "org.freedesktop.NetworkManager.Device.WireGuard", + default_service = "org.freedesktop.NetworkManager" +)] +pub trait WireGuardDevice { + /// FwMark property + #[dbus_proxy(property)] + fn fw_mark(&self) -> zbus::Result; + + /// ListenPort property + #[dbus_proxy(property)] + fn listen_port(&self) -> zbus::Result; + + /// PublicKey property + #[dbus_proxy(property)] + fn public_key(&self) -> zbus::Result>; +} diff --git a/networkmanager/src/interface/enums.rs b/networkmanager/src/interface/enums.rs index a778138..9608077 100644 --- a/networkmanager/src/interface/enums.rs +++ b/networkmanager/src/interface/enums.rs @@ -51,6 +51,8 @@ pub enum DeviceType { Ethernet, Wifi, Bluetooth, + TunTap, + WireGuard, Generic, Other, Unknown, @@ -63,6 +65,8 @@ impl From for DeviceType { 2 => DeviceType::Wifi, 5 => DeviceType::Bluetooth, 14 => DeviceType::Generic, + 16 => DeviceType::TunTap, + 29 => DeviceType::WireGuard, 3..=32 => DeviceType::Other, _ => DeviceType::Unknown, }