Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing wifi device data #1032

Open
wants to merge 2 commits into
base: beta21
Choose a base branch
from
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
4 changes: 0 additions & 4 deletions althea_kernel_interface/src/exit_server_tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ impl dyn KernelInterface {
fn test_iproute_parsing() {
let str = "fbad::/64,feee::/64";

if str.is_empty() {
return;
}

let ipv6_list: Vec<&str> = str.split(',').collect();

for ip in ipv6_list {
Expand Down
102 changes: 66 additions & 36 deletions althea_kernel_interface/src/hardware_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ use std::io::BufRead;
use std::io::BufReader;
use std::process::Command;
use std::process::Stdio;
use std::str::from_utf8;
use std::time::Duration;
use std::u64;

/// Gets the load average and memory of the system from /proc should be plenty
/// efficient and safe to run. Requires the device name to be passed in because
Expand Down Expand Up @@ -404,44 +402,42 @@ fn get_conntrack_info() -> Option<ConntrackInfo> {

/// Device names are in the form wlan0, wlan1 etc
fn parse_wifi_device_names() -> Result<Vec<String>, Error> {
// We parse /etc/config/wireless which is an openwrt config. We return an error if not openwrt
if KI.is_openwrt() {
let mut ret = Vec::new();

let lines = KI.run_command("uci", &["show", "wireless"])?;
let lines: Vec<&str> = from_utf8(&lines.stdout)?.lines().collect();

// trying to get lines 'wireless.default_radio1.ifname='wlan1''
for line in lines {
if line.contains("wireless.default_radio") && line.contains("device") {
let name = match line.split('=').collect::<Vec<&str>>().last() {
Some(a) => *a,
None => {
error!("Cannot parse wifi string {}", line);
continue;
}
};
let name = name.replace('\'', "");
ret.push(name)
// Call iw dev to get a list of wifi interfaces
let res = Command::new("iw")
.args(["dev"])
.stdout(Stdio::piped())
.output();
match res {
Ok(a) => match String::from_utf8(a.stdout) {
Ok(a) => Ok(extract_wifi_ifnames(&a)),
Err(e) => {
error!("Unable to parse iw dev output {:?}", e);
Err(Error::FromUtf8Error)
}
}
Ok(ret)
} else {
// Fallback to /proc/ parsing if no openwrt
let mut ret = Vec::new();
let path = "/proc/net/wireless";
let lines = get_lines(path)?;
for line in lines {
if line.contains(':') {
let name: Vec<&str> = line.split(':').collect();
let name = name[0];
let name = name.replace(' ', "");
ret.push(name.to_string());
},
Err(e) => Err(Error::ParseError(e.to_string())),
}
}

fn extract_wifi_ifnames(dev_output: &str) -> Vec<String> {
let mut ret: Vec<String> = vec![];

// we are looking for the line "Interface [ifname]"
let mut iter = dev_output.split_ascii_whitespace();
loop {
let to_struct = iter.next();
if let Some(to_struct) = to_struct {
if to_struct == "Interface" {
let ifname = iter.next();
if let Some(ifname) = ifname {
ret.push(ifname.to_string());
}
}
} else {
break;
}

Ok(ret)
}
ret
}

fn get_wifi_survey_info(dev: &str) -> Vec<WifiSurveyData> {
Expand Down Expand Up @@ -707,4 +703,38 @@ mod test {
.count()
);
}

#[test]
fn test_parse_wifi_device_names() {
// sample output from iw dev
let iw_dev_output = "phy#1
Interface wlan1
ifindex 12
wdev 0x100000002
addr 12:23:34:45:56:67
ssid altheahome-5
type AP
channel 36 (5180 MHz), width: 80 MHz, center1: 5210 MHz
txpower 23.00 dBm
multicast TXQ:
qsz-byt qsz-pkt flows drops marks overlmt hashcol tx-bytes tx-packets
0 0 3991833 0 0 0 0 1112061710 3991837
phy#0
Interface wlan0
ifindex 11
wdev 0x2
addr 76:65:54:43:32:21
ssid altheahome-2.4
type AP
channel 11 (2462 MHz), width: 20 MHz, center1: 2462 MHz
txpower 30.00 dBm
multicast TXQ:
qsz-byt qsz-pkt flows drops marks overlmt hashcol tx-bytes tx-packets
0 0 3991759 0 0 0 3 1112047714 3991791
";
let res = extract_wifi_ifnames(iw_dev_output);
assert!(res.len() == 2);
assert!(res.contains(&"wlan0".to_string()));
assert!(res.contains(&"wlan1".to_string()));
}
}
11 changes: 6 additions & 5 deletions althea_kernel_interface/src/ip_route.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::KernelInterface;
use crate::KernelInterfaceError as Error;
use althea_types::FromStr;
use std::fmt::Display;
use std::fmt::Write as _;
use std::net::IpAddr;

Expand Down Expand Up @@ -150,16 +151,16 @@ impl FromStr for IpRoute {
}
}

impl ToString for IpRoute {
impl Display for IpRoute {
/// Converts this route object into a string that is a ready-to-run command
/// for applying this route, once appended 'ip route add'
fn to_string(&self) -> String {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.clone() {
IpRoute::DefaultRoute(DefaultRoute { via, nic, src, .. }) => {
if let Some(src) = src {
format!("default via {via} dev {nic} proto static src {src}")
write!(f, "default via {via} dev {nic} proto static src {src}")
} else {
format!("default via {via} dev {nic} proto static")
write!(f, "default via {via} dev {nic} proto static")
}
}

Expand All @@ -183,7 +184,7 @@ impl ToString for IpRoute {
if let Some(src) = src {
write!(out, "src {src} ").unwrap();
}
out
write!(f, "{}", out)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions althea_kernel_interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub enum KernelInterfaceError {
FailedToGetSystemTime,
FailedToGetSystemKernelVersion,
ParseError(String),
FromUtf8Error,
}

impl fmt::Display for KernelInterfaceError {
Expand Down Expand Up @@ -134,6 +135,7 @@ impl fmt::Display for KernelInterfaceError {
KernelInterfaceError::FailedToGetSystemKernelVersion => {
write!(f, "Failed to get system kernel version!")
}
KernelInterfaceError::FromUtf8Error => write!(f, "Could not parse from utf8 output"),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion althea_kernel_interface/src/udp_socket_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::KernelInterfaceError as Error;
use std::collections::HashSet;
use std::fs::File;
use std::io::prelude::*;
use std::u16;

/// Returns a kernel interface runtime error with the given message.
fn runtime_error<T>(msg: &str) -> Result<T, Error> {
Expand Down
5 changes: 2 additions & 3 deletions antenna_forwarding_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,6 @@ mod tests {
use super::Identity;
use super::WgKey;
use rand::Rng;
use std::u16::MAX as U16MAX;

lazy_static! {
pub static ref FORWARDING_SERVER_PUBLIC_KEY: WgKey =
Expand Down Expand Up @@ -859,7 +858,7 @@ mod tests {
// should be small enough to be fast but long enough
// to cause issues
let mut len: u32 = rng.gen();
while len > U16MAX as u32 * 4 {
while len > u16::MAX as u32 * 4 {
len = rng.gen();
}
let mut out = Vec::new();
Expand All @@ -875,7 +874,7 @@ mod tests {
// should be small enough to be fast but long enough
// to cause issues
let mut len: u32 = rng.gen();
while len > U16MAX as u32 * 4 || len < U16MAX as u32 {
while len > u16::MAX as u32 * 4 || len < u16::MAX as u32 {
len = rng.gen();
}
let mut out = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion clu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ mod tests {
let mut history = HashSet::new();
for _ in 0..1000 {
let ip = generate_mesh_ip().unwrap();
if history.get(&ip).is_some() {
if history.contains(&ip) {
panic!("Got duplicate ip {}", ip)
} else {
history.insert(ip);
Expand Down
17 changes: 9 additions & 8 deletions rita_client/src/dashboard/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use actix_web_async::web::Path;
use actix_web_async::{web::Json, HttpRequest, HttpResponse};
use rita_common::{RitaCommonError, KI};
use std::collections::HashMap;
use std::fmt::Display;
use std::net::Ipv4Addr;

use crate::RitaClientError;
Expand Down Expand Up @@ -46,15 +47,15 @@ pub enum InterfaceMode {
Unknown,
}

impl ToString for InterfaceMode {
fn to_string(&self) -> String {
impl Display for InterfaceMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
InterfaceMode::Mesh => "mesh".to_owned(),
InterfaceMode::Lan => "LAN".to_owned(),
InterfaceMode::Wan => "WAN".to_owned(),
InterfaceMode::StaticWan { .. } => "StaticWAN".to_owned(),
InterfaceMode::Unknown => "unknown".to_owned(),
InterfaceMode::LTE => "LTE".to_owned(),
InterfaceMode::Mesh => write!(f, "mesh"),
InterfaceMode::Lan => write!(f, "LAN"),
InterfaceMode::Wan => write!(f, "WAN"),
InterfaceMode::StaticWan { .. } => write!(f, "StaticWAN"),
InterfaceMode::Unknown => write!(f, "unknown"),
InterfaceMode::LTE => write!(f, "LTE"),
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions rita_client/src/dashboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ use actix_async::System;
use actix_web_async::{web, App, HttpServer};
use rita_common::dashboard::babel::*;
use rita_common::dashboard::debts::*;
use rita_common::dashboard::development::*;
use rita_common::dashboard::nickname::*;
use rita_common::dashboard::own_info::*;
use rita_common::dashboard::settings::*;
Expand Down Expand Up @@ -186,7 +185,6 @@ pub fn start_client_dashboard(rita_dashboard_port: u16) {
"/remote_access/{status}",
web::post().to(set_remote_access_status),
)
.route("/wipe", web::post().to(wipe))
.route("/localization", web::get().to(get_localization))
.route(
"/installation_details",
Expand Down
4 changes: 2 additions & 2 deletions rita_client/src/dashboard/neighbors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn generate_neighbors_list(
if maybe_route.is_err() {
output.push(nonviable_node_info(
nickname,
u16::max_value(),
u16::MAX,
identity.mesh_ip.to_string(),
*identity,
neigh.speed_limit,
Expand Down Expand Up @@ -195,7 +195,7 @@ fn nonviable_node_info(
debt: 0.into(),
link_cost: 0,
price_to_exit: 0,
route_metric_to_exit: u16::max_value(),
route_metric_to_exit: u16::MAX,
route_metric: neigh_metric,
speed_limit,
stats: IfaceStats::default(),
Expand Down
78 changes: 0 additions & 78 deletions rita_common/src/dashboard/development.rs

This file was deleted.

1 change: 0 additions & 1 deletion rita_common/src/dashboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

pub mod babel;
pub mod debts;
pub mod development;
pub mod nickname;
pub mod own_info;
pub mod settings;
Expand Down
1 change: 0 additions & 1 deletion rita_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub use error::RitaCommonError;

pub use crate::dashboard::babel::*;
pub use crate::dashboard::debts::*;
pub use crate::dashboard::development::*;
pub use crate::dashboard::nickname::*;
pub use crate::dashboard::own_info::*;
pub use crate::dashboard::settings::*;
Expand Down
Loading
Loading