From f5a7afb3d4921f978b54db4b62ea5ffa9163bbfb Mon Sep 17 00:00:00 2001 From: hedi bouattour Date: Thu, 9 Jan 2025 17:46:31 +0000 Subject: [PATCH 1/2] add mac address to memif spec in annotations --- calico-vpp-agent/cni/pod_interface/memif.go | 7 +++++++ calico-vpp-agent/cni/storage/storage.go | 2 +- config/config.go | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/calico-vpp-agent/cni/pod_interface/memif.go b/calico-vpp-agent/cni/pod_interface/memif.go index 791066e51..a12f8e8a8 100644 --- a/calico-vpp-agent/cni/pod_interface/memif.go +++ b/calico-vpp-agent/cni/pod_interface/memif.go @@ -17,6 +17,7 @@ package pod_interface import ( "fmt" + "net" "github.com/containernetworking/plugins/pkg/ns" "github.com/pkg/errors" @@ -83,6 +84,12 @@ func (i *MemifPodInterfaceDriver) CreateInterface(podSpec *storage.LocalPodSpec, } if *usedIfSpec.IsL3 { memif.Mode = types.MemifModeIP + } else if podSpec.NetworkName == "" && podSpec.PBLMemifSpec.Mac != "" { + pblMac, err := net.ParseMAC(podSpec.PBLMemifSpec.Mac) + if err != nil { + return err + } + memif.MacAddress = pblMac } err = i.vpp.CreateMemif(memif) diff --git a/calico-vpp-agent/cni/storage/storage.go b/calico-vpp-agent/cni/storage/storage.go index 28b3847f9..47ce87ecc 100644 --- a/calico-vpp-agent/cni/storage/storage.go +++ b/calico-vpp-agent/cni/storage/storage.go @@ -35,7 +35,7 @@ import ( ) const ( - CniServerStateFileVersion = 8 // Used to ensure compatibility wen we reload data + CniServerStateFileVersion = 9 // Used to ensure compatibility wen we reload data MaxApiTagLen = 63 /* No more than 64 characters in API tags */ VrfTagHashLen = 8 /* how many hash charatecters (b64) of the name in tag prefix (useful when trucated) */ ) diff --git a/config/config.go b/config/config.go index 3fcda0caf..9ef6f863a 100644 --- a/config/config.go +++ b/config/config.go @@ -176,6 +176,7 @@ type InterfaceSpec struct { IsL3 *bool `json:"isl3"` /* "interrupt" "adaptive" or "polling" mode */ RxMode types.RxMode `json:"rxMode"` + Mac string `json:"mac"` } func (i *InterfaceSpec) GetIsL3(isMemif bool) bool { From 2e44c03196fb4ec4ea8dab44ff6e29c6e2499cdf Mon Sep 17 00:00:00 2001 From: hedi bouattour Date: Mon, 13 Jan 2025 10:38:48 +0000 Subject: [PATCH 2/2] add mac address to tap in annotations --- calico-vpp-agent/cni/pod_interface/tuntap.go | 8 ++++++++ calico-vpp-agent/cni/storage/storage.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/calico-vpp-agent/cni/pod_interface/tuntap.go b/calico-vpp-agent/cni/pod_interface/tuntap.go index 875b5fd40..6e8ab504f 100644 --- a/calico-vpp-agent/cni/pod_interface/tuntap.go +++ b/calico-vpp-agent/cni/pod_interface/tuntap.go @@ -149,6 +149,14 @@ func (i *TunTapPodInterfaceDriver) CreateInterface(podSpec *storage.LocalPodSpec HostMtu: i.computePodMtu(podSpec.Mtu, i.felixConfig, i.ipipEncapRefCounts > 0, i.vxlanEncapRefCounts > 0), } + if podSpec.IfSpec.Mac != "" { + i.log.Debugf("mac address specified for interface %s in vpp: '%s'", podSpec.InterfaceName, podSpec.IfSpec.Mac) + mac, err := net.ParseMAC("02:00:00:00:00:02") + if err != nil { + return err + } + tun.HardwareAddr = mac + } if *podSpec.IfSpec.IsL3 { tun.Flags |= types.TapFlagTun } diff --git a/calico-vpp-agent/cni/storage/storage.go b/calico-vpp-agent/cni/storage/storage.go index 47ce87ecc..407ee29fb 100644 --- a/calico-vpp-agent/cni/storage/storage.go +++ b/calico-vpp-agent/cni/storage/storage.go @@ -35,7 +35,7 @@ import ( ) const ( - CniServerStateFileVersion = 9 // Used to ensure compatibility wen we reload data + CniServerStateFileVersion = 10 // Used to ensure compatibility wen we reload data MaxApiTagLen = 63 /* No more than 64 characters in API tags */ VrfTagHashLen = 8 /* how many hash charatecters (b64) of the name in tag prefix (useful when trucated) */ )