All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups
@ 2009-11-25 18:48 Mark McLoughlin
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 01/44] net: move slirp code from net.c to net/slirp.c Mark McLoughlin
                   ` (43 more replies)
  0 siblings, 44 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:48 UTC (permalink / raw)
  To: qemu-devel


Hi,
        Here's a new series of patches mainly to fix qemu_announce_self()
with -netdev as discussed earlier on the list.

        I would have liked to have split the series in three, but there
would be conflicts between each, so here goes:

  1) Patches 01 to 05 - net.c cleanups

     These patches continue the job of moving net backends from net.c
     to individual files in the net/ directory

  2) Patches 06 to 39 - fix qemu_annonuce_self()

     The basic issue is that we need a sane way of iterating all the
     NICs on the system, obtaining the MAC address for each and
     inject a packet from each.

     The series splits out the per-device-type data from VLANClientState
     into a new structure called NetClientInfo. It further allows devices
     to inherit from VLANClientState and introduces a NICState struct
     and qemu_new_nic() constructor for NICs.

     That's a huge amount of churn just to fix qemu_announce_self(), but
     I think the end result is a very nice cleanup to the net API.

  3) Patches 40 to 44 - misc fixes

     Some small misc networking fixes, including the two posted by
     Pierre Riteau earlier.


        I've given all this quite a bit of compile and runtime testing
and it seems in good shape.

Thanks,
Mark.
        

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 01/44] net: move slirp code from net.c to net/slirp.c
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
@ 2009-11-25 18:48 ` Mark McLoughlin
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 02/44] net: move vde code from net.c to net/vde.c Mark McLoughlin
                   ` (42 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile    |    1 +
 monitor.c   |    1 +
 net.c       |  718 +-------------------------------------------------------
 net.h       |    8 +-
 net/slirp.c |  752 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/slirp.h |   51 ++++
 vl.c        |    1 +
 7 files changed, 814 insertions(+), 718 deletions(-)
 create mode 100644 net/slirp.c
 create mode 100644 net/slirp.h

diff --git a/Makefile b/Makefile
index 63a7128..45362fa 100644
--- a/Makefile
+++ b/Makefile
@@ -106,6 +106,7 @@ net-nested-$(CONFIG_WIN32) += tap-win32.o
 net-nested-$(CONFIG_BSD) += tap-bsd.o
 net-nested-$(CONFIG_SOLARIS) += tap-solaris.o
 net-nested-$(CONFIG_AIX) += tap-aix.o
+net-nested-$(CONFIG_SLIRP) += slirp.o
 net-obj-y += $(addprefix net/, $(net-nested-y))
 
 ######################################################################
diff --git a/monitor.c b/monitor.c
index 3286ba2..fa1561a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -32,6 +32,7 @@
 #include "hw/loader.h"
 #include "gdbstub.h"
 #include "net.h"
+#include "net/slirp.h"
 #include "qemu-char.h"
 #include "sysemu.h"
 #include "monitor.h"
diff --git a/net.c b/net.c
index 9ea66e3..9b030a1 100644
--- a/net.c
+++ b/net.c
@@ -40,9 +40,7 @@
 #include <sys/ioctl.h>
 #include <sys/resource.h>
 #include <sys/socket.h>
-#include <netinet/in.h>
 #include <net/if.h>
-#include <arpa/inet.h>
 #include <dirent.h>
 #include <netdb.h>
 #include <sys/select.h>
@@ -98,6 +96,7 @@
 #include "qemu-common.h"
 #include "net.h"
 #include "net/tap.h"
+#include "net/slirp.h"
 #include "monitor.h"
 #include "sysemu.h"
 #include "qemu-timer.h"
@@ -107,15 +106,13 @@
 #include "qemu-log.h"
 #include "qemu-config.h"
 
-#include "slirp/libslirp.h"
-
 static QTAILQ_HEAD(, VLANState) vlans;
 static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
 
 /***********************************************************/
 /* network device redirectors */
 
-#if defined(DEBUG_NET) || defined(DEBUG_SLIRP)
+#if defined(DEBUG_NET)
 static void hex_dump(FILE *f, const uint8_t *buf, int size)
 {
     int len, i, j, c;
@@ -406,7 +403,7 @@ VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque)
     return NULL;
 }
 
-static VLANClientState *
+VLANClientState *
 qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
                               const char *client_str)
 {
@@ -725,597 +722,6 @@ qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt)
     return qemu_sendv_packet_async(vc, iov, iovcnt, NULL);
 }
 
-#if defined(CONFIG_SLIRP)
-
-/* slirp network adapter */
-
-#define SLIRP_CFG_HOSTFWD 1
-#define SLIRP_CFG_LEGACY  2
-
-struct slirp_config_str {
-    struct slirp_config_str *next;
-    int flags;
-    char str[1024];
-    int legacy_format;
-};
-
-typedef struct SlirpState {
-    QTAILQ_ENTRY(SlirpState) entry;
-    VLANClientState *vc;
-    Slirp *slirp;
-#ifndef _WIN32
-    char smb_dir[128];
-#endif
-} SlirpState;
-
-static struct slirp_config_str *slirp_configs;
-const char *legacy_tftp_prefix;
-const char *legacy_bootp_filename;
-static QTAILQ_HEAD(slirp_stacks, SlirpState) slirp_stacks =
-    QTAILQ_HEAD_INITIALIZER(slirp_stacks);
-
-static int slirp_hostfwd(SlirpState *s, const char *redir_str,
-                         int legacy_format);
-static int slirp_guestfwd(SlirpState *s, const char *config_str,
-                          int legacy_format);
-
-#ifndef _WIN32
-static const char *legacy_smb_export;
-
-static int slirp_smb(SlirpState *s, const char *exported_dir,
-                     struct in_addr vserver_addr);
-static void slirp_smb_cleanup(SlirpState *s);
-#else
-static inline void slirp_smb_cleanup(SlirpState *s) { }
-#endif
-
-int slirp_can_output(void *opaque)
-{
-    SlirpState *s = opaque;
-
-    return qemu_can_send_packet(s->vc);
-}
-
-void slirp_output(void *opaque, const uint8_t *pkt, int pkt_len)
-{
-    SlirpState *s = opaque;
-
-#ifdef DEBUG_SLIRP
-    printf("slirp output:\n");
-    hex_dump(stdout, pkt, pkt_len);
-#endif
-    qemu_send_packet(s->vc, pkt, pkt_len);
-}
-
-static ssize_t slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
-{
-    SlirpState *s = vc->opaque;
-
-#ifdef DEBUG_SLIRP
-    printf("slirp input:\n");
-    hex_dump(stdout, buf, size);
-#endif
-    slirp_input(s->slirp, buf, size);
-    return size;
-}
-
-static void net_slirp_cleanup(VLANClientState *vc)
-{
-    SlirpState *s = vc->opaque;
-
-    slirp_cleanup(s->slirp);
-    slirp_smb_cleanup(s);
-    QTAILQ_REMOVE(&slirp_stacks, s, entry);
-    qemu_free(s);
-}
-
-static int net_slirp_init(VLANState *vlan, const char *model,
-                          const char *name, int restricted,
-                          const char *vnetwork, const char *vhost,
-                          const char *vhostname, const char *tftp_export,
-                          const char *bootfile, const char *vdhcp_start,
-                          const char *vnameserver, const char *smb_export,
-                          const char *vsmbserver)
-{
-    /* default settings according to historic slirp */
-    struct in_addr net  = { .s_addr = htonl(0x0a000200) }; /* 10.0.2.0 */
-    struct in_addr mask = { .s_addr = htonl(0xffffff00) }; /* 255.255.255.0 */
-    struct in_addr host = { .s_addr = htonl(0x0a000202) }; /* 10.0.2.2 */
-    struct in_addr dhcp = { .s_addr = htonl(0x0a00020f) }; /* 10.0.2.15 */
-    struct in_addr dns  = { .s_addr = htonl(0x0a000203) }; /* 10.0.2.3 */
-#ifndef _WIN32
-    struct in_addr smbsrv = { .s_addr = 0 };
-#endif
-    SlirpState *s;
-    char buf[20];
-    uint32_t addr;
-    int shift;
-    char *end;
-    struct slirp_config_str *config;
-
-    if (!tftp_export) {
-        tftp_export = legacy_tftp_prefix;
-    }
-    if (!bootfile) {
-        bootfile = legacy_bootp_filename;
-    }
-
-    if (vnetwork) {
-        if (get_str_sep(buf, sizeof(buf), &vnetwork, '/') < 0) {
-            if (!inet_aton(vnetwork, &net)) {
-                return -1;
-            }
-            addr = ntohl(net.s_addr);
-            if (!(addr & 0x80000000)) {
-                mask.s_addr = htonl(0xff000000); /* class A */
-            } else if ((addr & 0xfff00000) == 0xac100000) {
-                mask.s_addr = htonl(0xfff00000); /* priv. 172.16.0.0/12 */
-            } else if ((addr & 0xc0000000) == 0x80000000) {
-                mask.s_addr = htonl(0xffff0000); /* class B */
-            } else if ((addr & 0xffff0000) == 0xc0a80000) {
-                mask.s_addr = htonl(0xffff0000); /* priv. 192.168.0.0/16 */
-            } else if ((addr & 0xffff0000) == 0xc6120000) {
-                mask.s_addr = htonl(0xfffe0000); /* tests 198.18.0.0/15 */
-            } else if ((addr & 0xe0000000) == 0xe0000000) {
-                mask.s_addr = htonl(0xffffff00); /* class C */
-            } else {
-                mask.s_addr = htonl(0xfffffff0); /* multicast/reserved */
-            }
-        } else {
-            if (!inet_aton(buf, &net)) {
-                return -1;
-            }
-            shift = strtol(vnetwork, &end, 10);
-            if (*end != '\0') {
-                if (!inet_aton(vnetwork, &mask)) {
-                    return -1;
-                }
-            } else if (shift < 4 || shift > 32) {
-                return -1;
-            } else {
-                mask.s_addr = htonl(0xffffffff << (32 - shift));
-            }
-        }
-        net.s_addr &= mask.s_addr;
-        host.s_addr = net.s_addr | (htonl(0x0202) & ~mask.s_addr);
-        dhcp.s_addr = net.s_addr | (htonl(0x020f) & ~mask.s_addr);
-        dns.s_addr  = net.s_addr | (htonl(0x0203) & ~mask.s_addr);
-    }
-
-    if (vhost && !inet_aton(vhost, &host)) {
-        return -1;
-    }
-    if ((host.s_addr & mask.s_addr) != net.s_addr) {
-        return -1;
-    }
-
-    if (vdhcp_start && !inet_aton(vdhcp_start, &dhcp)) {
-        return -1;
-    }
-    if ((dhcp.s_addr & mask.s_addr) != net.s_addr ||
-        dhcp.s_addr == host.s_addr || dhcp.s_addr == dns.s_addr) {
-        return -1;
-    }
-
-    if (vnameserver && !inet_aton(vnameserver, &dns)) {
-        return -1;
-    }
-    if ((dns.s_addr & mask.s_addr) != net.s_addr ||
-        dns.s_addr == host.s_addr) {
-        return -1;
-    }
-
-#ifndef _WIN32
-    if (vsmbserver && !inet_aton(vsmbserver, &smbsrv)) {
-        return -1;
-    }
-#endif
-
-    s = qemu_mallocz(sizeof(SlirpState));
-    s->slirp = slirp_init(restricted, net, mask, host, vhostname,
-                          tftp_export, bootfile, dhcp, dns, s);
-    QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry);
-
-    for (config = slirp_configs; config; config = config->next) {
-        if (config->flags & SLIRP_CFG_HOSTFWD) {
-            if (slirp_hostfwd(s, config->str,
-                              config->flags & SLIRP_CFG_LEGACY) < 0)
-                return -1;
-        } else {
-            if (slirp_guestfwd(s, config->str,
-                               config->flags & SLIRP_CFG_LEGACY) < 0)
-                return -1;
-        }
-    }
-#ifndef _WIN32
-    if (!smb_export) {
-        smb_export = legacy_smb_export;
-    }
-    if (smb_export) {
-        if (slirp_smb(s, smb_export, smbsrv) < 0)
-            return -1;
-    }
-#endif
-
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SLIRP,
-                                 vlan, NULL, model, name, NULL,
-                                 slirp_receive, NULL, NULL,
-                                 net_slirp_cleanup, s);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n');
-    return 0;
-}
-
-static SlirpState *slirp_lookup(Monitor *mon, const char *vlan,
-                                const char *stack)
-{
-    VLANClientState *vc;
-
-    if (vlan) {
-        vc = qemu_find_vlan_client_by_name(mon, strtol(vlan, NULL, 0), stack);
-        if (!vc) {
-            return NULL;
-        }
-        if (strcmp(vc->model, "user")) {
-            monitor_printf(mon, "invalid device specified\n");
-            return NULL;
-        }
-        return vc->opaque;
-    } else {
-        if (QTAILQ_EMPTY(&slirp_stacks)) {
-            monitor_printf(mon, "user mode network stack not in use\n");
-            return NULL;
-        }
-        return QTAILQ_FIRST(&slirp_stacks);
-    }
-}
-
-void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict)
-{
-    struct in_addr host_addr = { .s_addr = INADDR_ANY };
-    int host_port;
-    char buf[256] = "";
-    const char *src_str, *p;
-    SlirpState *s;
-    int is_udp = 0;
-    int err;
-    const char *arg1 = qdict_get_str(qdict, "arg1");
-    const char *arg2 = qdict_get_try_str(qdict, "arg2");
-    const char *arg3 = qdict_get_try_str(qdict, "arg3");
-
-    if (arg2) {
-        s = slirp_lookup(mon, arg1, arg2);
-        src_str = arg3;
-    } else {
-        s = slirp_lookup(mon, NULL, NULL);
-        src_str = arg1;
-    }
-    if (!s) {
-        return;
-    }
-
-    if (!src_str || !src_str[0])
-        goto fail_syntax;
-
-    p = src_str;
-    get_str_sep(buf, sizeof(buf), &p, ':');
-
-    if (!strcmp(buf, "tcp") || buf[0] == '\0') {
-        is_udp = 0;
-    } else if (!strcmp(buf, "udp")) {
-        is_udp = 1;
-    } else {
-        goto fail_syntax;
-    }
-
-    if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
-        goto fail_syntax;
-    }
-    if (buf[0] != '\0' && !inet_aton(buf, &host_addr)) {
-        goto fail_syntax;
-    }
-
-    host_port = atoi(p);
-
-    err = slirp_remove_hostfwd(QTAILQ_FIRST(&slirp_stacks)->slirp, is_udp,
-                               host_addr, host_port);
-
-    monitor_printf(mon, "host forwarding rule for %s %s\n", src_str,
-                   err ? "removed" : "not found");
-    return;
-
- fail_syntax:
-    monitor_printf(mon, "invalid format\n");
-}
-
-static int slirp_hostfwd(SlirpState *s, const char *redir_str,
-                         int legacy_format)
-{
-    struct in_addr host_addr = { .s_addr = INADDR_ANY };
-    struct in_addr guest_addr = { .s_addr = 0 };
-    int host_port, guest_port;
-    const char *p;
-    char buf[256];
-    int is_udp;
-    char *end;
-
-    p = redir_str;
-    if (!p || get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
-        goto fail_syntax;
-    }
-    if (!strcmp(buf, "tcp") || buf[0] == '\0') {
-        is_udp = 0;
-    } else if (!strcmp(buf, "udp")) {
-        is_udp = 1;
-    } else {
-        goto fail_syntax;
-    }
-
-    if (!legacy_format) {
-        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
-            goto fail_syntax;
-        }
-        if (buf[0] != '\0' && !inet_aton(buf, &host_addr)) {
-            goto fail_syntax;
-        }
-    }
-
-    if (get_str_sep(buf, sizeof(buf), &p, legacy_format ? ':' : '-') < 0) {
-        goto fail_syntax;
-    }
-    host_port = strtol(buf, &end, 0);
-    if (*end != '\0' || host_port < 1 || host_port > 65535) {
-        goto fail_syntax;
-    }
-
-    if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
-        goto fail_syntax;
-    }
-    if (buf[0] != '\0' && !inet_aton(buf, &guest_addr)) {
-        goto fail_syntax;
-    }
-
-    guest_port = strtol(p, &end, 0);
-    if (*end != '\0' || guest_port < 1 || guest_port > 65535) {
-        goto fail_syntax;
-    }
-
-    if (slirp_add_hostfwd(s->slirp, is_udp, host_addr, host_port, guest_addr,
-                          guest_port) < 0) {
-        qemu_error("could not set up host forwarding rule '%s'\n",
-                   redir_str);
-        return -1;
-    }
-    return 0;
-
- fail_syntax:
-    qemu_error("invalid host forwarding rule '%s'\n", redir_str);
-    return -1;
-}
-
-void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict)
-{
-    const char *redir_str;
-    SlirpState *s;
-    const char *arg1 = qdict_get_str(qdict, "arg1");
-    const char *arg2 = qdict_get_try_str(qdict, "arg2");
-    const char *arg3 = qdict_get_try_str(qdict, "arg3");
-
-    if (arg2) {
-        s = slirp_lookup(mon, arg1, arg2);
-        redir_str = arg3;
-    } else {
-        s = slirp_lookup(mon, NULL, NULL);
-        redir_str = arg1;
-    }
-    if (s) {
-        slirp_hostfwd(s, redir_str, 0);
-    }
-
-}
-
-int net_slirp_redir(const char *redir_str)
-{
-    struct slirp_config_str *config;
-
-    if (QTAILQ_EMPTY(&slirp_stacks)) {
-        config = qemu_malloc(sizeof(*config));
-        pstrcpy(config->str, sizeof(config->str), redir_str);
-        config->flags = SLIRP_CFG_HOSTFWD | SLIRP_CFG_LEGACY;
-        config->next = slirp_configs;
-        slirp_configs = config;
-        return 0;
-    }
-
-    return slirp_hostfwd(QTAILQ_FIRST(&slirp_stacks), redir_str, 1);
-}
-
-#ifndef _WIN32
-
-/* automatic user mode samba server configuration */
-static void slirp_smb_cleanup(SlirpState *s)
-{
-    char cmd[128];
-
-    if (s->smb_dir[0] != '\0') {
-        snprintf(cmd, sizeof(cmd), "rm -rf %s", s->smb_dir);
-        system(cmd);
-        s->smb_dir[0] = '\0';
-    }
-}
-
-static int slirp_smb(SlirpState* s, const char *exported_dir,
-                     struct in_addr vserver_addr)
-{
-    static int instance;
-    char smb_conf[128];
-    char smb_cmdline[128];
-    FILE *f;
-
-    snprintf(s->smb_dir, sizeof(s->smb_dir), "/tmp/qemu-smb.%ld-%d",
-             (long)getpid(), instance++);
-    if (mkdir(s->smb_dir, 0700) < 0) {
-        qemu_error("could not create samba server dir '%s'\n", s->smb_dir);
-        return -1;
-    }
-    snprintf(smb_conf, sizeof(smb_conf), "%s/%s", s->smb_dir, "smb.conf");
-
-    f = fopen(smb_conf, "w");
-    if (!f) {
-        slirp_smb_cleanup(s);
-        qemu_error("could not create samba server configuration file '%s'\n",
-                   smb_conf);
-        return -1;
-    }
-    fprintf(f,
-            "[global]\n"
-            "private dir=%s\n"
-            "smb ports=0\n"
-            "socket address=127.0.0.1\n"
-            "pid directory=%s\n"
-            "lock directory=%s\n"
-            "log file=%s/log.smbd\n"
-            "smb passwd file=%s/smbpasswd\n"
-            "security = share\n"
-            "[qemu]\n"
-            "path=%s\n"
-            "read only=no\n"
-            "guest ok=yes\n",
-            s->smb_dir,
-            s->smb_dir,
-            s->smb_dir,
-            s->smb_dir,
-            s->smb_dir,
-            exported_dir
-            );
-    fclose(f);
-
-    snprintf(smb_cmdline, sizeof(smb_cmdline), "%s -s %s",
-             SMBD_COMMAND, smb_conf);
-
-    if (slirp_add_exec(s->slirp, 0, smb_cmdline, &vserver_addr, 139) < 0) {
-        slirp_smb_cleanup(s);
-        qemu_error("conflicting/invalid smbserver address\n");
-        return -1;
-    }
-    return 0;
-}
-
-/* automatic user mode samba server configuration (legacy interface) */
-int net_slirp_smb(const char *exported_dir)
-{
-    struct in_addr vserver_addr = { .s_addr = 0 };
-
-    if (legacy_smb_export) {
-        fprintf(stderr, "-smb given twice\n");
-        return -1;
-    }
-    legacy_smb_export = exported_dir;
-    if (!QTAILQ_EMPTY(&slirp_stacks)) {
-        return slirp_smb(QTAILQ_FIRST(&slirp_stacks), exported_dir,
-                         vserver_addr);
-    }
-    return 0;
-}
-
-#endif /* !defined(_WIN32) */
-
-struct GuestFwd {
-    CharDriverState *hd;
-    struct in_addr server;
-    int port;
-    Slirp *slirp;
-};
-
-static int guestfwd_can_read(void *opaque)
-{
-    struct GuestFwd *fwd = opaque;
-    return slirp_socket_can_recv(fwd->slirp, fwd->server, fwd->port);
-}
-
-static void guestfwd_read(void *opaque, const uint8_t *buf, int size)
-{
-    struct GuestFwd *fwd = opaque;
-    slirp_socket_recv(fwd->slirp, fwd->server, fwd->port, buf, size);
-}
-
-static int slirp_guestfwd(SlirpState *s, const char *config_str,
-                          int legacy_format)
-{
-    struct in_addr server = { .s_addr = 0 };
-    struct GuestFwd *fwd;
-    const char *p;
-    char buf[128];
-    char *end;
-    int port;
-
-    p = config_str;
-    if (legacy_format) {
-        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
-            goto fail_syntax;
-        }
-    } else {
-        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
-            goto fail_syntax;
-        }
-        if (strcmp(buf, "tcp") && buf[0] != '\0') {
-            goto fail_syntax;
-        }
-        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
-            goto fail_syntax;
-        }
-        if (buf[0] != '\0' && !inet_aton(buf, &server)) {
-            goto fail_syntax;
-        }
-        if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) {
-            goto fail_syntax;
-        }
-    }
-    port = strtol(buf, &end, 10);
-    if (*end != '\0' || port < 1 || port > 65535) {
-        goto fail_syntax;
-    }
-
-    fwd = qemu_malloc(sizeof(struct GuestFwd));
-    snprintf(buf, sizeof(buf), "guestfwd.tcp:%d", port);
-    fwd->hd = qemu_chr_open(buf, p, NULL);
-    if (!fwd->hd) {
-        qemu_error("could not open guest forwarding device '%s'\n", buf);
-        qemu_free(fwd);
-        return -1;
-    }
-
-    if (slirp_add_exec(s->slirp, 3, fwd->hd, &server, port) < 0) {
-        qemu_error("conflicting/invalid host:port in guest forwarding "
-                   "rule '%s'\n", config_str);
-        qemu_free(fwd);
-        return -1;
-    }
-    fwd->server = server;
-    fwd->port = port;
-    fwd->slirp = s->slirp;
-
-    qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read,
-                          NULL, fwd);
-    return 0;
-
- fail_syntax:
-    qemu_error("invalid guest forwarding rule '%s'\n", config_str);
-    return -1;
-}
-
-void do_info_usernet(Monitor *mon)
-{
-    SlirpState *s;
-
-    QTAILQ_FOREACH(s, &slirp_stacks, entry) {
-        monitor_printf(mon, "VLAN %d (%s):\n", s->vc->vlan->id, s->vc->name);
-        slirp_connection_info(s->slirp, mon);
-    }
-}
-
-#endif /* CONFIG_SLIRP */
-
 #if defined(CONFIG_VDE)
 typedef struct VDEState {
     VLANClientState *vc;
@@ -2116,101 +1522,6 @@ static int net_init_nic(QemuOpts *opts,
     return idx;
 }
 
-#if defined(CONFIG_SLIRP)
-static int net_init_slirp_configs(const char *name, const char *value, void *opaque)
-{
-    struct slirp_config_str *config;
-
-    if (strcmp(name, "hostfwd") != 0 && strcmp(name, "guestfwd") != 0) {
-        return 0;
-    }
-
-    config = qemu_mallocz(sizeof(*config));
-
-    pstrcpy(config->str, sizeof(config->str), value);
-
-    if (!strcmp(name, "hostfwd")) {
-        config->flags = SLIRP_CFG_HOSTFWD;
-    }
-
-    config->next = slirp_configs;
-    slirp_configs = config;
-
-    return 0;
-}
-
-static int net_init_slirp(QemuOpts *opts,
-                          Monitor *mon,
-                          const char *name,
-                          VLANState *vlan)
-{
-    struct slirp_config_str *config;
-    const char *vhost;
-    const char *vhostname;
-    const char *vdhcp_start;
-    const char *vnamesrv;
-    const char *tftp_export;
-    const char *bootfile;
-    const char *smb_export;
-    const char *vsmbsrv;
-    char *vnet = NULL;
-    int restricted = 0;
-    int ret;
-
-    vhost       = qemu_opt_get(opts, "host");
-    vhostname   = qemu_opt_get(opts, "hostname");
-    vdhcp_start = qemu_opt_get(opts, "dhcpstart");
-    vnamesrv    = qemu_opt_get(opts, "dns");
-    tftp_export = qemu_opt_get(opts, "tftp");
-    bootfile    = qemu_opt_get(opts, "bootfile");
-    smb_export  = qemu_opt_get(opts, "smb");
-    vsmbsrv     = qemu_opt_get(opts, "smbserver");
-
-    if (qemu_opt_get(opts, "ip")) {
-        const char *ip = qemu_opt_get(opts, "ip");
-        int l = strlen(ip) + strlen("/24") + 1;
-
-        vnet = qemu_malloc(l);
-
-        /* emulate legacy ip= parameter */
-        pstrcpy(vnet, l, ip);
-        pstrcat(vnet, l, "/24");
-    }
-
-    if (qemu_opt_get(opts, "net")) {
-        if (vnet) {
-            qemu_free(vnet);
-        }
-        vnet = qemu_strdup(qemu_opt_get(opts, "net"));
-    }
-
-    if (qemu_opt_get(opts, "restrict") &&
-        qemu_opt_get(opts, "restrict")[0] == 'y') {
-        restricted = 1;
-    }
-
-    qemu_opt_foreach(opts, net_init_slirp_configs, NULL, 0);
-
-    ret = net_slirp_init(vlan, "user", name, restricted, vnet, vhost,
-                         vhostname, tftp_export, bootfile, vdhcp_start,
-                         vnamesrv, smb_export, vsmbsrv);
-
-    while (slirp_configs) {
-        config = slirp_configs;
-        slirp_configs = config->next;
-        qemu_free(config);
-    }
-
-    if (ret != -1 && vlan) {
-        vlan->nb_host_devs++;
-    }
-
-    qemu_free(vnet);
-
-    return ret;
-}
-#endif /* CONFIG_SLIRP */
-
 static int net_init_socket(QemuOpts *opts,
                            Monitor *mon,
                            const char *name,
@@ -2860,29 +2171,12 @@ int net_init_clients(void)
 int net_client_parse(QemuOptsList *opts_list, const char *optarg)
 {
 #if defined(CONFIG_SLIRP)
-    /* handle legacy -net channel,port:chr */
-    if (!strcmp(opts_list->name, "net") &&
-        !strncmp(optarg, "channel,", strlen("channel,"))) {
-        int ret;
-
-        optarg += strlen("channel,");
-
-        if (QTAILQ_EMPTY(&slirp_stacks)) {
-            struct slirp_config_str *config;
-
-            config = qemu_malloc(sizeof(*config));
-            pstrcpy(config->str, sizeof(config->str), optarg);
-            config->flags = SLIRP_CFG_LEGACY;
-            config->next = slirp_configs;
-            slirp_configs = config;
-            ret = 0;
-        } else {
-            ret = slirp_guestfwd(QTAILQ_FIRST(&slirp_stacks), optarg, 1);
-        }
-
+    int ret;
+    if (net_slirp_parse_legacy(opts_list, optarg, &ret)) {
         return ret;
     }
 #endif
+
     if (!qemu_opts_parse(opts_list, optarg, "type")) {
         return -1;
     }
diff --git a/net.h b/net.h
index 4ffce91..42ac42d 100644
--- a/net.h
+++ b/net.h
@@ -87,6 +87,8 @@ VLANClientState *qemu_new_vlan_client(net_client_type type,
                                       void *opaque);
 void qemu_del_vlan_client(VLANClientState *vc);
 VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
+VLANClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
+                                               const char *client_str);
 int qemu_can_send_packet(VLANClientState *vc);
 ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
                           int iovcnt);
@@ -108,8 +110,6 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models,
 void do_info_network(Monitor *mon);
 void do_set_link(Monitor *mon, const QDict *qdict);
 
-void do_info_usernet(Monitor *mon);
-
 /* NIC info */
 
 #define MAX_NICS 8
@@ -156,10 +156,6 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
 void net_client_uninit(NICInfo *nd);
 int net_client_parse(QemuOptsList *opts_list, const char *str);
 int net_init_clients(void);
-int net_slirp_smb(const char *exported_dir);
-void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict);
-void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict);
-int net_slirp_redir(const char *redir_str);
 void net_cleanup(void);
 void net_set_boot_mask(int boot_mask);
 void net_host_device_add(Monitor *mon, const QDict *qdict);
diff --git a/net/slirp.c b/net/slirp.c
new file mode 100644
index 0000000..d6d5772
--- /dev/null
+++ b/net/slirp.c
@@ -0,0 +1,752 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "net/slirp.h"
+
+#include "config-host.h"
+
+#include "net.h"
+#include "monitor.h"
+#include "sysemu.h"
+#include "qemu_socket.h"
+#include "slirp/libslirp.h"
+
+static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
+{
+    const char *p, *p1;
+    int len;
+    p = *pp;
+    p1 = strchr(p, sep);
+    if (!p1)
+        return -1;
+    len = p1 - p;
+    p1++;
+    if (buf_size > 0) {
+        if (len > buf_size - 1)
+            len = buf_size - 1;
+        memcpy(buf, p, len);
+        buf[len] = '\0';
+    }
+    *pp = p1;
+    return 0;
+}
+
+/* slirp network adapter */
+
+#define SLIRP_CFG_HOSTFWD 1
+#define SLIRP_CFG_LEGACY  2
+
+struct slirp_config_str {
+    struct slirp_config_str *next;
+    int flags;
+    char str[1024];
+    int legacy_format;
+};
+
+typedef struct SlirpState {
+    QTAILQ_ENTRY(SlirpState) entry;
+    VLANClientState *vc;
+    Slirp *slirp;
+#ifndef _WIN32
+    char smb_dir[128];
+#endif
+} SlirpState;
+
+static struct slirp_config_str *slirp_configs;
+const char *legacy_tftp_prefix;
+const char *legacy_bootp_filename;
+static QTAILQ_HEAD(slirp_stacks, SlirpState) slirp_stacks =
+    QTAILQ_HEAD_INITIALIZER(slirp_stacks);
+
+static int slirp_hostfwd(SlirpState *s, const char *redir_str,
+                         int legacy_format);
+static int slirp_guestfwd(SlirpState *s, const char *config_str,
+                          int legacy_format);
+
+#ifndef _WIN32
+static const char *legacy_smb_export;
+
+static int slirp_smb(SlirpState *s, const char *exported_dir,
+                     struct in_addr vserver_addr);
+static void slirp_smb_cleanup(SlirpState *s);
+#else
+static inline void slirp_smb_cleanup(SlirpState *s) { }
+#endif
+
+int slirp_can_output(void *opaque)
+{
+    SlirpState *s = opaque;
+
+    return qemu_can_send_packet(s->vc);
+}
+
+void slirp_output(void *opaque, const uint8_t *pkt, int pkt_len)
+{
+    SlirpState *s = opaque;
+
+    qemu_send_packet(s->vc, pkt, pkt_len);
+}
+
+static ssize_t slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+{
+    SlirpState *s = vc->opaque;
+
+    slirp_input(s->slirp, buf, size);
+
+    return size;
+}
+
+static void net_slirp_cleanup(VLANClientState *vc)
+{
+    SlirpState *s = vc->opaque;
+
+    slirp_cleanup(s->slirp);
+    slirp_smb_cleanup(s);
+    QTAILQ_REMOVE(&slirp_stacks, s, entry);
+    qemu_free(s);
+}
+
+static int net_slirp_init(VLANState *vlan, const char *model,
+                          const char *name, int restricted,
+                          const char *vnetwork, const char *vhost,
+                          const char *vhostname, const char *tftp_export,
+                          const char *bootfile, const char *vdhcp_start,
+                          const char *vnameserver, const char *smb_export,
+                          const char *vsmbserver)
+{
+    /* default settings according to historic slirp */
+    struct in_addr net  = { .s_addr = htonl(0x0a000200) }; /* 10.0.2.0 */
+    struct in_addr mask = { .s_addr = htonl(0xffffff00) }; /* 255.255.255.0 */
+    struct in_addr host = { .s_addr = htonl(0x0a000202) }; /* 10.0.2.2 */
+    struct in_addr dhcp = { .s_addr = htonl(0x0a00020f) }; /* 10.0.2.15 */
+    struct in_addr dns  = { .s_addr = htonl(0x0a000203) }; /* 10.0.2.3 */
+#ifndef _WIN32
+    struct in_addr smbsrv = { .s_addr = 0 };
+#endif
+    SlirpState *s;
+    char buf[20];
+    uint32_t addr;
+    int shift;
+    char *end;
+    struct slirp_config_str *config;
+
+    if (!tftp_export) {
+        tftp_export = legacy_tftp_prefix;
+    }
+    if (!bootfile) {
+        bootfile = legacy_bootp_filename;
+    }
+
+    if (vnetwork) {
+        if (get_str_sep(buf, sizeof(buf), &vnetwork, '/') < 0) {
+            if (!inet_aton(vnetwork, &net)) {
+                return -1;
+            }
+            addr = ntohl(net.s_addr);
+            if (!(addr & 0x80000000)) {
+                mask.s_addr = htonl(0xff000000); /* class A */
+            } else if ((addr & 0xfff00000) == 0xac100000) {
+                mask.s_addr = htonl(0xfff00000); /* priv. 172.16.0.0/12 */
+            } else if ((addr & 0xc0000000) == 0x80000000) {
+                mask.s_addr = htonl(0xffff0000); /* class B */
+            } else if ((addr & 0xffff0000) == 0xc0a80000) {
+                mask.s_addr = htonl(0xffff0000); /* priv. 192.168.0.0/16 */
+            } else if ((addr & 0xffff0000) == 0xc6120000) {
+                mask.s_addr = htonl(0xfffe0000); /* tests 198.18.0.0/15 */
+            } else if ((addr & 0xe0000000) == 0xe0000000) {
+                mask.s_addr = htonl(0xffffff00); /* class C */
+            } else {
+                mask.s_addr = htonl(0xfffffff0); /* multicast/reserved */
+            }
+        } else {
+            if (!inet_aton(buf, &net)) {
+                return -1;
+            }
+            shift = strtol(vnetwork, &end, 10);
+            if (*end != '\0') {
+                if (!inet_aton(vnetwork, &mask)) {
+                    return -1;
+                }
+            } else if (shift < 4 || shift > 32) {
+                return -1;
+            } else {
+                mask.s_addr = htonl(0xffffffff << (32 - shift));
+            }
+        }
+        net.s_addr &= mask.s_addr;
+        host.s_addr = net.s_addr | (htonl(0x0202) & ~mask.s_addr);
+        dhcp.s_addr = net.s_addr | (htonl(0x020f) & ~mask.s_addr);
+        dns.s_addr  = net.s_addr | (htonl(0x0203) & ~mask.s_addr);
+    }
+
+    if (vhost && !inet_aton(vhost, &host)) {
+        return -1;
+    }
+    if ((host.s_addr & mask.s_addr) != net.s_addr) {
+        return -1;
+    }
+
+    if (vdhcp_start && !inet_aton(vdhcp_start, &dhcp)) {
+        return -1;
+    }
+    if ((dhcp.s_addr & mask.s_addr) != net.s_addr ||
+        dhcp.s_addr == host.s_addr || dhcp.s_addr == dns.s_addr) {
+        return -1;
+    }
+
+    if (vnameserver && !inet_aton(vnameserver, &dns)) {
+        return -1;
+    }
+    if ((dns.s_addr & mask.s_addr) != net.s_addr ||
+        dns.s_addr == host.s_addr) {
+        return -1;
+    }
+
+#ifndef _WIN32
+    if (vsmbserver && !inet_aton(vsmbserver, &smbsrv)) {
+        return -1;
+    }
+#endif
+
+    s = qemu_mallocz(sizeof(SlirpState));
+    s->slirp = slirp_init(restricted, net, mask, host, vhostname,
+                          tftp_export, bootfile, dhcp, dns, s);
+    QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry);
+
+    for (config = slirp_configs; config; config = config->next) {
+        if (config->flags & SLIRP_CFG_HOSTFWD) {
+            if (slirp_hostfwd(s, config->str,
+                              config->flags & SLIRP_CFG_LEGACY) < 0)
+                return -1;
+        } else {
+            if (slirp_guestfwd(s, config->str,
+                               config->flags & SLIRP_CFG_LEGACY) < 0)
+                return -1;
+        }
+    }
+#ifndef _WIN32
+    if (!smb_export) {
+        smb_export = legacy_smb_export;
+    }
+    if (smb_export) {
+        if (slirp_smb(s, smb_export, smbsrv) < 0)
+            return -1;
+    }
+#endif
+
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SLIRP,
+                                 vlan, NULL, model, name, NULL,
+                                 slirp_receive, NULL, NULL,
+                                 net_slirp_cleanup, s);
+    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
+             "net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n');
+    return 0;
+}
+
+static SlirpState *slirp_lookup(Monitor *mon, const char *vlan,
+                                const char *stack)
+{
+    VLANClientState *vc;
+
+    if (vlan) {
+        vc = qemu_find_vlan_client_by_name(mon, strtol(vlan, NULL, 0), stack);
+        if (!vc) {
+            return NULL;
+        }
+        if (strcmp(vc->model, "user")) {
+            monitor_printf(mon, "invalid device specified\n");
+            return NULL;
+        }
+        return vc->opaque;
+    } else {
+        if (QTAILQ_EMPTY(&slirp_stacks)) {
+            monitor_printf(mon, "user mode network stack not in use\n");
+            return NULL;
+        }
+        return QTAILQ_FIRST(&slirp_stacks);
+    }
+}
+
+void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict)
+{
+    struct in_addr host_addr = { .s_addr = INADDR_ANY };
+    int host_port;
+    char buf[256] = "";
+    const char *src_str, *p;
+    SlirpState *s;
+    int is_udp = 0;
+    int err;
+    const char *arg1 = qdict_get_str(qdict, "arg1");
+    const char *arg2 = qdict_get_try_str(qdict, "arg2");
+    const char *arg3 = qdict_get_try_str(qdict, "arg3");
+
+    if (arg2) {
+        s = slirp_lookup(mon, arg1, arg2);
+        src_str = arg3;
+    } else {
+        s = slirp_lookup(mon, NULL, NULL);
+        src_str = arg1;
+    }
+    if (!s) {
+        return;
+    }
+
+    if (!src_str || !src_str[0])
+        goto fail_syntax;
+
+    p = src_str;
+    get_str_sep(buf, sizeof(buf), &p, ':');
+
+    if (!strcmp(buf, "tcp") || buf[0] == '\0') {
+        is_udp = 0;
+    } else if (!strcmp(buf, "udp")) {
+        is_udp = 1;
+    } else {
+        goto fail_syntax;
+    }
+
+    if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
+        goto fail_syntax;
+    }
+    if (buf[0] != '\0' && !inet_aton(buf, &host_addr)) {
+        goto fail_syntax;
+    }
+
+    host_port = atoi(p);
+
+    err = slirp_remove_hostfwd(QTAILQ_FIRST(&slirp_stacks)->slirp, is_udp,
+                               host_addr, host_port);
+
+    monitor_printf(mon, "host forwarding rule for %s %s\n", src_str,
+                   err ? "removed" : "not found");
+    return;
+
+ fail_syntax:
+    monitor_printf(mon, "invalid format\n");
+}
+
+static int slirp_hostfwd(SlirpState *s, const char *redir_str,
+                         int legacy_format)
+{
+    struct in_addr host_addr = { .s_addr = INADDR_ANY };
+    struct in_addr guest_addr = { .s_addr = 0 };
+    int host_port, guest_port;
+    const char *p;
+    char buf[256];
+    int is_udp;
+    char *end;
+
+    p = redir_str;
+    if (!p || get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
+        goto fail_syntax;
+    }
+    if (!strcmp(buf, "tcp") || buf[0] == '\0') {
+        is_udp = 0;
+    } else if (!strcmp(buf, "udp")) {
+        is_udp = 1;
+    } else {
+        goto fail_syntax;
+    }
+
+    if (!legacy_format) {
+        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
+            goto fail_syntax;
+        }
+        if (buf[0] != '\0' && !inet_aton(buf, &host_addr)) {
+            goto fail_syntax;
+        }
+    }
+
+    if (get_str_sep(buf, sizeof(buf), &p, legacy_format ? ':' : '-') < 0) {
+        goto fail_syntax;
+    }
+    host_port = strtol(buf, &end, 0);
+    if (*end != '\0' || host_port < 1 || host_port > 65535) {
+        goto fail_syntax;
+    }
+
+    if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
+        goto fail_syntax;
+    }
+    if (buf[0] != '\0' && !inet_aton(buf, &guest_addr)) {
+        goto fail_syntax;
+    }
+
+    guest_port = strtol(p, &end, 0);
+    if (*end != '\0' || guest_port < 1 || guest_port > 65535) {
+        goto fail_syntax;
+    }
+
+    if (slirp_add_hostfwd(s->slirp, is_udp, host_addr, host_port, guest_addr,
+                          guest_port) < 0) {
+        qemu_error("could not set up host forwarding rule '%s'\n",
+                   redir_str);
+        return -1;
+    }
+    return 0;
+
+ fail_syntax:
+    qemu_error("invalid host forwarding rule '%s'\n", redir_str);
+    return -1;
+}
+
+void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict)
+{
+    const char *redir_str;
+    SlirpState *s;
+    const char *arg1 = qdict_get_str(qdict, "arg1");
+    const char *arg2 = qdict_get_try_str(qdict, "arg2");
+    const char *arg3 = qdict_get_try_str(qdict, "arg3");
+
+    if (arg2) {
+        s = slirp_lookup(mon, arg1, arg2);
+        redir_str = arg3;
+    } else {
+        s = slirp_lookup(mon, NULL, NULL);
+        redir_str = arg1;
+    }
+    if (s) {
+        slirp_hostfwd(s, redir_str, 0);
+    }
+
+}
+
+int net_slirp_redir(const char *redir_str)
+{
+    struct slirp_config_str *config;
+
+    if (QTAILQ_EMPTY(&slirp_stacks)) {
+        config = qemu_malloc(sizeof(*config));
+        pstrcpy(config->str, sizeof(config->str), redir_str);
+        config->flags = SLIRP_CFG_HOSTFWD | SLIRP_CFG_LEGACY;
+        config->next = slirp_configs;
+        slirp_configs = config;
+        return 0;
+    }
+
+    return slirp_hostfwd(QTAILQ_FIRST(&slirp_stacks), redir_str, 1);
+}
+
+#ifndef _WIN32
+
+/* automatic user mode samba server configuration */
+static void slirp_smb_cleanup(SlirpState *s)
+{
+    char cmd[128];
+
+    if (s->smb_dir[0] != '\0') {
+        snprintf(cmd, sizeof(cmd), "rm -rf %s", s->smb_dir);
+        system(cmd);
+        s->smb_dir[0] = '\0';
+    }
+}
+
+static int slirp_smb(SlirpState* s, const char *exported_dir,
+                     struct in_addr vserver_addr)
+{
+    static int instance;
+    char smb_conf[128];
+    char smb_cmdline[128];
+    FILE *f;
+
+    snprintf(s->smb_dir, sizeof(s->smb_dir), "/tmp/qemu-smb.%ld-%d",
+             (long)getpid(), instance++);
+    if (mkdir(s->smb_dir, 0700) < 0) {
+        qemu_error("could not create samba server dir '%s'\n", s->smb_dir);
+        return -1;
+    }
+    snprintf(smb_conf, sizeof(smb_conf), "%s/%s", s->smb_dir, "smb.conf");
+
+    f = fopen(smb_conf, "w");
+    if (!f) {
+        slirp_smb_cleanup(s);
+        qemu_error("could not create samba server configuration file '%s'\n",
+                   smb_conf);
+        return -1;
+    }
+    fprintf(f,
+            "[global]\n"
+            "private dir=%s\n"
+            "smb ports=0\n"
+            "socket address=127.0.0.1\n"
+            "pid directory=%s\n"
+            "lock directory=%s\n"
+            "log file=%s/log.smbd\n"
+            "smb passwd file=%s/smbpasswd\n"
+            "security = share\n"
+            "[qemu]\n"
+            "path=%s\n"
+            "read only=no\n"
+            "guest ok=yes\n",
+            s->smb_dir,
+            s->smb_dir,
+            s->smb_dir,
+            s->smb_dir,
+            s->smb_dir,
+            exported_dir
+            );
+    fclose(f);
+
+    snprintf(smb_cmdline, sizeof(smb_cmdline), "%s -s %s",
+             SMBD_COMMAND, smb_conf);
+
+    if (slirp_add_exec(s->slirp, 0, smb_cmdline, &vserver_addr, 139) < 0) {
+        slirp_smb_cleanup(s);
+        qemu_error("conflicting/invalid smbserver address\n");
+        return -1;
+    }
+    return 0;
+}
+
+/* automatic user mode samba server configuration (legacy interface) */
+int net_slirp_smb(const char *exported_dir)
+{
+    struct in_addr vserver_addr = { .s_addr = 0 };
+
+    if (legacy_smb_export) {
+        fprintf(stderr, "-smb given twice\n");
+        return -1;
+    }
+    legacy_smb_export = exported_dir;
+    if (!QTAILQ_EMPTY(&slirp_stacks)) {
+        return slirp_smb(QTAILQ_FIRST(&slirp_stacks), exported_dir,
+                         vserver_addr);
+    }
+    return 0;
+}
+
+#endif /* !defined(_WIN32) */
+
+struct GuestFwd {
+    CharDriverState *hd;
+    struct in_addr server;
+    int port;
+    Slirp *slirp;
+};
+
+static int guestfwd_can_read(void *opaque)
+{
+    struct GuestFwd *fwd = opaque;
+    return slirp_socket_can_recv(fwd->slirp, fwd->server, fwd->port);
+}
+
+static void guestfwd_read(void *opaque, const uint8_t *buf, int size)
+{
+    struct GuestFwd *fwd = opaque;
+    slirp_socket_recv(fwd->slirp, fwd->server, fwd->port, buf, size);
+}
+
+static int slirp_guestfwd(SlirpState *s, const char *config_str,
+                          int legacy_format)
+{
+    struct in_addr server = { .s_addr = 0 };
+    struct GuestFwd *fwd;
+    const char *p;
+    char buf[128];
+    char *end;
+    int port;
+
+    p = config_str;
+    if (legacy_format) {
+        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
+            goto fail_syntax;
+        }
+    } else {
+        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
+            goto fail_syntax;
+        }
+        if (strcmp(buf, "tcp") && buf[0] != '\0') {
+            goto fail_syntax;
+        }
+        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
+            goto fail_syntax;
+        }
+        if (buf[0] != '\0' && !inet_aton(buf, &server)) {
+            goto fail_syntax;
+        }
+        if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) {
+            goto fail_syntax;
+        }
+    }
+    port = strtol(buf, &end, 10);
+    if (*end != '\0' || port < 1 || port > 65535) {
+        goto fail_syntax;
+    }
+
+    fwd = qemu_malloc(sizeof(struct GuestFwd));
+    snprintf(buf, sizeof(buf), "guestfwd.tcp:%d", port);
+    fwd->hd = qemu_chr_open(buf, p, NULL);
+    if (!fwd->hd) {
+        qemu_error("could not open guest forwarding device '%s'\n", buf);
+        qemu_free(fwd);
+        return -1;
+    }
+
+    if (slirp_add_exec(s->slirp, 3, fwd->hd, &server, port) < 0) {
+        qemu_error("conflicting/invalid host:port in guest forwarding "
+                   "rule '%s'\n", config_str);
+        qemu_free(fwd);
+        return -1;
+    }
+    fwd->server = server;
+    fwd->port = port;
+    fwd->slirp = s->slirp;
+
+    qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read,
+                          NULL, fwd);
+    return 0;
+
+ fail_syntax:
+    qemu_error("invalid guest forwarding rule '%s'\n", config_str);
+    return -1;
+}
+
+void do_info_usernet(Monitor *mon)
+{
+    SlirpState *s;
+
+    QTAILQ_FOREACH(s, &slirp_stacks, entry) {
+        monitor_printf(mon, "VLAN %d (%s):\n", s->vc->vlan->id, s->vc->name);
+        slirp_connection_info(s->slirp, mon);
+    }
+}
+
+static int net_init_slirp_configs(const char *name, const char *value, void *opaque)
+{
+    struct slirp_config_str *config;
+
+    if (strcmp(name, "hostfwd") != 0 && strcmp(name, "guestfwd") != 0) {
+        return 0;
+    }
+
+    config = qemu_mallocz(sizeof(*config));
+
+    pstrcpy(config->str, sizeof(config->str), value);
+
+    if (!strcmp(name, "hostfwd")) {
+        config->flags = SLIRP_CFG_HOSTFWD;
+    }
+
+    config->next = slirp_configs;
+    slirp_configs = config;
+
+    return 0;
+}
+
+int net_init_slirp(QemuOpts *opts,
+                   Monitor *mon,
+                   const char *name,
+                   VLANState *vlan)
+{
+    struct slirp_config_str *config;
+    const char *vhost;
+    const char *vhostname;
+    const char *vdhcp_start;
+    const char *vnamesrv;
+    const char *tftp_export;
+    const char *bootfile;
+    const char *smb_export;
+    const char *vsmbsrv;
+    char *vnet = NULL;
+    int restricted = 0;
+    int ret;
+
+    vhost       = qemu_opt_get(opts, "host");
+    vhostname   = qemu_opt_get(opts, "hostname");
+    vdhcp_start = qemu_opt_get(opts, "dhcpstart");
+    vnamesrv    = qemu_opt_get(opts, "dns");
+    tftp_export = qemu_opt_get(opts, "tftp");
+    bootfile    = qemu_opt_get(opts, "bootfile");
+    smb_export  = qemu_opt_get(opts, "smb");
+    vsmbsrv     = qemu_opt_get(opts, "smbserver");
+
+    if (qemu_opt_get(opts, "ip")) {
+        const char *ip = qemu_opt_get(opts, "ip");
+        int l = strlen(ip) + strlen("/24") + 1;
+
+        vnet = qemu_malloc(l);
+
+        /* emulate legacy ip= parameter */
+        pstrcpy(vnet, l, ip);
+        pstrcat(vnet, l, "/24");
+    }
+
+    if (qemu_opt_get(opts, "net")) {
+        if (vnet) {
+            qemu_free(vnet);
+        }
+        vnet = qemu_strdup(qemu_opt_get(opts, "net"));
+    }
+
+    if (qemu_opt_get(opts, "restrict") &&
+        qemu_opt_get(opts, "restrict")[0] == 'y') {
+        restricted = 1;
+    }
+
+    qemu_opt_foreach(opts, net_init_slirp_configs, NULL, 0);
+
+    ret = net_slirp_init(vlan, "user", name, restricted, vnet, vhost,
+                         vhostname, tftp_export, bootfile, vdhcp_start,
+                         vnamesrv, smb_export, vsmbsrv);
+
+    while (slirp_configs) {
+        config = slirp_configs;
+        slirp_configs = config->next;
+        qemu_free(config);
+    }
+
+    if (ret != -1 && vlan) {
+        vlan->nb_host_devs++;
+    }
+
+    qemu_free(vnet);
+
+    return ret;
+}
+
+int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret)
+{
+    if (strcmp(opts_list->name, "net") != 0 ||
+        strncmp(optarg, "channel,", strlen("channel,")) != 0) {
+        return 0;
+    }
+
+    /* handle legacy -net channel,port:chr */
+    optarg += strlen("channel,");
+
+    if (QTAILQ_EMPTY(&slirp_stacks)) {
+        struct slirp_config_str *config;
+
+        config = qemu_malloc(sizeof(*config));
+        pstrcpy(config->str, sizeof(config->str), optarg);
+        config->flags = SLIRP_CFG_LEGACY;
+        config->next = slirp_configs;
+        slirp_configs = config;
+        *ret = 0;
+    } else {
+        *ret = slirp_guestfwd(QTAILQ_FIRST(&slirp_stacks), optarg, 1);
+    }
+
+    return 1;
+}
+
diff --git a/net/slirp.h b/net/slirp.h
new file mode 100644
index 0000000..c17de8e
--- /dev/null
+++ b/net/slirp.h
@@ -0,0 +1,51 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef QEMU_NET_SLIRP_H
+#define QEMU_NET_SLIRP_H
+
+#include "qemu-common.h"
+#include "qdict.h"
+#include "qemu-option.h"
+
+#ifdef CONFIG_SLIRP
+
+int net_init_slirp(QemuOpts *opts,
+                   Monitor *mon,
+                   const char *name,
+                   VLANState *vlan);
+
+void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict);
+void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict);
+
+int net_slirp_redir(const char *redir_str);
+
+int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret);
+
+int net_slirp_smb(const char *exported_dir);
+
+void do_info_usernet(Monitor *mon);
+
+#endif
+
+#endif /* QEMU_NET_SLIRP_H */
diff --git a/vl.c b/vl.c
index ee43808..6038e2d 100644
--- a/vl.c
+++ b/vl.c
@@ -140,6 +140,7 @@ int main(int argc, char **argv)
 #include "hw/loader.h"
 #include "bt-host.h"
 #include "net.h"
+#include "net/slirp.h"
 #include "monitor.h"
 #include "console.h"
 #include "sysemu.h"
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 02/44] net: move vde code from net.c to net/vde.c
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 01/44] net: move slirp code from net.c to net/slirp.c Mark McLoughlin
@ 2009-11-25 18:48 ` Mark McLoughlin
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 03/44] net: move socket backend code from net.c to net/socket.c Mark McLoughlin
                   ` (41 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile  |    1 +
 net.c     |  102 +-------------------------------------------------
 net/vde.c |  124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/vde.h |   36 ++++++++++++++++++
 4 files changed, 162 insertions(+), 101 deletions(-)
 create mode 100644 net/vde.c
 create mode 100644 net/vde.h

diff --git a/Makefile b/Makefile
index 45362fa..ee00ecc 100644
--- a/Makefile
+++ b/Makefile
@@ -107,6 +107,7 @@ net-nested-$(CONFIG_BSD) += tap-bsd.o
 net-nested-$(CONFIG_SOLARIS) += tap-solaris.o
 net-nested-$(CONFIG_AIX) += tap-aix.o
 net-nested-$(CONFIG_SLIRP) += slirp.o
+net-nested-$(CONFIG_VDE) += vde.o
 net-obj-y += $(addprefix net/, $(net-nested-y))
 
 ######################################################################
diff --git a/net.c b/net.c
index 9b030a1..5f8457c 100644
--- a/net.c
+++ b/net.c
@@ -89,14 +89,11 @@
 #include <util.h>
 #endif
 
-#if defined(CONFIG_VDE)
-#include <libvdeplug.h>
-#endif
-
 #include "qemu-common.h"
 #include "net.h"
 #include "net/tap.h"
 #include "net/slirp.h"
+#include "net/vde.h"
 #include "monitor.h"
 #include "sysemu.h"
 #include "qemu-timer.h"
@@ -722,75 +719,6 @@ qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt)
     return qemu_sendv_packet_async(vc, iov, iovcnt, NULL);
 }
 
-#if defined(CONFIG_VDE)
-typedef struct VDEState {
-    VLANClientState *vc;
-    VDECONN *vde;
-} VDEState;
-
-static void vde_to_qemu(void *opaque)
-{
-    VDEState *s = opaque;
-    uint8_t buf[4096];
-    int size;
-
-    size = vde_recv(s->vde, (char *)buf, sizeof(buf), 0);
-    if (size > 0) {
-        qemu_send_packet(s->vc, buf, size);
-    }
-}
-
-static ssize_t vde_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
-{
-    VDEState *s = vc->opaque;
-    ssize_t ret;
-
-    do {
-      ret = vde_send(s->vde, (const char *)buf, size, 0);
-    } while (ret < 0 && errno == EINTR);
-
-    return ret;
-}
-
-static void vde_cleanup(VLANClientState *vc)
-{
-    VDEState *s = vc->opaque;
-    qemu_set_fd_handler(vde_datafd(s->vde), NULL, NULL, NULL);
-    vde_close(s->vde);
-    qemu_free(s);
-}
-
-static int net_vde_init(VLANState *vlan, const char *model,
-                        const char *name, const char *sock,
-                        int port, const char *group, int mode)
-{
-    VDEState *s;
-    char *init_group = (char *)group;
-    char *init_sock = (char *)sock;
-
-    struct vde_open_args args = {
-        .port = port,
-        .group = init_group,
-        .mode = mode,
-    };
-
-    s = qemu_mallocz(sizeof(VDEState));
-    s->vde = vde_open(init_sock, (char *)"QEMU", &args);
-    if (!s->vde){
-        free(s);
-        return -1;
-    }
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_VDE,
-                                 vlan, NULL, model, name, NULL,
-                                 vde_receive, NULL, NULL,
-                                 vde_cleanup, s);
-    qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
-             sock, vde_datafd(s->vde));
-    return 0;
-}
-#endif
-
 /* network connection */
 typedef struct NetSocketState {
     VLANClientState *vc;
@@ -1603,34 +1531,6 @@ static int net_init_socket(QemuOpts *opts,
     return 0;
 }
 
-#ifdef CONFIG_VDE
-static int net_init_vde(QemuOpts *opts,
-                        Monitor *mon,
-                        const char *name,
-                        VLANState *vlan)
-{
-    const char *sock;
-    const char *group;
-    int port, mode;
-
-    sock  = qemu_opt_get(opts, "sock");
-    group = qemu_opt_get(opts, "group");
-
-    port = qemu_opt_get_number(opts, "port", 0);
-    mode = qemu_opt_get_number(opts, "mode", 0700);
-
-    if (net_vde_init(vlan, "vde", name, sock, port, group, mode) == -1) {
-        return -1;
-    }
-
-    if (vlan) {
-        vlan->nb_host_devs++;
-    }
-
-    return 0;
-}
-#endif
-
 static int net_init_dump(QemuOpts *opts,
                          Monitor *mon,
                          const char *name,
diff --git a/net/vde.c b/net/vde.c
new file mode 100644
index 0000000..4d09967
--- /dev/null
+++ b/net/vde.c
@@ -0,0 +1,124 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "net/vde.h"
+
+#include "config-host.h"
+
+#include <libvdeplug.h>
+
+#include "net.h"
+#include "qemu-char.h"
+#include "qemu-common.h"
+#include "qemu-option.h"
+#include "sysemu.h"
+
+typedef struct VDEState {
+    VLANClientState *vc;
+    VDECONN *vde;
+} VDEState;
+
+static void vde_to_qemu(void *opaque)
+{
+    VDEState *s = opaque;
+    uint8_t buf[4096];
+    int size;
+
+    size = vde_recv(s->vde, (char *)buf, sizeof(buf), 0);
+    if (size > 0) {
+        qemu_send_packet(s->vc, buf, size);
+    }
+}
+
+static ssize_t vde_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+{
+    VDEState *s = vc->opaque;
+    ssize_t ret;
+
+    do {
+      ret = vde_send(s->vde, (const char *)buf, size, 0);
+    } while (ret < 0 && errno == EINTR);
+
+    return ret;
+}
+
+static void vde_cleanup(VLANClientState *vc)
+{
+    VDEState *s = vc->opaque;
+    qemu_set_fd_handler(vde_datafd(s->vde), NULL, NULL, NULL);
+    vde_close(s->vde);
+    qemu_free(s);
+}
+
+static int net_vde_init(VLANState *vlan, const char *model,
+                        const char *name, const char *sock,
+                        int port, const char *group, int mode)
+{
+    VDEState *s;
+    char *init_group = (char *)group;
+    char *init_sock = (char *)sock;
+
+    struct vde_open_args args = {
+        .port = port,
+        .group = init_group,
+        .mode = mode,
+    };
+
+    s = qemu_mallocz(sizeof(VDEState));
+    s->vde = vde_open(init_sock, (char *)"QEMU", &args);
+    if (!s->vde){
+        free(s);
+        return -1;
+    }
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_VDE,
+                                 vlan, NULL, model, name, NULL,
+                                 vde_receive, NULL, NULL,
+                                 vde_cleanup, s);
+    qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
+    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
+             sock, vde_datafd(s->vde));
+    return 0;
+}
+
+int net_init_vde(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)
+{
+    const char *sock;
+    const char *group;
+    int port, mode;
+
+    sock  = qemu_opt_get(opts, "sock");
+    group = qemu_opt_get(opts, "group");
+
+    port = qemu_opt_get_number(opts, "port", 0);
+    mode = qemu_opt_get_number(opts, "mode", 0700);
+
+    if (net_vde_init(vlan, "vde", name, sock, port, group, mode) == -1) {
+        return -1;
+    }
+
+    if (vlan) {
+        vlan->nb_host_devs++;
+    }
+
+    return 0;
+}
diff --git a/net/vde.h b/net/vde.h
new file mode 100644
index 0000000..3e6ca3e
--- /dev/null
+++ b/net/vde.h
@@ -0,0 +1,36 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef QEMU_NET_VDE_H
+#define QEMU_NET_VDE_H
+
+#include "qemu-common.h"
+#include "qemu-option.h"
+
+#ifdef CONFIG_VDE
+
+int net_init_vde(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan);
+
+#endif /* CONFIG_VDE */
+
+#endif /* QEMU_NET_VDE_H */
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 03/44] net: move socket backend code from net.c to net/socket.c
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 01/44] net: move slirp code from net.c to net/slirp.c Mark McLoughlin
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 02/44] net: move vde code from net.c to net/vde.c Mark McLoughlin
@ 2009-11-25 18:48 ` Mark McLoughlin
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 04/44] net: move dump backend code from net.c to net/dump.c Mark McLoughlin
                   ` (40 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile     |    1 +
 net.c        |  530 +------------------------------------------------------
 net/socket.c |  561 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/socket.h |   33 ++++
 4 files changed, 596 insertions(+), 529 deletions(-)
 create mode 100644 net/socket.c
 create mode 100644 net/socket.h

diff --git a/Makefile b/Makefile
index ee00ecc..fa1070d 100644
--- a/Makefile
+++ b/Makefile
@@ -100,6 +100,7 @@ block-obj-y +=  $(addprefix block/, $(block-nested-y))
 
 net-obj-y = net.o
 net-nested-y = queue.o checksum.o
+net-nested-y += socket.o
 net-nested-$(CONFIG_POSIX) += tap.o
 net-nested-$(CONFIG_LINUX) += tap-linux.o
 net-nested-$(CONFIG_WIN32) += tap-win32.o
diff --git a/net.c b/net.c
index 5f8457c..3b3f3d6 100644
--- a/net.c
+++ b/net.c
@@ -92,6 +92,7 @@
 #include "qemu-common.h"
 #include "net.h"
 #include "net/tap.h"
+#include "net/socket.h"
 #include "net/slirp.h"
 #include "net/vde.h"
 #include "monitor.h"
@@ -719,454 +720,6 @@ qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt)
     return qemu_sendv_packet_async(vc, iov, iovcnt, NULL);
 }
 
-/* network connection */
-typedef struct NetSocketState {
-    VLANClientState *vc;
-    int fd;
-    int state; /* 0 = getting length, 1 = getting data */
-    unsigned int index;
-    unsigned int packet_len;
-    uint8_t buf[4096];
-    struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */
-} NetSocketState;
-
-typedef struct NetSocketListenState {
-    VLANState *vlan;
-    char *model;
-    char *name;
-    int fd;
-} NetSocketListenState;
-
-/* XXX: we consider we can send the whole packet without blocking */
-static ssize_t net_socket_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
-{
-    NetSocketState *s = vc->opaque;
-    uint32_t len;
-    len = htonl(size);
-
-    send_all(s->fd, (const uint8_t *)&len, sizeof(len));
-    return send_all(s->fd, buf, size);
-}
-
-static ssize_t net_socket_receive_dgram(VLANClientState *vc, const uint8_t *buf, size_t size)
-{
-    NetSocketState *s = vc->opaque;
-
-    return sendto(s->fd, (const void *)buf, size, 0,
-                  (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst));
-}
-
-static void net_socket_send(void *opaque)
-{
-    NetSocketState *s = opaque;
-    int size, err;
-    unsigned l;
-    uint8_t buf1[4096];
-    const uint8_t *buf;
-
-    size = recv(s->fd, (void *)buf1, sizeof(buf1), 0);
-    if (size < 0) {
-        err = socket_error();
-        if (err != EWOULDBLOCK)
-            goto eoc;
-    } else if (size == 0) {
-        /* end of connection */
-    eoc:
-        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
-        closesocket(s->fd);
-        return;
-    }
-    buf = buf1;
-    while (size > 0) {
-        /* reassemble a packet from the network */
-        switch(s->state) {
-        case 0:
-            l = 4 - s->index;
-            if (l > size)
-                l = size;
-            memcpy(s->buf + s->index, buf, l);
-            buf += l;
-            size -= l;
-            s->index += l;
-            if (s->index == 4) {
-                /* got length */
-                s->packet_len = ntohl(*(uint32_t *)s->buf);
-                s->index = 0;
-                s->state = 1;
-            }
-            break;
-        case 1:
-            l = s->packet_len - s->index;
-            if (l > size)
-                l = size;
-            if (s->index + l <= sizeof(s->buf)) {
-                memcpy(s->buf + s->index, buf, l);
-            } else {
-                fprintf(stderr, "serious error: oversized packet received,"
-                    "connection terminated.\n");
-                s->state = 0;
-                goto eoc;
-            }
-
-            s->index += l;
-            buf += l;
-            size -= l;
-            if (s->index >= s->packet_len) {
-                qemu_send_packet(s->vc, s->buf, s->packet_len);
-                s->index = 0;
-                s->state = 0;
-            }
-            break;
-        }
-    }
-}
-
-static void net_socket_send_dgram(void *opaque)
-{
-    NetSocketState *s = opaque;
-    int size;
-
-    size = recv(s->fd, (void *)s->buf, sizeof(s->buf), 0);
-    if (size < 0)
-        return;
-    if (size == 0) {
-        /* end of connection */
-        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
-        return;
-    }
-    qemu_send_packet(s->vc, s->buf, size);
-}
-
-static int net_socket_mcast_create(struct sockaddr_in *mcastaddr)
-{
-    struct ip_mreq imr;
-    int fd;
-    int val, ret;
-    if (!IN_MULTICAST(ntohl(mcastaddr->sin_addr.s_addr))) {
-	fprintf(stderr, "qemu: error: specified mcastaddr \"%s\" (0x%08x) does not contain a multicast address\n",
-		inet_ntoa(mcastaddr->sin_addr),
-                (int)ntohl(mcastaddr->sin_addr.s_addr));
-	return -1;
-
-    }
-    fd = socket(PF_INET, SOCK_DGRAM, 0);
-    if (fd < 0) {
-        perror("socket(PF_INET, SOCK_DGRAM)");
-        return -1;
-    }
-
-    val = 1;
-    ret=setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
-                   (const char *)&val, sizeof(val));
-    if (ret < 0) {
-	perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)");
-	goto fail;
-    }
-
-    ret = bind(fd, (struct sockaddr *)mcastaddr, sizeof(*mcastaddr));
-    if (ret < 0) {
-        perror("bind");
-        goto fail;
-    }
-
-    /* Add host to multicast group */
-    imr.imr_multiaddr = mcastaddr->sin_addr;
-    imr.imr_interface.s_addr = htonl(INADDR_ANY);
-
-    ret = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
-                     (const char *)&imr, sizeof(struct ip_mreq));
-    if (ret < 0) {
-	perror("setsockopt(IP_ADD_MEMBERSHIP)");
-	goto fail;
-    }
-
-    /* Force mcast msgs to loopback (eg. several QEMUs in same host */
-    val = 1;
-    ret=setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
-                   (const char *)&val, sizeof(val));
-    if (ret < 0) {
-	perror("setsockopt(SOL_IP, IP_MULTICAST_LOOP)");
-	goto fail;
-    }
-
-    socket_set_nonblock(fd);
-    return fd;
-fail:
-    if (fd >= 0)
-        closesocket(fd);
-    return -1;
-}
-
-static void net_socket_cleanup(VLANClientState *vc)
-{
-    NetSocketState *s = vc->opaque;
-    qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
-    close(s->fd);
-    qemu_free(s);
-}
-
-static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
-                                                const char *model,
-                                                const char *name,
-                                                int fd, int is_connected)
-{
-    struct sockaddr_in saddr;
-    int newfd;
-    socklen_t saddr_len;
-    NetSocketState *s;
-
-    /* fd passed: multicast: "learn" dgram_dst address from bound address and save it
-     * Because this may be "shared" socket from a "master" process, datagrams would be recv()
-     * by ONLY ONE process: we must "clone" this dgram socket --jjo
-     */
-
-    if (is_connected) {
-	if (getsockname(fd, (struct sockaddr *) &saddr, &saddr_len) == 0) {
-	    /* must be bound */
-	    if (saddr.sin_addr.s_addr==0) {
-		fprintf(stderr, "qemu: error: init_dgram: fd=%d unbound, cannot setup multicast dst addr\n",
-			fd);
-		return NULL;
-	    }
-	    /* clone dgram socket */
-	    newfd = net_socket_mcast_create(&saddr);
-	    if (newfd < 0) {
-		/* error already reported by net_socket_mcast_create() */
-		close(fd);
-		return NULL;
-	    }
-	    /* clone newfd to fd, close newfd */
-	    dup2(newfd, fd);
-	    close(newfd);
-
-	} else {
-	    fprintf(stderr, "qemu: error: init_dgram: fd=%d failed getsockname(): %s\n",
-		    fd, strerror(errno));
-	    return NULL;
-	}
-    }
-
-    s = qemu_mallocz(sizeof(NetSocketState));
-    s->fd = fd;
-
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SOCKET,
-                                 vlan, NULL, model, name, NULL,
-                                 net_socket_receive_dgram, NULL, NULL,
-                                 net_socket_cleanup, s);
-    qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
-
-    /* mcast: save bound address as dst */
-    if (is_connected) s->dgram_dst=saddr;
-
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-	    "socket: fd=%d (%s mcast=%s:%d)",
-	    fd, is_connected? "cloned" : "",
-	    inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
-    return s;
-}
-
-static void net_socket_connect(void *opaque)
-{
-    NetSocketState *s = opaque;
-    qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
-}
-
-static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
-                                                 const char *model,
-                                                 const char *name,
-                                                 int fd, int is_connected)
-{
-    NetSocketState *s;
-    s = qemu_mallocz(sizeof(NetSocketState));
-    s->fd = fd;
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SOCKET,
-                                 vlan, NULL, model, name, NULL,
-                                 net_socket_receive, NULL, NULL,
-                                 net_socket_cleanup, s);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "socket: fd=%d", fd);
-    if (is_connected) {
-        net_socket_connect(s);
-    } else {
-        qemu_set_fd_handler(s->fd, NULL, net_socket_connect, s);
-    }
-    return s;
-}
-
-static NetSocketState *net_socket_fd_init(VLANState *vlan,
-                                          const char *model, const char *name,
-                                          int fd, int is_connected)
-{
-    int so_type = -1, optlen=sizeof(so_type);
-
-    if(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&so_type,
-        (socklen_t *)&optlen)< 0) {
-	fprintf(stderr, "qemu: error: getsockopt(SO_TYPE) for fd=%d failed\n", fd);
-	return NULL;
-    }
-    switch(so_type) {
-    case SOCK_DGRAM:
-        return net_socket_fd_init_dgram(vlan, model, name, fd, is_connected);
-    case SOCK_STREAM:
-        return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
-    default:
-        /* who knows ... this could be a eg. a pty, do warn and continue as stream */
-        fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
-        return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
-    }
-    return NULL;
-}
-
-static void net_socket_accept(void *opaque)
-{
-    NetSocketListenState *s = opaque;
-    NetSocketState *s1;
-    struct sockaddr_in saddr;
-    socklen_t len;
-    int fd;
-
-    for(;;) {
-        len = sizeof(saddr);
-        fd = accept(s->fd, (struct sockaddr *)&saddr, &len);
-        if (fd < 0 && errno != EINTR) {
-            return;
-        } else if (fd >= 0) {
-            break;
-        }
-    }
-    s1 = net_socket_fd_init(s->vlan, s->model, s->name, fd, 1);
-    if (!s1) {
-        closesocket(fd);
-    } else {
-        snprintf(s1->vc->info_str, sizeof(s1->vc->info_str),
-                 "socket: connection from %s:%d",
-                 inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
-    }
-}
-
-static int net_socket_listen_init(VLANState *vlan,
-                                  const char *model,
-                                  const char *name,
-                                  const char *host_str)
-{
-    NetSocketListenState *s;
-    int fd, val, ret;
-    struct sockaddr_in saddr;
-
-    if (parse_host_port(&saddr, host_str) < 0)
-        return -1;
-
-    s = qemu_mallocz(sizeof(NetSocketListenState));
-
-    fd = socket(PF_INET, SOCK_STREAM, 0);
-    if (fd < 0) {
-        perror("socket");
-        return -1;
-    }
-    socket_set_nonblock(fd);
-
-    /* allow fast reuse */
-    val = 1;
-    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&val, sizeof(val));
-
-    ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr));
-    if (ret < 0) {
-        perror("bind");
-        return -1;
-    }
-    ret = listen(fd, 0);
-    if (ret < 0) {
-        perror("listen");
-        return -1;
-    }
-    s->vlan = vlan;
-    s->model = qemu_strdup(model);
-    s->name = name ? qemu_strdup(name) : NULL;
-    s->fd = fd;
-    qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
-    return 0;
-}
-
-static int net_socket_connect_init(VLANState *vlan,
-                                   const char *model,
-                                   const char *name,
-                                   const char *host_str)
-{
-    NetSocketState *s;
-    int fd, connected, ret, err;
-    struct sockaddr_in saddr;
-
-    if (parse_host_port(&saddr, host_str) < 0)
-        return -1;
-
-    fd = socket(PF_INET, SOCK_STREAM, 0);
-    if (fd < 0) {
-        perror("socket");
-        return -1;
-    }
-    socket_set_nonblock(fd);
-
-    connected = 0;
-    for(;;) {
-        ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));
-        if (ret < 0) {
-            err = socket_error();
-            if (err == EINTR || err == EWOULDBLOCK) {
-            } else if (err == EINPROGRESS) {
-                break;
-#ifdef _WIN32
-            } else if (err == WSAEALREADY) {
-                break;
-#endif
-            } else {
-                perror("connect");
-                closesocket(fd);
-                return -1;
-            }
-        } else {
-            connected = 1;
-            break;
-        }
-    }
-    s = net_socket_fd_init(vlan, model, name, fd, connected);
-    if (!s)
-        return -1;
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "socket: connect to %s:%d",
-             inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
-    return 0;
-}
-
-static int net_socket_mcast_init(VLANState *vlan,
-                                 const char *model,
-                                 const char *name,
-                                 const char *host_str)
-{
-    NetSocketState *s;
-    int fd;
-    struct sockaddr_in saddr;
-
-    if (parse_host_port(&saddr, host_str) < 0)
-        return -1;
-
-
-    fd = net_socket_mcast_create(&saddr);
-    if (fd < 0)
-	return -1;
-
-    s = net_socket_fd_init(vlan, model, name, fd, 0);
-    if (!s)
-        return -1;
-
-    s->dgram_dst = saddr;
-
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "socket: mcast=%s:%d",
-             inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
-    return 0;
-
-}
-
 typedef struct DumpState {
     VLANClientState *pcap_vc;
     int fd;
@@ -1450,87 +1003,6 @@ static int net_init_nic(QemuOpts *opts,
     return idx;
 }
 
-static int net_init_socket(QemuOpts *opts,
-                           Monitor *mon,
-                           const char *name,
-                           VLANState *vlan)
-{
-    if (qemu_opt_get(opts, "fd")) {
-        int fd;
-
-        if (qemu_opt_get(opts, "listen") ||
-            qemu_opt_get(opts, "connect") ||
-            qemu_opt_get(opts, "mcast")) {
-            qemu_error("listen=, connect= and mcast= is invalid with fd=\n");
-            return -1;
-        }
-
-        fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd"));
-        if (fd == -1) {
-            return -1;
-        }
-
-        if (!net_socket_fd_init(vlan, "socket", name, fd, 1)) {
-            close(fd);
-            return -1;
-        }
-    } else if (qemu_opt_get(opts, "listen")) {
-        const char *listen;
-
-        if (qemu_opt_get(opts, "fd") ||
-            qemu_opt_get(opts, "connect") ||
-            qemu_opt_get(opts, "mcast")) {
-            qemu_error("fd=, connect= and mcast= is invalid with listen=\n");
-            return -1;
-        }
-
-        listen = qemu_opt_get(opts, "listen");
-
-        if (net_socket_listen_init(vlan, "socket", name, listen) == -1) {
-            return -1;
-        }
-    } else if (qemu_opt_get(opts, "connect")) {
-        const char *connect;
-
-        if (qemu_opt_get(opts, "fd") ||
-            qemu_opt_get(opts, "listen") ||
-            qemu_opt_get(opts, "mcast")) {
-            qemu_error("fd=, listen= and mcast= is invalid with connect=\n");
-            return -1;
-        }
-
-        connect = qemu_opt_get(opts, "connect");
-
-        if (net_socket_connect_init(vlan, "socket", name, connect) == -1) {
-            return -1;
-        }
-    } else if (qemu_opt_get(opts, "mcast")) {
-        const char *mcast;
-
-        if (qemu_opt_get(opts, "fd") ||
-            qemu_opt_get(opts, "connect") ||
-            qemu_opt_get(opts, "listen")) {
-            qemu_error("fd=, connect= and listen= is invalid with mcast=\n");
-            return -1;
-        }
-
-        mcast = qemu_opt_get(opts, "mcast");
-
-        if (net_socket_mcast_init(vlan, "socket", name, mcast) == -1) {
-            return -1;
-        }
-    } else {
-        qemu_error("-socket requires fd=, listen=, connect= or mcast=\n");
-        return -1;
-    }
-
-    if (vlan) {
-        vlan->nb_host_devs++;
-    }
-
-    return 0;
-}
-
 static int net_init_dump(QemuOpts *opts,
                          Monitor *mon,
                          const char *name,
diff --git a/net/socket.c b/net/socket.c
new file mode 100644
index 0000000..551fc2b
--- /dev/null
+++ b/net/socket.c
@@ -0,0 +1,561 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "net/socket.h"
+
+#include "config-host.h"
+
+#include "net.h"
+#include "qemu-char.h"
+#include "qemu-common.h"
+#include "qemu-option.h"
+#include "qemu_socket.h"
+#include "sysemu.h"
+
+typedef struct NetSocketState {
+    VLANClientState *vc;
+    int fd;
+    int state; /* 0 = getting length, 1 = getting data */
+    unsigned int index;
+    unsigned int packet_len;
+    uint8_t buf[4096];
+    struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */
+} NetSocketState;
+
+typedef struct NetSocketListenState {
+    VLANState *vlan;
+    char *model;
+    char *name;
+    int fd;
+} NetSocketListenState;
+
+/* XXX: we consider we can send the whole packet without blocking */
+static ssize_t net_socket_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+{
+    NetSocketState *s = vc->opaque;
+    uint32_t len;
+    len = htonl(size);
+
+    send_all(s->fd, (const uint8_t *)&len, sizeof(len));
+    return send_all(s->fd, buf, size);
+}
+
+static ssize_t net_socket_receive_dgram(VLANClientState *vc, const uint8_t *buf, size_t size)
+{
+    NetSocketState *s = vc->opaque;
+
+    return sendto(s->fd, (const void *)buf, size, 0,
+                  (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst));
+}
+
+static void net_socket_send(void *opaque)
+{
+    NetSocketState *s = opaque;
+    int size, err;
+    unsigned l;
+    uint8_t buf1[4096];
+    const uint8_t *buf;
+
+    size = recv(s->fd, (void *)buf1, sizeof(buf1), 0);
+    if (size < 0) {
+        err = socket_error();
+        if (err != EWOULDBLOCK)
+            goto eoc;
+    } else if (size == 0) {
+        /* end of connection */
+    eoc:
+        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+        closesocket(s->fd);
+        return;
+    }
+    buf = buf1;
+    while (size > 0) {
+        /* reassemble a packet from the network */
+        switch(s->state) {
+        case 0:
+            l = 4 - s->index;
+            if (l > size)
+                l = size;
+            memcpy(s->buf + s->index, buf, l);
+            buf += l;
+            size -= l;
+            s->index += l;
+            if (s->index == 4) {
+                /* got length */
+                s->packet_len = ntohl(*(uint32_t *)s->buf);
+                s->index = 0;
+                s->state = 1;
+            }
+            break;
+        case 1:
+            l = s->packet_len - s->index;
+            if (l > size)
+                l = size;
+            if (s->index + l <= sizeof(s->buf)) {
+                memcpy(s->buf + s->index, buf, l);
+            } else {
+                fprintf(stderr, "serious error: oversized packet received,"
+                    "connection terminated.\n");
+                s->state = 0;
+                goto eoc;
+            }
+
+            s->index += l;
+            buf += l;
+            size -= l;
+            if (s->index >= s->packet_len) {
+                qemu_send_packet(s->vc, s->buf, s->packet_len);
+                s->index = 0;
+                s->state = 0;
+            }
+            break;
+        }
+    }
+}
+
+static void net_socket_send_dgram(void *opaque)
+{
+    NetSocketState *s = opaque;
+    int size;
+
+    size = recv(s->fd, (void *)s->buf, sizeof(s->buf), 0);
+    if (size < 0)
+        return;
+    if (size == 0) {
+        /* end of connection */
+        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+        return;
+    }
+    qemu_send_packet(s->vc, s->buf, size);
+}
+
+static int net_socket_mcast_create(struct sockaddr_in *mcastaddr)
+{
+    struct ip_mreq imr;
+    int fd;
+    int val, ret;
+    if (!IN_MULTICAST(ntohl(mcastaddr->sin_addr.s_addr))) {
+	fprintf(stderr, "qemu: error: specified mcastaddr \"%s\" (0x%08x) does not contain a multicast address\n",
+		inet_ntoa(mcastaddr->sin_addr),
+                (int)ntohl(mcastaddr->sin_addr.s_addr));
+	return -1;
+
+    }
+    fd = socket(PF_INET, SOCK_DGRAM, 0);
+    if (fd < 0) {
+        perror("socket(PF_INET, SOCK_DGRAM)");
+        return -1;
+    }
+
+    val = 1;
+    ret=setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
+                   (const char *)&val, sizeof(val));
+    if (ret < 0) {
+	perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)");
+	goto fail;
+    }
+
+    ret = bind(fd, (struct sockaddr *)mcastaddr, sizeof(*mcastaddr));
+    if (ret < 0) {
+        perror("bind");
+        goto fail;
+    }
+
+    /* Add host to multicast group */
+    imr.imr_multiaddr = mcastaddr->sin_addr;
+    imr.imr_interface.s_addr = htonl(INADDR_ANY);
+
+    ret = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+                     (const char *)&imr, sizeof(struct ip_mreq));
+    if (ret < 0) {
+	perror("setsockopt(IP_ADD_MEMBERSHIP)");
+	goto fail;
+    }
+
+    /* Force mcast msgs to loopback (eg. several QEMUs in same host */
+    val = 1;
+    ret=setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
+                   (const char *)&val, sizeof(val));
+    if (ret < 0) {
+	perror("setsockopt(SOL_IP, IP_MULTICAST_LOOP)");
+	goto fail;
+    }
+
+    socket_set_nonblock(fd);
+    return fd;
+fail:
+    if (fd >= 0)
+        closesocket(fd);
+    return -1;
+}
+
+static void net_socket_cleanup(VLANClientState *vc)
+{
+    NetSocketState *s = vc->opaque;
+    qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+    close(s->fd);
+    qemu_free(s);
+}
+
+static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
+                                                const char *model,
+                                                const char *name,
+                                                int fd, int is_connected)
+{
+    struct sockaddr_in saddr;
+    int newfd;
+    socklen_t saddr_len;
+    NetSocketState *s;
+
+    /* fd passed: multicast: "learn" dgram_dst address from bound address and save it
+     * Because this may be "shared" socket from a "master" process, datagrams would be recv()
+     * by ONLY ONE process: we must "clone" this dgram socket --jjo
+     */
+
+    if (is_connected) {
+	if (getsockname(fd, (struct sockaddr *) &saddr, &saddr_len) == 0) {
+	    /* must be bound */
+	    if (saddr.sin_addr.s_addr==0) {
+		fprintf(stderr, "qemu: error: init_dgram: fd=%d unbound, cannot setup multicast dst addr\n",
+			fd);
+		return NULL;
+	    }
+	    /* clone dgram socket */
+	    newfd = net_socket_mcast_create(&saddr);
+	    if (newfd < 0) {
+		/* error already reported by net_socket_mcast_create() */
+		close(fd);
+		return NULL;
+	    }
+	    /* clone newfd to fd, close newfd */
+	    dup2(newfd, fd);
+	    close(newfd);
+
+	} else {
+	    fprintf(stderr, "qemu: error: init_dgram: fd=%d failed getsockname(): %s\n",
+		    fd, strerror(errno));
+	    return NULL;
+	}
+    }
+
+    s = qemu_mallocz(sizeof(NetSocketState));
+    s->fd = fd;
+
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SOCKET,
+                                 vlan, NULL, model, name, NULL,
+                                 net_socket_receive_dgram, NULL, NULL,
+                                 net_socket_cleanup, s);
+    qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
+
+    /* mcast: save bound address as dst */
+    if (is_connected) s->dgram_dst=saddr;
+
+    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
+	    "socket: fd=%d (%s mcast=%s:%d)",
+	    fd, is_connected? "cloned" : "",
+	    inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+    return s;
+}
+
+static void net_socket_connect(void *opaque)
+{
+    NetSocketState *s = opaque;
+    qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
+}
+
+static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
+                                                 const char *model,
+                                                 const char *name,
+                                                 int fd, int is_connected)
+{
+    NetSocketState *s;
+    s = qemu_mallocz(sizeof(NetSocketState));
+    s->fd = fd;
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SOCKET,
+                                 vlan, NULL, model, name, NULL,
+                                 net_socket_receive, NULL, NULL,
+                                 net_socket_cleanup, s);
+    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
+             "socket: fd=%d", fd);
+    if (is_connected) {
+        net_socket_connect(s);
+    } else {
+        qemu_set_fd_handler(s->fd, NULL, net_socket_connect, s);
+    }
+    return s;
+}
+
+static NetSocketState *net_socket_fd_init(VLANState *vlan,
+                                          const char *model, const char *name,
+                                          int fd, int is_connected)
+{
+    int so_type = -1, optlen=sizeof(so_type);
+
+    if(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&so_type,
+        (socklen_t *)&optlen)< 0) {
+	fprintf(stderr, "qemu: error: getsockopt(SO_TYPE) for fd=%d failed\n", fd);
+	return NULL;
+    }
+    switch(so_type) {
+    case SOCK_DGRAM:
+        return net_socket_fd_init_dgram(vlan, model, name, fd, is_connected);
+    case SOCK_STREAM:
+        return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
+    default:
+        /* who knows ... this could be a eg. a pty, do warn and continue as stream */
+        fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
+        return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
+    }
+    return NULL;
+}
+
+static void net_socket_accept(void *opaque)
+{
+    NetSocketListenState *s = opaque;
+    NetSocketState *s1;
+    struct sockaddr_in saddr;
+    socklen_t len;
+    int fd;
+
+    for(;;) {
+        len = sizeof(saddr);
+        fd = accept(s->fd, (struct sockaddr *)&saddr, &len);
+        if (fd < 0 && errno != EINTR) {
+            return;
+        } else if (fd >= 0) {
+            break;
+        }
+    }
+    s1 = net_socket_fd_init(s->vlan, s->model, s->name, fd, 1);
+    if (!s1) {
+        closesocket(fd);
+    } else {
+        snprintf(s1->vc->info_str, sizeof(s1->vc->info_str),
+                 "socket: connection from %s:%d",
+                 inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+    }
+}
+
+static int net_socket_listen_init(VLANState *vlan,
+                                  const char *model,
+                                  const char *name,
+                                  const char *host_str)
+{
+    NetSocketListenState *s;
+    int fd, val, ret;
+    struct sockaddr_in saddr;
+
+    if (parse_host_port(&saddr, host_str) < 0)
+        return -1;
+
+    s = qemu_mallocz(sizeof(NetSocketListenState));
+
+    fd = socket(PF_INET, SOCK_STREAM, 0);
+    if (fd < 0) {
+        perror("socket");
+        return -1;
+    }
+    socket_set_nonblock(fd);
+
+    /* allow fast reuse */
+    val = 1;
+    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&val, sizeof(val));
+
+    ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr));
+    if (ret < 0) {
+        perror("bind");
+        return -1;
+    }
+    ret = listen(fd, 0);
+    if (ret < 0) {
+        perror("listen");
+        return -1;
+    }
+    s->vlan = vlan;
+    s->model = qemu_strdup(model);
+    s->name = name ? qemu_strdup(name) : NULL;
+    s->fd = fd;
+    qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
+    return 0;
+}
+
+static int net_socket_connect_init(VLANState *vlan,
+                                   const char *model,
+                                   const char *name,
+                                   const char *host_str)
+{
+    NetSocketState *s;
+    int fd, connected, ret, err;
+    struct sockaddr_in saddr;
+
+    if (parse_host_port(&saddr, host_str) < 0)
+        return -1;
+
+    fd = socket(PF_INET, SOCK_STREAM, 0);
+    if (fd < 0) {
+        perror("socket");
+        return -1;
+    }
+    socket_set_nonblock(fd);
+
+    connected = 0;
+    for(;;) {
+        ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));
+        if (ret < 0) {
+            err = socket_error();
+            if (err == EINTR || err == EWOULDBLOCK) {
+            } else if (err == EINPROGRESS) {
+                break;
+#ifdef _WIN32
+            } else if (err == WSAEALREADY) {
+                break;
+#endif
+            } else {
+                perror("connect");
+                closesocket(fd);
+                return -1;
+            }
+        } else {
+            connected = 1;
+            break;
+        }
+    }
+    s = net_socket_fd_init(vlan, model, name, fd, connected);
+    if (!s)
+        return -1;
+    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
+             "socket: connect to %s:%d",
+             inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+    return 0;
+}
+
+static int net_socket_mcast_init(VLANState *vlan,
+                                 const char *model,
+                                 const char *name,
+                                 const char *host_str)
+{
+    NetSocketState *s;
+    int fd;
+    struct sockaddr_in saddr;
+
+    if (parse_host_port(&saddr, host_str) < 0)
+        return -1;
+
+
+    fd = net_socket_mcast_create(&saddr);
+    if (fd < 0)
+	return -1;
+
+    s = net_socket_fd_init(vlan, model, name, fd, 0);
+    if (!s)
+        return -1;
+
+    s->dgram_dst = saddr;
+
+    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
+             "socket: mcast=%s:%d",
+             inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+    return 0;
+
+}
+
+int net_init_socket(QemuOpts *opts,
+                    Monitor *mon,
+                    const char *name,
+                    VLANState *vlan)
+{
+    if (qemu_opt_get(opts, "fd")) {
+        int fd;
+
+        if (qemu_opt_get(opts, "listen") ||
+            qemu_opt_get(opts, "connect") ||
+            qemu_opt_get(opts, "mcast")) {
+            qemu_error("listen=, connect= and mcast= is invalid with fd=\n");
+            return -1;
+        }
+
+        fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd"));
+        if (fd == -1) {
+            return -1;
+        }
+
+        if (!net_socket_fd_init(vlan, "socket", name, fd, 1)) {
+            close(fd);
+            return -1;
+        }
+    } else if (qemu_opt_get(opts, "listen")) {
+        const char *listen;
+
+        if (qemu_opt_get(opts, "fd") ||
+            qemu_opt_get(opts, "connect") ||
+            qemu_opt_get(opts, "mcast")) {
+            qemu_error("fd=, connect= and mcast= is invalid with listen=\n");
+            return -1;
+        }
+
+        listen = qemu_opt_get(opts, "listen");
+
+        if (net_socket_listen_init(vlan, "socket", name, listen) == -1) {
+            return -1;
+        }
+    } else if (qemu_opt_get(opts, "connect")) {
+        const char *connect;
+
+        if (qemu_opt_get(opts, "fd") ||
+            qemu_opt_get(opts, "listen") ||
+            qemu_opt_get(opts, "mcast")) {
+            qemu_error("fd=, listen= and mcast= is invalid with connect=\n");
+            return -1;
+        }
+
+        connect = qemu_opt_get(opts, "connect");
+
+        if (net_socket_connect_init(vlan, "socket", name, connect) == -1) {
+            return -1;
+        }
+    } else if (qemu_opt_get(opts, "mcast")) {
+        const char *mcast;
+
+        if (qemu_opt_get(opts, "fd") ||
+            qemu_opt_get(opts, "connect") ||
+            qemu_opt_get(opts, "listen")) {
+            qemu_error("fd=, connect= and listen= is invalid with mcast=\n");
+            return -1;
+        }
+
+        mcast = qemu_opt_get(opts, "mcast");
+
+        if (net_socket_mcast_init(vlan, "socket", name, mcast) == -1) {
+            return -1;
+        }
+    } else {
+        qemu_error("-socket requires fd=, listen=, connect= or mcast=\n");
+        return -1;
+    }
+
+    if (vlan) {
+        vlan->nb_host_devs++;
+    }
+
+    return 0;
+}
diff --git a/net/socket.h b/net/socket.h
new file mode 100644
index 0000000..ea46f02
--- /dev/null
+++ b/net/socket.h
@@ -0,0 +1,33 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef QEMU_NET_SOCKET_H
+#define QEMU_NET_SOCKET_H
+
+#include "net.h"
+#include "qemu-common.h"
+
+int net_init_socket(QemuOpts *opts, Monitor *mon,
+                    const char *name, VLANState *vlan);
+
+#endif /* QEMU_NET_SOCKET_H */
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 04/44] net: move dump backend code from net.c to net/dump.c
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (2 preceding siblings ...)
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 03/44] net: move socket backend code from net.c to net/socket.c Mark McLoughlin
@ 2009-11-25 18:48 ` Mark McLoughlin
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 05/44] net: clean up includes in net.c Mark McLoughlin
                   ` (39 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile   |    1 +
 net.c      |  127 +--------------------------------------------------
 net/dump.c |  151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/dump.h |   33 +++++++++++++
 4 files changed, 186 insertions(+), 126 deletions(-)
 create mode 100644 net/dump.c
 create mode 100644 net/dump.h

diff --git a/Makefile b/Makefile
index fa1070d..6ed4bf8 100644
--- a/Makefile
+++ b/Makefile
@@ -101,6 +101,7 @@ block-obj-y +=  $(addprefix block/, $(block-nested-y))
 net-obj-y = net.o
 net-nested-y = queue.o checksum.o
 net-nested-y += socket.o
+net-nested-y += dump.o
 net-nested-$(CONFIG_POSIX) += tap.o
 net-nested-$(CONFIG_LINUX) += tap-linux.o
 net-nested-$(CONFIG_WIN32) += tap-win32.o
diff --git a/net.c b/net.c
index 3b3f3d6..5667485 100644
--- a/net.c
+++ b/net.c
@@ -93,6 +93,7 @@
 #include "net.h"
 #include "net/tap.h"
 #include "net/socket.h"
+#include "net/dump.h"
 #include "net/slirp.h"
 #include "net/vde.h"
 #include "monitor.h"
@@ -720,110 +721,6 @@ qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt)
     return qemu_sendv_packet_async(vc, iov, iovcnt, NULL);
 }
 
-typedef struct DumpState {
-    VLANClientState *pcap_vc;
-    int fd;
-    int pcap_caplen;
-} DumpState;
-
-#define PCAP_MAGIC 0xa1b2c3d4
-
-struct pcap_file_hdr {
-    uint32_t magic;
-    uint16_t version_major;
-    uint16_t version_minor;
-    int32_t thiszone;
-    uint32_t sigfigs;
-    uint32_t snaplen;
-    uint32_t linktype;
-};
-
-struct pcap_sf_pkthdr {
-    struct {
-        int32_t tv_sec;
-        int32_t tv_usec;
-    } ts;
-    uint32_t caplen;
-    uint32_t len;
-};
-
-static ssize_t dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
-{
-    DumpState *s = vc->opaque;
-    struct pcap_sf_pkthdr hdr;
-    int64_t ts;
-    int caplen;
-
-    /* Early return in case of previous error. */
-    if (s->fd < 0) {
-        return size;
-    }
-
-    ts = muldiv64(qemu_get_clock(vm_clock), 1000000, get_ticks_per_sec());
-    caplen = size > s->pcap_caplen ? s->pcap_caplen : size;
-
-    hdr.ts.tv_sec = ts / 1000000;
-    hdr.ts.tv_usec = ts % 1000000;
-    hdr.caplen = caplen;
-    hdr.len = size;
-    if (write(s->fd, &hdr, sizeof(hdr)) != sizeof(hdr) ||
-        write(s->fd, buf, caplen) != caplen) {
-        qemu_log("-net dump write error - stop dump\n");
-        close(s->fd);
-        s->fd = -1;
-    }
-
-    return size;
-}
-
-static void net_dump_cleanup(VLANClientState *vc)
-{
-    DumpState *s = vc->opaque;
-
-    close(s->fd);
-    qemu_free(s);
-}
-
-static int net_dump_init(VLANState *vlan, const char *device,
-                         const char *name, const char *filename, int len)
-{
-    struct pcap_file_hdr hdr;
-    DumpState *s;
-
-    s = qemu_malloc(sizeof(DumpState));
-
-    s->fd = open(filename, O_CREAT | O_WRONLY | O_BINARY, 0644);
-    if (s->fd < 0) {
-        qemu_error("-net dump: can't open %s\n", filename);
-        return -1;
-    }
-
-    s->pcap_caplen = len;
-
-    hdr.magic = PCAP_MAGIC;
-    hdr.version_major = 2;
-    hdr.version_minor = 4;
-    hdr.thiszone = 0;
-    hdr.sigfigs = 0;
-    hdr.snaplen = s->pcap_caplen;
-    hdr.linktype = 1;
-
-    if (write(s->fd, &hdr, sizeof(hdr)) < sizeof(hdr)) {
-        qemu_error("-net dump write error: %s\n", strerror(errno));
-        close(s->fd);
-        qemu_free(s);
-        return -1;
-    }
-
-    s->pcap_vc = qemu_new_vlan_client(NET_CLIENT_TYPE_DUMP,
-                                      vlan, NULL, device, name, NULL,
-                                      dump_receive, NULL, NULL,
-                                      net_dump_cleanup, s);
-    snprintf(s->pcap_vc->info_str, sizeof(s->pcap_vc->info_str),
-             "dump to %s (len=%d)", filename, len);
-    return 0;
-}
-
 /* find or alloc a new VLAN */
 VLANState *qemu_find_vlan(int id, int allocate)
 {
@@ -1003,28 +900,6 @@ static int net_init_nic(QemuOpts *opts,
     return idx;
 }
 
-static int net_init_dump(QemuOpts *opts,
-                         Monitor *mon,
-                         const char *name,
-                         VLANState *vlan)
-{
-    int len;
-    const char *file;
-    char def_file[128];
-
-    assert(vlan);
-
-    file = qemu_opt_get(opts, "file");
-    if (!file) {
-        snprintf(def_file, sizeof(def_file), "qemu-vlan%d.pcap", vlan->id);
-        file = def_file;
-    }
-
-    len = qemu_opt_get_size(opts, "len", 65536);
-
-    return net_dump_init(vlan, "dump", name, file, len);
-}
-
 #define NET_COMMON_PARAMS_DESC                     \
     {                                              \
         .name = "type",                            \
diff --git a/net/dump.c b/net/dump.c
new file mode 100644
index 0000000..05a102b
--- /dev/null
+++ b/net/dump.c
@@ -0,0 +1,151 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "dump.h"
+#include "qemu-common.h"
+#include "sysemu.h"
+#include "qemu-log.h"
+
+typedef struct DumpState {
+    VLANClientState *pcap_vc;
+    int fd;
+    int pcap_caplen;
+} DumpState;
+
+#define PCAP_MAGIC 0xa1b2c3d4
+
+struct pcap_file_hdr {
+    uint32_t magic;
+    uint16_t version_major;
+    uint16_t version_minor;
+    int32_t thiszone;
+    uint32_t sigfigs;
+    uint32_t snaplen;
+    uint32_t linktype;
+};
+
+struct pcap_sf_pkthdr {
+    struct {
+        int32_t tv_sec;
+        int32_t tv_usec;
+    } ts;
+    uint32_t caplen;
+    uint32_t len;
+};
+
+static ssize_t dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+{
+    DumpState *s = vc->opaque;
+    struct pcap_sf_pkthdr hdr;
+    int64_t ts;
+    int caplen;
+
+    /* Early return in case of previous error. */
+    if (s->fd < 0) {
+        return size;
+    }
+
+    ts = muldiv64(qemu_get_clock(vm_clock), 1000000, get_ticks_per_sec());
+    caplen = size > s->pcap_caplen ? s->pcap_caplen : size;
+
+    hdr.ts.tv_sec = ts / 1000000;
+    hdr.ts.tv_usec = ts % 1000000;
+    hdr.caplen = caplen;
+    hdr.len = size;
+    if (write(s->fd, &hdr, sizeof(hdr)) != sizeof(hdr) ||
+        write(s->fd, buf, caplen) != caplen) {
+        qemu_log("-net dump write error - stop dump\n");
+        close(s->fd);
+        s->fd = -1;
+    }
+
+    return size;
+}
+
+static void net_dump_cleanup(VLANClientState *vc)
+{
+    DumpState *s = vc->opaque;
+
+    close(s->fd);
+    qemu_free(s);
+}
+
+static int net_dump_init(VLANState *vlan, const char *device,
+                         const char *name, const char *filename, int len)
+{
+    struct pcap_file_hdr hdr;
+    DumpState *s;
+
+    s = qemu_malloc(sizeof(DumpState));
+
+    s->fd = open(filename, O_CREAT | O_WRONLY | O_BINARY, 0644);
+    if (s->fd < 0) {
+        qemu_error("-net dump: can't open %s\n", filename);
+        return -1;
+    }
+
+    s->pcap_caplen = len;
+
+    hdr.magic = PCAP_MAGIC;
+    hdr.version_major = 2;
+    hdr.version_minor = 4;
+    hdr.thiszone = 0;
+    hdr.sigfigs = 0;
+    hdr.snaplen = s->pcap_caplen;
+    hdr.linktype = 1;
+
+    if (write(s->fd, &hdr, sizeof(hdr)) < sizeof(hdr)) {
+        qemu_error("-net dump write error: %s\n", strerror(errno));
+        close(s->fd);
+        qemu_free(s);
+        return -1;
+    }
+
+    s->pcap_vc = qemu_new_vlan_client(NET_CLIENT_TYPE_DUMP,
+                                      vlan, NULL, device, name, NULL,
+                                      dump_receive, NULL, NULL,
+                                      net_dump_cleanup, s);
+    snprintf(s->pcap_vc->info_str, sizeof(s->pcap_vc->info_str),
+             "dump to %s (len=%d)", filename, len);
+    return 0;
+}
+
+int net_init_dump(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)
+{
+    int len;
+    const char *file;
+    char def_file[128];
+
+    assert(vlan);
+
+    file = qemu_opt_get(opts, "file");
+    if (!file) {
+        snprintf(def_file, sizeof(def_file), "qemu-vlan%d.pcap", vlan->id);
+        file = def_file;
+    }
+
+    len = qemu_opt_get_size(opts, "len", 65536);
+
+    return net_dump_init(vlan, "dump", name, file, len);
+}
diff --git a/net/dump.h b/net/dump.h
new file mode 100644
index 0000000..fdc91ad
--- /dev/null
+++ b/net/dump.h
@@ -0,0 +1,33 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef QEMU_NET_DUMP_H
+#define QEMU_NET_DUMP_H
+
+#include "net.h"
+#include "qemu-common.h"
+
+int net_init_dump(QemuOpts *opts, Monitor *mon,
+                  const char *name, VLANState *vlan);
+
+#endif /* QEMU_NET_DUMP_H */
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 05/44] net: clean up includes in net.c
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (3 preceding siblings ...)
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 04/44] net: move dump backend code from net.c to net/dump.c Mark McLoughlin
@ 2009-11-25 18:48 ` Mark McLoughlin
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 06/44] net: remove NICInfo::vc Mark McLoughlin
                   ` (38 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

This is probably a little drastic, but the includes in this file are
now totally out of control when compared with what includes are
actually needed.

This may break the build on e.g. *BSD, but it will be easily fixed by
re-instating an include.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |   74 +---------------------------------------------------------------
 1 files changed, 2 insertions(+), 72 deletions(-)

diff --git a/net.c b/net.c
index 5667485..599e5b0 100644
--- a/net.c
+++ b/net.c
@@ -21,76 +21,10 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include <unistd.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <zlib.h>
-
-/* Needed early for CONFIG_BSD etc. */
-#include "config-host.h"
-
-#ifndef _WIN32
-#include <sys/times.h>
-#include <sys/wait.h>
-#include <termios.h>
-#include <sys/mman.h>
-#include <sys/ioctl.h>
-#include <sys/resource.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <dirent.h>
-#include <netdb.h>
-#include <sys/select.h>
-#ifdef CONFIG_BSD
-#include <sys/stat.h>
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-#include <libutil.h>
-#else
-#include <util.h>
-#endif
-#elif defined (__GLIBC__) && defined (__FreeBSD_kernel__)
-#include <freebsd/stdlib.h>
-#else
-#ifdef __linux__
-#include <pty.h>
-#include <malloc.h>
-#include <linux/rtc.h>
-
-/* For the benefit of older linux systems which don't supply it,
-   we use a local copy of hpet.h. */
-/* #include <linux/hpet.h> */
-#include "hpet.h"
-
-#include <linux/ppdev.h>
-#include <linux/parport.h>
-#endif
-#ifdef __sun__
-#include <sys/stat.h>
-#include <sys/ethernet.h>
-#include <sys/sockio.h>
-#include <netinet/arp.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_icmp.h> // must come after ip.h
-#include <netinet/udp.h>
-#include <netinet/tcp.h>
-#include <net/if.h>
-#include <syslog.h>
-#include <stropts.h>
-#endif
-#endif
-#endif
+#include "net.h"
 
-#if defined(__OpenBSD__)
-#include <util.h>
-#endif
+#include "config-host.h"
 
-#include "qemu-common.h"
-#include "net.h"
 #include "net/tap.h"
 #include "net/socket.h"
 #include "net/dump.h"
@@ -98,12 +32,8 @@
 #include "net/vde.h"
 #include "monitor.h"
 #include "sysemu.h"
-#include "qemu-timer.h"
-#include "qemu-char.h"
-#include "audio/audio.h"
+#include "qemu-common.h"
 #include "qemu_socket.h"
-#include "qemu-log.h"
-#include "qemu-config.h"
 
 static QTAILQ_HEAD(, VLANState) vlans;
 static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 06/44] net: remove NICInfo::vc
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (4 preceding siblings ...)
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 05/44] net: clean up includes in net.c Mark McLoughlin
@ 2009-11-25 18:48 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 07/44] net: remove NICInfo::private Mark McLoughlin
                   ` (37 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Since 1cc33683, this field is not set for most devices, so just
remove it and its remaining few uses.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/dp8393x.c     |   10 +++++-----
 hw/etraxfs_eth.c |   10 +++++-----
 hw/mcf_fec.c     |   10 +++++-----
 hw/mipsnet.c     |   10 +++++-----
 hw/usb-net.c     |   14 +++++++-------
 net.h            |    1 -
 6 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index ae8b16e..5143cc8 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -889,11 +889,11 @@ 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(NET_CLIENT_TYPE_NIC,
-                                          nd->vlan, nd->netdev,
-                                          nd->model, nd->name,
-                                          nic_can_receive, nic_receive, NULL, NULL,
-                                          nic_cleanup, s);
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+                                 nd->vlan, nd->netdev,
+                                 nd->model, nd->name,
+                                 nic_can_receive, nic_receive, NULL, NULL,
+                                 nic_cleanup, s);
 
     qemu_format_nic_info_str(s->vc, nd->macaddr);
     qemu_register_reset(nic_reset, s);
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index ffe7082..2cc2332 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -590,11 +590,11 @@ 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(NET_CLIENT_TYPE_NIC,
-                                                nd->vlan, nd->netdev,
-                                                nd->model, nd->name,
-                                                eth_can_receive, eth_receive,
-                                                NULL, NULL, eth_cleanup, eth);
+	eth->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+                                       nd->vlan, nd->netdev,
+                                       nd->model, nd->name,
+                                       eth_can_receive, eth_receive,
+                                       NULL, NULL, eth_cleanup, eth);
 	eth->vc->opaque = eth;
 	eth->vc->link_status_changed = eth_set_link;
 
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 9f0d0f4..8242c8a 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -462,11 +462,11 @@ 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(NET_CLIENT_TYPE_NIC,
-                                          nd->vlan, nd->netdev,
-                                          nd->model, nd->name,
-                                          mcf_fec_can_receive, mcf_fec_receive,
-                                          NULL, NULL, mcf_fec_cleanup, s);
+    s->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, NULL, mcf_fec_cleanup, s);
     memcpy(s->macaddr, nd->macaddr, 6);
     qemu_format_nic_info_str(s->vc, s->macaddr);
 }
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 65e1d59..67160a4 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -263,11 +263,11 @@ 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(NET_CLIENT_TYPE_NIC,
-                                              nd->vlan, nd->netdev,
-                                              nd->model, nd->name,
-                                              mipsnet_can_receive, mipsnet_receive,
-                                              NULL, NULL, mipsnet_cleanup, s);
+        s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+                                     nd->vlan, nd->netdev,
+                                     nd->model, nd->name,
+                                     mipsnet_can_receive, mipsnet_receive,
+                                     NULL, NULL, mipsnet_cleanup, s);
     } else {
         s->vc = NULL;
     }
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 9c6549c..7b8cc7a 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1460,13 +1460,13 @@ USBDevice *usb_net_init(NICInfo *nd)
 
     memcpy(s->mac, nd->macaddr, 6);
 
