All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000
@ 2008-12-09 10:55 Mark McLoughlin
  2008-12-09 10:55 ` [Qemu-devel] [PATCH 1/4] Add 'set_link' monitor command Mark McLoughlin
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Mark McLoughlin @ 2008-12-09 10:55 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Rusty Russell, qemu-devel

Hi,
        Here's a small patch set which adds link up/down
emulation to e1000 via a "set_link" monitor command. This is
useful for people who want to e.g. test how applications
and/or the guest OS handles this condition.

        The command itself takes a VLAN ID and device index
in order to identify which device to modify. That's a bit
lame and could clearly by improved if the overall idea was
thought to be sound.

Thanks,
Mark.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 1/4] Add 'set_link' monitor command
  2008-12-09 10:55 [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000 Mark McLoughlin
@ 2008-12-09 10:55 ` Mark McLoughlin
  2008-12-09 10:55   ` [Qemu-devel] [PATCH 2/4] Add device index to 'info network' output Mark McLoughlin
  2008-12-09 15:01   ` [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command Anthony Liguori
  2008-12-09 11:23 ` [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000 Daniel P. Berrange
  2008-12-09 15:06 ` [Qemu-devel] " Anthony Liguori
  2 siblings, 2 replies; 26+ messages in thread
From: Mark McLoughlin @ 2008-12-09 10:55 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, Rusty Russell, qemu-devel

Add a monitor command to setting a given network device's link status
to 'up' or 'down'.

Allows simulation of network cable disconnect.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 monitor.c |    1 +
 net.c     |   41 ++++++++++++++++++++++++++++++++++++++++-
 net.h     |    2 ++
 3 files changed, 43 insertions(+), 1 deletions(-)

diff --git a/monitor.c b/monitor.c
index f142a87..ac74711 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1497,6 +1497,7 @@ static const term_cmd_t term_cmds[] = {
       "value", "set maximum speed (in bytes) for migrations" },
     { "balloon", "i", do_balloon,
       "target", "request VM to change it's memory allocation (in MB)" },
+    { "set_link", "iis", do_set_link, "vlan_id dev_idx [up|down]" },
     { NULL, NULL, },
 };
 
diff --git a/net.c b/net.c
index cbf1cdf..250519c 100644
--- a/net.c
+++ b/net.c
@@ -358,12 +358,15 @@ void qemu_send_packet(VLANClientState *vc1, const uint8_t *buf, int size)
     VLANState *vlan = vc1->vlan;
     VLANClientState *vc;
 
+    if (vc1->link_down)
+        return;
+
 #ifdef DEBUG_NET
     printf("vlan %d send:\n", vlan->id);
     hex_dump(stdout, buf, size);
 #endif
     for(vc = vlan->first_client; vc != NULL; vc = vc->next) {
-        if (vc != vc1) {
+        if (vc != vc1 && !vc->link_down) {
             vc->fd_read(vc->opaque, buf, size);
         }
     }
@@ -1560,6 +1563,42 @@ void do_info_network(void)
     }
 }
 
+int do_set_link(int vlan_id, int device_idx, const char *up_or_down)
+{
+    VLANState *vlan;
+    VLANClientState *vc;
+    int i = 0;
+
+    for(vlan = first_vlan; vlan != NULL; vlan = vlan->next)
+        if (vlan->id == vlan_id)
+            break;
+
+    if (!vlan) {
+        term_printf("could not find vlan '%d'\n", vlan_id);
+        return 0;
+    }
+
+    for(vc = vlan->first_client; vc != NULL; vc = vc->next)
+        if (i++ == device_idx)
+            break;
+
+    if (!vc) {
+        term_printf("could not find device '%d' on vlan '%d'\n",
+                    device_idx, vlan_id);
+        return 0;
+    }
+
+    if (strcmp(up_or_down, "up") == 0)
+        vc->link_down = 0;
+    else if (strcmp(up_or_down, "down") == 0)
+        vc->link_down = 1;
+    else
+        term_printf("invalid link status '%s'; only 'up' or 'down' valid\n",
+                    up_or_down);
+
+    return 1;
+}
+
 void net_cleanup(void)
 {
     VLANState *vlan;
diff --git a/net.h b/net.h
index a2b01ae..e7cd062 100644
--- a/net.h
+++ b/net.h
@@ -10,6 +10,7 @@ struct VLANClientState {
     /* Packets may still be sent if this returns zero.  It's used to
        rate-limit the slirp code.  */
     IOCanRWHandler *fd_can_read;
+    int link_down;
     void *opaque;
     struct VLANClientState *next;
     struct VLANState *vlan;
@@ -34,6 +35,7 @@ void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
 void qemu_handler_true(void *opaque);
 
 void do_info_network(void);
+int do_set_link(int vlan_id, int device_idx, const char *up_or_down);
 
 /* NIC info */
 
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 2/4] Add device index to 'info network' output
  2008-12-09 10:55 ` [Qemu-devel] [PATCH 1/4] Add 'set_link' monitor command Mark McLoughlin
@ 2008-12-09 10:55   ` Mark McLoughlin
  2008-12-09 10:55     ` [Qemu-devel] [PATCH 3/4] Allow devices be notified of link status change Mark McLoughlin
  2008-12-09 15:04     ` [Qemu-devel] Re: [PATCH 2/4] Add device index to 'info network' output Anthony Liguori
  2008-12-09 15:01   ` [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command Anthony Liguori
  1 sibling, 2 replies; 26+ messages in thread
From: Mark McLoughlin @ 2008-12-09 10:55 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, Rusty Russell, qemu-devel

The 'set_link' command requires the user to specify a device index.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/net.c b/net.c
index 250519c..35ec501 100644
--- a/net.c
+++ b/net.c
@@ -1557,9 +1557,10 @@ void do_info_network(void)
     VLANClientState *vc;
 
     for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
+        int i = 0;
         term_printf("VLAN %d devices:\n", vlan->id);
         for(vc = vlan->first_client; vc != NULL; vc = vc->next)
-            term_printf("  %s\n", vc->info_str);
+            term_printf("  %d %s\n", i++, vc->info_str);
     }
 }
 
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 3/4] Allow devices be notified of link status change
  2008-12-09 10:55   ` [Qemu-devel] [PATCH 2/4] Add device index to 'info network' output Mark McLoughlin
@ 2008-12-09 10:55     ` Mark McLoughlin
  2008-12-09 10:55       ` [Qemu-devel] [PATCH 4/4] Implement e1000 link status Mark McLoughlin
  2008-12-09 15:04     ` [Qemu-devel] Re: [PATCH 2/4] Add device index to 'info network' output Anthony Liguori
  1 sibling, 1 reply; 26+ messages in thread
From: Mark McLoughlin @ 2008-12-09 10:55 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, Rusty Russell, qemu-devel

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |    3 +++
 net.h |    3 +++
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/net.c b/net.c
index 35ec501..883544f 100644
--- a/net.c
+++ b/net.c
@@ -1597,6 +1597,9 @@ int do_set_link(int vlan_id, int device_idx, const char *up_or_down)
         term_printf("invalid link status '%s'; only 'up' or 'down' valid\n",
                     up_or_down);
 
+    if (vc->link_status_changed)
+        vc->link_status_changed(vc);
+
     return 1;
 }
 
diff --git a/net.h b/net.h
index e7cd062..75b22c1 100644
--- a/net.h
+++ b/net.h
@@ -5,11 +5,14 @@
 
 typedef struct VLANClientState VLANClientState;
 
+typedef void (LinkStatusChanged)(VLANClientState *);
+
 struct VLANClientState {
     IOReadHandler *fd_read;
     /* Packets may still be sent if this returns zero.  It's used to
        rate-limit the slirp code.  */
     IOCanRWHandler *fd_can_read;
+    LinkStatusChanged *link_status_changed;
     int link_down;
     void *opaque;
     struct VLANClientState *next;
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 4/4] Implement e1000 link status
  2008-12-09 10:55     ` [Qemu-devel] [PATCH 3/4] Allow devices be notified of link status change Mark McLoughlin
@ 2008-12-09 10:55       ` Mark McLoughlin
  0 siblings, 0 replies; 26+ messages in thread
From: Mark McLoughlin @ 2008-12-09 10:55 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, Rusty Russell, qemu-devel

On link up or down we set the E1000_STATUS_LU ("link up") bit
in the status register and set the E1000_ICR_LSC ("link
status changed") bit in the interrupt cause register before
interrupting the guest.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/e1000.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index f07936f..c541e36 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -570,6 +570,21 @@ receive_filter(E1000State *s, const uint8_t *buf, int size)
     return 0;
 }
 
+static void
+e1000_set_link_status(VLANClientState *vc)
+{
+    E1000State *s = vc->opaque;
+    uint32_t old_status = s->mac_reg[STATUS];
+
+    if (vc->link_down)
+        s->mac_reg[STATUS] &= ~E1000_STATUS_LU;
+    else
+        s->mac_reg[STATUS] |= E1000_STATUS_LU;
+
+    if (s->mac_reg[STATUS] != old_status)
+        set_ics(s, 0, E1000_ICR_LSC);
+}
+
 static int
 e1000_can_receive(void *opaque)
 {
@@ -1061,6 +1076,7 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
 
     d->vc = qemu_new_vlan_client(nd->vlan, e1000_receive,
                                  e1000_can_receive, d);
+    d->vc->link_status_changed = e1000_set_link_status;
 
     snprintf(d->vc->info_str, sizeof(d->vc->info_str),
              "%s macaddr=%02x:%02x:%02x:%02x:%02x:%02x", info_str,
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000
  2008-12-09 10:55 [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000 Mark McLoughlin
  2008-12-09 10:55 ` [Qemu-devel] [PATCH 1/4] Add 'set_link' monitor command Mark McLoughlin
@ 2008-12-09 11:23 ` Daniel P. Berrange
  2008-12-09 13:57   ` Dor Laor
  2008-12-09 15:06 ` [Qemu-devel] " Anthony Liguori
  2 siblings, 1 reply; 26+ messages in thread
From: Daniel P. Berrange @ 2008-12-09 11:23 UTC (permalink / raw)
  To: qemu-devel

On Tue, Dec 09, 2008 at 10:55:39AM +0000, Mark McLoughlin wrote:
> Hi,
>         Here's a small patch set which adds link up/down
> emulation to e1000 via a "set_link" monitor command. This is
> useful for people who want to e.g. test how applications
> and/or the guest OS handles this condition.

It sounds like it could also be useful for people who use bridging of
guests to the LAN on mobile devices. eg, a management tool could 
monitor for when I unplugged my laptop from the ethernet and set the
guest link down. When I then plug it back it, it'd set the link back
up, and the guest (if using NetworkManager or equivalent) would be
able to correctly DHCP a new address. In current scenario with the
guest totally unaware of host link sstatus, they just continue using
the original bogus DHCP address at least until the renew time.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000
  2008-12-09 11:23 ` [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000 Daniel P. Berrange
@ 2008-12-09 13:57   ` Dor Laor
  0 siblings, 0 replies; 26+ messages in thread
From: Dor Laor @ 2008-12-09 13:57 UTC (permalink / raw)
  To: Daniel P. Berrange, qemu-devel

Daniel P. Berrange wrote:
> On Tue, Dec 09, 2008 at 10:55:39AM +0000, Mark McLoughlin wrote:
>   
>> Hi,
>>         Here's a small patch set which adds link up/down
>> emulation to e1000 via a "set_link" monitor command. This is
>> useful for people who want to e.g. test how applications
>> and/or the guest OS handles this condition.
>>     
>
> It sounds like it could also be useful for people who use bridging of
> guests to the LAN on mobile devices. eg, a management tool could 
> monitor for when I unplugged my laptop from the ethernet and set the
> guest link down. When I then plug it back it, it'd set the link back
> up, and the guest (if using NetworkManager or equivalent) would be
> able to correctly DHCP a new address. In current scenario with the
> guest totally unaware of host link sstatus, they just continue using
> the original bogus DHCP address at least until the renew time.
>
> Daniel
>   
Indeed.
Besides that its also good for windows virtio network certification. MS 
has a test
that needs to play with the link status.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command
  2008-12-09 10:55 ` [Qemu-devel] [PATCH 1/4] Add 'set_link' monitor command Mark McLoughlin
  2008-12-09 10:55   ` [Qemu-devel] [PATCH 2/4] Add device index to 'info network' output Mark McLoughlin
@ 2008-12-09 15:01   ` Anthony Liguori
  2008-12-12 14:45     ` Mark McLoughlin
  1 sibling, 1 reply; 26+ messages in thread
From: Anthony Liguori @ 2008-12-09 15:01 UTC (permalink / raw)
  To: Mark McLoughlin; +Cc: Rusty Russell, qemu-devel

Mark McLoughlin wrote:
> Add a monitor command to setting a given network device's link status
> to 'up' or 'down'.
>
> Allows simulation of network cable disconnect.
>
> Signed-off-by: Mark McLoughlin <markmc@redhat.com>
> ---
>  monitor.c |    1 +
>  net.c     |   41 ++++++++++++++++++++++++++++++++++++++++-
>  net.h     |    2 ++
>  3 files changed, 43 insertions(+), 1 deletions(-)
>
> diff --git a/monitor.c b/monitor.c
> index f142a87..ac74711 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -1497,6 +1497,7 @@ static const term_cmd_t term_cmds[] = {
>        "value", "set maximum speed (in bytes) for migrations" },
>      { "balloon", "i", do_balloon,
>        "target", "request VM to change it's memory allocation (in MB)" },
> +    { "set_link", "iis", do_set_link, "vlan_id dev_idx [up|down]" },
>      { NULL, NULL, },
>  };
>   

This command seems reasonable to me but the dev_idx thing is a bit too 
hacky.

> +    for(vc = vlan->first_client; vc != NULL; vc = vc->next)
> +        if (i++ == device_idx)
> +            break;
>   

I think a better way would be to allow a user to specify an id for the 
nic that gets saved early on.  info nics should print the id and a 
default id should be assigned.  I think you could argue either way as to 
whether the ids should be vlan local or global.

I sort of think that making them global has a number of advantages.  You 
could also use a string to identify the nics globally, it's up to you.

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Qemu-devel] Re: [PATCH 2/4] Add device index to 'info network' output
  2008-12-09 10:55   ` [Qemu-devel] [PATCH 2/4] Add device index to 'info network' output Mark McLoughlin
  2008-12-09 10:55     ` [Qemu-devel] [PATCH 3/4] Allow devices be notified of link status change Mark McLoughlin
@ 2008-12-09 15:04     ` Anthony Liguori
  1 sibling, 0 replies; 26+ messages in thread
From: Anthony Liguori @ 2008-12-09 15:04 UTC (permalink / raw)
  To: Mark McLoughlin; +Cc: Rusty Russell, qemu-devel

Mark McLoughlin wrote:
> The 'set_link' command requires the user to specify a device index.
>
> Signed-off-by: Mark McLoughlin <markmc@redhat.com>
> ---
>  net.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/net.c b/net.c
> index 250519c..35ec501 100644
> --- a/net.c
> +++ b/net.c
> @@ -1557,9 +1557,10 @@ void do_info_network(void)
>      VLANClientState *vc;
>  
>      for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
> +        int i = 0;
>          term_printf("VLAN %d devices:\n", vlan->id);
>          for(vc = vlan->first_client; vc != NULL; vc = vc->next)
> -            term_printf("  %s\n", vc->info_str);
> +            term_printf("  %d %s\n", i++, vc->info_str);
>   

This info command is unfortunately not very well formed, but I still 
think you should do "  id=%d %s\n", i++, vc->info_str.

Regards,

Anthony Liguori

>      }
>  }
>  
>   

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Qemu-devel] Re: [PATCH 0/4] Add nic link up/down emulation to e1000
  2008-12-09 10:55 [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000 Mark McLoughlin
  2008-12-09 10:55 ` [Qemu-devel] [PATCH 1/4] Add 'set_link' monitor command Mark McLoughlin
  2008-12-09 11:23 ` [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000 Daniel P. Berrange
@ 2008-12-09 15:06 ` Anthony Liguori
  2008-12-10  8:53   ` Avi Kivity
  2 siblings, 1 reply; 26+ messages in thread
From: Anthony Liguori @ 2008-12-09 15:06 UTC (permalink / raw)
  To: Mark McLoughlin; +Cc: Rusty Russell, qemu-devel, Avi Kivity

Mark McLoughlin wrote:
> Hi,
>         Here's a small patch set which adds link up/down
> emulation to e1000 via a "set_link" monitor command. This is
> useful for people who want to e.g. test how applications
> and/or the guest OS handles this condition.
>
>         The command itself takes a VLAN ID and device index
> in order to identify which device to modify. That's a bit
> lame and could clearly by improved if the overall idea was
> thought to be sound.
>   

Yeah, this series looks good (as does the virtio-net one).  I plan on 
merging virtio-net either today or tomorrow and I can merge your 
virtio-net series into QEMU too.

BTW, I plan on introducing qemu_sendv_packet() to QEMU in the process of 
this.

Regards,

Anthony Liguori

> Thanks,
> Mark.
>
>
>   

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Qemu-devel] Re: [PATCH 0/4] Add nic link up/down emulation to e1000
  2008-12-09 15:06 ` [Qemu-devel] " Anthony Liguori
@ 2008-12-10  8:53   ` Avi Kivity
  0 siblings, 0 replies; 26+ messages in thread
From: Avi Kivity @ 2008-12-10  8:53 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, Rusty Russell, qemu-devel, Avi Kivity

Anthony Liguori wrote:
> Mark McLoughlin wrote:
>> Hi,
>>         Here's a small patch set which adds link up/down
>> emulation to e1000 via a "set_link" monitor command. This is
>> useful for people who want to e.g. test how applications
>> and/or the guest OS handles this condition.
>>
>>         The command itself takes a VLAN ID and device index
>> in order to identify which device to modify. That's a bit
>> lame and could clearly by improved if the overall idea was
>> thought to be sound.
>>   
>
> Yeah, this series looks good (as does the virtio-net one).  I plan on 
> merging virtio-net either today or tomorrow and I can merge your 
> virtio-net series into QEMU too. 

Excellent.  Mark, I'll get your patches from the next qemu merge.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command
  2008-12-09 15:01   ` [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command Anthony Liguori
@ 2008-12-12 14:45     ` Mark McLoughlin
  2008-12-12 14:46       ` [Qemu-devel] [PATCH 1/5] Add a model string to VLANClientState Mark McLoughlin
  2009-01-06 14:59       ` [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command Mark McLoughlin
  0 siblings, 2 replies; 26+ messages in thread
From: Mark McLoughlin @ 2008-12-12 14:45 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel

On Tue, 2008-12-09 at 09:01 -0600, Anthony Liguori wrote:
> > +    for(vc = vlan->first_client; vc != NULL; vc = vc->next)
> > +        if (i++ == device_idx)
> > +            break;
> >   
> 
> I think a better way would be to allow a user to specify an id for the 
> nic that gets saved early on.  info nics should print the id and a 
> default id should be assigned.  I think you could argue either way as to 
> whether the ids should be vlan local or global.
> 
> I sort of think that making them global has a number of advantages.  You 
> could also use a string to identify the nics globally, it's up to you.

Okay, here's a few patches to add a vlan client name.

I'll repost the set_link patches once we agree on this part.

Cheers,
Mark.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 1/5] Add a model string to VLANClientState
  2008-12-12 14:45     ` Mark McLoughlin
@ 2008-12-12 14:46       ` Mark McLoughlin
  2008-12-12 14:46         ` [Qemu-devel] [PATCH 2/5] Assign a name to each VLAN client Mark McLoughlin
  2009-01-06 14:59       ` [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command Mark McLoughlin
  1 sibling, 1 reply; 26+ messages in thread
From: Mark McLoughlin @ 2008-12-12 14:46 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, qemu-devel

Don't lose track of what type/model a vlan client is so that we can
e.g. assign a global per-model id to clients.

The entire patch is basically a tedious excercise in making sure the
type/model string gets propagated down to qemu_new_vlan_client().

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/e1000.c          |    4 +-
 hw/eepro100.c       |    3 +-
 hw/etraxfs_eth.c    |    2 +-
 hw/mcf_fec.c        |    4 +-
 hw/mipsnet.c        |    4 +-
 hw/musicpal.c       |    3 +-
 hw/ne2000.c         |    8 ++--
 hw/pcnet.c          |    4 +-
 hw/rtl8139.c        |    4 +-
 hw/smc91c111.c      |    4 +-
 hw/stellaris_enet.c |    4 +-
 hw/usb-net.c        |    2 +-
 net.c               |   78 ++++++++++++++++++++++++++++-----------------------
 net.h               |    2 +
 sysemu.h            |    2 +-
 tap-win32.c         |    4 +-
 16 files changed, 72 insertions(+), 60 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index 67a062a..45706bb 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1071,8 +1071,8 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
     d->rxbuf_min_shift = 1;
     memset(&d->tx, 0, sizeof d->tx);
 
-    d->vc = qemu_new_vlan_client(nd->vlan, e1000_receive,
-                                 e1000_can_receive, d);
+    d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 e1000_receive, e1000_can_receive, d);
 
     snprintf(d->vc->info_str, sizeof(d->vc->info_str),
              "%s macaddr=%02x:%02x:%02x:%02x:%02x:%02x", info_str,
diff --git a/hw/eepro100.c b/hw/eepro100.c
index cb3ca09..a7861ca 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1776,7 +1776,8 @@ static void nic_init(PCIBus * bus, NICInfo * nd,
 
     nic_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, nic_receive, nic_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 nic_receive, nic_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "eepro100 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index 51a129a..244a23d 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -596,7 +596,7 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
 	eth->ethregs = cpu_register_io_memory(0, eth_read, eth_write, eth);
 	cpu_register_physical_memory (base, 0x5c, eth->ethregs);
 
-	eth->vc = qemu_new_vlan_client(nd->vlan, 
+	eth->vc = qemu_new_vlan_client(nd->vlan, nd->model,
 				       eth_receive, eth_can_receive, eth);
 
 	return dma;
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 0049860..7e3afa5 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -452,7 +452,7 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
                                        mcf_fec_writefn, s);
     cpu_register_physical_memory(base, 0x400, iomemtype);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, mcf_fec_receive,
-                                 mcf_fec_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 mcf_fec_receive, mcf_fec_can_receive, s);
     memcpy(s->macaddr, nd->macaddr, 6);
 }
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index af560f8..549e6f3 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -250,8 +250,8 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
     s->irq = irq;
     s->nd = nd;
     if (nd && nd->vlan) {
-        s->vc = qemu_new_vlan_client(nd->vlan, mipsnet_receive,
-                                     mipsnet_can_receive, s);
+        s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                     mipsnet_receive, mipsnet_can_receive, s);
     } else {
         s->vc = NULL;
     }
