From: wexu@redhat.com
To: qemu-devel@nongnu.org
Cc: victork@redhat.com, mst@redhat.com, jasowang@redhat.com,
yvugenfi@redhat.com, Wei Xu <wexu@redhat.com>,
marcel@redhat.com, dfleytma@redhat.com
Subject: [Qemu-devel] [RFC Patch 07/10] TCP control packet handling.
Date: Tue, 26 Jan 2016 06:24:47 +0800 [thread overview]
Message-ID: <1453760690-21221-8-git-send-email-wexu@redhat.com> (raw)
In-Reply-To: <1453760690-21221-1-git-send-email-wexu@redhat.com>
From: Wei Xu <wexu@redhat.com>
All the 'SYN' packets will be bypassed, and flag with 'FIN/RST' set
will signal all the cached packets in the same connection to be purged,
this is to avoid out of data on the line.
Signed-off-by: Wei Xu <wexu@redhat.com>
---
hw/net/virtio-net.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 1ca3dd5..042b538 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -41,6 +41,12 @@
#define VIRTIO_HEADER 12 /* Virtio net header size */
#define IP_OFFSET (VIRTIO_HEADER + sizeof(struct eth_header))
+
+#define IP4_ADDR_OFFSET (IP_OFFSET + 12) /* ipv4 address start */
+#define TCP4_OFFSET (IP_OFFSET + sizeof(struct ip_header)) /* tcp4 header */
+#define TCP4_PORT_OFFSET TCP4_OFFSET /* tcp4 port offset */
+#define IP4_ADDR_SIZE 8 /* ipv4 saddr + daddr */
+#define TCP_PORT_SIZE 4 /* sport + dport */
#define TCP_WINDOW 65535
/* ip4 max payload, 16 bits in the header */
@@ -1850,6 +1856,27 @@ static int32_t virtio_net_rsc_try_coalesce4(NetRscChain *chain,
o_data, &o_ip->ip_len, MAX_IP4_PAYLOAD);
}
+
+/* Pakcets with 'SYN' should bypass, other flag should be sent after drain
+ * to prevent out of order */
+static int virtio_net_rsc_parse_tcp_ctrl(uint8_t *ip, uint16_t offset)
+{
+ uint16_t tcp_flag;
+ struct tcp_header *tcp;
+
+ tcp = (struct tcp_header *)(ip + offset);
+ tcp_flag = htons(tcp->th_offset_flags) & 0x3F;
+ if (tcp_flag & TH_SYN) {
+ return RSC_BYPASS;
+ }
+
+ if (tcp_flag & (TH_FIN | TH_URG | TH_RST)) {
+ return RSC_FINAL;
+ }
+
+ return 0;
+}
+
static size_t virtio_net_rsc_callback(NetRscChain *chain, NetClientState *nc,
const uint8_t *buf, size_t size, VirtioNetCoalesce *coalesce)
{
@@ -1895,12 +1922,51 @@ static size_t virtio_net_rsc_callback(NetRscChain *chain, NetClientState *nc,
return virtio_net_rsc_cache_buf(chain, nc, buf, size);
}
+/* Drain a connection data, this is to avoid out of order segments */
+static size_t virtio_net_rsc_drain_one(NetRscChain *chain, NetClientState *nc,
+ const uint8_t *buf, size_t size, uint16_t ip_start,
+ uint16_t ip_size, uint16_t tcp_port, uint16_t port_size)
+{
+ NetRscSeg *seg, *nseg;
+
+ QTAILQ_FOREACH_SAFE(seg, &chain->buffers, next, nseg) {
+ if (memcmp(buf + ip_start, seg->buf + ip_start, ip_size)
+ || memcmp(buf + tcp_port, seg->buf + tcp_port, port_size)) {
+ continue;
+ }
+ if ((chain->proto == ETH_P_IP) && seg->is_coalesced) {
+ virtio_net_rsc_ipv4_checksum(seg);
+ }
+
+ virtio_net_do_receive(seg->nc, seg->buf, seg->size);
+
+ QTAILQ_REMOVE(&chain->buffers, seg, next);
+ g_free(seg->buf);
+ g_free(seg);
+ break;
+ }
+
+ return virtio_net_do_receive(nc, buf, size);
+}
static size_t virtio_net_rsc_receive4(void *opq, NetClientState* nc,
const uint8_t *buf, size_t size)
{
+ int32_t ret;
+ struct ip_header *ip;
NetRscChain *chain;
chain = (NetRscChain *)opq;
+ ip = (struct ip_header *)(buf + IP_OFFSET);
+
+ ret = virtio_net_rsc_parse_tcp_ctrl((uint8_t *)ip,
+ (0xF & ip->ip_ver_len) << 2);
+ if (RSC_BYPASS == ret) {
+ return virtio_net_do_receive(nc, buf, size);
+ } else if (RSC_FINAL == ret) {
+ return virtio_net_rsc_drain_one(chain, nc, buf, size, IP4_ADDR_OFFSET,
+ IP4_ADDR_SIZE, TCP4_PORT_OFFSET, TCP_PORT_SIZE);
+ }
+
return virtio_net_rsc_callback(chain, nc, buf, size,
virtio_net_rsc_try_coalesce4);
}
--
2.4.0
next prev parent reply other threads:[~2016-01-25 22:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-25 22:24 [Qemu-devel] [RFC 0/10] Support Receive-Segment-Offload(RSC) for WHQL test of Window guest wexu
2016-01-25 22:24 ` [Qemu-devel] [RFC Patch 01/10] 'Segment', 'Chain' and 'Status' enumeration data structure wexu
2016-01-25 22:24 ` [Qemu-devel] [RFC Patch 02/10] Initilize & Cleanup wexu
2016-01-25 22:24 ` [Qemu-devel] [RFC Patch 03/10] Chain lookup and packets caching wexu
2016-01-25 22:24 ` [Qemu-devel] [RFC Patch 04/10] Tcp general data coalescing, the parameters is a little bit horrible, it's complicated to read, should can be optimized later wexu
2016-01-25 22:24 ` [Qemu-devel] [RFC Patch 05/10] The draining timer, create a timer to purge the packets from the cached pool wexu
2016-01-25 22:24 ` [Qemu-devel] [RFC Patch 06/10] IPv4 checksum wexu
2016-01-25 22:24 ` wexu [this message]
2016-01-25 22:24 ` [Qemu-devel] [RFC Patch 08/10] Sanity check & More bypass cases check wexu
2016-01-25 22:24 ` [Qemu-devel] [RFC Patch 09/10] IPv6 support wexu
2016-01-25 22:24 ` [Qemu-devel] [RFC Patch 10/10] Statistics wexu
2016-01-26 6:44 ` [Qemu-devel] [RFC 0/10] Support Receive-Segment-Offload(RSC) for WHQL test of Window guest Fam Zheng
2016-01-26 13:29 ` Wei Xu
2016-01-27 4:52 ` Jason Wang
2016-01-27 8:03 ` Wei Xu
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=1453760690-21221-8-git-send-email-wexu@redhat.com \
--to=wexu@redhat.com \
--cc=dfleytma@redhat.com \
--cc=jasowang@redhat.com \
--cc=marcel@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=victork@redhat.com \
--cc=yvugenfi@redhat.com \
/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).