-    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,
-                                          NULL, NULL,
-                                          usbnet_cleanup, s);
+    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+                                 nd->vlan, nd->netdev,
+                                 nd->model, nd->name,
+                                 usbnet_can_receive,
+                                 usbnet_receive,
+                                 NULL, NULL,
+                                 usbnet_cleanup, s);
 
     qemu_format_nic_info_str(s->vc, s->mac);
 
diff --git a/net.h b/net.h
index 42ac42d..bc8392b 100644
--- a/net.h
+++ b/net.h
@@ -124,7 +124,6 @@ struct NICInfo {
     char *devaddr;
     VLANState *vlan;
     VLANClientState *netdev;
-    VLANClientState *vc;
     void *private;
     int used;
     int bootable;
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 07/44] net: remove NICInfo::private
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (5 preceding siblings ...)
  2009-11-25 18:48 ` [Qemu-devel] [PATCH 06/44] net: remove NICInfo::vc Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 08/44] net: introduce NetClientInfo Mark McLoughlin
                   ` (36 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Was used by hot-unplug, but not anymore.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.h |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/net.h b/net.h
index bc8392b..9ffcfe3 100644
--- a/net.h
+++ b/net.h
@@ -124,7 +124,6 @@ struct NICInfo {
     char *devaddr;
     VLANState *vlan;
     VLANClientState *netdev;
-    void *private;
     int used;
     int bootable;
     int nvectors;
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 08/44] net: introduce NetClientInfo
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (6 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 07/44] net: remove NICInfo::private Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 09/44] net: introduce qemu_new_net_client() Mark McLoughlin
                   ` (35 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

This structure holds data which is common to all instances of a given
net client type/model.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/net.h b/net.h
index 9ffcfe3..56c5849 100644
--- a/net.h
+++ b/net.h
@@ -42,6 +42,17 @@ typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
 typedef void (NetCleanup) (VLANClientState *);
 typedef void (LinkStatusChanged)(VLANClientState *);
 
+typedef struct NetClientInfo {
+    net_client_type type;
+    size_t size;
+    NetReceive *receive;
+    NetReceive *receive_raw;
+    NetReceiveIOV *receive_iov;
+    NetCanReceive *can_receive;
+    NetCleanup *cleanup;
+    LinkStatusChanged *link_status_changed;
+} NetClientInfo;
+
 struct VLANClientState {
     net_client_type type;
     NetReceive *receive;
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 09/44] net: introduce qemu_new_net_client()
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (7 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 08/44] net: introduce NetClientInfo Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 20:36   ` Blue Swirl
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 10/44] qdev: move DO_UPCAST() into osdep.h Mark McLoughlin
                   ` (34 subsequent siblings)
  43 siblings, 1 reply; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

A replacement for qemu_new_vlan_client(), using NetClientInfo to
replace most arguments.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |   70 +++++++++++++++++++++++++++++++++++++++++++++-------------------
 net.h |    5 ++++
 2 files changed, 54 insertions(+), 21 deletions(-)

diff --git a/net.c b/net.c
index 599e5b0..355eb87 100644
--- a/net.c
+++ b/net.c
@@ -248,34 +248,31 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
                                        int iovcnt,
                                        void *opaque);
 
-VLANClientState *qemu_new_vlan_client(net_client_type type,
-                                      VLANState *vlan,
-                                      VLANClientState *peer,
-                                      const char *model,
-                                      const char *name,
-                                      NetCanReceive *can_receive,
-                                      NetReceive *receive,
-                                      NetReceive *receive_raw,
-                                      NetReceiveIOV *receive_iov,
-                                      NetCleanup *cleanup,
-                                      void *opaque)
+VLANClientState *qemu_new_net_client(NetClientInfo *info,
+                                     VLANState *vlan,
+                                     VLANClientState *peer,
+                                     const char *model,
+                                     const char *name)
 {
     VLANClientState *vc;
 
-    vc = qemu_mallocz(sizeof(VLANClientState));
+    assert(info->size >= sizeof(VLANClientState));
+
+    vc = qemu_mallocz(info->size);
 
-    vc->type = type;
+    vc->type = info->type;
     vc->model = qemu_strdup(model);
-    if (name)
+    if (name) {
         vc->name = qemu_strdup(name);
-    else
+    } else {
         vc->name = assign_name(vc, model);
-    vc->can_receive = can_receive;
-    vc->receive = receive;
-    vc->receive_raw = receive_raw;
-    vc->receive_iov = receive_iov;
-    vc->cleanup = cleanup;
-    vc->opaque = opaque;
+    }
+    vc->can_receive = info->can_receive;
+    vc->receive = info->receive;
+    vc->receive_raw = info->receive_raw;
+    vc->receive_iov = info->receive_iov;
+    vc->cleanup = info->cleanup;
+    vc->link_status_changed = info->link_status_changed;
 
     if (vlan) {
         assert(!peer);
@@ -296,6 +293,37 @@ VLANClientState *qemu_new_vlan_client(net_client_type type,
     return vc;
 }
 
+VLANClientState *qemu_new_vlan_client(net_client_type type,
+                                      VLANState *vlan,
+                                      VLANClientState *peer,
+                                      const char *model,
+                                      const char *name,
+                                      NetCanReceive *can_receive,
+                                      NetReceive *receive,
+                                      NetReceive *receive_raw,
+                                      NetReceiveIOV *receive_iov,
+                                      NetCleanup *cleanup,
+                                      void *opaque)
+{
+    VLANClientState *ret;
+    NetClientInfo info;
+
+    info.type = type;
+    info.size = sizeof(VLANClientState);
+    info.can_receive = can_receive;
+    info.receive = receive;
+    info.receive_raw = receive_raw;
+    info.receive_iov = receive_iov;
+    info.cleanup = cleanup;
+    info.link_status_changed = NULL;
+
+    ret = qemu_new_net_client(&info, vlan, peer, model, name);
+
+    ret->opaque = opaque;
+
+    return ret;
+}
+
 void qemu_del_vlan_client(VLANClientState *vc)
 {
     if (vc->vlan) {
diff --git a/net.h b/net.h
index 56c5849..71a9a44 100644
--- a/net.h
+++ b/net.h
@@ -85,6 +85,11 @@ struct VLANState {
 
 VLANState *qemu_find_vlan(int id, int allocate);
 VLANClientState *qemu_find_netdev(const char *id);
+VLANClientState *qemu_new_net_client(NetClientInfo *info,
+                                     VLANState *vlan,
+                                     VLANClientState *peer,
+                                     const char *model,
+                                     const char *name);
 VLANClientState *qemu_new_vlan_client(net_client_type type,
                                       VLANState *vlan,
                                       VLANClientState *peer,
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 10/44] qdev: move DO_UPCAST() into osdep.h
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (8 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 09/44] net: introduce qemu_new_net_client() Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 11/44] net: convert tap to NetClientInfo Mark McLoughlin
                   ` (33 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Nothing qdev specific about this, make it available throughtout.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/qdev.h |   10 ----------
 osdep.h   |   10 ++++++++++
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/hw/qdev.h b/hw/qdev.h
index 41642ee..8d53754 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -154,16 +154,6 @@ CharDriverState *qdev_init_chardev(DeviceState *dev);
 
 BusState *qdev_get_parent_bus(DeviceState *dev);
 
-/* Convert from a base type to a parent type, with compile time checking.  */
-#ifdef __GNUC__
-#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
-    char __attribute__((unused)) offset_must_be_zero[ \
-        -offsetof(type, field)]; \
-    container_of(dev, type, field);}))
-#else
-#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
-#endif
-
 /*** BUS API. ***/
 
 void qbus_create_inplace(BusState *bus, BusInfo *info,
diff --git a/osdep.h b/osdep.h
index 4b4aad4..75b5816 100644
--- a/osdep.h
+++ b/osdep.h
@@ -37,6 +37,16 @@
         (type *) ((char *) __mptr - offsetof(type, member));})
 #endif
 
