diff --git a/rust/agama-dbus-server/src/network/error.rs b/rust/agama-dbus-server/src/network/error.rs index 89f35d2ca0..8c62c05f24 100644 --- a/rust/agama-dbus-server/src/network/error.rs +++ b/rust/agama-dbus-server/src/network/error.rs @@ -15,8 +15,6 @@ pub enum NetworkStateError { InvalidIpMethod(u8), #[error("Invalid wireless mode: '{0}'")] InvalidWirelessMode(String), - #[error("Unknown parent kind '{0}'")] - UnknownParentKind(String), #[error("Connection '{0}' already exists")] ConnectionExists(Uuid), #[error("Invalid security wireless protocol: '{0}'")] diff --git a/rust/agama-dbus-server/src/network/model.rs b/rust/agama-dbus-server/src/network/model.rs index 4b5966fcd9..88a5416180 100644 --- a/rust/agama-dbus-server/src/network/model.rs +++ b/rust/agama-dbus-server/src/network/model.rs @@ -206,27 +206,6 @@ mod tests { let conn = Connection::Loopback(LoopbackConnection { base }); assert!(conn.is_loopback()); } - - #[test] - fn test_mac_addr() { - assert_eq!( - MacAddr::try_from("11:22:33:44:55:66"), - Ok(MacAddr { - data: [0x11, 0x22, 0x33, 0x44, 0x55, 0x66] - }) - ); - assert_eq!( - MacAddr::try_from("11-22-33-44-55-66"), - Ok(MacAddr { - data: [0x11, 0x22, 0x33, 0x44, 0x55, 0x66] - }) - ); - assert_eq!( - MacAddr::try_from("a-b-c-d-e-f").unwrap().to_string(), - String::from("0a:0b:0c:0d:0e:0f") - ); - assert!(MacAddr::try_from("invalid-mac-addr").is_err()); - } } /// Network device @@ -242,7 +221,6 @@ pub enum Connection { Ethernet(EthernetConnection), Wireless(WirelessConnection), Loopback(LoopbackConnection), - Bond(BondConnection), } impl Connection { @@ -258,10 +236,6 @@ impl Connection { }), DeviceType::Loopback => Connection::Loopback(LoopbackConnection { base }), DeviceType::Ethernet => Connection::Ethernet(EthernetConnection { base }), - DeviceType::Bond => Connection::Bond(BondConnection { - base, - ..Default::default() - }), } } @@ -272,7 +246,6 @@ impl Connection { Connection::Ethernet(conn) => &conn.base, Connection::Wireless(conn) => &conn.base, Connection::Loopback(conn) => &conn.base, - Connection::Bond(conn) => &conn.base, } } @@ -281,7 +254,6 @@ impl Connection { Connection::Ethernet(conn) => &mut conn.base, Connection::Wireless(conn) => &mut conn.base, Connection::Loopback(conn) => &mut conn.base, - Connection::Bond(conn) => &mut conn.base, } } @@ -336,37 +308,6 @@ impl Connection { } } -#[derive(Debug, PartialEq, Clone)] -pub enum ParentKind { - Bond, -} - -impl fmt::Display for ParentKind { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let name = match &self { - ParentKind::Bond => "bond", - }; - write!(f, "{}", name) - } -} - -impl FromStr for ParentKind { - type Err = NetworkStateError; - - fn from_str(s: &str) -> Result { - match s { - "bond" => Ok(ParentKind::Bond), - _ => Err(NetworkStateError::UnknownParentKind(s.to_string())), - } - } -} - -#[derive(Debug, Clone)] -pub struct Parent { - pub interface: String, - pub kind: ParentKind, -} - #[derive(Debug, Default, Clone)] pub struct BaseConnection { pub id: String, @@ -375,7 +316,6 @@ pub struct BaseConnection { pub status: Status, pub interface: String, pub match_config: MatchConfig, - pub parent: Option, } impl PartialEq for BaseConnection { @@ -540,55 +480,6 @@ pub struct LoopbackConnection { } #[derive(Debug, Default, PartialEq, Clone)] -pub struct BondConnection { - pub base: BaseConnection, - pub bond: BondConfig, -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct MacAddr { - pub data: [u8; 6], -} - -impl TryFrom<&str> for MacAddr { - type Error = &'static str; - - fn try_from(str: &str) -> Result { - let mut ret: [u8; 6] = [0; 6]; - - let split = str.split([':', '-']); - - for (i, s) in split.into_iter().enumerate() { - if i >= ret.len() { - return Err("The given string doesn't match xx:xx:xx:xx:xx:xx"); - } - match u8::from_str_radix(s, 16) { - Ok(v) => ret[i] = v, - _ => return Err("Unable to parse hex number"), - }; - } - - Ok(MacAddr { data: ret }) - } -} - -impl fmt::Display for MacAddr { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", - self.data[0], self.data[1], self.data[2], self.data[3], self.data[4], self.data[5] - ) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct BondConfig { - pub options: HashMap, - pub hwaddr: Option, -} - -#[derive(Debug, Default, Clone, PartialEq)] pub struct WirelessConfig { pub mode: WirelessMode, pub ssid: SSID, diff --git a/rust/agama-dbus-server/src/network/nm/dbus.rs b/rust/agama-dbus-server/src/network/nm/dbus.rs index ac123a8737..d601291e9f 100644 --- a/rust/agama-dbus-server/src/network/nm/dbus.rs +++ b/rust/agama-dbus-server/src/network/nm/dbus.rs @@ -14,7 +14,6 @@ use uuid::Uuid; use zbus::zvariant::{self, OwnedValue, Value}; const ETHERNET_KEY: &str = "802-3-ethernet"; -const BOND_KEY: &str = "bond"; const WIRELESS_KEY: &str = "802-11-wireless"; const WIRELESS_SECURITY_KEY: &str = "802-11-wireless-security"; const LOOPBACK_KEY: &str = "loopback"; @@ -29,34 +28,18 @@ pub fn connection_to_dbus(conn: &Connection) -> NestedHash { ("type", ETHERNET_KEY.into()), ("interface-name", conn.interface().into()), ]); - if let Some(parent) = &conn.base().parent { - connection_dbus.insert("master", parent.interface.clone().into()); - connection_dbus.insert("slave-type", parent.kind.to_string().into()); - } result.insert("ipv4", ip_config_to_ipv4_dbus(conn.ip_config())); result.insert("ipv6", ip_config_to_ipv6_dbus(conn.ip_config())); result.insert("match", match_config_to_dbus(conn.match_config())); if let Connection::Wireless(wireless) = conn { - connection_dbus.insert("type", WIRELESS_KEY.into()); + connection_dbus.insert("type", "802-11-wireless".into()); let wireless_dbus = wireless_config_to_dbus(wireless); for (k, v) in wireless_dbus { result.insert(k, v); } } - if let Connection::Bond(bond) = conn { - connection_dbus.insert("type", BOND_KEY.into()); - let bond_dbus = bond_config_to_dbus(bond); - for (k, v) in bond_dbus { - result.insert(k, v); - } - if let Some(mac) = &bond.bond.hwaddr { - let h = result.entry("802-3-ethernet").or_insert(HashMap::new()); - h.insert("assigned-mac-address", mac.to_string().into()); - } - } - result.insert("connection", connection_dbus); result } @@ -74,13 +57,6 @@ pub fn connection_from_dbus(conn: OwnedNestedHash) -> Option { })); } - if let Some(bond_config) = bond_config_from_dbus(&conn) { - return Some(Connection::Bond(BondConnection { - base, - bond: bond_config, - })); - } - if conn.get(LOOPBACK_KEY).is_some() { return Some(Connection::Loopback(LoopbackConnection { base })); }; @@ -257,14 +233,6 @@ fn wireless_config_to_dbus(conn: &WirelessConnection) -> NestedHash { ]) } -fn bond_config_to_dbus(conn: &BondConnection) -> NestedHash { - let config = &conn.bond; - let bond: HashMap<&str, zvariant::Value> = - HashMap::from([("options", Value::new(config.options.clone()))]); - - NestedHash::from([("bond", bond)]) -} - /// Converts a MatchConfig struct into a HashMap that can be sent over D-Bus. /// /// * `match_config`: MatchConfig to convert. @@ -502,37 +470,6 @@ fn wireless_config_from_dbus(conn: &OwnedNestedHash) -> Option { Some(wireless_config) } -fn bond_hwaddr_from_dbus(conn: &OwnedNestedHash) -> Option { - let Some(eth) = conn.get(ETHERNET_KEY) else { - return None; - }; - - let Some(mac) = eth.get("assigned-mac-address") else { - return None; - }; - - let mac: &str = mac.downcast_ref()?; - MacAddr::try_from(mac).ok() -} - -fn bond_config_from_dbus(conn: &OwnedNestedHash) -> Option { - let Some(bond) = conn.get(BOND_KEY) else { - return None; - }; - - if let Some(dict) = bond.get("options") { - let dict: zvariant::Dict = dict.downcast_ref::()?.try_into().unwrap(); - if dict.full_signature() == "a{aa}" { - let options: HashMap = dict.try_into().unwrap(); - return Some(BondConfig { - options, - hwaddr: bond_hwaddr_from_dbus(conn), - }); - } - } - None -} - /// Determines whether a value is empty. /// /// TODO: Generalize for other kind of values, like dicts or arrays. diff --git a/rust/agama-lib/src/network/types.rs b/rust/agama-lib/src/network/types.rs index 729f68bc10..5aa56c5145 100644 --- a/rust/agama-lib/src/network/types.rs +++ b/rust/agama-lib/src/network/types.rs @@ -29,7 +29,6 @@ pub enum DeviceType { Loopback = 0, Ethernet = 1, Wireless = 2, - Bond = 3, } #[derive(Debug, Error, PartialEq)] @@ -44,7 +43,6 @@ impl TryFrom for DeviceType { 0 => Ok(DeviceType::Loopback), 1 => Ok(DeviceType::Ethernet), 2 => Ok(DeviceType::Wireless), - 3 => Ok(DeviceType::Bond), _ => Err(InvalidDeviceType(value)), } } diff --git a/rust/migrate-wicked/src/interface.rs b/rust/migrate-wicked/src/interface.rs index 9866c6afa3..7244aa50ec 100644 --- a/rust/migrate-wicked/src/interface.rs +++ b/rust/migrate-wicked/src/interface.rs @@ -1,11 +1,11 @@ -use agama_dbus_server::network::model::{self, IpConfig, IpRoute, Ipv4Method, Ipv6Method, Parent}; +use agama_dbus_server::network::model::{self, IpConfig, IpRoute, Ipv4Method, Ipv6Method}; use cidr::IpInet; -use serde::{Deserialize, Deserializer, Serialize}; +use serde::{Deserialize, Serialize}; use serde_with::{ formats::CommaSeparator, serde_as, skip_serializing_none, DeserializeFromStr, SerializeDisplay, StringWithSeparator, }; -use std::{collections::HashMap, net::IpAddr, str::FromStr}; +use std::{net::IpAddr, str::FromStr}; use strum_macros::{Display, EnumString}; #[derive(Debug, PartialEq, Default, Serialize, Deserialize)] @@ -14,7 +14,6 @@ pub struct Interface { pub name: String, pub control: Control, pub firewall: Firewall, - pub link: Link, pub ipv4: Ipv4, #[serde(rename = "ipv4-static", skip_serializing_if = "Option::is_none")] pub ipv4_static: Option, @@ -25,17 +24,10 @@ pub struct Interface { pub ipv6_dhcp: Option, #[serde(rename = "ipv6-auto", skip_serializing_if = "Option::is_none")] pub ipv6_auto: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub bond: Option, #[serde(rename = "@origin")] pub origin: String, } -#[derive(Debug, PartialEq, Serialize, Clone, Deserialize)] -pub enum ParentKind { - Bond, -} - #[derive(Debug, PartialEq, Default, Serialize, Deserialize)] #[serde(default)] pub struct Control { @@ -46,15 +38,6 @@ pub struct Control { #[serde(default)] pub struct Firewall {} -#[derive(Debug, PartialEq, Default, Serialize, Deserialize)] -#[serde(default)] -pub struct Link { - #[serde(rename = "master", skip_serializing_if = "Option::is_none")] - pub parent: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub kind: Option, -} - #[derive(Debug, PartialEq, Default, Serialize, Deserialize)] #[serde(default)] pub struct Ipv4 { @@ -149,298 +132,6 @@ pub struct Nexthop { pub gateway: String, } -#[derive(Debug, PartialEq, SerializeDisplay, DeserializeFromStr, EnumString, Display)] -#[strum(serialize_all = "kebab_case")] -pub enum XmitHashPolicy { - Layer2, - Layer23, - Layer34, - Encap23, - Encap34, -} - -#[derive(Debug, PartialEq, SerializeDisplay, DeserializeFromStr, EnumString, Display)] -#[strum(serialize_all = "kebab_case")] -pub enum LacpRate { - Slow, - Fast, -} - -#[derive(Debug, PartialEq, SerializeDisplay, DeserializeFromStr, EnumString, Display)] -#[strum(serialize_all = "kebab_case")] -pub enum AdSelect { - Stable, - Bandwidth, - Count, -} - -#[derive(Debug, PartialEq, SerializeDisplay, DeserializeFromStr, EnumString, Display)] -#[strum(serialize_all = "kebab_case")] -pub enum PrimaryReselect { - Always, - Better, - Failure, -} - -#[derive(Debug, PartialEq, SerializeDisplay, DeserializeFromStr, EnumString, Display)] -#[strum(serialize_all = "kebab_case")] -pub enum BondMode { - BalanceRr = 0, - ActiveBackup, - BalanceXor, - Broadcast, - #[strum(serialize = "802.3ad")] - IEEE8023ad, - BalanceTlb, - BalanceAlb, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[skip_serializing_none] -#[serde(rename_all = "kebab-case")] -pub struct Bond { - pub mode: BondMode, - pub miimon: Option, - pub arpmon: Option, - #[serde(deserialize_with = "unwrap_slaves")] - pub slaves: Vec, - /* only on mode=[802.3ad, balance_xor] */ - pub xmit_hash_policy: Option, - /* only on mode=balance_rr */ - pub packets_per_slave: Option, - /* only on mode=balance_tlb */ - pub tlb_dynamic_lb: Option, - /* only on mode=802.3ad */ - pub lacp_rate: Option, - /* only on mode=802.3ad */ - pub ad_select: Option, - /* only on mode=802.3ad */ - pub ad_user_port_key: Option, - /* only on mode=802.3ad */ - pub ad_actor_sys_prio: Option, - /* only on mode=802.3ad */ - pub ad_actor_system: Option, - /* only on mode=802.3ad */ - pub min_links: Option, - /* only on mode=active-backup */ - pub primary_reselect: Option, - /* only on mode=active-backup */ - pub fail_over_mac: Option, - /* only on mode=active-backup */ - pub num_grat_arp: Option, - /* only on mode=active-backup */ - pub num_unsol_na: Option, - /* only on mode=[balance_tlb|balance_alb] */ - pub lp_interval: Option, - /* only on mode=[balance_tlb|balance_alb|balance_RR|active-backup] */ - pub resend_igmp: Option, - pub all_slaves_active: Option, - pub address: Option, -} - -impl Bond { - pub fn primary(self: &Bond) -> Option<&String> { - for s in self.slaves.iter() { - if s.primary.is_some() && s.primary.unwrap() { - return Some(&s.device); - } - } - None - } -} - -#[derive(Debug, PartialEq, Default, Serialize, Deserialize)] -pub struct Slave { - pub device: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub primary: Option, -} - -#[derive(Debug, PartialEq, Default, SerializeDisplay, DeserializeFromStr, EnumString, Display)] -#[strum(serialize_all = "kebab_case")] -pub enum CarrierDetect { - Ioctl = 0, - #[default] - Netif = 1, -} - -#[derive(Debug, PartialEq, Default, Serialize, Deserialize)] -pub struct Miimon { - pub frequency: u32, - #[serde(rename = "carrier-detect")] - pub carrier_detect: CarrierDetect, - pub downdelay: Option, - pub updelay: Option, -} - -#[derive(Debug, PartialEq, SerializeDisplay, DeserializeFromStr, EnumString, Display)] -#[strum(serialize_all = "kebab_case")] -pub enum ArpValidateTargets { - Any = 0, - All = 1, -} - -#[derive(Debug, PartialEq, SerializeDisplay, DeserializeFromStr, EnumString, Display)] -#[strum(serialize_all = "snake_case")] -pub enum ArpValidate { - None = 0, - Active = 1, - Backup = 2, - All = 3, - Filter = 4, - FilterActive = 5, - FilterBackup = 6, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct ArpMon { - pub interval: u32, - pub validate: ArpValidate, - #[serde(rename = "validate-targets", skip_serializing_if = "Option::is_none")] - pub validate_targets: Option, - #[serde(deserialize_with = "unwrap_arpmon_targets")] - pub targets: Vec, -} - -fn unwrap_arpmon_targets<'de, D>(deserializer: D) -> Result, D::Error> -where - D: Deserializer<'de>, -{ - #[derive(Debug, PartialEq, Default, Serialize, Deserialize)] - pub struct ArpMonTargetAddressV4 { - #[serde(rename = "ipv4-address")] - pub ipv4_address: Vec, - } - Ok(ArpMonTargetAddressV4::deserialize(deserializer)?.ipv4_address) -} - -fn unwrap_slaves<'de, D>(deserializer: D) -> Result, D::Error> -where - D: Deserializer<'de>, -{ - #[derive(Debug, PartialEq, Default, Serialize, Deserialize)] - struct Slaves { - slave: Vec, - } - Ok(Slaves::deserialize(deserializer)?.slave) -} - -impl From<&Bond> for model::BondConfig { - fn from(bond: &Bond) -> model::BondConfig { - let mut h: HashMap = HashMap::new(); - - h.insert(String::from("mode"), bond.mode.to_string()); - if let Some(p) = bond.primary() { - h.insert(String::from("primary"), p.clone()); - } - - if let Some(m) = &bond.miimon { - h.insert(String::from("miimon"), format!("{}", m.frequency)); - h.insert( - String::from("use_carrier"), - match m.carrier_detect { - CarrierDetect::Ioctl => 0, - CarrierDetect::Netif => 1, - } - .to_string(), - ); - if let Some(v) = m.downdelay { - h.insert(String::from("downdelay"), v.to_string()); - } - if let Some(v) = m.updelay { - h.insert(String::from("updelay"), v.to_string()); - } - } - - if let Some(a) = &bond.arpmon { - h.insert(String::from("arp_interval"), format!("{}", a.interval)); - h.insert(String::from("arp_validate"), a.validate.to_string()); - - if !a.targets.is_empty() { - let sv = a - .targets - .iter() - .map(|c| c.as_ref()) - .collect::>() - .join(","); - h.insert(String::from("arp_ip_target"), sv); - } - - if let Some(v) = &a.validate_targets { - h.insert(String::from("arp_all_targets"), v.to_string()); - } - } - - if let Some(fom) = &bond.fail_over_mac { - h.insert(String::from("fail_over_mac"), fom.to_string()); - } - - if let Some(v) = &bond.xmit_hash_policy { - h.insert(String::from("xmit_hash_policy"), v.to_string()); - } - - if let Some(v) = &bond.packets_per_slave { - h.insert(String::from("packets_per_slave"), v.to_string()); - } - - if let Some(v) = &bond.tlb_dynamic_lb { - h.insert( - String::from("tlb_dynamic_lb"), - if *v { 1.to_string() } else { 0.to_string() }, - ); - } - - if let Some(v) = &bond.lacp_rate { - h.insert(String::from("lacp_rate"), v.to_string()); - } - - if let Some(v) = &bond.ad_select { - h.insert(String::from("ad_select"), v.to_string()); - } - if let Some(v) = &bond.ad_user_port_key { - h.insert(String::from("ad_user_port_key"), v.to_string()); - } - if let Some(v) = &bond.ad_actor_sys_prio { - h.insert(String::from("ad_actor_sys_prio"), v.to_string()); - } - if let Some(v) = &bond.ad_actor_system { - h.insert(String::from("ad_actor_system"), v.clone()); - } - if let Some(v) = &bond.min_links { - h.insert(String::from("min_links"), v.to_string()); - } - if let Some(v) = &bond.primary_reselect { - h.insert(String::from("primary_reselect"), v.to_string()); - } - if let Some(v) = &bond.num_grat_arp { - h.insert(String::from("num_grat_arp"), v.to_string()); - } - if let Some(v) = &bond.num_unsol_na { - h.insert(String::from("num_unsol_na"), v.to_string()); - } - if let Some(v) = &bond.lp_interval { - h.insert(String::from("lp_interval"), v.to_string()); - } - if let Some(v) = &bond.resend_igmp { - h.insert(String::from("resend_igmp"), v.to_string()); - } - if let Some(v) = &bond.all_slaves_active { - h.insert( - String::from("all_slaves_active"), - if *v { 1.to_string() } else { 0.to_string() }, - ); - } - - model::BondConfig { - options: h, - hwaddr: match &bond.address { - Some(s) => model::MacAddr::try_from(s.as_ref()).ok(), - _ => None, - }, - } - } -} - pub struct ConnectionResult { pub connection: model::Connection, pub warnings: Vec, @@ -454,33 +145,15 @@ pub struct IpConfigResult { impl Interface { pub fn to_connection(&self) -> Result { let ip_config = self.to_ip_config()?; - let mut base = model::BaseConnection { + let base = model::BaseConnection { id: self.name.clone(), interface: self.name.clone(), ip_config: ip_config.ip_config, ..Default::default() }; - if self.link.kind.is_some() && self.link.parent.is_some() { - let interface = self.link.parent.clone().unwrap(); - let kind = match &self.link.kind { - Some(p) => match &p { - ParentKind::Bond => model::ParentKind::Bond, - }, - None => return Err(anyhow::anyhow!("Missing ParentType for {}", self.name)), - }; - base.parent = Some(Parent { interface, kind }); - } - Ok(ConnectionResult { - connection: if let Some(b) = &self.bond { - model::Connection::Bond(model::BondConnection { - base, - bond: b.into(), - }) - } else { - model::Connection::Ethernet(model::EthernetConnection { base }) - }, + connection: model::Connection::Ethernet(model::EthernetConnection { base }), warnings: ip_config.warnings, }) } @@ -744,92 +417,4 @@ mod tests { assert_eq!(static_connection.base().ip_config.method6, Ipv6Method::Auto); assert_eq!(static_connection.base().ip_config.addresses.len(), 0); } - - #[test] - fn test_bond_options() { - let bond = Bond { - mode: BondMode::IEEE8023ad, - xmit_hash_policy: Some(XmitHashPolicy::Encap34), - fail_over_mac: Some(FailOverMac::Active), - packets_per_slave: Some(23), - tlb_dynamic_lb: Some(true), - lacp_rate: Some(LacpRate::Slow), - ad_select: Some(AdSelect::Bandwidth), - ad_user_port_key: Some(42), - ad_actor_sys_prio: Some(5), - ad_actor_system: Some(String::from("00:de:ad:be:ef:00")), - min_links: Some(3), - primary_reselect: Some(PrimaryReselect::Better), - num_grat_arp: Some(7), - num_unsol_na: Some(13), - lp_interval: Some(17), - resend_igmp: Some(19), - all_slaves_active: Some(true), - miimon: Some(Miimon { - frequency: 42, - carrier_detect: CarrierDetect::Netif, - downdelay: Some(23), - updelay: Some(5), - }), - arpmon: Some(ArpMon { - interval: 23, - validate: ArpValidate::FilterBackup, - validate_targets: Some(ArpValidateTargets::Any), - targets: vec![String::from("1.2.3.4"), String::from("4.3.2.1")], - }), - slaves: vec![], - address: Some(String::from("02:11:22:33:44:55")), - }; - - let bondconfig: model::BondConfig = (&bond).into(); - let s = HashMap::from([ - ("xmit_hash_policy", String::from("encap34")), - ("packets_per_slave", 23.to_string()), - ("tlb_dynamic_lb", 1.to_string()), - ("lacp_rate", String::from("slow")), - ("ad_select", String::from("bandwidth")), - ("ad_user_port_key", 42.to_string()), - ("ad_actor_sys_prio", 5.to_string()), - ("ad_actor_system", String::from("00:de:ad:be:ef:00")), - ("min_links", 3.to_string()), - ("primary_reselect", String::from("better")), - ("fail_over_mac", String::from("active")), - ("num_grat_arp", 7.to_string()), - ("num_unsol_na", 13.to_string()), - ("lp_interval", 17.to_string()), - ("resend_igmp", 19.to_string()), - ("all_slaves_active", 1.to_string()), - // miimon - ("miimon", 42.to_string()), - ("use_carrier", 1.to_string()), - ("downdelay", 23.to_string()), - ("updelay", 5.to_string()), - // arpmon - ("arp_validate", String::from("filter_backup")), - ("arp_all_targets", String::from("any")), - ("arp_ip_target", String::from("1.2.3.4,4.3.2.1")), - ("arp_interval", 23.to_string()), - ]); - - for (k, v) in s.iter() { - assert!( - bondconfig.options.contains_key(*k), - "Missing key '{}' in bond hash {:?}", - *k, - bondconfig - ); - assert_eq!( - bondconfig.options.get(*k).unwrap(), - v, - "Unexpected value '{}' in key '{}'", - *k, - v - ); - } - - assert_eq!( - bondconfig.hwaddr.unwrap().data, - [0x02, 0x11, 0x22, 0x33, 0x44, 0x55] - ); - } } diff --git a/rust/migrate-wicked/src/reader.rs b/rust/migrate-wicked/src/reader.rs index 1f6700caa7..0f312c85be 100644 --- a/rust/migrate-wicked/src/reader.rs +++ b/rust/migrate-wicked/src/reader.rs @@ -1,7 +1,6 @@ -use crate::interface::{Interface, ParentKind}; +use crate::interface::Interface; use regex::Regex; -use std::collections::HashMap; use std::fs::{self, read_dir}; use std::path::{Path, PathBuf}; @@ -51,24 +50,6 @@ fn replace_colons(colon_string: &str) -> String { replaced } -pub fn post_process_interface(interfaces: &mut [Interface]) { - let mut helper = HashMap::new(); - for (idx, i) in interfaces.iter().enumerate() { - if let Some(parent) = &i.link.parent { - for j in interfaces.iter() { - if j.name == *parent && j.bond.is_some() { - helper.insert(idx, Some(ParentKind::Bond)); - } - } - } - } - for (_, (k, v)) in helper.iter().enumerate() { - if let Some(ifc) = interfaces.get_mut(*k) { - ifc.link.kind = v.clone(); - } - } -} - // https://stackoverflow.com/a/76820878 fn recurse_files(path: impl AsRef) -> std::io::Result> { let mut buf = vec![]; @@ -115,7 +96,6 @@ pub fn read(paths: Vec) -> Result { result.interfaces.append(&mut read_xml.interfaces); } } - post_process_interface(&mut result.interfaces); Ok(result) } @@ -124,99 +104,6 @@ mod tests { use super::*; use crate::interface::*; - #[test] - fn test_bond_options_from_xml() { - let xml = r##" - - bond0 - - active-backup - layer34 - none - 1 - true - slow - bandwidth - 5 - 7 - 00:de:ad:be:ef:00 - 11 - better - 13 - 17 - 19 - 23 - true - - en0 - - - 23 - 27 - 31 - ioctl - - - 23 - filter_backup - any - - 1.2.3.4 - 4.3.2.1 - - -
02:11:22:33:44:55
-
-
- "##; - let ifc = quick_xml::de::from_str::>(replace_colons(xml).as_str()) - .unwrap() - .pop() - .unwrap(); - assert!(ifc.bond.is_some()); - let bond = ifc.bond.unwrap(); - - assert_eq!( - bond, - Bond { - mode: BondMode::ActiveBackup, - xmit_hash_policy: Some(XmitHashPolicy::Layer34), - fail_over_mac: Some(FailOverMac::None), - packets_per_slave: Some(1), - tlb_dynamic_lb: Some(true), - lacp_rate: Some(LacpRate::Slow), - ad_select: Some(AdSelect::Bandwidth), - ad_user_port_key: Some(5), - ad_actor_sys_prio: Some(7), - ad_actor_system: Some(String::from("00:de:ad:be:ef:00")), - min_links: Some(11), - primary_reselect: Some(PrimaryReselect::Better), - num_grat_arp: Some(13), - num_unsol_na: Some(17), - lp_interval: Some(19), - resend_igmp: Some(23), - all_slaves_active: Some(true), - slaves: vec![Slave { - device: String::from("en0"), - primary: None - }], - miimon: Some(Miimon { - frequency: 23, - carrier_detect: CarrierDetect::Ioctl, - downdelay: Some(31), - updelay: Some(27), - }), - arpmon: Some(ArpMon { - interval: 23, - validate: ArpValidate::FilterBackup, - validate_targets: Some(ArpValidateTargets::Any), - targets: vec![String::from("1.2.3.4"), String::from("4.3.2.1")] - }), - address: Some(String::from("02:11:22:33:44:55")), - } - ); - } - #[test] fn test_broken_xml() { let xml = r##" diff --git a/rust/migrate-wicked/tests/bond_active-backup/system-connections/bond0.nmconnection b/rust/migrate-wicked/tests/bond_active-backup/system-connections/bond0.nmconnection deleted file mode 100644 index a14c852a1b..0000000000 --- a/rust/migrate-wicked/tests/bond_active-backup/system-connections/bond0.nmconnection +++ /dev/null @@ -1,25 +0,0 @@ -[connection] -id=bond0 -uuid=766a5c05-2ba1-45be-960d-9f2dbf89b293 -type=bond -interface-name=bond0 - -[ethernet] -cloned-mac-address=02:00:33:44:55:11 - -[bond] -miimon=100 -mode=active-backup -primary=en0 -use_carrier=1 - -[match] - -[ipv4] -method=auto - -[ipv6] -addr-gen-mode=default -method=auto - -[proxy] diff --git a/rust/migrate-wicked/tests/bond_active-backup/system-connections/en0.nmconnection b/rust/migrate-wicked/tests/bond_active-backup/system-connections/en0.nmconnection deleted file mode 100644 index 046d8e7906..0000000000 --- a/rust/migrate-wicked/tests/bond_active-backup/system-connections/en0.nmconnection +++ /dev/null @@ -1,11 +0,0 @@ -[connection] -id=en0 -uuid=38d979e6-aa0e-4bae-8cff-a6dda281d0c7 -type=ethernet -interface-name=en0 -master=bond0 -slave-type=bond - -[ethernet] - -[match] diff --git a/rust/migrate-wicked/tests/bond_active-backup/system-connections/en1.nmconnection b/rust/migrate-wicked/tests/bond_active-backup/system-connections/en1.nmconnection deleted file mode 100644 index 1e079a2789..0000000000 --- a/rust/migrate-wicked/tests/bond_active-backup/system-connections/en1.nmconnection +++ /dev/null @@ -1,11 +0,0 @@ -[connection] -id=en1 -uuid=9269bbb4-a771-406f-ba66-3f65ed15634c -type=ethernet -interface-name=en1 -master=bond0 -slave-type=bond - -[ethernet] - -[match] diff --git a/rust/migrate-wicked/tests/bond_active-backup/wicked_xml/bond_active-backup.xml b/rust/migrate-wicked/tests/bond_active-backup/wicked_xml/bond_active-backup.xml deleted file mode 100644 index b6228ab717..0000000000 --- a/rust/migrate-wicked/tests/bond_active-backup/wicked_xml/bond_active-backup.xml +++ /dev/null @@ -1,85 +0,0 @@ - - bond0 - - boot - - - public - - - active-backup - - 100 - netif - - - - en0 - true - - - en1 - - -
02:00:33:44:55:11
-
- - - true - true - - - true - group - default-route,hostname,dns,nis,ntp,smb,nds,mtu,tz,boot - 15 - true - false - - - true - prefer-public - false - - - true - group - dns,nis,ntp,tz,boot - auto - true - 15 - true - false - false - -
- - en0 - - hotplug - - - bond0 - - - false - - - false - - - - en1 - - hotplug - - - bond0 - - - false - - - false - -