From 65db75465ebd77c2425a67a6216b93ad16f4049c Mon Sep 17 00:00:00 2001 From: Kaihang Zhang Date: Fri, 2 Sep 2022 16:56:50 +0800 Subject: [PATCH] fix: Disable bridge MAC learning in virt-prerunner --- build/virt-prerunner/Dockerfile | 2 +- cmd/virt-prerunner/main.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/build/virt-prerunner/Dockerfile b/build/virt-prerunner/Dockerfile index 55ce637..cc698b2 100644 --- a/build/virt-prerunner/Dockerfile +++ b/build/virt-prerunner/Dockerfile @@ -14,7 +14,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build go build -a cmd/virt-prerunn FROM alpine -RUN apk add --no-cache tini curl screen dnsmasq cdrkit iptables +RUN apk add --no-cache tini curl screen dnsmasq cdrkit iptables iproute2 RUN set -eux; \ mkdir /var/lib/cloud-hypervisor; \ diff --git a/cmd/virt-prerunner/main.go b/cmd/virt-prerunner/main.go index d1ea79e..ed1c7b5 100644 --- a/cmd/virt-prerunner/main.go +++ b/cmd/virt-prerunner/main.go @@ -302,13 +302,14 @@ func setupBridgeNetwork(linkName string, cidr string, netConfig *cloudhypervisor return fmt.Errorf("spoof link MAC: %s", err) } + newLinkName := link.Attrs().Name if linkAddr != nil { if err := netlink.AddrDel(link, &linkAddrs[0]); err != nil { return fmt.Errorf("delete link address: %s", err) } originalLinkName := link.Attrs().Name - newLinkName := fmt.Sprintf("%s-nic", originalLinkName) + newLinkName = fmt.Sprintf("%s-nic", originalLinkName) if err := netlink.LinkSetName(link, newLinkName); err != nil { return fmt.Errorf("rename link: %s", err) @@ -335,6 +336,10 @@ func setupBridgeNetwork(linkName string, cidr string, netConfig *cloudhypervisor return fmt.Errorf("up link: %s", err) } + if _, err := executeCommand("bridge", "link", "set", "dev", newLinkName, "learning", "off"); err != nil { + return fmt.Errorf("disable port MAC learning on bridge: %s", err) + } + tapName := fmt.Sprintf("tap-%s", linkName) if _, err := createTap(bridge, tapName); err != nil { return fmt.Errorf("create tap: %s", err)