]> git.proxmox.com Git - qemu.git/commitdiff
net: add a client type code
authorMark McLoughlin <markmc@redhat.com>
Thu, 22 Oct 2009 16:43:38 +0000 (17:43 +0100)
committerAnthony Liguori <aliguori@us.ibm.com>
Tue, 27 Oct 2009 17:29:00 +0000 (12:29 -0500)
This is so as to allow APIs which operate on specific client types
without having to add a function table entry which is only implemented
by a single client type.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/dp8393x.c
hw/etraxfs_eth.c
hw/mcf_fec.c
hw/mipsnet.c
hw/usb-net.c
hw/xen_nic.c
net.c
net.h
tap-win32.c

index e4caab02cf27d748ae07153b02cc11f5c19ae4a2..5622170a08610cc7c828030e78fc2c6b8d34d04f 100644 (file)
@@ -889,7 +889,8 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift,
     s->watchdog = qemu_new_timer(vm_clock, dp8393x_watchdog, s);
     s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */
 
-    s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->netdev,
+    s->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+                                          nd->vlan, nd->netdev,
                                           nd->model, nd->name,
                                           nic_can_receive, nic_receive, NULL,
                                           nic_cleanup, s);
index a411dab0dd9cf64f4c74a6cd7d64e82dcc7cf0f2..2a583a3cb0bc46d65f3b33befeeaadc5986ecefa 100644 (file)
@@ -590,7 +590,8 @@ void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t base, int phyaddr)
        eth->ethregs = cpu_register_io_memory(eth_read, eth_write, eth);
        cpu_register_physical_memory (base, 0x5c, eth->ethregs);
 
-       eth->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->netdev,
+       eth->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+                                                nd->vlan, nd->netdev,
                                                 nd->model, nd->name,
                                                 eth_can_receive, eth_receive,
                                                 NULL, eth_cleanup, eth);
index f9f437af676ce73400a485e9ccdf090c0773e2d0..0567bcdcd4e518757a0b72478e4409c6c99c1dad 100644 (file)
@@ -462,7 +462,8 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
                                            mcf_fec_writefn, s);
     cpu_register_physical_memory(base, 0x400, s->mmio_index);
 
-    s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->netdev,
+    s->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+                                          nd->vlan, nd->netdev,
                                           nd->model, nd->name,
                                           mcf_fec_can_receive, mcf_fec_receive,
                                           NULL, mcf_fec_cleanup, s);
index ea8b570795e31fb1076ed3ced714fa8fafab95a7..d32099f6649ea92ae73d6ae97b16ad6001a1123b 100644 (file)
@@ -263,7 +263,8 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
     s->io_base = base;
     s->irq = irq;
     if (nd) {
-        s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->netdev,
+        s->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+                                              nd->vlan, nd->netdev,
                                               nd->model, nd->name,
                                               mipsnet_can_receive, mipsnet_receive,
                                               NULL, mipsnet_cleanup, s);
index 5c753e08727d84d903d5516197b7785e58b5b7ff..239381285858f75f565a22b8db898e5ed7062cbb 100644 (file)
@@ -1460,7 +1460,8 @@ USBDevice *usb_net_init(NICInfo *nd)
 
     memcpy(s->mac, nd->macaddr, 6);
 
-    s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->netdev,
+    s->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+                                          nd->vlan, nd->netdev,
                                           nd->model, nd->name,
                                           usbnet_can_receive,
                                           usbnet_receive,
index b09b48a22f7dc517cadada536334df3f8678910b..2a179f089368ffed3b7f624049a99402226e71de 100644 (file)
@@ -301,7 +301,8 @@ static int net_init(struct XenDevice *xendev)
        return -1;
 
     vlan = qemu_find_vlan(netdev->xendev.dev, 1);
-    netdev->vs = qemu_new_vlan_client(vlan, NULL, "xen", NULL,
+    netdev->vs = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+                                      vlan, NULL, "xen", NULL,
                                       net_rx_ok, net_rx_packet, NULL,
                                       NULL, netdev);
     snprintf(netdev->vs->info_str, sizeof(netdev->vs->info_str),
diff --git a/net.c b/net.c
index 3d9426016864a08608033242c51c6b238f5c97e0..59f9a529983a7646f20b7f3fb523623584fd0e73 100644 (file)
--- a/net.c
+++ b/net.c
@@ -325,7 +325,8 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
                                        int iovcnt,
                                        void *opaque);
 
