On 5/20/07, Blue Swirl <[EMAIL PROTECTED]> wrote:
On 5/20/07, Paul Brook <[EMAIL PROTECTED]> wrote:
> > > I think Qemu should reject -net user only. Currently that seems to
> > > mean that there is no nic, but still the vlan is connected to slirp
> > > stack. That does not make any sense.
>
> If you do this, do it properly and warn if any qemu vlans have a single device
> attached.

That is not correct either: -net user,vlan=0 -net socket,connect=1.2.3.4:1234.

How about this rule:
((one or more guest devices in a vlan) and (zero with a warning? or
more host devices)) or (no devices at all on either side)

This patch implements the logic above. Any comments?
Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c	2007-05-20 18:58:14.000000000 +0000
+++ qemu/vl.c	2007-05-20 19:36:53.000000000 +0000
@@ -4195,6 +4195,7 @@
         }
         nd->vlan = vlan;
         nb_nics++;
+        vlan->nb_guest_devs++;
         ret = 0;
     } else
     if (!strcmp(device, "none")) {
@@ -4207,6 +4208,7 @@
         if (get_param_value(buf, sizeof(buf), "hostname", p)) {
             pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf);
         }
+        vlan->nb_host_devs++;
         ret = net_slirp_init(vlan);
     } else
 #endif
@@ -4217,6 +4219,7 @@
             fprintf(stderr, "tap: no interface name\n");
             return -1;
         }
+        vlan->nb_host_devs++;
         ret = tap_win32_init(vlan, ifname);
     } else
 #else
@@ -4236,6 +4239,7 @@
             if (get_param_value(setup_script, sizeof(setup_script), "script", p) == 0) {
                 pstrcpy(setup_script, sizeof(setup_script), DEFAULT_NETWORK_SCRIPT);
             }
+            vlan->nb_host_devs++;
             ret = net_tap_init(vlan, ifname, setup_script);
         }
     } else
@@ -4257,6 +4261,7 @@
             fprintf(stderr, "Unknown socket options: %s\n", p);
             return -1;
         }
+        vlan->nb_host_devs++;
     } else
     {
         fprintf(stderr, "Unknown network device: %s\n", device);
@@ -6992,6 +6997,7 @@
     int usb_devices_index;
     int fds[2];
     const char *pid_file = NULL;
+    VLANState *vlan;
 
     LIST_INIT (&vm_change_state_head);
 #ifndef _WIN32
@@ -7611,6 +7617,19 @@
         if (net_client_init(net_clients[i]) < 0)
             exit(1);
     }
+    for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
+        if (vlan->nb_guest_devs == 0 && vlan->nb_host_devs == 0)
+            continue;
+        if (vlan->nb_guest_devs == 0) {
+            fprintf(stderr, "Invalid vlan (%d) with no nics\n", vlan->id);
+            exit(1);
+        }
+        if (vlan->nb_host_devs == 0) {
+            fprintf(stderr,
+                    "Warning: vlan %d is not connected to host network\n",
+                    vlan->id);
+        }
+    }
 
 #ifdef TARGET_I386
     if (boot_device == 'n') {
Index: qemu/vl.h
===================================================================
--- qemu.orig/vl.h	2007-05-20 19:01:59.000000000 +0000
+++ qemu/vl.h	2007-05-20 19:30:16.000000000 +0000
@@ -389,6 +389,7 @@
     int id;
     VLANClientState *first_client;
     struct VLANState *next;
+    int nb_guest_devs, nb_host_devs;
 } VLANState;
 
 VLANState *qemu_find_vlan(int id);

Reply via email to