qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "andrzej zaborowski" <balrogg@gmail.com>
To: qemu-devel mailing list <qemu-devel@nongnu.org>
Subject: [Qemu-devel] Allow VLANs with no nics
Date: Thu, 17 Jul 2008 23:23:27 +0200	[thread overview]
Message-ID: <fb249edb0807171423i3078e1eft11f81ee640051684@mail.gmail.com> (raw)

Hi,
  I added the usb-net patch, and it's the only NIC that is
hot-pluggable. The current command line switch to enable it has
suboptimal syntax requiring you to know the index of the nic in
nb_table[]. Instead -usbdevice net:... could automatically add the nic
in nb_table[] when needed (see below). This requires allowing empty
vlans on start, so the patch makes the "vlan (N) with no nics" message
non-fatal.  Do you have suggestions?

Cheers

diff --git a/qemu-doc.texi b/qemu-doc.texi
index 78ba587..62eda1c 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -567,7 +567,7 @@ available devices.
 Braille device.  This will use BrlAPI to display the braille output on a real
 or fake device.

-@item net:nic_num
+@item net:options
 Network adapter that supports CDC ethernet and RNDIS protocols.

 @end table
@@ -587,7 +587,7 @@ Qemu can emulate several different models of network card.
 Valid values for @var{type} are
 @code{i82551}, @code{i82557b}, @code{i82559er},
 @code{ne2k_pci}, @code{ne2k_isa}, @code{pcnet}, @code{rtl8139},
-@code{e1000}, @code{smc91c111}, @code{lance}, @code{mcf_fec} and @code{usb}.
+@code{e1000}, @code{smc91c111}, @code{lance} and @code{mcf_fec}.
 Not all devices are supported on all targets.  Use -net nic,model=?
 for a list of available devices for your target.

@@ -1710,14 +1710,12 @@ serial converter, faking a Matrix Orbital LCD
Display (USB ID 0403:FA00).
 @item braille
 Braille device.  This will use BrlAPI to display the braille output on a real
 or fake device.
-@item net:@var{nic_num}
-Network adapter that supports CDC ethernet and RNDIS protocols.  This must be
-used together with the @code{-net nic,model=usb,...} option (see description),
-where @var{nic_num} specifies the index of the @code{-net nic,...} option
-describing the interface (zero-based).
-For instance, user-mode networking can be used by specifying
-@example
-qemu -net user,vlan=1 -net nic,model=usb,vlan=1 -usbdevice net:0
[...OPTIONS...]
+@item net:@var{options}
+Network adapter that supports CDC ethernet and RNDIS protocols.  @var{options}
+specifies NIC options as with @code{-net nic,}@var{options} (see description).
+For instance, user-mode networking can be used with
+@example
+qemu [...OPTIONS...] -net user,vlan=0 -usbdevice net:vlan=0
 @end example
 Currently this cannot be used in machines that support PCI NICs.
 @end table
diff --git a/vl.c b/vl.c
index 613fa84..3005fe8 100644
--- a/vl.c
+++ b/vl.c
@@ -4917,26 +4917,12 @@ static int check_params(char *buf, int buf_size,
     return 0;
 }

-
-static int net_client_init(const char *str)
+static int net_client_init(const char *device, const char *p)
 {
-    const char *p;
-    char *q;
-    char device[64];
     char buf[1024];
     int vlan_id, ret;
     VLANState *vlan;

-    p = str;
-    q = device;
-    while (*p != '\0' && *p != ',') {
-        if ((q - device) < sizeof(device) - 1)
-            *q++ = *p;
-        p++;
-    }
-    *q = '\0';
-    if (*p == ',')
-        p++;
     vlan_id = 0;
     if (get_param_value(buf, sizeof(buf), "vlan", p)) {
         vlan_id = strtol(buf, NULL, 0);
@@ -5057,6 +5043,26 @@ static int net_client_init(const char *str)
     return ret;
 }

+static int net_client_parse(const char *str)
+{
+    const char *p;
+    char *q;
+    char device[64];
+
+    p = str;
+    q = device;
+    while (*p != '\0' && *p != ',') {
+        if ((q - device) < sizeof(device) - 1)
+            *q++ = *p;
+        p++;
+    }
+    *q = '\0';
+    if (*p == ',')
+        p++;
+
+    return net_client_init(device, p);
+}
+
 void do_info_network(void)
 {
     VLANState *vlan;
@@ -5480,6 +5486,13 @@ static int usb_device_add(const char *devname)
         dev = usb_keyboard_init();
     } else if (strstart(devname, "disk:", &p)) {
         dev = usb_msd_init(p);
+    } else if (strstart(devname, "net:", &p)) {
+        int nic = nb_nics;
+
+        if (net_client_init("nic", p) < 0)
+            return -1;
+        nd_table[nic].model = "usb";
+        dev = usb_net_init(&nd_table[nic]);
     } else if (!strcmp(devname, "wacom-tablet")) {
         dev = usb_wacom_init();
     } else if (strstart(devname, "serial:", &p)) {
@@ -5488,12 +5501,6 @@ static int usb_device_add(const char *devname)
     } else if (!strcmp(devname, "braille")) {
         dev = usb_baum_init();
 #endif
-    } else if (strstart(devname, "net:", &p)) {
-        int nicidx = strtoul(p, NULL, 0);
-
-        if (nicidx >= nb_nics || strcmp(nd_table[nicidx].model, "usb"))
-            return -1;
-        dev = usb_net_init(&nd_table[nicidx]);
     } else {
         return -1;
     }
@@ -8639,16 +8646,14 @@ int main(int argc, char **argv)
     }

     for(i = 0;i < nb_net_clients; i++) {
-        if (net_client_init(net_clients[i]) < 0)
+        if (net_client_parse(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_guest_devs == 0)
+            fprintf(stderr, "Warning: vlan %d with no nics\n", vlan->id);
         if (vlan->nb_host_devs == 0)
             fprintf(stderr,
                     "Warning: vlan %d is not connected to host network\n",

                 reply	other threads:[~2008-07-17 21:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb249edb0807171423i3078e1eft11f81ee640051684@mail.gmail.com \
    --to=balrogg@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).