diff --git a/hw/musicpal.c b/hw/musicpal.c
index c5a5b6f..d172a11 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -718,7 +718,8 @@ static void mv88w8618_eth_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     if (!s)
         return;
     s->irq = irq;
-    s->vc = qemu_new_vlan_client(nd->vlan, eth_receive, eth_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 eth_receive, eth_can_receive, s);
     iomemtype = cpu_register_io_memory(0, mv88w8618_eth_readfn,
                                        mv88w8618_eth_writefn, s);
     cpu_register_physical_memory(base, MP_ETH_SIZE, iomemtype);
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 3f0ccf5..dc97989 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -741,8 +741,8 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
 
     ne2000_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, ne2000_receive,
-                                 ne2000_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 ne2000_receive, ne2000_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "ne2000 macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
@@ -811,8 +811,8 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
     s->pci_dev = (PCIDevice *)d;
     memcpy(s->macaddr, nd->macaddr, 6);
     ne2000_reset(s);
-    s->vc = qemu_new_vlan_client(nd->vlan, ne2000_receive,
-                                 ne2000_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 ne2000_receive, ne2000_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "ne2000 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 30c453c..e961a06 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1936,8 +1936,8 @@ static void pcnet_common_init(PCNetState *d, NICInfo *nd, const char *info_str)
     d->nd = nd;
 
     if (nd && nd->vlan) {
-        d->vc = qemu_new_vlan_client(nd->vlan, pcnet_receive,
-                                     pcnet_can_receive, d);
+        d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                     pcnet_receive, pcnet_can_receive, d);
 
         snprintf(d->vc->info_str, sizeof(d->vc->info_str),
                  "pcnet macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index feffa9c..f3f6564 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3438,8 +3438,8 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
     s->pci_dev = (PCIDevice *)d;
     memcpy(s->macaddr, nd->macaddr, 6);
     rtl8139_reset(s);
-    s->vc = qemu_new_vlan_client(nd->vlan, rtl8139_receive,
-                                 rtl8139_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 rtl8139_receive, rtl8139_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "rtl8139 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index a517033..fadd151 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -704,7 +704,7 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
 
     smc91c111_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, smc91c111_receive,
-                                 smc91c111_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 smc91c111_receive, smc91c111_can_receive, s);
     /* ??? Save/restore.  */
 }
diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c
index 09d92b1..bd8dcd9 100644
--- a/hw/stellaris_enet.c
+++ b/hw/stellaris_enet.c
@@ -397,8 +397,8 @@ void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     memcpy(s->macaddr, nd->macaddr, 6);
 
     if (nd->vlan)
-        s->vc = qemu_new_vlan_client(nd->vlan, stellaris_enet_receive,
-                                     stellaris_enet_can_receive, s);
+        s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                     stellaris_enet_receive, stellaris_enet_can_receive, s);
 
     stellaris_enet_reset(s);
     register_savevm("stellaris_enet", -1, 1,
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 82005af..06ff668 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1454,7 +1454,7 @@ USBDevice *usb_net_init(NICInfo *nd)
 
     pstrcpy(s->dev.devname, sizeof(s->dev.devname),
                     "QEMU USB Network Interface");
-    s->vc = qemu_new_vlan_client(nd->vlan,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                     usbnet_receive, usbnet_can_receive, s);
 
     snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
diff --git a/net.c b/net.c
index cbf1cdf..d046b5e 100644
--- a/net.c
+++ b/net.c
@@ -305,6 +305,7 @@ static int parse_unix_path(struct sockaddr_un *uaddr, const char *str)
 #endif
 
 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
+                                      const char *model,
                                       IOReadHandler *fd_read,
                                       IOCanRWHandler *fd_can_read,
                                       void *opaque)
@@ -313,6 +314,7 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
     vc = qemu_mallocz(sizeof(VLANClientState));
     if (!vc)
         return NULL;
+    vc->model = strdup(model);
     vc->fd_read = fd_read;
     vc->fd_can_read = fd_can_read;
     vc->opaque = opaque;
@@ -333,6 +335,7 @@ void qemu_del_vlan_client(VLANClientState *vc)
     while (*pvc != NULL)
         if (*pvc == vc) {
             *pvc = vc->next;
+            free(vc->model);
             free(vc);
             break;
         } else
@@ -406,13 +409,13 @@ static void slirp_receive(void *opaque, const uint8_t *buf, int size)
     slirp_input(buf, size);
 }
 
-static int net_slirp_init(VLANState *vlan)
+static int net_slirp_init(VLANState *vlan, const char *model)
 {
     if (!slirp_inited) {
         slirp_inited = 1;
         slirp_init();
     }
-    slirp_vc = qemu_new_vlan_client(vlan,
+    slirp_vc = qemu_new_vlan_client(vlan, model,
                                     slirp_receive, NULL, NULL);
     snprintf(slirp_vc->info_str, sizeof(slirp_vc->info_str), "user redirector");
     return 0;
@@ -611,7 +614,7 @@ static void tap_send(void *opaque)
 
 /* fd support */
 
-static TAPState *net_tap_fd_init(VLANState *vlan, int fd)
+static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
 {
     TAPState *s;
 
@@ -619,7 +622,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, int fd)
     if (!s)
         return NULL;
     s->fd = fd;
-    s->vc = qemu_new_vlan_client(vlan, tap_receive, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
     qemu_set_fd_handler(s->fd, tap_send, NULL, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str), "tap: fd=%d", fd);
     return s;
@@ -851,7 +854,7 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)
     return 0;
 }
 
-static int net_tap_init(VLANState *vlan, const char *ifname1,
+static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
                         const char *setup_script, const char *down_script)
 {
     TAPState *s;
@@ -872,7 +875,7 @@ static int net_tap_init(VLANState *vlan, const char *ifname1,
 	if (launch_script(setup_script, ifname, fd))
 	    return -1;
     }
-    s = net_tap_fd_init(vlan, fd);
+    s = net_tap_fd_init(vlan, model, fd);
     if (!s)
         return -1;
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
@@ -915,8 +918,8 @@ static void vde_from_qemu(void *opaque, const uint8_t *buf, int size)
     }
 }
 
-static int net_vde_init(VLANState *vlan, const char *sock, int port,
-                        const char *group, int mode)
+static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
+                        int port, const char *group, int mode)
 {
     VDEState *s;
     char *init_group = strlen(group) ? (char *)group : NULL;
@@ -936,7 +939,7 @@ static int net_vde_init(VLANState *vlan, const char *sock, int port,
         free(s);
         return -1;
     }
-    s->vc = qemu_new_vlan_client(vlan, vde_from_qemu, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, vde_from_qemu, NULL, s);
     qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str), "vde: sock=%s fd=%d",
              sock, vde_datafd(s->vde));
@@ -957,6 +960,7 @@ typedef struct NetSocketState {
 
 typedef struct NetSocketListenState {
     VLANState *vlan;
+    char *model;
     int fd;
 } NetSocketListenState;
 
@@ -1110,8 +1114,8 @@ fail:
     return -1;
 }
 
-static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, int fd,
-                                          int is_connected)
+static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *model,
+                                                int fd, int is_connected)
 {
     struct sockaddr_in saddr;
     int newfd;
@@ -1154,7 +1158,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, int fd,
         return NULL;
     s->fd = fd;
 
-    s->vc = qemu_new_vlan_client(vlan, net_socket_receive_dgram, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, net_socket_receive_dgram, NULL, s);
     qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
 
     /* mcast: save bound address as dst */
@@ -1173,15 +1177,15 @@ static void net_socket_connect(void *opaque)
     qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
 }
 
-static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, int fd,
-                                          int is_connected)
+static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *model,
+                                                 int fd, int is_connected)
 {
     NetSocketState *s;
     s = qemu_mallocz(sizeof(NetSocketState));
     if (!s)
         return NULL;
     s->fd = fd;
-    s->vc = qemu_new_vlan_client(vlan,
+    s->vc = qemu_new_vlan_client(vlan, model,
                                  net_socket_receive, NULL, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "socket: fd=%d", fd);
@@ -1193,8 +1197,8 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, int fd,
     return s;
 }
 
-static NetSocketState *net_socket_fd_init(VLANState *vlan, int fd,
-                                          int is_connected)
+static NetSocketState *net_socket_fd_init(VLANState *vlan, const char *model,
+                                          int fd, int is_connected)
 {
     int so_type=-1, optlen=sizeof(so_type);
 
@@ -1205,13 +1209,13 @@ static NetSocketState *net_socket_fd_init(VLANState *vlan, int fd,
     }
     switch(so_type) {
     case SOCK_DGRAM:
-        return net_socket_fd_init_dgram(vlan, fd, is_connected);
+        return net_socket_fd_init_dgram(vlan, model, fd, is_connected);
     case SOCK_STREAM:
-        return net_socket_fd_init_stream(vlan, fd, is_connected);
+        return net_socket_fd_init_stream(vlan, model, fd, is_connected);
     default:
         /* who knows ... this could be a eg. a pty, do warn and continue as stream */
         fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
-        return net_socket_fd_init_stream(vlan, fd, is_connected);
+        return net_socket_fd_init_stream(vlan, model, fd, is_connected);
     }
     return NULL;
 }
@@ -1233,7 +1237,7 @@ static void net_socket_accept(void *opaque)
             break;
         }
     }
-    s1 = net_socket_fd_init(s->vlan, fd, 1);
+    s1 = net_socket_fd_init(s->vlan, s->model, fd, 1);
     if (!s1) {
         closesocket(fd);
     } else {
@@ -1243,7 +1247,8 @@ static void net_socket_accept(void *opaque)
     }
 }
 
-static int net_socket_listen_init(VLANState *vlan, const char *host_str)
+static int net_socket_listen_init(VLANState *vlan, const char *model,
+                                  const char *host_str)
 {
     NetSocketListenState *s;
     int fd, val, ret;
@@ -1278,12 +1283,14 @@ static int net_socket_listen_init(VLANState *vlan, const char *host_str)
         return -1;
     }
     s->vlan = vlan;
+    s->model = strdup(model);
     s->fd = fd;
     qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
     return 0;
 }
 
-static int net_socket_connect_init(VLANState *vlan, const char *host_str)
+static int net_socket_connect_init(VLANState *vlan, const char *model,
+                                   const char *host_str)
 {
     NetSocketState *s;
     int fd, connected, ret, err;
@@ -1321,7 +1328,7 @@ static int net_socket_connect_init(VLANState *vlan, const char *host_str)
             break;
         }
     }
-    s = net_socket_fd_init(vlan, fd, connected);
+    s = net_socket_fd_init(vlan, model, fd, connected);
     if (!s)
         return -1;
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
@@ -1330,7 +1337,8 @@ static int net_socket_connect_init(VLANState *vlan, const char *host_str)
     return 0;
 }
 
-static int net_socket_mcast_init(VLANState *vlan, const char *host_str)
+static int net_socket_mcast_init(VLANState *vlan, const char *model,
+                                 const char *host_str)
 {
     NetSocketState *s;
     int fd;
@@ -1344,7 +1352,7 @@ static int net_socket_mcast_init(VLANState *vlan, const char *host_str)
     if (fd < 0)
 	return -1;
 
-    s = net_socket_fd_init(vlan, fd, 0);
+    s = net_socket_fd_init(vlan, model, fd, 0);
     if (!s)
         return -1;
 
@@ -1434,7 +1442,7 @@ int net_client_init(const char *device, const char *p)
             pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf);
         }
         vlan->nb_host_devs++;
-        ret = net_slirp_init(vlan);
+        ret = net_slirp_init(vlan, device);
     } else
 #endif
 #ifdef _WIN32
@@ -1445,7 +1453,7 @@ int net_client_init(const char *device, const char *p)
             return -1;
         }
         vlan->nb_host_devs++;
-        ret = tap_win32_init(vlan, ifname);
+        ret = tap_win32_init(vlan, device, ifname);
     } else
 #elif defined (_AIX)
 #else
@@ -1458,7 +1466,7 @@ int net_client_init(const char *device, const char *p)
             fd = strtol(buf, NULL, 0);
             fcntl(fd, F_SETFL, O_NONBLOCK);
             ret = -1;
-            if (net_tap_fd_init(vlan, fd))
+            if (net_tap_fd_init(vlan, device, fd))
                 ret = 0;
         } else {
             if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {
@@ -1470,7 +1478,7 @@ int net_client_init(const char *device, const char *p)
             if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) {
                 pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT);
             }
-            ret = net_tap_init(vlan, ifname, setup_script, down_script);
+            ret = net_tap_init(vlan, device, ifname, setup_script, down_script);
         }
     } else
 #endif
@@ -1479,14 +1487,14 @@ int net_client_init(const char *device, const char *p)
             int fd;
             fd = strtol(buf, NULL, 0);
             ret = -1;
-            if (net_socket_fd_init(vlan, fd, 1))
+            if (net_socket_fd_init(vlan, device, fd, 1))
                 ret = 0;
         } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) {
-            ret = net_socket_listen_init(vlan, buf);
+            ret = net_socket_listen_init(vlan, device, buf);
         } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) {
-            ret = net_socket_connect_init(vlan, buf);
+            ret = net_socket_connect_init(vlan, device, buf);
         } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) {
-            ret = net_socket_mcast_init(vlan, buf);
+            ret = net_socket_mcast_init(vlan, device, buf);
         } else {
             fprintf(stderr, "Unknown socket options: %s\n", p);
             return -1;
@@ -1514,7 +1522,7 @@ int net_client_init(const char *device, const char *p)
 	} else {
 	    vde_mode = 0700;
 	}
-	ret = net_vde_init(vlan, vde_sock, vde_port, vde_group, vde_mode);
+	ret = net_vde_init(vlan, device, vde_sock, vde_port, vde_group, vde_mode);
     } else
 #endif
     {
diff --git a/net.h b/net.h
index a2b01ae..fcae0e2 100644
--- a/net.h
+++ b/net.h
@@ -13,6 +13,7 @@ struct VLANClientState {
     void *opaque;
     struct VLANClientState *next;
     struct VLANState *vlan;
+    char *model;
     char info_str[256];
 };
 
@@ -25,6 +26,7 @@ struct VLANState {
 
 VLANState *qemu_find_vlan(int id);
 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
+                                      const char *model,
                                       IOReadHandler *fd_read,
                                       IOCanRWHandler *fd_can_read,
                                       void *opaque);
diff --git a/sysemu.h b/sysemu.h
index 94cffaf..8ce3900 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -75,7 +75,7 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 #endif
 
 /* TAP win32 */
-int tap_win32_init(VLANState *vlan, const char *ifname);
+int tap_win32_init(VLANState *vlan, const char *model, const char *ifname);
 
 /* SLIRP */
 void do_info_slirp(void);
diff --git a/tap-win32.c b/tap-win32.c
index 299b4b3..ee9e23f 100644
--- a/tap-win32.c
+++ b/tap-win32.c
@@ -660,7 +660,7 @@ static void tap_win32_send(void *opaque)
     }
 }
 
-int tap_win32_init(VLANState *vlan, const char *ifname)
+int tap_win32_init(VLANState *vlan, const char *model, const char *ifname)
 {
     TAPState *s;
 
@@ -672,7 +672,7 @@ int tap_win32_init(VLANState *vlan, const char *ifname)
         return -1;
     }
 
-    s->vc = qemu_new_vlan_client(vlan, tap_receive, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "tap: ifname=%s", ifname);
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 2/5] Assign a name to each VLAN client
  2008-12-12 14:46       ` [Qemu-devel] [PATCH 1/5] Add a model string to VLANClientState Mark McLoughlin
@ 2008-12-12 14:46         ` Mark McLoughlin
  2008-12-12 14:46           ` [Qemu-devel] [PATCH 3/5] Fixup info_str formatting Mark McLoughlin
  0 siblings, 1 reply; 26+ messages in thread
From: Mark McLoughlin @ 2008-12-12 14:46 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, qemu-devel

Automatically assign a name to each vlan client based on its model,
e.g. e1000.0, tap.3 or vde.1.

This name is intended to be used by the forthcoming 'set_link'
monitor command.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |   21 +++++++++++++++++++++
 net.h |    1 +
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/net.c b/net.c
index d046b5e..fe7c648 100644
--- a/net.c
+++ b/net.c
@@ -304,6 +304,25 @@ static int parse_unix_path(struct sockaddr_un *uaddr, const char *str)
 }
 #endif
 
+static char *assign_name(VLANClientState *vc1, const char *model)
+{
+    VLANState *vlan;
+    char buf[256];
+    int id = 0;
+
+    for (vlan = first_vlan; vlan; vlan = vlan->next) {
+        VLANClientState *vc;
+
+        for (vc = vlan->first_client; vc; vc = vc->next)
+            if (vc != vc1 && strcmp(vc->model, model) == 0)
+                id++;
+    }
+
+    snprintf(buf, sizeof(buf), "%s.%d", model, id);
+
+    return strdup(buf);
+}
+
 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
                                       const char *model,
                                       IOReadHandler *fd_read,
@@ -315,6 +334,7 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
     if (!vc)
         return NULL;
     vc->model = strdup(model);
+    vc->name = assign_name(vc, model);
     vc->fd_read = fd_read;
     vc->fd_can_read = fd_can_read;
     vc->opaque = opaque;
@@ -335,6 +355,7 @@ void qemu_del_vlan_client(VLANClientState *vc)
     while (*pvc != NULL)
         if (*pvc == vc) {
             *pvc = vc->next;
+            free(vc->name);
             free(vc->model);
             free(vc);
             break;
diff --git a/net.h b/net.h
index fcae0e2..138cd23 100644
--- a/net.h
+++ b/net.h
@@ -14,6 +14,7 @@ struct VLANClientState {
     struct VLANClientState *next;
     struct VLANState *vlan;
     char *model;
+    char *name;
     char info_str[256];
 };
 
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 3/5] Fixup info_str formatting
  2008-12-12 14:46         ` [Qemu-devel] [PATCH 2/5] Assign a name to each VLAN client Mark McLoughlin
@ 2008-12-12 14:46           ` Mark McLoughlin
  2008-12-12 14:46             ` [Qemu-devel] [PATCH 4/5] Add qemu_format_nic_info_str() Mark McLoughlin
  0 siblings, 1 reply; 26+ messages in thread
From: Mark McLoughlin @ 2008-12-12 14:46 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, qemu-devel

The VLANClientState::info_str format isn't terribly consistent and
this patch moves towards it just containing the param strings
separated by a comma.

The type/model string is removed from info_str, and 'info network'
instead displays the vlan client name with the info_str.

There's a horrible little hack in net_cleanup() to parse a tap
client's info_str which I've also fixed up. The hack probably
shouldn't exist at all, though.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/e1000.c    |    2 +-
 hw/eepro100.c |    2 +-
 hw/mipsnet.c  |    2 +-
 hw/ne2000.c   |    4 ++--
 hw/pcnet.c    |    2 +-
 hw/rtl8139.c  |    2 +-
 hw/usb-net.c  |    2 +-
 net.c         |   14 ++++++++------
 8 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index 45706bb..13fcc1c 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1075,7 +1075,7 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
                                  e1000_receive, e1000_can_receive, d);
 
     snprintf(d->vc->info_str, sizeof(d->vc->info_str),
-             "%s macaddr=%02x:%02x:%02x:%02x:%02x:%02x", info_str,
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
              d->nd->macaddr[0], d->nd->macaddr[1], d->nd->macaddr[2],
              d->nd->macaddr[3], d->nd->macaddr[4], d->nd->macaddr[5]);
 
diff --git a/hw/eepro100.c b/hw/eepro100.c
index a7861ca..8ea283c 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1780,7 +1780,7 @@ static void nic_init(PCIBus * bus, NICInfo * nd,
                                  nic_receive, nic_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "eepro100 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
              s->macaddr[0],
              s->macaddr[1],
              s->macaddr[2], s->macaddr[3], s->macaddr[4], s->macaddr[5]);
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 549e6f3..8190738 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -257,7 +257,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
     }
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "mipsnet macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
               s->nd->macaddr[0],
               s->nd->macaddr[1],
               s->nd->macaddr[2],
diff --git a/hw/ne2000.c b/hw/ne2000.c
index dc97989..600cdc3 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -745,7 +745,7 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
                                  ne2000_receive, ne2000_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "ne2000 macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
              s->macaddr[0],
              s->macaddr[1],
              s->macaddr[2],
@@ -815,7 +815,7 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
                                  ne2000_receive, ne2000_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "ne2000 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
              s->macaddr[0],
              s->macaddr[1],
              s->macaddr[2],
