Skip to content

Commit

Permalink
fix sriov-vf release mac reset
Browse files Browse the repository at this point in the history
this commit fix a mac reset issue when the sriov-cni failed to
configure the original mac address on vf release function on some
of them vendor nics

Signed-off-by: Sebastian Sch <sebassch@gmail.com>
  • Loading branch information
SchSeba committed Feb 21, 2023
1 parent 73704ad commit 3cd9071
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
22 changes: 21 additions & 1 deletion pkg/sriov/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,27 @@ func (s *sriovManager) ReleaseVF(conf *sriovtypes.NetConf, podifName string, cid
return fmt.Errorf("failed to parse original effective MAC address %s: %v", conf.OrigVfState.EffectiveMAC, err)
}

if err = s.nLink.LinkSetHardwareAddr(linkObj, hwaddr); err != nil {
/* Some NIC drivers (i.e. i40e/iavf) set VF MAC address asynchronously.
This means that we can get an error from the setHardwareAddr, or it may just fail silently
so to cover both cases we will retry the set function
and also check the mac address on the VF after the configuration.
*/
err = utils.Retry(10, 100*time.Millisecond, func() error {
if err := s.nLink.LinkSetHardwareAddr(linkObj, hwaddr); err != nil {
return err
}

linkObj, err = s.nLink.LinkByName(conf.OrigVfState.HostIFName)
if err != nil {
return fmt.Errorf("failed to get netlink device with name %s: %q", linkObj.Attrs().Name, err)
}
if linkObj.Attrs().HardwareAddr.String() != conf.OrigVfState.EffectiveMAC {
return fmt.Errorf("effective nic mac address is different from original one")
}

return nil
})
if err != nil {
return fmt.Errorf("failed to restore original effective netlink MAC address %s: %v", hwaddr, err)
}
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/sriov/sriov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ var _ = Describe("Sriov", func() {
}()
Expect(err).NotTo(HaveOccurred())
mocked := &mocks_utils.NetlinkManager{}
fakeLink := &FakeLink{netlink.LinkAttrs{Index: 1000, Name: "dummylink"}}
macaddr, err := net.ParseMAC("c6:c8:7f:1f:21:90")
Expect(err).NotTo(HaveOccurred())
fakeLink := &FakeLink{netlink.LinkAttrs{Index: 1000, Name: "dummylink", HardwareAddr: macaddr}}

mocked.On("LinkByName", netconf.ContIFNames).Return(fakeLink, nil)
mocked.On("LinkByName", netconf.OrigVfState.HostIFName).Return(fakeLink, nil)
mocked.On("LinkSetDown", fakeLink).Return(nil)
mocked.On("LinkSetName", fakeLink, netconf.OrigVfState.HostIFName).Return(nil)
mocked.On("LinkSetNsFd", fakeLink, mock.AnythingOfType("int")).Return(nil)
Expand Down

0 comments on commit 3cd9071

Please sign in to comment.