From: Mark McLoughlin <markmc@redhat.com>
To: qemu-devel@nongnu.org
Cc: Mark McLoughlin <markmc@redhat.com>
Subject: [Qemu-devel] [PATCH 15/44] net: convert socket to NetClientInfo
Date: Wed, 25 Nov 2009 18:49:08 +0000 [thread overview]
Message-ID: <1259174977-26212-16-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1259174977-26212-1-git-send-email-markmc@redhat.com>
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
next prev parent reply other threads:[~2009-11-25 19:31 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Mark McLoughlin [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1259174977-26212-16-git-send-email-markmc@redhat.com \
--to=markmc@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).