+/* Convert from a base type to a parent type, with compile time checking.  */
+#ifdef __GNUC__
+#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
+    char __attribute__((unused)) offset_must_be_zero[ \
+        -offsetof(type, field)]; \
+    container_of(dev, type, field);}))
+#else
+#define DO_UPCAST(type, field, dev) container_of(dev, type, field)
+#endif
+
 #define typeof_field(type, field) typeof(((type *)0)->field)
 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 11/44] net: convert tap to NetClientInfo
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (9 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 10/44] qdev: move DO_UPCAST() into osdep.h Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 12/44] net: convert tap-win32 " Mark McLoughlin
                   ` (32 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/tap.c |   82 +++++++++++++++++++++++++++++++++---------------------------
 1 files changed, 45 insertions(+), 37 deletions(-)

diff --git a/net/tap.c b/net/tap.c
index b2e5908..d34feec 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -47,7 +47,7 @@
 #define TAP_BUFSIZE (4096 + 65536)
 
 typedef struct TAPState {
-    VLANClientState *vc;
+    VLANClientState nc;
     int fd;
     char down_script[1024];
     char down_script_arg[128];
@@ -92,7 +92,7 @@ static void tap_writable(void *opaque)
 
     tap_write_poll(s, 0);
 
-    qemu_flush_queued_packets(s->vc);
+    qemu_flush_queued_packets(&s->nc);
 }
 
 static ssize_t tap_write_packet(TAPState *s, const struct iovec *iov, int iovcnt)
@@ -111,10 +111,10 @@ static ssize_t tap_write_packet(TAPState *s, const struct iovec *iov, int iovcnt
     return len;
 }
 
-static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
+static ssize_t tap_receive_iov(VLANClientState *nc, const struct iovec *iov,
                                int iovcnt)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
     const struct iovec *iovp = iov;
     struct iovec iov_copy[iovcnt + 1];
     struct virtio_net_hdr hdr = { 0, };
@@ -130,9 +130,9 @@ static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
     return tap_write_packet(s, iovp, iovcnt);
 }
 
-static ssize_t tap_receive_raw(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t tap_receive_raw(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
     struct iovec iov[2];
     int iovcnt = 0;
     struct virtio_net_hdr hdr = { 0, };
@@ -150,13 +150,13 @@ static ssize_t tap_receive_raw(VLANClientState *vc, const uint8_t *buf, size_t s
     return tap_write_packet(s, iov, iovcnt);
 }
 
-static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t tap_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
     struct iovec iov[1];
 
     if (s->has_vnet_hdr && !s->using_vnet_hdr) {
-        return tap_receive_raw(vc, buf, size);
+        return tap_receive_raw(nc, buf, size);
     }
 
     iov[0].iov_base = (char *)buf;
@@ -169,7 +169,7 @@ static int tap_can_send(void *opaque)
 {
     TAPState *s = opaque;
 
-    return qemu_can_send_packet(s->vc);
+    return qemu_can_send_packet(&s->nc);
 }
 
 #ifndef __sun__
@@ -179,9 +179,9 @@ ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
 }
 #endif
 
-static void tap_send_completed(VLANClientState *vc, ssize_t len)
+static void tap_send_completed(VLANClientState *nc, ssize_t len)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
     tap_read_poll(s, 1);
 }
 
@@ -203,56 +203,56 @@ static void tap_send(void *opaque)
             size -= sizeof(struct virtio_net_hdr);
         }
 
-        size = qemu_send_packet_async(s->vc, buf, size, tap_send_completed);
+        size = qemu_send_packet_async(&s->nc, buf, size, tap_send_completed);
         if (size == 0) {
             tap_read_poll(s, 0);
         }
-    } while (size > 0 && qemu_can_send_packet(s->vc));
+    } while (size > 0 && qemu_can_send_packet(&s->nc));
 }
 
-int tap_has_ufo(VLANClientState *vc)
+int tap_has_ufo(VLANClientState *nc)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
-    assert(vc->type == NET_CLIENT_TYPE_TAP);
+    assert(nc->type == NET_CLIENT_TYPE_TAP);
 
     return s->has_ufo;
 }
 
-int tap_has_vnet_hdr(VLANClientState *vc)
+int tap_has_vnet_hdr(VLANClientState *nc)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
-    assert(vc->type == NET_CLIENT_TYPE_TAP);
+    assert(nc->type == NET_CLIENT_TYPE_TAP);
 
     return s->has_vnet_hdr;
 }
 
-void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr)
+void tap_using_vnet_hdr(VLANClientState *nc, int using_vnet_hdr)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
     using_vnet_hdr = using_vnet_hdr != 0;
 
-    assert(vc->type == NET_CLIENT_TYPE_TAP);
+    assert(nc->type == NET_CLIENT_TYPE_TAP);
     assert(s->has_vnet_hdr == using_vnet_hdr);
 
     s->using_vnet_hdr = using_vnet_hdr;
 }
 
-void tap_set_offload(VLANClientState *vc, int csum, int tso4,
+void tap_set_offload(VLANClientState *nc, int csum, int tso4,
                      int tso6, int ecn, int ufo)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
     return tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo);
 }
 
-static void tap_cleanup(VLANClientState *vc)
+static void tap_cleanup(VLANClientState *nc)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
-    qemu_purge_queued_packets(vc);
+    qemu_purge_queued_packets(nc);
 
     if (s->down_script[0])
         launch_script(s->down_script, s->down_script_arg, s->fd);
@@ -260,29 +260,37 @@ static void tap_cleanup(VLANClientState *vc)
     tap_read_poll(s, 0);
     tap_write_poll(s, 0);
     close(s->fd);
-    qemu_free(s);
 }
 
 /* fd support */
 
+static NetClientInfo net_tap_info = {
+    .type = NET_CLIENT_TYPE_TAP,
+    .size = sizeof(TAPState),
+    .receive = tap_receive,
+    .receive_raw = tap_receive_raw,
+    .receive_iov = tap_receive_iov,
+    .cleanup = tap_cleanup,
+};
+
 static TAPState *net_tap_fd_init(VLANState *vlan,
                                  const char *model,
                                  const char *name,
                                  int fd,
                                  int vnet_hdr)
 {
+    VLANClientState *nc;
     TAPState *s;
 
-    s = qemu_mallocz(sizeof(TAPState));
+    nc = qemu_new_net_client(&net_tap_info, vlan, NULL, model, name);
+
+    s = DO_UPCAST(TAPState, nc, nc);
+
     s->fd = fd;
     s->has_vnet_hdr = vnet_hdr != 0;
     s->using_vnet_hdr = 0;
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP,
-                                 vlan, NULL, model, name, NULL,
-                                 tap_receive, tap_receive_raw,
-                                 tap_receive_iov, tap_cleanup, s);
     s->has_ufo = tap_probe_has_ufo(s->fd);
-    tap_set_offload(s->vc, 0, 0, 0, 0, 0);
+    tap_set_offload(&s->nc, 0, 0, 0, 0, 0);
     tap_read_poll(s, 1);
     return s;
 }
@@ -415,7 +423,7 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
     }
 
     if (qemu_opt_get(opts, "fd")) {
-        snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd);
+        snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);
     } else {
         const char *ifname, *script, *downscript;
 
@@ -423,7 +431,7 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
         script     = qemu_opt_get(opts, "script");
         downscript = qemu_opt_get(opts, "downscript");
 
-        snprintf(s->vc->info_str, sizeof(s->vc->info_str),
+        snprintf(s->nc.info_str, sizeof(s->nc.info_str),
                  "ifname=%s,script=%s,downscript=%s",
                  ifname, script, downscript);
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 12/44] net: convert tap-win32 to NetClientInfo
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (10 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 11/44] net: convert tap to NetClientInfo Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 13/44] net: convert slirp " Mark McLoughlin
                   ` (31 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/tap-win32.c |   39 +++++++++++++++++++++++----------------
 1 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/net/tap-win32.c b/net/tap-win32.c
index ea66471..ef63782 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -630,25 +630,24 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,
 /********************************************/
 
  typedef struct TAPState {
-     VLANClientState *vc;
+     VLANClientState nc;
      tap_win32_overlapped_t *handle;
  } TAPState;
 
-static void tap_cleanup(VLANClientState *vc)
+static void tap_cleanup(VLANClientState *nc)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
     qemu_del_wait_object(s->handle->tap_semaphore, NULL, NULL);
 
     /* FIXME: need to kill thread and close file handle:
        tap_win32_close(s);
     */
-    qemu_free(s);
 }
 
