Skip to contentSkip to conversation

Add nic link up/down emulation to e1000

PATCH In review Mark McLoughlin 6 participants 26 messages Dec 9, 2008 – Jan 7, 2009

lore
Share & tools
lore
#0 lore raw

cover Add nic link up/down emulation to e1000

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.

#1 lore raw

PATCH 1/4 Add 'set_link' monitor command

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

Allows simulation of network cable disconnect.

---
 monitor.c |    1 +
 net.c     |   41 ++++++++++++++++++++++++++++++++++++++++-
 net.h     |    2 ++
 3 files changed, 43 insertions(+), 1 deletions(-)
monitor.c +1 -0
index f142a87..ac74711 100644
@@ -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, },
 };
 
net.c +40 -1

58 lines not on this page · raw message

net.h +2 -0
index a2b01ae..e7cd062 100644
@@ -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 */
 
Signature · 1 line
1.5.4.3
#2 lore raw

PATCH 2/4 Add device index to 'info network' output

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

---
 net.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
net.c +2 -1
index 250519c..35ec501 100644
@@ -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);
     }
 }
 
Signature · 1 line
1.5.4.3
#3 lore raw

PATCH 3/4 Allow devices be notified of link status change

---
 net.c |    3 +++
 net.h |    3 +++
 2 files changed, 6 insertions(+), 0 deletions(-)
net.c +3 -0
index 35ec501..883544f 100644
@@ -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;
 }
 
net.h +3 -0
index e7cd062..75b22c1 100644
@@ -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;
Signature · 1 line
1.5.4.3
#4 lore raw

PATCH 4/4 Implement e1000 link status

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.

---
 hw/e1000.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
hw/e1000.c +16 -0
index f07936f..c541e36 100644
@@ -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,
Signature · 1 line
1.5.4.3
#5 lore raw

[Qemu-devel] Re: [PATCH 2/4] Add device index to 'info network' output

In reply to Mark McLoughlin
Quoted 12 lines · Mark McLoughlin

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

---
 net.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
net.c +0 -0
index 250519c..35ec501 100644

net.c void do_info_network(void) · line 1564

Quoted 9 lines
net.c +2 -1
@@ -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

Quoted 4 lines
net.c +0 -0
     }
 }
#6 lore raw

[Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command

In reply to Mark McLoughlin
Quoted 17 lines · Mark McLoughlin

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

Allows simulation of network cable disconnect.

---
 monitor.c |    1 +
 net.c     |   41 ++++++++++++++++++++++++++++++++++++++++-
 net.h     |    2 ++
 3 files changed, 43 insertions(+), 1 deletions(-)
monitor.c +0 -0
index f142a87..ac74711 100644

monitor.c static const term_cmd_t term_cmds[] = { · line 1503

Quoted 7 lines
monitor.c +1 -0
@@ -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.

monitor.c

Quoted 4 lines
monitor.c +3 -0
+    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

#7 lore raw

[Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command

Quoted 5 lines · Anthony Liguori

net.c void do_info_network(void) · line 1583

Quoted 4 lines
net.c +3 -0
+    for(vc = vlan->first_client; vc != NULL; vc = vc->next)
+        if (i++ == device_idx)
+            break;
Quoted 7 lines

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.

#8 lore raw

PATCH 1/5 Add a model string to VLANClientState

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().

---
 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(-)
hw/e1000.c +2 -2
index 67a062a..45706bb 100644
@@ -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,
hw/eepro100.c +2 -1
index cb3ca09..a7861ca 100644
@@ -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",
hw/etraxfs_eth.c +1 -1
index 51a129a..244a23d 100644
@@ -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;
hw/mcf_fec.c +2 -2
index 0049860..7e3afa5 100644
@@ -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);
 }
hw/mipsnet.c +2 -2
index af560f8..549e6f3 100644
@@ -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;
     }
