typedef struct NetHub NetHub;
typedef struct NetHubPort {
- VLANClientState nc;
+ NetClientState nc;
QLIST_ENTRY(NetHubPort) next;
NetHub *hub;
int id;
return hub;
}
-static ssize_t net_hub_port_receive(VLANClientState *nc,
+static ssize_t net_hub_port_receive(NetClientState *nc,
const uint8_t *buf, size_t len)
{
NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc);
return net_hub_receive(port->hub, port, buf, len);
}
-static ssize_t net_hub_port_receive_iov(VLANClientState *nc,
+static ssize_t net_hub_port_receive_iov(NetClientState *nc,
const struct iovec *iov, int iovcnt)
{
NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc);
return net_hub_receive_iov(port->hub, port, iov, iovcnt);
}
-static void net_hub_port_cleanup(VLANClientState *nc)
+static void net_hub_port_cleanup(NetClientState *nc)
{
NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc);
static NetHubPort *net_hub_port_new(NetHub *hub, const char *name)
{
- VLANClientState *nc;
+ NetClientState *nc;
NetHubPort *port;
int id = hub->num_ports++;
char default_name[128];
name = default_name;
}
- nc = qemu_new_net_client(&net_hub_port_info, NULL, NULL, "hub", name);
+ nc = qemu_new_net_client(&net_hub_port_info, NULL, "hub", name);
port = DO_UPCAST(NetHubPort, nc, nc);
port->id = id;
port->hub = hub;
*
* If there is no existing hub with the given id then a new hub is created.
*/
-VLANClientState *net_hub_add_port(int hub_id, const char *name)
+NetClientState *net_hub_add_port(int hub_id, const char *name)
{
NetHub *hub;
NetHubPort *port;
/**
* Find a specific client on a hub
*/
-VLANClientState *net_hub_find_client_by_name(int hub_id, const char *name)
+NetClientState *net_hub_find_client_by_name(int hub_id, const char *name)
{
NetHub *hub;
NetHubPort *port;
- VLANClientState *peer;
+ NetClientState *peer;
QLIST_FOREACH(hub, &hubs, next) {
if (hub->id == hub_id) {
return NULL;
}
+/**
+ * Find a available port on a hub; otherwise create one new port
+ */
+NetClientState *net_hub_port_find(int hub_id)
+{
+ NetHub *hub;
+ NetHubPort *port;
+ NetClientState *nc;
+
+ QLIST_FOREACH(hub, &hubs, next) {
+ if (hub->id == hub_id) {
+ QLIST_FOREACH(port, &hub->ports, next) {
+ nc = port->nc.peer;
+ if (!nc) {
+ return &(port->nc);
+ }
+ }
+ break;
+ }
+ }
+
+ nc = net_hub_add_port(hub_id, NULL);
+ return nc;
+}
+
/**
* Print hub configuration
*/
*
* @id Pointer for hub id output, may be NULL
*/
-int net_hub_id_for_client(VLANClientState *nc, int *id)
+int net_hub_id_for_client(NetClientState *nc, int *id)
{
NetHubPort *port;
}
int net_init_hubport(const NetClientOptions *opts, const char *name,
- VLANClientState *peer)
+ NetClientState *peer)
{
const NetdevHubPortOptions *hubport;
{
NetHub *hub;
NetHubPort *port;
- VLANClientState *peer;
+ NetClientState *peer;
QLIST_FOREACH(hub, &hubs, next) {
int has_nic = 0, has_host_dev = 0;