Skip to content

Commit

Permalink
vrrp: remove create mvlan bug.
Browse files Browse the repository at this point in the history
When creating the mvlan interface, the data being
received on the southbound has not been in sync
with the local state, therefore details such as
ifindex not correctly updated.
Modification of the calls made when creating a
macvlan interface have fixed this.

Signed-off-by: Paul Wekesa <[email protected]>
  • Loading branch information
Paul-weqe committed Sep 18, 2024
1 parent 7525ac5 commit dde744a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
4 changes: 2 additions & 2 deletions holo-vrrp/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ pub struct Statistics {
// ===== impl Instance =====

impl Instance {
pub(crate) fn new() -> Self {
pub(crate) fn new(vrid: u8) -> Self {
let mut inst = Instance {
config: Default::default(),
config: InstanceCfg::new(vrid),
state: InstanceState::new(),
timer: VrrpTimer::Null,
};
Expand Down
13 changes: 12 additions & 1 deletion holo-vrrp/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub struct ProtocolInputChannelsRx {

impl Interface {
pub(crate) fn create_instance(&mut self, vrid: u8) {
let instance = Instance::new();
let instance = Instance::new(vrid);
self.instances.insert(vrid, instance);

// `mvlan-vrrp{primary-interface-ifindex}{vrid}`
Expand Down Expand Up @@ -273,6 +273,17 @@ impl ProtocolInstance for Interface {
}
}

// ==== impl MacVlanInterface ====
impl MacVlanInterface {
pub fn new(vrid: u8) -> Self {
let name = format!("mvlan-vrrp-{}", vrid);
Self {
name,
system: InterfaceSys::default(),
}
}
}

// ===== impl InterfaceNet =====

impl InterfaceNet {
Expand Down
15 changes: 12 additions & 3 deletions holo-vrrp/src/northbound/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct InstanceCfg {
pub priority: u8,
pub advertise_interval: u8,
pub virtual_addresses: BTreeSet<Ipv4Network>,
pub mac_vlan: Option<MacVlanInterface>,
pub mac_vlan: MacVlanInterface,
}

// ===== callbacks =====
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Provider for Interface {
async fn process_event(&mut self, event: Event) {
match event {
Event::InstanceCreate { vrid } => {
let instance = Instance::new();
let instance = Instance::new(vrid);
self.instances.insert(vrid, instance);
}
Event::InstanceDelete { vrid } => {
Expand All @@ -183,6 +183,15 @@ impl Provider for Interface {
}
}

// ===== impl InstanceCfg ====
impl InstanceCfg {
pub fn new(vrid: u8) -> Self {
let mut cfg = InstanceCfg::default();
cfg.mac_vlan = MacVlanInterface::new(vrid);
cfg
}
}

// ===== configuration defaults =====

impl Default for InstanceCfg {
Expand All @@ -200,7 +209,7 @@ impl Default for InstanceCfg {
priority,
advertise_interval,
virtual_addresses: Default::default(),
mac_vlan: None,
mac_vlan: MacVlanInterface::new(0),
}
}
}
30 changes: 8 additions & 22 deletions holo-vrrp/src/southbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use holo_utils::southbound::{
};
use ipnetwork::IpNetwork;

use crate::interface::{Interface, MacVlanInterface};
use crate::interface::Interface;

// ===== global functions =====

Expand All @@ -28,35 +28,21 @@ pub(crate) fn process_iface_update(
// update names for all macvlans
for (vrid, instance) in iface.instances.iter_mut() {
let name = format!("mvlan-vrrp-{}", vrid);
if let Some(mvlan) = &mut instance.config.mac_vlan {
mvlan.name = name;
}
instance.config.mac_vlan.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-{}", vrid);
let mvlan_iface = &mut instance.config.mac_vlan;

if let Some(mvlan_iface) = &mut instance.config.mac_vlan {
if mvlan_iface.system.ifindex.unwrap() == msg.ifindex {
mvlan_iface.system.flags = msg.flags;
mvlan_iface.system.ifindex = Some(msg.ifindex);
mvlan_iface.system.mac_address = msg.mac_address;
return;
}
} else if msg.ifname == name {
let mvlan_iface = MacVlanInterface {
name,
system: crate::interface::InterfaceSys {
flags: msg.flags,
ifindex: Some(msg.ifindex),
addresses: Default::default(),
mac_address: msg.mac_address,
},
};
instance.config.mac_vlan = Some(mvlan_iface);
if mvlan_iface.name == name {
mvlan_iface.system.flags = msg.flags;
mvlan_iface.system.ifindex = Some(msg.ifindex);
mvlan_iface.system.mac_address = msg.mac_address;
return;
}
}
}
Expand Down

0 comments on commit dde744a

Please sign in to comment.