Skip to contentSkip to conversation

net: convert NetClientState to QOM

PATCH New Stefan Hajnoczi 1 participant 5 messages Jul 2, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover net: convert NetClientState to QOM

Note: These patches apply on top of Zhi Yong Wu's vlan-hub v6 and -netdev socket v2 series.

This series is the first step in QOMifying the net subsystem. These patches make NetClientState an Object so that all -netdev and NICs use QOM. The net clients are not yet visible in the QOM tree and have no properties.

I wanted to send this out before I go on vacation 3 - 11 July since others are making changes in the net subsystem and this could conflict.

Future patch series will focus on:
1. QOM lifecycle for NetClientState, including dealing with hotplug.
2. QOM properties for each -netdev type.
3. Exposing net clients in the QOM tree.
4. Replacing ad-hoc code with QOM usage.

Stefan Hajnoczi (4):
net: add public qemu_net_poll() function
net: add net_is_tap_client()
net: extract notify_link_status_changed() function
net: convert NetClientState to QOM

 hw/cadence_gem.c        |   27 +++++++---
 hw/dp8393x.c            |   41 ++++++++++----
 hw/e1000.c              |   32 +++++++----
 hw/eepro100.c           |   27 +++++++---
 hw/etraxfs_eth.c        |   27 +++++++---
 hw/lan9118.c            |   27 +++++++---
 hw/lance.c              |   18 +------
 hw/mcf_fec.c            |   32 ++++++++---
 hw/milkymist-minimac2.c |   26 ++++++---
 hw/mipsnet.c            |   25 ++++++---
 hw/musicpal.c           |   26 ++++++---
 hw/ne2000-isa.c         |   17 +-----
 hw/ne2000.c             |   23 +++++---
 hw/ne2000.h             |    2 +
 hw/opencores_eth.c      |   28 +++++++---
 hw/pcnet-pci.c          |   18 +------
 hw/pcnet.c              |   36 +++++++++++--
 hw/pcnet.h              |    3 +-
 hw/rtl8139.c            |   26 ++++++---
 hw/smc91c111.c          |   26 ++++++---
 hw/spapr_llan.c         |   24 ++++++---
 hw/stellaris_enet.c     |   26 ++++++---
 hw/usb/dev-network.c    |   25 ++++++---
 hw/vhost_net.c          |   11 ++--
 hw/virtio-net.c         |   43 ++++++++++-----
 hw/xen_nic.c            |   29 +++++++---
 hw/xgmac.c              |   26 ++++++---
 hw/xilinx_axienet.c     |   26 ++++++---
 hw/xilinx_ethlite.c     |   26 ++++++---
 net.c                   |  138 ++++++++++++++++++++++++++++++++---------------
 net.h                   |   35 ++++++++----
 net/dump.c              |   30 ++++++++---
 net/hub.c               |   51 +++++++++++-------
 net/slirp.c             |   29 +++++++---
 net/socket.c            |   80 +++++++++++++++------------
 net/tap-win32.c         |   29 ++++++++--
 net/tap.c               |   83 ++++++++++++++++------------
 net/tap.h               |    1 +
 net/vde.c               |   28 ++++++++--
 39 files changed, 841 insertions(+), 386 deletions(-)
Signature · 1 line
1.7.10
#1 lore raw

PATCH 1/4 net: add public qemu_net_poll() function

The NetClientInfo .poll() callback is being called directly by hw/vhost_net.c. Create a public net.c function so callers do not depend on internals.

This change is useful because later patches change net internals. Those changes shouldn't affect .poll() callers.

---
 hw/vhost_net.c |    6 +++---
 net.c          |    7 +++++++
 net.h          |    2 ++
 3 files changed, 12 insertions(+), 3 deletions(-)
hw/vhost_net.c +3 -3
index c2d90df..ac3e616 100644
@@ -160,7 +160,7 @@ int vhost_net_start(struct vhost_net *net,
         goto fail_start;
     }
 
-    net->nc->info->poll(net->nc, false);
+    qemu_net_poll(net->nc, false);
     qemu_set_fd_handler(net->backend, NULL, NULL, NULL);
     file.fd = net->backend;
     for (file.index = 0; file.index < net->dev.nvqs; ++file.index) {
@@ -177,7 +177,7 @@ fail:
         int r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file);
         assert(r >= 0);
     }
-    net->nc->info->poll(net->nc, true);
+    qemu_net_poll(net->nc, true);
     vhost_dev_stop(&net->dev, dev);
     if (net->dev.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) {
         tap_set_vnet_hdr_len(net->nc, sizeof(struct virtio_net_hdr));
@@ -197,7 +197,7 @@ void vhost_net_stop(struct vhost_net *net,
         int r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file);
         assert(r >= 0);
     }
-    net->nc->info->poll(net->nc, true);
+    qemu_net_poll(net->nc, true);
     vhost_dev_stop(&net->dev, dev);
     if (net->dev.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) {
         tap_set_vnet_hdr_len(net->nc, sizeof(struct virtio_net_hdr));
net.c +7 -0
index 6bbc9fc..5e4957f 100644
@@ -450,6 +450,13 @@ qemu_sendv_packet(NetClientState *nc, const struct iovec *iov, int iovcnt)
     return qemu_sendv_packet_async(nc, iov, iovcnt, NULL);
 }
 
+void qemu_net_poll(NetClientState *nc, bool enable)
+{
+    if (nc->info->poll) {
+        nc->info->poll(nc, enable);
+    }
+}
+
 NetClientState *qemu_find_netdev(const char *id)
 {
     NetClientState *nc;
net.h +2 -0
index 0256ff9..64d5d0e 100644
@@ -124,6 +124,8 @@ ssize_t qemu_deliver_packet_iov(NetClientState *sender,
                             int iovcnt,
                             void *opaque);
 
+void qemu_net_poll(NetClientState *nc, bool enable);
+
 void print_net_client(Monitor *mon, NetClientState *vc);
 void do_info_network(Monitor *mon);
 
Signature · 1 line
1.7.10
#2 lore raw

PATCH 2/4 net: add net_is_tap_client()

In reply to Stefan Hajnoczi

The vhost-net code interacts closely with the net/tap.c backend so that it can pass the underlying file descriptor to the vhost_net.ko driver. We need a check that confirms a NetClientState is indeed a tap backend (and not something else like slirp or socket).

Formalize this in the new net_is_tap_client() function. This way callers do not reach inside net internals to check the type.

Note that I've added this function to net/tap.c but named it net_is_tap_client(). Ideally it should be in net.c but I want to keep the code where the tap net client is defined.

---
 hw/vhost_net.c  |    5 ++---
 hw/virtio-net.c |    9 +++++----
 net/tap.c       |    5 +++++
 net/tap.h       |    1 +
 4 files changed, 13 insertions(+), 7 deletions(-)
hw/vhost_net.c +2 -3
index ac3e616..47710ee 100644
@@ -82,10 +82,9 @@ void vhost_net_ack_features(struct vhost_net *net, unsigned features)
 
 static int vhost_net_get_fd(NetClientState *backend)
 {
-    switch (backend->info->type) {
-    case NET_CLIENT_TYPE_TAP:
+    if (net_is_tap_client(backend)) {
         return tap_get_fd(backend);
-    default:
+    } else {
         fprintf(stderr, "vhost-net requires tap backend\n");
         return -EBADFD;
     }
hw/virtio-net.c +5 -4
index d5527d4..1575879 100644
@@ -108,7 +108,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
     if (!n->nic->nc.peer) {
         return;
     }
-    if (n->nic->nc.peer->info->type != NET_CLIENT_TYPE_TAP) {
+    if (!net_is_tap_client(n->nic->nc.peer)) {
         return;
     }
 
@@ -205,8 +205,9 @@ static int peer_has_vnet_hdr(VirtIONet *n)
     if (!n->nic->nc.peer)
         return 0;
 
-    if (n->nic->nc.peer->info->type != NET_CLIENT_TYPE_TAP)
+    if (!net_is_tap_client(n->nic->nc.peer)) {
         return 0;
+    }
 
     n->has_vnet_hdr = tap_has_vnet_hdr(n->nic->nc.peer);
 
@@ -249,7 +250,7 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev, uint32_t features)
     }
 
     if (!n->nic->nc.peer ||
-        n->nic->nc.peer->info->type != NET_CLIENT_TYPE_TAP) {
+        !net_is_tap_client(n->nic->nc.peer)) {
         return features;
     }
     if (!tap_get_vhost_net(n->nic->nc.peer)) {
@@ -288,7 +289,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
                         (features >> VIRTIO_NET_F_GUEST_UFO)  & 1);
     }
     if (!n->nic->nc.peer ||
-        n->nic->nc.peer->info->type != NET_CLIENT_TYPE_TAP) {
+        !net_is_tap_client(n->nic->nc.peer)) {
         return;
     }
     if (!tap_get_vhost_net(n->nic->nc.peer)) {
net/tap.c +5 -0
index 20ce3ff..d5bdfa0 100644
@@ -303,6 +303,11 @@ static void tap_poll(NetClientState *nc, bool enable)
     tap_write_poll(s, enable);
 }
 
+bool net_is_tap_client(NetClientState *nc)
+{
+    return nc->info->type == NET_CLIENT_TYPE_TAP;
+}
+
 int tap_get_fd(NetClientState *nc)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
net/tap.h +1 -0
index 2966d81..9a341bf 100644
@@ -52,6 +52,7 @@ int tap_probe_has_ufo(int fd);
 void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo);
 void tap_fd_set_vnet_hdr_len(int fd, int len);
 