diff --git a/hw/pcnet.c b/hw/pcnet.c
index e961a06..90bf7fd 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1940,7 +1940,7 @@ static void pcnet_common_init(PCNetState *d, NICInfo *nd, const char *info_str)
                                      pcnet_receive, pcnet_can_receive, d);
 
         snprintf(d->vc->info_str, sizeof(d->vc->info_str),
-                 "pcnet macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+                 "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
                  d->nd->macaddr[0],
                  d->nd->macaddr[1],
                  d->nd->macaddr[2],
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index f3f6564..b16c4cc 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3442,7 +3442,7 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
                                  rtl8139_receive, rtl8139_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "rtl8139 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
              s->macaddr[0],
              s->macaddr[1],
              s->macaddr[2],
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 06ff668..c80b048 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1462,7 +1462,7 @@ USBDevice *usb_net_init(NICInfo *nd)
                     0x40, s->mac[1], s->mac[2],
                     s->mac[3], s->mac[4], s->mac[5]);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-                    "usbnet macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+                    "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
                     s->mac[0], s->mac[1], s->mac[2],
                     s->mac[3], s->mac[4], s->mac[5]);
     fprintf(stderr, "usbnet: initialized mac %02x:%02x:%02x:%02x:%02x:%02x\n",
diff --git a/net.c b/net.c
index fe7c648..100e335 100644
--- a/net.c
+++ b/net.c
@@ -438,7 +438,7 @@ static int net_slirp_init(VLANState *vlan, const char *model)
     }
     slirp_vc = qemu_new_vlan_client(vlan, model,
                                     slirp_receive, NULL, NULL);
-    snprintf(slirp_vc->info_str, sizeof(slirp_vc->info_str), "user redirector");
+    slirp_vc->info_str[0] = '\0';
     return 0;
 }
 
@@ -645,7 +645,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
     s->fd = fd;
     s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
     qemu_set_fd_handler(s->fd, tap_send, NULL, s);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "tap: fd=%d", fd);
+    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd);
     return s;
 }
 
@@ -900,7 +900,8 @@ static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
     if (!s)
         return -1;
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "tap: ifname=%s setup_script=%s", ifname, setup_script);
+             "ifname=%s,script=%s,downscript=%s",
+             ifname, setup_script, down_script);
     if (down_script && strcmp(down_script, "no"))
         snprintf(s->down_script, sizeof(s->down_script), "%s", down_script);
     return 0;
@@ -962,7 +963,7 @@ static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
     }
     s->vc = qemu_new_vlan_client(vlan, model, vde_from_qemu, NULL, s);
     qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "vde: sock=%s fd=%d",
+    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
              sock, vde_datafd(s->vde));
     return 0;
 }
@@ -1585,7 +1586,7 @@ void do_info_network(void)
     for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
         term_printf("VLAN %d devices:\n", vlan->id);
         for(vc = vlan->first_client; vc != NULL; vc = vc->next)
-            term_printf("  %s\n", vc->info_str);
+            term_printf("  %s: %s\n", vc->name, vc->info_str);
     }
 }
 
@@ -1603,7 +1604,8 @@ void net_cleanup(void)
                 char ifname[64];
                 TAPState *s = vc->opaque;
 
-                if (sscanf(vc->info_str, "tap: ifname=%63s ", ifname) == 1 &&
+                if (strcmp(vc->model, "tap") == 0 &&
+                    sscanf(vc->info_str, "ifname=%63s ", ifname) == 1 &&
                     s->down_script[0])
                     launch_script(s->down_script, ifname, s->fd);
             }
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 4/5] Add qemu_format_nic_info_str()
  2008-12-12 14:46           ` [Qemu-devel] [PATCH 3/5] Fixup info_str formatting Mark McLoughlin
@ 2008-12-12 14:46             ` Mark McLoughlin
  2008-12-12 14:46               ` [Qemu-devel] [PATCH 5/5] Add a -net name=foo parameter Mark McLoughlin
  0 siblings, 1 reply; 26+ messages in thread
From: Mark McLoughlin @ 2008-12-12 14:46 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, qemu-devel

Factor out a simple little function for formatting a NIC's
info_str and make all NICs use it.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/e1000.c    |    5 +----
 hw/eepro100.c |    6 +-----
 hw/mipsnet.c  |    9 +--------
 hw/ne2000.c   |   18 ++----------------
 hw/pcnet.c    |    9 +--------
 hw/rtl8139.c  |    9 +--------
 hw/usb-net.c  |    6 ++----
 net.c         |    8 ++++++++
 net.h         |    1 +
 9 files changed, 18 insertions(+), 53 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index 13fcc1c..9b4dbbd 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1074,10 +1074,7 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
     d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  e1000_receive, e1000_can_receive, d);
 
-    snprintf(d->vc->info_str, sizeof(d->vc->info_str),
-             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             d->nd->macaddr[0], d->nd->macaddr[1], d->nd->macaddr[2],
-             d->nd->macaddr[3], d->nd->macaddr[4], d->nd->macaddr[5]);
+    qemu_format_nic_info_str(d->vc, d->nd->macaddr);
 
     register_savevm(info_str, -1, 2, nic_save, nic_load, d);
 }
diff --git a/hw/eepro100.c b/hw/eepro100.c
index 8ea283c..86a4e6e 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1779,11 +1779,7 @@ static void nic_init(PCIBus * bus, NICInfo * nd,
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  nic_receive, nic_can_receive, s);
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             s->macaddr[0],
-             s->macaddr[1],
-             s->macaddr[2], s->macaddr[3], s->macaddr[4], s->macaddr[5]);
+    qemu_format_nic_info_str(s->vc, s->macaddr);
 
     qemu_register_reset(nic_reset, s);
 
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 8190738..4b3e8e9 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -256,14 +256,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
         s->vc = NULL;
     }
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-              s->nd->macaddr[0],
-              s->nd->macaddr[1],
-              s->nd->macaddr[2],
-              s->nd->macaddr[3],
-              s->nd->macaddr[4],
-              s->nd->macaddr[5]);
+    qemu_format_nic_info_str(s->vc, s->nd->macaddr);
 
     mipsnet_reset(s);
     register_savevm("mipsnet", 0, 0, mipsnet_save, mipsnet_load, s);
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 600cdc3..ad97bc5 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -744,14 +744,7 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  ne2000_receive, ne2000_can_receive, s);
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             s->macaddr[0],
-             s->macaddr[1],
-             s->macaddr[2],
-             s->macaddr[3],
-             s->macaddr[4],
-             s->macaddr[5]);
+    qemu_format_nic_info_str(s->vc, s->macaddr);
 
     register_savevm("ne2000", -1, 2, ne2000_save, ne2000_load, s);
 }
@@ -814,14 +807,7 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  ne2000_receive, ne2000_can_receive, s);
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             s->macaddr[0],
-             s->macaddr[1],
-             s->macaddr[2],
-             s->macaddr[3],
-             s->macaddr[4],
-             s->macaddr[5]);
+    qemu_format_nic_info_str(s->vc, s->macaddr);
 
     register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s);
 }
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 90bf7fd..5b45956 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1939,14 +1939,7 @@ static void pcnet_common_init(PCNetState *d, NICInfo *nd, const char *info_str)
         d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                      pcnet_receive, pcnet_can_receive, d);
 
-        snprintf(d->vc->info_str, sizeof(d->vc->info_str),
-                 "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-                 d->nd->macaddr[0],
-                 d->nd->macaddr[1],
-                 d->nd->macaddr[2],
-                 d->nd->macaddr[3],
-                 d->nd->macaddr[4],
-                 d->nd->macaddr[5]);
+        qemu_format_nic_info_str(d->vc, d->nd->macaddr);
     } else {
         d->vc = NULL;
     }
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index b16c4cc..4449fd2 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3441,14 +3441,7 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  rtl8139_receive, rtl8139_can_receive, s);
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             s->macaddr[0],
-             s->macaddr[1],
-             s->macaddr[2],
-             s->macaddr[3],
-             s->macaddr[4],
-             s->macaddr[5]);
+    qemu_format_nic_info_str(s->vc, s->macaddr);
 
     s->cplus_txbuffer = NULL;
     s->cplus_txbuffer_len = 0;
diff --git a/hw/usb-net.c b/hw/usb-net.c
index c80b048..95ebac8 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1457,14 +1457,12 @@ USBDevice *usb_net_init(NICInfo *nd)
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                     usbnet_receive, usbnet_can_receive, s);
 
+    qemu_format_nic_info_str(s->vc, s->mac);
+
     snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
                     "%02x%02x%02x%02x%02x%02x",
                     0x40, s->mac[1], s->mac[2],
                     s->mac[3], s->mac[4], s->mac[5]);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-                    "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-                    s->mac[0], s->mac[1], s->mac[2],
-                    s->mac[3], s->mac[4], s->mac[5]);
     fprintf(stderr, "usbnet: initialized mac %02x:%02x:%02x:%02x:%02x:%02x\n",
                     s->mac[0], s->mac[1], s->mac[2],
                     s->mac[3], s->mac[4], s->mac[5]);
diff --git a/net.c b/net.c
index 100e335..69f6546 100644
--- a/net.c
+++ b/net.c
@@ -304,6 +304,14 @@ static int parse_unix_path(struct sockaddr_un *uaddr, const char *str)
 }
 #endif
 
+void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6])
+{
+    snprintf(vc->info_str, sizeof(vc->info_str),
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             macaddr[0], macaddr[1], macaddr[2],
+             macaddr[3], macaddr[4], macaddr[5]);
+}
+
 static char *assign_name(VLANClientState *vc1, const char *model)
 {
     VLANState *vlan;
diff --git a/net.h b/net.h
index 138cd23..244f80b 100644
--- a/net.h
+++ b/net.h
@@ -34,6 +34,7 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
 void qemu_del_vlan_client(VLANClientState *vc);
 int qemu_can_send_packet(VLANClientState *vc);
 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
+void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
 void qemu_handler_true(void *opaque);
 
 void do_info_network(void);
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 5/5] Add a -net name=foo parameter
  2008-12-12 14:46             ` [Qemu-devel] [PATCH 4/5] Add qemu_format_nic_info_str() Mark McLoughlin
@ 2008-12-12 14:46               ` Mark McLoughlin
  2008-12-14 23:48                 ` Aurelien Jarno
  0 siblings, 1 reply; 26+ messages in thread
From: Mark McLoughlin @ 2008-12-12 14:46 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, qemu-devel

Allow the user to supply a vlan client name on the command line.

This is probably only useful for management tools so that they can
use their own names rather than parsing the output of 'info network'.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/e1000.c       |    2 +-
 hw/eepro100.c    |    2 +-
 hw/etraxfs_eth.c |    2 +-
 hw/mcf_fec.c     |    2 +-
 hw/mipsnet.c     |    2 +-
 hw/musicpal.c    |    2 +-
 hw/ne2000.c      |    4 +-
 hw/pcnet.c       |    2 +-
 hw/rtl8139.c     |    2 +-
 hw/smc91c111.c   |    2 +-
 hw/usb-net.c     |    2 +-
 net.c            |   97 +++++++++++++++++++++++++++++++++++------------------
 net.h            |    2 +
 qemu-doc.texi    |   15 ++++----
 sysemu.h         |    3 +-
 tap-win32.c      |    5 ++-
 vl.c             |   14 ++++----
 17 files changed, 98 insertions(+), 62 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index 9b4dbbd..7c8824d 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1071,7 +1071,7 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
     d->rxbuf_min_shift = 1;
     memset(&d->tx, 0, sizeof d->tx);
 
-    d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    d->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  e1000_receive, e1000_can_receive, d);
 
     qemu_format_nic_info_str(d->vc, d->nd->macaddr);
diff --git a/hw/eepro100.c b/hw/eepro100.c
index 86a4e6e..5eca105 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1776,7 +1776,7 @@ static void nic_init(PCIBus * bus, NICInfo * nd,
 
     nic_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  nic_receive, nic_can_receive, s);
 
     qemu_format_nic_info_str(s->vc, s->macaddr);
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index 244a23d..4bad3d2 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -596,7 +596,7 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
 	eth->ethregs = cpu_register_io_memory(0, eth_read, eth_write, eth);
 	cpu_register_physical_memory (base, 0x5c, eth->ethregs);
 
-	eth->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+	eth->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
 				       eth_receive, eth_can_receive, eth);
 
 	return dma;
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 7e3afa5..bb9f68f 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -452,7 +452,7 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
                                        mcf_fec_writefn, s);
     cpu_register_physical_memory(base, 0x400, iomemtype);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  mcf_fec_receive, mcf_fec_can_receive, s);
     memcpy(s->macaddr, nd->macaddr, 6);
 }
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 4b3e8e9..0eb4c1e 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -250,7 +250,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
     s->irq = irq;
     s->nd = nd;
     if (nd && nd->vlan) {
-        s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+        s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                      mipsnet_receive, mipsnet_can_receive, s);
     } else {
         s->vc = NULL;
diff --git a/hw/musicpal.c b/hw/musicpal.c
index d172a11..1c932ec 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -718,7 +718,7 @@ static void mv88w8618_eth_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     if (!s)
         return;
     s->irq = irq;
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  eth_receive, eth_can_receive, s);
     iomemtype = cpu_register_io_memory(0, mv88w8618_eth_readfn,
                                        mv88w8618_eth_writefn, s);
diff --git a/hw/ne2000.c b/hw/ne2000.c
index ad97bc5..200db90 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -741,7 +741,7 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
 
     ne2000_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  ne2000_receive, ne2000_can_receive, s);
 
     qemu_format_nic_info_str(s->vc, s->macaddr);
@@ -804,7 +804,7 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
     s->pci_dev = (PCIDevice *)d;
     memcpy(s->macaddr, nd->macaddr, 6);
     ne2000_reset(s);
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  ne2000_receive, ne2000_can_receive, s);
 
     qemu_format_nic_info_str(s->vc, s->macaddr);
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 5b45956..102166e 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1936,7 +1936,7 @@ static void pcnet_common_init(PCNetState *d, NICInfo *nd, const char *info_str)
     d->nd = nd;
 
     if (nd && nd->vlan) {
-        d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+        d->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                      pcnet_receive, pcnet_can_receive, d);
 
         qemu_format_nic_info_str(d->vc, d->nd->macaddr);
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 4449fd2..5805795 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3438,7 +3438,7 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
     s->pci_dev = (PCIDevice *)d;
     memcpy(s->macaddr, nd->macaddr, 6);
     rtl8139_reset(s);
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  rtl8139_receive, rtl8139_can_receive, s);
 
     qemu_format_nic_info_str(s->vc, s->macaddr);
diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index fadd151..2ee6701 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -704,7 +704,7 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
 
     smc91c111_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  smc91c111_receive, smc91c111_can_receive, s);
     /* ??? Save/restore.  */
 }
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 95ebac8..947461c 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1454,7 +1454,7 @@ USBDevice *usb_net_init(NICInfo *nd)
 
     pstrcpy(s->dev.devname, sizeof(s->dev.devname),
                     "QEMU USB Network Interface");
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                     usbnet_receive, usbnet_can_receive, s);
 
     qemu_format_nic_info_str(s->vc, s->mac);
diff --git a/net.c b/net.c
index 69f6546..414affb 100644
--- a/net.c
+++ b/net.c
@@ -333,6 +333,7 @@ static char *assign_name(VLANClientState *vc1, const char *model)
 
 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
                                       const char *model,
+                                      const char *name,
                                       IOReadHandler *fd_read,
                                       IOCanRWHandler *fd_can_read,
                                       void *opaque)
@@ -342,7 +343,10 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
     if (!vc)
         return NULL;
     vc->model = strdup(model);
-    vc->name = assign_name(vc, model);
+    if (name)
+        vc->name = strdup(name);
+    else
+        vc->name = assign_name(vc, model);
     vc->fd_read = fd_read;
     vc->fd_can_read = fd_can_read;
     vc->opaque = opaque;
@@ -438,13 +442,13 @@ static void slirp_receive(void *opaque, const uint8_t *buf, int size)
     slirp_input(buf, size);
 }
 
-static int net_slirp_init(VLANState *vlan, const char *model)
+static int net_slirp_init(VLANState *vlan, const char *model, const char *name)
 {
     if (!slirp_inited) {
         slirp_inited = 1;
         slirp_init();
     }
-    slirp_vc = qemu_new_vlan_client(vlan, model,
+    slirp_vc = qemu_new_vlan_client(vlan, model, name,
                                     slirp_receive, NULL, NULL);
     slirp_vc->info_str[0] = '\0';
     return 0;
@@ -643,7 +647,10 @@ static void tap_send(void *opaque)
 
 /* fd support */
 
-static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
+static TAPState *net_tap_fd_init(VLANState *vlan,
+                                 const char *model,
+                                 const char *name,
+                                 int fd)
 {
     TAPState *s;
 
@@ -651,7 +658,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
     if (!s)
         return NULL;
     s->fd = fd;
-    s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s);
     qemu_set_fd_handler(s->fd, tap_send, NULL, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd);
     return s;
@@ -883,7 +890,8 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)
     return 0;
 }
 
-static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
+static int net_tap_init(VLANState *vlan, const char *model,
+                        const char *name, const char *ifname1,
                         const char *setup_script, const char *down_script)
 {
     TAPState *s;
@@ -904,7 +912,7 @@ static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
 	if (launch_script(setup_script, ifname, fd))
 	    return -1;
     }
-    s = net_tap_fd_init(vlan, model, fd);
+    s = net_tap_fd_init(vlan, model, name, fd);
     if (!s)
         return -1;
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
@@ -948,7 +956,8 @@ static void vde_from_qemu(void *opaque, const uint8_t *buf, int size)
     }
 }
 
-static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
+static int net_vde_init(VLANState *vlan, const char *model,
+                        const char *name, const char *sock,
                         int port, const char *group, int mode)
 {
     VDEState *s;
@@ -969,7 +978,7 @@ static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
         free(s);
         return -1;
     }
-    s->vc = qemu_new_vlan_client(vlan, model, vde_from_qemu, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, name, vde_from_qemu, NULL, s);
     qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
              sock, vde_datafd(s->vde));
@@ -991,6 +1000,7 @@ typedef struct NetSocketState {
 typedef struct NetSocketListenState {
     VLANState *vlan;
     char *model;
+    char *name;
     int fd;
 } NetSocketListenState;
 
@@ -1144,7 +1154,9 @@ fail:
     return -1;
 }
 
-static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *model,
+static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
+                                                const char *model,
+                                                const char *name,
                                                 int fd, int is_connected)
 {
     struct sockaddr_in saddr;
@@ -1188,7 +1200,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *mod
         return NULL;
     s->fd = fd;
 
-    s->vc = qemu_new_vlan_client(vlan, model, net_socket_receive_dgram, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, name, net_socket_receive_dgram, NULL, s);
     qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
 
     /* mcast: save bound address as dst */
@@ -1207,7 +1219,9 @@ static void net_socket_connect(void *opaque)
     qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
 }
 
-static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *model,
+static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
+                                                 const char *model,
+                                                 const char *name,
                                                  int fd, int is_connected)
 {
     NetSocketState *s;
@@ -1215,7 +1229,7 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *mo
     if (!s)
         return NULL;
     s->fd = fd;
-    s->vc = qemu_new_vlan_client(vlan, model,
+    s->vc = qemu_new_vlan_client(vlan, model, name,
                                  net_socket_receive, NULL, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "socket: fd=%d", fd);
@@ -1227,7 +1241,8 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *mo
     return s;
 }
 
-static NetSocketState *net_socket_fd_init(VLANState *vlan, const char *model,
+static NetSocketState *net_socket_fd_init(VLANState *vlan,
+                                          const char *model, const char *name,
                                           int fd, int is_connected)
 {
     int so_type=-1, optlen=sizeof(so_type);
@@ -1239,13 +1254,13 @@ static NetSocketState *net_socket_fd_init(VLANState *vlan, const char *model,
     }
     switch(so_type) {
     case SOCK_DGRAM:
-        return net_socket_fd_init_dgram(vlan, model, fd, is_connected);
+        return net_socket_fd_init_dgram(vlan, model, name, fd, is_connected);
     case SOCK_STREAM:
-        return net_socket_fd_init_stream(vlan, model, fd, is_connected);
+        return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
     default:
         /* who knows ... this could be a eg. a pty, do warn and continue as stream */
         fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
-        return net_socket_fd_init_stream(vlan, model, fd, is_connected);
+        return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
     }
     return NULL;
 }
@@ -1267,7 +1282,7 @@ static void net_socket_accept(void *opaque)
             break;
         }
     }
-    s1 = net_socket_fd_init(s->vlan, s->model, fd, 1);
+    s1 = net_socket_fd_init(s->vlan, s->model, s->name, fd, 1);
     if (!s1) {
         closesocket(fd);
     } else {
@@ -1277,7 +1292,9 @@ static void net_socket_accept(void *opaque)
     }
 }
 
