Skip to content

Commit 623d642

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

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
@@ -330,20 +330,17 @@ func (l *Link) SetVfVlan(vf string, vlan string) error {
330330
}
331331

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

339-
// TODO: pass as bool
340-
check := mode == "on"
341-
342339
return netlink.LinkSetVfSpoofchk(&netlink.GenericLink{
343340
LinkAttrs: netlink.LinkAttrs{
344341
Name: l.Name,
345342
},
346-
}, vfInt, check)
343+
}, vfInt, on)
347344
}
348345

349346
// VirtFuncInfo holds information about vf.

0 commit comments

Comments
 (0)