Skip to content

Commit e2d12a6

Browse files
committed
incusd/ip/link: Refactor SetVfSpoofchk mode parameter to bool
Signed-off-by: Gwendolyn <[email protected]>
1 parent 6c18c08 commit e2d12a6

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

internal/server/device/device_utils_network.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ func networkSRIOVSetupVF(d deviceCommon, vfParent string, vfDevice string, vfID
786786
}
787787

788788
// Now that MAC is set on VF, we can enable spoof checking.
789-
err = link.SetVfSpoofchk(volatile["last_state.vf.id"], "on")
789+
err = link.SetVfSpoofchk(volatile["last_state.vf.id"], true)
790790
if err != nil {
791791
return vfPCIDev, 0, fmt.Errorf("Failed enabling spoof check for VF %q: %w", volatile["last_state.vf.id"], err)
792792
}
@@ -799,7 +799,7 @@ func networkSRIOVSetupVF(d deviceCommon, vfParent string, vfDevice string, vfID
799799

800800
if useSpoofCheck {
801801
// Ensure spoof checking is disabled if not enabled in instance (only for real VF).
802-
err = link.SetVfSpoofchk(volatile["last_state.vf.id"], "off")
802+
err = link.SetVfSpoofchk(volatile["last_state.vf.id"], false)
803803
if err != nil {
804804
return vfPCIDev, 0, fmt.Errorf("Failed disabling spoof check for VF %q: %w", volatile["last_state.vf.id"], err)
805805
}
@@ -912,13 +912,8 @@ func networkSRIOVRestoreVF(d deviceCommon, useSpoofCheck bool, volatile map[stri
912912
// Reset VF MAC spoofing protection if recorded. Do this first before resetting the MAC
913913
// to avoid any issues with zero MACs refusing to be set whilst spoof check is on.
914914
if useSpoofCheck && volatile["last_state.vf.spoofcheck"] != "" {
915-
mode := "off"
916-
if util.IsTrue(volatile["last_state.vf.spoofcheck"]) {
917-
mode = "on"
918-
}
919-
920915
link := &ip.Link{Name: parent}
921-
err := link.SetVfSpoofchk(volatile["last_state.vf.id"], mode)
916+
err := link.SetVfSpoofchk(volatile["last_state.vf.id"], util.IsTrue(volatile["last_state.vf.spoofcheck"]))
922917
if err != nil {
923918
return err
924919
}

internal/server/ip/link.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -334,20 +334,17 @@ func (l *Link) SetVfVlan(vf string, vlan string) error {
334334
}
335335

336336
// SetVfSpoofchk turns packet spoof checking on or off for the specified VF.
337-
func (l *Link) SetVfSpoofchk(vf string, mode string) error {
337+
func (l *Link) SetVfSpoofchk(vf string, on bool) error {
338338
vfInt, err := strconv.Atoi(vf)
339339
if err != nil {
340340
return err
341341
}
342342

343-
// TODO: pass as bool
344-
check := mode == "on"
345-
346343
return netlink.LinkSetVfSpoofchk(&netlink.GenericLink{
347344
LinkAttrs: netlink.LinkAttrs{
348345
Name: l.Name,
349346
},
350-
}, vfInt, check)
347+
}, vfInt, on)
351348
}
352349

353350
// VirtFuncInfo holds information about vf.

0 commit comments

Comments
 (0)