hw/musicpal.c +2 -1
index c5a5b6f..d172a11 100644
@@ -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);
hw/ne2000.c +4 -4
index 3f0ccf5..dc97989 100644
@@ -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",
hw/pcnet.c +2 -2
index 30c453c..e961a06 100644
@@ -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",
hw/rtl8139.c +2 -2
index feffa9c..f3f6564 100644
@@ -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",
hw/smc91c111.c +2 -2
index a517033..fadd151 100644
@@ -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.  */
 }
hw/stellaris_enet.c +2 -2
index 09d92b1..bd8dcd9 100644
@@ -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,
hw/usb-net.c +1 -1
index 82005af..06ff668 100644
@@ -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),
net.c +43 -35

270 lines not on this page · raw message

net.h +2 -0
index a2b01ae..fcae0e2 100644
@@ -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);
sysemu.h +1 -1
index 94cffaf..8ce3900 100644
@@ -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);
tap-win32.c +2 -2
index 299b4b3..ee9e23f 100644
@@ -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);
Signature · 1 line
1.5.4.3
#9 lore raw

PATCH 2/5 Assign a name to each VLAN client

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.

---
 net.c |   21 +++++++++++++++++++++
 net.h |    1 +
 2 files changed, 22 insertions(+), 0 deletions(-)
net.c +21 -0
index d046b5e..fe7c648 100644
@@ -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;
net.h +1 -0
index fcae0e2..138cd23 100644
@@ -14,6 +14,7 @@ struct VLANClientState {
     struct VLANClientState *next;
     struct VLANState *vlan;
     char *model;
+    char *name;
     char info_str[256];
 };
 
Signature · 1 line
1.5.4.3
#10 lore raw

PATCH 3/5 Fixup info_str formatting

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.

---
 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(-)
hw/e1000.c +1 -1
index 45706bb..13fcc1c 100644
@@ -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]);
 
hw/eepro100.c +1 -1
index a7861ca..8ea283c 100644
@@ -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]);
hw/mipsnet.c +1 -1
index 549e6f3..8190738 100644
@@ -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],
hw/ne2000.c +2 -2
index dc97989..600cdc3 100644
@@ -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],
hw/pcnet.c +1 -1
index e961a06..90bf7fd 100644
@@ -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],
hw/rtl8139.c +1 -1
index f3f6564..b16c4cc 100644
@@ -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],
hw/usb-net.c +1 -1
index 06ff668..c80b048 100644
@@ -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",
net.c +8 -6
index fe7c648..100e335 100644
@@ -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);
             }
Signature · 1 line
1.5.4.3
#11 lore raw

PATCH 4/5 Add qemu_format_nic_info_str()

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

---
 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(-)
hw/e1000.c +1 -4
index 13fcc1c..9b4dbbd 100644
@@ -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);
 }
hw/eepro100.c +1 -5
index 8ea283c..86a4e6e 100644
@@ -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);
 
hw/mipsnet.c +1 -8
index 8190738..4b3e8e9 100644
@@ -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);
hw/ne2000.c +2 -16
index 600cdc3..ad97bc5 100644
@@ -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);
 }
hw/pcnet.c +1 -8
index 90bf7fd..5b45956 100644
@@ -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;
     }
hw/rtl8139.c +1 -8
index b16c4cc..4449fd2 100644
@@ -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;
hw/usb-net.c +2 -4
index c80b048..95ebac8 100644
@@ -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]);
net.c +8 -0
index 100e335..69f6546 100644
@@ -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;
net.h +1 -0
index 138cd23..244f80b 100644
@@ -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);
Signature · 1 line
1.5.4.3
#12 lore raw

PATCH 5/5 Add a -net name=foo parameter

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'.

---
 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(-)
