Skip to content

Commit

Permalink
vrrp: automatic addition of mac address
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Paul-weqe committed Sep 14, 2024
1 parent 754a2a3 commit 15bc50d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions holo-interface/src/ibus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions holo-interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,15 @@ 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) {
if let Some(ifindex) = interface.ifindex {
let _ = netlink::macvlan_create(
netlink_handle,
mvlan_name,
mac_address,
ifindex,
)
.await;
Expand Down
9 changes: 6 additions & 3 deletions holo-interface/src/netlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions holo-utils/src/southbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 2 additions & 0 deletions holo-vrrp/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down
7 changes: 6 additions & 1 deletion holo-vrrp/src/southbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit 15bc50d

Please sign in to comment.