Commit 833c7174ce5145397d2b3405f6857ca607fed1f1
1 parent
1b2e93c1
Improved sanity checking to -net options
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2877 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
19 additions
and
0 deletions
vl.c
@@ -4197,6 +4197,7 @@ static int net_client_init(const char *str) | @@ -4197,6 +4197,7 @@ static int net_client_init(const char *str) | ||
4197 | } | 4197 | } |
4198 | nd->vlan = vlan; | 4198 | nd->vlan = vlan; |
4199 | nb_nics++; | 4199 | nb_nics++; |
4200 | + vlan->nb_guest_devs++; | ||
4200 | ret = 0; | 4201 | ret = 0; |
4201 | } else | 4202 | } else |
4202 | if (!strcmp(device, "none")) { | 4203 | if (!strcmp(device, "none")) { |
@@ -4209,6 +4210,7 @@ static int net_client_init(const char *str) | @@ -4209,6 +4210,7 @@ static int net_client_init(const char *str) | ||
4209 | if (get_param_value(buf, sizeof(buf), "hostname", p)) { | 4210 | if (get_param_value(buf, sizeof(buf), "hostname", p)) { |
4210 | pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf); | 4211 | pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf); |
4211 | } | 4212 | } |
4213 | + vlan->nb_host_devs++; | ||
4212 | ret = net_slirp_init(vlan); | 4214 | ret = net_slirp_init(vlan); |
4213 | } else | 4215 | } else |
4214 | #endif | 4216 | #endif |
@@ -4219,6 +4221,7 @@ static int net_client_init(const char *str) | @@ -4219,6 +4221,7 @@ static int net_client_init(const char *str) | ||
4219 | fprintf(stderr, "tap: no interface name\n"); | 4221 | fprintf(stderr, "tap: no interface name\n"); |
4220 | return -1; | 4222 | return -1; |
4221 | } | 4223 | } |
4224 | + vlan->nb_host_devs++; | ||
4222 | ret = tap_win32_init(vlan, ifname); | 4225 | ret = tap_win32_init(vlan, ifname); |
4223 | } else | 4226 | } else |
4224 | #else | 4227 | #else |
@@ -4238,6 +4241,7 @@ static int net_client_init(const char *str) | @@ -4238,6 +4241,7 @@ static int net_client_init(const char *str) | ||
4238 | if (get_param_value(setup_script, sizeof(setup_script), "script", p) == 0) { | 4241 | if (get_param_value(setup_script, sizeof(setup_script), "script", p) == 0) { |
4239 | pstrcpy(setup_script, sizeof(setup_script), DEFAULT_NETWORK_SCRIPT); | 4242 | pstrcpy(setup_script, sizeof(setup_script), DEFAULT_NETWORK_SCRIPT); |
4240 | } | 4243 | } |
4244 | + vlan->nb_host_devs++; | ||
4241 | ret = net_tap_init(vlan, ifname, setup_script); | 4245 | ret = net_tap_init(vlan, ifname, setup_script); |
4242 | } | 4246 | } |
4243 | } else | 4247 | } else |
@@ -4259,6 +4263,7 @@ static int net_client_init(const char *str) | @@ -4259,6 +4263,7 @@ static int net_client_init(const char *str) | ||
4259 | fprintf(stderr, "Unknown socket options: %s\n", p); | 4263 | fprintf(stderr, "Unknown socket options: %s\n", p); |
4260 | return -1; | 4264 | return -1; |
4261 | } | 4265 | } |
4266 | + vlan->nb_host_devs++; | ||
4262 | } else | 4267 | } else |
4263 | { | 4268 | { |
4264 | fprintf(stderr, "Unknown network device: %s\n", device); | 4269 | fprintf(stderr, "Unknown network device: %s\n", device); |
@@ -7131,6 +7136,7 @@ int main(int argc, char **argv) | @@ -7131,6 +7136,7 @@ int main(int argc, char **argv) | ||
7131 | int usb_devices_index; | 7136 | int usb_devices_index; |
7132 | int fds[2]; | 7137 | int fds[2]; |
7133 | const char *pid_file = NULL; | 7138 | const char *pid_file = NULL; |
7139 | + VLANState *vlan; | ||
7134 | 7140 | ||
7135 | LIST_INIT (&vm_change_state_head); | 7141 | LIST_INIT (&vm_change_state_head); |
7136 | #ifndef _WIN32 | 7142 | #ifndef _WIN32 |
@@ -7750,6 +7756,18 @@ int main(int argc, char **argv) | @@ -7750,6 +7756,18 @@ int main(int argc, char **argv) | ||
7750 | if (net_client_init(net_clients[i]) < 0) | 7756 | if (net_client_init(net_clients[i]) < 0) |
7751 | exit(1); | 7757 | exit(1); |
7752 | } | 7758 | } |
7759 | + for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) { | ||
7760 | + if (vlan->nb_guest_devs == 0 && vlan->nb_host_devs == 0) | ||
7761 | + continue; | ||
7762 | + if (vlan->nb_guest_devs == 0) { | ||
7763 | + fprintf(stderr, "Invalid vlan (%d) with no nics\n", vlan->id); | ||
7764 | + exit(1); | ||
7765 | + } | ||
7766 | + if (vlan->nb_host_devs == 0) | ||
7767 | + fprintf(stderr, | ||
7768 | + "Warning: vlan %d is not connected to host network\n", | ||
7769 | + vlan->id); | ||
7770 | + } | ||
7753 | 7771 | ||
7754 | #ifdef TARGET_I386 | 7772 | #ifdef TARGET_I386 |
7755 | if (boot_device == 'n') { | 7773 | if (boot_device == 'n') { |
vl.h
@@ -389,6 +389,7 @@ typedef struct VLANState { | @@ -389,6 +389,7 @@ typedef struct VLANState { | ||
389 | int id; | 389 | int id; |
390 | VLANClientState *first_client; | 390 | VLANClientState *first_client; |
391 | struct VLANState *next; | 391 | struct VLANState *next; |
392 | + unsigned int nb_guest_devs, nb_host_devs; | ||
392 | } VLANState; | 393 | } VLANState; |
393 | 394 | ||
394 | VLANState *qemu_find_vlan(int id); | 395 | VLANState *qemu_find_vlan(int id); |