hw/e1000.c +1 -1
index 9b4dbbd..7c8824d 100644
@@ -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);
hw/eepro100.c +1 -1
index 86a4e6e..5eca105 100644
@@ -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);
hw/etraxfs_eth.c +1 -1
index 244a23d..4bad3d2 100644
@@ -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;
hw/mcf_fec.c +1 -1
index 7e3afa5..bb9f68f 100644
@@ -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);
 }
hw/mipsnet.c +1 -1
index 4b3e8e9..0eb4c1e 100644
@@ -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;
hw/musicpal.c +1 -1
index d172a11..1c932ec 100644
@@ -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);
hw/ne2000.c +2 -2
index ad97bc5..200db90 100644
@@ -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);
hw/pcnet.c +1 -1
index 5b45956..102166e 100644
@@ -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);
hw/rtl8139.c +1 -1
index 4449fd2..5805795 100644
@@ -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);
hw/smc91c111.c +1 -1
index fadd151..2ee6701 100644
@@ -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.  */
 }
hw/usb-net.c +1 -1
index 95ebac8..947461c 100644
@@ -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);
net.c +64 -33

310 lines not on this page · raw message

net.h +2 -0
index 244f80b..bb4dce3 100644
@@ -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;
 };
 
qemu-doc.texi +8 -7
index 377e384..bb36fe7 100644
@@ -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
sysemu.h +2 -1
index 8ce3900..cac9a95 100644
@@ -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);
tap-win32.c +3 -2
index ee9e23f..da3283e 100644
@@ -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);
vl.c +7 -7
index c3a8d8f..bf7d78c 100644
@@ -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"
Signature · 1 line
1.5.4.3
#13 lore raw

Re: [Qemu-devel] [PATCH 5/5] Add a -net name=foo parameter

Quoted 6 lines · Mark McLoughlin

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'.

Quoted 12 lines
---
 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.

Quoted 670 lines
 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(-)
hw/e1000.c +1 -1
index 9b4dbbd..7c8824d 100644
@@ -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);
hw/eepro100.c +1 -1
index 86a4e6e..5eca105 100644
@@ -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);
hw/etraxfs_eth.c +1 -1
index 244a23d..4bad3d2 100644
@@ -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;
hw/mcf_fec.c +1 -1
index 7e3afa5..bb9f68f 100644
@@ -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);
 }
hw/mipsnet.c +1 -1
index 4b3e8e9..0eb4c1e 100644
@@ -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;
hw/musicpal.c +1 -1
index d172a11..1c932ec 100644
@@ -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);
hw/ne2000.c +2 -2
index ad97bc5..200db90 100644
@@ -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);
hw/pcnet.c +1 -1
index 5b45956..102166e 100644
@@ -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);
hw/rtl8139.c +1 -1
index 4449fd2..5805795 100644
@@ -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);
hw/smc91c111.c +1 -1
index fadd151..2ee6701 100644
@@ -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.  */
 }
hw/usb-net.c +1 -1
index 95ebac8..947461c 100644
@@ -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);
net.c +64 -33
index 69f6546..414affb 100644
@@ -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;
 }
 
net.h +2 -0
index 244f80b..bb4dce3 100644
@@ -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;
 };
 
qemu-doc.texi +8 -7
index 377e384..bb36fe7 100644
@@ -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
sysemu.h +2 -1
index 8ce3900..cac9a95 100644
@@ -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);
tap-win32.c +3 -2
index ee9e23f..da3283e 100644
@@ -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);
vl.c +7 -7
index c3a8d8f..bf7d78c 100644
@@ -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"
Signature · 1 line
1.5.4.3
Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net
#14 lore raw

Re: [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command

In reply to Mark McLoughlin

Hi Anthony,

Quoted 11 lines · Mark McLoughlin
Quoted 10 lines · Anthony Liguori

net.c void do_info_network(void) · line 1583

Quoted 4 lines
net.c +3 -0
+    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.

Quoted 6 lines
Quoted 2 lines

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.

#15 lore raw

PATCH 1/6 Add a model string to VLANClientState

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().

---
 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(-)
hw/e1000.c +2 -2
index 7ca0747..03c573b 100644
@@ -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,
hw/eepro100.c +2 -1
index cb3ca09..a7861ca 100644
@@ -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",
hw/etraxfs_eth.c +1 -1
index 51a129a..244a23d 100644
@@ -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;
hw/mcf_fec.c +2 -2
index 0049860..7e3afa5 100644
@@ -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);
 }
