Skip to content

Commit

Permalink
Move dbus mac-address processing to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
jcronenberg committed Dec 5, 2023
1 parent ecafa7a commit db9a040
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions rust/agama-dbus-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,38 +309,30 @@ fn base_connection_from_dbus(conn: &OwnedNestedHash) -> Option<BaseConnection> {
}

if let Some(ethernet_config) = conn.get(ETHERNET_KEY) {
if let Some(mac_address) = ethernet_config.get("assigned-mac-address") {
base_connection.mac_address =
match MacAddress::from_str(mac_address.downcast_ref::<str>()?) {
Ok(mac) => mac,
Err(e) => {
log::warn!("Couldn't parse MAC: {}", e);
MacAddress::Unset
}
};
} else {
base_connection.mac_address = MacAddress::Unset;
}
base_connection.mac_address = mac_address_from_dbus(ethernet_config)?;
} else if let Some(wireless_config) = conn.get(WIRELESS_KEY) {
if let Some(mac_address) = wireless_config.get("assigned-mac-address") {
base_connection.mac_address =
match MacAddress::from_str(mac_address.downcast_ref::<str>()?) {
Ok(mac) => mac,
Err(e) => {
log::warn!("Couldn't parse MAC: {}", e);
MacAddress::Unset
}
};
} else {
base_connection.mac_address = MacAddress::Unset;
}
base_connection.mac_address = mac_address_from_dbus(wireless_config)?;
}

base_connection.ip_config = ip_config_from_dbus(&conn)?;

Some(base_connection)
}

fn mac_address_from_dbus(config: &HashMap<String, OwnedValue>) -> Option<MacAddress> {
if let Some(mac_address) = config.get("assigned-mac-address") {
match MacAddress::from_str(mac_address.downcast_ref::<str>()?) {
Ok(mac) => Some(mac),
Err(e) => {
log::warn!("Couldn't parse MAC: {}", e);
None
}
}
} else {
Some(MacAddress::Unset)
}
}

fn match_config_from_dbus(
match_config: &HashMap<String, zvariant::OwnedValue>,
) -> Option<MatchConfig> {
Expand Down

0 comments on commit db9a040

Please sign in to comment.