]> xenbits.xensource.com Git - qemu-xen-4.4-testing.git/commitdiff
Improved sanity checking to -net options
authorblueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>
Sun, 27 May 2007 19:36:43 +0000 (19:36 +0000)
committerblueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>
Sun, 27 May 2007 19:36:43 +0000 (19:36 +0000)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2877 c046a42c-6fe2-441c-8c8c-71466251a162

vl.c
vl.h

diff --git a/vl.c b/vl.c
index d23af87a7148793545d8c7177750791c3e06a039..61c6c1a01322db4d8796f332b1d262c5e31d0049 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -4197,6 +4197,7 @@ static int net_client_init(const char *str)
         }
         nd->vlan = vlan;
         nb_nics++;
+        vlan->nb_guest_devs++;
         ret = 0;
     } else
     if (!strcmp(device, "none")) {
@@ -4209,6 +4210,7 @@ static int net_client_init(const char *str)
         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
@@ -4219,6 +4221,7 @@ static int net_client_init(const char *str)
             fprintf(stderr, "tap: no interface name\n");
             return -1;
         }
+        vlan->nb_host_devs++;
         ret = tap_win32_init(vlan, ifname);
     } else
 #else
@@ -4238,6 +4241,7 @@ static int net_client_init(const char *str)
             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
@@ -4259,6 +4263,7 @@ static int net_client_init(const char *str)
             fprintf(stderr, "Unknown socket options: %s\n", p);
             return -1;
         }
+        vlan->nb_host_devs++;
     } else
     {
         fprintf(stderr, "Unknown network device: %s\n", device);
@@ -7131,6 +7136,7 @@ int main(int argc, char **argv)
     int usb_devices_index;
     int fds[2];
     const char *pid_file = NULL;
+    VLANState *vlan;
 
     LIST_INIT (&vm_change_state_head);
 #ifndef _WIN32
@@ -7750,6 +7756,18 @@ int main(int argc, char **argv)
         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') {
diff --git a/vl.h b/vl.h
index e8caaf8df8fd0612c03b7b29d292f3bb21aa0e21..8fed8374d92a74e35309c2903ec200e991f30561 100644 (file)
--- a/vl.h
+++ b/vl.h
@@ -389,6 +389,7 @@ typedef struct VLANState {
     int id;
     VLANClientState *first_client;
     struct VLANState *next;
+    unsigned int nb_guest_devs, nb_host_devs;
 } VLANState;
 
 VLANState *qemu_find_vlan(int id);