hw/mipsnet.c +2 -2
index af560f8..549e6f3 100644
@@ -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;
     }
hw/musicpal.c +2 -1
index c5a5b6f..d172a11 100644
@@ -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);
hw/ne2000.c +4 -4
index 3f0ccf5..dc97989 100644
@@ -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",
hw/pcnet.c +2 -2
index 30c453c..e961a06 100644
@@ -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",
hw/rtl8139.c +2 -2
index c3ab854..39f3209 100644
@@ -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",
hw/smc91c111.c +2 -2
index a517033..fadd151 100644
@@ -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.  */
 }
hw/stellaris_enet.c +2 -2
index 09d92b1..bd8dcd9 100644
@@ -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,
hw/usb-net.c +1 -1
index f16a0a5..40ee41b 100644
@@ -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),
hw/virtio-net.c +2 -2
index 1f45b2d..4500fab 100644
@@ -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;
net.c +43 -35

270 lines not on this page · raw message

net.h +2 -0
index 31c7a30..a2c6a50 100644
@@ -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);
sysemu.h +1 -1
index 6e24e8a..d27faa6 100644
@@ -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);
tap-win32.c +2 -2
index 02a945e..13ca539 100644
@@ -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);
Signature · 1 line
1.6.0.6
#16 lore raw

PATCH 2/6 Assign a name to each VLAN client

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.

---
 net.c |   21 +++++++++++++++++++++
 net.h |    1 +
 2 files changed, 22 insertions(+), 0 deletions(-)
net.c +21 -0
index f3c2b89..c268233 100644
@@ -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;
net.h +1 -0
index a2c6a50..078dd18 100644
@@ -19,6 +19,7 @@ struct VLANClientState {
     struct VLANClientState *next;
     struct VLANState *vlan;
     char *model;
+    char *name;
     char info_str[256];
 };
 
Signature · 1 line
1.6.0.6
#17 lore raw

PATCH 3/6 Fixup info_str formatting

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.

---
 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(-)
hw/e1000.c +1 -1
index 03c573b..996260c 100644
@@ -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]);
 
hw/eepro100.c +1 -1
index a7861ca..8ea283c 100644
@@ -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]);
hw/mipsnet.c +1 -1
index 549e6f3..8190738 100644
@@ -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],
hw/ne2000.c +2 -2
index dc97989..600cdc3 100644
@@ -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],
hw/pcnet.c +1 -1
index e961a06..90bf7fd 100644
@@ -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],
hw/rtl8139.c +1 -1
index 39f3209..1853ab3 100644
@@ -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],
hw/usb-net.c +1 -1
index 40ee41b..1622ef8 100644
@@ -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",
net.c +8 -6
index c268233..db69c7f 100644
@@ -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);
             }
Signature · 1 line
1.6.0.6
#18 lore raw

PATCH 4/6 Add qemu_format_nic_info_str()

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

---
 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(-)
hw/e1000.c +1 -4
index 996260c..5b0b731 100644
@@ -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);
 }
hw/eepro100.c +1 -5
index 8ea283c..86a4e6e 100644
@@ -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);
 
hw/mipsnet.c +1 -8
index 8190738..4b3e8e9 100644
@@ -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);
hw/ne2000.c +2 -16
index 600cdc3..ad97bc5 100644
@@ -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);
 }
hw/pcnet.c +1 -8
index 90bf7fd..5b45956 100644
@@ -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;
     }
