From c8e877cf8344eb7265d9a143129aa603bd213412 Mon Sep 17 00:00:00 2001 From: Stephen Brennan Date: Tue, 29 Nov 2016 16:14:34 -0500 Subject: [PATCH] Adds support for bridged networking. The user may create bridges and connect them to host interfaces. Then, they can specify a bridge with the --bridge option, and qemu will create a tap device and connect it to that bridge. You can pass the same bridge multiple times to create several guest interfaces on the same bridge. The startup script requests a DHCP lease on all interfaces. --- vido | 16 +++++++++++++--- virt-stub | 4 +++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/vido b/vido index f039e51..935e9b3 100755 --- a/vido +++ b/vido @@ -200,6 +200,9 @@ sp_kvm = parser.add_argument_group('KVM-only options') sp_kvm.add_argument( '--net', action='store_true', help='Configure the network (unnecessary with userns)') +sp_kvm.add_argument( + '--bridge', default=[], nargs='*', + help='Bridges to use for virtual NICs') # qemu needs this to catch crashes (unnecessary with uml) sp_kvm.add_argument( '--watchdog', action='store_true', @@ -267,8 +270,10 @@ if args.watchdog and args.virt != 'kvm': fatal('--watchdog is not supported with {}'.format(args.virt)) if args.qemu_9p_workaround and args.virt != 'kvm': fatal('--qemu-9p-workaround is not supported with {}'.format(args.virt)) -if args.net and args.virt != 'kvm': - fatal('--net is not supported with {}'.format(args.virt)) +if (args.net or args.bridge) and args.virt != 'kvm': + fatal('--net and --bridge not supported with {}'.format(args.virt)) +if args.net and args.bridge: + fatal('--net and --bridge cannot be active at the same time') if args.run_as and args.virt not in 'kvm uml'.split(): fatal('--run-as is not supported with {}'.format(args.virt)) if args.gdb and args.virt not in 'kvm uml'.split(): @@ -348,6 +353,12 @@ if args.virt == 'kvm': # Not passing dns, sharing the host's resolv.conf # Suggest a port-forward for the local resolver case conf.net = dict(host='10.0.2.15/24', router='10.0.2.2') + elif args.bridge: + for i, bridge in enumerate(args.bridge): + qcmd += ['-net', 'nic,vlan=%d' % i, '-net', + 'bridge,vlan=%d,br=%s' % (i, bridge)] + conf.bridge = len(args.bridge) + if args.watchdog: qcmd += ['-watchdog', 'ib700', '-watchdog-action', 'poweroff'] @@ -452,4 +463,3 @@ else: if not exitstr: fatal('virt-stub crashed') sys.exit(int(exitstr)) - diff --git a/virt-stub b/virt-stub index 2daba54..9dcf342 100755 --- a/virt-stub +++ b/virt-stub @@ -192,6 +192,9 @@ if hasattr(conf, 'net'): subprocess.check_call( 'ip route add default via'.split() + [conf.net.router] + 'dev eth0'.split()) +elif hasattr(conf, 'bridge'): + for i in range(conf.bridge): + subprocess.check_call(['/usr/bin/dhcpcd', '--noarp', '-b', 'eth%d' % i]) for i, disk in enumerate(conf.disks): env['VIDO_DISK{}'.format(i)] = disk @@ -201,4 +204,3 @@ exit_status_file.write('%d' % rcode) exit_status_file.close() if conf.virt != 'userns': subprocess.check_call('/sbin/poweroff -f'.split()) -