qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Mark McLoughlin <markmc@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Mark McLoughlin <markmc@redhat.com>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 4/5] Add qemu_format_nic_info_str()
Date: Fri, 12 Dec 2008 14:46:30 +0000	[thread overview]
Message-ID: <1229093191-20618-4-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1229093191-20618-3-git-send-email-markmc@redhat.com>

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

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

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

  reply	other threads:[~2008-12-12 14:48 UTC|newest]

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

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=1229093191-20618-4-git-send-email-markmc@redhat.com \
    --to=markmc@redhat.com \
    --cc=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).