Skip to content

Commit

Permalink
cni: make sure mq and fq
Browse files Browse the repository at this point in the history
Signed-off-by: l1b0k <[email protected]>
  • Loading branch information
l1b0k committed Nov 28, 2024
1 parent 59d33ee commit 741cba4
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions plugin/datapath/policy_router_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (d *PolicyRoute) Setup(ctx context.Context, cfg *types.SetupConfig, netNS n
}

if cfg.BandwidthMode == types.BandwidthModeEDT && cfg.Egress > 0 {
err = ensureMQ(ctx, eni)
err = ensureMQFQ(ctx, eni)
if err != nil {
return err
}
Expand Down Expand Up @@ -496,34 +496,40 @@ func (d *PolicyRoute) Teardown(ctx context.Context, cfg *types.TeardownCfg, netN
return utils.DelEgressPriority(ctx, link, cfg.ContainerIPNet)
}

func ensureMQ(ctx context.Context, link netlink.Link) error {
mq := &netlink.GenericQdisc{
QdiscAttrs: netlink.QdiscAttrs{
LinkIndex: link.Attrs().Index,
Parent: netlink.HANDLE_ROOT,
},
QdiscType: "mq",
func ensureMQFQ(ctx context.Context, link netlink.Link) error {
// create mq at 1: root
err := utils.EnsureMQQdisc(ctx, link)
if err != nil {
return err
}

qds, err := netlink.QdiscList(link)
if err != nil {
return err
}
found := false
for _, qd := range qds {
if qd.Attrs().LinkIndex != link.Attrs().Index {
continue
}
if qd.Type() != mq.Type() {
// find parent is mq
major, minor := netlink.MajorMinor(qd.Attrs().Parent)
if major != 1 || minor == 0 {
continue
}
if qd.Attrs().Parent != mq.Parent {

if qd.Type() == "fq" {
continue
}

found = true
}
if found {
return nil
err = utils.QdiscReplace(ctx, &netlink.GenericQdisc{
QdiscAttrs: netlink.QdiscAttrs{
LinkIndex: link.Attrs().Index,
Parent: qd.Attrs().Parent,
},
QdiscType: "fq",
})
if err != nil {
return err
}
}
return utils.QdiscReplace(ctx, mq)
return nil
}

0 comments on commit 741cba4

Please sign in to comment.