-static int net_socket_listen_init(VLANState *vlan, const char *model,
+static int net_socket_listen_init(VLANState *vlan,
+                                  const char *model,
+                                  const char *name,
                                   const char *host_str)
 {
     NetSocketListenState *s;
@@ -1314,12 +1331,15 @@ static int net_socket_listen_init(VLANState *vlan, const char *model,
     }
     s->vlan = vlan;
     s->model = strdup(model);
+    s->name = strdup(name);
     s->fd = fd;
     qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
     return 0;
 }
 
-static int net_socket_connect_init(VLANState *vlan, const char *model,
+static int net_socket_connect_init(VLANState *vlan,
+                                   const char *model,
+                                   const char *name,
                                    const char *host_str)
 {
     NetSocketState *s;
@@ -1358,7 +1378,7 @@ static int net_socket_connect_init(VLANState *vlan, const char *model,
             break;
         }
     }
-    s = net_socket_fd_init(vlan, model, fd, connected);
+    s = net_socket_fd_init(vlan, model, name, fd, connected);
     if (!s)
         return -1;
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
@@ -1367,7 +1387,9 @@ static int net_socket_connect_init(VLANState *vlan, const char *model,
     return 0;
 }
 
-static int net_socket_mcast_init(VLANState *vlan, const char *model,
+static int net_socket_mcast_init(VLANState *vlan,
+                                 const char *model,
+                                 const char *name,
                                  const char *host_str)
 {
     NetSocketState *s;
@@ -1382,7 +1404,7 @@ static int net_socket_mcast_init(VLANState *vlan, const char *model,
     if (fd < 0)
 	return -1;
 
-    s = net_socket_fd_init(vlan, model, fd, 0);
+    s = net_socket_fd_init(vlan, model, name, fd, 0);
     if (!s)
         return -1;
 
@@ -1420,6 +1442,7 @@ int net_client_init(const char *device, const char *p)
     char buf[1024];
     int vlan_id, ret;
     VLANState *vlan;
+    char *name = NULL;
 
     vlan_id = 0;
     if (get_param_value(buf, sizeof(buf), "vlan", p)) {
@@ -1430,6 +1453,9 @@ int net_client_init(const char *device, const char *p)
         fprintf(stderr, "Could not create vlan %d\n", vlan_id);
         return -1;
     }
+    if (get_param_value(buf, sizeof(buf), "name", p)) {
+        name = strdup(buf);
+    }
     if (!strcmp(device, "nic")) {
         NICInfo *nd;
         uint8_t *macaddr;
@@ -1457,6 +1483,8 @@ int net_client_init(const char *device, const char *p)
             nd->model = strdup(buf);
         }
         nd->vlan = vlan;
+        nd->name = name;
+        name = NULL;
         nb_nics++;
         vlan->nb_guest_devs++;
         ret = 0;
@@ -1472,7 +1500,7 @@ int net_client_init(const char *device, const char *p)
             pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf);
         }
         vlan->nb_host_devs++;
-        ret = net_slirp_init(vlan, device);
+        ret = net_slirp_init(vlan, device, name);
     } else
 #endif
 #ifdef _WIN32
@@ -1483,7 +1511,7 @@ int net_client_init(const char *device, const char *p)
             return -1;
         }
         vlan->nb_host_devs++;
-        ret = tap_win32_init(vlan, device, ifname);
+        ret = tap_win32_init(vlan, device, name, ifname);
     } else
 #elif defined (_AIX)
 #else
@@ -1496,7 +1524,7 @@ int net_client_init(const char *device, const char *p)
             fd = strtol(buf, NULL, 0);
             fcntl(fd, F_SETFL, O_NONBLOCK);
             ret = -1;
-            if (net_tap_fd_init(vlan, device, fd))
+            if (net_tap_fd_init(vlan, device, name, fd))
                 ret = 0;
         } else {
             if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {
@@ -1508,7 +1536,7 @@ int net_client_init(const char *device, const char *p)
             if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) {
                 pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT);
             }
-            ret = net_tap_init(vlan, device, ifname, setup_script, down_script);
+            ret = net_tap_init(vlan, device, name, ifname, setup_script, down_script);
         }
     } else
 #endif
@@ -1517,14 +1545,14 @@ int net_client_init(const char *device, const char *p)
             int fd;
             fd = strtol(buf, NULL, 0);
             ret = -1;
-            if (net_socket_fd_init(vlan, device, fd, 1))
+            if (net_socket_fd_init(vlan, device, name, fd, 1))
                 ret = 0;
         } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) {
-            ret = net_socket_listen_init(vlan, device, buf);
+            ret = net_socket_listen_init(vlan, device, name, buf);
         } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) {
-            ret = net_socket_connect_init(vlan, device, buf);
+            ret = net_socket_connect_init(vlan, device, name, buf);
         } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) {
-            ret = net_socket_mcast_init(vlan, device, buf);
+            ret = net_socket_mcast_init(vlan, device, name, buf);
         } else {
             fprintf(stderr, "Unknown socket options: %s\n", p);
             return -1;
@@ -1552,17 +1580,20 @@ int net_client_init(const char *device, const char *p)
 	} else {
 	    vde_mode = 0700;
 	}
-	ret = net_vde_init(vlan, device, vde_sock, vde_port, vde_group, vde_mode);
+	ret = net_vde_init(vlan, device, name, vde_sock, vde_port, vde_group, vde_mode);
     } else
 #endif
     {
         fprintf(stderr, "Unknown network device: %s\n", device);
+        if (name)
+            free(name);
         return -1;
     }
     if (ret < 0) {
         fprintf(stderr, "Could not initialize device '%s'\n", device);
     }
-
+    if (name)
+        free(name);
     return ret;
 }
 
diff --git a/net.h b/net.h
index 244f80b..bb4dce3 100644
--- a/net.h
+++ b/net.h
@@ -28,6 +28,7 @@ struct VLANState {
 VLANState *qemu_find_vlan(int id);
 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
                                       const char *model,
+                                      const char *name,
                                       IOReadHandler *fd_read,
                                       IOCanRWHandler *fd_can_read,
                                       void *opaque);
@@ -46,6 +47,7 @@ void do_info_network(void);
 struct NICInfo {
     uint8_t macaddr[6];
     const char *model;
+    const char *name;
     VLANState *vlan;
 };
 
diff --git a/qemu-doc.texi b/qemu-doc.texi
index 377e384..bb36fe7 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -604,10 +604,11 @@ Network options:
 
 @table @option
 
-@item -net nic[,vlan=@var{n}][,macaddr=@var{addr}][,model=@var{type}]
+@item -net nic[,vlan=@var{n}][,macaddr=@var{addr}][,model=@var{type}][,name=@var{name}]
 Create a new Network Interface Card and connect it to VLAN @var{n} (@var{n}
 = 0 is the default). The NIC is an ne2k_pci by default on the PC
-target. Optionally, the MAC address can be changed. If no
+target. Optionally, the MAC address can be changed to @var{addr}
+and a @var{name} can be assigned for use in monitor commands. If no
 @option{-net} option is specified, a single NIC is created.
 Qemu can emulate several different models of network card.
 Valid values for @var{type} are
@@ -617,12 +618,12 @@ Valid values for @var{type} are
 Not all devices are supported on all targets.  Use -net nic,model=?
 for a list of available devices for your target.
 
-@item -net user[,vlan=@var{n}][,hostname=@var{name}]
+@item -net user[,vlan=@var{n}][,hostname=@var{name}][,name=@var{name}]
 Use the user mode network stack which requires no administrator
 privilege to run.  @option{hostname=name} can be used to specify the client
 hostname reported by the builtin DHCP server.
 
-@item -net tap[,vlan=@var{n}][,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}]
+@item -net tap[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}]
 Connect the host TAP network interface @var{name} to VLAN @var{n}, use
 the network script @var{file} to configure it and the network script 
 @var{dfile} to deconfigure it. If @var{name} is not provided, the OS 
@@ -643,7 +644,7 @@ qemu linux.img -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 \
 @end example
 
 
-@item -net socket[,vlan=@var{n}][,fd=@var{h}][,listen=[@var{host}]:@var{port}][,connect=@var{host}:@var{port}]
+@item -net socket[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,listen=[@var{host}]:@var{port}][,connect=@var{host}:@var{port}]
 
 Connect the VLAN @var{n} to a remote VLAN in another QEMU virtual
 machine using a TCP socket connection. If @option{listen} is
@@ -663,7 +664,7 @@ qemu linux.img -net nic,macaddr=52:54:00:12:34:57 \
                -net socket,connect=127.0.0.1:1234
 @end example
 
-@item -net socket[,vlan=@var{n}][,fd=@var{h}][,mcast=@var{maddr}:@var{port}]
+@item -net socket[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,mcast=@var{maddr}:@var{port}]
 
 Create a VLAN @var{n} shared with another QEMU virtual
 machines using a UDP multicast socket, effectively making a bus for
@@ -703,7 +704,7 @@ qemu linux.img -net nic,macaddr=52:54:00:12:34:56 \
 /path/to/linux ubd0=/path/to/root_fs eth0=mcast
 @end example
 
-@item -net vde[,vlan=@var{n}][,sock=@var{socketpath}][,port=@var{n}][,group=@var{groupname}][,mode=@var{octalmode}]
+@item -net vde[,vlan=@var{n}][,name=@var{name}][,sock=@var{socketpath}][,port=@var{n}][,group=@var{groupname}][,mode=@var{octalmode}]
 Connect VLAN @var{n} to PORT @var{n} of a vde switch running on host and
 listening for incoming connections on @var{socketpath}. Use GROUP @var{groupname}
 and MODE @var{octalmode} to change default ownership and permissions for
diff --git a/sysemu.h b/sysemu.h
index 8ce3900..cac9a95 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -75,7 +75,8 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 #endif
 
 /* TAP win32 */
-int tap_win32_init(VLANState *vlan, const char *model, const char *ifname);
+int tap_win32_init(VLANState *vlan, const char *model,
+                   const char *name, const char *ifname);
 
 /* SLIRP */
 void do_info_slirp(void);
diff --git a/tap-win32.c b/tap-win32.c
index ee9e23f..da3283e 100644
--- a/tap-win32.c
+++ b/tap-win32.c
@@ -660,7 +660,8 @@ static void tap_win32_send(void *opaque)
     }
 }
 
-int tap_win32_init(VLANState *vlan, const char *model, const char *ifname)
+int tap_win32_init(VLANState *vlan, const char *model,
+                   const char *name, const char *ifname)
 {
     TAPState *s;
 
@@ -672,7 +673,7 @@ int tap_win32_init(VLANState *vlan, const char *model, const char *ifname)
         return -1;
     }
 
-    s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "tap: ifname=%s", ifname);
diff --git a/vl.c b/vl.c
index c3a8d8f..bf7d78c 100644
--- a/vl.c
+++ b/vl.c
@@ -3878,30 +3878,30 @@ static void help(int exitcode)
            "-uuid %%08x-%%04x-%%04x-%%04x-%%012x specify machine UUID\n"
            "\n"
            "Network options:\n"
-           "-net nic[,vlan=n][,macaddr=addr][,model=type]\n"
+           "-net nic[,vlan=n][,macaddr=addr][,model=type][,name=str]\n"
            "                create a new Network Interface Card and connect it to VLAN 'n'\n"
 #ifdef CONFIG_SLIRP
-           "-net user[,vlan=n][,hostname=host]\n"
+           "-net user[,vlan=n][,name=str][,hostname=host]\n"
            "                connect the user mode network stack to VLAN 'n' and send\n"
            "                hostname 'host' to DHCP clients\n"
 #endif
 #ifdef _WIN32
-           "-net tap[,vlan=n],ifname=name\n"
+           "-net tap[,vlan=n][,name=str],ifname=name\n"
            "                connect the host TAP network interface to VLAN 'n'\n"
 #else
-           "-net tap[,vlan=n][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n"
+           "-net tap[,vlan=n][,name=str][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n"
            "                connect the host TAP network interface to VLAN 'n' and use the\n"
            "                network scripts 'file' (default=%s)\n"
            "                and 'dfile' (default=%s);\n"
            "                use '[down]script=no' to disable script execution;\n"
            "                use 'fd=h' to connect to an already opened TAP interface\n"
 #endif
-           "-net socket[,vlan=n][,fd=h][,listen=[host]:port][,connect=host:port]\n"
+           "-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]\n"
            "                connect the vlan 'n' to another VLAN using a socket connection\n"
-           "-net socket[,vlan=n][,fd=h][,mcast=maddr:port]\n"
+           "-net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port]\n"
            "                connect the vlan 'n' to multicast maddr and port\n"
 #ifdef CONFIG_VDE
-           "-net vde[,vlan=n][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n"
+           "-net vde[,vlan=n][,name=str][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n"
            "                connect the vlan 'n' to port 'n' of a vde switch running\n"
            "                on host and listening for incoming connections on 'socketpath'.\n"
            "                Use group 'groupname' and mode 'octalmode' to change default\n"
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [Qemu-devel] [PATCH 5/5] Add a -net name=foo parameter
  2008-12-12 14:46               ` [Qemu-devel] [PATCH 5/5] Add a -net name=foo parameter Mark McLoughlin
@ 2008-12-14 23:48                 ` Aurelien Jarno
  0 siblings, 0 replies; 26+ messages in thread
From: Aurelien Jarno @ 2008-12-14 23:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

On Fri, Dec 12, 2008 at 02:46:31PM +0000, Mark McLoughlin wrote:
> Allow the user to supply a vlan client name on the command line.
> 
> This is probably only useful for management tools so that they can
> use their own names rather than parsing the output of 'info network'.
> 
> Signed-off-by: Mark McLoughlin <markmc@redhat.com>
> ---
>  hw/e1000.c       |    2 +-
>  hw/eepro100.c    |    2 +-
>  hw/etraxfs_eth.c |    2 +-
>  hw/mcf_fec.c     |    2 +-
>  hw/mipsnet.c     |    2 +-
>  hw/musicpal.c    |    2 +-
>  hw/ne2000.c      |    4 +-
>  hw/pcnet.c       |    2 +-
>  hw/rtl8139.c     |    2 +-
>  hw/smc91c111.c   |    2 +-
>  hw/usb-net.c     |    2 +-

Looks like you have forget to convert at least hw/stellaris_enet.c, so
the code doesn't compile. Otherwise the series looks good.

