*/
#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "monitor/monitor.h"
#include "net/net.h"
#include "clients.h"
.cleanup = net_hub_port_cleanup,
};
-static NetHubPort *net_hub_port_new(NetHub *hub, const char *name)
+static NetHubPort *net_hub_port_new(NetHub *hub, const char *name,
+ NetClientState *hubpeer)
{
NetClientState *nc;
NetHubPort *port;
name = default_name;
}
- nc = qemu_new_net_client(&net_hub_port_info, NULL, "hub", name);
+ nc = qemu_new_net_client(&net_hub_port_info, hubpeer, "hub", name);
port = DO_UPCAST(NetHubPort, nc, nc);
port->id = id;
port->hub = hub;
/**
* Create a port on a given hub
+ * @hub_id: Number of the hub
* @name: Net client name or NULL for default name.
+ * @hubpeer: Peer to use (if "netdev=id" has been specified)
*
* If there is no existing hub with the given id then a new hub is created.
*/
-NetClientState *net_hub_add_port(int hub_id, const char *name)
+NetClientState *net_hub_add_port(int hub_id, const char *name,
+ NetClientState *hubpeer)
{
NetHub *hub;
NetHubPort *port;
hub = net_hub_new(hub_id);
}
- port = net_hub_port_new(hub, name);
+ port = net_hub_port_new(hub, name, hubpeer);
return &port->nc;
}
}
}
- nc = net_hub_add_port(hub_id, NULL);
+ nc = net_hub_add_port(hub_id, NULL, NULL);
return nc;
}
NetClientState *peer, Error **errp)
{
const NetdevHubPortOptions *hubport;
+ NetClientState *hubpeer = NULL;
assert(netdev->type == NET_CLIENT_DRIVER_HUBPORT);
assert(!peer);
hubport = &netdev->u.hubport;
- net_hub_add_port(hubport->hubid, name);
+ if (hubport->has_netdev) {
+ hubpeer = qemu_find_netdev(hubport->netdev);
+ if (!hubpeer) {
+ error_setg(errp, "netdev '%s' not found", hubport->netdev);
+ return -1;
+ }
+ }
+
+ net_hub_add_port(hubport->hubid, name, hubpeer);
+
return 0;
}
#include "qemu-common.h"
-NetClientState *net_hub_add_port(int hub_id, const char *name);
+NetClientState *net_hub_add_port(int hub_id, const char *name,
+ NetClientState *hubpeer);
NetClientState *net_hub_find_client_by_name(int hub_id, const char *name);
void net_hub_info(Monitor *mon);
void net_hub_check_clients(void);
/* Do not add to a vlan if it's a nic with a netdev= parameter. */
if (netdev->type != NET_CLIENT_DRIVER_NIC ||
!opts->u.nic.has_netdev) {
- peer = net_hub_add_port(net->has_vlan ? net->vlan : 0, NULL);
+ peer = net_hub_add_port(net->has_vlan ? net->vlan : 0, NULL, NULL);
}
if (net->has_vlan && !vlan_warned) {
# Connect two or more net clients through a software hub.
#
# @hubid: hub identifier number
+# @netdev: used to connect hub to a netdev instead of a device (since 2.12)
#
# Since: 1.2
##
{ 'struct': 'NetdevHubPortOptions',
'data': {
- 'hubid': 'int32' } }
+ 'hubid': 'int32',
+ '*netdev': 'str' } }
##
# @NetdevNetmapOptions:
#endif
"-netdev vhost-user,id=str,chardev=dev[,vhostforce=on|off]\n"
" configure a vhost-user network, backed by a chardev 'dev'\n"
- "-netdev hubport,id=str,hubid=n\n"
+ "-netdev hubport,id=str,hubid=n[,netdev=nd]\n"
" configure a hub port on QEMU VLAN 'n'\n", QEMU_ARCH_ALL)
DEF("net", HAS_ARG, QEMU_OPTION_net,
"-net nic[,vlan=n][,netdev=nd][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]\n"
qemu-system-i386 linux.img -net nic -net vde,sock=/tmp/myswitch
@end example
-@item -netdev hubport,id=@var{id},hubid=@var{hubid}
+@item -netdev hubport,id=@var{id},hubid=@var{hubid}[,netdev=@var{nd}]
Create a hub port on QEMU "vlan" @var{hubid}.
The hubport netdev lets you connect a NIC to a QEMU "vlan" instead of a single
netdev. @code{-net} and @code{-device} with parameter @option{vlan} create the
-required hub automatically.
+required hub automatically. Alternatively, you can also connect the hubport
+to another netdev with ID @var{nd} by using the @option{netdev=@var{nd}}
+option.
@item -netdev vhost-user,chardev=@var{id}[,vhostforce=on|off][,queues=n]