1
0
mirror of https://github.com/vishvananda/netlink synced 2025-02-19 05:36:54 +00:00

link: add LinkSetGSOMaxSize and LinkSetGROMaxSize

Add two new methods to allow setting GSO and GRO max size attributes only.
They make it much easier to enable BIG TCP[1].
The equivalent iproute2 commands are:
$ ip link set $link gso_max_size $maxSize
$ ip link set $link gro_max_size $maxSize

Also add tests for them.

[1] https://patchwork.kernel.org/project/netdevbpf/cover/20220513183408.686447-1-eric.dumazet@gmail.com/

Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
This commit is contained in:
Nikolay Aleksandrov 2022-06-06 15:05:29 +03:00 committed by Alessandro Boch
parent ef1d7077fb
commit 543bb1cade
4 changed files with 130 additions and 0 deletions

View File

@ -163,6 +163,14 @@ func (h *Handle) LinkSetGroup(link Link, group int) error {
return ErrNotImplemented
}
func (h *Handle) LinkSetGSOMaxSize(link Link, maxSize int) error {
return ErrNotImplemented
}
func (h *Handle) LinkSetGROMaxSize(link Link, maxSize int) error {
return ErrNotImplemented
}
func (h *Handle) setProtinfoAttr(link Link, mode bool, attr int) error {
return ErrNotImplemented
}

View File

@ -946,6 +946,60 @@ func LinkSetXdpFdWithFlags(link Link, fd, flags int) error {
return err
}
// LinkSetGSOMaxSize sets the GSO maximum size of the link device.
// Equivalent to: `ip link set $link gso_max_size $maxSize`
func LinkSetGSOMaxSize(link Link, maxSize int) error {
return pkgHandle.LinkSetGSOMaxSize(link, maxSize)
}
// LinkSetGSOMaxSize sets the GSO maximum size of the link device.
// Equivalent to: `ip link set $link gso_max_size $maxSize`
func (h *Handle) LinkSetGSOMaxSize(link Link, maxSize int) error {
base := link.Attrs()
h.ensureIndex(base)
req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
msg.Index = int32(base.Index)
req.AddData(msg)
b := make([]byte, 4)
native.PutUint32(b, uint32(maxSize))
data := nl.NewRtAttr(unix.IFLA_GSO_MAX_SIZE, b)
req.AddData(data)
_, err := req.Execute(unix.NETLINK_ROUTE, 0)
return err
}
// LinkSetGROMaxSize sets the GRO maximum size of the link device.
// Equivalent to: `ip link set $link gro_max_size $maxSize`
func LinkSetGROMaxSize(link Link, maxSize int) error {
return pkgHandle.LinkSetGROMaxSize(link, maxSize)
}
// LinkSetGROMaxSize sets the GRO maximum size of the link device.
// Equivalent to: `ip link set $link gro_max_size $maxSize`
func (h *Handle) LinkSetGROMaxSize(link Link, maxSize int) error {
base := link.Attrs()
h.ensureIndex(base)
req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
msg.Index = int32(base.Index)
req.AddData(msg)
b := make([]byte, 4)
native.PutUint32(b, uint32(maxSize))
data := nl.NewRtAttr(nl.IFLA_GRO_MAX_SIZE, b)
req.AddData(data)
_, err := req.Execute(unix.NETLINK_ROUTE, 0)
return err
}
func boolAttr(val bool) []byte {
var v uint8
if val {

View File

@ -2082,6 +2082,66 @@ func TestLinkAddDelVti(t *testing.T) {
Remote: net.IPv6loopback})
}
func TestLinkSetGSOMaxSize(t *testing.T) {
minKernelRequired(t, 5, 19)
tearDown := setUpNetlinkTest(t)
defer tearDown()
iface := &Veth{LinkAttrs: LinkAttrs{Name: "foo", TxQLen: testTxQLen, MTU: 1500}, PeerName: "bar"}
if err := LinkAdd(iface); err != nil {
t.Fatal(err)
}
link, err := LinkByName("foo")
if err != nil {
t.Fatal(err)
}
err = LinkSetGSOMaxSize(link, 32768)
if err != nil {
t.Fatal(err)
}
link, err = LinkByName("foo")
if err != nil {
t.Fatal(err)
}
if link.Attrs().GSOMaxSize != 32768 {
t.Fatalf("GSO max size was not modified")
}
}
func TestLinkSetGROMaxSize(t *testing.T) {
minKernelRequired(t, 5, 19)
tearDown := setUpNetlinkTest(t)
defer tearDown()
iface := &Veth{LinkAttrs: LinkAttrs{Name: "foo", TxQLen: testTxQLen, MTU: 1500}, PeerName: "bar"}
if err := LinkAdd(iface); err != nil {
t.Fatal(err)
}
link, err := LinkByName("foo")
if err != nil {
t.Fatal(err)
}
err = LinkSetGROMaxSize(link, 32768)
if err != nil {
t.Fatal(err)
}
link, err = LinkByName("foo")
if err != nil {
t.Fatal(err)
}
if link.Attrs().GROMaxSize != 32768 {
t.Fatalf("GRO max size was not modified")
}
}
func TestBridgeCreationWithMulticastSnooping(t *testing.T) {
minKernelRequired(t, 4, 4)

View File

@ -124,6 +124,14 @@ func LinkSetTxQLen(link Link, qlen int) error {
return ErrNotImplemented
}
func LinkSetGSOMaxSize(link Link, maxSize int) error {
return ErrNotImplemented
}
func LinkSetGROMaxSize(link Link, maxSize int) error {
return ErrNotImplemented
}
func LinkAdd(link Link) error {
return ErrNotImplemented
}