hw/rtl8139.c +1 -8
index 1853ab3..d517220 100644
@@ -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;
hw/usb-net.c +2 -4
index 1622ef8..5539336 100644
@@ -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]);
net.c +8 -0
index db69c7f..e293790 100644
@@ -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;
net.h +1 -0
index 078dd18..904519a 100644
@@ -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);
Signature · 1 line
1.6.0.6
#19 lore raw

PATCH 5/6 add missing MAC address to info_str for some NICs

---
 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(-)
hw/mcf_fec.c +1 -0
index 7e3afa5..6c044cd 100644
@@ -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);
 }
hw/smc91c111.c +1 -0
index fadd151..6416026 100644
@@ -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.  */
 }
hw/stellaris_enet.c +3 -1
index bd8dcd9..69fb85d 100644
@@ -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,
hw/virtio-net.c +2 -0
index 4500fab..b197c70 100644
@@ -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;
Signature · 1 line
1.6.0.6
#20 lore raw

PATCH 6/6 Add a -net name=foo parameter

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'.

---
 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(-)
hw/e1000.c +1 -1
index 5b0b731..09cb96a 100644
@@ -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);
hw/eepro100.c +1 -1
index 86a4e6e..5eca105 100644
@@ -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);
hw/etraxfs_eth.c +1 -1
index 244a23d..4bad3d2 100644
@@ -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;
hw/mcf_fec.c +1 -1
index 6c044cd..d39992f 100644
@@ -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);
hw/mipsnet.c +1 -1
index 4b3e8e9..0eb4c1e 100644
@@ -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;
hw/musicpal.c +1 -1
index d172a11..1c932ec 100644
@@ -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);
hw/ne2000.c +2 -2
index ad97bc5..200db90 100644
@@ -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);
hw/pcnet.c +1 -1
index 5b45956..102166e 100644
@@ -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);
hw/rtl8139.c +1 -1
index d517220..8be63c5 100644
@@ -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);
hw/smc91c111.c +1 -1
index 6416026..27a3158 100644
@@ -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.  */
hw/stellaris_enet.c +1 -1
index 69fb85d..a5cd163 100644
@@ -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);
     }
hw/usb-net.c +1 -1
index 5539336..c49fd62 100644
@@ -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);
hw/virtio-net.c +1 -1
index b197c70..4443ff5 100644
@@ -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);
net.c +64 -33

310 lines not on this page · raw message

net.h +2 -0
index 904519a..b89d165 100644
@@ -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;
 };
 
qemu-doc.texi +8 -7
index 0f1e7cc..a145b19 100644
@@ -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
sysemu.h +2 -1
index d27faa6..cd0f912 100644
@@ -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);
tap-win32.c +3 -2
index 13ca539..3279644 100644
@@ -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);
vl.c +7 -7
index 07740f5..2e54553 100644
@@ -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"
Signature · 1 line
1.6.0.6
#21 lore raw

[Qemu-devel] Re: [PATCH 1/6] Add a model string to VLANClientState

In reply to Mark McLoughlin
Quoted 8 lines · Mark McLoughlin

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().

Applied the whole series. Thanks.

Really nice series too.

Regards,

Anthony Liguori

#22 lore raw
In reply to Mark McLoughlin
Quoted 5 lines · Mark McLoughlin

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

Signature · 4 lines
|: 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 :|
#23 lore raw
Quoted 17 lines · Daniel P. Berrange
Quoted 6 lines · Mark McLoughlin

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.

Quoted 2 lines

Daniel

Indeed.
Besides that its also good for windows virtio network certification. MS has a test that needs to play with the link status.

#24 lore raw
In reply to Mark McLoughlin
Quoted 11 lines · Mark McLoughlin

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

Quoted 5 lines

Thanks,
Mark.

#25 lore raw
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Mark McLoughlin

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.

Quoted 7 lines
Quoted 5 lines

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.

Signature · 1 line
error compiling committee.c: too many arguments to function