From 919094f7b90854f91830bcd12691eda0dfead7fd Mon Sep 17 00:00:00 2001 From: Paul Wekesa Date: Thu, 12 Sep 2024 16:47:36 +0300 Subject: [PATCH] vrrp: add create prepare. change mvlan name 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 --- holo-interface/src/netlink.rs | 4 ++++ holo-interface/src/northbound/configuration.rs | 9 +++++++++ holo-vrrp/src/interface.rs | 12 ++++++++---- holo-vrrp/src/southbound.rs | 13 +++---------- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/holo-interface/src/netlink.rs b/holo-interface/src/netlink.rs index 5343f0ee..61cb86c3 100644 --- a/holo-interface/src/netlink.rs +++ b/holo-interface/src/netlink.rs @@ -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"); diff --git a/holo-interface/src/northbound/configuration.rs b/holo-interface/src/northbound/configuration.rs index 62825c75..7305fa67 100644 --- a/holo-interface/src/northbound/configuration.rs +++ b/holo-interface/src/northbound/configuration.rs @@ -75,6 +75,15 @@ fn load_callbacks() -> Callbacks { 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(); diff --git a/holo-vrrp/src/interface.rs b/holo-vrrp/src/interface.rs index f133c06a..378ecc73 100644 --- a/holo-vrrp/src/interface.rs +++ b/holo-vrrp/src/interface.rs @@ -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, @@ -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(), @@ -128,7 +127,7 @@ 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, ); @@ -136,6 +135,11 @@ impl Interface { 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); } diff --git a/holo-vrrp/src/southbound.rs b/holo-vrrp/src/southbound.rs index ba77d5cf..046d56bf 100644 --- a/holo-vrrp/src/southbound.rs +++ b/holo-vrrp/src/southbound.rs @@ -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 {