Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions orb-connd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ p256.workspace = true
prelude.workspace = true
rand.workspace = true
regex.workspace = true
reqwest.workspace = true
nix = { workspace = true, features = ["net"] }
rustix = { workspace = true, features = ["process"] }
rusty_network_manager = "0.6.0"
rkyv = { workspace = true, features = ["validation"] }
Expand All @@ -58,6 +60,7 @@ tracing.workspace = true
uuid = { workspace = true, features = ["v4"] }
uzers = "0.12.0"
zbus.workspace = true
zbus_systemd = { workspace = true, features = ["resolve1"] }
zenorb.workspace = true

[dev-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions orb-connd/src/connectivity_daemon.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::modem_manager::ModemManager;
use crate::network_manager::NetworkManager;
use crate::resolved::Resolved;
use crate::service::{ConndService, ProfileStorage};
use crate::statsd::StatsdClient;
use crate::{reporters, OrbCapabilities, Tasks};
Expand All @@ -17,6 +18,7 @@ pub async fn program(
sysfs: impl AsRef<Path>,
usr_persistent: impl AsRef<Path>,
network_manager: NetworkManager,
resolved: Resolved,
session_bus: zbus::Connection,
os_release: OrbOsRelease,
statsd_client: impl StatsdClient,
Expand Down Expand Up @@ -57,6 +59,7 @@ pub async fn program(
tasks.extend(
reporters::spawn(
network_manager,
resolved,
session_bus,
modem_manager,
statsd_client,
Expand Down
1 change: 1 addition & 0 deletions orb-connd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod connectivity_daemon;
pub mod modem_manager;
pub mod network_manager;
pub mod reporters;
pub mod resolved;
pub mod secure_storage;
pub mod service;
pub mod statsd;
Expand Down
6 changes: 5 additions & 1 deletion orb-connd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use orb_connd::{
connectivity_daemon,
modem_manager::cli::ModemManagerCli,
network_manager::NetworkManager,
resolved::Resolved,
secure_storage::{self, ConndStorageScopes, SecureStorage},
service::ProfileStorage,
statsd::dd::DogstatsdClient,
Expand Down Expand Up @@ -74,10 +75,12 @@ fn connectivity_daemon() -> Result<()> {

rt.block_on(async {
let os_release = OrbOsRelease::read().await?;
let system_bus = zbus::Connection::system().await?;
let nm = NetworkManager::new(
zbus::Connection::system().await?,
system_bus.clone(),
WpaCli::new(os_release.orb_os_platform_type),
);
let resolved = Resolved::new(system_bus);

let cancel_token = CancellationToken::new();
let profile_storage = match os_release.orb_os_platform_type {
Expand All @@ -103,6 +106,7 @@ fn connectivity_daemon() -> Result<()> {
.sysfs("/sys")
.usr_persistent("/usr/persistent")
.network_manager(nm)
.resolved(resolved)
.session_bus(zbus::Connection::session().await?)
.os_release(os_release)
.statsd_client(DogstatsdClient::new())
Expand Down
66 changes: 63 additions & 3 deletions orb-connd/src/network_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use rusty_network_manager::{
NM80211Mode, NMActiveConnectionState, NMConnectivityState, NMDeviceType,
NMState,
},
AccessPointProxy, ActiveProxy, DeviceProxy, NM80211ApFlags, NM80211ApSecurityFlags,
NetworkManagerProxy, SettingsConnectionProxy, SettingsProxy, WirelessProxy,
AccessPointProxy, ActiveProxy, DeviceProxy, IP4ConfigProxy, IP6ConfigProxy,
NM80211ApFlags, NM80211ApSecurityFlags, NetworkManagerProxy,
SettingsConnectionProxy, SettingsProxy, WirelessProxy,
};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, sync::Arc, time::Duration};
Expand Down Expand Up @@ -454,15 +455,70 @@ impl NetworkManager {
let mut ifaces = Vec::with_capacity(dev_paths.len());
for dp in dev_paths {
let dev = DeviceProxy::new_from_path(dp, &self.conn).await?;
ifaces.push(dev.interface().await?);
let iface = match dev.ip_interface().await {
Ok(ip) if !ip.is_empty() => ip,
_ => dev.interface().await?,
};
ifaces.push(iface);
}

let (ipv4_gateway, ipv4_dns) = match ac.ip4_config().await {
Ok(ip4_path) if ip4_path.as_str() != "/" => {
let ip4 =
IP4ConfigProxy::new_from_path(ip4_path, &self.conn).await?;

let gateway = ip4.gateway().await.ok().filter(|g| !g.is_empty());

let dns = ip4
.nameserver_data()
.await
.unwrap_or_default()
.into_iter()
.filter_map(|entry| {
let val = entry.get("address")?;
let s: &str = val.downcast_ref().ok()?;
Some(s.to_string())
})
.collect();

(gateway, dns)
}
_ => (None, Vec::new()),
};

let (ipv6_gateway, ipv6_dns) = match ac.ip6_config().await {
Ok(ip6_path) if ip6_path.as_str() != "/" => {
let ip6 =
IP6ConfigProxy::new_from_path(ip6_path, &self.conn).await?;

let gateway = ip6.gateway().await.ok().filter(|g| !g.is_empty());

let dns = ip6
.nameservers()
.await
.unwrap_or_default()
.into_iter()
.filter_map(|bytes| {
let octets: [u8; 16] = bytes.try_into().ok()?;
Some(std::net::Ipv6Addr::from(octets).to_string())
})
.collect();

(gateway, dns)
}
_ => (None, Vec::new()),
};

out.push(ActiveConn {
id,
uuid,
state,
devices: ifaces,
conn_path,
ipv4_gateway,
ipv4_dns,
ipv6_gateway,
ipv6_dns,
});
}

Expand Down Expand Up @@ -960,6 +1016,10 @@ pub struct ActiveConn {
pub state: ActiveConnState,
pub devices: Vec<String>,
pub conn_path: OwnedObjectPath,
pub ipv4_gateway: Option<String>,
pub ipv4_dns: Vec<String>,
pub ipv6_gateway: Option<String>,
pub ipv6_dns: Vec<String>,
}

#[cfg(test)]
Expand Down
5 changes: 4 additions & 1 deletion orb-connd/src/reporters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
modem_manager::ModemManager,
network_manager::NetworkManager,
reporters::modem_status::ModemStatus,
resolved::Resolved,
statsd::StatsdClient,
utils::{retry_for, State},
OrbCapabilities, Tasks,
Expand All @@ -23,8 +24,10 @@ pub mod modem_status;
pub mod net_changed_reporter;
pub mod net_stats;

#[allow(clippy::too_many_arguments)]
pub async fn spawn(
nm: NetworkManager,
resolved: Resolved,
session_bus: zbus::Connection,
modem_manager: Arc<dyn ModemManager>,
statsd_client: impl StatsdClient,
Expand All @@ -43,7 +46,7 @@ pub async fn spawn(
session_bus.clone(),
Duration::from_secs(30),
),
net_changed_reporter::spawn(nm, zsender),
net_changed_reporter::spawn(nm, resolved, zsender),
]);

if let OrbCapabilities::CellularAndWifi = cap {
Expand Down
Loading
Loading