Skip to content

Commit

Permalink
fix: Disable bridge MAC learning in virt-prerunner
Browse files Browse the repository at this point in the history
  • Loading branch information
carezkh authored and fengye87 committed Sep 5, 2022
1 parent d5ac5b2 commit 65db754
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/virt-prerunner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down
7 changes: 6 additions & 1 deletion cmd/virt-prerunner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 65db754

Please sign in to comment.