-static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t tap_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
     return tap_win32_write(s->handle, buf, size);
 }
@@ -662,33 +661,41 @@ static void tap_win32_send(void *opaque)
 
     size = tap_win32_read(s->handle, &buf, max_size);
     if (size > 0) {
-        qemu_send_packet(s->vc, buf, size);
+        qemu_send_packet(&s->nc, buf, size);
         tap_win32_free_buffer(s->handle, buf);
     }
 }
 
+static NetClientInfo net_tap_win32_info = {
+    .type = NET_CLIENT_TYPE_TAP,
+    .size = sizeof(TAPState),
+    .receive = tap_receive,
+    .cleanup = tap_cleanup,
+};
+
 static int tap_win32_init(VLANState *vlan, const char *model,
                           const char *name, const char *ifname)
 {
+    VLANClientState *nc;
     TAPState *s;
+    tap_win32_overlapped_t *handle;
 
-    s = qemu_mallocz(sizeof(TAPState));
-    if (!s)
-        return -1;
-    if (tap_win32_open(&s->handle, ifname) < 0) {
+    if (tap_win32_open(&handle, ifname) < 0) {
         printf("tap: Could not open '%s'\n", ifname);
         return -1;
     }
 
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP,
-                                 vlan, NULL, model, name,
-                                 NULL, tap_receive,
-                                 NULL, NULL, tap_cleanup, s);
+    nc = qemu_new_net_client(&net_tap_win32_info, vlan, NULL, model, name);
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
+    snprintf(s->nc.info_str, sizeof(s->nc.info_str),
              "tap: ifname=%s", ifname);
 
+    s = DO_UPCAST(TAPState, nc, nc);
+
+    s->handle = handle;
+
     qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s);
+
     return 0;
 }
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 13/44] net: convert slirp to NetClientInfo
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (11 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 12/44] net: convert tap-win32 " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 14/44] net: convert vde " Mark McLoughlin
                   ` (30 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/slirp.c |   61 +++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/net/slirp.c b/net/slirp.c
index d6d5772..3f91c4b 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -64,8 +64,8 @@ struct slirp_config_str {
 };
 
 typedef struct SlirpState {
+    VLANClientState nc;
     QTAILQ_ENTRY(SlirpState) entry;
-    VLANClientState *vc;
     Slirp *slirp;
 #ifndef _WIN32
     char smb_dir[128];
@@ -97,35 +97,41 @@ int slirp_can_output(void *opaque)
 {
     SlirpState *s = opaque;
 
-    return qemu_can_send_packet(s->vc);
+    return qemu_can_send_packet(&s->nc);
 }
 
 void slirp_output(void *opaque, const uint8_t *pkt, int pkt_len)
 {
     SlirpState *s = opaque;
 
-    qemu_send_packet(s->vc, pkt, pkt_len);
+    qemu_send_packet(&s->nc, pkt, pkt_len);
 }
 
-static ssize_t slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t net_slirp_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    SlirpState *s = vc->opaque;
+    SlirpState *s = DO_UPCAST(SlirpState, nc, nc);
 
     slirp_input(s->slirp, buf, size);
 
     return size;
 }
 
-static void net_slirp_cleanup(VLANClientState *vc)
+static void net_slirp_cleanup(VLANClientState *nc)
 {
-    SlirpState *s = vc->opaque;
+    SlirpState *s = DO_UPCAST(SlirpState, nc, nc);
 
     slirp_cleanup(s->slirp);
     slirp_smb_cleanup(s);
     QTAILQ_REMOVE(&slirp_stacks, s, entry);
-    qemu_free(s);
 }
 
+static NetClientInfo net_slirp_info = {
+    .type = NET_CLIENT_TYPE_SLIRP,
+    .size = sizeof(SlirpState),
+    .receive = net_slirp_receive,
+    .cleanup = net_slirp_cleanup,
+};
+
 static int net_slirp_init(VLANState *vlan, const char *model,
                           const char *name, int restricted,
                           const char *vnetwork, const char *vhost,
@@ -143,6 +149,7 @@ static int net_slirp_init(VLANState *vlan, const char *model,
 #ifndef _WIN32
     struct in_addr smbsrv = { .s_addr = 0 };
 #endif
+    VLANClientState *nc;
     SlirpState *s;
     char buf[20];
     uint32_t addr;
@@ -228,7 +235,13 @@ static int net_slirp_init(VLANState *vlan, const char *model,
     }
 #endif
 
-    s = qemu_mallocz(sizeof(SlirpState));
+    nc = qemu_new_net_client(&net_slirp_info, vlan, NULL, model, name);
+
+    snprintf(nc->info_str, sizeof(nc->info_str),
+             "net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n');
+
+    s = DO_UPCAST(SlirpState, nc, nc);
+
     s->slirp = slirp_init(restricted, net, mask, host, vhostname,
                           tftp_export, bootfile, dhcp, dns, s);
     QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry);
@@ -237,11 +250,11 @@ static int net_slirp_init(VLANState *vlan, const char *model,
         if (config->flags & SLIRP_CFG_HOSTFWD) {
             if (slirp_hostfwd(s, config->str,
                               config->flags & SLIRP_CFG_LEGACY) < 0)
-                return -1;
+                goto error;
         } else {
             if (slirp_guestfwd(s, config->str,
                                config->flags & SLIRP_CFG_LEGACY) < 0)
-                return -1;
+                goto error;
         }
     }
 #ifndef _WIN32
@@ -250,34 +263,32 @@ static int net_slirp_init(VLANState *vlan, const char *model,
     }
     if (smb_export) {
         if (slirp_smb(s, smb_export, smbsrv) < 0)
-            return -1;
+            goto error;
     }
 #endif
 
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SLIRP,
-                                 vlan, NULL, model, name, NULL,
-                                 slirp_receive, NULL, NULL,
-                                 net_slirp_cleanup, s);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n');
     return 0;
+
+error:
+    qemu_del_vlan_client(nc);
+    return -1;
 }
 
 static SlirpState *slirp_lookup(Monitor *mon, const char *vlan,
                                 const char *stack)
 {
-    VLANClientState *vc;
 
     if (vlan) {
-        vc = qemu_find_vlan_client_by_name(mon, strtol(vlan, NULL, 0), stack);
-        if (!vc) {
+        VLANClientState *nc;
+        nc = qemu_find_vlan_client_by_name(mon, strtol(vlan, NULL, 0), stack);
+        if (!nc) {
             return NULL;
         }
-        if (strcmp(vc->model, "user")) {
+        if (strcmp(nc->model, "user")) {
             monitor_printf(mon, "invalid device specified\n");
             return NULL;
         }
-        return vc->opaque;
+        return DO_UPCAST(SlirpState, nc, nc);
     } else {
         if (QTAILQ_EMPTY(&slirp_stacks)) {
             monitor_printf(mon, "user mode network stack not in use\n");
@@ -626,7 +637,9 @@ void do_info_usernet(Monitor *mon)
     SlirpState *s;
 
     QTAILQ_FOREACH(s, &slirp_stacks, entry) {
-        monitor_printf(mon, "VLAN %d (%s):\n", s->vc->vlan->id, s->vc->name);
+        monitor_printf(mon, "VLAN %d (%s):\n",
+                       s->nc.vlan ? s->nc.vlan->id : -1,
+                       s->nc.name);
         slirp_connection_info(s->slirp, mon);
     }
 }
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 14/44] net: convert vde to NetClientInfo
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (12 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 13/44] net: convert slirp " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 15/44] net: convert socket " Mark McLoughlin
                   ` (29 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/vde.c |   45 ++++++++++++++++++++++++++++-----------------
 1 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/net/vde.c b/net/vde.c
index 4d09967..42b4633 100644
--- a/net/vde.c
+++ b/net/vde.c
@@ -34,7 +34,7 @@
 #include "sysemu.h"
 
 typedef struct VDEState {
-    VLANClientState *vc;
+    VLANClientState nc;
     VDECONN *vde;
 } VDEState;
 
@@ -46,13 +46,13 @@ static void vde_to_qemu(void *opaque)
 
     size = vde_recv(s->vde, (char *)buf, sizeof(buf), 0);
     if (size > 0) {
-        qemu_send_packet(s->vc, buf, size);
+        qemu_send_packet(&s->nc, buf, size);
     }
 }
 