+bool net_is_tap_client(NetClientState *nc);
 int tap_get_fd(NetClientState *nc);
 
 struct vhost_net;
Signature · 1 line
1.7.10
#3 lore raw

PATCH 3/4 net: extract notify_link_status_changed() function

In reply to Stefan Hajnoczi

The code to invoke the NetClientInfo .link_status_changed() callback is duplicated in several places. Create a single notify_link_status_changed() function and avoid duplication.

This is useful because later patches change net internals. By having a single function it is easier to make changes without affecting callers.

---
 net.c |   19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
net.c +11 -8
index 5e4957f..8c27ff2 100644
@@ -153,6 +153,13 @@ void qemu_macaddr_default_if_unset(MACAddr *macaddr)
     macaddr->a[5] = 0x56 + index++;
 }
 
+static void notify_link_status_changed(NetClientState *nc)
+{
+    if (nc->info->link_status_changed) {
+        nc->info->link_status_changed(nc);
+    }
+}
+
 /**
  * Generate a name for net client
  *
@@ -266,9 +273,7 @@ void qemu_del_net_client(NetClientState *nc)
         nic->peer_deleted = true;
         /* Let NIC know peer is gone. */
         nc->peer->link_down = true;
-        if (nc->peer->info->link_status_changed) {
-            nc->peer->info->link_status_changed(nc->peer);
-        }
+        notify_link_status_changed(nc->peer);
         qemu_cleanup_net_client(nc);
         return;
     }
@@ -1129,9 +1134,7 @@ done:
 
     nc->link_down = !up;
 
-    if (nc->info->link_status_changed) {
-        nc->info->link_status_changed(nc);
-    }
+    notify_link_status_changed(nc);
 
     /* Notify peer. Don't update peer link status: this makes it possible to
      * disconnect from host network without notifying the guest.
@@ -1140,8 +1143,8 @@ done:
      * Current behaviour is compatible with qemu vlans where there could be
      * multiple clients that can still communicate with each other in
      * disconnected mode. For now maintain this compatibility. */
-    if (nc->peer && nc->peer->info->link_status_changed) {
-        nc->peer->info->link_status_changed(nc->peer);
+    if (nc->peer) {
+        notify_link_status_changed(nc->peer);
     }
 }
 
Signature · 1 line
1.7.10
#4 lore raw

PATCH 4/4 net: convert NetClientState to QOM

In reply to Stefan Hajnoczi

This patch makes all net clients QOM objects. This is the first step to converting the net subsystem to the QEMU Object Model. At this point net clients are not yet visible in the QOM tree and there are many simplifications that can still be made to drop ad-hoc code in favor of QOM.

The major changes are:

1. NetClientInfo becomes NetClientClass. The "virtual functions" (aka callbacks) for net clients are defined here and overridden by NetClient child classes.

2. NetClientState becomes a QOM object. I have not renamed it to NetClient yet because that would add too much noise, see later patches.

3. NICState becomes a QOM object with NetClient as its base class. In other words, a NIC is-a net client. NICState will also be renamed in later patches but doing so now would be too noisy.

All net backends in net/ and NICs in hw/ must be converted to NetClient subclasses. This makes up the bulk of this patch and was done automatically using a script. Unfortunately there is no clean way to split these changes into separate patches.

The net_client_type enum has been mostly dropped. For now users have been replaced with object_dynamic_cast() to test the type of an object. The cleaner solution in later patches is to design polymorphic interfaces instead of sprinkling code that tests the specific type of an object throughout the net subsystem.

Note that extrafx_eth.c uses tabs and checkpatch.pl will complain. The rest of the hunks are clean.

---
 hw/cadence_gem.c        |   27 +++++++----
 hw/dp8393x.c            |   41 ++++++++++++----
 hw/e1000.c              |   32 +++++++++----
 hw/eepro100.c           |   27 ++++++++---
 hw/etraxfs_eth.c        |   27 +++++++----
 hw/lan9118.c            |   27 +++++++----
 hw/lance.c              |   18 +------
 hw/mcf_fec.c            |   32 ++++++++++---
 hw/milkymist-minimac2.c |   26 +++++++---
 hw/mipsnet.c            |   25 +++++++---
 hw/musicpal.c           |   26 +++++++---
 hw/ne2000-isa.c         |   17 +------
 hw/ne2000.c             |   23 ++++++---
 hw/ne2000.h             |    2 +
 hw/opencores_eth.c      |   28 +++++++----
 hw/pcnet-pci.c          |   18 +------
 hw/pcnet.c              |   36 ++++++++++++--
 hw/pcnet.h              |    3 +-
 hw/rtl8139.c            |   26 +++++++---
 hw/smc91c111.c          |   26 +++++++---
 hw/spapr_llan.c         |   24 +++++++---
 hw/stellaris_enet.c     |   26 +++++++---
 hw/usb/dev-network.c    |   25 +++++++---
 hw/virtio-net.c         |   34 ++++++++++----
 hw/xen_nic.c            |   29 +++++++++---
 hw/xgmac.c              |   26 +++++++---
 hw/xilinx_axienet.c     |   26 +++++++---
 hw/xilinx_ethlite.c     |   26 +++++++---
 net.c                   |  120 ++++++++++++++++++++++++++++++++---------------
 net.h                   |   33 +++++++++----
 net/dump.c              |   30 +++++++++---
 net/hub.c               |   51 ++++++++++++--------
 net/slirp.c             |   29 +++++++++---
 net/socket.c            |   80 ++++++++++++++++++-------------
 net/tap-win32.c         |   29 ++++++++++--
 net/tap.c               |   80 +++++++++++++++++--------------
 net/vde.c               |   28 +++++++++--
 37 files changed, 810 insertions(+), 373 deletions(-)
hw/cadence_gem.c +19 -8
index 2245013..34b8bb2 100644
@@ -1160,13 +1160,23 @@ static void gem_set_link(NetClientState *nc)
     phy_update_link(DO_UPCAST(NICState, nc, nc)->opaque);
 }
 
-static NetClientInfo net_gem_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = gem_can_receive,
-    .receive = gem_receive,
-    .cleanup = gem_cleanup,
-    .link_status_changed = gem_set_link,
+#define TYPE_GEM_NET_CLIENT "gem-net-client"
+
+static void gem_net_client_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = gem_can_receive;
+    ncc->receive = gem_receive;
+    ncc->cleanup = gem_cleanup;
+    ncc->link_status_changed = gem_set_link;
+}
+
+static TypeInfo gem_net_client_info = {
+    .name = TYPE_GEM_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = gem_net_client_class_init,
 };
 
 static int gem_init(SysBusDevice *dev)
