Skip to content

Commit

Permalink
vrrp: recommended changes.
Browse files Browse the repository at this point in the history
Work on recommended changes based on previous
code review.

Signed-off-by: Paul Wekesa <[email protected]>
  • Loading branch information
Paul-weqe committed Oct 11, 2024
1 parent 3155aa1 commit 7218b3e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 33 deletions.
5 changes: 0 additions & 5 deletions holo-interface/src/ibus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,12 @@ pub(crate) fn notify_router_id_update(
}

pub(crate) fn notify_interface_update(ibus_tx: &IbusSender, iface: &Interface) {
let mut ip_addresses: Vec<IpNetwork> = vec![];
iface.addresses.iter().for_each(|(net, _addr)| {
ip_addresses.push(*net);
});
let msg = IbusMsg::InterfaceUpd(InterfaceUpdateMsg {
ifname: iface.name.clone(),
ifindex: iface.ifindex.unwrap_or(0),
mtu: iface.mtu.unwrap_or(0),
flags: iface.flags,
mac_address: iface.mac_address,
addresses: ip_addresses,
});
notify(ibus_tx, msg);
}
Expand Down
3 changes: 0 additions & 3 deletions holo-utils/src/southbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ pub struct InterfaceUpdateMsg {

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

#[serde(skip)]
pub addresses: Vec<IpNetwork>,
}

#[derive(Clone, Debug)]
Expand Down
4 changes: 3 additions & 1 deletion holo-vrrp/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use crate::packet::{ArpPacket, EthernetHdr, Ipv4Packet, VrrpHdr, VrrpPacket};
use crate::tasks::messages::input::VrrpNetRxPacketMsg;
use crate::tasks::messages::output::NetTxPacketMsg;

pub const MAX_VRRP_HDR_LENGTH: usize = 96;

pub fn socket_vrrp_tx(
interface: &Interface,
vrid: u8,
Expand Down Expand Up @@ -244,7 +246,7 @@ pub(crate) async fn vrrp_read_loop(
socket_vrrp: Arc<AsyncFd<Socket>>,
vrrp_net_packet_rxp: Sender<VrrpNetRxPacketMsg>,
) -> Result<(), SendError<VrrpNetRxPacketMsg>> {
let mut buf = [0u8; 96];
let mut buf = [0u8; MAX_VRRP_HDR_LENGTH];
loop {
match socket_vrrp
.async_io(tokio::io::Interest::READABLE, |sock| {
Expand Down
20 changes: 1 addition & 19 deletions holo-vrrp/src/southbound/rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
// SPDX-License-Identifier: MIT
//

use std::collections::BTreeSet;

use holo_utils::southbound::{AddressMsg, InterfaceUpdateMsg};
use ipnetwork::{IpNetwork, Ipv4Network};
use ipnetwork::IpNetwork;

use crate::interface::Interface;

Expand All @@ -23,14 +21,6 @@ pub(crate) fn process_iface_update(
iface.system.ifindex = Some(msg.ifindex);
iface.system.mac_address = msg.mac_address;

let mut ips: BTreeSet<Ipv4Network> = BTreeSet::default();
msg.addresses.iter().for_each(|addr| {
if let IpNetwork::V4(v4addr) = addr {
ips.insert(*v4addr);
}
});
iface.system.addresses = ips;

// update names for all macvlans
for (vrid, instance) in iface.instances.iter_mut() {
instance.mac_vlan.name = format!("mvlan-vrrp-{}", vrid);
Expand All @@ -50,14 +40,6 @@ pub(crate) fn process_iface_update(
mvlan_iface.system.ifindex = Some(msg.ifindex);
mvlan_iface.system.mac_address = msg.mac_address;

let mut ips: BTreeSet<Ipv4Network> = BTreeSet::default();
msg.addresses.iter().for_each(|addr| {
if let IpNetwork::V4(v4addr) = addr {
ips.insert(*v4addr);
}
});

mvlan_iface.system.addresses = ips;
target_vrid = Some(*vrid);

break 'outer;
Expand Down
8 changes: 3 additions & 5 deletions holo-vrrp/src/southbound/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
// SPDX-License-Identifier: MIT
//

use holo_utils::{
ibus::{IbusMsg, IbusSender},
southbound::{
InterfaceIpAddRequestMsg, InterfaceIpDeleteRequestMsg, MacvlanCreateMsg,
},
use holo_utils::ibus::{IbusMsg, IbusSender};
use holo_utils::southbound::{
InterfaceIpAddRequestMsg, InterfaceIpDeleteRequestMsg, MacvlanCreateMsg,
};
use ipnetwork::IpNetwork;

Expand Down

0 comments on commit 7218b3e

Please sign in to comment.