-static ssize_t vde_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t vde_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    VDEState *s = vc->opaque;
+    VDEState *s = DO_UPCAST(VDEState, nc, nc);
     ssize_t ret;
 
     do {
@@ -62,19 +62,27 @@ static ssize_t vde_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
     return ret;
 }
 
-static void vde_cleanup(VLANClientState *vc)
+static void vde_cleanup(VLANClientState *nc)
 {
-    VDEState *s = vc->opaque;
+    VDEState *s = DO_UPCAST(VDEState, nc, nc);
     qemu_set_fd_handler(vde_datafd(s->vde), NULL, NULL, NULL);
     vde_close(s->vde);
-    qemu_free(s);
 }
 
+static NetClientInfo net_vde_info = {
+    .type = NET_CLIENT_TYPE_VDE,
+    .size = sizeof(VDEState),
+    .receive = vde_receive,
+    .cleanup = vde_cleanup,
+};
+
 static int net_vde_init(VLANState *vlan, const char *model,
                         const char *name, const char *sock,
                         int port, const char *group, int mode)
 {
+    VLANClientState *nc;
     VDEState *s;
+    VDECONN *vde;
     char *init_group = (char *)group;
     char *init_sock = (char *)sock;
 
@@ -84,19 +92,22 @@ static int net_vde_init(VLANState *vlan, const char *model,
         .mode = mode,
     };
 
-    s = qemu_mallocz(sizeof(VDEState));
-    s->vde = vde_open(init_sock, (char *)"QEMU", &args);
-    if (!s->vde){
-        free(s);
+    vde = vde_open(init_sock, (char *)"QEMU", &args);
+    if (!vde){
         return -1;
     }
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_VDE,
-                                 vlan, NULL, model, name, NULL,
-                                 vde_receive, NULL, NULL,
-                                 vde_cleanup, s);
+
+    nc = qemu_new_net_client(&net_vde_info, vlan, NULL, model, name);
+
+    snprintf(nc->info_str, sizeof(nc->info_str), "sock=%s,fd=%d",
+             sock, vde_datafd(vde));
+
+    s = DO_UPCAST(VDEState, nc, nc);
+
+    s->vde = vde;
+
     qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
-             sock, vde_datafd(s->vde));
+
     return 0;
 }
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 15/44] net: convert socket to NetClientInfo
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (13 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 14/44] net: convert vde " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 16/44] net: convert dump " Mark McLoughlin
                   ` (28 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/socket.c |   74 +++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/net/socket.c b/net/socket.c
index 551fc2b..7331d87 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -33,7 +33,7 @@
 #include "sysemu.h"
 
 typedef struct NetSocketState {
-    VLANClientState *vc;
+    VLANClientState nc;
     int fd;
     int state; /* 0 = getting length, 1 = getting data */
     unsigned int index;
@@ -50,9 +50,9 @@ typedef struct NetSocketListenState {
 } NetSocketListenState;
 
 /* XXX: we consider we can send the whole packet without blocking */
-static ssize_t net_socket_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t net_socket_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    NetSocketState *s = vc->opaque;
+    NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc);
     uint32_t len;
     len = htonl(size);
 
@@ -60,9 +60,9 @@ static ssize_t net_socket_receive(VLANClientState *vc, const uint8_t *buf, size_
     return send_all(s->fd, buf, size);
 }
 
-static ssize_t net_socket_receive_dgram(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t net_socket_receive_dgram(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    NetSocketState *s = vc->opaque;
+    NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc);
 
     return sendto(s->fd, (const void *)buf, size, 0,
                   (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst));
@@ -124,7 +124,7 @@ static void net_socket_send(void *opaque)
             buf += l;
             size -= l;
             if (s->index >= s->packet_len) {
-                qemu_send_packet(s->vc, s->buf, s->packet_len);
+                qemu_send_packet(&s->nc, s->buf, s->packet_len);
                 s->index = 0;
                 s->state = 0;
             }
@@ -146,7 +146,7 @@ static void net_socket_send_dgram(void *opaque)
         qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
         return;
     }
-    qemu_send_packet(s->vc, s->buf, size);
+    qemu_send_packet(&s->nc, s->buf, size);
 }
 
 static int net_socket_mcast_create(struct sockaddr_in *mcastaddr)
@@ -209,14 +209,20 @@ fail:
     return -1;
 }
 
-static void net_socket_cleanup(VLANClientState *vc)
+static void net_socket_cleanup(VLANClientState *nc)
 {
-    NetSocketState *s = vc->opaque;
+    NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc);
     qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
     close(s->fd);
-    qemu_free(s);
 }
 
+static NetClientInfo net_dgram_socket_info = {
+    .type = NET_CLIENT_TYPE_SOCKET,
+    .size = sizeof(NetSocketState),
+    .receive = net_socket_receive_dgram,
+    .cleanup = net_socket_cleanup,
+};
+
 static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
                                                 const char *model,
                                                 const char *name,
@@ -225,6 +231,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
     struct sockaddr_in saddr;
     int newfd;
     socklen_t saddr_len;
+    VLANClientState *nc;
     NetSocketState *s;
 
     /* fd passed: multicast: "learn" dgram_dst address from bound address and save it
@@ -258,22 +265,22 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
 	}
     }
 
-    s = qemu_mallocz(sizeof(NetSocketState));
+    nc = qemu_new_net_client(&net_dgram_socket_info, vlan, NULL, model, name);
+
+    snprintf(nc->info_str, sizeof(nc->info_str),
+	    "socket: fd=%d (%s mcast=%s:%d)",
+	    fd, is_connected ? "cloned" : "",
+	    inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+
+    s = DO_UPCAST(NetSocketState, nc, nc);
+
     s->fd = fd;
 
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SOCKET,
-                                 vlan, NULL, model, name, NULL,
-                                 net_socket_receive_dgram, NULL, NULL,
-                                 net_socket_cleanup, s);
     qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
 
     /* mcast: save bound address as dst */
     if (is_connected) s->dgram_dst=saddr;
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-	    "socket: fd=%d (%s mcast=%s:%d)",
-	    fd, is_connected? "cloned" : "",
-	    inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
     return s;
 }
 
@@ -283,20 +290,29 @@ static void net_socket_connect(void *opaque)
     qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
 }
 
+static NetClientInfo net_socket_info = {
+    .type = NET_CLIENT_TYPE_SOCKET,
+    .size = sizeof(NetSocketState),
+    .receive = net_socket_receive,
+    .cleanup = net_socket_cleanup,
+};
+
 static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
                                                  const char *model,
                                                  const char *name,
                                                  int fd, int is_connected)
 {
+    VLANClientState *nc;
     NetSocketState *s;
-    s = qemu_mallocz(sizeof(NetSocketState));
+
+    nc = qemu_new_net_client(&net_socket_info, vlan, NULL, model, name);
+
+    snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd);
+
+    s = DO_UPCAST(NetSocketState, nc, nc);
+
     s->fd = fd;
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SOCKET,
-                                 vlan, NULL, model, name, NULL,
-                                 net_socket_receive, NULL, NULL,
-                                 net_socket_cleanup, s);
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "socket: fd=%d", fd);
+
     if (is_connected) {
         net_socket_connect(s);
     } else {
@@ -350,7 +366,7 @@ static void net_socket_accept(void *opaque)
     if (!s1) {
         closesocket(fd);
     } else {
-        snprintf(s1->vc->info_str, sizeof(s1->vc->info_str),
+        snprintf(s1->nc.info_str, sizeof(s1->nc.info_str),
                  "socket: connection from %s:%d",
                  inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
     }
@@ -443,7 +459,7 @@ static int net_socket_connect_init(VLANState *vlan,
     s = net_socket_fd_init(vlan, model, name, fd, connected);
     if (!s)
         return -1;
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
+    snprintf(s->nc.info_str, sizeof(s->nc.info_str),
              "socket: connect to %s:%d",
              inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
     return 0;
@@ -472,7 +488,7 @@ static int net_socket_mcast_init(VLANState *vlan,
 
     s->dgram_dst = saddr;
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
+    snprintf(s->nc.info_str, sizeof(s->nc.info_str),
              "socket: mcast=%s:%d",
              inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
     return 0;
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 16/44] net: convert dump to NetClientInfo
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (14 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 15/44] net: convert socket " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 17/44] net: introduce NICState and qemu_new_nic() Mark McLoughlin
                   ` (27 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/dump.c |   47 +++++++++++++++++++++++++++--------------------
 1 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/net/dump.c b/net/dump.c
index 05a102b..4ed3f5f 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -28,7 +28,7 @@
 #include "qemu-log.h"
 
 typedef struct DumpState {
-    VLANClientState *pcap_vc;
+    VLANClientState nc;
     int fd;
     int pcap_caplen;
 } DumpState;
@@ -54,9 +54,9 @@ struct pcap_sf_pkthdr {
     uint32_t len;
 };
 
-static ssize_t dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t dump_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    DumpState *s = vc->opaque;
+    DumpState *s = DO_UPCAST(DumpState, nc, nc);
     struct pcap_sf_pkthdr hdr;
     int64_t ts;
     int caplen;
@@ -83,30 +83,34 @@ static ssize_t dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size
     return size;
 }
 
-static void net_dump_cleanup(VLANClientState *vc)
+static void dump_cleanup(VLANClientState *nc)
 {
-    DumpState *s = vc->opaque;
+    DumpState *s = DO_UPCAST(DumpState, nc, nc);
 
     close(s->fd);
-    qemu_free(s);
 }
 
+static NetClientInfo net_dump_info = {
+    .type = NET_CLIENT_TYPE_DUMP,
+    .size = sizeof(DumpState),
+    .receive = dump_receive,
+    .cleanup = dump_cleanup,
+};
+
 static int net_dump_init(VLANState *vlan, const char *device,
                          const char *name, const char *filename, int len)
 {
     struct pcap_file_hdr hdr;
+    VLANClientState *nc;
     DumpState *s;
+    int fd;
 
-    s = qemu_malloc(sizeof(DumpState));
-
-    s->fd = open(filename, O_CREAT | O_WRONLY | O_BINARY, 0644);
-    if (s->fd < 0) {
+    fd = open(filename, O_CREAT | O_WRONLY | O_BINARY, 0644);
+    if (fd < 0) {
         qemu_error("-net dump: can't open %s\n", filename);
         return -1;
     }
 
-    s->pcap_caplen = len;
-
     hdr.magic = PCAP_MAGIC;
     hdr.version_major = 2;
     hdr.version_minor = 4;
@@ -115,19 +119,22 @@ static int net_dump_init(VLANState *vlan, const char *device,
     hdr.snaplen = s->pcap_caplen;
     hdr.linktype = 1;
 
-    if (write(s->fd, &hdr, sizeof(hdr)) < sizeof(hdr)) {
+    if (write(fd, &hdr, sizeof(hdr)) < sizeof(hdr)) {
         qemu_error("-net dump write error: %s\n", strerror(errno));
-        close(s->fd);
-        qemu_free(s);
+        close(fd);
         return -1;
     }
 
-    s->pcap_vc = qemu_new_vlan_client(NET_CLIENT_TYPE_DUMP,
-                                      vlan, NULL, device, name, NULL,
-                                      dump_receive, NULL, NULL,
-                                      net_dump_cleanup, s);
-    snprintf(s->pcap_vc->info_str, sizeof(s->pcap_vc->info_str),
+    nc = qemu_new_net_client(&net_dump_info, vlan, NULL, device, name);
+
+    snprintf(nc->info_str, sizeof(nc->info_str),
              "dump to %s (len=%d)", filename, len);
+
+    s = DO_UPCAST(DumpState, nc, nc);
+
+    s->fd = fd;
+    s->pcap_caplen = len;
+
     return 0;
 }
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 17/44] net: introduce NICState and qemu_new_nic()
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (15 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 16/44] net: convert dump " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 18/44] net: convert virtio to NICState Mark McLoughlin
                   ` (26 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Common state for all NICs.

The opaque member will replace the opaque member in VLANClientState
since only NICs need it.

The conf member will allow us to iterate over NICs, access the MAC
addr for the NIC and send a packet from each NIC in qemu_announce_self().

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |   21 +++++++++++++++++++++
 net.h |   11 +++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/net.c b/net.c
index 355eb87..7195827 100644
--- a/net.c
+++ b/net.c
@@ -293,6 +293,27 @@ VLANClientState *qemu_new_net_client(NetClientInfo *info,
     return vc;
 }
 
+NICState *qemu_new_nic(NetClientInfo *info,
+                       NICConf *conf,
+                       const char *model,
+                       const char *name,
+                       void *opaque)
+{
+    VLANClientState *nc;
+    NICState *nic;
+
+    assert(info->type == NET_CLIENT_TYPE_NIC);
+    assert(info->size >= sizeof(NICState));
+
+    nc = qemu_new_net_client(info, conf->vlan, conf->peer, model, name);
+
+    nic = DO_UPCAST(NICState, nc, nc);
+    nic->conf = conf;
+    nic->opaque = opaque;
+
+    return nic;
+}
+
 VLANClientState *qemu_new_vlan_client(net_client_type type,
                                       VLANState *vlan,
                                       VLANClientState *peer,
diff --git a/net.h b/net.h
index 71a9a44..4de20de 100644
--- a/net.h
+++ b/net.h
@@ -75,6 +75,12 @@ struct VLANClientState {
     unsigned receive_disabled : 1;
 };
 
+typedef struct NICState {
+    VLANClientState nc;
+    NICConf *conf;
+    void *opaque;
+} NICState;
+
 struct VLANState {
     int id;
     QTAILQ_HEAD(, VLANClientState) clients;
@@ -90,6 +96,11 @@ VLANClientState *qemu_new_net_client(NetClientInfo *info,
                                      VLANClientState *peer,
                                      const char *model,
                                      const char *name);
+NICState *qemu_new_nic(NetClientInfo *info,
+                       NICConf *conf,
+                       const char *model,
+                       const char *name,
+                       void *opaque);
 VLANClientState *qemu_new_vlan_client(net_client_type type,
                                       VLANState *vlan,
                                       VLANClientState *peer,
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 18/44] net: convert virtio to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (16 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 17/44] net: introduce NICState and qemu_new_nic() Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 19/44] net: convert e1000 " Mark McLoughlin
                   ` (25 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/virtio-net.c |   73 +++++++++++++++++++++++++++++-------------------------
 1 files changed, 39 insertions(+), 34 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 2f147e5..4f8d89e 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -31,7 +31,7 @@ typedef struct VirtIONet
     VirtQueue *rx_vq;
     VirtQueue *tx_vq;
     VirtQueue *ctrl_vq;
-    VLANClientState *vc;
+    NICState *nic;
     QEMUTimer *tx_timer;
     int tx_timer_active;
     uint32_t has_vnet_hdr;
@@ -85,16 +85,16 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
 
     if (memcmp(netcfg.mac, n->mac, ETH_ALEN)) {
         memcpy(n->mac, netcfg.mac, ETH_ALEN);
-        qemu_format_nic_info_str(n->vc, n->mac);
+        qemu_format_nic_info_str(&n->nic->nc, n->mac);
     }
 }
 
-static void virtio_net_set_link_status(VLANClientState *vc)
+static void virtio_net_set_link_status(VLANClientState *nc)
 {
-    VirtIONet *n = vc->opaque;
+    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
     uint16_t old_status = n->status;
 
-    if (vc->link_down)
+    if (nc->link_down)
         n->status &= ~VIRTIO_NET_S_LINK_UP;
     else
         n->status |= VIRTIO_NET_S_LINK_UP;
@@ -126,13 +126,13 @@ static void virtio_net_reset(VirtIODevice *vdev)
 
 static int peer_has_vnet_hdr(VirtIONet *n)
 {
-    if (!n->vc->peer)
+    if (!n->nic->nc.peer)
         return 0;
 
-    if (n->vc->peer->type != NET_CLIENT_TYPE_TAP)
+    if (n->nic->nc.peer->type != NET_CLIENT_TYPE_TAP)
         return 0;
 
-    n->has_vnet_hdr = tap_has_vnet_hdr(n->vc->peer);
+    n->has_vnet_hdr = tap_has_vnet_hdr(n->nic->nc.peer);
 
     return n->has_vnet_hdr;
 }
@@ -142,7 +142,7 @@ static int peer_has_ufo(VirtIONet *n)
     if (!peer_has_vnet_hdr(n))
         return 0;
 
-    n->has_ufo = tap_has_ufo(n->vc->peer);
+    n->has_ufo = tap_has_ufo(n->nic->nc.peer);
 
     return n->has_ufo;
 }
@@ -159,7 +159,7 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev)
                         (1 << VIRTIO_NET_F_CTRL_RX_EXTRA);
 
     if (peer_has_vnet_hdr(n)) {
-        tap_using_vnet_hdr(n->vc->peer, 1);
+        tap_using_vnet_hdr(n->nic->nc.peer, 1);
 
         features |= (1 << VIRTIO_NET_F_CSUM);
         features |= (1 << VIRTIO_NET_F_HOST_TSO4);
@@ -202,7 +202,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
     n->mergeable_rx_bufs = !!(features & (1 << VIRTIO_NET_F_MRG_RXBUF));
 
     if (n->has_vnet_hdr) {
-        tap_set_offload(n->vc->peer,
+        tap_set_offload(n->nic->nc.peer,
                         (features >> VIRTIO_NET_F_GUEST_CSUM) & 1,
                         (features >> VIRTIO_NET_F_GUEST_TSO4) & 1,
                         (features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
@@ -360,16 +360,16 @@ static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIONet *n = to_virtio_net(vdev);
 
-    qemu_flush_queued_packets(n->vc);
+    qemu_flush_queued_packets(&n->nic->nc);
 
     /* We now have RX buffers, signal to the IO thread to break out of the
      * select to re-poll the tap file descriptor */
     qemu_notify_event();
 }
 
-static int virtio_net_can_receive(VLANClientState *vc)
+static int virtio_net_can_receive(VLANClientState *nc)
 {
-    VirtIONet *n = vc->opaque;
+    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
 
     if (!virtio_queue_ready(n->rx_vq) ||
         !(n->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK))
@@ -511,13 +511,13 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)
     return 0;
 }
 
-static ssize_t virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t virtio_net_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    VirtIONet *n = vc->opaque;
+    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
     struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL;
     size_t hdr_len, offset, i;
 
-    if (!virtio_net_can_receive(n->vc))
+    if (!virtio_net_can_receive(&n->nic->nc))
         return -1;
 
     if (!virtio_net_has_buffers(n, size))
@@ -590,9 +590,9 @@ static ssize_t virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_
 
 static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq);
 
-static void virtio_net_tx_complete(VLANClientState *vc, ssize_t len)
+static void virtio_net_tx_complete(VLANClientState *nc, ssize_t len)
 {
-    VirtIONet *n = vc->opaque;
+    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
 
     virtqueue_push(n->tx_vq, &n->async_tx.elem, n->async_tx.len);
     virtio_notify(&n->vdev, n->tx_vq);
@@ -644,7 +644,7 @@ static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)
             len += hdr_len;
         }
 
-        ret = qemu_sendv_packet_async(n->vc, out_sg, out_num,
+        ret = qemu_sendv_packet_async(&n->nic->nc, out_sg, out_num,
                                       virtio_net_tx_complete);
         if (ret == 0) {
             virtio_queue_set_notification(n->tx_vq, 0);
@@ -766,8 +766,8 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
         }
 
         if (n->has_vnet_hdr) {
-            tap_using_vnet_hdr(n->vc->peer, 1);
-            tap_set_offload(n->vc->peer,
+            tap_using_vnet_hdr(n->nic->nc.peer, 1);
+            tap_set_offload(n->nic->nc.peer,
                             (n->vdev.features >> VIRTIO_NET_F_GUEST_CSUM) & 1,
                             (n->vdev.features >> VIRTIO_NET_F_GUEST_TSO4) & 1,
                             (n->vdev.features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
@@ -811,13 +811,22 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-static void virtio_net_cleanup(VLANClientState *vc)
+static void virtio_net_cleanup(VLANClientState *nc)
 {
-    VirtIONet *n = vc->opaque;
+    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
 
-    n->vc = NULL;
+    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,
+};
+
 VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf)
 {
     VirtIONet *n;
@@ -839,14 +848,10 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf)
     qemu_macaddr_default_if_unset(&conf->macaddr);
     memcpy(&n->mac[0], &conf->macaddr, sizeof(n->mac));
     n->status = VIRTIO_NET_S_LINK_UP;
-    n->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, conf->vlan, conf->peer,
-                                 dev->info->name, dev->id,
-                                 virtio_net_can_receive,
-                                 virtio_net_receive, NULL, NULL,
-                                 virtio_net_cleanup, n);
-    n->vc->link_status_changed = virtio_net_set_link_status;
 
-    qemu_format_nic_info_str(n->vc, conf->macaddr.a);
+    n->nic = qemu_new_nic(&net_virtio_info, conf, dev->info->name, dev->id, n);
+
+    qemu_format_nic_info_str(&n->nic->nc, conf->macaddr.a);
 
     n->tx_timer = qemu_new_timer(vm_clock, virtio_net_tx_timer, n);
     n->tx_timer_active = 0;
@@ -867,7 +872,7 @@ void virtio_net_exit(VirtIODevice *vdev)
 {
     VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);
 
-    qemu_purge_queued_packets(n->vc);
+    qemu_purge_queued_packets(&n->nic->nc);
 
     unregister_savevm("virtio-net", n);
 
@@ -878,5 +883,5 @@ void virtio_net_exit(VirtIODevice *vdev)
     qemu_free_timer(n->tx_timer);
 
     virtio_cleanup(&n->vdev);
-    qemu_del_vlan_client(n->vc);
+    qemu_del_vlan_client(&n->nic->nc);
 }
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 19/44] net: convert e1000 to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (17 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 18/44] net: convert virtio to NICState Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 20/44] net: convert rtl8139 " Mark McLoughlin
                   ` (24 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/e1000.c |   47 ++++++++++++++++++++++++++---------------------
 1 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index 00f6a57..683fdcc 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -75,7 +75,7 @@ enum {
 
 typedef struct E1000State_st {
     PCIDevice dev;
-    VLANClientState *vc;
+    NICState *nic;
     NICConf conf;
     int mmio_index;
 
@@ -385,9 +385,9 @@ xmit_seg(E1000State *s)
     if (tp->vlan_needed) {
         memmove(tp->vlan, tp->data, 12);
         memcpy(tp->data + 8, tp->vlan_header, 4);
-        qemu_send_packet(s->vc, tp->vlan, tp->size + 4);
+        qemu_send_packet(&s->nic->nc, tp->vlan, tp->size + 4);
     } else
-        qemu_send_packet(s->vc, tp->data, tp->size);
+        qemu_send_packet(&s->nic->nc, tp->data, tp->size);
     s->mac_reg[TPT]++;
     s->mac_reg[GPTC]++;
     n = s->mac_reg[TOTL];
@@ -590,12 +590,12 @@ receive_filter(E1000State *s, const uint8_t *buf, int size)
 }
 
 static void
-e1000_set_link_status(VLANClientState *vc)
+e1000_set_link_status(VLANClientState *nc)
 {
-    E1000State *s = vc->opaque;
+    E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
     uint32_t old_status = s->mac_reg[STATUS];
 
-    if (vc->link_down)
+    if (nc->link_down)
         s->mac_reg[STATUS] &= ~E1000_STATUS_LU;
     else
         s->mac_reg[STATUS] |= E1000_STATUS_LU;
@@ -605,17 +605,17 @@ e1000_set_link_status(VLANClientState *vc)
 }
 
 static int
-e1000_can_receive(VLANClientState *vc)
+e1000_can_receive(VLANClientState *nc)
 {
-    E1000State *s = vc->opaque;
+    E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
     return (s->mac_reg[RCTL] & E1000_RCTL_EN);
 }
 
 static ssize_t
-e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    E1000State *s = vc->opaque;
+    E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
     struct e1000_rx_desc desc;
     target_phys_addr_t base;
     unsigned int n, rdt;
@@ -1037,11 +1037,11 @@ e1000_mmio_map(PCIDevice *pci_dev, int region_num,
 }
 
 static void
-e1000_cleanup(VLANClientState *vc)
+e1000_cleanup(VLANClientState *nc)
 {
-    E1000State *d = vc->opaque;
+    E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
-    d->vc = NULL;
+    s->nic = NULL;
 }
 
 static int
@@ -1050,7 +1050,7 @@ pci_e1000_uninit(PCIDevice *dev)
     E1000State *d = DO_UPCAST(E1000State, dev, dev);
 
     cpu_unregister_io_memory(d->mmio_index);
-    qemu_del_vlan_client(d->vc);
+    qemu_del_vlan_client(&d->nic->nc);
     vmstate_unregister(&vmstate_e1000, d);
     return 0;
 }
@@ -1067,6 +1067,15 @@ static void e1000_reset(void *opaque)
     memset(&d->tx, 0, sizeof d->tx);
 }
 
+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,
+};
+
 static int pci_e1000_init(PCIDevice *pci_dev)
 {
     E1000State *d = DO_UPCAST(E1000State, dev, pci_dev);
@@ -1107,14 +1116,10 @@ static int pci_e1000_init(PCIDevice *pci_dev)
     checksum = (uint16_t) EEPROM_SUM - checksum;
     d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
 
-    d->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                 d->conf.vlan, d->conf.peer,
-                                 d->dev.qdev.info->name, d->dev.qdev.id,
-                                 e1000_can_receive, e1000_receive, NULL,
-                                 NULL, e1000_cleanup, d);
-    d->vc->link_status_changed = e1000_set_link_status;
+    d->nic = qemu_new_nic(&net_e1000_info, &d->conf,
+                          d->dev.qdev.info->name, d->dev.qdev.id, d);
 
-    qemu_format_nic_info_str(d->vc, macaddr);
+    qemu_format_nic_info_str(&d->nic->nc, macaddr);
 
     vmstate_register(-1, &vmstate_e1000, d);
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 20/44] net: convert rtl8139 to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (18 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 19/44] net: convert e1000 " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 21/44] net: convert ne2000 " Mark McLoughlin
                   ` (23 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/rtl8139.c |   43 ++++++++++++++++++++++++-------------------
 1 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index c166db0..931cde9 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -459,7 +459,7 @@ typedef struct RTL8139State {
     uint16_t CpCmd;
     uint8_t  TxThresh;
 
-    VLANClientState *vc;
+    NICState *nic;
     NICConf conf;
     int rtl8139_mmio_io_addr;
 
@@ -785,9 +785,9 @@ static inline target_phys_addr_t rtl8139_addr64(uint32_t low, uint32_t high)
 #endif
 }
 
-static int rtl8139_can_receive(VLANClientState *vc)
+static int rtl8139_can_receive(VLANClientState *nc)
 {
-    RTL8139State *s = vc->opaque;
+    RTL8139State *s = DO_UPCAST(NICState, nc, nc)->opaque;
     int avail;
 
     /* Receive (drop) packets if card is disabled.  */
@@ -807,9 +807,9 @@ static int rtl8139_can_receive(VLANClientState *vc)
     }
 }
 
-static ssize_t rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, size_t size_, int do_interrupt)
+static ssize_t rtl8139_do_receive(VLANClientState *nc, const uint8_t *buf, size_t size_, int do_interrupt)
 {
-    RTL8139State *s = vc->opaque;
+    RTL8139State *s = DO_UPCAST(NICState, nc, nc)->opaque;
     int size = size_;
 
     uint32_t packet_header = 0;
@@ -1156,9 +1156,9 @@ static ssize_t rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, size_
     return size_;
 }
 
-static ssize_t rtl8139_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t rtl8139_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    return rtl8139_do_receive(vc, buf, size, 1);
+    return rtl8139_do_receive(nc, buf, size, 1);
 }
 
 static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize)
@@ -1744,11 +1744,11 @@ static void rtl8139_transfer_frame(RTL8139State *s, const uint8_t *buf, int size
     if (TxLoopBack == (s->TxConfig & TxLoopBack))
     {
         DEBUG_PRINT(("RTL8139: +++ transmit loopback mode\n"));
-        rtl8139_do_receive(s->vc, buf, size, do_interrupt);
+        rtl8139_do_receive(&s->nic->nc, buf, size, do_interrupt);
     }
     else
     {
-        qemu_send_packet(s->vc, buf, size);
+        qemu_send_packet(&s->nic->nc, buf, size);
     }
 }
 
@@ -3280,11 +3280,11 @@ static void rtl8139_timer(void *opaque)
 }
 #endif /* RTL8139_ONBOARD_TIMER */
 
-static void rtl8139_cleanup(VLANClientState *vc)
+static void rtl8139_cleanup(VLANClientState *nc)
 {
-    RTL8139State *s = vc->opaque;
+    RTL8139State *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
-    s->vc = NULL;
+    s->nic = NULL;
 }
 
 static int pci_rtl8139_uninit(PCIDevice *dev)
@@ -3301,10 +3301,18 @@ static int pci_rtl8139_uninit(PCIDevice *dev)
     qemu_free_timer(s->timer);
 #endif
     vmstate_unregister(&vmstate_rtl8139, s);
-    qemu_del_vlan_client(s->vc);
+    qemu_del_vlan_client(&s->nic->nc);
     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,
