Patchworks-ID: 35507
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
#include "qemu-config.h"
#include "slirp/libslirp.h"
#include "qemu-config.h"
#include "slirp/libslirp.h"
-
-static VLANState *first_vlan;
+static QTAILQ_HEAD(, VLANState) vlans;
/***********************************************************/
/* network device redirectors */
/***********************************************************/
/* network device redirectors */
char buf[256];
int id = 0;
char buf[256];
int id = 0;
- for (vlan = first_vlan; vlan; vlan = vlan->next) {
+ QTAILQ_FOREACH(vlan, &vlans, next) {
- for (vc = vlan->first_client; vc; vc = vc->next)
- if (vc != vc1 && strcmp(vc->model, model) == 0)
+ QTAILQ_FOREACH(vc, &vlan->clients, next) {
+ if (vc != vc1 && strcmp(vc->model, model) == 0) {
}
snprintf(buf, sizeof(buf), "%s.%d", model, id);
}
snprintf(buf, sizeof(buf), "%s.%d", model, id);
NetCleanup *cleanup,
void *opaque)
{
NetCleanup *cleanup,
void *opaque)
{
- VLANClientState *vc, **pvc;
vc = qemu_mallocz(sizeof(VLANClientState));
vc = qemu_mallocz(sizeof(VLANClientState));
vc->model = qemu_strdup(model);
if (name)
vc->name = qemu_strdup(name);
vc->model = qemu_strdup(model);
if (name)
vc->name = qemu_strdup(name);
vc->receive_iov = receive_iov;
vc->cleanup = cleanup;
vc->opaque = opaque;
vc->receive_iov = receive_iov;
vc->cleanup = cleanup;
vc->opaque = opaque;
+ QTAILQ_INSERT_TAIL(&vc->vlan->clients, vc, next);
- vc->next = NULL;
- pvc = &vlan->first_client;
- while (*pvc != NULL)
- pvc = &(*pvc)->next;
- *pvc = vc;
return vc;
}
void qemu_del_vlan_client(VLANClientState *vc)
{
return vc;
}
void qemu_del_vlan_client(VLANClientState *vc)
{
- VLANClientState **pvc = &vc->vlan->first_client;
+ QTAILQ_REMOVE(&vc->vlan->clients, vc, next);
- while (*pvc != NULL)
- if (*pvc == vc) {
- *pvc = vc->next;
- if (vc->cleanup) {
- vc->cleanup(vc);
- }
- qemu_free(vc->name);
- qemu_free(vc->model);
- qemu_free(vc);
- break;
- } else
- pvc = &(*pvc)->next;
+ if (vc->cleanup) {
+ vc->cleanup(vc);
+ }
+
+ qemu_free(vc->name);
+ qemu_free(vc->model);
+ qemu_free(vc);
}
VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque)
{
}
VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque)
{
- VLANClientState **pvc = &vlan->first_client;
- while (*pvc != NULL)
- if ((*pvc)->opaque == opaque)
- return *pvc;
- else
- pvc = &(*pvc)->next;
+ QTAILQ_FOREACH(vc, &vlan->clients, next) {
+ if (vc->opaque == opaque) {
+ return vc;
+ }
+ }
- for (vc = vlan->first_client; vc != NULL; vc = vc->next) {
+ QTAILQ_FOREACH(vc, &vlan->clients, next) {
if (!strcmp(vc->name, client_str)) {
break;
}
if (!strcmp(vc->name, client_str)) {
break;
}
VLANState *vlan = sender->vlan;
VLANClientState *vc;
VLANState *vlan = sender->vlan;
VLANClientState *vc;
- for (vc = vlan->first_client; vc != NULL; vc = vc->next) {
+ QTAILQ_FOREACH(vc, &vlan->clients, next) {
if (vc == sender) {
continue;
}
if (vc == sender) {
continue;
}
sender->vlan->delivering = 1;
sender->vlan->delivering = 1;
- for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) {
+ QTAILQ_FOREACH(vc, &sender->vlan->clients, next) {
ssize_t len;
if (vc == sender) {
ssize_t len;
if (vc == sender) {
sender->vlan->delivering = 1;
sender->vlan->delivering = 1;
- for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) {
+ QTAILQ_FOREACH(vc, &sender->vlan->clients, next) {
ssize_t len;
if (vc == sender) {
ssize_t len;
if (vc == sender) {
/* find or alloc a new VLAN */
VLANState *qemu_find_vlan(int id, int allocate)
{
/* find or alloc a new VLAN */
VLANState *qemu_find_vlan(int id, int allocate)
{
- VLANState **pvlan, *vlan;
- for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
- if (vlan->id == id)
+ VLANState *vlan;
+
+ QTAILQ_FOREACH(vlan, &vlans, next) {
+ if (vlan->id == id) {
if (!allocate) {
return NULL;
}
if (!allocate) {
return NULL;
}
vlan = qemu_mallocz(sizeof(VLANState));
vlan->id = id;
vlan = qemu_mallocz(sizeof(VLANState));
vlan->id = id;
+ QTAILQ_INIT(&vlan->clients);
QTAILQ_INIT(&vlan->send_queue);
QTAILQ_INIT(&vlan->send_queue);
- vlan->next = NULL;
- pvlan = &first_vlan;
- while (*pvlan != NULL)
- pvlan = &(*pvlan)->next;
- *pvlan = vlan;
+
+ QTAILQ_INSERT_TAIL(&vlans, vlan, next);
+
void do_info_network(Monitor *mon)
{
VLANState *vlan;
void do_info_network(Monitor *mon)
{
VLANState *vlan;
- for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
+ QTAILQ_FOREACH(vlan, &vlans, next) {
+ VLANClientState *vc;
+
monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
- for(vc = vlan->first_client; vc != NULL; vc = vc->next)
+
+ QTAILQ_FOREACH(vc, &vlan->clients, next) {
monitor_printf(mon, " %s: %s\n", vc->name, vc->info_str);
monitor_printf(mon, " %s: %s\n", vc->name, vc->info_str);
const char *name = qdict_get_str(qdict, "name");
const char *up_or_down = qdict_get_str(qdict, "up_or_down");
const char *name = qdict_get_str(qdict, "name");
const char *up_or_down = qdict_get_str(qdict, "up_or_down");
- for (vlan = first_vlan; vlan != NULL; vlan = vlan->next)
- for (vc = vlan->first_client; vc != NULL; vc = vc->next)
- if (strcmp(vc->name, name) == 0)
+ QTAILQ_FOREACH(vlan, &vlans, next) {
+ QTAILQ_FOREACH(vc, &vlan->clients, next) {
+ if (strcmp(vc->name, name) == 0) {
- /* close network clients */
- for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
- VLANClientState *vc = vlan->first_client;
-
- while (vc) {
- VLANClientState *next = vc->next;
+ QTAILQ_FOREACH(vlan, &vlans, next) {
+ VLANClientState *vc, *next_vc;
+ QTAILQ_FOREACH_SAFE(vc, &vlan->clients, next, next_vc) {
qemu_del_vlan_client(vc);
qemu_del_vlan_client(vc);
- for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
+ QTAILQ_FOREACH(vlan, &vlans, next) {
if (vlan->nb_guest_devs == 0 && vlan->nb_host_devs == 0)
continue;
if (vlan->nb_guest_devs == 0)
if (vlan->nb_guest_devs == 0 && vlan->nb_host_devs == 0)
continue;
if (vlan->nb_guest_devs == 0)
if (qemu_opts_foreach(&qemu_net_opts, net_init_client, NULL, 1) == -1) {
return -1;
}
if (qemu_opts_foreach(&qemu_net_opts, net_init_client, NULL, 1) == -1) {
return -1;
}
LinkStatusChanged *link_status_changed;
int link_down;
void *opaque;
LinkStatusChanged *link_status_changed;
int link_down;
void *opaque;
- struct VLANClientState *next;
+ QTAILQ_ENTRY(VLANClientState) next;
struct VLANState *vlan;
char *model;
char *name;
struct VLANState *vlan;
char *model;
char *name;
struct VLANState {
int id;
struct VLANState {
int id;
- VLANClientState *first_client;
- struct VLANState *next;
+ QTAILQ_HEAD(, VLANClientState) clients;
+ QTAILQ_ENTRY(VLANState) next;
unsigned int nb_guest_devs, nb_host_devs;
QTAILQ_HEAD(send_queue, VLANPacket) send_queue;
int delivering;
unsigned int nb_guest_devs, nb_host_devs;
QTAILQ_HEAD(send_queue, VLANPacket) send_queue;
int delivering;
continue;
len = announce_self_create(buf, nd_table[i].macaddr);
vlan = nd_table[i].vlan;
continue;
len = announce_self_create(buf, nd_table[i].macaddr);
vlan = nd_table[i].vlan;
- for(vc = vlan->first_client; vc != NULL; vc = vc->next) {
+ QTAILQ_FOREACH(vc, &vlan->clients, next) {
vc->receive(vc, buf, len);
}
}
vc->receive(vc, buf, len);
}
}