From d237c92273e2b1b38331a2b9b9c81e1d2efd2a4d Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Thu, 20 Jul 2017 12:36:07 -0600 Subject: [PATCH] support tap devices in qemu backend The motivation for this is networking out (in particular, testing NFS support) from the VM. We could be a lot more user friendly (a la libvirt) by creating the tap device for users and allowing them to specify a bridge instead, but then we'd need root to create this tap device. For now, let's make people do their own tap devices, and just use them. A tap device can be created for a bridge as follows: # ip tuntap add linuxkit0 mode tap user `whoami` # ip link set linuxkit0 up # ip link set linuxkit0 master $bridge_name and then used by: $ ./bin/linuxkit run qemu -tap-device linuxkit0 linuxkit Signed-off-by: Tycho Andersen --- src/cmd/linuxkit/run_qemu.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cmd/linuxkit/run_qemu.go b/src/cmd/linuxkit/run_qemu.go index 210faa630..618d84e84 100644 --- a/src/cmd/linuxkit/run_qemu.go +++ b/src/cmd/linuxkit/run_qemu.go @@ -35,6 +35,7 @@ type QemuConfig struct { QemuBinPath string QemuImgPath string PublishedPorts []string + TapDevice string } func haveKVM() bool { @@ -96,6 +97,7 @@ func runQemu(args []string) { publishFlags := multipleFlag{} flags.Var(&publishFlags, "publish", "Publish a vm's port(s) to the host (default [])") + tapDevice := flags.String("tap-device", "", "Tap device to use as eth0 (optional)") if err := flags.Parse(args); err != nil { log.Fatal("Unable to parse args") @@ -215,6 +217,7 @@ func runQemu(args []string) { KVM: *enableKVM, Containerized: *qemuContainerized, PublishedPorts: publishFlags, + TapDevice: *tapDevice, } config = discoverBackend(config) @@ -447,6 +450,12 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) { qemuArgs = append(qemuArgs, "-net", "nic") } + if config.TapDevice != "" { + qemuArgs = append(qemuArgs, "-net", "nic,model=virtio") + tapArg := fmt.Sprintf("tap,ifname=%s,script=no,downscript=no", config.TapDevice) + qemuArgs = append(qemuArgs, "-net", tapArg) + } + if config.GUI != true { qemuArgs = append(qemuArgs, "-nographic") }