>  net.c            |   97 +++++++++++++++++++++++++++++++++++------------------
>  net.h            |    2 +
>  qemu-doc.texi    |   15 ++++----
>  sysemu.h         |    3 +-
>  tap-win32.c      |    5 ++-
>  vl.c             |   14 ++++----
>  17 files changed, 98 insertions(+), 62 deletions(-)
> 
> diff --git a/hw/e1000.c b/hw/e1000.c
> index 9b4dbbd..7c8824d 100644
> --- a/hw/e1000.c
> +++ b/hw/e1000.c
> @@ -1071,7 +1071,7 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
>      d->rxbuf_min_shift = 1;
>      memset(&d->tx, 0, sizeof d->tx);
>  
> -    d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
> +    d->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
>                                   e1000_receive, e1000_can_receive, d);
>  
>      qemu_format_nic_info_str(d->vc, d->nd->macaddr);
> diff --git a/hw/eepro100.c b/hw/eepro100.c
> index 86a4e6e..5eca105 100644
> --- a/hw/eepro100.c
> +++ b/hw/eepro100.c
> @@ -1776,7 +1776,7 @@ static void nic_init(PCIBus * bus, NICInfo * nd,
>  
>      nic_reset(s);
>  
> -    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
> +    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
>                                   nic_receive, nic_can_receive, s);
>  
>      qemu_format_nic_info_str(s->vc, s->macaddr);
> diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
> index 244a23d..4bad3d2 100644
> --- a/hw/etraxfs_eth.c
> +++ b/hw/etraxfs_eth.c
> @@ -596,7 +596,7 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
>  	eth->ethregs = cpu_register_io_memory(0, eth_read, eth_write, eth);
>  	cpu_register_physical_memory (base, 0x5c, eth->ethregs);
>  
> -	eth->vc = qemu_new_vlan_client(nd->vlan, nd->model,
> +	eth->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
>  				       eth_receive, eth_can_receive, eth);
>  
>  	return dma;
> diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
> index 7e3afa5..bb9f68f 100644
> --- a/hw/mcf_fec.c
> +++ b/hw/mcf_fec.c
> @@ -452,7 +452,7 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
>                                         mcf_fec_writefn, s);
>      cpu_register_physical_memory(base, 0x400, iomemtype);
>  
> -    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
> +    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
>                                   mcf_fec_receive, mcf_fec_can_receive, s);
>      memcpy(s->macaddr, nd->macaddr, 6);
>  }
> diff --git a/hw/mipsnet.c b/hw/mipsnet.c
> index 4b3e8e9..0eb4c1e 100644
> --- a/hw/mipsnet.c
> +++ b/hw/mipsnet.c
> @@ -250,7 +250,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
>      s->irq = irq;
>      s->nd = nd;
>      if (nd && nd->vlan) {
> -        s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
> +        s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
>                                       mipsnet_receive, mipsnet_can_receive, s);
>      } else {
>          s->vc = NULL;
> diff --git a/hw/musicpal.c b/hw/musicpal.c
> index d172a11..1c932ec 100644
> --- a/hw/musicpal.c
> +++ b/hw/musicpal.c
> @@ -718,7 +718,7 @@ static void mv88w8618_eth_init(NICInfo *nd, uint32_t base, qemu_irq irq)
>      if (!s)
>          return;
>      s->irq = irq;
> -    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
> +    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
>                                   eth_receive, eth_can_receive, s);
>      iomemtype = cpu_register_io_memory(0, mv88w8618_eth_readfn,
>                                         mv88w8618_eth_writefn, s);
> diff --git a/hw/ne2000.c b/hw/ne2000.c
> index ad97bc5..200db90 100644
> --- a/hw/ne2000.c
> +++ b/hw/ne2000.c
> @@ -741,7 +741,7 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
>  
>      ne2000_reset(s);
>  
> -    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
> +    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
>                                   ne2000_receive, ne2000_can_receive, s);
>  
>      qemu_format_nic_info_str(s->vc, s->macaddr);
> @@ -804,7 +804,7 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
>      s->pci_dev = (PCIDevice *)d;
>      memcpy(s->macaddr, nd->macaddr, 6);
>      ne2000_reset(s);
> -    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
> +    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
>                                   ne2000_receive, ne2000_can_receive, s);
>  
>      qemu_format_nic_info_str(s->vc, s->macaddr);
> diff --git a/hw/pcnet.c b/hw/pcnet.c
> index 5b45956..102166e 100644
> --- a/hw/pcnet.c
> +++ b/hw/pcnet.c
> @@ -1936,7 +1936,7 @@ static void pcnet_common_init(PCNetState *d, NICInfo *nd, const char *info_str)
>      d->nd = nd;
>  
>      if (nd && nd->vlan) {
> -        d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
> +        d->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
>                                       pcnet_receive, pcnet_can_receive, d);
>  
>          qemu_format_nic_info_str(d->vc, d->nd->macaddr);
> diff --git a/hw/rtl8139.c b/hw/rtl8139.c
> index 4449fd2..5805795 100644
> --- a/hw/rtl8139.c
> +++ b/hw/rtl8139.c
> @@ -3438,7 +3438,7 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
>      s->pci_dev = (PCIDevice *)d;
>      memcpy(s->macaddr, nd->macaddr, 6);
>      rtl8139_reset(s);
> -    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
> +    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
>                                   rtl8139_receive, rtl8139_can_receive, s);
>  
>      qemu_format_nic_info_str(s->vc, s->macaddr);
> diff --git a/hw/smc91c111.c b/hw/smc91c111.c
> index fadd151..2ee6701 100644
> --- a/hw/smc91c111.c
> +++ b/hw/smc91c111.c
> @@ -704,7 +704,7 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
>  
>      smc91c111_reset(s);
>  
> -    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
> +    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
>                                   smc91c111_receive, smc91c111_can_receive, s);
>      /* ??? Save/restore.  */
>  }
> diff --git a/hw/usb-net.c b/hw/usb-net.c
> index 95ebac8..947461c 100644
> --- a/hw/usb-net.c
> +++ b/hw/usb-net.c
> @@ -1454,7 +1454,7 @@ USBDevice *usb_net_init(NICInfo *nd)
>  
>      pstrcpy(s->dev.devname, sizeof(s->dev.devname),
>                      "QEMU USB Network Interface");
> -    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
> +    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
>                      usbnet_receive, usbnet_can_receive, s);
>  
>      qemu_format_nic_info_str(s->vc, s->mac);
> diff --git a/net.c b/net.c
> index 69f6546..414affb 100644
> --- a/net.c
> +++ b/net.c
> @@ -333,6 +333,7 @@ static char *assign_name(VLANClientState *vc1, const char *model)
>  
>  VLANClientState *qemu_new_vlan_client(VLANState *vlan,
>                                        const char *model,
> +                                      const char *name,
>                                        IOReadHandler *fd_read,
>                                        IOCanRWHandler *fd_can_read,
>                                        void *opaque)
> @@ -342,7 +343,10 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
>      if (!vc)
>          return NULL;
>      vc->model = strdup(model);
> -    vc->name = assign_name(vc, model);
> +    if (name)
> +        vc->name = strdup(name);
> +    else
> +        vc->name = assign_name(vc, model);
>      vc->fd_read = fd_read;
>      vc->fd_can_read = fd_can_read;
>      vc->opaque = opaque;
> @@ -438,13 +442,13 @@ static void slirp_receive(void *opaque, const uint8_t *buf, int size)
>      slirp_input(buf, size);
>  }
>  
> -static int net_slirp_init(VLANState *vlan, const char *model)
> +static int net_slirp_init(VLANState *vlan, const char *model, const char *name)
>  {
>      if (!slirp_inited) {
>          slirp_inited = 1;
>          slirp_init();
>      }
> -    slirp_vc = qemu_new_vlan_client(vlan, model,
> +    slirp_vc = qemu_new_vlan_client(vlan, model, name,
>                                      slirp_receive, NULL, NULL);
>      slirp_vc->info_str[0] = '\0';
>      return 0;
> @@ -643,7 +647,10 @@ static void tap_send(void *opaque)
>  
>  /* fd support */
>  
> -static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
> +static TAPState *net_tap_fd_init(VLANState *vlan,
> +                                 const char *model,
> +                                 const char *name,
> +                                 int fd)
>  {
>      TAPState *s;
>  
> @@ -651,7 +658,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
>      if (!s)
>          return NULL;
>      s->fd = fd;
> -    s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
> +    s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s);
>      qemu_set_fd_handler(s->fd, tap_send, NULL, s);
>      snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd);
>      return s;
> @@ -883,7 +890,8 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)
>      return 0;
>  }
>  
> -static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
> +static int net_tap_init(VLANState *vlan, const char *model,
> +                        const char *name, const char *ifname1,
>                          const char *setup_script, const char *down_script)
>  {
>      TAPState *s;
> @@ -904,7 +912,7 @@ static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
>  	if (launch_script(setup_script, ifname, fd))
>  	    return -1;
>      }
> -    s = net_tap_fd_init(vlan, model, fd);
> +    s = net_tap_fd_init(vlan, model, name, fd);
>      if (!s)
>          return -1;
>      snprintf(s->vc->info_str, sizeof(s->vc->info_str),
> @@ -948,7 +956,8 @@ static void vde_from_qemu(void *opaque, const uint8_t *buf, int size)
>      }
>  }
>  
> -static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
> +static int net_vde_init(VLANState *vlan, const char *model,
> +                        const char *name, const char *sock,
>                          int port, const char *group, int mode)
>  {
>      VDEState *s;
> @@ -969,7 +978,7 @@ static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
>          free(s);
>          return -1;
>      }
> -    s->vc = qemu_new_vlan_client(vlan, model, vde_from_qemu, NULL, s);
> +    s->vc = qemu_new_vlan_client(vlan, model, name, vde_from_qemu, NULL, s);
>      qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
>      snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
>               sock, vde_datafd(s->vde));
> @@ -991,6 +1000,7 @@ typedef struct NetSocketState {
>  typedef struct NetSocketListenState {
>      VLANState *vlan;
>      char *model;
> +    char *name;
>      int fd;
>  } NetSocketListenState;
>  
> @@ -1144,7 +1154,9 @@ fail:
>      return -1;
>  }
>  
> -static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *model,
> +static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
> +                                                const char *model,
> +                                                const char *name,
>                                                  int fd, int is_connected)
>  {
>      struct sockaddr_in saddr;
> @@ -1188,7 +1200,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *mod
>          return NULL;
>      s->fd = fd;
>  
> -    s->vc = qemu_new_vlan_client(vlan, model, net_socket_receive_dgram, NULL, s);
> +    s->vc = qemu_new_vlan_client(vlan, model, name, net_socket_receive_dgram, NULL, s);
>      qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
>  
>      /* mcast: save bound address as dst */
> @@ -1207,7 +1219,9 @@ static void net_socket_connect(void *opaque)
>      qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
>  }
>  
> -static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *model,
> +static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
> +                                                 const char *model,
> +                                                 const char *name,
>                                                   int fd, int is_connected)
>  {
>      NetSocketState *s;
> @@ -1215,7 +1229,7 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *mo
>      if (!s)
>          return NULL;
>      s->fd = fd;
> -    s->vc = qemu_new_vlan_client(vlan, model,
> +    s->vc = qemu_new_vlan_client(vlan, model, name,
>                                   net_socket_receive, NULL, s);
>      snprintf(s->vc->info_str, sizeof(s->vc->info_str),
>               "socket: fd=%d", fd);
> @@ -1227,7 +1241,8 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *mo
>      return s;
>  }
>  
> -static NetSocketState *net_socket_fd_init(VLANState *vlan, const char *model,
> +static NetSocketState *net_socket_fd_init(VLANState *vlan,
> +                                          const char *model, const char *name,
>                                            int fd, int is_connected)
>  {
>      int so_type=-1, optlen=sizeof(so_type);
> @@ -1239,13 +1254,13 @@ static NetSocketState *net_socket_fd_init(VLANState *vlan, const char *model,
>      }
>      switch(so_type) {
>      case SOCK_DGRAM:
> -        return net_socket_fd_init_dgram(vlan, model, fd, is_connected);
> +        return net_socket_fd_init_dgram(vlan, model, name, fd, is_connected);
>      case SOCK_STREAM:
> -        return net_socket_fd_init_stream(vlan, model, fd, is_connected);
> +        return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
>      default:
>          /* who knows ... this could be a eg. a pty, do warn and continue as stream */
>          fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
> -        return net_socket_fd_init_stream(vlan, model, fd, is_connected);
> +        return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
>      }
>      return NULL;
>  }
> @@ -1267,7 +1282,7 @@ static void net_socket_accept(void *opaque)
>              break;
>          }
>      }
> -    s1 = net_socket_fd_init(s->vlan, s->model, fd, 1);
> +    s1 = net_socket_fd_init(s->vlan, s->model, s->name, fd, 1);
>      if (!s1) {
>          closesocket(fd);
>      } else {
> @@ -1277,7 +1292,9 @@ static void net_socket_accept(void *opaque)
>      }
>  }
>  
> -static int net_socket_listen_init(VLANState *vlan, const char *model,
> +static int net_socket_listen_init(VLANState *vlan,
> +                                  const char *model,
> +                                  const char *name,
>                                    const char *host_str)
>  {
>      NetSocketListenState *s;
> @@ -1314,12 +1331,15 @@ static int net_socket_listen_init(VLANState *vlan, const char *model,
>      }
>      s->vlan = vlan;
>      s->model = strdup(model);
> +    s->name = strdup(name);
>      s->fd = fd;
>      qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
>      return 0;
>  }
>  
> -static int net_socket_connect_init(VLANState *vlan, const char *model,
> +static int net_socket_connect_init(VLANState *vlan,
> +                                   const char *model,
> +                                   const char *name,
>                                     const char *host_str)
>  {
>      NetSocketState *s;
> @@ -1358,7 +1378,7 @@ static int net_socket_connect_init(VLANState *vlan, const char *model,
>              break;
>          }
>      }
> -    s = net_socket_fd_init(vlan, model, fd, connected);
> +    s = net_socket_fd_init(vlan, model, name, fd, connected);
>      if (!s)
>          return -1;
>      snprintf(s->vc->info_str, sizeof(s->vc->info_str),
> @@ -1367,7 +1387,9 @@ static int net_socket_connect_init(VLANState *vlan, const char *model,
>      return 0;
>  }
>  
> -static int net_socket_mcast_init(VLANState *vlan, const char *model,
> +static int net_socket_mcast_init(VLANState *vlan,
> +                                 const char *model,
> +                                 const char *name,
>                                   const char *host_str)
>  {
>      NetSocketState *s;
> @@ -1382,7 +1404,7 @@ static int net_socket_mcast_init(VLANState *vlan, const char *model,
>      if (fd < 0)
>  	return -1;
>  
> -    s = net_socket_fd_init(vlan, model, fd, 0);
> +    s = net_socket_fd_init(vlan, model, name, fd, 0);
>      if (!s)
>          return -1;
>  
> @@ -1420,6 +1442,7 @@ int net_client_init(const char *device, const char *p)
>      char buf[1024];
>      int vlan_id, ret;
>      VLANState *vlan;
> +    char *name = NULL;
>  
>      vlan_id = 0;
>      if (get_param_value(buf, sizeof(buf), "vlan", p)) {
> @@ -1430,6 +1453,9 @@ int net_client_init(const char *device, const char *p)
>          fprintf(stderr, "Could not create vlan %d\n", vlan_id);
>          return -1;
>      }
> +    if (get_param_value(buf, sizeof(buf), "name", p)) {
> +        name = strdup(buf);
> +    }
>      if (!strcmp(device, "nic")) {
>          NICInfo *nd;
>          uint8_t *macaddr;
> @@ -1457,6 +1483,8 @@ int net_client_init(const char *device, const char *p)
>              nd->model = strdup(buf);
>          }
>          nd->vlan = vlan;
> +        nd->name = name;
> +        name = NULL;
>          nb_nics++;
>          vlan->nb_guest_devs++;
>          ret = 0;
> @@ -1472,7 +1500,7 @@ int net_client_init(const char *device, const char *p)
>              pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf);
>          }
>          vlan->nb_host_devs++;
> -        ret = net_slirp_init(vlan, device);
> +        ret = net_slirp_init(vlan, device, name);
>      } else
>  #endif
>  #ifdef _WIN32
> @@ -1483,7 +1511,7 @@ int net_client_init(const char *device, const char *p)
>              return -1;
>          }
>          vlan->nb_host_devs++;
> -        ret = tap_win32_init(vlan, device, ifname);
> +        ret = tap_win32_init(vlan, device, name, ifname);
>      } else
>  #elif defined (_AIX)
>  #else
> @@ -1496,7 +1524,7 @@ int net_client_init(const char *device, const char *p)
>              fd = strtol(buf, NULL, 0);
>              fcntl(fd, F_SETFL, O_NONBLOCK);
>              ret = -1;
> -            if (net_tap_fd_init(vlan, device, fd))
> +            if (net_tap_fd_init(vlan, device, name, fd))
>                  ret = 0;
>          } else {
>              if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {
> @@ -1508,7 +1536,7 @@ int net_client_init(const char *device, const char *p)
>              if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) {
>                  pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT);
>              }
> -            ret = net_tap_init(vlan, device, ifname, setup_script, down_script);
> +            ret = net_tap_init(vlan, device, name, ifname, setup_script, down_script);
>          }
>      } else
>  #endif
> @@ -1517,14 +1545,14 @@ int net_client_init(const char *device, const char *p)
>              int fd;
>              fd = strtol(buf, NULL, 0);
>              ret = -1;
> -            if (net_socket_fd_init(vlan, device, fd, 1))
> +            if (net_socket_fd_init(vlan, device, name, fd, 1))
>                  ret = 0;
>          } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) {
> -            ret = net_socket_listen_init(vlan, device, buf);
> +            ret = net_socket_listen_init(vlan, device, name, buf);
>          } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) {
> -            ret = net_socket_connect_init(vlan, device, buf);
> +            ret = net_socket_connect_init(vlan, device, name, buf);
>          } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) {
> -            ret = net_socket_mcast_init(vlan, device, buf);
> +            ret = net_socket_mcast_init(vlan, device, name, buf);
>          } else {
>              fprintf(stderr, "Unknown socket options: %s\n", p);
>              return -1;
> @@ -1552,17 +1580,20 @@ int net_client_init(const char *device, const char *p)
>  	} else {
>  	    vde_mode = 0700;
>  	}
> -	ret = net_vde_init(vlan, device, vde_sock, vde_port, vde_group, vde_mode);
> +	ret = net_vde_init(vlan, device, name, vde_sock, vde_port, vde_group, vde_mode);
>      } else
>  #endif
>      {
>          fprintf(stderr, "Unknown network device: %s\n", device);
> +        if (name)
> +            free(name);
>          return -1;
>      }
>      if (ret < 0) {
>          fprintf(stderr, "Could not initialize device '%s'\n", device);
>      }
> -
> +    if (name)
> +        free(name);
>      return ret;
>  }
>  
> diff --git a/net.h b/net.h
> index 244f80b..bb4dce3 100644
> --- a/net.h
> +++ b/net.h
> @@ -28,6 +28,7 @@ struct VLANState {
>  VLANState *qemu_find_vlan(int id);
>  VLANClientState *qemu_new_vlan_client(VLANState *vlan,
>                                        const char *model,
> +                                      const char *name,
>                                        IOReadHandler *fd_read,
>                                        IOCanRWHandler *fd_can_read,
>                                        void *opaque);
> @@ -46,6 +47,7 @@ void do_info_network(void);
>  struct NICInfo {
>      uint8_t macaddr[6];
>      const char *model;
> +    const char *name;
>      VLANState *vlan;
>  };
>  
> diff --git a/qemu-doc.texi b/qemu-doc.texi
> index 377e384..bb36fe7 100644
> --- a/qemu-doc.texi
> +++ b/qemu-doc.texi
> @@ -604,10 +604,11 @@ Network options:
>  
>  @table @option
>  
> -@item -net nic[,vlan=@var{n}][,macaddr=@var{addr}][,model=@var{type}]
> +@item -net nic[,vlan=@var{n}][,macaddr=@var{addr}][,model=@var{type}][,name=@var{name}]
>  Create a new Network Interface Card and connect it to VLAN @var{n} (@var{n}
>  = 0 is the default). The NIC is an ne2k_pci by default on the PC
> -target. Optionally, the MAC address can be changed. If no
> +target. Optionally, the MAC address can be changed to @var{addr}
> +and a @var{name} can be assigned for use in monitor commands. If no
>  @option{-net} option is specified, a single NIC is created.
>  Qemu can emulate several different models of network card.
>  Valid values for @var{type} are
> @@ -617,12 +618,12 @@ Valid values for @var{type} are
>  Not all devices are supported on all targets.  Use -net nic,model=?
>  for a list of available devices for your target.
>  
> -@item -net user[,vlan=@var{n}][,hostname=@var{name}]
> +@item -net user[,vlan=@var{n}][,hostname=@var{name}][,name=@var{name}]
>  Use the user mode network stack which requires no administrator
>  privilege to run.  @option{hostname=name} can be used to specify the client
>  hostname reported by the builtin DHCP server.
>  
> -@item -net tap[,vlan=@var{n}][,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}]
> +@item -net tap[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}]
>  Connect the host TAP network interface @var{name} to VLAN @var{n}, use
>  the network script @var{file} to configure it and the network script 
>  @var{dfile} to deconfigure it. If @var{name} is not provided, the OS 
> @@ -643,7 +644,7 @@ qemu linux.img -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 \
>  @end example
>  
>  
> -@item -net socket[,vlan=@var{n}][,fd=@var{h}][,listen=[@var{host}]:@var{port}][,connect=@var{host}:@var{port}]
> +@item -net socket[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,listen=[@var{host}]:@var{port}][,connect=@var{host}:@var{port}]
>  
>  Connect the VLAN @var{n} to a remote VLAN in another QEMU virtual
>  machine using a TCP socket connection. If @option{listen} is
> @@ -663,7 +664,7 @@ qemu linux.img -net nic,macaddr=52:54:00:12:34:57 \
>                 -net socket,connect=127.0.0.1:1234
>  @end example
>  
> -@item -net socket[,vlan=@var{n}][,fd=@var{h}][,mcast=@var{maddr}:@var{port}]
> +@item -net socket[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,mcast=@var{maddr}:@var{port}]
>  
>  Create a VLAN @var{n} shared with another QEMU virtual
>  machines using a UDP multicast socket, effectively making a bus for
> @@ -703,7 +704,7 @@ qemu linux.img -net nic,macaddr=52:54:00:12:34:56 \
>  /path/to/linux ubd0=/path/to/root_fs eth0=mcast
>  @end example
>  
> -@item -net vde[,vlan=@var{n}][,sock=@var{socketpath}][,port=@var{n}][,group=@var{groupname}][,mode=@var{octalmode}]
> +@item -net vde[,vlan=@var{n}][,name=@var{name}][,sock=@var{socketpath}][,port=@var{n}][,group=@var{groupname}][,mode=@var{octalmode}]
>  Connect VLAN @var{n} to PORT @var{n} of a vde switch running on host and
>  listening for incoming connections on @var{socketpath}. Use GROUP @var{groupname}
>  and MODE @var{octalmode} to change default ownership and permissions for
> diff --git a/sysemu.h b/sysemu.h
> index 8ce3900..cac9a95 100644
> --- a/sysemu.h
> +++ b/sysemu.h
> @@ -75,7 +75,8 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
>  #endif
>  
>  /* TAP win32 */
> -int tap_win32_init(VLANState *vlan, const char *model, const char *ifname);
> +int tap_win32_init(VLANState *vlan, const char *model,
> +                   const char *name, const char *ifname);
>  
>  /* SLIRP */
>  void do_info_slirp(void);
> diff --git a/tap-win32.c b/tap-win32.c
> index ee9e23f..da3283e 100644
> --- a/tap-win32.c
> +++ b/tap-win32.c
> @@ -660,7 +660,8 @@ static void tap_win32_send(void *opaque)
>      }
>  }
>  
> -int tap_win32_init(VLANState *vlan, const char *model, const char *ifname)
> +int tap_win32_init(VLANState *vlan, const char *model,
> +                   const char *name, const char *ifname)
>  {
>      TAPState *s;
>  
> @@ -672,7 +673,7 @@ int tap_win32_init(VLANState *vlan, const char *model, const char *ifname)
>          return -1;
>      }
>  
> -    s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
> +    s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s);
>  
>      snprintf(s->vc->info_str, sizeof(s->vc->info_str),
>               "tap: ifname=%s", ifname);
> diff --git a/vl.c b/vl.c
> index c3a8d8f..bf7d78c 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -3878,30 +3878,30 @@ static void help(int exitcode)
>             "-uuid %%08x-%%04x-%%04x-%%04x-%%012x specify machine UUID\n"
>             "\n"
>             "Network options:\n"
> -           "-net nic[,vlan=n][,macaddr=addr][,model=type]\n"
> +           "-net nic[,vlan=n][,macaddr=addr][,model=type][,name=str]\n"
>             "                create a new Network Interface Card and connect it to VLAN 'n'\n"
>  #ifdef CONFIG_SLIRP
> -           "-net user[,vlan=n][,hostname=host]\n"
> +           "-net user[,vlan=n][,name=str][,hostname=host]\n"
>             "                connect the user mode network stack to VLAN 'n' and send\n"
>             "                hostname 'host' to DHCP clients\n"
>  #endif
>  #ifdef _WIN32
> -           "-net tap[,vlan=n],ifname=name\n"
> +           "-net tap[,vlan=n][,name=str],ifname=name\n"
>             "                connect the host TAP network interface to VLAN 'n'\n"
>  #else
> -           "-net tap[,vlan=n][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n"
> +           "-net tap[,vlan=n][,name=str][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n"
>             "                connect the host TAP network interface to VLAN 'n' and use the\n"
>             "                network scripts 'file' (default=%s)\n"
>             "                and 'dfile' (default=%s);\n"
>             "                use '[down]script=no' to disable script execution;\n"
>             "                use 'fd=h' to connect to an already opened TAP interface\n"
>  #endif
> -           "-net socket[,vlan=n][,fd=h][,listen=[host]:port][,connect=host:port]\n"
> +           "-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]\n"
>             "                connect the vlan 'n' to another VLAN using a socket connection\n"
> -           "-net socket[,vlan=n][,fd=h][,mcast=maddr:port]\n"
> +           "-net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port]\n"
>             "                connect the vlan 'n' to multicast maddr and port\n"
>  #ifdef CONFIG_VDE
> -           "-net vde[,vlan=n][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n"
> +           "-net vde[,vlan=n][,name=str][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n"
>             "                connect the vlan 'n' to port 'n' of a vde switch running\n"
>             "                on host and listening for incoming connections on 'socketpath'.\n"
>             "                Use group 'groupname' and mode 'octalmode' to change default\n"
> -- 
> 1.5.4.3
> 
> 
> 
> 