+};
+
 static int pci_rtl8139_init(PCIDevice *dev)
 {
     RTL8139State * s = DO_UPCAST(RTL8139State, dev, dev);
@@ -3332,12 +3340,9 @@ static int pci_rtl8139_init(PCIDevice *dev)
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                 s->conf.vlan, s->conf.peer,
-                                 dev->qdev.info->name, dev->qdev.id,
-                                 rtl8139_can_receive, rtl8139_receive, NULL,
-                                 NULL, rtl8139_cleanup, s);
-    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
+    s->nic = qemu_new_nic(&net_rtl8139_info, &s->conf,
+                          dev->qdev.info->name, dev->qdev.id, s);
+    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     s->cplus_txbuffer = NULL;
     s->cplus_txbuffer_len = 0;
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 21/44] net: convert ne2000 to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (19 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 20/44] net: convert rtl8139 " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 22/44] net: convert pcnet " Mark McLoughlin
                   ` (22 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/ne2000-isa.c |   22 ++++++++++++++--------
 hw/ne2000.c     |   35 +++++++++++++++++++++--------------
 hw/ne2000.h     |    2 +-
 3 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index 729e8e2..0260f84 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -35,13 +35,21 @@ typedef struct ISANE2000State {
     NE2000State ne2000;
 } ISANE2000State;
 
-static void isa_ne2000_cleanup(VLANClientState *vc)
+static void isa_ne2000_cleanup(VLANClientState *nc)
 {
-    NE2000State *s = vc->opaque;
+    NE2000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
-    s->vc = NULL;
+    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 int isa_ne2000_initfn(ISADevice *dev)
 {
     ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev);
@@ -63,11 +71,9 @@ static int isa_ne2000_initfn(ISADevice *dev)
     qemu_macaddr_default_if_unset(&s->c.macaddr);
     ne2000_reset(s);
 
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, s->c.vlan, s->c.peer,
-                                 dev->qdev.info->name, dev->qdev.id,
-                                 ne2000_can_receive, ne2000_receive, NULL,
-                                 NULL, isa_ne2000_cleanup, s);
-    qemu_format_nic_info_str(s->vc, s->c.macaddr.a);
+    s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
+                          dev->qdev.info->name, dev->qdev.id, s);
+    qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
 
     vmstate_register(-1, &vmstate_ne2000, s);
     return 0;
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 63efc3a..0be189a 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -188,9 +188,9 @@ static int ne2000_buffer_full(NE2000State *s)
     return 0;
 }
 
-int ne2000_can_receive(VLANClientState *vc)
+int ne2000_can_receive(VLANClientState *nc)
 {
-    NE2000State *s = vc->opaque;
+    NE2000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
     if (s->cmd & E8390_STOP)
         return 1;
@@ -199,9 +199,9 @@ int ne2000_can_receive(VLANClientState *vc)
 
 #define MIN_BUF_SIZE 60
 
-ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_)
+ssize_t ne2000_receive(VLANClientState *nc, const uint8_t *buf, size_t size_)
 {
-    NE2000State *s = vc->opaque;
+    NE2000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
     int size = size_;
     uint8_t *p;
     unsigned int total_len, next, avail, len, index, mcast_idx;
@@ -323,7 +323,7 @@ void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
                     index -= NE2000_PMEM_SIZE;
                 /* fail safe: check range on the transmitted length  */
                 if (index + s->tcnt <= NE2000_PMEM_END) {
-                    qemu_send_packet(s->vc, s->mem + index, s->tcnt);
+                    qemu_send_packet(&s->nic->nc, s->mem + index, s->tcnt);
                 }
                 /* signal end of transfer */
                 s->tsr = ENTSR_PTX;
@@ -698,13 +698,21 @@ static void ne2000_map(PCIDevice *pci_dev, int region_num,
     register_ioport_read(addr + 0x1f, 1, 1, ne2000_reset_ioport_read, s);
 }
 
-static void ne2000_cleanup(VLANClientState *vc)
+static void ne2000_cleanup(VLANClientState *nc)
 {
-    NE2000State *s = vc->opaque;
+    NE2000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
-    s->vc = NULL;
+    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 int pci_ne2000_init(PCIDevice *pci_dev)
 {
     PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
@@ -725,11 +733,10 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
 
     qemu_macaddr_default_if_unset(&s->c.macaddr);
     ne2000_reset(s);
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, s->c.vlan, s->c.peer,
-                                 pci_dev->qdev.info->name, pci_dev->qdev.id,
-                                 ne2000_can_receive, ne2000_receive, NULL,
-                                 NULL, ne2000_cleanup, s);
-    qemu_format_nic_info_str(s->vc, s->c.macaddr.a);
+
+    s->nic = qemu_new_nic(&net_ne2000_info, &s->c,
+                          pci_dev->qdev.info->name, pci_dev->qdev.id, s);
+    qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
 
     if (!pci_dev->qdev.hotplugged) {
         static int loaded = 0;
@@ -749,7 +756,7 @@ static int pci_ne2000_exit(PCIDevice *pci_dev)
     NE2000State *s = &d->ne2000;
 
     vmstate_unregister(&vmstate_pci_ne2000, s);
-    qemu_del_vlan_client(s->vc);
+    qemu_del_vlan_client(&s->nic->nc);
     return 0;
 }
 
diff --git a/hw/ne2000.h b/hw/ne2000.h
index 2bbce71..54fdfca 100644
--- a/hw/ne2000.h
+++ b/hw/ne2000.h
@@ -22,7 +22,7 @@ typedef struct NE2000State {
     uint8_t curpag;
     uint8_t mult[8]; /* multicast mask array */
     qemu_irq irq;
-    VLANClientState *vc;
+    NICState *nic;
     NICConf c;
     uint8_t mem[NE2000_MEM_SIZE];
 } NE2000State;
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 22/44] net: convert pcnet to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (20 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 21/44] net: convert ne2000 " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 23/44] net: convert eepro100 " Mark McLoughlin
                   ` (21 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/lance.c |   14 +++++++++++---
 hw/pcnet.c |   43 +++++++++++++++++++++++--------------------
 hw/pcnet.h |    7 ++++---
 3 files changed, 38 insertions(+), 26 deletions(-)

diff --git a/hw/lance.c b/hw/lance.c
index 0a96644..98033a4 100644
--- a/hw/lance.c
+++ b/hw/lance.c
@@ -92,14 +92,22 @@ static CPUWriteMemoryFunc * const lance_mem_write[3] = {
     NULL,
 };
 
-static void lance_cleanup(VLANClientState *vc)
+static void lance_cleanup(VLANClientState *nc)
 {
-    PCNetState *d = vc->opaque;
+    PCNetState *d = DO_UPCAST(NICState, nc, nc)->opaque;
 
     vmstate_unregister(&vmstate_pcnet, d);
     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,
+    .cleanup = lance_cleanup,
+};
+
 static int lance_init(SysBusDevice *dev)
 {
     SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev);
@@ -118,7 +126,7 @@ static int lance_init(SysBusDevice *dev)
     s->phys_mem_write = ledma_memory_write;
 
     vmstate_register(-1, &vmstate_pcnet, d);
-    return pcnet_common_init(&dev->qdev, s, lance_cleanup);
+    return pcnet_common_init(&dev->qdev, s, &net_lance_info);
 }
 
 static void lance_reset(DeviceState *dev)
diff --git a/hw/pcnet.c b/hw/pcnet.c
index ee3db09..195c825 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1028,9 +1028,9 @@ static int pcnet_tdte_poll(PCNetState *s)
     return !!(CSR_CXST(s) & 0x8000);
 }
 
-static int pcnet_can_receive(VLANClientState *vc)
+int pcnet_can_receive(VLANClientState *nc)
 {
-    PCNetState *s = vc->opaque;
+    PCNetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
     if (CSR_STOP(s) || CSR_SPND(s))
         return 0;
 
@@ -1039,9 +1039,9 @@ static int pcnet_can_receive(VLANClientState *vc)
 
 #define MIN_BUF_SIZE 60
 
-static ssize_t pcnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size_)
+ssize_t pcnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size_)
 {
-    PCNetState *s = vc->opaque;
+    PCNetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
     int is_padr = 0, is_bcast = 0, is_ladr = 0;
     uint8_t buf1[60];
     int remaining;
@@ -1268,11 +1268,11 @@ static void pcnet_transmit(PCNetState *s)
                 if (BCR_SWSTYLE(s) == 1)
                     add_crc = !GET_FIELD(tmd.status, TMDS, NOFCS);
                 s->looptest = add_crc ? PCNET_LOOPTEST_CRC : PCNET_LOOPTEST_NOCRC;
-                pcnet_receive(s->vc, s->buffer, s->xmit_pos);
+                pcnet_receive(&s->nic->nc, s->buffer, s->xmit_pos);
                 s->looptest = 0;
             } else
-                if (s->vc)
-                    qemu_send_packet(s->vc, s->buffer, s->xmit_pos);
+                if (s->nic)
+                    qemu_send_packet(&s->nic->nc, s->buffer, s->xmit_pos);
 
             s->csr[0] &= ~0x0008;   /* clear TDMD */
             s->csr[4] |= 0x0004;    /* set TXSTRT */
@@ -1888,21 +1888,16 @@ static const VMStateDescription vmstate_pci_pcnet = {
 
 void pcnet_common_cleanup(PCNetState *d)
 {
-    d->vc = NULL;
+    d->nic = NULL;
 }
 
-int pcnet_common_init(DeviceState *dev, PCNetState *s,
-                             NetCleanup *cleanup)
+int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
 {
     s->poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, s);
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                 s->conf.vlan, s->conf.peer,
-                                 dev->info->name, dev->id,
-                                 pcnet_can_receive, pcnet_receive, NULL, NULL,
-                                 cleanup, s);
-    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
+    s->nic = qemu_new_nic(info, &s->conf, dev->info->name, dev->id, s);
+    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     return 0;
 }
 
@@ -1945,9 +1940,9 @@ static void pci_physical_memory_read(void *dma_opaque, target_phys_addr_t addr,
     cpu_physical_memory_read(addr, buf, len);
 }
 
-static void pci_pcnet_cleanup(VLANClientState *vc)
+static void pci_pcnet_cleanup(VLANClientState *nc)
 {
-    PCNetState *d = vc->opaque;
+    PCNetState *d = DO_UPCAST(NICState, nc, nc)->opaque;
 
     pcnet_common_cleanup(d);
 }
@@ -1960,10 +1955,18 @@ static int pci_pcnet_uninit(PCIDevice *dev)
     vmstate_unregister(&vmstate_pci_pcnet, d);
     qemu_del_timer(d->state.poll_timer);
     qemu_free_timer(d->state.poll_timer);
-    qemu_del_vlan_client(d->state.vc);
+    qemu_del_vlan_client(&d->state.nic->nc);
     return 0;
 }
 
+static NetClientInfo net_pci_pcnet_info = {
+    .type = NET_CLIENT_TYPE_NIC,
+    .size = sizeof(NICState),
+    .can_receive = pcnet_can_receive,
+    .receive = pcnet_receive,
+    .cleanup = pci_pcnet_cleanup,
+};
+
 static int pci_pcnet_init(PCIDevice *pci_dev)
 {
     PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, pci_dev);
@@ -2017,7 +2020,7 @@ static int pci_pcnet_init(PCIDevice *pci_dev)
         }
     }
 
-    return pcnet_common_init(&pci_dev->qdev, s, pci_pcnet_cleanup);
+    return pcnet_common_init(&pci_dev->qdev, s, &net_pci_pcnet_info);
 }
 
 static void pci_reset(DeviceState *dev)
diff --git a/hw/pcnet.h b/hw/pcnet.h
index e61d5a4..efacc9f 100644
--- a/hw/pcnet.h
+++ b/hw/pcnet.h
@@ -8,7 +8,7 @@
 typedef struct PCNetState_st PCNetState;
 
 struct PCNetState_st {
-    VLANClientState *vc;
+    NICState *nic;
     NICConf conf;
     QEMUTimer *poll_timer;
     int rap, isr, lnkst;
@@ -32,7 +32,8 @@ struct PCNetState_st {
 void pcnet_h_reset(void *opaque);
 void pcnet_ioport_writew(void *opaque, uint32_t addr, uint32_t val);
 uint32_t pcnet_ioport_readw(void *opaque, uint32_t addr);
+int pcnet_can_receive(VLANClientState *nc);
+ssize_t pcnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size_);
 void pcnet_common_cleanup(PCNetState *d);
-int pcnet_common_init(DeviceState *dev, PCNetState *s,
-                      NetCleanup *cleanup);
+int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info);
 extern const VMStateDescription vmstate_pcnet;
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 23/44] net: convert eepro100 to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (21 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 22/44] net: convert pcnet " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 24/44] net: convert dp8393x " Mark McLoughlin
                   ` (20 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/eepro100.c |   43 ++++++++++++++++++++++++-------------------
 1 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/hw/eepro100.c b/hw/eepro100.c
index 8734907..eb16a51 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -195,7 +195,7 @@ typedef struct {
     PCIDevice dev;
     uint8_t mult[8];            /* multicast mask array */
     int mmio_index;
-    VLANClientState *vc;
+    NICState *nic;
     NICConf conf;
     uint8_t scb_stat;           /* SCB stat/ack byte */
     uint8_t int_stat;           /* PCI interrupt status */
@@ -868,7 +868,7 @@ static void action_command(EEPRO100State *s)
                 }
             }
             TRACE(RXTX, logout("%p sending frame, len=%d,%s\n", s, size, nic_dump(buf, size)));
-            qemu_send_packet(s->vc, buf, size);
+            qemu_send_packet(&s->nic->nc, buf, size);
             s->statistics.tx_good_frames++;
             /* Transmit with bad status would raise an CX/TNO interrupt.
              * (82557 only). Emulation never has bad status. */
@@ -1599,21 +1599,21 @@ static void pci_mmio_map(PCIDevice * pci_dev, int region_num,
     }
 }
 
-static int nic_can_receive(VLANClientState *vc)
+static int nic_can_receive(VLANClientState *nc)
 {
-    EEPRO100State *s = vc->opaque;
+    EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque;
     TRACE(RXTX, logout("%p\n", s));
     return get_ru_state(s) == ru_ready;
     //~ return !eepro100_buffer_full(s);
 }
 
-static ssize_t nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size)
+static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size)
 {
     /* TODO:
      * - Magic packets should set bit 30 in power management driver register.
      * - Interesting packets should set bit 29 in power management driver register.
      */
-    EEPRO100State *s = vc->opaque;
+    EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque;
     uint16_t rfd_status = 0xa000;
     static const uint8_t broadcast_macaddr[6] =
         { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@@ -1779,11 +1779,11 @@ static const VMStateDescription vmstate_eepro100 = {
     }
 };
 
-static void nic_cleanup(VLANClientState *vc)
+static void nic_cleanup(VLANClientState *nc)
 {
-    EEPRO100State *s = vc->opaque;
+    EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
-    s->vc = NULL;
+    s->nic = NULL;
 }
 
 static int pci_nic_uninit(PCIDevice *pci_dev)
@@ -1793,10 +1793,18 @@ static int pci_nic_uninit(PCIDevice *pci_dev)
     cpu_unregister_io_memory(s->mmio_index);
     vmstate_unregister(s->vmstate, s);
     eeprom93xx_free(s->eeprom);
-    qemu_del_vlan_client(s->vc);
+    qemu_del_vlan_client(&s->nic->nc);
     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,
+};
+
 static int nic_init(PCIDevice *pci_dev, uint32_t device)
 {
     EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
@@ -1829,27 +1837,24 @@ static int nic_init(PCIDevice *pci_dev, uint32_t device)
 
     nic_reset(s);
 
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                 s->conf.vlan, s->conf.peer,
-                                 pci_dev->qdev.info->name, pci_dev->qdev.id,
-                                 nic_can_receive, nic_receive, NULL, NULL,
-                                 nic_cleanup, s);
+    s->nic = qemu_new_nic(&net_eepro100_info, &s->conf,
+                          pci_dev->qdev.info->name, pci_dev->qdev.id, s);
 
-    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
-    TRACE(OTHER, logout("%s\n", s->vc->info_str));
+    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+    TRACE(OTHER, logout("%s\n", s->nic->nc.info_str));
 
     qemu_register_reset(nic_reset, s);
 
     s->vmstate = qemu_malloc(sizeof(vmstate_eepro100));
     memcpy(s->vmstate, &vmstate_eepro100, sizeof(vmstate_eepro100));
-    s->vmstate->name = s->vc->model;
+    s->vmstate->name = s->nic->nc.model;
     vmstate_register(-1, s->vmstate, s);
 
     if (!pci_dev->qdev.hotplugged) {
         static int loaded = 0;
         if (!loaded) {
             char fname[32];
-            snprintf(fname, sizeof(fname), "pxe-%s.bin", s->vc->model);
+            snprintf(fname, sizeof(fname), "pxe-%s.bin", s->nic->nc.model);
             rom_add_option(fname);
             loaded = 1;
         }
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 24/44] net: convert dp8393x to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (22 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 23/44] net: convert eepro100 " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 25/44] net: convert etrax " Mark McLoughlin
                   ` (19 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/dp8393x.c |   41 +++++++++++++++++++++++++----------------
 1 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index 5143cc8..be9714d 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -154,7 +154,8 @@ typedef struct dp8393xState {
 #endif
     QEMUTimer *watchdog;
     int64_t wt_last_update;
-    VLANClientState *vc;
+    NICConf conf;
+    NICState *nic;
     int mmio_index;
 
     /* Registers */
@@ -406,13 +407,13 @@ static void do_transmit_packets(dp8393xState *s)
         if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) {
             /* Loopback */
             s->regs[SONIC_TCR] |= SONIC_TCR_CRSL;
-            if (s->vc->can_receive(s->vc)) {
+            if (s->nic->nc.can_receive(&s->nic->nc)) {
                 s->loopback_packet = 1;
-                s->vc->receive(s->vc, s->tx_buffer, tx_len);
+                s->nic->nc.receive(&s->nic->nc, s->tx_buffer, tx_len);
             }
         } else {
             /* Transmit packet */
-            qemu_send_packet(s->vc, s->tx_buffer, tx_len);
+            qemu_send_packet(&s->nic->nc, s->tx_buffer, tx_len);
         }
         s->regs[SONIC_TCR] |= SONIC_TCR_PTX;
 
@@ -675,9 +676,9 @@ static CPUWriteMemoryFunc * const dp8393x_write[3] = {
     dp8393x_writel,
 };
 
-static int nic_can_receive(VLANClientState *vc)
+static int nic_can_receive(VLANClientState *nc)
 {
-    dp8393xState *s = vc->opaque;
+    dp8393xState *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
     if (!(s->regs[SONIC_CR] & SONIC_CR_RXEN))
         return 0;
@@ -724,10 +725,10 @@ static int receive_filter(dp8393xState *s, const uint8_t * buf, int size)
     return -1;
 }
 
-static ssize_t nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size)
+static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size)
 {
+    dp8393xState *s = DO_UPCAST(NICState, nc, nc)->opaque;
     uint16_t data[10];
-    dp8393xState *s = vc->opaque;
     int packet_type;
     uint32_t available, address;
     int width, rx_len = size;
@@ -860,9 +861,9 @@ static void nic_reset(void *opaque)
     dp8393x_update_irq(s);
 }
 
-static void nic_cleanup(VLANClientState *vc)
+static void nic_cleanup(VLANClientState *nc)
 {
-    dp8393xState *s = vc->opaque;
+    dp8393xState *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
     cpu_unregister_io_memory(s->mmio_index);
 
@@ -872,6 +873,14 @@ static void nic_cleanup(VLANClientState *vc)
     qemu_free(s);
 }
 
+static NetClientInfo net_dp83932_info = {
+    .type = NET_CLIENT_TYPE_NIC,
+    .size = sizeof(NICState),
+    .can_receive = nic_can_receive,
+    .receive = nic_receive,
+    .cleanup = nic_cleanup,
+};
+
 void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift,
                   qemu_irq irq, void* mem_opaque,
                   void (*memory_rw)(void *opaque, target_phys_addr_t addr, uint8_t *buf, int len, int is_write))
@@ -889,13 +898,13 @@ 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 = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                 nd->vlan, nd->netdev,
-                                 nd->model, nd->name,
-                                 nic_can_receive, nic_receive, NULL, NULL,
-                                 nic_cleanup, s);
+    memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(s->conf.macaddr));
+    s->conf.vlan = nd->vlan;
+    s->conf.peer = nd->netdev;
+
+    s->nic = qemu_new_nic(&net_dp83932_info, &s->conf, nd->model, nd->name, s);
 
-    qemu_format_nic_info_str(s->vc, nd->macaddr);
+    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     qemu_register_reset(nic_reset, s);
     nic_reset(s);
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 25/44] net: convert etrax to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (23 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 24/44] net: convert dp8393x " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 26/44] net: convert LAN9118 " Mark McLoughlin
                   ` (18 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/etraxfs_eth.c |   45 +++++++++++++++++++++++++++------------------
 1 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index 2cc2332..dedd107 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -319,7 +319,8 @@ static void mdio_cycle(struct qemu_mdio *bus)
 
 struct fs_eth
 {
-	VLANClientState *vc;
+	NICState *nic;
+	NICConf conf;
 	int ethregs;
 
 	/* Two addrs in the filter.  */
@@ -495,15 +496,15 @@ static int eth_match_groupaddr(struct fs_eth *eth, const unsigned char *sa)
 	return match;
 }
 
-static int eth_can_receive(VLANClientState *vc)
+static int eth_can_receive(VLANClientState *nc)
 {
 	return 1;
 }
 
-static ssize_t eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t eth_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
 	unsigned char sa_bcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
-	struct fs_eth *eth = vc->opaque;
+	struct fs_eth *eth = DO_UPCAST(NICState, nc, nc)->opaque;
 	int use_ma0 = eth->regs[RW_REC_CTRL] & 1;
 	int use_ma1 = eth->regs[RW_REC_CTRL] & 2;
 	int r_bcast = eth->regs[RW_REC_CTRL] & 8;
@@ -533,15 +534,15 @@ static int eth_tx_push(void *opaque, unsigned char *buf, int len)
 	struct fs_eth *eth = opaque;
 
 	D(printf("%s buf=%p len=%d\n", __func__, buf, len));
-	qemu_send_packet(eth->vc, buf, len);
+	qemu_send_packet(&eth->nic->nc, buf, len);
 	return len;
 }
 
-static void eth_set_link(VLANClientState *vc)
+static void eth_set_link(VLANClientState *nc)
 {
-	struct fs_eth *eth = vc->opaque;
-	D(printf("%s %d\n", __func__, vc->link_down));
-	eth->phy.link = !vc->link_down;
+	struct fs_eth *eth = DO_UPCAST(NICState, nc, nc)->opaque;
+	D(printf("%s %d\n", __func__, nc->link_down));
+	eth->phy.link = !nc->link_down;
 }
 
 static CPUReadMemoryFunc * const eth_read[] = {
@@ -554,9 +555,9 @@ static CPUWriteMemoryFunc * const eth_write[] = {
 	&eth_writel,
 };
 
-static void eth_cleanup(VLANClientState *vc)
+static void eth_cleanup(VLANClientState *nc)
 {
-        struct fs_eth *eth = vc->opaque;
+	struct fs_eth *eth = DO_UPCAST(NICState, nc, nc)->opaque;
 
         cpu_unregister_io_memory(eth->ethregs);
 
@@ -564,6 +565,15 @@ static void eth_cleanup(VLANClientState *vc)
         qemu_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,
+};
+
 void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t base, int phyaddr)
 {
 	struct etraxfs_dma_client *dma = NULL;	
@@ -590,13 +600,12 @@ 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 = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                       nd->vlan, nd->netdev,
-                                       nd->model, nd->name,
-                                       eth_can_receive, eth_receive,
-                                       NULL, NULL, eth_cleanup, eth);
-	eth->vc->opaque = eth;
-	eth->vc->link_status_changed = eth_set_link;
+	memcpy(eth->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr));
+	eth->conf.vlan = nd->vlan;
+	eth->conf.peer = nd->netdev;
+
+	eth->nic = qemu_new_nic(&net_etraxfs_info, &eth->conf,
+				nd->model, nd->name, eth);
 
 	return dma;
 }
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 26/44] net: convert LAN9118 to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (24 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 25/44] net: convert etrax " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 27/44] net: convert mcf_fec " Mark McLoughlin
                   ` (17 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/lan9118.c |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/hw/lan9118.c b/hw/lan9118.c
index 6394f3a..ba982d1 100644
--- a/hw/lan9118.c
+++ b/hw/lan9118.c
@@ -137,7 +137,7 @@ typedef struct {
 
 typedef struct {
     SysBusDevice busdev;
-    VLANClientState *vc;
+    NICState *nic;
     NICConf conf;
     qemu_irq irq;
     int mmio_index;
@@ -212,7 +212,7 @@ static void lan9118_update(lan9118_state *s)
 
 static void lan9118_mac_changed(lan9118_state *s)
 {
-    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
+    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 }
 
 static void lan9118_reload_eeprom(lan9118_state *s)
@@ -234,16 +234,16 @@ static void lan9118_reload_eeprom(lan9118_state *s)
 static void phy_update_link(lan9118_state *s)
 {
     /* Autonegotiation status mirrors link status.  */
-    if (s->vc->link_down) {
+    if (s->nic->nc.link_down) {
         s->phy_status &= ~0x0024;
     } else {
         s->phy_status |= 0x0024;
     }
 }
 
-static void lan9118_set_link(VLANClientState *vc)
+static void lan9118_set_link(VLANClientState *nc)
 {
-    phy_update_link(vc->opaque);
+    phy_update_link(DO_UPCAST(NICState, nc, nc)->opaque);
 }
 
 static void phy_reset(lan9118_state *s)
@@ -305,7 +305,7 @@ static void lan9118_reset(DeviceState *d)
     lan9118_reload_eeprom(s);
 }
 
-static int lan9118_can_receive(VLANClientState *vc)
+static int lan9118_can_receive(VLANClientState *nc)
 {
     return 1;
 }
@@ -358,10 +358,10 @@ static int lan9118_filter(lan9118_state *s, const uint8_t *addr)
     }
 }
 
-static ssize_t lan9118_receive(VLANClientState *vc, const uint8_t *buf,
+static ssize_t lan9118_receive(VLANClientState *nc, const uint8_t *buf,
                                size_t size)
 {
-    lan9118_state *s = vc->opaque;
+    lan9118_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
     int fifo_len;
     int offset;
     int src_pos;
@@ -506,9 +506,9 @@ static void do_tx_packet(lan9118_state *s)
     /* FIXME: Honor TX disable, and allow queueing of packets.  */
     if (s->phy_control & 0x4000)  {
         /* This assumes the receive routine doesn't touch the VLANClient.  */
-        lan9118_receive(s->vc, s->txp->data, s->txp->len);
+        lan9118_receive(&s->nic->nc, s->txp->data, s->txp->len);
     } else {
-        qemu_send_packet(s->vc, s->txp->data, s->txp->len);
+        qemu_send_packet(&s->nic->nc, s->txp->data, s->txp->len);
     }
     s->txp->fifo_used = 0;
 
@@ -1022,13 +1022,22 @@ static CPUWriteMemoryFunc * const lan9118_writefn[] = {
     lan9118_writel
 };
 
-static void lan9118_cleanup(VLANClientState *vc)
+static void lan9118_cleanup(VLANClientState *nc)
 {
-    lan9118_state *s = vc->opaque;
+    lan9118_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
-    s->vc = NULL;
+    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,
+};
+
 static int lan9118_init1(SysBusDevice *dev)
 {
     lan9118_state *s = FROM_SYSBUS(lan9118_state, dev);
@@ -1040,13 +1049,9 @@ static int lan9118_init1(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                 s->conf.vlan, s->conf.peer,
-                                 dev->qdev.info->name, dev->qdev.id,
-                                 lan9118_can_receive, lan9118_receive, NULL,
-                                 NULL, lan9118_cleanup, s);
-    s->vc->link_status_changed = lan9118_set_link;
-    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
+    s->nic = qemu_new_nic(&net_lan9118_info, &s->conf,
+                          dev->qdev.info->name, dev->qdev.id, s);
+    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     s->eeprom[0] = 0xa5;
     for (i = 0; i < 6; i++) {
         s->eeprom[i + 1] = s->conf.macaddr.a[i];
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 27/44] net: convert mcf_fec to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (25 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 26/44] net: convert LAN9118 " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 28/44] net: convert mipsnet " Mark McLoughlin
                   ` (16 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/mcf_fec.c |   58 +++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 33 insertions(+), 25 deletions(-)

diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 8242c8a..4e7fbed 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -25,7 +25,8 @@ do { printf("mcf_fec: " fmt , ## __VA_ARGS__); } while (0)
 typedef struct {
     qemu_irq *irq;
     int mmio_index;
-    VLANClientState *vc;
+    NICState *nic;
+    NICConf conf;
     uint32_t irq_state;
     uint32_t eir;
     uint32_t eimr;
@@ -42,7 +43,6 @@ typedef struct {
     uint32_t erdsr;
     uint32_t etdsr;
     uint32_t emrbr;
-    uint8_t macaddr[6];
 } mcf_fec_state;
 
 #define FEC_INT_HB   0x80000000
@@ -172,7 +172,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)
         if (bd.flags & FEC_BD_L) {
             /* Last buffer in frame.  */
             DPRINTF("Sending packet\n");
-            qemu_send_packet(s->vc, frame, len);
+            qemu_send_packet(&s->nic->nc, frame, len);
             ptr = frame;
             frame_size = 0;
             s->eir |= FEC_INT_TXF;
@@ -229,11 +229,11 @@ static uint32_t mcf_fec_read(void *opaque, target_phys_addr_t addr)
     case 0x084: return s->rcr;
     case 0x0c4: return s->tcr;
     case 0x0e4: /* PALR */
-        return (s->macaddr[0] << 24) | (s->macaddr[1] << 16)
-              | (s->macaddr[2] << 8) | s->macaddr[3];
+        return (s->conf.macaddr.a[0] << 24) | (s->conf.macaddr.a[1] << 16)
+              | (s->conf.macaddr.a[2] << 8) | s->conf.macaddr.a[3];
         break;
     case 0x0e8: /* PAUR */
-        return (s->macaddr[4] << 24) | (s->macaddr[5] << 16) | 0x8808;
+        return (s->conf.macaddr.a[4] << 24) | (s->conf.macaddr.a[5] << 16) | 0x8808;
     case 0x0ec: return 0x10000; /* OPD */
     case 0x118: return 0;
     case 0x11c: return 0;
@@ -303,14 +303,14 @@ static void mcf_fec_write(void *opaque, target_phys_addr_t addr, uint32_t value)
             s->eir |= FEC_INT_GRA;
         break;
     case 0x0e4: /* PALR */
-        s->macaddr[0] = value >> 24;
-        s->macaddr[1] = value >> 16;
-        s->macaddr[2] = value >> 8;
-        s->macaddr[3] = value;
+        s->conf.macaddr.a[0] = value >> 24;
+        s->conf.macaddr.a[1] = value >> 16;
+        s->conf.macaddr.a[2] = value >> 8;
+        s->conf.macaddr.a[3] = value;
         break;
     case 0x0e8: /* PAUR */
-        s->macaddr[4] = value >> 24;
-        s->macaddr[5] = value >> 16;
+        s->conf.macaddr.a[4] = value >> 24;
+        s->conf.macaddr.a[5] = value >> 16;
         break;
     case 0x0ec:
         /* OPD */
@@ -347,15 +347,15 @@ static void mcf_fec_write(void *opaque, target_phys_addr_t addr, uint32_t value)
     mcf_fec_update(s);
 }
 
-static int mcf_fec_can_receive(VLANClientState *vc)
+static int mcf_fec_can_receive(VLANClientState *nc)
 {
-    mcf_fec_state *s = vc->opaque;
+    mcf_fec_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
     return s->rx_enabled;
 }
 
-static ssize_t mcf_fec_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t mcf_fec_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    mcf_fec_state *s = vc->opaque;
+    mcf_fec_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
     mcf_fec_bd bd;
     uint32_t flags = 0;
     uint32_t addr;
@@ -441,15 +441,23 @@ static CPUWriteMemoryFunc * const mcf_fec_writefn[] = {
    mcf_fec_write
 };
 
-static void mcf_fec_cleanup(VLANClientState *vc)
+static void mcf_fec_cleanup(VLANClientState *nc)
 {
-    mcf_fec_state *s = vc->opaque;
+    mcf_fec_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
     cpu_unregister_io_memory(s->mmio_index);
 
     qemu_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,
+};
+
 void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
 {
     mcf_fec_state *s;
@@ -462,11 +470,11 @@ 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 = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                 nd->vlan, nd->netdev,
-                                 nd->model, nd->name,
-                                 mcf_fec_can_receive, mcf_fec_receive,
-                                 NULL, NULL, mcf_fec_cleanup, s);
-    memcpy(s->macaddr, nd->macaddr, 6);
-    qemu_format_nic_info_str(s->vc, s->macaddr);
+    memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr));
+    s->conf.vlan = nd->vlan;
+    s->conf.peer = nd->netdev;
+
+    s->nic = qemu_new_nic(&net_mcf_fec_info, &s->conf, nd->model, nd->name, s);
+
+    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 }
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 28/44] net: convert mipsnet to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (26 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 27/44] net: convert mcf_fec " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 29/44] net: convert musicpal " Mark McLoughlin
                   ` (15 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/mipsnet.c |   45 +++++++++++++++++++++++++++------------------
 1 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 67160a4..a066f63 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -35,7 +35,8 @@ typedef struct MIPSnetState {
     uint8_t tx_buffer[MAX_ETH_FRAME_SIZE];
     int io_base;
     qemu_irq irq;
-    VLANClientState *vc;
+    NICState *nic;
+    NICConf conf;
 } MIPSnetState;
 
 static void mipsnet_reset(MIPSnetState *s)
@@ -66,23 +67,23 @@ static int mipsnet_buffer_full(MIPSnetState *s)
     return 0;
 }
 
-static int mipsnet_can_receive(VLANClientState *vc)
+static int mipsnet_can_receive(VLANClientState *nc)
 {
-    MIPSnetState *s = vc->opaque;
+    MIPSnetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
     if (s->busy)
         return 0;
     return !mipsnet_buffer_full(s);
 }
 
-static ssize_t mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t mipsnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    MIPSnetState *s = vc->opaque;
+    MIPSnetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
 #ifdef DEBUG_MIPSNET_RECEIVE
     printf("mipsnet: receiving len=%d\n", size);
 #endif
-    if (!mipsnet_can_receive(vc))
+    if (!mipsnet_can_receive(nc))
         return -1;
 
     s->busy = 1;
@@ -183,7 +184,7 @@ static void mipsnet_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 #ifdef DEBUG_MIPSNET_SEND
             printf("mipsnet: sending len=%d\n", s->tx_count);
 #endif
-            qemu_send_packet(s->vc, s->tx_buffer, s->tx_count);
+            qemu_send_packet(&s->nic->nc, s->tx_buffer, s->tx_count);
             s->tx_count = s->tx_written = 0;
             s->intctl |= MIPSNET_INTCTL_TXDONE;
             s->busy = 1;
@@ -234,9 +235,9 @@ static int mipsnet_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-static void mipsnet_cleanup(VLANClientState *vc)
+static void mipsnet_cleanup(VLANClientState *nc)
 {
-    MIPSnetState *s = vc->opaque;
+    MIPSnetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
     unregister_savevm("mipsnet", s);
 
@@ -245,6 +246,14 @@ static void mipsnet_cleanup(VLANClientState *vc)
     qemu_free(s);
 }
 
+static NetClientInfo net_mipsnet_info = {
+    .type = NET_CLIENT_TYPE_NIC,
+    .size = sizeof(NICState),
+    .can_receive = mipsnet_can_receive,
+    .receive = mipsnet_receive,
+    .cleanup = mipsnet_cleanup,
+};
+
 void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
 {
     MIPSnetState *s;
@@ -262,17 +271,17 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
 
     s->io_base = base;
     s->irq = irq;
+
     if (nd) {
-        s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                     nd->vlan, nd->netdev,
-                                     nd->model, nd->name,
-                                     mipsnet_can_receive, mipsnet_receive,
-                                     NULL, NULL, mipsnet_cleanup, s);
-    } else {
-        s->vc = NULL;
-    }
+        memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr));
+        s->conf.vlan = nd->vlan;
+        s->conf.peer = nd->netdev;
 
-    qemu_format_nic_info_str(s->vc, nd->macaddr);
+        s->nic = qemu_new_nic(&net_mipsnet_info, &s->conf,
+                              nd->model, nd->name, s);
+
+        qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+    }
 
     mipsnet_reset(s);
     register_savevm("mipsnet", 0, 0, mipsnet_save, mipsnet_load, s);
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 29/44] net: convert musicpal to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (27 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 28/44] net: convert mipsnet " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 30/44] net: convert smc91c111 " Mark McLoughlin
                   ` (14 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/musicpal.c |   31 ++++++++++++++++++-------------
 1 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/hw/musicpal.c b/hw/musicpal.c
index 264669f..4a33e28 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -151,7 +151,7 @@ typedef struct mv88w8618_eth_state {
     uint32_t rx_queue[4];
     uint32_t frx_queue[4];
     uint32_t cur_rx[4];
-    VLANClientState *vc;
+    NICState *nic;
     NICConf conf;
 } mv88w8618_eth_state;
 
@@ -175,14 +175,14 @@ static void eth_rx_desc_get(uint32_t addr, mv88w8618_rx_desc *desc)
     le32_to_cpus(&desc->next);
 }
 
-static int eth_can_receive(VLANClientState *vc)
+static int eth_can_receive(VLANClientState *nc)
 {
     return 1;
 }
 
-static ssize_t eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t eth_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    mv88w8618_eth_state *s = vc->opaque;
+    mv88w8618_eth_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
     uint32_t desc_addr;
     mv88w8618_rx_desc desc;
     int i;
@@ -250,7 +250,7 @@ static void eth_send(mv88w8618_eth_state *s, int queue_index)
             len = desc.bytes;
             if (len < 2048) {
                 cpu_physical_memory_read(desc.buffer, buf, len);
-                qemu_send_packet(s->vc, buf, len);
+                qemu_send_packet(&s->nic->nc, buf, len);
             }
             desc.cmdstat &= ~MP_ETH_TX_OWN;
             s->icr |= 1 << (MP_ETH_IRQ_TXLO_BIT - queue_index);
@@ -365,23 +365,28 @@ static CPUWriteMemoryFunc * const mv88w8618_eth_writefn[] = {
     mv88w8618_eth_write
 };
 
-static void eth_cleanup(VLANClientState *vc)
+static void eth_cleanup(VLANClientState *nc)
 {
-    mv88w8618_eth_state *s = vc->opaque;
+    mv88w8618_eth_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
-    s->vc = NULL;
+    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,
+};
+
 static int mv88w8618_eth_init(SysBusDevice *dev)
 {
     mv88w8618_eth_state *s = FROM_SYSBUS(mv88w8618_eth_state, dev);
 
     sysbus_init_irq(dev, &s->irq);
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                 s->conf.vlan, s->conf.peer,
-                                 dev->qdev.info->name, dev->qdev.id,
-                                 eth_can_receive, eth_receive, NULL,
-                                 NULL, eth_cleanup, s);
+    s->nic = qemu_new_nic(&net_mv88w8618_info, &s->conf,
+                          dev->qdev.info->name, dev->qdev.id, s);
     s->mmio_index = cpu_register_io_memory(mv88w8618_eth_readfn,
                                            mv88w8618_eth_writefn, s);
     sysbus_init_mmio(dev, MP_ETH_SIZE, s->mmio_index);
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 30/44] net: convert smc91c111 to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (28 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 29/44] net: convert musicpal " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 31/44] net: convert stellaris " Mark McLoughlin
                   ` (13 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/smc91c111.c |   35 ++++++++++++++++++++---------------
 1 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index b7398c9..c1a88c9 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -18,7 +18,7 @@
 
 typedef struct {
     SysBusDevice busdev;
-    VLANClientState *vc;
+    NICState *nic;
     NICConf conf;
     uint16_t tcr;
     uint16_t rcr;
@@ -207,7 +207,7 @@ static void smc91c111_do_tx(smc91c111_state *s)
             smc91c111_release_packet(s, packetnum);
         else if (s->tx_fifo_done_len < NUM_PACKETS)
             s->tx_fifo_done[s->tx_fifo_done_len++] = packetnum;
-        qemu_send_packet(s->vc, p, len);
+        qemu_send_packet(&s->nic->nc, p, len);
     }
     s->tx_fifo_len = 0;
     smc91c111_update(s);
@@ -591,9 +591,9 @@ static uint32_t smc91c111_readl(void *opaque, target_phys_addr_t offset)
     return val;
 }
 
