From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41450) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aBMDi-0005ED-CH for qemu-devel@nongnu.org; Tue, 22 Dec 2015 07:39:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aBMDh-00006G-8P for qemu-devel@nongnu.org; Tue, 22 Dec 2015 07:39:14 -0500 Received: from [59.151.112.132] (port=13328 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aBMDg-00005d-SO for qemu-devel@nongnu.org; Tue, 22 Dec 2015 07:39:13 -0500 From: Zhang Chen Date: Tue, 22 Dec 2015 18:42:52 +0800 Message-ID: <1450780978-19123-5-git-send-email-zhangchen.fnst@cn.fujitsu.com> In-Reply-To: <1450780978-19123-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1450780978-19123-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [RFC PATCH v2 04/10] Colo-proxy: add data structure and jhash func List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu devel , Jason Wang , Stefan Hajnoczi Cc: Li Zhijian , Gui jianfeng , "eddie.dong" , "Dr. David Alan Gilbert" , Huang peng , Gong lei , jan.kiszka@siemens.com, Zhang Chen , Yang Hongyang , zhanghailiang From: zhangchen add data structure and hash func will be uesed Signed-off-by: zhangchen Signed-off-by: zhanghailiang --- net/colo-proxy.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/net/colo-proxy.c b/net/colo-proxy.c index 2e37c45..f448ee1 100644 --- a/net/colo-proxy.c +++ b/net/colo-proxy.c @@ -90,6 +90,40 @@ typedef struct COLOProxyState { } COLOProxyState; +typedef struct Packet { + void *data; + union { + uint8_t *network_layer; + struct ip *ip; + }; + uint8_t *transport_layer; + int size; + COLOProxyState *s; + NetClientState *sender; +} Packet; + +typedef struct ConnectionKey { + /* (src, dst) must be grouped, in the same way than in IP header */ + struct in_addr src; + struct in_addr dst; + uint16_t src_port; + uint16_t dst_port; + uint8_t ip_proto; +} QEMU_PACKED ConnectionKey; + +/* define one connection */ +typedef struct Connection { + /* connection primary send queue: element type: Packet */ + GQueue primary_list; + /* connection secondary send queue: element type: Packet */ + GQueue secondary_list; + /* flag to enqueue unprocessed_connections */ + bool processing; + int ip_proto; + + void *proto; /* tcp only now */ +} Connection; + enum { COLO_PROXY_NONE, /* colo proxy is not started */ COLO_PROXY_RUNNING, /* colo proxy is running */ @@ -101,6 +135,38 @@ GHashTable *colo_conn_hash; static bool colo_do_checkpoint; static ssize_t hashtable_max_size; +static inline void colo_proxy_dump_packet(Packet *pkt) +{ + int i; + for (i = 0; i < pkt->size; i++) { + printf("%02x ", ((uint8_t *)pkt->data)[i]); + } + printf("\n"); +} + +static uint32_t connection_key_hash(const void *opaque) +{ + const ConnectionKey *key = opaque; + uint32_t a, b, c; + + /* Jenkins hash */ + a = b = c = JHASH_INITVAL + sizeof(*key); + a += key->src.s_addr; + b += key->dst.s_addr; + c += (key->src_port | key->dst_port << 16); + __jhash_mix(a, b, c); + + a += key->ip_proto; + __jhash_final(a, b, c); + + return c; +} + +static int connection_key_equal(const void *opaque1, const void *opaque2) +{ + return memcmp(opaque1, opaque2, sizeof(ConnectionKey)) == 0; +} + static ssize_t colo_proxy_receive_iov(NetFilterState *nf, NetClientState *sender, unsigned flags, -- 1.9.1