-VLANClientState *qemu_new_vlan_client(VLANState *vlan,
+VLANClientState *qemu_new_vlan_client(net_client_type type,
+                                      VLANState *vlan,
                                       VLANClientState *peer,
                                       const char *model,
                                       const char *name,
@@ -339,6 +340,7 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
 
     vc = qemu_mallocz(sizeof(VLANClientState));
 
+    vc->type = type;
     vc->model = qemu_strdup(model);
     if (name)
         vc->name = qemu_strdup(name);
@@ -880,7 +882,8 @@ static int net_slirp_init(VLANState *vlan, const char *model,
     }
 #endif
 
-    s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL,
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SLIRP,
+                                 vlan, NULL, model, name, NULL,
                                  slirp_receive, NULL,
                                  net_slirp_cleanup, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
@@ -1486,7 +1489,8 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
     s = qemu_mallocz(sizeof(TAPState));
     s->fd = fd;
     s->has_vnet_hdr = vnet_hdr != 0;
-    s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL,
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP,
+                                 vlan, NULL, model, name, NULL,
                                  tap_receive, tap_receive_iov,
                                  tap_cleanup, s);
     tap_read_poll(s, 1);
@@ -1845,7 +1849,8 @@ static int net_vde_init(VLANState *vlan, const char *model,
         free(s);
         return -1;
     }
-    s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL,
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_VDE,
+                                 vlan, NULL, model, name, NULL,
                                  vde_receive, NULL,
                                  vde_cleanup, s);
     qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
@@ -2085,7 +2090,8 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
     s = qemu_mallocz(sizeof(NetSocketState));
     s->fd = fd;
 
-    s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL,
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SOCKET,
+                                 vlan, NULL, model, name, NULL,
                                  net_socket_receive_dgram, NULL,
                                  net_socket_cleanup, s);
     qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
@@ -2114,7 +2120,8 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
     NetSocketState *s;
     s = qemu_mallocz(sizeof(NetSocketState));
     s->fd = fd;
-    s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL,
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SOCKET,
+                                 vlan, NULL, model, name, NULL,
                                  net_socket_receive, NULL,
                                  net_socket_cleanup, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str),
@@ -2396,7 +2403,8 @@ static int net_dump_init(VLANState *vlan, const char *device,
         return -1;
     }
 
-    s->pcap_vc = qemu_new_vlan_client(vlan, NULL, device, name, NULL,
+    s->pcap_vc = qemu_new_vlan_client(NET_CLIENT_TYPE_DUMP,
+                                      vlan, NULL, device, name, NULL,
                                       dump_receive, NULL,
                                       net_dump_cleanup, s);
     snprintf(s->pcap_vc->info_str, sizeof(s->pcap_vc->info_str),
diff --git a/net.h b/net.h
index c96f29142d331eea2ca2d6e38286996e318225c6..f592ffb2902b2e84ccfe97fc55f505007e77ad7c 100644 (file)
--- a/net.h
+++ b/net.h
@@ -26,6 +26,16 @@ typedef struct NICConf {
 
 /* VLANs support */
 
+typedef enum {
+    NET_CLIENT_TYPE_NONE,
+    NET_CLIENT_TYPE_NIC,
+    NET_CLIENT_TYPE_SLIRP,
+    NET_CLIENT_TYPE_TAP,
+    NET_CLIENT_TYPE_SOCKET,
+    NET_CLIENT_TYPE_VDE,
+    NET_CLIENT_TYPE_DUMP
+} net_client_type;
+
 typedef int (NetCanReceive)(VLANClientState *);
 typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
 typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
@@ -33,6 +43,7 @@ typedef void (NetCleanup) (VLANClientState *);
 typedef void (LinkStatusChanged)(VLANClientState *);
 
 struct VLANClientState {
+    net_client_type type;
     NetReceive *receive;
     NetReceiveIOV *receive_iov;
     /* Packets may still be sent if this returns zero.  It's used to
index e4fdde816612757a7978ffbc64fc48d897956d1f..e2bac3e448a28b7f53130b051c0b9fee79899400 100644 (file)
@@ -677,7 +677,8 @@ int tap_win32_init(VLANState *vlan, const char *model,
         return -1;
     }
 
-    s->vc = qemu_new_vlan_client(vlan, NULL, model, name,
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP,
+                                 vlan, NULL, model, name,
                                  NULL, tap_receive,
                                  NULL, tap_cleanup, s);