Commit 9ad97e65034ad8da566ca3fdecc4920ed4783681
1 parent
2fa7d3bf
Simplify -usbdevice net: syntax, allow VLANs with no NICs.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4965 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
36 additions
and
33 deletions
qemu-doc.texi
... | ... | @@ -567,7 +567,7 @@ available devices. |
567 | 567 | Braille device. This will use BrlAPI to display the braille output on a real |
568 | 568 | or fake device. |
569 | 569 | |
570 | -@item net:nic_num | |
570 | +@item net:options | |
571 | 571 | Network adapter that supports CDC ethernet and RNDIS protocols. |
572 | 572 | |
573 | 573 | @end table |
... | ... | @@ -587,7 +587,7 @@ Qemu can emulate several different models of network card. |
587 | 587 | Valid values for @var{type} are |
588 | 588 | @code{i82551}, @code{i82557b}, @code{i82559er}, |
589 | 589 | @code{ne2k_pci}, @code{ne2k_isa}, @code{pcnet}, @code{rtl8139}, |
590 | -@code{e1000}, @code{smc91c111}, @code{lance}, @code{mcf_fec} and @code{usb}. | |
590 | +@code{e1000}, @code{smc91c111}, @code{lance} and @code{mcf_fec}. | |
591 | 591 | Not all devices are supported on all targets. Use -net nic,model=? |
592 | 592 | for a list of available devices for your target. |
593 | 593 | |
... | ... | @@ -1725,14 +1725,12 @@ serial converter, faking a Matrix Orbital LCD Display (USB ID 0403:FA00). |
1725 | 1725 | @item braille |
1726 | 1726 | Braille device. This will use BrlAPI to display the braille output on a real |
1727 | 1727 | or fake device. |
1728 | -@item net:@var{nic_num} | |
1729 | -Network adapter that supports CDC ethernet and RNDIS protocols. This must be | |
1730 | -used together with the @code{-net nic,model=usb,...} option (see description), | |
1731 | -where @var{nic_num} specifies the index of the @code{-net nic,...} option | |
1732 | -describing the interface (zero-based). | |
1733 | -For instance, user-mode networking can be used by specifying | |
1734 | -@example | |
1735 | -qemu -net user,vlan=1 -net nic,model=usb,vlan=1 -usbdevice net:0 [...OPTIONS...] | |
1728 | +@item net:@var{options} | |
1729 | +Network adapter that supports CDC ethernet and RNDIS protocols. @var{options} | |
1730 | +specifies NIC options as with @code{-net nic,}@var{options} (see description). | |
1731 | +For instance, user-mode networking can be used with | |
1732 | +@example | |
1733 | +qemu [...OPTIONS...] -net user,vlan=0 -usbdevice net:vlan=0 | |
1736 | 1734 | @end example |
1737 | 1735 | Currently this cannot be used in machines that support PCI NICs. |
1738 | 1736 | @end table | ... | ... |
vl.c
... | ... | @@ -5138,26 +5138,12 @@ static int check_params(char *buf, int buf_size, |
5138 | 5138 | return 0; |
5139 | 5139 | } |
5140 | 5140 | |
5141 | - | |
5142 | -static int net_client_init(const char *str) | |
5141 | +static int net_client_init(const char *device, const char *p) | |
5143 | 5142 | { |
5144 | - const char *p; | |
5145 | - char *q; | |
5146 | - char device[64]; | |
5147 | 5143 | char buf[1024]; |
5148 | 5144 | int vlan_id, ret; |
5149 | 5145 | VLANState *vlan; |
5150 | 5146 | |
5151 | - p = str; | |
5152 | - q = device; | |
5153 | - while (*p != '\0' && *p != ',') { | |
5154 | - if ((q - device) < sizeof(device) - 1) | |
5155 | - *q++ = *p; | |
5156 | - p++; | |
5157 | - } | |
5158 | - *q = '\0'; | |
5159 | - if (*p == ',') | |
5160 | - p++; | |
5161 | 5147 | vlan_id = 0; |
5162 | 5148 | if (get_param_value(buf, sizeof(buf), "vlan", p)) { |
5163 | 5149 | vlan_id = strtol(buf, NULL, 0); |
... | ... | @@ -5302,6 +5288,26 @@ static int net_client_init(const char *str) |
5302 | 5288 | return ret; |
5303 | 5289 | } |
5304 | 5290 | |
5291 | +static int net_client_parse(const char *str) | |
5292 | +{ | |
5293 | + const char *p; | |
5294 | + char *q; | |
5295 | + char device[64]; | |
5296 | + | |
5297 | + p = str; | |
5298 | + q = device; | |
5299 | + while (*p != '\0' && *p != ',') { | |
5300 | + if ((q - device) < sizeof(device) - 1) | |
5301 | + *q++ = *p; | |
5302 | + p++; | |
5303 | + } | |
5304 | + *q = '\0'; | |
5305 | + if (*p == ',') | |
5306 | + p++; | |
5307 | + | |
5308 | + return net_client_init(device, p); | |
5309 | +} | |
5310 | + | |
5305 | 5311 | void do_info_network(void) |
5306 | 5312 | { |
5307 | 5313 | VLANState *vlan; |
... | ... | @@ -5734,11 +5740,12 @@ static int usb_device_add(const char *devname) |
5734 | 5740 | dev = usb_baum_init(); |
5735 | 5741 | #endif |
5736 | 5742 | } else if (strstart(devname, "net:", &p)) { |
5737 | - int nicidx = strtoul(p, NULL, 0); | |
5743 | + int nic = nb_nics; | |
5738 | 5744 | |
5739 | - if (nicidx >= nb_nics || strcmp(nd_table[nicidx].model, "usb")) | |
5745 | + if (net_client_init("nic", p) < 0) | |
5740 | 5746 | return -1; |
5741 | - dev = usb_net_init(&nd_table[nicidx]); | |
5747 | + nd_table[nic].model = "usb"; | |
5748 | + dev = usb_net_init(&nd_table[nic]); | |
5742 | 5749 | } else { |
5743 | 5750 | return -1; |
5744 | 5751 | } |
... | ... | @@ -8887,16 +8894,14 @@ int main(int argc, char **argv) |
8887 | 8894 | } |
8888 | 8895 | |
8889 | 8896 | for(i = 0;i < nb_net_clients; i++) { |
8890 | - if (net_client_init(net_clients[i]) < 0) | |
8897 | + if (net_client_parse(net_clients[i]) < 0) | |
8891 | 8898 | exit(1); |
8892 | 8899 | } |
8893 | 8900 | for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) { |
8894 | 8901 | if (vlan->nb_guest_devs == 0 && vlan->nb_host_devs == 0) |
8895 | 8902 | continue; |
8896 | - if (vlan->nb_guest_devs == 0) { | |
8897 | - fprintf(stderr, "Invalid vlan (%d) with no nics\n", vlan->id); | |
8898 | - exit(1); | |
8899 | - } | |
8903 | + if (vlan->nb_guest_devs == 0) | |
8904 | + fprintf(stderr, "Warning: vlan %d with no nics\n", vlan->id); | |
8900 | 8905 | if (vlan->nb_host_devs == 0) |
8901 | 8906 | fprintf(stderr, |
8902 | 8907 | "Warning: vlan %d is not connected to host network\n", | ... | ... |