Skip to content

Commit

Permalink
Set MAC address after renaming the interface
Browse files Browse the repository at this point in the history
Setting the MAC address at the end of SetupVF reduces
the chances of race conditions with tools that set MAC i
address asynchronously (i.e. iavf).

Signed-off-by: Andrea Panattoni <apanatto@redhat.com>
  • Loading branch information
zeeke committed Sep 29, 2023
1 parent 5ccf2aa commit 11ea0a4
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions pkg/sriov/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sriov

import (
"fmt"

"github.com/containernetworking/plugins/pkg/ns"

sriovtypes "github.com/k8snetworkplumbingwg/sriov-cni/pkg/types"
Expand Down Expand Up @@ -80,29 +81,30 @@ func (s *sriovManager) SetupVF(conf *sriovtypes.NetConf, podifName string, netns

// Save the original effective MAC address before overriding it
conf.OrigVfState.EffectiveMAC = linkObj.Attrs().HardwareAddr.String()
// 3. Set MAC address
if conf.MAC != "" {
err = utils.SetVFEffectiveMAC(s.nLink, tempName, conf.MAC)
if err != nil {
return fmt.Errorf("failed to set netlink MAC address to %s: %v", conf.MAC, err)
}
}

// 4. Change netns
// 3. Change netns
if err := s.nLink.LinkSetNsFd(linkObj, int(netns.Fd())); err != nil {
return fmt.Errorf("failed to move IF %s to netns: %q", tempName, err)
}

if err := netns.Do(func(_ ns.NetNS) error {
// 5. Set Pod IF name
// 4. Set Pod IF name
if err := s.nLink.LinkSetName(linkObj, podifName); err != nil {
return fmt.Errorf("error setting container interface name %s for %s", linkName, tempName)
}

// 6. Enable IPv4 ARP notify and IPv6 Network Discovery notify
// 5. Enable IPv4 ARP notify and IPv6 Network Discovery notify
// Error is ignored here because enabling this feature is only a performance enhancement.
_ = s.utils.EnableArpAndNdiscNotify(podifName)

// 6. Set MAC address
if conf.MAC != "" {
err = utils.SetVFEffectiveMAC(s.nLink, podifName, conf.MAC)
if err != nil {
return fmt.Errorf("failed to set netlink MAC address to %s: %v", conf.MAC, err)
}
}

// 7. Bring IF up in Pod netns
if err := s.nLink.LinkSetUp(linkObj); err != nil {
return fmt.Errorf("error bringing interface up in container ns: %q", err)
Expand Down

0 comments on commit 11ea0a4

Please # to comment.