-- 
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   aurel32@debian.org         | aurelien@aurel32.net
   `-    people.debian.org/~aurel32 | www.aurel32.net

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command
  2008-12-12 14:45     ` Mark McLoughlin
  2008-12-12 14:46       ` [Qemu-devel] [PATCH 1/5] Add a model string to VLANClientState Mark McLoughlin
@ 2009-01-06 14:59       ` Mark McLoughlin
  2009-01-06 15:00         ` [Qemu-devel] [PATCH 1/6] Add a model string to VLANClientState Mark McLoughlin
  1 sibling, 1 reply; 26+ messages in thread
From: Mark McLoughlin @ 2009-01-06 14:59 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel

Hi Anthony,

On Fri, 2008-12-12 at 14:45 +0000, Mark McLoughlin wrote:
> On Tue, 2008-12-09 at 09:01 -0600, Anthony Liguori wrote:
> > > +    for(vc = vlan->first_client; vc != NULL; vc = vc->next)
> > > +        if (i++ == device_idx)
> > > +            break;
> > >   
> > 
> > I think a better way would be to allow a user to specify an id for the 
> > nic that gets saved early on.  info nics should print the id and a 
> > default id should be assigned.  I think you could argue either way as to 
> > whether the ids should be vlan local or global.
> > 
> > I sort of think that making them global has a number of advantages.  You 
> > could also use a string to identify the nics globally, it's up to you.
> 
> Okay, here's a few patches to add a vlan client name.
> 
> I'll repost the set_link patches once we agree on this part.

Re-posting a re-based version of these patches; also includes a fix for
the build error pointer out by Aurelien Jarno.

Cheers,
Mark.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 1/6] Add a model string to VLANClientState
  2009-01-06 14:59       ` [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command Mark McLoughlin
@ 2009-01-06 15:00         ` Mark McLoughlin
  2009-01-06 15:00           ` [Qemu-devel] [PATCH 2/6] Assign a name to each VLAN client Mark McLoughlin
  2009-01-07 17:49           ` [Qemu-devel] Re: [PATCH 1/6] Add a model string to VLANClientState Anthony Liguori
  0 siblings, 2 replies; 26+ messages in thread
From: Mark McLoughlin @ 2009-01-06 15:00 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, qemu-devel

Don't lose track of what type/model a vlan client is so that we can
e.g. assign a global per-model id to clients.

The entire patch is basically a tedious excercise in making sure the
type/model string gets propagated down to qemu_new_vlan_client().

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/e1000.c          |    4 +-
 hw/eepro100.c       |    3 +-
 hw/etraxfs_eth.c    |    2 +-
 hw/mcf_fec.c        |    4 +-
 hw/mipsnet.c        |    4 +-
 hw/musicpal.c       |    3 +-
 hw/ne2000.c         |    8 ++--
 hw/pcnet.c          |    4 +-
 hw/rtl8139.c        |    4 +-
 hw/smc91c111.c      |    4 +-
 hw/stellaris_enet.c |    4 +-
 hw/usb-net.c        |    2 +-
 hw/virtio-net.c     |    4 +-
 net.c               |   78 ++++++++++++++++++++++++++++-----------------------
 net.h               |    2 +
 sysemu.h            |    2 +-
 tap-win32.c         |    4 +-
 17 files changed, 74 insertions(+), 62 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index 7ca0747..03c573b 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1071,8 +1071,8 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
     d->rxbuf_min_shift = 1;
     memset(&d->tx, 0, sizeof d->tx);
 
-    d->vc = qemu_new_vlan_client(nd->vlan, e1000_receive,
-                                 e1000_can_receive, d);
+    d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 e1000_receive, e1000_can_receive, d);
 
     snprintf(d->vc->info_str, sizeof(d->vc->info_str),
              "%s macaddr=%02x:%02x:%02x:%02x:%02x:%02x", info_str,
diff --git a/hw/eepro100.c b/hw/eepro100.c
index cb3ca09..a7861ca 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1776,7 +1776,8 @@ static void nic_init(PCIBus * bus, NICInfo * nd,
 
     nic_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, nic_receive, nic_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 nic_receive, nic_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "eepro100 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index 51a129a..244a23d 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -596,7 +596,7 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
 	eth->ethregs = cpu_register_io_memory(0, eth_read, eth_write, eth);
 	cpu_register_physical_memory (base, 0x5c, eth->ethregs);
 
-	eth->vc = qemu_new_vlan_client(nd->vlan, 
+	eth->vc = qemu_new_vlan_client(nd->vlan, nd->model,
 				       eth_receive, eth_can_receive, eth);
 
 	return dma;
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 0049860..7e3afa5 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -452,7 +452,7 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
                                        mcf_fec_writefn, s);
     cpu_register_physical_memory(base, 0x400, iomemtype);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, mcf_fec_receive,
-                                 mcf_fec_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 mcf_fec_receive, mcf_fec_can_receive, s);
     memcpy(s->macaddr, nd->macaddr, 6);
 }
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index af560f8..549e6f3 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -250,8 +250,8 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
     s->irq = irq;
     s->nd = nd;
     if (nd && nd->vlan) {
-        s->vc = qemu_new_vlan_client(nd->vlan, mipsnet_receive,
-                                     mipsnet_can_receive, s);
+        s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                     mipsnet_receive, mipsnet_can_receive, s);
     } else {
         s->vc = NULL;
     }
diff --git a/hw/musicpal.c b/hw/musicpal.c
index c5a5b6f..d172a11 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -718,7 +718,8 @@ static void mv88w8618_eth_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     if (!s)
         return;
     s->irq = irq;
-    s->vc = qemu_new_vlan_client(nd->vlan, eth_receive, eth_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 eth_receive, eth_can_receive, s);
     iomemtype = cpu_register_io_memory(0, mv88w8618_eth_readfn,
                                        mv88w8618_eth_writefn, s);
     cpu_register_physical_memory(base, MP_ETH_SIZE, iomemtype);
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 3f0ccf5..dc97989 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -741,8 +741,8 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
 
     ne2000_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, ne2000_receive,
-                                 ne2000_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 ne2000_receive, ne2000_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "ne2000 macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
@@ -811,8 +811,8 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
     s->pci_dev = (PCIDevice *)d;
     memcpy(s->macaddr, nd->macaddr, 6);
     ne2000_reset(s);
-    s->vc = qemu_new_vlan_client(nd->vlan, ne2000_receive,
-                                 ne2000_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 ne2000_receive, ne2000_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "ne2000 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 30c453c..e961a06 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1936,8 +1936,8 @@ static void pcnet_common_init(PCNetState *d, NICInfo *nd, const char *info_str)
     d->nd = nd;
 
     if (nd && nd->vlan) {
-        d->vc = qemu_new_vlan_client(nd->vlan, pcnet_receive,
-                                     pcnet_can_receive, d);
+        d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                     pcnet_receive, pcnet_can_receive, d);
 
         snprintf(d->vc->info_str, sizeof(d->vc->info_str),
                  "pcnet macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index c3ab854..39f3209 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3438,8 +3438,8 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
     s->pci_dev = (PCIDevice *)d;
     memcpy(s->macaddr, nd->macaddr, 6);
     rtl8139_reset(s);
-    s->vc = qemu_new_vlan_client(nd->vlan, rtl8139_receive,
-                                 rtl8139_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 rtl8139_receive, rtl8139_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "rtl8139 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index a517033..fadd151 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -704,7 +704,7 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
 
     smc91c111_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, smc91c111_receive,
-                                 smc91c111_can_receive, s);
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 smc91c111_receive, smc91c111_can_receive, s);
     /* ??? Save/restore.  */
 }
diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c
index 09d92b1..bd8dcd9 100644
--- a/hw/stellaris_enet.c
+++ b/hw/stellaris_enet.c
@@ -397,8 +397,8 @@ void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     memcpy(s->macaddr, nd->macaddr, 6);
 
     if (nd->vlan)
-        s->vc = qemu_new_vlan_client(nd->vlan, stellaris_enet_receive,
-                                     stellaris_enet_can_receive, s);
+        s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                     stellaris_enet_receive, stellaris_enet_can_receive, s);
 
     stellaris_enet_reset(s);
     register_savevm("stellaris_enet", -1, 1,
diff --git a/hw/usb-net.c b/hw/usb-net.c
index f16a0a5..40ee41b 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1453,7 +1453,7 @@ USBDevice *usb_net_init(NICInfo *nd)
 
     pstrcpy(s->dev.devname, sizeof(s->dev.devname),
                     "QEMU USB Network Interface");
-    s->vc = qemu_new_vlan_client(nd->vlan,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                     usbnet_receive, usbnet_can_receive, s);
 
     snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 1f45b2d..4500fab 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -315,8 +315,8 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
     n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx);
     n->tx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_tx);
     memcpy(n->mac, nd->macaddr, 6);
-    n->vc = qemu_new_vlan_client(nd->vlan, virtio_net_receive,
-                                 virtio_net_can_receive, n);
+    n->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+                                 virtio_net_receive, virtio_net_can_receive, n);
 
     n->tx_timer = qemu_new_timer(vm_clock, virtio_net_tx_timer, n);
     n->tx_timer_active = 0;
diff --git a/net.c b/net.c
index c49abef..f3c2b89 100644
--- a/net.c
+++ b/net.c
@@ -297,6 +297,7 @@ static int parse_unix_path(struct sockaddr_un *uaddr, const char *str)
 #endif
 
 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
+                                      const char *model,
                                       IOReadHandler *fd_read,
                                       IOCanRWHandler *fd_can_read,
                                       void *opaque)
@@ -305,6 +306,7 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
     vc = qemu_mallocz(sizeof(VLANClientState));
     if (!vc)
         return NULL;
+    vc->model = strdup(model);
     vc->fd_read = fd_read;
     vc->fd_can_read = fd_can_read;
     vc->opaque = opaque;
@@ -325,6 +327,7 @@ void qemu_del_vlan_client(VLANClientState *vc)
     while (*pvc != NULL)
         if (*pvc == vc) {
             *pvc = vc->next;
+            free(vc->model);
             free(vc);
             break;
         } else
@@ -442,13 +445,13 @@ static void slirp_receive(void *opaque, const uint8_t *buf, int size)
     slirp_input(buf, size);
 }
 
-static int net_slirp_init(VLANState *vlan)
+static int net_slirp_init(VLANState *vlan, const char *model)
 {
     if (!slirp_inited) {
         slirp_inited = 1;
         slirp_init();
     }
-    slirp_vc = qemu_new_vlan_client(vlan,
+    slirp_vc = qemu_new_vlan_client(vlan, model,
                                     slirp_receive, NULL, NULL);
     snprintf(slirp_vc->info_str, sizeof(slirp_vc->info_str), "user redirector");
     return 0;
@@ -662,7 +665,7 @@ static void tap_send(void *opaque)
 
 /* fd support */
 
-static TAPState *net_tap_fd_init(VLANState *vlan, int fd)
+static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
 {
     TAPState *s;
 
@@ -670,7 +673,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, int fd)
     if (!s)
         return NULL;
     s->fd = fd;
-    s->vc = qemu_new_vlan_client(vlan, tap_receive, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
 #ifdef HAVE_IOVEC
     s->vc->fd_readv = tap_receive_iov;
 #endif
@@ -905,7 +908,7 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)
     return 0;
 }
 
-static int net_tap_init(VLANState *vlan, const char *ifname1,
+static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
                         const char *setup_script, const char *down_script)
 {
     TAPState *s;
@@ -926,7 +929,7 @@ static int net_tap_init(VLANState *vlan, const char *ifname1,
 	if (launch_script(setup_script, ifname, fd))
 	    return -1;
     }
-    s = net_tap_fd_init(vlan, fd);
+    s = net_tap_fd_init(vlan, model, fd);
     if (!s)
         return -1;
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
@@ -969,8 +972,8 @@ static void vde_from_qemu(void *opaque, const uint8_t *buf, int size)
     }
 }
 
-static int net_vde_init(VLANState *vlan, const char *sock, int port,
-                        const char *group, int mode)
+static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
+                        int port, const char *group, int mode)
 {
     VDEState *s;
     char *init_group = strlen(group) ? (char *)group : NULL;
@@ -990,7 +993,7 @@ static int net_vde_init(VLANState *vlan, const char *sock, int port,
         free(s);
         return -1;
     }
-    s->vc = qemu_new_vlan_client(vlan, vde_from_qemu, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, vde_from_qemu, NULL, s);
     qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str), "vde: sock=%s fd=%d",
              sock, vde_datafd(s->vde));
@@ -1011,6 +1014,7 @@ typedef struct NetSocketState {
 
 typedef struct NetSocketListenState {
     VLANState *vlan;
+    char *model;
     int fd;
 } NetSocketListenState;
 
@@ -1164,8 +1168,8 @@ fail:
     return -1;
 }
 
-static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, int fd,
-                                          int is_connected)
+static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *model,
+                                                int fd, int is_connected)
 {
     struct sockaddr_in saddr;
     int newfd;
@@ -1208,7 +1212,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, int fd,
         return NULL;
     s->fd = fd;
 
-    s->vc = qemu_new_vlan_client(vlan, net_socket_receive_dgram, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, net_socket_receive_dgram, NULL, s);
     qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
 
     /* mcast: save bound address as dst */
@@ -1227,15 +1231,15 @@ static void net_socket_connect(void *opaque)
     qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
 }
 
-static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, int fd,
-                                          int is_connected)
+static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *model,
+                                                 int fd, int is_connected)
 {
     NetSocketState *s;
     s = qemu_mallocz(sizeof(NetSocketState));
     if (!s)
         return NULL;
     s->fd = fd;
-    s->vc = qemu_new_vlan_client(vlan,
+    s->vc = qemu_new_vlan_client(vlan, model,
                                  net_socket_receive, NULL, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "socket: fd=%d", fd);
@@ -1247,8 +1251,8 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, int fd,
     return s;
 }
 
-static NetSocketState *net_socket_fd_init(VLANState *vlan, int fd,
-                                          int is_connected)
+static NetSocketState *net_socket_fd_init(VLANState *vlan, const char *model,
+                                          int fd, int is_connected)
 {
     int so_type=-1, optlen=sizeof(so_type);
 
@@ -1259,13 +1263,13 @@ static NetSocketState *net_socket_fd_init(VLANState *vlan, int fd,
     }
     switch(so_type) {
     case SOCK_DGRAM:
-        return net_socket_fd_init_dgram(vlan, fd, is_connected);
+        return net_socket_fd_init_dgram(vlan, model, fd, is_connected);
     case SOCK_STREAM:
-        return net_socket_fd_init_stream(vlan, fd, is_connected);
+        return net_socket_fd_init_stream(vlan, model, fd, is_connected);
     default:
         /* who knows ... this could be a eg. a pty, do warn and continue as stream */
         fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
-        return net_socket_fd_init_stream(vlan, fd, is_connected);
+        return net_socket_fd_init_stream(vlan, model, fd, is_connected);
     }
     return NULL;
 }
@@ -1287,7 +1291,7 @@ static void net_socket_accept(void *opaque)
             break;
         }
     }
-    s1 = net_socket_fd_init(s->vlan, fd, 1);
+    s1 = net_socket_fd_init(s->vlan, s->model, fd, 1);
     if (!s1) {
         closesocket(fd);
     } else {
@@ -1297,7 +1301,8 @@ static void net_socket_accept(void *opaque)
     }
 }
 
-static int net_socket_listen_init(VLANState *vlan, const char *host_str)
+static int net_socket_listen_init(VLANState *vlan, const char *model,
+                                  const char *host_str)
 {
     NetSocketListenState *s;
     int fd, val, ret;
@@ -1332,12 +1337,14 @@ static int net_socket_listen_init(VLANState *vlan, const char *host_str)
         return -1;
     }
     s->vlan = vlan;
+    s->model = strdup(model);
     s->fd = fd;
     qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
     return 0;
 }
 
-static int net_socket_connect_init(VLANState *vlan, const char *host_str)
+static int net_socket_connect_init(VLANState *vlan, const char *model,
+                                   const char *host_str)
 {
     NetSocketState *s;
     int fd, connected, ret, err;
@@ -1375,7 +1382,7 @@ static int net_socket_connect_init(VLANState *vlan, const char *host_str)
             break;
         }
     }
-    s = net_socket_fd_init(vlan, fd, connected);
+    s = net_socket_fd_init(vlan, model, fd, connected);
     if (!s)
         return -1;
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
@@ -1384,7 +1391,8 @@ static int net_socket_connect_init(VLANState *vlan, const char *host_str)
     return 0;
 }
 
-static int net_socket_mcast_init(VLANState *vlan, const char *host_str)
+static int net_socket_mcast_init(VLANState *vlan, const char *model,
+                                 const char *host_str)
 {
     NetSocketState *s;
     int fd;
@@ -1398,7 +1406,7 @@ static int net_socket_mcast_init(VLANState *vlan, const char *host_str)
     if (fd < 0)
 	return -1;
 
-    s = net_socket_fd_init(vlan, fd, 0);
+    s = net_socket_fd_init(vlan, model, fd, 0);
     if (!s)
         return -1;
 
@@ -1488,7 +1496,7 @@ int net_client_init(const char *device, const char *p)
             pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf);
         }
         vlan->nb_host_devs++;
-        ret = net_slirp_init(vlan);
+        ret = net_slirp_init(vlan, device);
     } else
 #endif
 #ifdef _WIN32
@@ -1499,7 +1507,7 @@ int net_client_init(const char *device, const char *p)
             return -1;
         }
         vlan->nb_host_devs++;
-        ret = tap_win32_init(vlan, ifname);
+        ret = tap_win32_init(vlan, device, ifname);
     } else
 #elif defined (_AIX)
 #else
@@ -1512,7 +1520,7 @@ int net_client_init(const char *device, const char *p)
             fd = strtol(buf, NULL, 0);
             fcntl(fd, F_SETFL, O_NONBLOCK);
             ret = -1;
-            if (net_tap_fd_init(vlan, fd))
+            if (net_tap_fd_init(vlan, device, fd))
                 ret = 0;
         } else {
             if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {
@@ -1524,7 +1532,7 @@ int net_client_init(const char *device, const char *p)
             if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) {
                 pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT);
             }
-            ret = net_tap_init(vlan, ifname, setup_script, down_script);
+            ret = net_tap_init(vlan, device, ifname, setup_script, down_script);
         }
     } else
 #endif
@@ -1533,14 +1541,14 @@ int net_client_init(const char *device, const char *p)
             int fd;
             fd = strtol(buf, NULL, 0);
             ret = -1;
-            if (net_socket_fd_init(vlan, fd, 1))
+            if (net_socket_fd_init(vlan, device, fd, 1))
                 ret = 0;
         } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) {
-            ret = net_socket_listen_init(vlan, buf);
+            ret = net_socket_listen_init(vlan, device, buf);
         } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) {
-            ret = net_socket_connect_init(vlan, buf);
+            ret = net_socket_connect_init(vlan, device, buf);
         } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) {
-            ret = net_socket_mcast_init(vlan, buf);
+            ret = net_socket_mcast_init(vlan, device, buf);
         } else {
             fprintf(stderr, "Unknown socket options: %s\n", p);
             return -1;
@@ -1568,7 +1576,7 @@ int net_client_init(const char *device, const char *p)
 	} else {
 	    vde_mode = 0700;
 	}
-	ret = net_vde_init(vlan, vde_sock, vde_port, vde_group, vde_mode);
+	ret = net_vde_init(vlan, device, vde_sock, vde_port, vde_group, vde_mode);
     } else
 #endif
     {
diff --git a/net.h b/net.h
index 31c7a30..a2c6a50 100644
--- a/net.h
+++ b/net.h
@@ -18,6 +18,7 @@ struct VLANClientState {
     void *opaque;
     struct VLANClientState *next;
     struct VLANState *vlan;
+    char *model;
     char info_str[256];
 };
 
@@ -30,6 +31,7 @@ struct VLANState {
 
 VLANState *qemu_find_vlan(int id);
 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
+                                      const char *model,
                                       IOReadHandler *fd_read,
                                       IOCanRWHandler *fd_can_read,
                                       void *opaque);
diff --git a/sysemu.h b/sysemu.h
index 6e24e8a..d27faa6 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -75,7 +75,7 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 #endif
 
 /* TAP win32 */
-int tap_win32_init(VLANState *vlan, const char *ifname);
+int tap_win32_init(VLANState *vlan, const char *model, const char *ifname);
 
 /* SLIRP */
 void do_info_slirp(void);
diff --git a/tap-win32.c b/tap-win32.c
index 02a945e..13ca539 100644
--- a/tap-win32.c
+++ b/tap-win32.c
@@ -660,7 +660,7 @@ static void tap_win32_send(void *opaque)
     }
 }
 
-int tap_win32_init(VLANState *vlan, const char *ifname)
+int tap_win32_init(VLANState *vlan, const char *model, const char *ifname)
 {
     TAPState *s;
 
@@ -672,7 +672,7 @@ int tap_win32_init(VLANState *vlan, const char *ifname)
         return -1;
     }
 
-    s->vc = qemu_new_vlan_client(vlan, tap_receive, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "tap: ifname=%s", ifname);
-- 
1.6.0.6

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 2/6] Assign a name to each VLAN client
  2009-01-06 15:00         ` [Qemu-devel] [PATCH 1/6] Add a model string to VLANClientState Mark McLoughlin
@ 2009-01-06 15:00           ` Mark McLoughlin
  2009-01-06 15:00             ` [Qemu-devel] [PATCH 3/6] Fixup info_str formatting Mark McLoughlin
  2009-01-07 17:49           ` [Qemu-devel] Re: [PATCH 1/6] Add a model string to VLANClientState Anthony Liguori
  1 sibling, 1 reply; 26+ messages in thread
From: Mark McLoughlin @ 2009-01-06 15:00 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, qemu-devel

Automatically assign a name to each vlan client based on its model,
e.g. e1000.0, tap.3 or vde.1.

This name is intended to be used by the forthcoming 'set_link'
monitor command.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |   21 +++++++++++++++++++++
 net.h |    1 +
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/net.c b/net.c
index f3c2b89..c268233 100644
--- a/net.c
+++ b/net.c
@@ -296,6 +296,25 @@ static int parse_unix_path(struct sockaddr_un *uaddr, const char *str)
 }
 #endif
 
+static char *assign_name(VLANClientState *vc1, const char *model)
+{
+    VLANState *vlan;
+    char buf[256];
+    int id = 0;
+
+    for (vlan = first_vlan; vlan; vlan = vlan->next) {
+        VLANClientState *vc;
+
+        for (vc = vlan->first_client; vc; vc = vc->next)
+            if (vc != vc1 && strcmp(vc->model, model) == 0)
+                id++;
+    }
+
+    snprintf(buf, sizeof(buf), "%s.%d", model, id);
+
+    return strdup(buf);
+}
+
 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
                                       const char *model,
                                       IOReadHandler *fd_read,
@@ -307,6 +326,7 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
     if (!vc)
         return NULL;
     vc->model = strdup(model);
+    vc->name = assign_name(vc, model);
     vc->fd_read = fd_read;
     vc->fd_can_read = fd_can_read;
     vc->opaque = opaque;
@@ -327,6 +347,7 @@ void qemu_del_vlan_client(VLANClientState *vc)
     while (*pvc != NULL)
         if (*pvc == vc) {
             *pvc = vc->next;
+            free(vc->name);
             free(vc->model);
             free(vc);
             break;
diff --git a/net.h b/net.h
index a2c6a50..078dd18 100644
--- a/net.h
+++ b/net.h
@@ -19,6 +19,7 @@ struct VLANClientState {
     struct VLANClientState *next;
     struct VLANState *vlan;
     char *model;
+    char *name;
     char info_str[256];
 };
 
-- 
1.6.0.6

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 3/6] Fixup info_str formatting
  2009-01-06 15:00           ` [Qemu-devel] [PATCH 2/6] Assign a name to each VLAN client Mark McLoughlin
@ 2009-01-06 15:00             ` Mark McLoughlin
  2009-01-06 15:00               ` [Qemu-devel] [PATCH 4/6] Add qemu_format_nic_info_str() Mark McLoughlin
  0 siblings, 1 reply; 26+ messages in thread
From: Mark McLoughlin @ 2009-01-06 15:00 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, qemu-devel

The VLANClientState::info_str format isn't terribly consistent and
this patch moves towards it just containing the param strings
separated by a comma.

The type/model string is removed from info_str, and 'info network'
instead displays the vlan client name with the info_str.

There's a horrible little hack in net_cleanup() to parse a tap
client's info_str which I've also fixed up. The hack probably
shouldn't exist at all, though.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/e1000.c    |    2 +-
 hw/eepro100.c |    2 +-
 hw/mipsnet.c  |    2 +-
 hw/ne2000.c   |    4 ++--
 hw/pcnet.c    |    2 +-
 hw/rtl8139.c  |    2 +-
 hw/usb-net.c  |    2 +-
 net.c         |   14 ++++++++------
 8 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index 03c573b..996260c 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1075,7 +1075,7 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
                                  e1000_receive, e1000_can_receive, d);
 
     snprintf(d->vc->info_str, sizeof(d->vc->info_str),
-             "%s macaddr=%02x:%02x:%02x:%02x:%02x:%02x", info_str,
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
              d->nd->macaddr[0], d->nd->macaddr[1], d->nd->macaddr[2],
              d->nd->macaddr[3], d->nd->macaddr[4], d->nd->macaddr[5]);
 
