From 15bc50d972b114d0f875299159d93b8d9caa2065 Mon Sep 17 00:00:00 2001 From: Paul Wekesa Date: Sat, 14 Sep 2024 13:46:34 +0300 Subject: [PATCH] vrrp: automatic addition of mac address Introduce the automatic addition of a Mac Address. This will be implemented once PR 30(upgrading rtnetlink) has been merged. Signed-off-by: Paul Wekesa --- holo-interface/src/ibus.rs | 1 + holo-interface/src/interface.rs | 2 ++ holo-interface/src/netlink.rs | 9 ++++++--- holo-utils/src/southbound.rs | 1 + holo-vrrp/src/interface.rs | 2 ++ holo-vrrp/src/southbound.rs | 7 ++++++- 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/holo-interface/src/ibus.rs b/holo-interface/src/ibus.rs index 38b19a25..4dc1c402 100644 --- a/holo-interface/src/ibus.rs +++ b/holo-interface/src/ibus.rs @@ -63,6 +63,7 @@ pub(crate) async fn process_msg(master: &mut Master, msg: IbusMsg) { .create_macvlan_interface( &master.netlink_handle, &msg.parent_name, + msg.mac_address, msg.name, ) .await; diff --git a/holo-interface/src/interface.rs b/holo-interface/src/interface.rs index 5effd099..d4b24b46 100644 --- a/holo-interface/src/interface.rs +++ b/holo-interface/src/interface.rs @@ -412,6 +412,7 @@ impl Interfaces { &self, netlink_handle: &rtnetlink::Handle, parent_name: &str, + mac_address: Option<[u8; 6]>, mvlan_name: String, ) { if let Some(interface) = self.get_by_name(parent_name) { @@ -419,6 +420,7 @@ impl Interfaces { let _ = netlink::macvlan_create( netlink_handle, mvlan_name, + mac_address, ifindex, ) .await; diff --git a/holo-interface/src/netlink.rs b/holo-interface/src/netlink.rs index 61cb86c3..a162c47c 100644 --- a/holo-interface/src/netlink.rs +++ b/holo-interface/src/netlink.rs @@ -242,6 +242,7 @@ pub(crate) async fn vlan_create( pub(crate) async fn macvlan_create( handle: &Handle, name: String, + mac_address: Option<[u8; 6]>, parent_ifindex: u32, ) { // Create netlink request @@ -250,9 +251,11 @@ 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]); + + // will be uncommented on upgrade of rtnetlink + //if Some(address) = mac_address { + // request.address(address); + //} // Execute request. if let Err(error) = request.execute().await { diff --git a/holo-utils/src/southbound.rs b/holo-utils/src/southbound.rs index 860541c1..2fb71bc4 100644 --- a/holo-utils/src/southbound.rs +++ b/holo-utils/src/southbound.rs @@ -81,6 +81,7 @@ pub struct InterfaceUpdateMsg { pub struct MacvlanCreateMsg { pub parent_name: String, pub name: String, + pub mac_address: Option<[u8; 6]>, } #[derive(Clone, Debug)] diff --git a/holo-vrrp/src/interface.rs b/holo-vrrp/src/interface.rs index 378ecc73..149490fb 100644 --- a/holo-vrrp/src/interface.rs +++ b/holo-vrrp/src/interface.rs @@ -119,9 +119,11 @@ impl Interface { // `mvlan-vrrp{primary-interface-ifindex}{vrid}` let name = format!("mvlan-vrrp-{}", vrid); + let mac_address: [u8; 6] = [0x00, 0x00, 0x5e, 0x00, 0x01, vrid]; southbound::create_macvlan_address( name.clone(), self.name.clone(), + mac_address, // virtual mac address &self.tx.ibus, ); diff --git a/holo-vrrp/src/southbound.rs b/holo-vrrp/src/southbound.rs index 046d56bf..662dc200 100644 --- a/holo-vrrp/src/southbound.rs +++ b/holo-vrrp/src/southbound.rs @@ -89,9 +89,14 @@ pub(crate) fn process_addr_del(iface: &mut Interface, msg: AddressMsg) { pub(crate) fn create_macvlan_address( name: String, parent_name: String, + mac_address: [u8; 6], ibus_tx: &IbusSender, ) { - let msg = MacvlanCreateMsg { parent_name, name }; + let msg = MacvlanCreateMsg { + parent_name, + name, + mac_address: Some(mac_address), + }; let _ = ibus_tx.send(IbusMsg::CreateMacVlan(msg)); }