From e104583c52ed7865c2cb5c867943d46500669a25 Mon Sep 17 00:00:00 2001 From: Tomofumi Hayashi Date: Sun, 23 Apr 2017 12:50:30 +0900 Subject: [PATCH] Support num{tx,rx}queues and udp6zerocsum{tx,rx} Add IFLA_NUM_TX_QUEUES and IFLA_NUM_RX_QUEUES in link attribute and IFLA_VXLAN_UDP_ZERO_CSUM6_TX and IFLA_VXLAN_UDP_ZERO_CSUM6_RX in VXLAN attribute. --- link.go | 44 ++++++++++++++++++++++------------------- link_linux.go | 16 +++++++++++++++ link_test.go | 55 ++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 88 insertions(+), 27 deletions(-) diff --git a/link.go b/link.go index 8c9ec51..78cdbb1 100644 --- a/link.go +++ b/link.go @@ -38,6 +38,8 @@ type LinkAttrs struct { Protinfo *Protinfo OperState LinkOperState NetNsID int + NumTxQueues int + NumRxQueues int } // LinkOperState represents the values of the IFLA_OPERSTATE link @@ -327,26 +329,28 @@ func (generic *GenericLink) Type() string { type Vxlan struct { LinkAttrs - VxlanId int - VtepDevIndex int - SrcAddr net.IP - Group net.IP - TTL int - TOS int - Learning bool - Proxy bool - RSC bool - L2miss bool - L3miss bool - UDPCSum bool - NoAge bool - GBP bool - FlowBased bool - Age int - Limit int - Port int - PortLow int - PortHigh int + VxlanId int + VtepDevIndex int + SrcAddr net.IP + Group net.IP + TTL int + TOS int + Learning bool + Proxy bool + RSC bool + L2miss bool + L3miss bool + UDPCSum bool + UDP6ZeroCSumTx bool + UDP6ZeroCSumRx bool + NoAge bool + GBP bool + FlowBased bool + Age int + Limit int + Port int + PortLow int + PortHigh int } func (vxlan *Vxlan) Attrs() *LinkAttrs { diff --git a/link_linux.go b/link_linux.go index 09008b9..7392d16 100644 --- a/link_linux.go +++ b/link_linux.go @@ -643,6 +643,8 @@ func addVxlanAttrs(vxlan *Vxlan, linkInfo *nl.RtAttr) { nl.NewRtAttrChild(data, nl.IFLA_VXLAN_RSC, boolAttr(vxlan.RSC)) nl.NewRtAttrChild(data, nl.IFLA_VXLAN_L2MISS, boolAttr(vxlan.L2miss)) nl.NewRtAttrChild(data, nl.IFLA_VXLAN_L3MISS, boolAttr(vxlan.L3miss)) + nl.NewRtAttrChild(data, nl.IFLA_VXLAN_UDP_ZERO_CSUM6_TX, boolAttr(vxlan.UDP6ZeroCSumTx)) + nl.NewRtAttrChild(data, nl.IFLA_VXLAN_UDP_ZERO_CSUM6_RX, boolAttr(vxlan.UDP6ZeroCSumRx)) if vxlan.UDPCSum { nl.NewRtAttrChild(data, nl.IFLA_VXLAN_UDP_CSUM, boolAttr(vxlan.UDPCSum)) @@ -885,6 +887,16 @@ func (h *Handle) linkModify(link Link, flags int) error { req.AddData(hwaddr) } + if base.NumTxQueues > 0 { + txqueues := nl.NewRtAttr(nl.IFLA_NUM_TX_QUEUES, nl.Uint32Attr(uint32(base.NumTxQueues))) + req.AddData(txqueues) + } + + if base.NumRxQueues > 0 { + rxqueues := nl.NewRtAttr(nl.IFLA_NUM_RX_QUEUES, nl.Uint32Attr(uint32(base.NumRxQueues))) + req.AddData(rxqueues) + } + if base.Namespace != nil { var attr *nl.RtAttr switch base.Namespace.(type) { @@ -1560,6 +1572,10 @@ func parseVxlanData(link Link, data []syscall.NetlinkRouteAttr) { vxlan.L3miss = int8(datum.Value[0]) != 0 case nl.IFLA_VXLAN_UDP_CSUM: vxlan.UDPCSum = int8(datum.Value[0]) != 0 + case nl.IFLA_VXLAN_UDP_ZERO_CSUM6_TX: + vxlan.UDP6ZeroCSumTx = int8(datum.Value[0]) != 0 + case nl.IFLA_VXLAN_UDP_ZERO_CSUM6_RX: + vxlan.UDP6ZeroCSumRx = int8(datum.Value[0]) != 0 case nl.IFLA_VXLAN_GBP: vxlan.GBP = true case nl.IFLA_VXLAN_FLOWBASED: diff --git a/link_test.go b/link_test.go index 0623754..b83541f 100644 --- a/link_test.go +++ b/link_test.go @@ -17,6 +17,8 @@ import ( const ( testTxQLen int = 100 defaultTxQLen int = 1000 + testTxQueues int = 1 + testRxQueues int = 1 ) func testLinkAddDel(t *testing.T, link Link) { @@ -250,6 +252,12 @@ func compareVxlan(t *testing.T, expected, actual *Vxlan) { if actual.FlowBased != expected.FlowBased { t.Fatal("Vxlan.FlowBased doesn't match") } + if actual.UDP6ZeroCSumTx != expected.UDP6ZeroCSumTx { + t.Fatal("Vxlan.UDP6ZeroCSumTx doesn't match") + } + if actual.UDP6ZeroCSumRx != expected.UDP6ZeroCSumRx { + t.Fatal("Vxlan.UDP6ZeroCSumRx doesn't match") + } if expected.NoAge { if !actual.NoAge { t.Fatal("Vxlan.NoAge doesn't match") @@ -431,7 +439,7 @@ func TestLinkAddDelVeth(t *testing.T) { tearDown := setUpNetlinkTest(t) defer tearDown() - veth := &Veth{LinkAttrs: LinkAttrs{Name: "foo", TxQLen: testTxQLen, MTU: 1400}, PeerName: "bar"} + veth := &Veth{LinkAttrs: LinkAttrs{Name: "foo", TxQLen: testTxQLen, MTU: 1400, NumTxQueues: testTxQueues, NumRxQueues: testRxQueues}, PeerName: "bar"} testLinkAddDel(t, veth) } @@ -730,6 +738,37 @@ func TestLinkAddDelVxlan(t *testing.T) { } } +func TestLinkAddDelVxlanUdpCSum6(t *testing.T) { + minKernelRequired(t, 3, 16) + tearDown := setUpNetlinkTest(t) + defer tearDown() + + parent := &Dummy{ + LinkAttrs{Name: "foo"}, + } + if err := LinkAdd(parent); err != nil { + t.Fatal(err) + } + + vxlan := Vxlan{ + LinkAttrs: LinkAttrs{ + Name: "bar", + }, + VxlanId: 10, + VtepDevIndex: parent.Index, + Learning: true, + L2miss: true, + L3miss: true, + UDP6ZeroCSumTx: true, + UDP6ZeroCSumRx: true, + } + + testLinkAddDel(t, &vxlan) + if err := LinkDel(parent); err != nil { + t.Fatal(err) + } +} + func TestLinkAddDelVxlanGbp(t *testing.T) { minKernelRequired(t, 4, 0) @@ -747,12 +786,14 @@ func TestLinkAddDelVxlanGbp(t *testing.T) { LinkAttrs: LinkAttrs{ Name: "bar", }, - VxlanId: 10, - VtepDevIndex: parent.Index, - Learning: true, - L2miss: true, - L3miss: true, - GBP: true, + VxlanId: 10, + VtepDevIndex: parent.Index, + Learning: true, + L2miss: true, + L3miss: true, + UDP6ZeroCSumTx: true, + UDP6ZeroCSumRx: true, + GBP: true, } testLinkAddDel(t, &vxlan)