From 6afddb37c1f00693528264222a57a3c08dccbab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20G=C3=B6gge?= Date: Sat, 22 Jul 2023 19:51:51 +0200 Subject: [PATCH] Fix FlowBased support for Geneve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The IFLA_GENEVE_COLLECT_METADATA netlink attribute shouldn't have any a payload. For Geneve devices also other attributes can be set next to FlowBased, however the VNI needs to be 0. This commit also adds a test for creating a Geneve device in FlowBased mode. Signed-off-by: Robin Gögge --- link_linux.go | 7 ++++--- link_test.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/link_linux.go b/link_linux.go index 5979d09..a2c6b47 100644 --- a/link_linux.go +++ b/link_linux.go @@ -2778,9 +2778,8 @@ func addGeneveAttrs(geneve *Geneve, linkInfo *nl.RtAttr) { data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil) if geneve.FlowBased { - // In flow based mode, no other attributes need to be configured - linkInfo.AddRtAttr(nl.IFLA_GENEVE_COLLECT_METADATA, boolAttr(geneve.FlowBased)) - return + geneve.ID = 0 + data.AddRtAttr(nl.IFLA_GENEVE_COLLECT_METADATA, []byte{}) } if ip := geneve.Remote; ip != nil { @@ -2822,6 +2821,8 @@ func parseGeneveData(link Link, data []syscall.NetlinkRouteAttr) { geneve.Ttl = uint8(datum.Value[0]) case nl.IFLA_GENEVE_TOS: geneve.Tos = uint8(datum.Value[0]) + case nl.IFLA_GENEVE_COLLECT_METADATA: + geneve.FlowBased = true } } } diff --git a/link_test.go b/link_test.go index a6d3514..e70c254 100644 --- a/link_test.go +++ b/link_test.go @@ -341,6 +341,10 @@ func compareGeneve(t *testing.T, expected, actual *Geneve) { t.Fatalf("Geneve.Remote is not equal: %s!=%s", actual.Remote, expected.Remote) } + if actual.FlowBased != expected.FlowBased { + t.Fatal("Geneve.FlowBased doesn't match") + } + // TODO: we should implement the rest of the geneve methods } @@ -661,6 +665,16 @@ func TestLinkAddDelGeneve(t *testing.T) { Remote: net.ParseIP("2001:db8:ef33::2")}) } +func TestLinkAddDelGeneveFlowBased(t *testing.T) { + tearDown := setUpNetlinkTest(t) + defer tearDown() + + testLinkAddDel(t, &Geneve{ + LinkAttrs: LinkAttrs{Name: "foo"}, + Dport: 1234, + FlowBased: true}) +} + func TestGeneveCompareToIP(t *testing.T) { ns, tearDown := setUpNamedNetlinkTest(t) defer tearDown()