@@ -1182,7 +1192,7 @@ static int gem_init(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
-    s->nic = qemu_new_nic(&net_gem_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_GEM_NET_CLIENT, &s->conf,
             object_get_typename(OBJECT(dev)), dev->qdev.id, s);
 
     return 0;
@@ -1228,6 +1238,7 @@ static TypeInfo gem_info = {
 static void gem_register_types(void)
 {
     type_register_static(&gem_info);
+    type_register_static(&gem_net_client_info);
 }
 
 type_init(gem_register_types)
hw/dp8393x.c +32 -9

69 lines not on this page · raw message

hw/e1000.c +23 -9
index cf1e124..f729305 100644
@@ -144,6 +144,9 @@ enum {
     defreg(VET),
 };
 
+static ssize_t e1000_receive(NetClientState *nc, const uint8_t *buf,
+                             size_t size);
+
 static void
 e1000_link_down(E1000State *s)
 {
@@ -446,7 +449,7 @@ static void
 e1000_send_packet(E1000State *s, const uint8_t *buf, int size)
 {
     if (s->phy_reg[PHY_CTRL] & MII_CR_LOOPBACK) {
-        s->nic->nc.info->receive(&s->nic->nc, buf, size);
+        e1000_receive(&s->nic->nc, buf, size);
     } else {
         qemu_send_packet(&s->nic->nc, buf, size);
     }
@@ -1205,13 +1208,23 @@ pci_e1000_uninit(PCIDevice *dev)
     return 0;
 }
 
-static NetClientInfo net_e1000_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = e1000_can_receive,
-    .receive = e1000_receive,
-    .cleanup = e1000_cleanup,
-    .link_status_changed = e1000_set_link_status,
+#define TYPE_E1000_NET_CLIENT "e1000-net-client"
+
+static void e1000_net_client_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = e1000_can_receive;
+    ncc->receive = e1000_receive;
+    ncc->cleanup = e1000_cleanup;
+    ncc->link_status_changed = e1000_set_link_status;
+}
+
+static TypeInfo e1000_net_client_info = {
+    .name = TYPE_E1000_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = e1000_net_client_class_init,
 };
 
 static int pci_e1000_init(PCIDevice *pci_dev)
@@ -1246,7 +1259,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)
     checksum = (uint16_t) EEPROM_SUM - checksum;
     d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
 
-    d->nic = qemu_new_nic(&net_e1000_info, &d->conf,
+    d->nic = qemu_new_nic(TYPE_E1000_NET_CLIENT, &d->conf,
                           object_get_typename(OBJECT(d)), d->dev.qdev.id, d);
 
     qemu_format_nic_info_str(&d->nic->nc, macaddr);
@@ -1297,6 +1310,7 @@ static TypeInfo e1000_info = {
 static void e1000_register_types(void)
 {
     type_register_static(&e1000_info);
+    type_register_static(&e1000_net_client_info);
 }
 
 type_init(e1000_register_types)
hw/eepro100.c +20 -7
index 0217795..8ee15d3 100644
@@ -1844,12 +1844,23 @@ static int pci_nic_uninit(PCIDevice *pci_dev)
     return 0;
 }
 
-static NetClientInfo net_eepro100_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = nic_can_receive,
-    .receive = nic_receive,
-    .cleanup = nic_cleanup,
+#define TYPE_EEPRO100_NET_CLIENT "eepro100-net-client"
+
+static void eepro100_net_client_class_init(ObjectClass *klass,
+                                           void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = nic_can_receive;
+    ncc->receive = nic_receive;
+    ncc->cleanup = nic_cleanup;
+}
+
+static TypeInfo eepro100_net_client_info = {
+    .name = TYPE_EEPRO100_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = eepro100_net_client_class_init,
 };
 
 static int e100_nic_init(PCIDevice *pci_dev)
@@ -1884,7 +1895,7 @@ static int e100_nic_init(PCIDevice *pci_dev)
 
     nic_reset(s);
 
-    s->nic = qemu_new_nic(&net_eepro100_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_EEPRO100_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(pci_dev)), pci_dev->qdev.id, s);
 
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
@@ -2102,6 +2113,8 @@ static void eepro100_register_types(void)
         
         type_register(&type_info);
     }
+
+    type_register_static(&eepro100_net_client_info);
 }
 
 type_init(eepro100_register_types)
hw/etraxfs_eth.c +19 -8
index 1ca5849..5470642 100644
@@ -578,13 +578,23 @@ static void eth_cleanup(NetClientState *nc)
         g_free(eth);
 }
 
