@@ -15,6 +15,7 @@ import (
15
15
16
16
"github.com/mdlayher/arp"
17
17
"github.com/mdlayher/ndp"
18
+ "golang.org/x/sys/unix"
18
19
19
20
deviceConfig "github.com/lxc/incus/v6/internal/server/device/config"
20
21
pcidev "github.com/lxc/incus/v6/internal/server/device/pci"
@@ -216,13 +217,13 @@ func networkCreateVethPair(hostName string, m deviceConfig.Device) (string, uint
216
217
217
218
veth := & ip.Veth {
218
219
Link : ip.Link {
219
- Name : hostName ,
220
- Up : true ,
220
+ Name : hostName ,
221
+ Up : true ,
222
+ Master : m ["vrf" ],
221
223
},
222
224
Peer : ip.Link {
223
225
Name : network .RandomDevName ("veth" ),
224
226
},
225
- Master : m ["vrf" ],
226
227
}
227
228
228
229
// Set the MTU on both ends.
@@ -412,20 +413,20 @@ func networkNICRouteAdd(routeDev string, routes ...string) error {
412
413
413
414
for _ , r := range routes {
414
415
route := r // Local var for revert.
415
- ipAddress , _ , err := net . ParseCIDR (route )
416
+ ipNet , err := ip . ParseIPNet (route )
416
417
if err != nil {
417
418
return fmt .Errorf ("Invalid route %q: %w" , route , err )
418
419
}
419
420
420
421
ipVersion := ip .FamilyV4
421
- if ipAddress .To4 () == nil {
422
+ if ipNet . IP .To4 () == nil {
422
423
ipVersion = ip .FamilyV6
423
424
}
424
425
425
426
// Add IP route (using boot proto to avoid conflicts with network defined static routes).
426
427
r := & ip.Route {
427
428
DevName : routeDev ,
428
- Route : route ,
429
+ Route : ipNet ,
429
430
Proto : "boot" ,
430
431
Family : ipVersion ,
431
432
}
@@ -438,7 +439,7 @@ func networkNICRouteAdd(routeDev string, routes ...string) error {
438
439
reverter .Add (func () {
439
440
r := & ip.Route {
440
441
DevName : routeDev ,
441
- Route : route ,
442
+ Route : ipNet ,
442
443
Proto : "boot" ,
443
444
Family : ipVersion ,
444
445
}
@@ -466,21 +467,21 @@ func networkNICRouteDelete(routeDev string, routes ...string) {
466
467
467
468
for _ , r := range routes {
468
469
route := r // Local var for revert.
469
- ipAddress , _ , err := net . ParseCIDR (route )
470
+ ipNet , err := ip . ParseIPNet (route )
470
471
if err != nil {
471
472
logger .Errorf ("Failed to remove static route %q to %q: %v" , route , routeDev , err )
472
473
continue
473
474
}
474
475
475
476
ipVersion := ip .FamilyV4
476
- if ipAddress .To4 () == nil {
477
+ if ipNet . IP .To4 () == nil {
477
478
ipVersion = ip .FamilyV6
478
479
}
479
480
480
481
// Add IP route (using boot proto to avoid conflicts with network defined static routes).
481
482
r := & ip.Route {
482
483
DevName : routeDev ,
483
- Route : route ,
484
+ Route : ipNet ,
484
485
Proto : "boot" ,
485
486
Family : ipVersion ,
486
487
}
@@ -527,14 +528,21 @@ func networkSetupHostVethLimits(d *deviceCommon, oldConfig deviceConfig.Device,
527
528
}
528
529
529
530
// Clean any existing entry
530
- qdisc := & ip.Qdisc {Dev : veth , Root : true }
531
- _ = qdisc .Delete ()
532
- qdisc = & ip.Qdisc {Dev : veth , Ingress : true }
533
- _ = qdisc .Delete ()
531
+ qdiscIngress := & ip.QdiscIngress {Qdisc : ip.Qdisc {Dev : veth , Handle : "ffff:0" }}
532
+ err = qdiscIngress .Delete ()
533
+ if err != nil && ! errors .Is (err , unix .ENOENT ) {
534
+ return err
535
+ }
536
+
537
+ qdiscHTB := & ip.QdiscHTB {Qdisc : ip.Qdisc {Dev : veth , Handle : "1:0" , Parent : "root" }}
538
+ err = qdiscHTB .Delete ()
539
+ if err != nil && ! errors .Is (err , unix .ENOENT ) {
540
+ return err
541
+ }
534
542
535
543
// Apply new limits
536
544
if d .config ["limits.ingress" ] != "" {
537
- qdiscHTB : = & ip.QdiscHTB {Qdisc : ip.Qdisc {Dev : veth , Handle : "1:0" , Root : true }, Default : "10" }
545
+ qdiscHTB = & ip.QdiscHTB {Qdisc : ip.Qdisc {Dev : veth , Handle : "1:0" , Parent : "root" }, Default : 10 }
538
546
err := qdiscHTB .Add ()
539
547
if err != nil {
540
548
return fmt .Errorf ("Failed to create root tc qdisc: %s" , err )
@@ -546,22 +554,22 @@ func networkSetupHostVethLimits(d *deviceCommon, oldConfig deviceConfig.Device,
546
554
return fmt .Errorf ("Failed to create limit tc class: %s" , err )
547
555
}
548
556
549
- filter := & ip.U32Filter {Filter : ip.Filter {Dev : veth , Parent : "1:0" , Protocol : "all" , Flowid : "1:1" }, Value : "0" , Mask : "0" }
557
+ filter := & ip.U32Filter {Filter : ip.Filter {Dev : veth , Parent : "1:0" , Protocol : "all" , Flowid : "1:1" }, Value : 0 , Mask : 0 }
550
558
err = filter .Add ()
551
559
if err != nil {
552
560
return fmt .Errorf ("Failed to create tc filter: %s" , err )
553
561
}
554
562
}
555
563
556
564
if d .config ["limits.egress" ] != "" {
557
- qdisc = & ip.Qdisc {Dev : veth , Handle : "ffff:0" , Ingress : true }
558
- err := qdisc .Add ()
565
+ qdiscIngress = & ip.QdiscIngress { Qdisc : ip. Qdisc {Dev : veth , Handle : "ffff:0" } }
566
+ err := qdiscIngress .Add ()
559
567
if err != nil {
560
568
return fmt .Errorf ("Failed to create ingress tc qdisc: %s" , err )
561
569
}
562
570
563
- police := & ip.ActionPolice {Rate : fmt . Sprintf ( "%dbit" , egressInt ), Burst : fmt . Sprintf ( "%d" , egressInt / 40 ), Mtu : "64kb" , Drop : true }
564
- filter := & ip.U32Filter {Filter : ip.Filter {Dev : veth , Parent : "ffff:0" , Protocol : "all" }, Value : "0" , Mask : "0" , Actions : []ip.Action {police }}
571
+ police := & ip.ActionPolice {Rate : uint32 ( egressInt / 8 ), Burst : uint32 ( egressInt / 40 ), Mtu : 65535 , Drop : true }
572
+ filter := & ip.U32Filter {Filter : ip.Filter {Dev : veth , Parent : "ffff:0" , Protocol : "all" }, Value : 0 , Mask : 0 , Actions : []ip.Action {police }}
565
573
err = filter .Add ()
566
574
if err != nil {
567
575
return fmt .Errorf ("Failed to create ingress tc filter: %s" , err )
@@ -690,7 +698,7 @@ func bgpRemovePrefix(d *deviceCommon, config map[string]string) error {
690
698
return nil
691
699
}
692
700
693
- // networkSRIOVParentVFInfo returns info about an SR-IOV virtual function from the parent NIC using the ip tool .
701
+ // networkSRIOVParentVFInfo returns info about an SR-IOV virtual function from the parent NIC.
694
702
func networkSRIOVParentVFInfo (vfParent string , vfID int ) (ip.VirtFuncInfo , error ) {
695
703
link := & ip.Link {Name : vfParent }
696
704
vfi , err := link .GetVFInfo (vfID )
@@ -716,9 +724,9 @@ func networkSRIOVSetupVF(d deviceCommon, vfParent string, vfDevice string, vfID
716
724
717
725
// Record properties of VF settings on the parent device.
718
726
volatile ["last_state.vf.parent" ] = vfParent
719
- volatile ["last_state.vf.hwaddr" ] = vfInfo .Address
727
+ volatile ["last_state.vf.hwaddr" ] = vfInfo .Address . String ()
720
728
volatile ["last_state.vf.id" ] = fmt .Sprintf ("%d" , vfID )
721
- volatile ["last_state.vf.vlan" ] = fmt .Sprintf ("%d" , vfInfo .VLANs [ 0 ][ "vlan" ] )
729
+ volatile ["last_state.vf.vlan" ] = fmt .Sprintf ("%d" , vfInfo .VLAN )
722
730
volatile ["last_state.vf.spoofcheck" ] = fmt .Sprintf ("%t" , vfInfo .SpoofCheck )
723
731
724
732
// Record the host interface we represents the VF device which we will move into instance.
@@ -772,7 +780,7 @@ func networkSRIOVSetupVF(d deviceCommon, vfParent string, vfDevice string, vfID
772
780
}
773
781
774
782
// Now that MAC is set on VF, we can enable spoof checking.
775
- err = link .SetVfSpoofchk (volatile ["last_state.vf.id" ], "on" )
783
+ err = link .SetVfSpoofchk (volatile ["last_state.vf.id" ], true )
776
784
if err != nil {
777
785
return vfPCIDev , 0 , fmt .Errorf ("Failed enabling spoof check for VF %q: %w" , volatile ["last_state.vf.id" ], err )
778
786
}
@@ -784,7 +792,7 @@ func networkSRIOVSetupVF(d deviceCommon, vfParent string, vfDevice string, vfID
784
792
_ = link .SetVfAddress (volatile ["last_state.vf.id" ], "00:00:00:00:00:00" )
785
793
786
794
// Ensure spoof checking is disabled if not enabled in instance (only for real VF).
787
- err = link .SetVfSpoofchk (volatile ["last_state.vf.id" ], "off" )
795
+ err = link .SetVfSpoofchk (volatile ["last_state.vf.id" ], false )
788
796
if err != nil && d .config ["security.mac_filtering" ] != "" {
789
797
return vfPCIDev , 0 , fmt .Errorf ("Failed disabling spoof check for VF %q: %w" , volatile ["last_state.vf.id" ], err )
790
798
}
@@ -897,11 +905,7 @@ func networkSRIOVRestoreVF(d deviceCommon, useSpoofCheck bool, volatile map[stri
897
905
// Reset VF MAC spoofing protection if recorded. Do this first before resetting the MAC
898
906
// to avoid any issues with zero MACs refusing to be set whilst spoof check is on.
899
907
if volatile ["last_state.vf.spoofcheck" ] != "" {
900
- mode := "off"
901
- if util .IsTrue (volatile ["last_state.vf.spoofcheck" ]) {
902
- mode = "on"
903
- }
904
-
908
+ mode := util .IsTrue (volatile ["last_state.vf.spoofcheck" ])
905
909
link := & ip.Link {Name : parent }
906
910
err := link .SetVfSpoofchk (volatile ["last_state.vf.id" ], mode )
907
911
if err != nil && d .config ["security.mac_filtering" ] != "" {
0 commit comments