diff --git a/hw/eepro100.c b/hw/eepro100.c
index a7861ca..8ea283c 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1780,7 +1780,7 @@ static void nic_init(PCIBus * bus, NICInfo * nd,
                                  nic_receive, nic_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "eepro100 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
              s->macaddr[0],
              s->macaddr[1],
              s->macaddr[2], s->macaddr[3], s->macaddr[4], s->macaddr[5]);
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 549e6f3..8190738 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -257,7 +257,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
     }
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "mipsnet macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
               s->nd->macaddr[0],
               s->nd->macaddr[1],
               s->nd->macaddr[2],
diff --git a/hw/ne2000.c b/hw/ne2000.c
index dc97989..600cdc3 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -745,7 +745,7 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
                                  ne2000_receive, ne2000_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "ne2000 macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
              s->macaddr[0],
              s->macaddr[1],
              s->macaddr[2],
@@ -815,7 +815,7 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
                                  ne2000_receive, ne2000_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "ne2000 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
              s->macaddr[0],
              s->macaddr[1],
              s->macaddr[2],
diff --git a/hw/pcnet.c b/hw/pcnet.c
index e961a06..90bf7fd 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1940,7 +1940,7 @@ static void pcnet_common_init(PCNetState *d, NICInfo *nd, const char *info_str)
                                      pcnet_receive, pcnet_can_receive, d);
 
         snprintf(d->vc->info_str, sizeof(d->vc->info_str),
-                 "pcnet macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+                 "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
                  d->nd->macaddr[0],
                  d->nd->macaddr[1],
                  d->nd->macaddr[2],
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 39f3209..1853ab3 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3442,7 +3442,7 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
                                  rtl8139_receive, rtl8139_can_receive, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "rtl8139 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
              s->macaddr[0],
              s->macaddr[1],
              s->macaddr[2],
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 40ee41b..1622ef8 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1461,7 +1461,7 @@ USBDevice *usb_net_init(NICInfo *nd)
                     0x40, s->mac[1], s->mac[2],
                     s->mac[3], s->mac[4], s->mac[5]);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-                    "usbnet macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+                    "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
                     s->mac[0], s->mac[1], s->mac[2],
                     s->mac[3], s->mac[4], s->mac[5]);
     fprintf(stderr, "usbnet: initialized mac %02x:%02x:%02x:%02x:%02x:%02x\n",
diff --git a/net.c b/net.c
index c268233..db69c7f 100644
--- a/net.c
+++ b/net.c
@@ -474,7 +474,7 @@ static int net_slirp_init(VLANState *vlan, const char *model)
     }
     slirp_vc = qemu_new_vlan_client(vlan, model,
                                     slirp_receive, NULL, NULL);
-    snprintf(slirp_vc->info_str, sizeof(slirp_vc->info_str), "user redirector");
+    slirp_vc->info_str[0] = '\0';
     return 0;
 }
 
@@ -699,7 +699,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
     s->vc->fd_readv = tap_receive_iov;
 #endif
     qemu_set_fd_handler(s->fd, tap_send, NULL, s);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "tap: fd=%d", fd);
+    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd);
     return s;
 }
 
@@ -954,7 +954,8 @@ static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
     if (!s)
         return -1;
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "tap: ifname=%s setup_script=%s", ifname, setup_script);
+             "ifname=%s,script=%s,downscript=%s",
+             ifname, setup_script, down_script);
     if (down_script && strcmp(down_script, "no"))
         snprintf(s->down_script, sizeof(s->down_script), "%s", down_script);
     return 0;
@@ -1016,7 +1017,7 @@ static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
     }
     s->vc = qemu_new_vlan_client(vlan, model, vde_from_qemu, NULL, s);
     qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "vde: sock=%s fd=%d",
+    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
              sock, vde_datafd(s->vde));
     return 0;
 }
@@ -1639,7 +1640,7 @@ void do_info_network(void)
     for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) {
         term_printf("VLAN %d devices:\n", vlan->id);
         for(vc = vlan->first_client; vc != NULL; vc = vc->next)
-            term_printf("  %s\n", vc->info_str);
+            term_printf("  %s: %s\n", vc->name, vc->info_str);
     }
 }
 
@@ -1657,7 +1658,8 @@ void net_cleanup(void)
                 char ifname[64];
                 TAPState *s = vc->opaque;
 
-                if (sscanf(vc->info_str, "tap: ifname=%63s ", ifname) == 1 &&
+                if (strcmp(vc->model, "tap") == 0 &&
+                    sscanf(vc->info_str, "ifname=%63s ", ifname) == 1 &&
                     s->down_script[0])
                     launch_script(s->down_script, ifname, s->fd);
             }
-- 
1.6.0.6

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 4/6] Add qemu_format_nic_info_str()
  2009-01-06 15:00             ` [Qemu-devel] [PATCH 3/6] Fixup info_str formatting Mark McLoughlin
@ 2009-01-06 15:00               ` Mark McLoughlin
  2009-01-06 15:00                 ` [Qemu-devel] [PATCH 5/6] add missing MAC address to info_str for some NICs Mark McLoughlin
  0 siblings, 1 reply; 26+ messages in thread
From: Mark McLoughlin @ 2009-01-06 15:00 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, qemu-devel

Factor out a simple little function for formatting a NIC's
info_str and make all NICs use it.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/e1000.c    |    5 +----
 hw/eepro100.c |    6 +-----
 hw/mipsnet.c  |    9 +--------
 hw/ne2000.c   |   18 ++----------------
 hw/pcnet.c    |    9 +--------
 hw/rtl8139.c  |    9 +--------
 hw/usb-net.c  |    6 ++----
 net.c         |    8 ++++++++
 net.h         |    1 +
 9 files changed, 18 insertions(+), 53 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index 996260c..5b0b731 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1074,10 +1074,7 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
     d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  e1000_receive, e1000_can_receive, d);
 
-    snprintf(d->vc->info_str, sizeof(d->vc->info_str),
-             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             d->nd->macaddr[0], d->nd->macaddr[1], d->nd->macaddr[2],
-             d->nd->macaddr[3], d->nd->macaddr[4], d->nd->macaddr[5]);
+    qemu_format_nic_info_str(d->vc, d->nd->macaddr);
 
     register_savevm(info_str, -1, 2, nic_save, nic_load, d);
 }
diff --git a/hw/eepro100.c b/hw/eepro100.c
index 8ea283c..86a4e6e 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1779,11 +1779,7 @@ static void nic_init(PCIBus * bus, NICInfo * nd,
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  nic_receive, nic_can_receive, s);
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             s->macaddr[0],
-             s->macaddr[1],
-             s->macaddr[2], s->macaddr[3], s->macaddr[4], s->macaddr[5]);
+    qemu_format_nic_info_str(s->vc, s->macaddr);
 
     qemu_register_reset(nic_reset, s);
 
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 8190738..4b3e8e9 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -256,14 +256,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
         s->vc = NULL;
     }
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-              s->nd->macaddr[0],
-              s->nd->macaddr[1],
-              s->nd->macaddr[2],
-              s->nd->macaddr[3],
-              s->nd->macaddr[4],
-              s->nd->macaddr[5]);
+    qemu_format_nic_info_str(s->vc, s->nd->macaddr);
 
     mipsnet_reset(s);
     register_savevm("mipsnet", 0, 0, mipsnet_save, mipsnet_load, s);
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 600cdc3..ad97bc5 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -744,14 +744,7 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  ne2000_receive, ne2000_can_receive, s);
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             s->macaddr[0],
-             s->macaddr[1],
-             s->macaddr[2],
-             s->macaddr[3],
-             s->macaddr[4],
-             s->macaddr[5]);
+    qemu_format_nic_info_str(s->vc, s->macaddr);
 
     register_savevm("ne2000", -1, 2, ne2000_save, ne2000_load, s);
 }
@@ -814,14 +807,7 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  ne2000_receive, ne2000_can_receive, s);
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             s->macaddr[0],
-             s->macaddr[1],
-             s->macaddr[2],
-             s->macaddr[3],
-             s->macaddr[4],
-             s->macaddr[5]);
+    qemu_format_nic_info_str(s->vc, s->macaddr);
 
     register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s);
 }
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 90bf7fd..5b45956 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1939,14 +1939,7 @@ static void pcnet_common_init(PCNetState *d, NICInfo *nd, const char *info_str)
         d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                      pcnet_receive, pcnet_can_receive, d);
 
-        snprintf(d->vc->info_str, sizeof(d->vc->info_str),
-                 "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-                 d->nd->macaddr[0],
-                 d->nd->macaddr[1],
-                 d->nd->macaddr[2],
-                 d->nd->macaddr[3],
-                 d->nd->macaddr[4],
-                 d->nd->macaddr[5]);
+        qemu_format_nic_info_str(d->vc, d->nd->macaddr);
     } else {
         d->vc = NULL;
     }
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 1853ab3..d517220 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3441,14 +3441,7 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  rtl8139_receive, rtl8139_can_receive, s);
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             s->macaddr[0],
-             s->macaddr[1],
-             s->macaddr[2],
-             s->macaddr[3],
-             s->macaddr[4],
-             s->macaddr[5]);
+    qemu_format_nic_info_str(s->vc, s->macaddr);
 
     s->cplus_txbuffer = NULL;
     s->cplus_txbuffer_len = 0;
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 1622ef8..5539336 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1456,14 +1456,12 @@ USBDevice *usb_net_init(NICInfo *nd)
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                     usbnet_receive, usbnet_can_receive, s);
 
+    qemu_format_nic_info_str(s->vc, s->mac);
+
     snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
                     "%02x%02x%02x%02x%02x%02x",
                     0x40, s->mac[1], s->mac[2],
                     s->mac[3], s->mac[4], s->mac[5]);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-                    "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-                    s->mac[0], s->mac[1], s->mac[2],
-                    s->mac[3], s->mac[4], s->mac[5]);
     fprintf(stderr, "usbnet: initialized mac %02x:%02x:%02x:%02x:%02x:%02x\n",
                     s->mac[0], s->mac[1], s->mac[2],
                     s->mac[3], s->mac[4], s->mac[5]);
diff --git a/net.c b/net.c
index db69c7f..e293790 100644
--- a/net.c
+++ b/net.c
@@ -296,6 +296,14 @@ static int parse_unix_path(struct sockaddr_un *uaddr, const char *str)
 }
 #endif
 
+void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6])
+{
+    snprintf(vc->info_str, sizeof(vc->info_str),
+             "macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+             macaddr[0], macaddr[1], macaddr[2],
+             macaddr[3], macaddr[4], macaddr[5]);
+}
+
 static char *assign_name(VLANClientState *vc1, const char *model)
 {
     VLANState *vlan;
diff --git a/net.h b/net.h
index 078dd18..904519a 100644
--- a/net.h
+++ b/net.h
@@ -41,6 +41,7 @@ int qemu_can_send_packet(VLANClientState *vc);
 ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
                           int iovcnt);
 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
+void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
 void qemu_handler_true(void *opaque);
 
 void do_info_network(void);
-- 
1.6.0.6

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 5/6] add missing MAC address to info_str for some NICs
  2009-01-06 15:00               ` [Qemu-devel] [PATCH 4/6] Add qemu_format_nic_info_str() Mark McLoughlin
@ 2009-01-06 15:00                 ` Mark McLoughlin
  2009-01-06 15:00                   ` [Qemu-devel] [PATCH 6/6] Add a -net name=foo parameter Mark McLoughlin
  0 siblings, 1 reply; 26+ messages in thread
From: Mark McLoughlin @ 2009-01-06 15:00 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, qemu-devel

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/mcf_fec.c        |    1 +
 hw/smc91c111.c      |    1 +
 hw/stellaris_enet.c |    4 +++-
 hw/virtio-net.c     |    2 ++
 4 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 7e3afa5..6c044cd 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -455,4 +455,5 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  mcf_fec_receive, mcf_fec_can_receive, s);
     memcpy(s->macaddr, nd->macaddr, 6);
+    qemu_format_nic_info_str(n->vc, s->macaddr);
 }
diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index fadd151..6416026 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -706,5 +706,6 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
 
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  smc91c111_receive, smc91c111_can_receive, s);
+    qemu_format_nic_info_str(s->vc, s->macaddr);
     /* ??? Save/restore.  */
 }
diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c
index bd8dcd9..69fb85d 100644
--- a/hw/stellaris_enet.c
+++ b/hw/stellaris_enet.c
@@ -396,9 +396,11 @@ void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     s->irq = irq;
     memcpy(s->macaddr, nd->macaddr, 6);
 
-    if (nd->vlan)
+    if (nd->vlan) {
         s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                      stellaris_enet_receive, stellaris_enet_can_receive, s);
+        qemu_format_nic_info_str(s->vc, s->macaddr);
+    }
 
     stellaris_enet_reset(s);
     register_savevm("stellaris_enet", -1, 1,
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 4500fab..b197c70 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -318,6 +318,8 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
     n->vc = qemu_new_vlan_client(nd->vlan, nd->model,
                                  virtio_net_receive, virtio_net_can_receive, n);
 
+    qemu_format_nic_info_str(n->vc, n->mac);
+
     n->tx_timer = qemu_new_timer(vm_clock, virtio_net_tx_timer, n);
     n->tx_timer_active = 0;
     n->mergeable_rx_bufs = 0;
-- 
1.6.0.6

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] [PATCH 6/6] Add a -net name=foo parameter
  2009-01-06 15:00                 ` [Qemu-devel] [PATCH 5/6] add missing MAC address to info_str for some NICs Mark McLoughlin
@ 2009-01-06 15:00                   ` Mark McLoughlin
  0 siblings, 0 replies; 26+ messages in thread
From: Mark McLoughlin @ 2009-01-06 15:00 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Mark McLoughlin, qemu-devel

Allow the user to supply a vlan client name on the command line.

This is probably only useful for management tools so that they can
use their own names rather than parsing the output of 'info network'.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/e1000.c          |    2 +-
 hw/eepro100.c       |    2 +-
 hw/etraxfs_eth.c    |    2 +-
 hw/mcf_fec.c        |    2 +-
 hw/mipsnet.c        |    2 +-
 hw/musicpal.c       |    2 +-
 hw/ne2000.c         |    4 +-
 hw/pcnet.c          |    2 +-
 hw/rtl8139.c        |    2 +-
 hw/smc91c111.c      |    2 +-
 hw/stellaris_enet.c |    2 +-
 hw/usb-net.c        |    2 +-
 hw/virtio-net.c     |    2 +-
 net.c               |   97 +++++++++++++++++++++++++++++++++-----------------
 net.h               |    2 +
 qemu-doc.texi       |   15 ++++----
 sysemu.h            |    3 +-
 tap-win32.c         |    5 ++-
 vl.c                |   14 ++++----
 19 files changed, 100 insertions(+), 64 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index 5b0b731..09cb96a 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1071,7 +1071,7 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
     d->rxbuf_min_shift = 1;
     memset(&d->tx, 0, sizeof d->tx);
 
-    d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    d->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  e1000_receive, e1000_can_receive, d);
 
     qemu_format_nic_info_str(d->vc, d->nd->macaddr);
diff --git a/hw/eepro100.c b/hw/eepro100.c
index 86a4e6e..5eca105 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1776,7 +1776,7 @@ static void nic_init(PCIBus * bus, NICInfo * nd,
 
     nic_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  nic_receive, nic_can_receive, s);
 
     qemu_format_nic_info_str(s->vc, s->macaddr);
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index 244a23d..4bad3d2 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -596,7 +596,7 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
 	eth->ethregs = cpu_register_io_memory(0, eth_read, eth_write, eth);
 	cpu_register_physical_memory (base, 0x5c, eth->ethregs);
 
-	eth->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+	eth->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
 				       eth_receive, eth_can_receive, eth);
 
 	return dma;
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 6c044cd..d39992f 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -452,7 +452,7 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
                                        mcf_fec_writefn, s);
     cpu_register_physical_memory(base, 0x400, iomemtype);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  mcf_fec_receive, mcf_fec_can_receive, s);
     memcpy(s->macaddr, nd->macaddr, 6);
     qemu_format_nic_info_str(n->vc, s->macaddr);
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 4b3e8e9..0eb4c1e 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -250,7 +250,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
     s->irq = irq;
     s->nd = nd;
     if (nd && nd->vlan) {
-        s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+        s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                      mipsnet_receive, mipsnet_can_receive, s);
     } else {
         s->vc = NULL;
diff --git a/hw/musicpal.c b/hw/musicpal.c
index d172a11..1c932ec 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -718,7 +718,7 @@ static void mv88w8618_eth_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     if (!s)
         return;
     s->irq = irq;
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  eth_receive, eth_can_receive, s);
     iomemtype = cpu_register_io_memory(0, mv88w8618_eth_readfn,
                                        mv88w8618_eth_writefn, s);
diff --git a/hw/ne2000.c b/hw/ne2000.c
index ad97bc5..200db90 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -741,7 +741,7 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
 
     ne2000_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  ne2000_receive, ne2000_can_receive, s);
 
     qemu_format_nic_info_str(s->vc, s->macaddr);
@@ -804,7 +804,7 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
     s->pci_dev = (PCIDevice *)d;
     memcpy(s->macaddr, nd->macaddr, 6);
     ne2000_reset(s);
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  ne2000_receive, ne2000_can_receive, s);
 
     qemu_format_nic_info_str(s->vc, s->macaddr);
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 5b45956..102166e 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1936,7 +1936,7 @@ static void pcnet_common_init(PCNetState *d, NICInfo *nd, const char *info_str)
     d->nd = nd;
 
     if (nd && nd->vlan) {
-        d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+        d->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                      pcnet_receive, pcnet_can_receive, d);
 
         qemu_format_nic_info_str(d->vc, d->nd->macaddr);
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index d517220..8be63c5 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3438,7 +3438,7 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
     s->pci_dev = (PCIDevice *)d;
     memcpy(s->macaddr, nd->macaddr, 6);
     rtl8139_reset(s);
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  rtl8139_receive, rtl8139_can_receive, s);
 
     qemu_format_nic_info_str(s->vc, s->macaddr);
diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index 6416026..27a3158 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -704,7 +704,7 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
 
     smc91c111_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  smc91c111_receive, smc91c111_can_receive, s);
     qemu_format_nic_info_str(s->vc, s->macaddr);
     /* ??? Save/restore.  */
diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c
index 69fb85d..a5cd163 100644
--- a/hw/stellaris_enet.c
+++ b/hw/stellaris_enet.c
@@ -397,7 +397,7 @@ void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     memcpy(s->macaddr, nd->macaddr, 6);
 
     if (nd->vlan) {
-        s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+        s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                      stellaris_enet_receive, stellaris_enet_can_receive, s);
         qemu_format_nic_info_str(s->vc, s->macaddr);
     }
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 5539336..c49fd62 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1453,7 +1453,7 @@ USBDevice *usb_net_init(NICInfo *nd)
 
     pstrcpy(s->dev.devname, sizeof(s->dev.devname),
                     "QEMU USB Network Interface");
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                     usbnet_receive, usbnet_can_receive, s);
 
     qemu_format_nic_info_str(s->vc, s->mac);
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index b197c70..4443ff5 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -315,7 +315,7 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
     n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx);
     n->tx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_tx);
     memcpy(n->mac, nd->macaddr, 6);
-    n->vc = qemu_new_vlan_client(nd->vlan, nd->model,
+    n->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  virtio_net_receive, virtio_net_can_receive, n);
 
     qemu_format_nic_info_str(n->vc, n->mac);
diff --git a/net.c b/net.c
index e293790..15f9153 100644
--- a/net.c
+++ b/net.c
@@ -325,6 +325,7 @@ static char *assign_name(VLANClientState *vc1, const char *model)
 
 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
                                       const char *model,
+                                      const char *name,
                                       IOReadHandler *fd_read,
                                       IOCanRWHandler *fd_can_read,
                                       void *opaque)
@@ -334,7 +335,10 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
     if (!vc)
         return NULL;
     vc->model = strdup(model);
-    vc->name = assign_name(vc, model);
+    if (name)
+        vc->name = strdup(name);
+    else
+        vc->name = assign_name(vc, model);
     vc->fd_read = fd_read;
     vc->fd_can_read = fd_can_read;
     vc->opaque = opaque;
@@ -474,13 +478,13 @@ static void slirp_receive(void *opaque, const uint8_t *buf, int size)
     slirp_input(buf, size);
 }
 
