openvpn3_rs/proxy/
netcfg.rs

1//! # DBus interface proxy for: `net.openvpn.v3.netcfg`
2//!
3//! This code was generated by `zbus-xmlgen` `3.1.0` from DBus introspection data.
4//! Source: `net.openvpn.v3.netcfg.xml`.
5
6use self::constants::*;
7use super::netcfg_node::{NetCfgNodeProxy, NetCfgNodeProxyBlocking};
8use crate::log::constants::{LogCategory, LogGroup, LogLevel};
9use enumflags2::BitFlags;
10use zbus::dbus_proxy;
11
12/// Network Configuration Service
13///
14/// [OpenVPN Documentation](https://github.com/OpenVPN/openvpn3-linux/blob/master/docs/dbus/dbus-service-net.openvpn.v3.netcfg.md)
15#[dbus_proxy(
16    interface = "net.openvpn.v3.netcfg",
17    default_service = "net.openvpn.v3.netcfg",
18    default_path = "/net/openvpn/v3/netcfg"
19)]
20trait NetCfg {
21    /// Cleanup method
22    ///
23    /// This method will remove/cleanup any resources still held by the calling PID.
24    fn cleanup(&self) -> zbus::Result<()>;
25
26    /// CreateVirtualInterface method
27    ///
28    /// Create a virtual interface and return the object path of the new interface.
29    ///
30    /// # Arguments
31    ///
32    /// * `device_name` - A user friendly name for the device, will be part of device_path.
33    ///
34    /// # Returns
35    ///
36    /// A unique D-Bus object path for create device.
37    #[dbus_proxy(object = "NetCfgNode")]
38    fn create_virtual_interface(&self, device_name: &str);
39
40    /// DcoAvailable method
41    ///
42    /// This method is called by the VPN client backend to check if the DCO kernel module is available. It it called by through the tun_builder interface, to query the status during instantiation of the transport used to establish the tunnel.
43    ///
44    /// # Returns
45    ///
46    /// True if the DCO kernel module is available and loadable.
47    fn dco_available(&self) -> zbus::Result<bool>;
48
49    /// FetchInterfaceList method
50    ///
51    /// This method will return an array of object paths to virtual interfaces the caller is granted access to.
52    ///
53    /// # Returns
54    ///
55    /// An array of object paths to accessible virtual interfaces.
56    fn fetch_interface_list(&self) -> zbus::Result<Vec<zbus::zvariant::OwnedObjectPath>>;
57
58    /// NotificationSubscribe method
59    ///
60    /// A service which wants to respond to various network change activities triggered by OpenVPN can subscribe to the `net.openvpn.v3.netcfg.NetworkChange` signal. Such subscriptions are handled by calling this method.
61    ///
62    /// # Arguments
63    ///
64    /// `filter` - A filter mask defining which NetworkChange events to subscribe to. Valid values are `1` to `2047`.
65    fn notification_subscribe(&self, filter: BitFlags<NetCfgChangeType>) -> zbus::Result<()>;
66
67    /// NotificationSubscriberList method
68    ///
69    /// Retrieves a list of all active subscriptions together with their filter mask.
70    ///
71    /// This method is restricted to the *root* user.
72    ///
73    /// # Returns
74    ///
75    /// An array of tuples with the subscribers unique D-Bus name and the attached filter mask.
76    fn notification_subscriber_list(
77        &self,
78    ) -> zbus::Result<Vec<(String, BitFlags<NetCfgChangeType>)>>;
79
80    /// NotificationUnsubscribe method
81    ///
82    /// Any services who has subscribed to NetworkChange signals must unsubscribe before disconnecting from the D-Bus. This is done by calling this method.
83    ///
84    /// The subscriber argument this method needs should always be an empty string. Processes running as *root* can send the the unique D-Bus name to forcefully unsubscribe a specific subscription.
85    ///
86    /// # Arguments
87    ///
88    /// * `optional_subscriber` - This should be empty for non-root users. Must otherwise contain a valid unique D-Bus name.
89    fn notification_unsubscribe(&self, optional_subscriber: &str) -> zbus::Result<()>;
90
91    /// ProtectSocket method
92    ///
93    /// This method is called by the service client to signal that a socket needs to be protected from being routed over the VPN to avoid routing loops. The method of how this is actually implemented can be controlled by command line arguments to the netcfg service process.
94    ///
95    /// # Arguments
96    ///
97    /// * File descriptor of the socket to protect (Unix file descriptors that are passed are not in the D-Bus method signature). Only the first provided fd is being processed.
98    /// * `remote`- The remote host this socket is connected to.
99    /// * `ipv6`- ?
100    /// * `device_path`- If an tun device is already opened, ignore routes from this device
101    fn protect_socket(
102        &self,
103        remote: &str,
104        ipv6: bool,
105        device_path: &zbus::zvariant::ObjectPath<'_>,
106    ) -> zbus::Result<bool>;
107
108    /// Log signal
109    ///
110    /// Whenever the network configuration service needs to log something, it issues a Log signal which carries a log group, log verbosity level and a string with the log message itself.
111    #[dbus_proxy(signal)]
112    fn log(&self, group: LogGroup, category: LogCategory, message: &str) -> zbus::Result<()>;
113
114    /// Filename of the config file netcfg has parsed at start-up.
115    #[dbus_proxy(property, name = "config_file")]
116    fn config_file(&self) -> zbus::Result<String>;
117
118    /// DNS search domains in used, pushed from all VPN sessions.
119    #[dbus_proxy(property, name = "global_dns_search")]
120    fn global_dns_search(&self) -> zbus::Result<u32>;
121
122    /// DNS servers in use, pushed from all VPN sessions.
123    #[dbus_proxy(property, name = "global_dns_servers")]
124    fn global_dns_servers(&self) -> zbus::Result<u32>;
125
126    /// Controls the log verbosity of messages intended to be proxied to the user frontend.
127    ///
128    /// **Note:** Not currently implemented.
129    #[dbus_proxy(property, name = "log_level")]
130    fn log_level(&self) -> zbus::Result<LogLevel>;
131    fn set_log_level(&self, value: LogLevel) -> zbus::Result<()>;
132
133    /// Version information about the running service.
134    #[dbus_proxy(property, name = "version")]
135    fn version(&self) -> zbus::Result<String>;
136}
137
138pub mod constants {
139    use std::fmt;
140
141    use enumflags2::bitflags;
142    use serde::{Deserialize, Serialize};
143    use static_assertions::assert_impl_all;
144    use zbus::zvariant::Type;
145
146    /// Network Configuration Change Type
147    ///
148    /// Source: openvpn3-linux/src/netcfg/netcfg-changetype.hpp
149    #[bitflags]
150    #[repr(u16)]
151    #[derive(Type, Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)]
152    pub enum NetCfgChangeType {
153        ///	A new virtual interface has been added on the system
154        DeviceAdded = 0x001,
155        ///	A virtual interface has been removed from the system
156        DeviceRemoved = 0x002,
157        ///	An IP address has been added to a virtual interface
158        IpaddrAdded = 0x004,
159        ///	An IP address has been removed from the virtual interface
160        IpaddrRemoved = 0x008,
161        ///	A route has been added to the routing table, related to this interface
162        RouteAdded = 0x010,
163        ///	A route has been remove from the routing table, related to this interface
164        RouteRemoved = 0x020,
165        ///	A route has been excluded from the routing table, related to this interface
166        RouteExcluded = 0x040,
167        ///	A DNS server has been added to the DNS configuration
168        DnsServerAdded = 0x080,
169        ///	A DNS server has been removed from the DNS configuration
170        DnsServerRemoved = 0x100,
171        ///	A DNS search domain has been added to the DNS configuration
172        DnsSearchAdded = 0x200,
173        ///	A DNS search domain has been removed from the DNS configuration
174        DnsSearchRemoved = 0x400,
175    }
176
177    assert_impl_all!(NetCfgChangeType: Send, Sync, Unpin);
178
179    impl fmt::Display for NetCfgChangeType {
180        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
181            match self {
182                Self::DeviceAdded => write!(f, "Device Added"),
183                Self::DeviceRemoved => write!(f, "Device Removed"),
184                Self::IpaddrAdded => write!(f, "IP Address Added"),
185                Self::IpaddrRemoved => write!(f, "IP Address Removed"),
186                Self::RouteAdded => write!(f, "Route Added"),
187                Self::RouteRemoved => write!(f, "Route Removed"),
188                Self::RouteExcluded => write!(f, "Route Excluded"),
189                Self::DnsServerAdded => write!(f, "DNS Server Added"),
190                Self::DnsServerRemoved => write!(f, "DNS Server Removed"),
191                Self::DnsSearchAdded => write!(f, "DNS Search Added"),
192                Self::DnsSearchRemoved => write!(f, "DNS Search Removed"),
193            }
194        }
195    }
196}