From 16d31db2358884ece09bbbaa2b754c225c788032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20G=C3=B6gge?= Date: Thu, 13 Jul 2023 15:24:58 +0200 Subject: [PATCH] Fix FlowBased support for Iptun MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IFLA_IPTUN_COLLECT_METADATA is a "flag" netlink attribute, and shouldn't have any payload. This also needs to be considered when parsing netlink messages for Iptun. This fixes Iptun link, by crafting and parsing messages accordingly and adds a test. Signed-off-by: Robin Gögge --- link_linux.go | 10 +++------- link_test.go | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/link_linux.go b/link_linux.go index 33a47a7..bec560b 100644 --- a/link_linux.go +++ b/link_linux.go @@ -2997,14 +2997,14 @@ func parseLinkXdp(data []byte) (*LinkXdp, error) { } func addIptunAttrs(iptun *Iptun, linkInfo *nl.RtAttr) { + data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil) + if iptun.FlowBased { // In flow based mode, no other attributes need to be configured - linkInfo.AddRtAttr(nl.IFLA_IPTUN_COLLECT_METADATA, boolAttr(iptun.FlowBased)) + data.AddRtAttr(nl.IFLA_IPTUN_COLLECT_METADATA, []byte{}) return } - data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil) - ip := iptun.Local.To4() if ip != nil { data.AddRtAttr(nl.IFLA_IPTUN_LOCAL, []byte(ip)) @@ -3031,10 +3031,6 @@ func addIptunAttrs(iptun *Iptun, linkInfo *nl.RtAttr) { func parseIptunData(link Link, data []syscall.NetlinkRouteAttr) { iptun := link.(*Iptun) for _, datum := range data { - // NOTE: same with vxlan, ip tunnel may also has null datum.Value - if len(datum.Value) == 0 { - continue - } switch datum.Attr.Type { case nl.IFLA_IPTUN_LOCAL: iptun.Local = net.IP(datum.Value[0:4]) diff --git a/link_test.go b/link_test.go index cb8eb1c..eff7f7c 100644 --- a/link_test.go +++ b/link_test.go @@ -223,11 +223,14 @@ func testLinkAddDel(t *testing.T, link Link) { } } - if _, ok := link.(*Iptun); ok { - _, ok := result.(*Iptun) + if iptun, ok := link.(*Iptun); ok { + other, ok := result.(*Iptun) if !ok { t.Fatal("Result of create is not a iptun") } + if iptun.FlowBased != other.FlowBased { + t.Fatal("Iptun.FlowBased doesn't match") + } } if ip6tnl, ok := link.(*Ip6tnl); ok { @@ -2051,6 +2054,17 @@ func TestLinkAddDelIptun(t *testing.T) { Remote: net.IPv4(127, 0, 0, 1)}) } +func TestLinkAddDelIptunFlowBased(t *testing.T) { + minKernelRequired(t, 4, 9) + tearDown := setUpNetlinkTest(t) + defer tearDown() + + testLinkAddDel(t, &Iptun{ + LinkAttrs: LinkAttrs{Name: "iptunflowfoo"}, + FlowBased: true, + }) +} + func TestLinkAddDelIp6tnl(t *testing.T) { tearDown := setUpNetlinkTest(t) defer tearDown()