qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [6218] Add qemu_format_nic_info_str() (Mark McLoughlin)
Date: Wed, 07 Jan 2009 17:46:21 +0000	[thread overview]
Message-ID: <E1LKcU1-0007f1-NI@cvs.savannah.gnu.org> (raw)

Revision: 6218
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6218
Author:   aliguori
Date:     2009-01-07 17:46:21 +0000 (Wed, 07 Jan 2009)

Log Message:
-----------
Add qemu_format_nic_info_str() (Mark McLoughlin)

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

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Modified Paths:
--------------
    trunk/hw/e1000.c
    trunk/hw/eepro100.c
    trunk/hw/mipsnet.c
    trunk/hw/ne2000.c
    trunk/hw/pcnet.c
    trunk/hw/rtl8139.c
    trunk/hw/usb-net.c
    trunk/net.c
    trunk/net.h

Modified: trunk/hw/e1000.c
===================================================================
--- trunk/hw/e1000.c	2009-01-07 17:43:44 UTC (rev 6217)
+++ trunk/hw/e1000.c	2009-01-07 17:46:21 UTC (rev 6218)
@@ -1074,10 +1074,7 @@
     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,
-             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);
 }

Modified: trunk/hw/eepro100.c
===================================================================
--- trunk/hw/eepro100.c	2009-01-07 17:43:44 UTC (rev 6217)
+++ trunk/hw/eepro100.c	2009-01-07 17:46:21 UTC (rev 6218)
@@ -1779,11 +1779,7 @@
     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",
-             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);
 

Modified: trunk/hw/mipsnet.c
===================================================================
--- trunk/hw/mipsnet.c	2009-01-07 17:43:44 UTC (rev 6217)
+++ trunk/hw/mipsnet.c	2009-01-07 17:46:21 UTC (rev 6218)
@@ -256,14 +256,7 @@
         s->vc = NULL;
     }
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "mipsnet 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);

Modified: trunk/hw/ne2000.c
===================================================================
--- trunk/hw/ne2000.c	2009-01-07 17:43:44 UTC (rev 6217)
+++ trunk/hw/ne2000.c	2009-01-07 17:46:21 UTC (rev 6218)
@@ -744,14 +744,7 @@
     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",
-             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 @@
     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",
-             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);
 }

Modified: trunk/hw/pcnet.c
===================================================================
--- trunk/hw/pcnet.c	2009-01-07 17:43:44 UTC (rev 6217)
+++ trunk/hw/pcnet.c	2009-01-07 17:46:21 UTC (rev 6218)
@@ -1939,14 +1939,7 @@
         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",
-                 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;
     }

Modified: trunk/hw/rtl8139.c
===================================================================
--- trunk/hw/rtl8139.c	2009-01-07 17:43:44 UTC (rev 6217)
+++ trunk/hw/rtl8139.c	2009-01-07 17:46:21 UTC (rev 6218)
@@ -3441,14 +3441,7 @@
     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",
-             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;

Modified: trunk/hw/usb-net.c
===================================================================
--- trunk/hw/usb-net.c	2009-01-07 17:43:44 UTC (rev 6217)
+++ trunk/hw/usb-net.c	2009-01-07 17:46:21 UTC (rev 6218)
@@ -1456,14 +1456,12 @@
     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),
-                    "usbnet 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]);

Modified: trunk/net.c
===================================================================
--- trunk/net.c	2009-01-07 17:43:44 UTC (rev 6217)
+++ trunk/net.c	2009-01-07 17:46:21 UTC (rev 6218)
@@ -296,6 +296,14 @@
 }
 #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;
@@ -474,7 +482,7 @@
     }
     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 +707,7 @@
     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 +962,8 @@
     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 +1025,7 @@
     }
     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 +1648,7 @@
     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 +1666,8 @@
                 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);
             }

Modified: trunk/net.h
===================================================================
--- trunk/net.h	2009-01-07 17:43:44 UTC (rev 6217)
+++ trunk/net.h	2009-01-07 17:46:21 UTC (rev 6218)
@@ -41,6 +41,7 @@
 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);

                 reply	other threads:[~2009-01-07 17:46 UTC|newest]

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

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=E1LKcU1-0007f1-NI@cvs.savannah.gnu.org \
    --to=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

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

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