Skip to content

Commit

Permalink
vrrp: add create prepare. change mvlan name
Browse files Browse the repository at this point in the history
Changed the name of the macvlan interface being
created to `mvlan-vrrp-{vrid}`. At the moment,
when creating the interfae, the messages are not
correctly received, so this simplifies the type
of interface we deal with.
Also add create_prepare in the configuration of
holo-interface to make sure the interface object
is correctly created.

Signed-off-by: Paul Wekesa <[email protected]>
  • Loading branch information
Paul-weqe committed Sep 12, 2024
1 parent 980d582 commit 919094f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
4 changes: 4 additions & 0 deletions holo-interface/src/netlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ pub(crate) async fn macvlan_create(
parent_ifindex,
MACVLAN_MODE_BRIDGE,
);
// address() method is added in rtnetlink version 0.14.0. Will be uncommented when the
// version upgrade is done in this project.
//.address(vec![0x00, 0x00, 0x5e, 0x00, 0x01, 0x1e]);

// Execute request.
if let Err(error) = request.execute().await {
error!(%parent_ifindex, %name, %error, "Failed to create MacVlan interface");
Expand Down
9 changes: 9 additions & 0 deletions holo-interface/src/northbound/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ fn load_callbacks() -> Callbacks<Master> {
let event_queue = args.event_queue;
event_queue.insert(Event::VrrpStart(ifname));
})
.create_prepare(|master, args| {
let ifname = args.dnode.get_string_relative("./name").unwrap();
master.interfaces.add(ifname.clone());

let event_queue = args.event_queue;
event_queue.insert(Event::VrrpStart(ifname));

Ok(())
})
.delete_apply(|_master, args| {
let ifname = args.list_entry.into_interface().unwrap();

Expand Down
12 changes: 8 additions & 4 deletions holo-vrrp/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub struct MacVlanInterface {
// Interface name.
//
// Macvlan interface naming for VRRP will be in the format:
// `mvlan-vrrp{primary-interface-ifindex}{vrid}`
// `mvlan-vrrp-{vrid}`
pub name: String,
// Interface system data.
pub system: InterfaceSys,
Expand Down Expand Up @@ -118,8 +118,7 @@ impl Interface {
self.instances.insert(vrid, instance);

// `mvlan-vrrp{primary-interface-ifindex}{vrid}`
let name =
format!("mvlan-vrrp-{}-{}", self.system.ifindex.unwrap_or(0), vrid);
let name = format!("mvlan-vrrp-{}", vrid);
southbound::create_macvlan_address(
name.clone(),
self.name.clone(),
Expand All @@ -128,14 +127,19 @@ impl Interface {

// change the interface mac address to the virtual MAC adderss
southbound::update_iface_mac_address(
name.clone(),
name,
[0x00, 0x00, 0x5e, 0x00, 0x01, vrid],
&self.tx.ibus,
);
}

pub(crate) fn change_state(&mut self, vrid: u8, state: State) {
if let Some(instance) = self.instances.get_mut(&vrid) {
if state == State::Backup {
// change admin state of MacVlan to down.
} else if state == State::Master {
// change admin state of MacVlan to up.
}
instance.state.state = state;
tasks::set_timer(self, vrid);
}
Expand Down
13 changes: 3 additions & 10 deletions holo-vrrp/src/southbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,17 @@ pub(crate) fn process_iface_update(

// update names for all macvlans
for (vrid, instance) in iface.instances.iter_mut() {
let name = format!(
"mvlan-vrrp-{}-{}",
iface.system.ifindex.unwrap_or(0),
vrid
);
let name = format!("mvlan-vrrp-{}", vrid);
if let Some(mvlan) = &mut instance.config.mac_vlan {
mvlan.name = name;
}
}
return;
}

// check if it is one of the macvlans being updated.
for (vrid, instance) in iface.instances.iter_mut() {
let name = format!(
"mvlan-vrrp-{}-{}",
iface.system.ifindex.unwrap_or(0),
vrid,
);
let name = format!("mvlan-vrrp-{}", vrid);

if let Some(mvlan_iface) = &mut instance.config.mac_vlan {
if mvlan_iface.system.ifindex.unwrap() == msg.ifindex {
Expand Down

0 comments on commit 919094f

Please sign in to comment.