From a1c5e0237d0d52661dd0a42b0faf53585cb74ede Mon Sep 17 00:00:00 2001 From: Byoungchan Lee Date: Thu, 24 Aug 2023 16:44:48 +0900 Subject: [PATCH] Add support for TCA_HTB_DIRECT_QLEN in HTB qdisc - Extend Htb struct in qdisc.go to include DirectQlen field - Implement the DirectQlen option in qdisc_linux.go - Modify TestHtbAddDel test to validate DirectQlen changes --- qdisc.go | 2 ++ qdisc_linux.go | 8 +++++--- qdisc_test.go | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/qdisc.go b/qdisc.go index 6f5d6df..067743d 100644 --- a/qdisc.go +++ b/qdisc.go @@ -123,6 +123,7 @@ type Htb struct { Defcls uint32 Debug uint32 DirectPkts uint32 + DirectQlen *uint32 } func NewHtb(attrs QdiscAttrs) *Htb { @@ -133,6 +134,7 @@ func NewHtb(attrs QdiscAttrs) *Htb { Rate2Quantum: 10, Debug: 0, DirectPkts: 0, + DirectQlen: nil, } } diff --git a/qdisc_linux.go b/qdisc_linux.go index 9c53885..e732ae3 100644 --- a/qdisc_linux.go +++ b/qdisc_linux.go @@ -201,7 +201,9 @@ func qdiscPayload(req *nl.NetlinkRequest, qdisc Qdisc) error { opt.Debug = qdisc.Debug opt.DirectPkts = qdisc.DirectPkts options.AddRtAttr(nl.TCA_HTB_INIT, opt.Serialize()) - // options.AddRtAttr(nl.TCA_HTB_DIRECT_QLEN, opt.Serialize()) + if qdisc.DirectQlen != nil { + options.AddRtAttr(nl.TCA_HTB_DIRECT_QLEN, nl.Uint32Attr(*qdisc.DirectQlen)) + } case *Hfsc: opt := nl.TcHfscOpt{} opt.Defcls = qdisc.Defcls @@ -526,8 +528,8 @@ func parseHtbData(qdisc Qdisc, data []syscall.NetlinkRouteAttr) error { htb.Debug = opt.Debug htb.DirectPkts = opt.DirectPkts case nl.TCA_HTB_DIRECT_QLEN: - // TODO - //htb.DirectQlen = native.uint32(datum.Value) + directQlen := native.Uint32(datum.Value) + htb.DirectQlen = &directQlen } } return nil diff --git a/qdisc_test.go b/qdisc_test.go index 2430748..21c7786 100644 --- a/qdisc_test.go +++ b/qdisc_test.go @@ -87,6 +87,8 @@ func TestHtbAddDel(t *testing.T) { qdisc := NewHtb(attrs) qdisc.Rate2Quantum = 5 + directQlen := uint32(10) + qdisc.DirectQlen = &directQlen if err := QdiscAdd(qdisc); err != nil { t.Fatal(err) } @@ -111,6 +113,9 @@ func TestHtbAddDel(t *testing.T) { if htb.Debug != qdisc.Debug { t.Fatal("Debug doesn't match") } + if htb.DirectQlen == nil || *htb.DirectQlen != directQlen { + t.Fatalf("DirectQlen doesn't match. Expected %d, got %v", directQlen, htb.DirectQlen) + } if err := QdiscDel(qdisc); err != nil { t.Fatal(err) }