tap: Allow specifying a bridge

The tap backend is already using qemu-bridge-helper to attach tap
interface to a bridge but (unlike the bridge backend) it always uses
the default bridge name - br0.

This adds a "br" property support to the tap backend.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Greg Kurz <groug@kaod.org>
Tested-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
Alexey Kardashevskiy 2016-09-13 17:11:54 +10:00 committed by Jason Wang
parent fb56d323e2
commit 584613eacb
3 changed files with 13 additions and 6 deletions

View File

@ -857,7 +857,9 @@ free_fail:
return -1; return -1;
} }
fd = net_bridge_run_helper(tap->helper, DEFAULT_BRIDGE_INTERFACE, fd = net_bridge_run_helper(tap->helper,
tap->has_br ?
tap->br : DEFAULT_BRIDGE_INTERFACE,
errp); errp);
if (fd == -1) { if (fd == -1) {
return -1; return -1;

View File

@ -2636,6 +2636,8 @@
# #
# @downscript: #optional script to shut down the interface # @downscript: #optional script to shut down the interface
# #
# @br: #optional bridge name (since 2.8)
#
# @helper: #optional command to execute to configure bridge # @helper: #optional command to execute to configure bridge
# #
# @sndbuf: #optional send buffer limit. Understands [TGMKkb] suffixes. # @sndbuf: #optional send buffer limit. Understands [TGMKkb] suffixes.
@ -2665,6 +2667,7 @@
'*fds': 'str', '*fds': 'str',
'*script': 'str', '*script': 'str',
'*downscript': 'str', '*downscript': 'str',
'*br': 'str',
'*helper': 'str', '*helper': 'str',
'*sndbuf': 'size', '*sndbuf': 'size',
'*vnet_hdr': 'bool', '*vnet_hdr': 'bool',

View File

@ -1598,10 +1598,11 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
" configure a host TAP network backend with ID 'str'\n" " configure a host TAP network backend with ID 'str'\n"
#else #else
"-netdev tap,id=str[,fd=h][,fds=x:y:...:z][,ifname=name][,script=file][,downscript=dfile]\n" "-netdev tap,id=str[,fd=h][,fds=x:y:...:z][,ifname=name][,script=file][,downscript=dfile]\n"
" [,helper=helper][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off]\n" " [,br=bridge][,helper=helper][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off]\n"
" [,vhostfd=h][,vhostfds=x:y:...:z][,vhostforce=on|off][,queues=n]\n" " [,vhostfd=h][,vhostfds=x:y:...:z][,vhostforce=on|off][,queues=n]\n"
" [,poll-us=n]\n" " [,poll-us=n]\n"
" configure a host TAP network backend with ID 'str'\n" " configure a host TAP network backend with ID 'str'\n"
" connected to a bridge (default=" DEFAULT_BRIDGE_INTERFACE ")\n"
" use network scripts 'file' (default=" DEFAULT_NETWORK_SCRIPT ")\n" " use network scripts 'file' (default=" DEFAULT_NETWORK_SCRIPT ")\n"
" to configure it and 'dfile' (default=" DEFAULT_NETWORK_DOWN_SCRIPT ")\n" " to configure it and 'dfile' (default=" DEFAULT_NETWORK_DOWN_SCRIPT ")\n"
" to deconfigure it\n" " to deconfigure it\n"
@ -1888,8 +1889,8 @@ processed and applied to -net user. Mixing them with the new configuration
syntax gives undefined results. Their use for new applications is discouraged syntax gives undefined results. Their use for new applications is discouraged
as they will be removed from future versions. as they will be removed from future versions.
@item -netdev tap,id=@var{id}[,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}][,helper=@var{helper}] @item -netdev tap,id=@var{id}[,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}][,br=@var{bridge}][,helper=@var{helper}]
@itemx -net tap[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}][,helper=@var{helper}] @itemx -net tap[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}][,br=@var{bridge}][,helper=@var{helper}]
Connect the host TAP network interface @var{name} to VLAN @var{n}. Connect the host TAP network interface @var{name} to VLAN @var{n}.
Use the network script @var{file} to configure it and the network script Use the network script @var{file} to configure it and the network script
@ -1900,8 +1901,9 @@ automatically provides one. The default network configure script is
to disable script execution. to disable script execution.
If running QEMU as an unprivileged user, use the network helper If running QEMU as an unprivileged user, use the network helper
@var{helper} to configure the TAP interface. The default network @var{helper} to configure the TAP interface and attach it to the bridge.
helper executable is @file{/path/to/qemu-bridge-helper}. The default network helper executable is @file{/path/to/qemu-bridge-helper}
and the default bridge device is @file{br0}.
@option{fd}=@var{h} can be used to specify the handle of an already @option{fd}=@var{h} can be used to specify the handle of an already
opened host TAP interface. opened host TAP interface.