-static int smc91c111_can_receive(VLANClientState *vc)
+static int smc91c111_can_receive(VLANClientState *nc)
 {
-    smc91c111_state *s = vc->opaque;
+    smc91c111_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
     if ((s->rcr & RCR_RXEN) == 0 || (s->rcr & RCR_SOFT_RST))
         return 1;
@@ -602,9 +602,9 @@ static int smc91c111_can_receive(VLANClientState *vc)
     return 1;
 }
 
-static ssize_t smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t smc91c111_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    smc91c111_state *s = vc->opaque;
+    smc91c111_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
     int status;
     int packetsize;
     uint32_t crc;
@@ -692,13 +692,21 @@ static CPUWriteMemoryFunc * const smc91c111_writefn[] = {
     smc91c111_writel
 };
 
-static void smc91c111_cleanup(VLANClientState *vc)
+static void smc91c111_cleanup(VLANClientState *nc)
 {
-    smc91c111_state *s = vc->opaque;
+    smc91c111_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
-    s->vc = NULL;
+    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,
+};
+
 static int smc91c111_init1(SysBusDevice *dev)
 {
     smc91c111_state *s = FROM_SYSBUS(smc91c111_state, dev);
@@ -711,12 +719,9 @@ static int smc91c111_init1(SysBusDevice *dev)
 
     smc91c111_reset(s);
 
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                 s->conf.vlan, s->conf.peer,
-                                 dev->qdev.info->name, dev->qdev.id,
-                                 smc91c111_can_receive, smc91c111_receive, NULL,
-                                 NULL, smc91c111_cleanup, s);
-    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
+    s->nic = qemu_new_nic(&net_smc91c111_info, &s->conf,
+                          dev->qdev.info->name, dev->qdev.id, s);
+    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     /* ??? Save/restore.  */
     return 0;
 }
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 31/44] net: convert stellaris to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (29 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 30/44] net: convert smc91c111 " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 32/44] net: convert usb-net " Mark McLoughlin
                   ` (12 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/stellaris_enet.c |   34 +++++++++++++++++++---------------
 1 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c
index 2252f1a..d1d755e 100644
--- a/hw/stellaris_enet.c
+++ b/hw/stellaris_enet.c
@@ -66,7 +66,7 @@ typedef struct {
     uint8_t *rx_fifo;
     int rx_fifo_len;
     int next_packet;
-    VLANClientState *vc;
+    NICState *nic;
     NICConf conf;
     qemu_irq irq;
     int mmio_index;
@@ -78,9 +78,9 @@ static void stellaris_enet_update(stellaris_enet_state *s)
 }
 
 /* TODO: Implement MAC address filtering.  */
-static ssize_t stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t stellaris_enet_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    stellaris_enet_state *s = vc->opaque;
+    stellaris_enet_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
     int n;
     uint8_t *p;
     uint32_t crc;
@@ -120,9 +120,9 @@ static ssize_t stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, s
     return size;
 }
 
-static int stellaris_enet_can_receive(VLANClientState *vc)
+static int stellaris_enet_can_receive(VLANClientState *nc)
 {
-    stellaris_enet_state *s = vc->opaque;
+    stellaris_enet_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
     if ((s->rctl & SE_RCTL_RXEN) == 0)
         return 1;
@@ -258,7 +258,7 @@ static void stellaris_enet_write(void *opaque, target_phys_addr_t offset,
                     memset(&s->tx_fifo[s->tx_frame_len], 0, 60 - s->tx_frame_len);
                     s->tx_fifo_len = 60;
                 }
-                qemu_send_packet(s->vc, s->tx_fifo, s->tx_frame_len);
+                qemu_send_packet(&s->nic->nc, s->tx_fifo, s->tx_frame_len);
                 s->tx_frame_len = -1;
                 s->ris |= SE_INT_TXEMP;
                 stellaris_enet_update(s);
@@ -385,9 +385,9 @@ static int stellaris_enet_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-static void stellaris_enet_cleanup(VLANClientState *vc)
+static void stellaris_enet_cleanup(VLANClientState *nc)
 {
-    stellaris_enet_state *s = vc->opaque;
+    stellaris_enet_state *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
     unregister_savevm("stellaris_enet", s);
 
@@ -396,6 +396,14 @@ static void stellaris_enet_cleanup(VLANClientState *vc)
     qemu_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,
+};
+
 static int stellaris_enet_init(SysBusDevice *dev)
 {
     stellaris_enet_state *s = FROM_SYSBUS(stellaris_enet_state, dev);
@@ -406,13 +414,9 @@ static int stellaris_enet_init(SysBusDevice *dev)
     sysbus_init_irq(dev, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                 s->conf.vlan, s->conf.peer,
-                                 dev->qdev.info->name, dev->qdev.id,
-                                 stellaris_enet_can_receive,
-                                 stellaris_enet_receive, NULL, NULL,
-                                 stellaris_enet_cleanup, s);
-    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
+    s->nic = qemu_new_nic(&net_stellaris_enet_info, &s->conf,
+                          dev->qdev.info->name, dev->qdev.id, s);
+    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     stellaris_enet_reset(s);
     register_savevm("stellaris_enet", -1, 1,
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 32/44] net: convert usb-net to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (30 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 31/44] net: convert stellaris " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 33/44] net: convert xilinx_ethlite " Mark McLoughlin
                   ` (11 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/usb-net.c |   57 +++++++++++++++++++++++++++++++--------------------------
 1 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/hw/usb-net.c b/hw/usb-net.c
index 7b8cc7a..2556e05 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -610,7 +610,6 @@ typedef struct USBNetState {
     uint32_t media_state;
     uint16_t filter;
     uint32_t vendorid;
-    uint8_t mac[6];
 
     unsigned int out_ptr;
     uint8_t out_buf[2048];
@@ -620,7 +619,8 @@ typedef struct USBNetState {
     uint8_t in_buf[2048];
 
     char usbstring_mac[13];
-    VLANClientState *vc;
+    NICState *nic;
+    NICConf conf;
     QTAILQ_HEAD(rndis_resp_head, rndis_response) rndis_resp;
 } USBNetState;
 
@@ -741,12 +741,12 @@ static int ndis_query(USBNetState *s, uint32_t oid,
     /* ieee802.3 OIDs (table 4-3) */
     /* mandatory */
     case OID_802_3_PERMANENT_ADDRESS:
-        memcpy(outbuf, s->mac, 6);
+        memcpy(outbuf, s->conf.macaddr.a, 6);
         return 6;
 
     /* mandatory */
     case OID_802_3_CURRENT_ADDRESS:
-        memcpy(outbuf, s->mac, 6);
+        memcpy(outbuf, s->conf.macaddr.a, 6);
         return 6;
 
     /* mandatory */
@@ -1305,7 +1305,7 @@ static int usb_net_handle_dataout(USBNetState *s, USBPacket *p)
 
     if (!s->rndis) {
         if (ret < 64) {
-            qemu_send_packet(s->vc, s->out_buf, s->out_ptr);
+            qemu_send_packet(&s->nic->nc, s->out_buf, s->out_ptr);
             s->out_ptr = 0;
         }
         return ret;
@@ -1317,7 +1317,7 @@ static int usb_net_handle_dataout(USBNetState *s, USBPacket *p)
         uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
         uint32_t size = le32_to_cpu(msg->DataLength);
         if (offs + size <= len)
-            qemu_send_packet(s->vc, s->out_buf + offs, size);
+            qemu_send_packet(&s->nic->nc, s->out_buf + offs, size);
     }
     s->out_ptr -= len;
     memmove(s->out_buf, &s->out_buf[len], s->out_ptr);
@@ -1369,9 +1369,9 @@ static int usb_net_handle_data(USBDevice *dev, USBPacket *p)
     return ret;
 }
 
-static ssize_t usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t usbnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    USBNetState *s = vc->opaque;
+    USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
     struct rndis_packet_msg_type *msg;
 
     if (s->rndis) {
@@ -1406,9 +1406,9 @@ static ssize_t usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t si
     return size;
 }
 
-static int usbnet_can_receive(VLANClientState *vc)
+static int usbnet_can_receive(VLANClientState *nc)
 {
-    USBNetState *s = vc->opaque;
+    USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
     if (s->rndis && !s->rndis_state == RNDIS_DATA_INITIALIZED)
         return 1;
@@ -1416,9 +1416,9 @@ static int usbnet_can_receive(VLANClientState *vc)
     return !s->in_len;
 }
 
-static void usbnet_cleanup(VLANClientState *vc)
+static void usbnet_cleanup(VLANClientState *nc)
 {
-    USBNetState *s = vc->opaque;
+    USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
     rndis_clear_responsequeue(s);
     qemu_free(s);
@@ -1429,7 +1429,7 @@ static void usb_net_handle_destroy(USBDevice *dev)
     USBNetState *s = (USBNetState *) dev;
 
     /* TODO: remove the nd_table[] entry */
-    qemu_del_vlan_client(s->vc);
+    qemu_del_vlan_client(&s->nic->nc);
 }
 
 static int usb_net_initfn(USBDevice *dev)
@@ -1450,6 +1450,14 @@ static int usb_net_initfn(USBDevice *dev)
     return 0;
 }
 
+static NetClientInfo net_usbnet_info = {
+    .type = NET_CLIENT_TYPE_NIC,
+    .size = sizeof(NICState),
+    .can_receive = usbnet_can_receive,
+    .receive = usbnet_receive,
+    .cleanup = usbnet_cleanup,
+};
+
 USBDevice *usb_net_init(NICInfo *nd)
 {
     USBDevice *dev;
@@ -1458,25 +1466,22 @@ USBDevice *usb_net_init(NICInfo *nd)
     dev = usb_create_simple(NULL /* FIXME */, "QEMU USB Network Interface");
     s = DO_UPCAST(USBNetState, dev, dev);
 
-    memcpy(s->mac, nd->macaddr, 6);
+    memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr));
+    s->conf.vlan = nd->vlan;
+    s->conf.peer = nd->netdev;
 
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                 nd->vlan, nd->netdev,
-                                 nd->model, nd->name,
-                                 usbnet_can_receive,
-                                 usbnet_receive,
-                                 NULL, NULL,
-                                 usbnet_cleanup, s);
+    s->nic = qemu_new_nic(&net_usbnet_info, &s->conf,
+                          nd->model, nd->name, s);
 
-    qemu_format_nic_info_str(s->vc, s->mac);
+    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
 
     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]);
+                    0x40, s->conf.macaddr.a[1], s->conf.macaddr.a[2],
+                    s->conf.macaddr.a[3], s->conf.macaddr.a[4], s->conf.macaddr.a[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]);
+                    s->conf.macaddr.a[0], s->conf.macaddr.a[1], s->conf.macaddr.a[2],
+                    s->conf.macaddr.a[3], s->conf.macaddr.a[4], s->conf.macaddr.a[5]);
 
     return (USBDevice *) s;
 }
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 33/44] net: convert xilinx_ethlite to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (31 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 32/44] net: convert usb-net " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 34/44] net: move parse_macaddr() to net/util.[ch] Mark McLoughlin
                   ` (10 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/xilinx_ethlite.c |   35 ++++++++++++++++++++---------------
 1 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/hw/xilinx_ethlite.c b/hw/xilinx_ethlite.c
index b7129d5..37e33ec 100644
--- a/hw/xilinx_ethlite.c
+++ b/hw/xilinx_ethlite.c
@@ -51,7 +51,7 @@ struct xlx_ethlite
 {
     SysBusDevice busdev;
     qemu_irq irq;
-    VLANClientState *vc;
+    NICState *nic;
     NICConf conf;
 
     uint32_t c_tx_pingpong;
@@ -118,7 +118,7 @@ eth_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
 
             D(qemu_log("%s addr=%x val=%x\n", __func__, addr * 4, value));
             if ((value & (CTRL_P | CTRL_S)) == CTRL_S) {
-                qemu_send_packet(s->vc,
+                qemu_send_packet(&s->nic->nc,
                                  (void *) &s->regs[base],
                                  s->regs[base + R_TX_LEN0]);
                 D(qemu_log("eth_tx %d\n", s->regs[base + R_TX_LEN0]));
@@ -160,17 +160,17 @@ static CPUWriteMemoryFunc * const eth_write[] = {
     NULL, NULL, &eth_writel,
 };
 
-static int eth_can_rx(VLANClientState *vc)
+static int eth_can_rx(VLANClientState *nc)
 {
-    struct xlx_ethlite *s = vc->opaque;
+    struct xlx_ethlite *s = DO_UPCAST(NICState, nc, nc)->opaque;
     int r;
     r = !(s->regs[R_RX_CTRL0] & CTRL_S);
     return r;
 }
 
-static ssize_t eth_rx(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t eth_rx(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    struct xlx_ethlite *s = vc->opaque;
+    struct xlx_ethlite *s = DO_UPCAST(NICState, nc, nc)->opaque;
     unsigned int rxbase = s->rxbuf * (0x800 / 4);
     int i;
 
@@ -201,13 +201,21 @@ static ssize_t eth_rx(VLANClientState *vc, const uint8_t *buf, size_t size)
     return size;
 }
 
-static void eth_cleanup(VLANClientState *vc)
+static void eth_cleanup(VLANClientState *nc)
 {
-    struct xlx_ethlite *s = vc->opaque;
+    struct xlx_ethlite *s = DO_UPCAST(NICState, nc, nc)->opaque;
 
-    s->vc = NULL;
+    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,
+};
+
 static int xilinx_ethlite_init(SysBusDevice *dev)
 {
     struct xlx_ethlite *s = FROM_SYSBUS(typeof (*s), dev);
@@ -220,12 +228,9 @@ static int xilinx_ethlite_init(SysBusDevice *dev)
     sysbus_init_mmio(dev, R_MAX * 4, regs);
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                 s->conf.vlan, s->conf.peer,
-                                 dev->qdev.info->name, dev->qdev.id,
-                                 eth_can_rx, eth_rx, NULL,
-                                 NULL, eth_cleanup, s);
-    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
+    s->nic = qemu_new_nic(&net_xilinx_ethlite_info, &s->conf,
+                          dev->qdev.info->name, dev->qdev.id, s);
+    qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
     return 0;
 }
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 34/44] net: move parse_macaddr() to net/util.[ch]
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (32 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 33/44] net: convert xilinx_ethlite " Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 35/44] net: convert xen to NICState Mark McLoughlin
                   ` (9 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 Makefile   |    2 +-
 net.c      |   35 ++---------------------------------
 net/util.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/util.h |   32 ++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+), 34 deletions(-)
 create mode 100644 net/util.c
 create mode 100644 net/util.h

diff --git a/Makefile b/Makefile
index 6ed4bf8..b18bba9 100644
--- a/Makefile
+++ b/Makefile
@@ -99,7 +99,7 @@ block-nested-$(CONFIG_CURL) += curl.o
 block-obj-y +=  $(addprefix block/, $(block-nested-y))
 
 net-obj-y = net.o
-net-nested-y = queue.o checksum.o
+net-nested-y = queue.o checksum.o util.o
 net-nested-y += socket.o
 net-nested-y += dump.o
 net-nested-$(CONFIG_POSIX) += tap.o
diff --git a/net.c b/net.c
index 7195827..cca008a 100644
--- a/net.c
+++ b/net.c
@@ -30,6 +30,7 @@
 #include "net/dump.h"
 #include "net/slirp.h"
 #include "net/vde.h"
+#include "net/util.h"
 #include "monitor.h"
 #include "sysemu.h"
 #include "qemu-common.h"
@@ -69,38 +70,6 @@ static void hex_dump(FILE *f, const uint8_t *buf, int size)
 }
 #endif
 
-static int parse_macaddr(uint8_t *macaddr, const char *p)
-{
-    int i;
-    char *last_char;
-    long int offset;
-
-    errno = 0;
-    offset = strtol(p, &last_char, 0);    
-    if (0 == errno && '\0' == *last_char &&
-            offset >= 0 && offset <= 0xFFFFFF) {
-        macaddr[3] = (offset & 0xFF0000) >> 16;
-        macaddr[4] = (offset & 0xFF00) >> 8;
-        macaddr[5] = offset & 0xFF;
-        return 0;
-    } else {
-        for(i = 0; i < 6; i++) {
-            macaddr[i] = strtol(p, (char **)&p, 16);
-            if (i == 5) {
-                if (*p != '\0')
-                    return -1;
-            } else {
-                if (*p != ':' && *p != '-')
-                    return -1;
-                p++;
-            }
-        }
-        return 0;    
-    }
-
-    return -1;
-}
-
 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
 {
     const char *p, *p1;
@@ -858,7 +827,7 @@ static int net_init_nic(QemuOpts *opts,
     nd->macaddr[5] = 0x56 + idx;
 
     if (qemu_opt_get(opts, "macaddr") &&
-        parse_macaddr(nd->macaddr, qemu_opt_get(opts, "macaddr")) < 0) {
+        net_parse_macaddr(nd->macaddr, qemu_opt_get(opts, "macaddr")) < 0) {
         qemu_error("invalid syntax for ethernet address\n");
         return -1;
     }
diff --git a/net/util.c b/net/util.c
new file mode 100644
index 0000000..1e9afbc
--- /dev/null
+++ b/net/util.c
@@ -0,0 +1,60 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "net/util.h"
+#include <errno.h>
+#include <stdlib.h>
+
+int net_parse_macaddr(uint8_t *macaddr, const char *p)
+{
+    int i;
+    char *last_char;
+    long int offset;
+
+    errno = 0;
+    offset = strtol(p, &last_char, 0);
+    if (errno == 0 && *last_char == '\0' &&
+        offset >= 0 && offset <= 0xFFFFFF) {
+        macaddr[3] = (offset & 0xFF0000) >> 16;
+        macaddr[4] = (offset & 0xFF00) >> 8;
+        macaddr[5] = offset & 0xFF;
+        return 0;
+    }
+
+    for (i = 0; i < 6; i++) {
+        macaddr[i] = strtol(p, (char **)&p, 16);
+        if (i == 5) {
+            if (*p != '\0') {
+                return -1;
+            }
+        } else {
+            if (*p != ':' && *p != '-') {
+                return -1;
+            }
+            p++;
+        }
+    }
+
+    return 0;
+}
diff --git a/net/util.h b/net/util.h
new file mode 100644
index 0000000..10c7da9
--- /dev/null
+++ b/net/util.h
@@ -0,0 +1,32 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_NET_UTIL_H
+#define QEMU_NET_UTIL_H
+
+#include <stdint.h>
+
+int net_parse_macaddr(uint8_t *macaddr, const char *p);
+
+#endif /* QEMU_NET_UTIL_H */
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 35/44] net: convert xen to NICState
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (33 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 34/44] net: move parse_macaddr() to net/util.[ch] Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 36/44] net: remove qemu_new_vlan_client() Mark McLoughlin
                   ` (8 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/xen_nic.c |   46 +++++++++++++++++++++++++++++-----------------
 1 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/hw/xen_nic.c b/hw/xen_nic.c
index bcf161c..08055b8 100644
--- a/hw/xen_nic.c
+++ b/hw/xen_nic.c
@@ -41,6 +41,7 @@
 #include "hw.h"
 #include "net.h"
 #include "net/checksum.h"
+#include "net/util.h"
 #include "qemu-char.h"
 #include "xen_backend.h"
 
@@ -56,7 +57,8 @@ struct XenNetDev {
     struct netif_rx_sring *rxs;
     netif_tx_back_ring_t  tx_ring;
     netif_rx_back_ring_t  rx_ring;
-    VLANClientState       *vs;
+    NICConf               conf;
+    NICState              *nic;
 };
 
 /* ------------------------------------------------------------- */
@@ -179,9 +181,9 @@ static void net_tx_packets(struct XenNetDev *netdev)
                     tmpbuf = qemu_malloc(XC_PAGE_SIZE);
                 memcpy(tmpbuf, page + txreq.offset, txreq.size);
 		net_checksum_calculate(tmpbuf, txreq.size);
-                qemu_send_packet(netdev->vs, tmpbuf, txreq.size);
+                qemu_send_packet(&netdev->nic->nc, tmpbuf, txreq.size);
             } else {
-                qemu_send_packet(netdev->vs, page + txreq.offset, txreq.size);
+                qemu_send_packet(&netdev->nic->nc, page + txreq.offset, txreq.size);
             }
 	    xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);
 	    net_tx_response(netdev, &txreq, NETIF_RSP_OKAY);
@@ -223,9 +225,9 @@ static void net_rx_response(struct XenNetDev *netdev,
 
 #define NET_IP_ALIGN 2
 
-static int net_rx_ok(VLANClientState *vc)
+static int net_rx_ok(VLANClientState *nc)
 {
-    struct XenNetDev *netdev = vc->opaque;
+    struct XenNetDev *netdev = DO_UPCAST(NICState, nc, nc)->opaque;
     RING_IDX rc, rp;
 
     if (netdev->xendev.be_state != XenbusStateConnected)
@@ -243,9 +245,9 @@ static int net_rx_ok(VLANClientState *vc)
     return 1;
 }
 
-static ssize_t net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t net_rx_packet(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    struct XenNetDev *netdev = vc->opaque;
+    struct XenNetDev *netdev = DO_UPCAST(NICState, nc, nc)->opaque;
     netif_rx_request_t rxreq;
     RING_IDX rc, rp;
     void *page;
@@ -288,10 +290,16 @@ static ssize_t net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t siz
 
 /* ------------------------------------------------------------- */
 
+static NetClientInfo net_xen_info = {
+    .type = NET_CLIENT_TYPE_NIC,
+    .size = sizeof(NICState),
+    .can_receive = net_rx_ok,
+    .receive = net_rx_packet,
+};
+
 static int net_init(struct XenDevice *xendev)
 {
     struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
-    VLANState *vlan;
 
     /* read xenstore entries */
     if (netdev->mac == NULL)
@@ -301,12 +309,16 @@ static int net_init(struct XenDevice *xendev)
     if (netdev->mac == NULL)
 	return -1;
 
-    vlan = qemu_find_vlan(netdev->xendev.dev, 1);
-    netdev->vs = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
-                                      vlan, NULL, "xen", NULL,
-                                      net_rx_ok, net_rx_packet, NULL, NULL,
-                                      NULL, netdev);
-    snprintf(netdev->vs->info_str, sizeof(netdev->vs->info_str),
+    if (net_parse_macaddr(netdev->conf.macaddr.a, netdev->mac) < 0)
+        return -1;
+
+    netdev->conf.vlan = qemu_find_vlan(netdev->xendev.dev, 1);
+    netdev->conf.peer = NULL;
+
+    netdev->nic = qemu_new_nic(&net_xen_info, &netdev->conf,
+                               "xen", NULL, netdev);
+
+    snprintf(netdev->nic->nc.info_str, sizeof(netdev->nic->nc.info_str),
              "nic: xenbus vif macaddr=%s", netdev->mac);
 
     /* fill info */
@@ -376,9 +388,9 @@ static void net_disconnect(struct XenDevice *xendev)
 	xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->rxs, 1);
 	netdev->rxs = NULL;
     }
-    if (netdev->vs) {
-        qemu_del_vlan_client(netdev->vs);
-        netdev->vs = NULL;
+    if (netdev->nic) {
+        qemu_del_vlan_client(&netdev->nic->nc);
+        netdev->nic = NULL;
     }
 }
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 36/44] net: remove qemu_new_vlan_client()
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (34 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 35/44] net: convert xen to NICState Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 37/44] net: remove VLANClientState members now in NetClientInfo Mark McLoughlin
                   ` (7 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

... and VLANClientState::opaque and qemu_find_vlan_client().

All of these are now unused

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |   44 --------------------------------------------
 net.h |   13 -------------
 2 files changed, 0 insertions(+), 57 deletions(-)

diff --git a/net.c b/net.c
index cca008a..d77320b 100644
--- a/net.c
+++ b/net.c
@@ -283,37 +283,6 @@ NICState *qemu_new_nic(NetClientInfo *info,
     return nic;
 }
 
-VLANClientState *qemu_new_vlan_client(net_client_type type,
-                                      VLANState *vlan,
-                                      VLANClientState *peer,
-                                      const char *model,
-                                      const char *name,
-                                      NetCanReceive *can_receive,
-                                      NetReceive *receive,
-                                      NetReceive *receive_raw,
-                                      NetReceiveIOV *receive_iov,
-                                      NetCleanup *cleanup,
-                                      void *opaque)
-{
-    VLANClientState *ret;
-    NetClientInfo info;
-
-    info.type = type;
-    info.size = sizeof(VLANClientState);
-    info.can_receive = can_receive;
-    info.receive = receive;
-    info.receive_raw = receive_raw;
-    info.receive_iov = receive_iov;
-    info.cleanup = cleanup;
-    info.link_status_changed = NULL;
-
-    ret = qemu_new_net_client(&info, vlan, peer, model, name);
-
-    ret->opaque = opaque;
-
-    return ret;
-}
-
 void qemu_del_vlan_client(VLANClientState *vc)
 {
     if (vc->vlan) {
@@ -337,19 +306,6 @@ void qemu_del_vlan_client(VLANClientState *vc)
     qemu_free(vc);
 }
 
-VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque)
-{
-    VLANClientState *vc;
-
-    QTAILQ_FOREACH(vc, &vlan->clients, next) {
-        if (vc->opaque == opaque) {
-            return vc;
-        }
-    }
-
-    return NULL;
-}
-
 VLANClientState *
 qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
                               const char *client_str)