-static int net_slirp_init(VLANState *vlan, const char *model)
+static int net_slirp_init(VLANState *vlan, const char *model, const char *name)
 {
     if (!slirp_inited) {
         slirp_inited = 1;
         slirp_init();
     }
-    slirp_vc = qemu_new_vlan_client(vlan, model,
+    slirp_vc = qemu_new_vlan_client(vlan, model, name,
                                     slirp_receive, NULL, NULL);
     slirp_vc->info_str[0] = '\0';
     return 0;
@@ -694,7 +698,10 @@ static void tap_send(void *opaque)
 
 /* fd support */
 
-static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
+static TAPState *net_tap_fd_init(VLANState *vlan,
+                                 const char *model,
+                                 const char *name,
+                                 int fd)
 {
     TAPState *s;
 
@@ -702,7 +709,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
     if (!s)
         return NULL;
     s->fd = fd;
-    s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s);
 #ifdef HAVE_IOVEC
     s->vc->fd_readv = tap_receive_iov;
 #endif
@@ -937,7 +944,8 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)
     return 0;
 }
 
-static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
+static int net_tap_init(VLANState *vlan, const char *model,
+                        const char *name, const char *ifname1,
                         const char *setup_script, const char *down_script)
 {
     TAPState *s;
@@ -958,7 +966,7 @@ static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
 	if (launch_script(setup_script, ifname, fd))
 	    return -1;
     }
-    s = net_tap_fd_init(vlan, model, fd);
+    s = net_tap_fd_init(vlan, model, name, fd);
     if (!s)
         return -1;
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
@@ -1002,7 +1010,8 @@ static void vde_from_qemu(void *opaque, const uint8_t *buf, int size)
     }
 }
 
-static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
+static int net_vde_init(VLANState *vlan, const char *model,
+                        const char *name, const char *sock,
                         int port, const char *group, int mode)
 {
     VDEState *s;
@@ -1023,7 +1032,7 @@ static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
         free(s);
         return -1;
     }
-    s->vc = qemu_new_vlan_client(vlan, model, vde_from_qemu, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, name, vde_from_qemu, NULL, s);
     qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
              sock, vde_datafd(s->vde));
@@ -1045,6 +1054,7 @@ typedef struct NetSocketState {
 typedef struct NetSocketListenState {
     VLANState *vlan;
     char *model;
+    char *name;
     int fd;
 } NetSocketListenState;
 
@@ -1198,7 +1208,9 @@ fail:
     return -1;
 }
 
-static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *model,
+static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
+                                                const char *model,
+                                                const char *name,
                                                 int fd, int is_connected)
 {
     struct sockaddr_in saddr;
@@ -1242,7 +1254,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *mod
         return NULL;
     s->fd = fd;
 
-    s->vc = qemu_new_vlan_client(vlan, model, net_socket_receive_dgram, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, name, net_socket_receive_dgram, NULL, s);
     qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
 
     /* mcast: save bound address as dst */
@@ -1261,7 +1273,9 @@ static void net_socket_connect(void *opaque)
     qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
 }
 
-static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *model,
+static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
+                                                 const char *model,
+                                                 const char *name,
                                                  int fd, int is_connected)
 {
     NetSocketState *s;
@@ -1269,7 +1283,7 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *mo
     if (!s)
         return NULL;
     s->fd = fd;
-    s->vc = qemu_new_vlan_client(vlan, model,
+    s->vc = qemu_new_vlan_client(vlan, model, name,
                                  net_socket_receive, NULL, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "socket: fd=%d", fd);
@@ -1281,7 +1295,8 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *mo
     return s;
 }
 
-static NetSocketState *net_socket_fd_init(VLANState *vlan, const char *model,
+static NetSocketState *net_socket_fd_init(VLANState *vlan,
+                                          const char *model, const char *name,
                                           int fd, int is_connected)
 {
     int so_type=-1, optlen=sizeof(so_type);
@@ -1293,13 +1308,13 @@ static NetSocketState *net_socket_fd_init(VLANState *vlan, const char *model,
     }
     switch(so_type) {
     case SOCK_DGRAM:
-        return net_socket_fd_init_dgram(vlan, model, fd, is_connected);
+        return net_socket_fd_init_dgram(vlan, model, name, fd, is_connected);
     case SOCK_STREAM:
-        return net_socket_fd_init_stream(vlan, model, fd, is_connected);
+        return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
     default:
         /* who knows ... this could be a eg. a pty, do warn and continue as stream */
         fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
-        return net_socket_fd_init_stream(vlan, model, fd, is_connected);
+        return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
     }
     return NULL;
 }
@@ -1321,7 +1336,7 @@ static void net_socket_accept(void *opaque)
             break;
         }
     }
-    s1 = net_socket_fd_init(s->vlan, s->model, fd, 1);
+    s1 = net_socket_fd_init(s->vlan, s->model, s->name, fd, 1);
     if (!s1) {
         closesocket(fd);
     } else {
@@ -1331,7 +1346,9 @@ static void net_socket_accept(void *opaque)
     }
 }
 
-static int net_socket_listen_init(VLANState *vlan, const char *model,
+static int net_socket_listen_init(VLANState *vlan,
+                                  const char *model,
+                                  const char *name,
                                   const char *host_str)
 {
     NetSocketListenState *s;
@@ -1368,12 +1385,15 @@ static int net_socket_listen_init(VLANState *vlan, const char *model,
     }
     s->vlan = vlan;
     s->model = strdup(model);
+    s->name = strdup(name);
     s->fd = fd;
     qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
     return 0;
 }
 
-static int net_socket_connect_init(VLANState *vlan, const char *model,
+static int net_socket_connect_init(VLANState *vlan,
+                                   const char *model,
+                                   const char *name,
                                    const char *host_str)
 {
     NetSocketState *s;
@@ -1412,7 +1432,7 @@ static int net_socket_connect_init(VLANState *vlan, const char *model,
             break;
         }
     }
-    s = net_socket_fd_init(vlan, model, fd, connected);
+    s = net_socket_fd_init(vlan, model, name, fd, connected);
     if (!s)
         return -1;
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
@@ -1421,7 +1441,9 @@ static int net_socket_connect_init(VLANState *vlan, const char *model,
     return 0;
 }
 
-static int net_socket_mcast_init(VLANState *vlan, const char *model,
+static int net_socket_mcast_init(VLANState *vlan,
+                                 const char *model,
+                                 const char *name,
                                  const char *host_str)
 {
     NetSocketState *s;
@@ -1436,7 +1458,7 @@ static int net_socket_mcast_init(VLANState *vlan, const char *model,
     if (fd < 0)
 	return -1;
 
-    s = net_socket_fd_init(vlan, model, fd, 0);
+    s = net_socket_fd_init(vlan, model, name, fd, 0);
     if (!s)
         return -1;
 
@@ -1474,6 +1496,7 @@ int net_client_init(const char *device, const char *p)
     char buf[1024];
     int vlan_id, ret;
     VLANState *vlan;
+    char *name = NULL;
 
     vlan_id = 0;
     if (get_param_value(buf, sizeof(buf), "vlan", p)) {
@@ -1484,6 +1507,9 @@ int net_client_init(const char *device, const char *p)
         fprintf(stderr, "Could not create vlan %d\n", vlan_id);
         return -1;
     }
+    if (get_param_value(buf, sizeof(buf), "name", p)) {
+        name = strdup(buf);
+    }
     if (!strcmp(device, "nic")) {
         NICInfo *nd;
         uint8_t *macaddr;
@@ -1511,6 +1537,8 @@ int net_client_init(const char *device, const char *p)
             nd->model = strdup(buf);
         }
         nd->vlan = vlan;
+        nd->name = name;
+        name = NULL;
         nb_nics++;
         vlan->nb_guest_devs++;
         ret = 0;
@@ -1526,7 +1554,7 @@ int net_client_init(const char *device, const char *p)
             pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf);
         }
         vlan->nb_host_devs++;
-        ret = net_slirp_init(vlan, device);
+        ret = net_slirp_init(vlan, device, name);
     } else
 #endif
 #ifdef _WIN32
@@ -1537,7 +1565,7 @@ int net_client_init(const char *device, const char *p)
             return -1;
         }
         vlan->nb_host_devs++;
-        ret = tap_win32_init(vlan, device, ifname);
+        ret = tap_win32_init(vlan, device, name, ifname);
     } else
 #elif defined (_AIX)
 #else
@@ -1550,7 +1578,7 @@ int net_client_init(const char *device, const char *p)
             fd = strtol(buf, NULL, 0);
             fcntl(fd, F_SETFL, O_NONBLOCK);
             ret = -1;
-            if (net_tap_fd_init(vlan, device, fd))
+            if (net_tap_fd_init(vlan, device, name, fd))
                 ret = 0;
         } else {
             if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {
@@ -1562,7 +1590,7 @@ int net_client_init(const char *device, const char *p)
             if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) {
                 pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT);
             }
-            ret = net_tap_init(vlan, device, ifname, setup_script, down_script);
+            ret = net_tap_init(vlan, device, name, ifname, setup_script, down_script);
         }
     } else
 #endif
@@ -1571,14 +1599,14 @@ int net_client_init(const char *device, const char *p)
             int fd;
             fd = strtol(buf, NULL, 0);
             ret = -1;
-            if (net_socket_fd_init(vlan, device, fd, 1))
+            if (net_socket_fd_init(vlan, device, name, fd, 1))
                 ret = 0;
         } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) {
-            ret = net_socket_listen_init(vlan, device, buf);
+            ret = net_socket_listen_init(vlan, device, name, buf);
         } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) {
-            ret = net_socket_connect_init(vlan, device, buf);
+            ret = net_socket_connect_init(vlan, device, name, buf);
         } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) {
-            ret = net_socket_mcast_init(vlan, device, buf);
+            ret = net_socket_mcast_init(vlan, device, name, buf);
         } else {
             fprintf(stderr, "Unknown socket options: %s\n", p);
             return -1;
@@ -1606,17 +1634,20 @@ int net_client_init(const char *device, const char *p)
 	} else {
 	    vde_mode = 0700;
 	}
-	ret = net_vde_init(vlan, device, vde_sock, vde_port, vde_group, vde_mode);
+	ret = net_vde_init(vlan, device, name, vde_sock, vde_port, vde_group, vde_mode);
     } else
 #endif
     {
         fprintf(stderr, "Unknown network device: %s\n", device);
+        if (name)
+            free(name);
         return -1;
     }
     if (ret < 0) {
         fprintf(stderr, "Could not initialize device '%s'\n", device);
     }
-
+    if (name)
+        free(name);
     return ret;
 }
 
diff --git a/net.h b/net.h
index 904519a..b89d165 100644
--- a/net.h
+++ b/net.h
@@ -33,6 +33,7 @@ struct VLANState {
 VLANState *qemu_find_vlan(int id);
 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
                                       const char *model,
+                                      const char *name,
                                       IOReadHandler *fd_read,
                                       IOCanRWHandler *fd_can_read,
                                       void *opaque);
@@ -53,6 +54,7 @@ void do_info_network(void);
 struct NICInfo {
     uint8_t macaddr[6];
     const char *model;
+    const char *name;
     VLANState *vlan;
 };
 
diff --git a/qemu-doc.texi b/qemu-doc.texi
index 0f1e7cc..a145b19 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -606,10 +606,11 @@ Network options:
 
 @table @option
 
-@item -net nic[,vlan=@var{n}][,macaddr=@var{addr}][,model=@var{type}]
+@item -net nic[,vlan=@var{n}][,macaddr=@var{addr}][,model=@var{type}][,name=@var{name}]
 Create a new Network Interface Card and connect it to VLAN @var{n} (@var{n}
 = 0 is the default). The NIC is an ne2k_pci by default on the PC
-target. Optionally, the MAC address can be changed. If no
+target. Optionally, the MAC address can be changed to @var{addr}
+and a @var{name} can be assigned for use in monitor commands. If no
 @option{-net} option is specified, a single NIC is created.
 Qemu can emulate several different models of network card.
 Valid values for @var{type} are
@@ -619,12 +620,12 @@ Valid values for @var{type} are
 Not all devices are supported on all targets.  Use -net nic,model=?
 for a list of available devices for your target.
 
-@item -net user[,vlan=@var{n}][,hostname=@var{name}]
+@item -net user[,vlan=@var{n}][,hostname=@var{name}][,name=@var{name}]
 Use the user mode network stack which requires no administrator
 privilege to run.  @option{hostname=name} can be used to specify the client
 hostname reported by the builtin DHCP server.
 
-@item -net tap[,vlan=@var{n}][,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}]
+@item -net tap[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}]
 Connect the host TAP network interface @var{name} to VLAN @var{n}, use
 the network script @var{file} to configure it and the network script 
 @var{dfile} to deconfigure it. If @var{name} is not provided, the OS 
@@ -645,7 +646,7 @@ qemu linux.img -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 \
 @end example
 
 
-@item -net socket[,vlan=@var{n}][,fd=@var{h}][,listen=[@var{host}]:@var{port}][,connect=@var{host}:@var{port}]
+@item -net socket[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,listen=[@var{host}]:@var{port}][,connect=@var{host}:@var{port}]
 
 Connect the VLAN @var{n} to a remote VLAN in another QEMU virtual
 machine using a TCP socket connection. If @option{listen} is
@@ -665,7 +666,7 @@ qemu linux.img -net nic,macaddr=52:54:00:12:34:57 \
                -net socket,connect=127.0.0.1:1234
 @end example
 
-@item -net socket[,vlan=@var{n}][,fd=@var{h}][,mcast=@var{maddr}:@var{port}]
+@item -net socket[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,mcast=@var{maddr}:@var{port}]
 
 Create a VLAN @var{n} shared with another QEMU virtual
 machines using a UDP multicast socket, effectively making a bus for
@@ -705,7 +706,7 @@ qemu linux.img -net nic,macaddr=52:54:00:12:34:56 \
 /path/to/linux ubd0=/path/to/root_fs eth0=mcast
 @end example
 
-@item -net vde[,vlan=@var{n}][,sock=@var{socketpath}][,port=@var{n}][,group=@var{groupname}][,mode=@var{octalmode}]
+@item -net vde[,vlan=@var{n}][,name=@var{name}][,sock=@var{socketpath}][,port=@var{n}][,group=@var{groupname}][,mode=@var{octalmode}]
 Connect VLAN @var{n} to PORT @var{n} of a vde switch running on host and
 listening for incoming connections on @var{socketpath}. Use GROUP @var{groupname}
 and MODE @var{octalmode} to change default ownership and permissions for
diff --git a/sysemu.h b/sysemu.h
index d27faa6..cd0f912 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -75,7 +75,8 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 #endif
 
 /* TAP win32 */
-int tap_win32_init(VLANState *vlan, const char *model, const char *ifname);
+int tap_win32_init(VLANState *vlan, const char *model,
+                   const char *name, const char *ifname);
 
 /* SLIRP */
 void do_info_slirp(void);
diff --git a/tap-win32.c b/tap-win32.c
index 13ca539..3279644 100644
--- a/tap-win32.c
+++ b/tap-win32.c
@@ -660,7 +660,8 @@ static void tap_win32_send(void *opaque)
     }
 }
 
-int tap_win32_init(VLANState *vlan, const char *model, const char *ifname)
+int tap_win32_init(VLANState *vlan, const char *model,
+                   const char *name, const char *ifname)
 {
     TAPState *s;
 
@@ -672,7 +673,7 @@ int tap_win32_init(VLANState *vlan, const char *model, const char *ifname)
         return -1;
     }
 
-    s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
+    s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s);
 
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
              "tap: ifname=%s", ifname);
diff --git a/vl.c b/vl.c
index 07740f5..2e54553 100644
--- a/vl.c
+++ b/vl.c
@@ -3871,30 +3871,30 @@ static void help(int exitcode)
            "-uuid %%08x-%%04x-%%04x-%%04x-%%012x specify machine UUID\n"
            "\n"
            "Network options:\n"
-           "-net nic[,vlan=n][,macaddr=addr][,model=type]\n"
+           "-net nic[,vlan=n][,macaddr=addr][,model=type][,name=str]\n"
            "                create a new Network Interface Card and connect it to VLAN 'n'\n"
 #ifdef CONFIG_SLIRP
-           "-net user[,vlan=n][,hostname=host]\n"
+           "-net user[,vlan=n][,name=str][,hostname=host]\n"
            "                connect the user mode network stack to VLAN 'n' and send\n"
            "                hostname 'host' to DHCP clients\n"
 #endif
 #ifdef _WIN32
-           "-net tap[,vlan=n],ifname=name\n"
+           "-net tap[,vlan=n][,name=str],ifname=name\n"
            "                connect the host TAP network interface to VLAN 'n'\n"
 #else
-           "-net tap[,vlan=n][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n"
+           "-net tap[,vlan=n][,name=str][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n"
            "                connect the host TAP network interface to VLAN 'n' and use the\n"
            "                network scripts 'file' (default=%s)\n"
            "                and 'dfile' (default=%s);\n"
            "                use '[down]script=no' to disable script execution;\n"
            "                use 'fd=h' to connect to an already opened TAP interface\n"
 #endif
-           "-net socket[,vlan=n][,fd=h][,listen=[host]:port][,connect=host:port]\n"
+           "-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]\n"
            "                connect the vlan 'n' to another VLAN using a socket connection\n"
-           "-net socket[,vlan=n][,fd=h][,mcast=maddr:port]\n"
+           "-net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port]\n"
            "                connect the vlan 'n' to multicast maddr and port\n"
 #ifdef CONFIG_VDE
-           "-net vde[,vlan=n][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n"
+           "-net vde[,vlan=n][,name=str][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n"
            "                connect the vlan 'n' to port 'n' of a vde switch running\n"
            "                on host and listening for incoming connections on 'socketpath'.\n"
            "                Use group 'groupname' and mode 'octalmode' to change default\n"
-- 
1.6.0.6

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [Qemu-devel] Re: [PATCH 1/6] Add a model string to VLANClientState
  2009-01-06 15:00         ` [Qemu-devel] [PATCH 1/6] Add a model string to VLANClientState Mark McLoughlin
  2009-01-06 15:00           ` [Qemu-devel] [PATCH 2/6] Assign a name to each VLAN client Mark McLoughlin
@ 2009-01-07 17:49           ` Anthony Liguori
  1 sibling, 0 replies; 26+ messages in thread
From: Anthony Liguori @ 2009-01-07 17:49 UTC (permalink / raw)
  To: Mark McLoughlin; +Cc: qemu-devel

Mark McLoughlin wrote:
> Don't lose track of what type/model a vlan client is so that we can
> e.g. assign a global per-model id to clients.
>
> The entire patch is basically a tedious excercise in making sure the
> type/model string gets propagated down to qemu_new_vlan_client().
>
> Signed-off-by: Mark McLoughlin <markmc@redhat.com>
>   

Applied the whole series. Thanks.

Really nice series too.

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2009-01-07 17:49 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-09 10:55 [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000 Mark McLoughlin
2008-12-09 10:55 ` [Qemu-devel] [PATCH 1/4] Add 'set_link' monitor command Mark McLoughlin
2008-12-09 10:55   ` [Qemu-devel] [PATCH 2/4] Add device index to 'info network' output Mark McLoughlin
2008-12-09 10:55     ` [Qemu-devel] [PATCH 3/4] Allow devices be notified of link status change Mark McLoughlin
2008-12-09 10:55       ` [Qemu-devel] [PATCH 4/4] Implement e1000 link status Mark McLoughlin
2008-12-09 15:04     ` [Qemu-devel] Re: [PATCH 2/4] Add device index to 'info network' output Anthony Liguori
2008-12-09 15:01   ` [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command Anthony Liguori
2008-12-12 14:45     ` Mark McLoughlin
2008-12-12 14:46       ` [Qemu-devel] [PATCH 1/5] Add a model string to VLANClientState Mark McLoughlin
2008-12-12 14:46         ` [Qemu-devel] [PATCH 2/5] Assign a name to each VLAN client Mark McLoughlin
2008-12-12 14:46           ` [Qemu-devel] [PATCH 3/5] Fixup info_str formatting Mark McLoughlin
2008-12-12 14:46             ` [Qemu-devel] [PATCH 4/5] Add qemu_format_nic_info_str() Mark McLoughlin
2008-12-12 14:46               ` [Qemu-devel] [PATCH 5/5] Add a -net name=foo parameter Mark McLoughlin
2008-12-14 23:48                 ` Aurelien Jarno
2009-01-06 14:59       ` [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command Mark McLoughlin
2009-01-06 15:00         ` [Qemu-devel] [PATCH 1/6] Add a model string to VLANClientState Mark McLoughlin
2009-01-06 15:00           ` [Qemu-devel] [PATCH 2/6] Assign a name to each VLAN client Mark McLoughlin
2009-01-06 15:00             ` [Qemu-devel] [PATCH 3/6] Fixup info_str formatting Mark McLoughlin
2009-01-06 15:00               ` [Qemu-devel] [PATCH 4/6] Add qemu_format_nic_info_str() Mark McLoughlin
2009-01-06 15:00                 ` [Qemu-devel] [PATCH 5/6] add missing MAC address to info_str for some NICs Mark McLoughlin
2009-01-06 15:00                   ` [Qemu-devel] [PATCH 6/6] Add a -net name=foo parameter Mark McLoughlin
2009-01-07 17:49           ` [Qemu-devel] Re: [PATCH 1/6] Add a model string to VLANClientState Anthony Liguori
2008-12-09 11:23 ` [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000 Daniel P. Berrange
2008-12-09 13:57   ` Dor Laor
2008-12-09 15:06 ` [Qemu-devel] " Anthony Liguori
2008-12-10  8:53   ` Avi Kivity

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.