On 15.01.2018 08:40, Jason Wang wrote: > > On 2018年01月10日 22:32, Thomas Huth wrote: >> QEMU can emulate hubs to connect NICs and netdevs. This is currently >> primarily used for the mis-named 'vlan' feature of the networking >> subsystem. Now the 'vlan' feature has been marked as deprecated, since >> its name is rather confusing and the users often rather mis-configure >> their network when trying to use it. But while the 'vlan' parameter >> should be removed at one point in time, the basic idea of emulating >> a hub in QEMU is still good: It's useful for bundling up the output of >> multiple NICs into one single l2tp netdev for example. >> >> Now to be able to use the hubport feature without 'vlan's, there is one >> missing piece: The possibility to connect a hubport to a netdev, too. >> This patch adds this possibility by introducing a new "netdev=..." >> parameter to the hubports. [...] >> @@ -286,12 +287,32 @@ int net_init_hubport(const Netdev *netdev, const >> char *name, >> NetClientState *peer, Error **errp) >> { >> const NetdevHubPortOptions *hubport; >> + NetClientState *hubncs; >> assert(netdev->type == NET_CLIENT_DRIVER_HUBPORT); >> assert(!peer); >> hubport = &netdev->u.hubport; >> - net_hub_add_port(hubport->hubid, name); >> + hubncs = net_hub_add_port(hubport->hubid, name); >> + if (!hubncs) { >> + error_setg(errp, "failed to add port to hub %i with id '%s'", >> + hubport->hubid, name); >> + return -1; >> + } >> + >> + if (hubport->has_netdev) { >> + NetClientState *hubpeer; >> + >> + hubpeer = qemu_find_netdev(hubport->netdev); >> + if (!hubpeer) { >> + error_setg(errp, "netdev '%s' not found", hubport->netdev); >> + return -1; >> + } >> + assert(!hubncs->peer && !hubpeer->peer); >> + hubncs->peer = hubpeer; >> + hubpeer->peer = hubncs; >> + } >> + > > Instead of open coding here, maybe you can pass peer to > net_hub_port_new() and let qemu_new_net_client() do this for you.
Sure. I'll send a v2. > And since it was a hub, do we need to send to its netdev too inside > net_hub_receive()? I currently don't think so, but I'll check again... Thomas