Skip to content

Commit

Permalink
Merge pull request #29 from holo-routing/add-iface-macaddr
Browse files Browse the repository at this point in the history
Add mac address to Interfaces
  • Loading branch information
rwestphal authored Sep 13, 2024
2 parents 222d545 + 44d2f24 commit 32fb3f4
Show file tree
Hide file tree
Showing 4 changed files with 24 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.mac_address,
});
notify(ibus_tx, msg);
}
Expand Down
6 changes: 6 additions & 0 deletions holo-interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct Interface {
pub mtu: Option<u32>,
pub flags: InterfaceFlags,
pub addresses: BTreeMap<IpNetwork, InterfaceAddress>,
pub mac_address: [u8; 6],
pub owner: Owner,
}

Expand Down Expand Up @@ -123,6 +124,7 @@ impl Interfaces {
flags: InterfaceFlags::default(),
addresses: Default::default(),
owner: Owner::CONFIG,
mac_address: Default::default(),
};

let iface_idx = self.arena.insert(iface);
Expand All @@ -136,6 +138,7 @@ impl Interfaces {
ifindex: u32,
mtu: u32,
flags: InterfaceFlags,
mac_address: [u8; 6],
netlink_handle: &rtnetlink::Handle,
ibus_tx: Option<&IbusSender>,
) {
Expand All @@ -152,6 +155,7 @@ impl Interfaces {
if iface.name == ifname
&& iface.mtu == Some(mtu)
&& iface.flags == flags
&& iface.mac_address == mac_address
{
return;
}
Expand All @@ -170,6 +174,7 @@ impl Interfaces {
iface.owner.insert(Owner::SYSTEM);
iface.mtu = Some(mtu);
iface.flags = flags;
iface.mac_address = mac_address;

// Notify protocol instances about the interface update.
//
Expand Down Expand Up @@ -214,6 +219,7 @@ impl Interfaces {
flags,
addresses: Default::default(),
owner: Owner::SYSTEM,
mac_address: Default::default(),
};

// Notify protocol instances about the interface update.
Expand Down
15 changes: 14 additions & 1 deletion holo-interface/src/netlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ async fn process_newlink_msg(
let ifindex = msg.header.index;
let mut ifname = None;
let mut mtu = None;
let mut mac_address: [u8; 6] = [0u8; 6];

let mut flags = InterfaceFlags::empty();
if msg.header.link_layer_type == ARPHRD_LOOPBACK {
flags.insert(InterfaceFlags::LOOPBACK);
Expand All @@ -57,6 +59,9 @@ 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.try_into().unwrap_or([0u8; 6]);
}
_ => (),
}
}
Expand All @@ -68,7 +73,15 @@ 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
3 changes: 3 additions & 0 deletions holo-utils/src/southbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ pub struct InterfaceUpdateMsg {
pub ifindex: u32,
pub mtu: u32,
pub flags: InterfaceFlags,

#[serde(skip)]
pub mac_address: [u8; 6],
}

#[derive(Clone, Debug)]
Expand Down

0 comments on commit 32fb3f4

Please sign in to comment.