From adb577d4a45e341da53c4d9196ad4222c9a23e69 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Tue, 12 Mar 2019 12:34:31 -0700 Subject: [PATCH] Add support for IFLA_GSO_* IFLA_GSO_MAX_SIZE - maximum GSO segment size IFLA_GSO_MAX_SEGS - maximum number of GSO segments Signed-off-by: Andrei Vagin --- link.go | 2 ++ link_linux.go | 14 ++++++++++++++ link_test.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/link.go b/link.go index bbf117e..c142b22 100644 --- a/link.go +++ b/link.go @@ -41,6 +41,8 @@ type LinkAttrs struct { NetNsID int NumTxQueues int NumRxQueues int + GSOMaxSize uint32 + GSOMaxSegs uint32 Vfs []VfInfo // virtual functions available on link } diff --git a/link_linux.go b/link_linux.go index 855fabb..f7e4863 100644 --- a/link_linux.go +++ b/link_linux.go @@ -1118,6 +1118,16 @@ func (h *Handle) linkModify(link Link, flags int) error { req.AddData(rxqueues) } + if base.GSOMaxSegs > 0 { + gsoAttr := nl.NewRtAttr(unix.IFLA_GSO_MAX_SEGS, nl.Uint32Attr(base.GSOMaxSegs)) + req.AddData(gsoAttr) + } + + if base.GSOMaxSize > 0 { + gsoAttr := nl.NewRtAttr(unix.IFLA_GSO_MAX_SIZE, nl.Uint32Attr(base.GSOMaxSize)) + req.AddData(gsoAttr) + } + if base.Namespace != nil { var attr *nl.RtAttr switch ns := base.Namespace.(type) { @@ -1537,6 +1547,10 @@ func LinkDeserialize(hdr *unix.NlMsghdr, m []byte) (Link, error) { base.OperState = LinkOperState(uint8(attr.Value[0])) case unix.IFLA_LINK_NETNSID: base.NetNsID = int(native.Uint32(attr.Value[0:4])) + case unix.IFLA_GSO_MAX_SIZE: + base.GSOMaxSize = native.Uint32(attr.Value[0:4]) + case unix.IFLA_GSO_MAX_SEGS: + base.GSOMaxSegs = native.Uint32(attr.Value[0:4]) case unix.IFLA_VFINFO_LIST: data, err := nl.ParseRouteAttr(attr.Value) if err != nil { diff --git a/link_test.go b/link_test.go index e154204..98597fb 100644 --- a/link_test.go +++ b/link_test.go @@ -694,6 +694,36 @@ func TestLinkAddVethWithZeroTxQLen(t *testing.T) { } } +func TestLinkAddDelDummyWithGSO(t *testing.T) { + const ( + gsoMaxSegs = 16 + gsoMaxSize = 1 << 14 + ) + minKernelRequired(t, 4, 16) + tearDown := setUpNetlinkTest(t) + defer tearDown() + + dummy := &Dummy{LinkAttrs: LinkAttrs{Name: "foo", GSOMaxSize: gsoMaxSize, GSOMaxSegs: gsoMaxSegs}} + if err := LinkAdd(dummy); err != nil { + t.Fatal(err) + } + link, err := LinkByName("foo") + if err != nil { + t.Fatal(err) + } + dummy, ok := link.(*Dummy) + if !ok { + t.Fatalf("unexpected link type: %T", link) + } + + if dummy.GSOMaxSize != gsoMaxSize { + t.Fatalf("GSOMaxSize is %d, should be %d", dummy.GSOMaxSize, gsoMaxSize) + } + if dummy.GSOMaxSegs != gsoMaxSegs { + t.Fatalf("GSOMaxSeg is %d, should be %d", dummy.GSOMaxSegs, gsoMaxSegs) + } +} + func TestLinkAddDummyWithTxQLen(t *testing.T) { tearDown := setUpNetlinkTest(t) defer tearDown()