-static NetClientInfo net_etraxfs_info = {
-	.type = NET_CLIENT_TYPE_NIC,
-	.size = sizeof(NICState),
-	.can_receive = eth_can_receive,
-	.receive = eth_receive,
-	.cleanup = eth_cleanup,
-	.link_status_changed = eth_set_link,
+#define TYPE_ETRAXFS_NET_CLIENT "etraxfs-net-client"
+
+static void etraxfs_net_client_class_init(ObjectClass *klass, void *class_data)
+{
+	NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+	ncc->can_receive = eth_can_receive;
+	ncc->receive = eth_receive;
+	ncc->cleanup = eth_cleanup;
+	ncc->link_status_changed = eth_set_link;
+}
+
+static TypeInfo etraxfs_net_client_info = {
+	.name = TYPE_ETRAXFS_NET_CLIENT,
+	.parent = TYPE_NIC_NET_CLIENT,
+	.instance_size = sizeof(NICState),
+	.class_init = etraxfs_net_client_class_init,
 };
 
 static int fs_eth_init(SysBusDevice *dev)
@@ -604,7 +614,7 @@ static int fs_eth_init(SysBusDevice *dev)
 	sysbus_init_mmio(dev, &s->mmio);
 
 	qemu_macaddr_default_if_unset(&s->conf.macaddr);
-	s->nic = qemu_new_nic(&net_etraxfs_info, &s->conf,
+	s->nic = qemu_new_nic(TYPE_ETRAXFS_NET_CLIENT, &s->conf,
 			      object_get_typename(OBJECT(s)), dev->qdev.id, s);
 	qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
@@ -640,6 +650,7 @@ static TypeInfo etraxfs_eth_info = {
 static void etraxfs_eth_register_types(void)
 {
     type_register_static(&etraxfs_eth_info);
+    type_register_static(&etraxfs_net_client_info);
 }
 
 type_init(etraxfs_eth_register_types)
hw/lan9118.c +19 -8
index 6a37895..b891675 100644
@@ -1309,13 +1309,23 @@ static void lan9118_cleanup(NetClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_lan9118_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = lan9118_can_receive,
-    .receive = lan9118_receive,
-    .cleanup = lan9118_cleanup,
-    .link_status_changed = lan9118_set_link,
+#define TYPE_LAN9118_NET_CLIENT "lan9118-net-client"
+
+static void lan9118_net_client_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = lan9118_can_receive;
+    ncc->receive = lan9118_receive;
+    ncc->cleanup = lan9118_cleanup;
+    ncc->link_status_changed = lan9118_set_link;
+}
+
+static TypeInfo lan9118_net_client_info = {
+    .name = TYPE_LAN9118_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = lan9118_net_client_class_init,
 };
 
 static int lan9118_init1(SysBusDevice *dev)
@@ -1331,7 +1341,7 @@ static int lan9118_init1(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
-    s->nic = qemu_new_nic(&net_lan9118_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_LAN9118_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     s->eeprom[0] = 0xa5;
@@ -1376,6 +1386,7 @@ static TypeInfo lan9118_info = {
 static void lan9118_register_types(void)
 {
     type_register_static(&lan9118_info);
+    type_register_static(&lan9118_net_client_info);
 }
 
 /* Legacy helper function.  Should go away when machine config files are
hw/lance.c +1 -17
index 1aedb19..25daca7 100644
@@ -85,22 +85,6 @@ static const MemoryRegionOps lance_mem_ops = {
     },
 };
 
-static void lance_cleanup(NetClientState *nc)
-{
-    PCNetState *d = DO_UPCAST(NICState, nc, nc)->opaque;
-
-    pcnet_common_cleanup(d);
-}
-
-static NetClientInfo net_lance_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = pcnet_can_receive,
-    .receive = pcnet_receive,
-    .link_status_changed = pcnet_set_link_status,
-    .cleanup = lance_cleanup,
-};
-
 static const VMStateDescription vmstate_lance = {
     .name = "pcnet",
     .version_id = 3,
@@ -127,7 +111,7 @@ static int lance_init(SysBusDevice *dev)
 
     s->phys_mem_read = ledma_memory_read;
     s->phys_mem_write = ledma_memory_write;
-    return pcnet_common_init(&dev->qdev, s, &net_lance_info);
+    return pcnet_common_init(&dev->qdev, s);
 }
 
 static void lance_reset(DeviceState *dev)
hw/mcf_fec.c +25 -7
index 2730178..2957805 100644
@@ -449,12 +449,22 @@ static void mcf_fec_cleanup(NetClientState *nc)
     g_free(s);
 }
 
-static NetClientInfo net_mcf_fec_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = mcf_fec_can_receive,
-    .receive = mcf_fec_receive,
-    .cleanup = mcf_fec_cleanup,
+#define TYPE_MCF_FEC_NET_CLIENT "mcf-fec-net-client"
+
+static void mcf_fec_net_client_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = mcf_fec_can_receive;
+    ncc->receive = mcf_fec_receive;
+    ncc->cleanup = mcf_fec_cleanup;
+}
+
+static TypeInfo mcf_fec_net_client_info = {
+    .name = TYPE_MCF_FEC_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = mcf_fec_net_client_class_init,
 };
 
 void mcf_fec_init(MemoryRegion *sysmem, NICInfo *nd,
@@ -474,7 +484,15 @@ void mcf_fec_init(MemoryRegion *sysmem, NICInfo *nd,
     s->conf.macaddr = nd->macaddr;
     s->conf.peer = nd->netdev;
 
-    s->nic = qemu_new_nic(&net_mcf_fec_info, &s->conf, nd->model, nd->name, s);
+    s->nic = qemu_new_nic(TYPE_MCF_FEC_NET_CLIENT, &s->conf, nd->model,
+                          nd->name, s);
 
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 }
+
+static void mcf_fec_register_types(void)
+{
+    type_register_static(&mcf_fec_net_client_info);
+}
+
+type_init(mcf_fec_register_types)
hw/milkymist-minimac2.c +19 -7
index 0369894..3c80c35 100644
@@ -447,12 +447,23 @@ static void milkymist_minimac2_reset(DeviceState *d)
     s->phy_regs[R_PHY_ID2] = 0x161a;
 }
 
-static NetClientInfo net_milkymist_minimac2_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = minimac2_can_rx,
-    .receive = minimac2_rx,
-    .cleanup = minimac2_cleanup,
+#define TYPE_MILKYMIST_MINIMAC2_NET_CLIENT "milkymist-minimac2-net-client"
+
+static void milkymist_minimac2_net_client_class_init(ObjectClass *klass,
+                                                     void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = minimac2_can_rx;
+    ncc->receive = minimac2_rx;
+    ncc->cleanup = minimac2_cleanup;
+}
+
+static TypeInfo milkymist_minimac2_net_client_info = {
+    .name = TYPE_MILKYMIST_MINIMAC2_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = milkymist_minimac2_net_client_class_init,
 };
 
 static int milkymist_minimac2_init(SysBusDevice *dev)
@@ -478,7 +489,7 @@ static int milkymist_minimac2_init(SysBusDevice *dev)
     sysbus_add_memory(dev, s->buffers_base, &s->buffers);
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    s->nic = qemu_new_nic(&net_milkymist_minimac2_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_MILKYMIST_MINIMAC2_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
@@ -545,6 +556,7 @@ static TypeInfo milkymist_minimac2_info = {
 static void milkymist_minimac2_register_types(void)
 {
     type_register_static(&milkymist_minimac2_info);
+    type_register_static(&milkymist_minimac2_net_client_info);
 }
 
 type_init(milkymist_minimac2_register_types)
hw/mipsnet.c +18 -7
index 9cde90a..df06219 100644
@@ -216,12 +216,22 @@ static void mipsnet_cleanup(NetClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_mipsnet_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = mipsnet_can_receive,
-    .receive = mipsnet_receive,
-    .cleanup = mipsnet_cleanup,
+#define TYPE_MIPSNET_NET_CLIENT "mipsnet-net-client"
+
+static void mipsnet_net_client_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = mipsnet_can_receive;
+    ncc->receive = mipsnet_receive;
+    ncc->cleanup = mipsnet_cleanup;
+}
+
+static TypeInfo mipsnet_net_client_info = {
+    .name = TYPE_MIPSNET_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = mipsnet_net_client_class_init,
 };
 
 static const MemoryRegionOps mipsnet_ioport_ops = {
@@ -239,7 +249,7 @@ static int mipsnet_sysbus_init(SysBusDevice *dev)
     sysbus_init_mmio(dev, &s->io);
     sysbus_init_irq(dev, &s->irq);
 
-    s->nic = qemu_new_nic(&net_mipsnet_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_MIPSNET_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
@@ -279,6 +289,7 @@ static TypeInfo mipsnet_info = {
 static void mipsnet_register_types(void)
 {
     type_register_static(&mipsnet_info);
+    type_register_static(&mipsnet_net_client_info);
 }
 
 type_init(mipsnet_register_types)
hw/musicpal.c +19 -7
index 10d4f38..539d1ce 100644
@@ -373,12 +373,23 @@ static void eth_cleanup(NetClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_mv88w8618_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = eth_can_receive,
-    .receive = eth_receive,
-    .cleanup = eth_cleanup,
+#define TYPE_MV88W8618_NET_CLIENT "mv88w8618-net-client"
+
+static void mv88w8618_net_client_class_init(ObjectClass *klass,
+                                            void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = eth_can_receive;
+    ncc->receive = eth_receive;
+    ncc->cleanup = eth_cleanup;
+}
+
+static TypeInfo mv88w8618_net_client_info = {
+    .name = TYPE_MV88W8618_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = mv88w8618_net_client_class_init,
 };
 
 static int mv88w8618_eth_init(SysBusDevice *dev)
@@ -386,7 +397,7 @@ static int mv88w8618_eth_init(SysBusDevice *dev)
     mv88w8618_eth_state *s = FROM_SYSBUS(mv88w8618_eth_state, dev);
 
     sysbus_init_irq(dev, &s->irq);
-    s->nic = qemu_new_nic(&net_mv88w8618_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_MV88W8618_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     memory_region_init_io(&s->iomem, &mv88w8618_eth_ops, s, "mv88w8618-eth",
                           MP_ETH_SIZE);
@@ -1691,6 +1702,7 @@ static void musicpal_register_types(void)
     type_register_static(&musicpal_lcd_info);
     type_register_static(&musicpal_gpio_info);
     type_register_static(&musicpal_key_info);
+    type_register_static(&mv88w8618_net_client_info);
 }
 
 type_init(musicpal_register_types)
hw/ne2000-isa.c +1 -16
index ff4b885..2b4cd61 100644
@@ -36,21 +36,6 @@ typedef struct ISANE2000State {
     NE2000State ne2000;
 } ISANE2000State;
 
-static void isa_ne2000_cleanup(NetClientState *nc)
-{
-    NE2000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
-
-    s->nic = NULL;
-}
-
-static NetClientInfo net_ne2000_isa_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = ne2000_can_receive,
-    .receive = ne2000_receive,
-    .cleanup = isa_ne2000_cleanup,
-};
-
 static const VMStateDescription vmstate_isa_ne2000 = {
     .name = "ne2000",
     .version_id = 2,
@@ -75,7 +60,7 @@ static int isa_ne2000_initfn(ISADevice *dev)
     qemu_macaddr_default_if_unset(&s->c.macaddr);
     ne2000_reset(s);
 
-    s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
+    s->nic = qemu_new_nic(TYPE_NE2000_NET_CLIENT, &s->c,
                           object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
 
hw/ne2000.c +16 -7
index e8b1d68..d998601 100644
@@ -710,12 +710,20 @@ static void ne2000_cleanup(NetClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_ne2000_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = ne2000_can_receive,
-    .receive = ne2000_receive,
-    .cleanup = ne2000_cleanup,
+static void ne2000_net_client_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = ne2000_can_receive;
+    ncc->receive = ne2000_receive;
+    ncc->cleanup = ne2000_cleanup;
+}
+
+static TypeInfo ne2000_net_client_info = {
+    .name = TYPE_NE2000_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = ne2000_net_client_class_init,
 };
 
 static int pci_ne2000_init(PCIDevice *pci_dev)
@@ -735,7 +743,7 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
     qemu_macaddr_default_if_unset(&s->c.macaddr);
     ne2000_reset(s);
 
-    s->nic = qemu_new_nic(&net_ne2000_info, &s->c,
+    s->nic = qemu_new_nic(TYPE_NE2000_NET_CLIENT, &s->c,
                           object_get_typename(OBJECT(pci_dev)), pci_dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
 
@@ -784,6 +792,7 @@ static TypeInfo ne2000_info = {
 static void ne2000_register_types(void)
 {
     type_register_static(&ne2000_info);
+    type_register_static(&ne2000_net_client_info);
 }
 
 type_init(ne2000_register_types)
hw/ne2000.h +2 -0
index 1e7ab07..2d790cb 100644
@@ -28,6 +28,8 @@ typedef struct NE2000State {
     uint8_t mem[NE2000_MEM_SIZE];
 } NE2000State;
 
+#define TYPE_NE2000_NET_CLIENT "ne2000-net-client"
+
 void ne2000_setup_io(NE2000State *s, unsigned size);
 extern const VMStateDescription vmstate_ne2000;
 void ne2000_reset(NE2000State *s);
hw/opencores_eth.c +20 -8
index 990ec37..40b4059 100644
@@ -466,13 +466,24 @@ static void open_eth_cleanup(NetClientState *nc)
 {
 }
 
-static NetClientInfo net_open_eth_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = open_eth_can_receive,
-    .receive = open_eth_receive,
-    .cleanup = open_eth_cleanup,
-    .link_status_changed = open_eth_set_link_status,
+#define TYPE_OPEN_ETH_NET_CLIENT "open-eth-net-client"
+
+static void open_eth_net_client_class_init(ObjectClass *klass,
+                                           void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = open_eth_can_receive;
+    ncc->receive = open_eth_receive;
+    ncc->cleanup = open_eth_cleanup;
+    ncc->link_status_changed = open_eth_set_link_status;
+}
+
+static TypeInfo open_eth_net_client_info = {
+    .name = TYPE_OPEN_ETH_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = open_eth_net_client_class_init,
 };
 
 static void open_eth_start_xmit(OpenEthState *s, desc *tx)
@@ -691,7 +702,7 @@ static int sysbus_open_eth_init(SysBusDevice *dev)
 
     sysbus_init_irq(dev, &s->irq);
 
-    s->nic = qemu_new_nic(&net_open_eth_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_OPEN_ETH_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(s)), s->dev.qdev.id, s);
     return 0;
 }
@@ -728,6 +739,7 @@ static TypeInfo open_eth_info = {
 static void open_eth_register_types(void)
 {
     type_register_static(&open_eth_info);
+    type_register_static(&open_eth_net_client_info);
 }
 
 type_init(open_eth_register_types)
hw/pcnet-pci.c +1 -17
index 8bbad47..e8ffa78 100644
@@ -264,13 +264,6 @@ static void pci_physical_memory_read(void *dma_opaque, target_phys_addr_t addr,
     pci_dma_read(dma_opaque, addr, buf, len);
 }
 
-static void pci_pcnet_cleanup(NetClientState *nc)
-{
-    PCNetState *d = DO_UPCAST(NICState, nc, nc)->opaque;
-
-    pcnet_common_cleanup(d);
-}
-
 static int pci_pcnet_uninit(PCIDevice *dev)
 {
     PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, dev);
@@ -283,15 +276,6 @@ static int pci_pcnet_uninit(PCIDevice *dev)
     return 0;
 }
 
-static NetClientInfo net_pci_pcnet_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = pcnet_can_receive,
-    .receive = pcnet_receive,
-    .link_status_changed = pcnet_set_link_status,
-    .cleanup = pci_pcnet_cleanup,
-};
-
 static int pci_pcnet_init(PCIDevice *pci_dev)
 {
     PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, pci_dev);
@@ -330,7 +314,7 @@ static int pci_pcnet_init(PCIDevice *pci_dev)
     s->phys_mem_write = pci_physical_memory_write;
     s->dma_opaque = pci_dev;
 
-    return pcnet_common_init(&pci_dev->qdev, s, &net_pci_pcnet_info);
+    return pcnet_common_init(&pci_dev->qdev, s);
 }
 
 static void pci_reset(DeviceState *dev)
hw/pcnet.c +33 -3
index 40820b3..9444b97 100644
@@ -1716,12 +1716,34 @@ const VMStateDescription vmstate_pcnet = {
     }
 };
 
-void pcnet_common_cleanup(PCNetState *d)
+static void pcnet_common_cleanup(NetClientState *nc)
 {
+    NICState *nic = DO_UPCAST(NICState, nc, nc);
+    PCNetState *d = nic->opaque;
+
     d->nic = NULL;
 }
 
-int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
+#define TYPE_PCNET_NET_CLIENT "pcnet-net-client"
+
+static void pcnet_net_client_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = pcnet_can_receive;
+    ncc->receive = pcnet_receive;
+    ncc->link_status_changed = pcnet_set_link_status;
+    ncc->cleanup = pcnet_common_cleanup;
+}
+
+static TypeInfo pcnet_net_client_info = {
+    .name = TYPE_PCNET_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = pcnet_net_client_class_init,
+};
+
+int pcnet_common_init(DeviceState *dev, PCNetState *s)
 {
     int i;
     uint16_t checksum;
@@ -1729,7 +1751,8 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
     s->poll_timer = qemu_new_timer_ns(vm_clock, pcnet_poll_timer, s);
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    s->nic = qemu_new_nic(info, &s->conf, object_get_typename(OBJECT(dev)), dev->id, s);
+    s->nic = qemu_new_nic(TYPE_PCNET_NET_CLIENT, &s->conf,
+                          object_get_typename(OBJECT(dev)), dev->id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     add_boot_device_path(s->conf.bootindex, dev, "/ethernet-phy@0");
@@ -1765,3 +1788,10 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
 
     return 0;
 }
+
+static void pcnet_register_types(void)
+{
+    type_register_static(&pcnet_net_client_info);
+}
+
+type_init(pcnet_register_types)
hw/pcnet.h +1 -2
index d0af54a..c9b408d 100644
@@ -60,6 +60,5 @@ uint32_t pcnet_bcr_readw(PCNetState *s, uint32_t rap);
 int pcnet_can_receive(NetClientState *nc);
 ssize_t pcnet_receive(NetClientState *nc, const uint8_t *buf, size_t size_);
 void pcnet_set_link_status(NetClientState *nc);
-void pcnet_common_cleanup(PCNetState *d);
-int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info);
+int pcnet_common_init(DeviceState *dev, PCNetState *s);
 extern const VMStateDescription vmstate_pcnet;
hw/rtl8139.c +19 -7
index b31a649..8150a67 100644
@@ -3452,12 +3452,23 @@ static int pci_rtl8139_uninit(PCIDevice *dev)
     return 0;
 }
 
-static NetClientInfo net_rtl8139_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = rtl8139_can_receive,
-    .receive = rtl8139_receive,
-    .cleanup = rtl8139_cleanup,
+#define TYPE_RTL8139_NET_CLIENT "rtl8139-net-client"
+
+static void rtl8139_net_client_class_init(ObjectClass *klass,
+                                          void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = rtl8139_can_receive;
+    ncc->receive = rtl8139_receive;
+    ncc->cleanup = rtl8139_cleanup;
+}
+
+static TypeInfo rtl8139_net_client_info = {
+    .name = TYPE_RTL8139_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = rtl8139_net_client_class_init,
 };
 
 static int pci_rtl8139_init(PCIDevice *dev)
@@ -3489,7 +3500,7 @@ static int pci_rtl8139_init(PCIDevice *dev)
     s->eeprom.contents[8] = s->conf.macaddr.a[2] | s->conf.macaddr.a[3] << 8;
     s->eeprom.contents[9] = s->conf.macaddr.a[4] | s->conf.macaddr.a[5] << 8;
 
-    s->nic = qemu_new_nic(&net_rtl8139_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_RTL8139_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
@@ -3538,6 +3549,7 @@ static TypeInfo rtl8139_info = {
 static void rtl8139_register_types(void)
 {
     type_register_static(&rtl8139_info);
+    type_register_static(&rtl8139_net_client_info);
 }
 
 type_init(rtl8139_register_types)
hw/smc91c111.c +19 -7
index aaa2c60..4337462 100644
@@ -735,12 +735,23 @@ static void smc91c111_cleanup(NetClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_smc91c111_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = smc91c111_can_receive,
-    .receive = smc91c111_receive,
-    .cleanup = smc91c111_cleanup,
+#define TYPE_SMC91C111_NET_CLIENT "smc91c111-net-client"
+
+static void smc91c111_net_client_class_init(ObjectClass *klass,
+                                            void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = smc91c111_can_receive;
+    ncc->receive = smc91c111_receive;
+    ncc->cleanup = smc91c111_cleanup;
+}
+
+static TypeInfo smc91c111_net_client_info = {
+    .name = TYPE_SMC91C111_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = smc91c111_net_client_class_init,
 };
 
 static int smc91c111_init1(SysBusDevice *dev)
@@ -751,7 +762,7 @@ static int smc91c111_init1(SysBusDevice *dev)
     sysbus_init_mmio(dev, &s->mmio);
     sysbus_init_irq(dev, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    s->nic = qemu_new_nic(&net_smc91c111_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_SMC91C111_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     /* ??? Save/restore.  */
@@ -784,6 +795,7 @@ static TypeInfo smc91c111_info = {
 static void smc91c111_register_types(void)
 {
     type_register_static(&smc91c111_info);
+    type_register_static(&smc91c111_net_client_info);
 }
 
 /* Legacy helper function.  Should go away when machine config files are
hw/spapr_llan.c +18 -6
index 76fa0b5..54c8b38 100644
@@ -175,11 +175,22 @@ static ssize_t spapr_vlan_receive(NetClientState *nc, const uint8_t *buf,
     return size;
 }
 
-static NetClientInfo net_spapr_vlan_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = spapr_vlan_can_receive,
-    .receive = spapr_vlan_receive,
+#define TYPE_SPAPR_VLAN_NET_CLIENT "spapr-vlan-net-client"
+
+static void spapr_vlan_net_client_class_init(ObjectClass *klass,
+                                             void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = spapr_vlan_can_receive;
+    ncc->receive = spapr_vlan_receive;
+}
+
+static TypeInfo spapr_vlan_net_client_info = {
+    .name = TYPE_SPAPR_VLAN_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = spapr_vlan_net_client_class_init,
 };
 
 static void spapr_vlan_reset(VIOsPAPRDevice *sdev)
@@ -197,7 +208,7 @@ static int spapr_vlan_init(VIOsPAPRDevice *sdev)
 
     qemu_macaddr_default_if_unset(&dev->nicconf.macaddr);
 
-    dev->nic = qemu_new_nic(&net_spapr_vlan_info, &dev->nicconf,
+    dev->nic = qemu_new_nic(TYPE_SPAPR_VLAN_NET_CLIENT, &dev->nicconf,
                             object_get_typename(OBJECT(sdev)), sdev->qdev.id, dev);
     qemu_format_nic_info_str(&dev->nic->nc, dev->nicconf.macaddr.a);
 
@@ -515,6 +526,7 @@ static void spapr_vlan_register_types(void)
                              h_add_logical_lan_buffer);
     spapr_register_hypercall(H_MULTICAST_CTRL, h_multicast_ctrl);
     type_register_static(&spapr_vlan_info);
+    type_register_static(&spapr_vlan_net_client_info);
 }
 
 type_init(spapr_vlan_register_types)
hw/stellaris_enet.c +19 -7
index fcc6cd0..a892712 100644
@@ -392,12 +392,23 @@ static void stellaris_enet_cleanup(NetClientState *nc)
     g_free(s);
 }
 
-static NetClientInfo net_stellaris_enet_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = stellaris_enet_can_receive,
-    .receive = stellaris_enet_receive,
-    .cleanup = stellaris_enet_cleanup,
+#define TYPE_STELLARIS_ENET_NET_CLIENT "stellaris-enet-net-client"
+
+static void stellaris_enet_net_client_class_init(ObjectClass *klass,
+                                                 void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = stellaris_enet_can_receive;
+    ncc->receive = stellaris_enet_receive;
+    ncc->cleanup = stellaris_enet_cleanup;
+}
+
+static TypeInfo stellaris_enet_net_client_info = {
+    .name = TYPE_STELLARIS_ENET_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = stellaris_enet_net_client_class_init,
 };
 
 static int stellaris_enet_init(SysBusDevice *dev)
@@ -410,7 +421,7 @@ static int stellaris_enet_init(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
-    s->nic = qemu_new_nic(&net_stellaris_enet_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_STELLARIS_ENET_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
@@ -444,6 +455,7 @@ static TypeInfo stellaris_enet_info = {
 static void stellaris_enet_register_types(void)
 {
     type_register_static(&stellaris_enet_info);
+    type_register_static(&stellaris_enet_net_client_info);
 }
 
 type_init(stellaris_enet_register_types)
hw/usb/dev-network.c +18 -7
index 2d03639..e8464ed 100644
@@ -1312,12 +1312,22 @@ static void usb_net_handle_destroy(USBDevice *dev)
     qemu_del_net_client(&s->nic->nc);
 }
 
-static NetClientInfo net_usbnet_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = usbnet_can_receive,
-    .receive = usbnet_receive,
-    .cleanup = usbnet_cleanup,
+#define TYPE_USB_NET_CLIENT "usb-net-client"
+
+static void usb_net_client_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = usbnet_can_receive;
+    ncc->receive = usbnet_receive;
+    ncc->cleanup = usbnet_cleanup;
+}
+
+static TypeInfo usb_net_client_info = {
+    .name = TYPE_USB_NET_CLIENT,
+    .parent = TYPE_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = usb_net_client_class_init,
 };
 
 static int usb_net_initfn(USBDevice *dev)
@@ -1337,7 +1347,7 @@ static int usb_net_initfn(USBDevice *dev)
     s->vendorid = 0x1234;
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    s->nic = qemu_new_nic(&net_usbnet_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_USB_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(s)), s->dev.qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
@@ -1422,6 +1432,7 @@ static void usb_net_register_types(void)
 {
     type_register_static(&net_info);
     usb_legacy_register("usb-net", "net", usb_net_init);
+    type_register_static(&usb_net_client_info);
 }
 
 type_init(usb_net_register_types)
hw/virtio-net.c +26 -8
index 1575879..cdde3fb 100644
@@ -988,13 +988,23 @@ static void virtio_net_cleanup(NetClientState *nc)
     n->nic = NULL;
 }
 
-static NetClientInfo net_virtio_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = virtio_net_can_receive,
-    .receive = virtio_net_receive,
-        .cleanup = virtio_net_cleanup,
-    .link_status_changed = virtio_net_set_link_status,
+#define TYPE_VIRTIO_NET_CLIENT "virtio-net-client"
+
+static void virtio_net_client_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = virtio_net_can_receive;
+    ncc->receive = virtio_net_receive;
+    ncc->cleanup = virtio_net_cleanup;
+    ncc->link_status_changed = virtio_net_set_link_status;
+}
+
+static TypeInfo virtio_net_client_info = {
+    .name = TYPE_VIRTIO_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = virtio_net_client_class_init,
 };
 
 VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
@@ -1035,7 +1045,8 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
     memcpy(&n->mac[0], &conf->macaddr, sizeof(n->mac));
     n->status = VIRTIO_NET_S_LINK_UP;
 
-    n->nic = qemu_new_nic(&net_virtio_info, conf, object_get_typename(OBJECT(dev)), dev->id, n);
+    n->nic = qemu_new_nic(TYPE_VIRTIO_NET_CLIENT, conf,
+                          object_get_typename(OBJECT(dev)), dev->id, n);
 
     qemu_format_nic_info_str(&n->nic->nc, conf->macaddr.a);
 
@@ -1081,3 +1092,10 @@ void virtio_net_exit(VirtIODevice *vdev)
     qemu_del_net_client(&n->nic->nc);
     virtio_cleanup(&n->vdev);
 }
+
+static void virtio_net_register_types(void)
+{
+    type_register_static(&virtio_net_client_info);
+}
+
+type_init(virtio_net_register_types)
hw/xen_nic.c +23 -6
index ba4a45c..d8b7fa5 100644
@@ -303,11 +303,21 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t size
 
 /* ------------------------------------------------------------- */
 
-static NetClientInfo net_xen_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = net_rx_ok,
-    .receive = net_rx_packet,
+#define TYPE_XEN_NET_CLIENT "xen-net-client"
+
+static void xen_net_client_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = net_rx_ok;
+    ncc->receive = net_rx_packet;
+}
+
+static TypeInfo xen_net_client_info = {
+    .name = TYPE_XEN_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = xen_net_client_class_init,
 };
 
 static int net_init(struct XenDevice *xendev)
@@ -330,7 +340,7 @@ static int net_init(struct XenDevice *xendev)
 
     netdev->conf.peer = NULL;
 
-    netdev->nic = qemu_new_nic(&net_xen_info, &netdev->conf,
+    netdev->nic = qemu_new_nic(TYPE_XEN_NET_CLIENT, &netdev->conf,
                                "xen", NULL, netdev);
 
     snprintf(netdev->nic->nc.info_str, sizeof(netdev->nic->nc.info_str),
@@ -439,3 +449,10 @@ struct XenDevOps xen_netdev_ops = {
     .disconnect = net_disconnect,
     .free       = net_free,
 };
+
+static void xen_net_register_types(void)
+{
+    type_register_static(&xen_net_client_info);
+}
+
+type_init(xen_net_register_types)
hw/xgmac.c +19 -7
index b2cae49..41264dc 100644
@@ -370,12 +370,23 @@ static void eth_cleanup(NetClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_xgmac_enet_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = eth_can_rx,
-    .receive = eth_rx,
-    .cleanup = eth_cleanup,
+#define TYPE_XGMAC_ENET_NET_CLIENT "xgmac-enet-net-client"
+
+static void xgmac_enet_net_client_class_init(ObjectClass *klass,
+                                             void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = eth_can_rx;
+    ncc->receive = eth_rx;
+    ncc->cleanup = eth_cleanup;
+}
+
+static TypeInfo xgmac_enet_net_client_info = {
+    .name = TYPE_XGMAC_ENET_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = xgmac_enet_net_client_class_init,
 };
 
 static int xgmac_enet_init(SysBusDevice *dev)
@@ -389,7 +400,7 @@ static int xgmac_enet_init(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->mci_irq);
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    s->nic = qemu_new_nic(&net_xgmac_enet_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_XGMAC_ENET_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
@@ -428,6 +439,7 @@ static TypeInfo xgmac_enet_info = {
 static void xgmac_enet_register_types(void)
 {
     type_register_static(&xgmac_enet_info);
+    type_register_static(&xgmac_enet_net_client_info);
 }
 
 type_init(xgmac_enet_register_types)
hw/xilinx_axienet.c +19 -7
index 984071a..6e12a06 100644
@@ -831,12 +831,23 @@ axienet_stream_push(void *opaque, uint8_t *buf, size_t size, uint32_t *hdr)
     enet_update_irq(s);
 }
 
-static NetClientInfo net_xilinx_enet_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = eth_can_rx,
-    .receive = eth_rx,
-    .cleanup = eth_cleanup,
+#define TYPE_XILINX_AXI_NET_CLIENT "xilinx-axi-net-client"
+
+static void xilinx_axi_net_client_class_init(ObjectClass *klass,
+                                             void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = eth_can_rx;
+    ncc->receive = eth_rx;
+    ncc->cleanup = eth_cleanup;
+}
+
+static TypeInfo xilinx_axi_net_client_info = {
+    .name = TYPE_XILINX_AXI_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = xilinx_axi_net_client_class_init,
 };
 
 static int xilinx_enet_init(SysBusDevice *dev)
@@ -855,7 +866,7 @@ static int xilinx_enet_init(SysBusDevice *dev)
     sysbus_init_mmio(dev, &s->iomem);
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    s->nic = qemu_new_nic(&net_xilinx_enet_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_XILINX_AXI_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
@@ -898,6 +909,7 @@ static TypeInfo xilinx_enet_info = {
 static void xilinx_enet_register_types(void)
 {
     type_register_static(&xilinx_enet_info);
+    type_register_static(&xilinx_axi_net_client_info);
 }
 
 type_init(xilinx_enet_register_types)
hw/xilinx_ethlite.c +19 -7
index f261d89..9a88165 100644
@@ -201,12 +201,23 @@ static void eth_cleanup(NetClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_xilinx_ethlite_info = {
-    .type = NET_CLIENT_TYPE_NIC,
-    .size = sizeof(NICState),
-    .can_receive = eth_can_rx,
-    .receive = eth_rx,
-    .cleanup = eth_cleanup,
+#define TYPE_XILINX_ETHLITE_NET_CLIENT "xilinx-ethlite-net-client"
+
+static void xilinx_ethlite_net_client_class_init(ObjectClass *klass,
+                                                 void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->can_receive = eth_can_rx;
+    ncc->receive = eth_rx;
+    ncc->cleanup = eth_cleanup;
+}
+
+static TypeInfo xilinx_ethlite_net_client_info = {
+    .name = TYPE_XILINX_ETHLITE_NET_CLIENT,
+    .parent = TYPE_NIC_NET_CLIENT,
+    .instance_size = sizeof(NICState),
+    .class_init = xilinx_ethlite_net_client_class_init,
 };
 
 static int xilinx_ethlite_init(SysBusDevice *dev)
@@ -221,7 +232,7 @@ static int xilinx_ethlite_init(SysBusDevice *dev)
     sysbus_init_mmio(dev, &s->mmio);
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    s->nic = qemu_new_nic(&net_xilinx_ethlite_info, &s->conf,
+    s->nic = qemu_new_nic(TYPE_XILINX_ETHLITE_NET_CLIENT, &s->conf,
                           object_get_typename(OBJECT(dev)), dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     return 0;
@@ -253,6 +264,7 @@ static TypeInfo xilinx_ethlite_info = {
 static void xilinx_ethlite_register_types(void)
 {
     type_register_static(&xilinx_ethlite_info);
+    type_register_static(&xilinx_ethlite_net_client_info);
 }
 
 type_init(xilinx_ethlite_register_types)
net.c +81 -39

276 lines not on this page · raw message

net.h +24 -9
index 64d5d0e..efce535 100644
@@ -1,6 +1,7 @@
 #ifndef QEMU_NET_H
 #define QEMU_NET_H
 
+#include "qemu/object.h"
 #include "qemu-queue.h"
 #include "qemu-common.h"
 #include "qdict.h"
@@ -42,6 +43,14 @@ typedef enum {
     NET_CLIENT_TYPE_MAX
 } net_client_type;
 
+#define TYPE_NET_CLIENT "net-client"
+#define NET_CLIENT_GET_CLASS(obj) \
+   OBJECT_GET_CLASS(NetClientClass, obj, TYPE_NET_CLIENT)
+#define NET_CLIENT_CLASS(klass) \
+   OBJECT_CLASS_CHECK(NetClientClass, klass, TYPE_NET_CLIENT)
+#define NET_CLIENT(obj) \
+   OBJECT_CHECK(NetClientState, obj, TYPE_NET_CLIENT)
+
 typedef void (NetPoll)(NetClientState *, bool enable);
 typedef int (NetCanReceive)(NetClientState *);
 typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t);
@@ -49,9 +58,10 @@ typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);
 typedef void (NetCleanup) (NetClientState *);
 typedef void (LinkStatusChanged)(NetClientState *);
 
-typedef struct NetClientInfo {
-    net_client_type type;
-    size_t size;
+typedef struct NetClientClass {
+    ObjectClass parent;
+
+    const char *type_str; /* human-readable name for "info network" */
     NetReceive *receive;
     NetReceive *receive_raw;
     NetReceiveIOV *receive_iov;
@@ -59,10 +69,11 @@ typedef struct NetClientInfo {
     NetCleanup *cleanup;
     LinkStatusChanged *link_status_changed;
     NetPoll *poll;
-} NetClientInfo;
+} NetClientClass;
+
+typedef struct NetClientState {
+    Object parent;
 
-struct NetClientState {
-    NetClientInfo *info;
     int link_down;
     QTAILQ_ENTRY(NetClientState) next;
     NetClientState *peer;
@@ -71,7 +82,11 @@ struct NetClientState {
     char *name;
     char info_str[256];
     unsigned receive_disabled : 1;
-};
+} NetClientState;
+
+#define TYPE_NIC_NET_CLIENT "nic-net-client"
+#define NIC_NET_CLIENT(obj) \
+   OBJECT_CHECK(NICState, obj, TYPE_NIC_NET_CLIENT)
 
 typedef struct NICState {
     NetClientState nc;
@@ -81,11 +96,11 @@ typedef struct NICState {
 } NICState;
 
 NetClientState *qemu_find_netdev(const char *id);
-NetClientState *qemu_new_net_client(NetClientInfo *info,
+NetClientState *qemu_new_net_client(const char *typename,
                                     NetClientState *peer,
                                     const char *model,
                                     const char *name);
-NICState *qemu_new_nic(NetClientInfo *info,
+NICState *qemu_new_nic(const char *typename,
                        NICConf *conf,
                        const char *model,
                        const char *name,
net/dump.c +24 -6
index 76f3664..eb39ad7 100644
@@ -93,11 +93,22 @@ static void dump_cleanup(NetClientState *nc)
     close(s->fd);
 }
 
-static NetClientInfo net_dump_info = {
-    .type = NET_CLIENT_TYPE_DUMP,
-    .size = sizeof(DumpState),
-    .receive = dump_receive,
-    .cleanup = dump_cleanup,
+#define TYPE_DUMP_NET_CLIENT "dump-net-client"
+
+static void net_dump_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->type_str = "dump",
+    ncc->receive = dump_receive;
+    ncc->cleanup = dump_cleanup;
+}
+
+static TypeInfo net_dump_info = {
+    .name = TYPE_DUMP_NET_CLIENT,
+    .parent = TYPE_NET_CLIENT,
+    .instance_size = sizeof(DumpState),
+    .class_init = net_dump_class_init,
 };
 
 static int net_dump_init(NetClientState *peer, const char *device,
@@ -129,7 +140,7 @@ static int net_dump_init(NetClientState *peer, const char *device,
         return -1;
     }
 
-    nc = qemu_new_net_client(&net_dump_info, peer, device, name);
+    nc = qemu_new_net_client(TYPE_DUMP_NET_CLIENT, peer, device, name);
 
     snprintf(nc->info_str, sizeof(nc->info_str),
              "dump to %s (len=%d)", filename, len);
@@ -169,3 +180,10 @@ int net_init_dump(QemuOpts *opts, const char *name, NetClientState *peer)
 
     return net_dump_init(peer, "dump", name, file, len);
 }
+
+static void net_dump_register_types(void)
+{
+    type_register_static(&net_dump_info);
+}
+
+type_init(net_dump_register_types)
net/hub.c +32 -19

74 lines not on this page · raw message

net/slirp.c +23 -6
index 1e5cabb..990268c 100644
@@ -121,11 +121,22 @@ static void net_slirp_cleanup(NetClientState *nc)
     QTAILQ_REMOVE(&slirp_stacks, s, entry);
 }
 
-static NetClientInfo net_slirp_info = {
-    .type = NET_CLIENT_TYPE_USER,
-    .size = sizeof(SlirpState),
-    .receive = net_slirp_receive,
-    .cleanup = net_slirp_cleanup,
+#define TYPE_SLIRP_NET_CLIENT "slirp-net-client"
+
+static void net_slirp_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->type_str = "user";
+    ncc->receive = net_slirp_receive;
+    ncc->cleanup = net_slirp_cleanup;
+}
+
+static TypeInfo net_slirp_info = {
+    .name = TYPE_SLIRP_NET_CLIENT,
+    .parent = TYPE_NET_CLIENT,
+    .instance_size = sizeof(SlirpState),
+    .class_init = net_slirp_class_init,
 };
 
 static int net_slirp_init(NetClientState *peer, const char *model,
@@ -231,7 +242,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
     }
 #endif
 
-    nc = qemu_new_net_client(&net_slirp_info, peer, model, name);
+    nc = qemu_new_net_client(TYPE_SLIRP_NET_CLIENT, peer, model, name);
 
     snprintf(nc->info_str, sizeof(nc->info_str),
              "net=%s,restrict=%s", inet_ntoa(net),
@@ -768,3 +779,9 @@ int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret
     return 1;
 }
 
+static void net_slirp_register_types(void)
+{
+    type_register_static(&net_slirp_info);
+}
+
+type_init(net_slirp_register_types)
net/socket.c +47 -33

163 lines not on this page · raw message

net/tap-win32.c +24 -5
index ebb36e8..7a3ba37 100644
@@ -666,11 +666,23 @@ static void tap_win32_send(void *opaque)
     }
 }
 
-static NetClientInfo net_tap_win32_info = {
-    .type = NET_CLIENT_TYPE_TAP,
-    .size = sizeof(TAPState),
-    .receive = tap_receive,
-    .cleanup = tap_cleanup,
+#define TYPE_TAP_WIN32_NET_CLIENT "tap-win32-net-client"
+
+static void tap_win32_net_client_class_init(ObjectClass *klass,
+                                            void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->type_str = "tap";
+    ncc->receive = tap_receive;
+    ncc->cleanup = tap_cleanup;
+}
+
+static TypeInfo tap_win32_net_client_info = {
+    .name = TYPE_TAP_WIN32_NET_CLIENT,
+    .parent = TYPE_NET_CLIENT,
+    .instance_size = sizeof(TAPState),
+    .class_init = tap_win32_net_client_class_init,
 };
 
 static int tap_win32_init(NetClientState *peer, const char *model,
@@ -749,3 +761,10 @@ struct vhost_net *tap_get_vhost_net(NetClientState *nc)
 {
     return NULL;
 }
+
+static void tap_win32_register_types(void)
+{
+    type_register_static(&tap_win32_net_client_info);
+}
+
+type_init(tap_win32_register_types)
net/tap.c +45 -35

189 lines not on this page · raw message

net/vde.c +23 -5
index 48fb010..fbda843 100644
@@ -68,11 +68,22 @@ static void vde_cleanup(NetClientState *nc)
     vde_close(s->vde);
 }
 
-static NetClientInfo net_vde_info = {
-    .type = NET_CLIENT_TYPE_VDE,
-    .size = sizeof(VDEState),
-    .receive = vde_receive,
-    .cleanup = vde_cleanup,
+#define TYPE_VDE_NET_CLIENT "vde-net-client"
+
+static void vde_net_client_class_init(ObjectClass *klass, void *class_data)
+{
+    NetClientClass *ncc = NET_CLIENT_CLASS(klass);
+
+    ncc->type_str = "vde";
+    ncc->receive = vde_receive;
+    ncc->cleanup = vde_cleanup;
+}
+
+static TypeInfo vde_net_client_info = {
+    .name = TYPE_VDE_NET_CLIENT,
+    .parent = TYPE_NET_CLIENT,
+    .instance_size = sizeof(VDEState),
+    .class_init = vde_net_client_class_init,
 };
 
 static int net_vde_init(NetClientState *peer, const char *model,
@@ -128,3 +139,10 @@ int net_init_vde(QemuOpts *opts, const char *name, NetClientState *peer)
 
     return 0;
 }
+
+static void vde_register_types(void)
+{
+    type_register_static(&vde_net_client_info);
+}
+
+type_init(vde_register_types)
Signature · 1 line
1.7.10