From 147964b241c650139be0bcb5d17940003f788c5f Mon Sep 17 00:00:00 2001 From: Dennis Chen Date: Mon, 11 Sep 2017 01:47:08 +0000 Subject: [PATCH] qemu: Fix the networking issue in 'tap' mode on arm64 This PR is used to fix the issue #2488. Currently we use '-net' the old way to initialize a host nic interface, this method will not work on arm64 platform(#2488 issue), so we use the '-netdev' method which will work on both arm64 and amd64. Signed-off-by: Dennis Chen --- src/cmd/linuxkit/run_qemu.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cmd/linuxkit/run_qemu.go b/src/cmd/linuxkit/run_qemu.go index 73bc54fab..151c3d5ec 100644 --- a/src/cmd/linuxkit/run_qemu.go +++ b/src/cmd/linuxkit/run_qemu.go @@ -276,7 +276,7 @@ func runQemu(args []string) { var netdevConfig string switch netMode[0] { case qemuNetworkingUser: - netdevConfig = "user" + netdevConfig = "user,id=t0" case qemuNetworkingTap: if len(netMode) != 2 { log.Fatalf("Not enough arugments for %q networking mode", qemuNetworkingTap) @@ -284,7 +284,7 @@ func runQemu(args []string) { if len(publishFlags) != 0 { log.Fatalf("Port publishing requires %q networking mode", qemuNetworkingUser) } - netdevConfig = fmt.Sprintf("tap,ifname=%s,script=no,downscript=no", netMode[1]) + netdevConfig = fmt.Sprintf("tap,id=t0,ifname=%s,script=no,downscript=no", netMode[1]) case qemuNetworkingBridge: if len(netMode) != 2 { log.Fatalf("Not enough arugments for %q networking mode", qemuNetworkingBridge) @@ -292,7 +292,7 @@ func runQemu(args []string) { if len(publishFlags) != 0 { log.Fatalf("Port publishing requires %q networking mode", qemuNetworkingUser) } - netdevConfig = fmt.Sprintf("bridge,br=%s", netMode[1]) + netdevConfig = fmt.Sprintf("bridge,id=t0,br=%s", netMode[1]) case qemuNetworkingNone: if len(publishFlags) != 0 { log.Fatalf("Port publishing requires %q networking mode", qemuNetworkingUser) @@ -571,13 +571,14 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) { if config.NetdevConfig == "" { qemuArgs = append(qemuArgs, "-net", "none") } else { - mac := retrieveMAC(config.StatePath) - qemuArgs = append(qemuArgs, "-net", "nic,model=virtio,macaddr="+mac.String()) + // provide a network device first for the QEMU VM if '-networking' is specified, + qemuArgs = append(qemuArgs, "-device", "virtio-net-pci,netdev=t0") forwardings, err := buildQemuForwardings(config.PublishedPorts, config.Containerized) if err != nil { log.Error(err) } - qemuArgs = append(qemuArgs, "-net", config.NetdevConfig+forwardings) + // we perfer "-netdev" to the "-net" which is an old way to initialize a host nic + qemuArgs = append(qemuArgs, "-netdev", config.NetdevConfig+forwardings) } if config.GUI != true {