diff --git a/net.h b/net.h
index 4de20de..9185bcf 100644
--- a/net.h
+++ b/net.h
@@ -64,7 +64,6 @@ struct VLANClientState {
     NetCleanup *cleanup;
     LinkStatusChanged *link_status_changed;
     int link_down;
-    void *opaque;
     QTAILQ_ENTRY(VLANClientState) next;
     struct VLANState *vlan;
     VLANClientState *peer;
@@ -101,19 +100,7 @@ NICState *qemu_new_nic(NetClientInfo *info,
                        const char *model,
                        const char *name,
                        void *opaque);
-VLANClientState *qemu_new_vlan_client(net_client_type type,
-                                      VLANState *vlan,
-                                      VLANClientState *peer,
-                                      const char *model,
-                                      const char *name,
-                                      NetCanReceive *can_receive,
-                                      NetReceive *receive,
-                                      NetReceive *receive_raw,
-                                      NetReceiveIOV *receive_iov,
-                                      NetCleanup *cleanup,
-                                      void *opaque);
 void qemu_del_vlan_client(VLANClientState *vc);
-VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
 VLANClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
                                                const char *client_str);
 int qemu_can_send_packet(VLANClientState *vc);
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 37/44] net: remove VLANClientState members now in NetClientInfo
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (35 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 36/44] net: remove qemu_new_vlan_client() Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 38/44] net: add qemu_foreach_nic() Mark McLoughlin
                   ` (6 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Add a NetClientInfo pointer to VLANClientState and use that
for the typecode and function pointers.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/dp8393x.c    |    4 ++--
 hw/virtio-net.c |    2 +-
 net.c           |   45 ++++++++++++++++++++-------------------------
 net.h           |   10 +---------
 net/tap.c       |    6 +++---
 5 files changed, 27 insertions(+), 40 deletions(-)

diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index be9714d..e65e4d1 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -407,9 +407,9 @@ static void do_transmit_packets(dp8393xState *s)
         if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) {
             /* Loopback */
             s->regs[SONIC_TCR] |= SONIC_TCR_CRSL;
-            if (s->nic->nc.can_receive(&s->nic->nc)) {
+            if (s->nic->nc.info->can_receive(&s->nic->nc)) {
                 s->loopback_packet = 1;
-                s->nic->nc.receive(&s->nic->nc, s->tx_buffer, tx_len);
+                s->nic->nc.info->receive(&s->nic->nc, s->tx_buffer, tx_len);
             }
         } else {
             /* Transmit packet */
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 4f8d89e..2f201ff 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -129,7 +129,7 @@ static int peer_has_vnet_hdr(VirtIONet *n)
     if (!n->nic->nc.peer)
         return 0;
 
-    if (n->nic->nc.peer->type != NET_CLIENT_TYPE_TAP)
+    if (n->nic->nc.peer->info->type != NET_CLIENT_TYPE_TAP)
         return 0;
 
     n->has_vnet_hdr = tap_has_vnet_hdr(n->nic->nc.peer);
diff --git a/net.c b/net.c
index d77320b..a1ec243 100644
--- a/net.c
+++ b/net.c
@@ -229,19 +229,13 @@ VLANClientState *qemu_new_net_client(NetClientInfo *info,
 
     vc = qemu_mallocz(info->size);
 
-    vc->type = info->type;
+    vc->info = info;
     vc->model = qemu_strdup(model);
     if (name) {
         vc->name = qemu_strdup(name);
     } else {
         vc->name = assign_name(vc, model);
     }
-    vc->can_receive = info->can_receive;
-    vc->receive = info->receive;
-    vc->receive_raw = info->receive_raw;
-    vc->receive_iov = info->receive_iov;
-    vc->cleanup = info->cleanup;
-    vc->link_status_changed = info->link_status_changed;
 
     if (vlan) {
         assert(!peer);
@@ -297,8 +291,8 @@ void qemu_del_vlan_client(VLANClientState *vc)
         }
     }
 
-    if (vc->cleanup) {
-        vc->cleanup(vc);
+    if (vc->info->cleanup) {
+        vc->info->cleanup(vc);
     }
 
     qemu_free(vc->name);
@@ -340,8 +334,8 @@ int qemu_can_send_packet(VLANClientState *sender)
     if (sender->peer) {
         if (sender->peer->receive_disabled) {
             return 0;
-        } else if (sender->peer->can_receive &&
-                   !sender->peer->can_receive(sender->peer)) {
+        } else if (sender->peer->info->can_receive &&
+                   !sender->peer->info->can_receive(sender->peer)) {
             return 0;
         } else {
             return 1;
@@ -358,7 +352,7 @@ int qemu_can_send_packet(VLANClientState *sender)
         }
 
         /* no can_receive() handler, they can always receive */
-        if (!vc->can_receive || vc->can_receive(vc)) {
+        if (!vc->info->can_receive || vc->info->can_receive(vc)) {
             return 1;
         }
     }
@@ -382,10 +376,10 @@ static ssize_t qemu_deliver_packet(VLANClientState *sender,
         return 0;
     }
 
-    if (flags & QEMU_NET_PACKET_FLAG_RAW && vc->receive_raw) {
-        ret = vc->receive_raw(vc, data, size);
+    if (flags & QEMU_NET_PACKET_FLAG_RAW && vc->info->receive_raw) {
+        ret = vc->info->receive_raw(vc, data, size);
     } else {
-        ret = vc->receive(vc, data, size);
+        ret = vc->info->receive(vc, data, size);
     }
 
     if (ret == 0) {
@@ -422,10 +416,10 @@ static ssize_t qemu_vlan_deliver_packet(VLANClientState *sender,
             continue;
         }
 
-        if (flags & QEMU_NET_PACKET_FLAG_RAW && vc->receive_raw) {
-            len = vc->receive_raw(vc, buf, size);
+        if (flags & QEMU_NET_PACKET_FLAG_RAW && vc->info->receive_raw) {
+            len = vc->info->receive_raw(vc, buf, size);
         } else {
-            len = vc->receive(vc, buf, size);
+            len = vc->info->receive(vc, buf, size);
         }
 
         if (len == 0) {
@@ -530,7 +524,7 @@ static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov,
         offset += len;
     }
 
-    return vc->receive(vc, buffer, offset);
+    return vc->info->receive(vc, buffer, offset);
 }
 
 static ssize_t calc_iov_length(const struct iovec *iov, int iovcnt)
@@ -555,8 +549,8 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
         return calc_iov_length(iov, iovcnt);
     }
 
-    if (vc->receive_iov) {
-        return vc->receive_iov(vc, iov, iovcnt);
+    if (vc->info->receive_iov) {
+        return vc->info->receive_iov(vc, iov, iovcnt);
     } else {
         return vc_sendv_compat(vc, iov, iovcnt);
     }
@@ -586,8 +580,8 @@ static ssize_t qemu_vlan_deliver_packet_iov(VLANClientState *sender,
 
         assert(!(flags & QEMU_NET_PACKET_FLAG_RAW));
 
-        if (vc->receive_iov) {
-            len = vc->receive_iov(vc, iov, iovcnt);
+        if (vc->info->receive_iov) {
+            len = vc->info->receive_iov(vc, iov, iovcnt);
         } else {
             len = vc_sendv_compat(vc, iov, iovcnt);
         }
@@ -1246,8 +1240,9 @@ done:
         monitor_printf(mon, "invalid link status '%s'; only 'up' or 'down' "
                        "valid\n", up_or_down);
 
-    if (vc->link_status_changed)
-        vc->link_status_changed(vc);
+    if (vc->info->link_status_changed) {
+        vc->info->link_status_changed(vc);
+    }
 }
 
 void net_cleanup(void)
diff --git a/net.h b/net.h
index 9185bcf..497a737 100644
--- a/net.h
+++ b/net.h
@@ -54,15 +54,7 @@ typedef struct NetClientInfo {
 } NetClientInfo;
 
 struct VLANClientState {
-    net_client_type type;
-    NetReceive *receive;
-    NetReceive *receive_raw;
-    NetReceiveIOV *receive_iov;
-    /* Packets may still be sent if this returns zero.  It's used to
-       rate-limit the slirp code.  */
-    NetCanReceive *can_receive;
-    NetCleanup *cleanup;
-    LinkStatusChanged *link_status_changed;
+    NetClientInfo *info;
     int link_down;
     QTAILQ_ENTRY(VLANClientState) next;
     struct VLANState *vlan;
diff --git a/net/tap.c b/net/tap.c
index d34feec..a327a9a 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -214,7 +214,7 @@ int tap_has_ufo(VLANClientState *nc)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
-    assert(nc->type == NET_CLIENT_TYPE_TAP);
+    assert(nc->info->type == NET_CLIENT_TYPE_TAP);
 
     return s->has_ufo;
 }
@@ -223,7 +223,7 @@ int tap_has_vnet_hdr(VLANClientState *nc)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
-    assert(nc->type == NET_CLIENT_TYPE_TAP);
+    assert(nc->info->type == NET_CLIENT_TYPE_TAP);
 
     return s->has_vnet_hdr;
 }
@@ -234,7 +234,7 @@ void tap_using_vnet_hdr(VLANClientState *nc, int using_vnet_hdr)
 
     using_vnet_hdr = using_vnet_hdr != 0;
 
-    assert(nc->type == NET_CLIENT_TYPE_TAP);
+    assert(nc->info->type == NET_CLIENT_TYPE_TAP);
     assert(s->has_vnet_hdr == using_vnet_hdr);
 
     s->using_vnet_hdr = using_vnet_hdr;
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 38/44] net: add qemu_foreach_nic()
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (36 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 37/44] net: remove VLANClientState members now in NetClientInfo Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 39/44] net: fix qemu_announce_self() Mark McLoughlin
                   ` (5 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |   20 ++++++++++++++++++++
 net.h |    2 ++
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/net.c b/net.c
index a1ec243..c71699d 100644
--- a/net.c
+++ b/net.c
@@ -326,6 +326,26 @@ qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
     return vc;
 }
 
+void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
+{
+    VLANClientState *nc;
+    VLANState *vlan;
+
+    QTAILQ_FOREACH(nc, &non_vlan_clients, next) {
+        if (nc->info->type == NET_CLIENT_TYPE_NIC) {
+            func(DO_UPCAST(NICState, nc, nc), opaque);
+        }
+    }
+
+    QTAILQ_FOREACH(vlan, &vlans, next) {
+        QTAILQ_FOREACH(nc, &vlan->clients, next) {
+            if (nc->info->type == NET_CLIENT_TYPE_NIC) {
+                func(DO_UPCAST(NICState, nc, nc), opaque);
+            }
+        }
+    }
+}
+
 int qemu_can_send_packet(VLANClientState *sender)
 {
     VLANState *vlan = sender->vlan;
diff --git a/net.h b/net.h
index 497a737..d583d59 100644
--- a/net.h
+++ b/net.h
@@ -95,6 +95,8 @@ NICState *qemu_new_nic(NetClientInfo *info,
 void qemu_del_vlan_client(VLANClientState *vc);
 VLANClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
                                                const char *client_str);
+typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
+void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
 int qemu_can_send_packet(VLANClientState *vc);
 ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
                           int iovcnt);
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 39/44] net: fix qemu_announce_self()
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (37 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 38/44] net: add qemu_foreach_nic() Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 40/44] net: print correct error for '-netdev ""' Mark McLoughlin
                   ` (4 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Now that we have a way to iterate NICs.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 savevm.c |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/savevm.c b/savevm.c
index 4668843..3cfc5aa 100644
--- a/savevm.c
+++ b/savevm.c
@@ -123,24 +123,24 @@ static int announce_self_create(uint8_t *buf,
     return 60; /* len (FCS will be added by hardware) */
 }
 
-static void qemu_announce_self_once(void *opaque)
+static void qemu_announce_self_iter(NICState *nic, void *opaque)
 {
-    int i, len;
-    VLANState *vlan;
-    VLANClientState *vc;
     uint8_t buf[60];
+    int len;
+
+    len = announce_self_create(buf, nic->conf->macaddr.a);
+
+    qemu_send_packet_raw(&nic->nc, buf, len);
+}
+
+
+static void qemu_announce_self_once(void *opaque)
+{
     static int count = SELF_ANNOUNCE_ROUNDS;
     QEMUTimer *timer = *(QEMUTimer **)opaque;
 
-    for (i = 0; i < MAX_NICS; i++) {
-        if (!nd_table[i].used)
-            continue;
-        len = announce_self_create(buf, nd_table[i].macaddr);
-        vlan = nd_table[i].vlan;
-        QTAILQ_FOREACH(vc, &vlan->clients, next) {
-            qemu_send_packet_raw(vc, buf, len);
-        }
-    }
+    qemu_foreach_nic(qemu_announce_self_iter, NULL);
+
     if (--count) {
         /* delay 50ms, 150ms, 250ms, ... */
         qemu_mod_timer(timer, qemu_get_clock(rt_clock) +
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 40/44] net: print correct error for '-netdev ""'
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (38 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 39/44] net: fix qemu_announce_self() Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 41/44] net: fix TAP networking on host kernels without IFF_VNET_HDR support Mark McLoughlin
                   ` (3 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Reported-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/net.c b/net.c
index c71699d..13bdbb2 100644
--- a/net.c
+++ b/net.c
@@ -1055,12 +1055,18 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
     int i;
 
     type = qemu_opt_get(opts, "type");
-    if (!type) {
-        qemu_error("No type specified for -net\n");
-        return -1;
-    }
 
-    if (is_netdev) {
+    if (!is_netdev) {
+        if (!type) {
+            qemu_error("No type specified for -net\n");
+            return -1;
+        }
+    } else {
+        if (!type) {
+            qemu_error("No type specified for -netdev\n");
+            return -1;
+        }
+
         if (strcmp(type, "tap") != 0 &&
 #ifdef CONFIG_SLIRP
             strcmp(type, "user") != 0 &&
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 41/44] net: fix TAP networking on host kernels without IFF_VNET_HDR support
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (39 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 40/44] net: print correct error for '-netdev ""' Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 42/44] net: check for TUNSETOFFLOAD support before trying to enable offload features Mark McLoughlin
                   ` (2 subsequent siblings)
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin, Pierre Riteau

From: Pierre Riteau <Pierre.Riteau@irisa.fr>

vnet_hdr is initialized at 1 by default. We need to reset it to 0 if
the kernel doesn't support IFF_VNET_HDR.

Signed-off-by: Pierre Riteau <Pierre.Riteau@irisa.fr>
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/tap-linux.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/net/tap-linux.c b/net/tap-linux.c
index 0f621a2..e4f7e27 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -52,6 +52,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
             features & IFF_VNET_HDR) {
             *vnet_hdr = 1;
             ifr.ifr_flags |= IFF_VNET_HDR;
+        } else {
+            *vnet_hdr = 0;
         }
 
         if (vnet_hdr_required && !*vnet_hdr) {
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 42/44] net: check for TUNSETOFFLOAD support before trying to enable offload features
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (40 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 41/44] net: fix TAP networking on host kernels without IFF_VNET_HDR support Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 43/44] net: initialize vnet_hdr in net_init_tap() Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 44/44] net: fix vnet_hdr handling in solaris tap code Mark McLoughlin
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin, Pierre Riteau

From: Pierre Riteau <Pierre.Riteau@irisa.fr>

This avoids the "TUNSETOFFLOAD ioctl() failed: Invalid argument" message
on kernels without TUNSETOFFLOAD support.

Signed-off-by: Pierre Riteau <Pierre.Riteau@irisa.fr>
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/tap-linux.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/net/tap-linux.c b/net/tap-linux.c
index e4f7e27..6af9e82 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -131,6 +131,11 @@ void tap_fd_set_offload(int fd, int csum, int tso4,
 {
     unsigned int offload = 0;
 
+    /* Check if our kernel supports TUNSETOFFLOAD */
+    if (ioctl(fd, TUNSETOFFLOAD, 0) != 0 && errno == EINVAL) {
+        return;
+    }
+
     if (csum) {
         offload |= TUN_F_CSUM;
         if (tso4)
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 43/44] net: initialize vnet_hdr in net_init_tap()
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (41 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 42/44] net: check for TUNSETOFFLOAD support before trying to enable offload features Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 44/44] net: fix vnet_hdr handling in solaris tap code Mark McLoughlin
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

net_tap_init() always sets vnet_hdr using qemu_opt_get_bool(), but
initialize it in net_init_tap() just to reduce confusion.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/tap.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/tap.c b/net/tap.c
index a327a9a..0d8b424 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -378,7 +378,7 @@ static int net_tap_init(QemuOpts *opts, int *vnet_hdr)
 int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)
 {
     TAPState *s;
-    int fd, vnet_hdr;
+    int fd, vnet_hdr = 0;
 
     if (qemu_opt_get(opts, "fd")) {
         if (qemu_opt_get(opts, "ifname") ||
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [Qemu-devel] [PATCH 44/44] net: fix vnet_hdr handling in solaris tap code
  2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
                   ` (42 preceding siblings ...)
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 43/44] net: initialize vnet_hdr in net_init_tap() Mark McLoughlin
@ 2009-11-25 18:49 ` Mark McLoughlin
  43 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-25 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark McLoughlin

Print an error if the user specifies vnet_hdr=1 on the cmdline.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net/tap-solaris.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index ef4e60c..e14fe36 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -180,6 +180,17 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
        return -1;
     }
     pstrcpy(ifname, ifname_size, dev);
+    if (*vnet_hdr) {
+        /* Solaris doesn't have IFF_VNET_HDR */
+        *vnet_hdr = 0;
+
+        if (vnet_hdr_required && !*vnet_hdr) {
+            qemu_error("vnet_hdr=1 requested, but no kernel "
+                       "support for IFF_VNET_HDR available");
+            close(fd);
+            return -1;
+        }
+    }
     fcntl(fd, F_SETFL, O_NONBLOCK);
     return fd;
 }
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

* Re: [Qemu-devel] [PATCH 09/44] net: introduce qemu_new_net_client()
  2009-11-25 18:49 ` [Qemu-devel] [PATCH 09/44] net: introduce qemu_new_net_client() Mark McLoughlin
@ 2009-11-25 20:36   ` Blue Swirl
  2009-11-26 18:06     ` Mark McLoughlin
  0 siblings, 1 reply; 47+ messages in thread
From: Blue Swirl @ 2009-11-25 20:36 UTC (permalink / raw)
  To: Mark McLoughlin; +Cc: qemu-devel

On Wed, Nov 25, 2009 at 6:49 PM, Mark McLoughlin <markmc@redhat.com> wrote:
> A replacement for qemu_new_vlan_client(), using NetClientInfo to
> replace most arguments.

> +VLANClientState *qemu_new_net_client(NetClientInfo *info,
> +                                     VLANState *vlan,
> +                                     VLANClientState *peer,
> +                                     const char *model,
> +                                     const char *name)
>  {

Could you change this to use const NetClientInfo *info instead? Then
the device structures could be const as well.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [Qemu-devel] [PATCH 09/44] net: introduce qemu_new_net_client()
  2009-11-25 20:36   ` Blue Swirl
@ 2009-11-26 18:06     ` Mark McLoughlin
  0 siblings, 0 replies; 47+ messages in thread
From: Mark McLoughlin @ 2009-11-26 18:06 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel

On Wed, 2009-11-25 at 20:36 +0000, Blue Swirl wrote:
> On Wed, Nov 25, 2009 at 6:49 PM, Mark McLoughlin <markmc@redhat.com> wrote:
> > A replacement for qemu_new_vlan_client(), using NetClientInfo to
> > replace most arguments.
> 
> > +VLANClientState *qemu_new_net_client(NetClientInfo *info,
> > +                                     VLANState *vlan,
> > +                                     VLANClientState *peer,
> > +                                     const char *model,
> > +                                     const char *name)
> >  {
> 
> Could you change this to use const NetClientInfo *info instead? Then
> the device structures could be const as well.

Good idea.

I've added the patch below to http://repo.or.cz/w/qemu/markmc.git

Thanks,
Mark.

From: Mark McLoughlin <markmc@redhat.com>
Subject: [PATCH] net: constify NetClientInfo

Reported-by: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/dp8393x.c        |    2 +-
 hw/e1000.c          |    2 +-
 hw/eepro100.c       |    2 +-
 hw/etraxfs_eth.c    |    2 +-
 hw/lan9118.c        |    2 +-
 hw/lance.c          |    2 +-
 hw/mcf_fec.c        |    2 +-
 hw/mipsnet.c        |    2 +-
 hw/musicpal.c       |    2 +-
 hw/ne2000-isa.c     |    2 +-
 hw/ne2000.c         |    2 +-
 hw/pcnet.c          |    4 ++--
 hw/pcnet.h          |    2 +-
 hw/rtl8139.c        |    2 +-
 hw/smc91c111.c      |    2 +-
 hw/stellaris_enet.c |    2 +-
 hw/usb-net.c        |    2 +-
 hw/virtio-net.c     |    2 +-
 hw/xen_nic.c        |    2 +-
 hw/xilinx_ethlite.c |    2 +-
 net.c               |    4 ++--
 net.h               |    6 +++---
 net/dump.c          |    2 +-
 net/slirp.c         |    2 +-
 net/socket.c        |    4 ++--
 net/tap-win32.c     |    2 +-
 net/tap.c           |    2 +-
 net/vde.c           |    2 +-
 28 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index e65e4d1..b4b2e62 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -873,7 +873,7 @@ static void nic_cleanup(VLANClientState *nc)
     qemu_free(s);
 }
 
-static NetClientInfo net_dp83932_info = {
+static const NetClientInfo net_dp83932_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = nic_can_receive,
diff --git a/hw/e1000.c b/hw/e1000.c
index 683fdcc..2ca4c07 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1067,7 +1067,7 @@ static void e1000_reset(void *opaque)
     memset(&d->tx, 0, sizeof d->tx);
 }
 
-static NetClientInfo net_e1000_info = {
+static const NetClientInfo net_e1000_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = e1000_can_receive,
diff --git a/hw/eepro100.c b/hw/eepro100.c
index eb16a51..f6816f7 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1797,7 +1797,7 @@ static int pci_nic_uninit(PCIDevice *pci_dev)
     return 0;
 }
 
-static NetClientInfo net_eepro100_info = {
+static const NetClientInfo net_eepro100_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = nic_can_receive,
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index dedd107..6398c0c 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -565,7 +565,7 @@ static void eth_cleanup(VLANClientState *nc)
         qemu_free(eth);
 }
 
-static NetClientInfo net_etraxfs_info = {
+static const NetClientInfo net_etraxfs_info = {
 	.type = NET_CLIENT_TYPE_NIC,
 	.size = sizeof(NICState),
 	.can_receive = eth_can_receive,
diff --git a/hw/lan9118.c b/hw/lan9118.c
index ba982d1..306a16a 100644
--- a/hw/lan9118.c
+++ b/hw/lan9118.c
@@ -1029,7 +1029,7 @@ static void lan9118_cleanup(VLANClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_lan9118_info = {
+static const NetClientInfo net_lan9118_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = lan9118_can_receive,
diff --git a/hw/lance.c b/hw/lance.c
index 98033a4..cba111b 100644
--- a/hw/lance.c
+++ b/hw/lance.c
@@ -100,7 +100,7 @@ static void lance_cleanup(VLANClientState *nc)
     pcnet_common_cleanup(d);
 }
 
-static NetClientInfo net_lance_info = {
+static const NetClientInfo net_lance_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = pcnet_can_receive,
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 4e7fbed..ed7e0c8 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -450,7 +450,7 @@ static void mcf_fec_cleanup(VLANClientState *nc)
     qemu_free(s);
 }
 
-static NetClientInfo net_mcf_fec_info = {
+static const NetClientInfo net_mcf_fec_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = mcf_fec_can_receive,
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index a066f63..5396489 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -246,7 +246,7 @@ static void mipsnet_cleanup(VLANClientState *nc)
     qemu_free(s);
 }
 
-static NetClientInfo net_mipsnet_info = {
+static const NetClientInfo net_mipsnet_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = mipsnet_can_receive,
diff --git a/hw/musicpal.c b/hw/musicpal.c
index 4a33e28..5128c06 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -372,7 +372,7 @@ static void eth_cleanup(VLANClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_mv88w8618_info = {
+static const NetClientInfo net_mv88w8618_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = eth_can_receive,
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index 0260f84..e1519a8 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -42,7 +42,7 @@ static void isa_ne2000_cleanup(VLANClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_ne2000_isa_info = {
+static const NetClientInfo net_ne2000_isa_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = ne2000_can_receive,
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 0be189a..e7ef91a 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -705,7 +705,7 @@ static void ne2000_cleanup(VLANClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_ne2000_info = {
+static const NetClientInfo net_ne2000_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = ne2000_can_receive,
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 195c825..42c3464 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1891,7 +1891,7 @@ void pcnet_common_cleanup(PCNetState *d)
     d->nic = NULL;
 }
 
-int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
+int pcnet_common_init(DeviceState *dev, PCNetState *s, const NetClientInfo *info)
 {
     s->poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, s);
 
@@ -1959,7 +1959,7 @@ static int pci_pcnet_uninit(PCIDevice *dev)
     return 0;
 }
 
-static NetClientInfo net_pci_pcnet_info = {
+static const NetClientInfo net_pci_pcnet_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = pcnet_can_receive,
diff --git a/hw/pcnet.h b/hw/pcnet.h
index efacc9f..1274f95 100644
--- a/hw/pcnet.h
+++ b/hw/pcnet.h
@@ -35,5 +35,5 @@ uint32_t pcnet_ioport_readw(void *opaque, uint32_t addr);
 int pcnet_can_receive(VLANClientState *nc);
 ssize_t pcnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size_);
 void pcnet_common_cleanup(PCNetState *d);
-int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info);
+int pcnet_common_init(DeviceState *dev, PCNetState *s, const NetClientInfo *info);
 extern const VMStateDescription vmstate_pcnet;
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 931cde9..7a73598 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3305,7 +3305,7 @@ static int pci_rtl8139_uninit(PCIDevice *dev)
     return 0;
 }
 
-static NetClientInfo net_rtl8139_info = {
+static const NetClientInfo net_rtl8139_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = rtl8139_can_receive,
diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index c1a88c9..1ed841d 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -699,7 +699,7 @@ static void smc91c111_cleanup(VLANClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_smc91c111_info = {
+static const NetClientInfo net_smc91c111_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = smc91c111_can_receive,
diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c
index d1d755e..198c8bf 100644
--- a/hw/stellaris_enet.c
+++ b/hw/stellaris_enet.c
@@ -396,7 +396,7 @@ static void stellaris_enet_cleanup(VLANClientState *nc)
     qemu_free(s);
 }
 
-static NetClientInfo net_stellaris_enet_info = {
+static const NetClientInfo net_stellaris_enet_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = stellaris_enet_can_receive,
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 2556e05..d5c60f7 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1450,7 +1450,7 @@ static int usb_net_initfn(USBDevice *dev)
     return 0;
 }
 
-static NetClientInfo net_usbnet_info = {
+static const NetClientInfo net_usbnet_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = usbnet_can_receive,
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 2f201ff..b97151a 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -818,7 +818,7 @@ static void virtio_net_cleanup(VLANClientState *nc)
     n->nic = NULL;
 }
 
-static NetClientInfo net_virtio_info = {
+static const NetClientInfo net_virtio_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = virtio_net_can_receive,
diff --git a/hw/xen_nic.c b/hw/xen_nic.c
index 08055b8..bdc8134 100644
--- a/hw/xen_nic.c
+++ b/hw/xen_nic.c
@@ -290,7 +290,7 @@ static ssize_t net_rx_packet(VLANClientState *nc, const uint8_t *buf, size_t siz
 
 /* ------------------------------------------------------------- */
 
-static NetClientInfo net_xen_info = {
+static const NetClientInfo net_xen_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = net_rx_ok,
diff --git a/hw/xilinx_ethlite.c b/hw/xilinx_ethlite.c
index 37e33ec..87b393b 100644
--- a/hw/xilinx_ethlite.c
+++ b/hw/xilinx_ethlite.c
@@ -208,7 +208,7 @@ static void eth_cleanup(VLANClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_xilinx_ethlite_info = {
+static const NetClientInfo net_xilinx_ethlite_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = eth_can_rx,
diff --git a/net.c b/net.c
index 13bdbb2..5e3f2e8 100644
--- a/net.c
+++ b/net.c
@@ -217,7 +217,7 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
                                        int iovcnt,
                                        void *opaque);
 
-VLANClientState *qemu_new_net_client(NetClientInfo *info,
+VLANClientState *qemu_new_net_client(const NetClientInfo *info,
                                      VLANState *vlan,
                                      VLANClientState *peer,
                                      const char *model,
@@ -256,7 +256,7 @@ VLANClientState *qemu_new_net_client(NetClientInfo *info,
     return vc;
 }
 
-NICState *qemu_new_nic(NetClientInfo *info,
+NICState *qemu_new_nic(const NetClientInfo *info,
                        NICConf *conf,
                        const char *model,
                        const char *name,
diff --git a/net.h b/net.h
index d583d59..36a3448 100644
--- a/net.h
+++ b/net.h
@@ -54,7 +54,7 @@ typedef struct NetClientInfo {
 } NetClientInfo;
 
 struct VLANClientState {
-    NetClientInfo *info;
+    const NetClientInfo *info;
     int link_down;
     QTAILQ_ENTRY(VLANClientState) next;
     struct VLANState *vlan;
@@ -82,12 +82,12 @@ struct VLANState {
 
 VLANState *qemu_find_vlan(int id, int allocate);
 VLANClientState *qemu_find_netdev(const char *id);
-VLANClientState *qemu_new_net_client(NetClientInfo *info,
+VLANClientState *qemu_new_net_client(const NetClientInfo *info,
                                      VLANState *vlan,
                                      VLANClientState *peer,
                                      const char *model,
                                      const char *name);
-NICState *qemu_new_nic(NetClientInfo *info,
+NICState *qemu_new_nic(const NetClientInfo *info,
                        NICConf *conf,
                        const char *model,
                        const char *name,
diff --git a/net/dump.c b/net/dump.c
index 4ed3f5f..b8660d2 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -90,7 +90,7 @@ static void dump_cleanup(VLANClientState *nc)
     close(s->fd);
 }
 
-static NetClientInfo net_dump_info = {
+static const NetClientInfo net_dump_info = {
     .type = NET_CLIENT_TYPE_DUMP,
     .size = sizeof(DumpState),
     .receive = dump_receive,
diff --git a/net/slirp.c b/net/slirp.c
index 3f91c4b..fc53ab5 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -125,7 +125,7 @@ static void net_slirp_cleanup(VLANClientState *nc)
     QTAILQ_REMOVE(&slirp_stacks, s, entry);
 }
 
-static NetClientInfo net_slirp_info = {
+static const NetClientInfo net_slirp_info = {
     .type = NET_CLIENT_TYPE_SLIRP,
     .size = sizeof(SlirpState),
     .receive = net_slirp_receive,
diff --git a/net/socket.c b/net/socket.c
index 7331d87..931dff5 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -216,7 +216,7 @@ static void net_socket_cleanup(VLANClientState *nc)
     close(s->fd);
 }
 
-static NetClientInfo net_dgram_socket_info = {
+static const NetClientInfo net_dgram_socket_info = {
     .type = NET_CLIENT_TYPE_SOCKET,
     .size = sizeof(NetSocketState),
     .receive = net_socket_receive_dgram,
@@ -290,7 +290,7 @@ static void net_socket_connect(void *opaque)
     qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
 }
 
-static NetClientInfo net_socket_info = {
+static const NetClientInfo net_socket_info = {
     .type = NET_CLIENT_TYPE_SOCKET,
     .size = sizeof(NetSocketState),
     .receive = net_socket_receive,
diff --git a/net/tap-win32.c b/net/tap-win32.c
index ef63782..5734ada 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -666,7 +666,7 @@ static void tap_win32_send(void *opaque)
     }
 }
 
-static NetClientInfo net_tap_win32_info = {
+static const NetClientInfo net_tap_win32_info = {
     .type = NET_CLIENT_TYPE_TAP,
     .size = sizeof(TAPState),
     .receive = tap_receive,
diff --git a/net/tap.c b/net/tap.c
index 0d8b424..a4c25dd 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -264,7 +264,7 @@ static void tap_cleanup(VLANClientState *nc)
 
 /* fd support */
 
-static NetClientInfo net_tap_info = {
+static const NetClientInfo net_tap_info = {
     .type = NET_CLIENT_TYPE_TAP,
     .size = sizeof(TAPState),
     .receive = tap_receive,
diff --git a/net/vde.c b/net/vde.c
index 42b4633..8f834d6 100644
--- a/net/vde.c
+++ b/net/vde.c
@@ -69,7 +69,7 @@ static void vde_cleanup(VLANClientState *nc)
     vde_close(s->vde);
 }
 
-static NetClientInfo net_vde_info = {
+static const NetClientInfo net_vde_info = {
     .type = NET_CLIENT_TYPE_VDE,
     .size = sizeof(VDEState),
     .receive = vde_receive,
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2009-11-26 18:09 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-25 18:48 [Qemu-devel] [PATCH 00/44] Fix announce_self(), misc net fixes and cleanups Mark McLoughlin
2009-11-25 18:48 ` [Qemu-devel] [PATCH 01/44] net: move slirp code from net.c to net/slirp.c Mark McLoughlin
2009-11-25 18:48 ` [Qemu-devel] [PATCH 02/44] net: move vde code from net.c to net/vde.c Mark McLoughlin
2009-11-25 18:48 ` [Qemu-devel] [PATCH 03/44] net: move socket backend code from net.c to net/socket.c Mark McLoughlin
2009-11-25 18:48 ` [Qemu-devel] [PATCH 04/44] net: move dump backend code from net.c to net/dump.c Mark McLoughlin
2009-11-25 18:48 ` [Qemu-devel] [PATCH 05/44] net: clean up includes in net.c Mark McLoughlin
2009-11-25 18:48 ` [Qemu-devel] [PATCH 06/44] net: remove NICInfo::vc Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 07/44] net: remove NICInfo::private Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 08/44] net: introduce NetClientInfo Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 09/44] net: introduce qemu_new_net_client() Mark McLoughlin
2009-11-25 20:36   ` Blue Swirl
2009-11-26 18:06     ` Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 10/44] qdev: move DO_UPCAST() into osdep.h Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 11/44] net: convert tap to NetClientInfo Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 12/44] net: convert tap-win32 " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 13/44] net: convert slirp " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 14/44] net: convert vde " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 15/44] net: convert socket " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 16/44] net: convert dump " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 17/44] net: introduce NICState and qemu_new_nic() Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 18/44] net: convert virtio to NICState Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 19/44] net: convert e1000 " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 20/44] net: convert rtl8139 " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 21/44] net: convert ne2000 " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 22/44] net: convert pcnet " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 23/44] net: convert eepro100 " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 24/44] net: convert dp8393x " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 25/44] net: convert etrax " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 26/44] net: convert LAN9118 " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 27/44] net: convert mcf_fec " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 28/44] net: convert mipsnet " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 29/44] net: convert musicpal " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 30/44] net: convert smc91c111 " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 31/44] net: convert stellaris " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 32/44] net: convert usb-net " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 33/44] net: convert xilinx_ethlite " Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 34/44] net: move parse_macaddr() to net/util.[ch] Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 35/44] net: convert xen to NICState Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 36/44] net: remove qemu_new_vlan_client() Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 37/44] net: remove VLANClientState members now in NetClientInfo Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 38/44] net: add qemu_foreach_nic() Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 39/44] net: fix qemu_announce_self() Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 40/44] net: print correct error for '-netdev ""' Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 41/44] net: fix TAP networking on host kernels without IFF_VNET_HDR support Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 42/44] net: check for TUNSETOFFLOAD support before trying to enable offload features Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 43/44] net: initialize vnet_hdr in net_init_tap() Mark McLoughlin
2009-11-25 18:49 ` [Qemu-devel] [PATCH 44/44] net: fix vnet_hdr handling in solaris tap code Mark McLoughlin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.