Skip to content

Commit

Permalink
Revert "Merge pull request jcronenberg#14 from cfconrad/pr_fix_bond_o…
Browse files Browse the repository at this point in the history
…ptions"

This reverts commit 041fbab, reversing
changes made to 60766d5.

Revert "Merge pull request jcronenberg#10 from cfconrad/pr_finalize_bond_options"

This reverts commit fe96673, reversing
changes made to cf1a7b1.

Revert "Merge pull request jcronenberg#1 from cfconrad/impl_bonding"

This reverts commit dabe0c0, reversing
changes made to 518d236.
  • Loading branch information
cfconrad committed Dec 7, 2023
1 parent c897466 commit ca95d51
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 842 deletions.
2 changes: 0 additions & 2 deletions rust/agama-dbus-server/src/network/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}'")]
Expand Down
109 changes: 0 additions & 109 deletions rust/agama-dbus-server/src/network/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -242,7 +221,6 @@ pub enum Connection {
Ethernet(EthernetConnection),
Wireless(WirelessConnection),
Loopback(LoopbackConnection),
Bond(BondConnection),
}

impl Connection {
Expand All @@ -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()
}),
}
}

Expand All @@ -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,
}
}

Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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<Self, Self::Err> {
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,
Expand All @@ -375,7 +316,6 @@ pub struct BaseConnection {
pub status: Status,
pub interface: String,
pub match_config: MatchConfig,
pub parent: Option<Parent>,
}

impl PartialEq for BaseConnection {
Expand Down Expand Up @@ -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<Self, Self::Error> {
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<String, String>,
pub hwaddr: Option<MacAddr>,
}

#[derive(Debug, Default, Clone, PartialEq)]
pub struct WirelessConfig {
pub mode: WirelessMode,
pub ssid: SSID,
Expand Down
63 changes: 0 additions & 63 deletions rust/agama-dbus-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -29,10 +28,6 @@ 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()));
Expand All @@ -45,18 +40,6 @@ pub fn connection_to_dbus(conn: &Connection) -> NestedHash {
}
}

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
}
Expand All @@ -74,13 +57,6 @@ pub fn connection_from_dbus(conn: OwnedNestedHash) -> Option<Connection> {
}));
}

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 }));
};
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -502,37 +470,6 @@ fn wireless_config_from_dbus(conn: &OwnedNestedHash) -> Option<WirelessConfig> {
Some(wireless_config)
}

fn bond_hwaddr_from_dbus(conn: &OwnedNestedHash) -> Option<MacAddr> {
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<BondConfig> {
let Some(bond) = conn.get(BOND_KEY) else {
return None;
};

if let Some(dict) = bond.get("options") {
let dict: zvariant::Dict = dict.downcast_ref::<Value>()?.try_into().unwrap();
if dict.full_signature() == "a{aa}" {
let options: HashMap<String, String> = 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.
Expand Down
2 changes: 0 additions & 2 deletions rust/agama-lib/src/network/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub enum DeviceType {
Loopback = 0,
Ethernet = 1,
Wireless = 2,
Bond = 3,
}

#[derive(Debug, Error, PartialEq)]
Expand All @@ -44,7 +43,6 @@ impl TryFrom<u8> for DeviceType {
0 => Ok(DeviceType::Loopback),
1 => Ok(DeviceType::Ethernet),
2 => Ok(DeviceType::Wireless),
3 => Ok(DeviceType::Bond),
_ => Err(InvalidDeviceType(value)),
}
}
Expand Down
Loading

0 comments on commit ca95d51

Please sign in to comment.