Skip to content

Commit

Permalink
Add mac address in notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-weqe committed Jul 29, 2024
1 parent 8afa889 commit 1e401fc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions holo-interface/src/ibus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub(crate) fn notify_interface_update(ibus_tx: &IbusSender, iface: &Interface) {
ifindex: iface.ifindex.unwrap_or(0),
mtu: iface.mtu.unwrap_or(0),
flags: iface.flags,
mac_address: iface.config.mac_address.clone(),
});
notify(ibus_tx, msg);
}
Expand Down
3 changes: 3 additions & 0 deletions holo-interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ impl Interfaces {
ifindex: u32,
mtu: u32,
flags: InterfaceFlags,
mac_address: Vec<u8>,
netlink_handle: &rtnetlink::Handle,
ibus_tx: Option<&IbusSender>,
) {
Expand Down Expand Up @@ -173,6 +174,7 @@ impl Interfaces {
iface.owner.insert(Owner::SYSTEM);
iface.mtu = Some(mtu);
iface.flags = flags;
iface.config.mac_address = mac_address;

// Notify protocol instances about the interface update.
//
Expand Down Expand Up @@ -206,6 +208,7 @@ impl Interfaces {
let iface = &self.arena[iface_idx];
iface.apply_config(ifindex, netlink_handle, self).await;
}

}
None => {
// If the interface does not exist, create a new entry.
Expand Down
5 changes: 4 additions & 1 deletion holo-interface/src/netlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ async fn process_newlink_msg(
let ifindex = msg.header.index;
let mut ifname = None;
let mut mtu = None;
let mut mac_address: Vec<u8> = Vec::default();

let mut flags = InterfaceFlags::empty();
if msg.header.link_layer_type == ARPHRD_LOOPBACK {
flags.insert(InterfaceFlags::LOOPBACK);
Expand All @@ -56,6 +58,7 @@ async fn process_newlink_msg(
match nla {
Nla::IfName(nla_ifname) => ifname = Some(nla_ifname),
Nla::Mtu(nla_mtu) => mtu = Some(nla_mtu),
Nla::Address(addr) => mac_address = addr,
_ => (),
}
}
Expand All @@ -67,7 +70,7 @@ async fn process_newlink_msg(
let ibus_tx = notify.then_some(&master.ibus_tx);
master
.interfaces
.update(ifname, ifindex, mtu, flags, &master.netlink_handle, ibus_tx)
.update(ifname, ifindex, mtu, flags, mac_address, &master.netlink_handle, ibus_tx)
.await;
}

Expand Down
2 changes: 2 additions & 0 deletions holo-interface/src/northbound/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub struct InterfaceCfg {
pub parent: Option<String>,
pub vlan_id: Option<u16>,
pub addr_list: BTreeMap<IpAddr, u8>,
pub mac_address: Vec<u8>,
}

// ===== callbacks =====
Expand Down Expand Up @@ -461,6 +462,7 @@ impl Default for InterfaceCfg {
parent: None,
vlan_id: None,
addr_list: Default::default(),
mac_address: Default::default(),
}
}
}
1 change: 1 addition & 0 deletions holo-utils/src/southbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub struct InterfaceUpdateMsg {
pub ifindex: u32,
pub mtu: u32,
pub flags: InterfaceFlags,
pub mac_address: Vec<u8>,
}

#[derive(Clone, Debug)]
Expand Down

0 comments on commit 1e401fc

Please sign in to comment.