return NULL;
}
+static VLANClientState *
+qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
+ const char *client_str)
+{
+ VLANState *vlan;
+ VLANClientState *vc;
+
+ vlan = qemu_find_vlan(vlan_id, 0);
+ if (!vlan) {
+ monitor_printf(mon, "unknown VLAN %d\n", vlan_id);
+ return NULL;
+ }
+
+ for (vc = vlan->first_client; vc != NULL; vc = vc->next) {
+ if (!strcmp(vc->name, client_str)) {
+ break;
+ }
+ }
+ if (!vc) {
+ monitor_printf(mon, "can't find device %s on VLAN %d\n",
+ client_str, vlan_id);
+ }
+
+ return vc;
+}
+
int qemu_can_send_packet(VLANClientState *sender)
{
VLANState *vlan = sender->vlan;
}
/* find or alloc a new VLAN */
-VLANState *qemu_find_vlan(int id)
+VLANState *qemu_find_vlan(int id, int allocate)
{
VLANState **pvlan, *vlan;
for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
if (vlan->id == id)
return vlan;
}
+ if (!allocate) {
+ return NULL;
+ }
vlan = qemu_mallocz(sizeof(VLANState));
vlan->id = id;
vlan->next = NULL;
if (get_param_value(buf, sizeof(buf), "vlan", p)) {
vlan_id = strtol(buf, NULL, 0);
}
- vlan = qemu_find_vlan(vlan_id);
+ vlan = qemu_find_vlan(vlan_id, 1);
if (get_param_value(buf, sizeof(buf), "name", p)) {
name = qemu_strdup(buf);
void net_host_device_remove(Monitor *mon, int vlan_id, const char *device)
{
- VLANState *vlan;
VLANClientState *vc;
- vlan = qemu_find_vlan(vlan_id);
-
- for (vc = vlan->first_client; vc != NULL; vc = vc->next) {
- if (!strcmp(vc->name, device)) {
- break;
- }
- }
-
+ vc = qemu_find_vlan_client_by_name(mon, vlan_id, device);
if (!vc) {
- monitor_printf(mon, "can't find device %s\n", device);
return;
}
if (!net_host_check_device(vc->model)) {