colo-compare: track connection and enqueue packet
[qemu/kevin.git] / net / colo.h
blobc511bcdeb9f18e4536ab47220e6b3a182db13fd3
1 /*
2 * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO)
3 * (a.k.a. Fault Tolerance or Continuous Replication)
5 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
6 * Copyright (c) 2016 FUJITSU LIMITED
7 * Copyright (c) 2016 Intel Corporation
9 * Author: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
11 * This work is licensed under the terms of the GNU GPL, version 2 or
12 * later. See the COPYING file in the top-level directory.
15 #ifndef QEMU_COLO_PROXY_H
16 #define QEMU_COLO_PROXY_H
18 #include "slirp/slirp.h"
19 #include "qemu/jhash.h"
21 #define HASHTABLE_MAX_SIZE 16384
23 #ifndef IPPROTO_DCCP
24 #define IPPROTO_DCCP 33
25 #endif
27 #ifndef IPPROTO_SCTP
28 #define IPPROTO_SCTP 132
29 #endif
31 #ifndef IPPROTO_UDPLITE
32 #define IPPROTO_UDPLITE 136
33 #endif
35 typedef struct Packet {
36 void *data;
37 union {
38 uint8_t *network_header;
39 struct ip *ip;
41 uint8_t *transport_header;
42 int size;
43 } Packet;
45 typedef struct ConnectionKey {
46 /* (src, dst) must be grouped, in the same way than in IP header */
47 struct in_addr src;
48 struct in_addr dst;
49 uint16_t src_port;
50 uint16_t dst_port;
51 uint8_t ip_proto;
52 } QEMU_PACKED ConnectionKey;
54 typedef struct Connection {
55 /* connection primary send queue: element type: Packet */
56 GQueue primary_list;
57 /* connection secondary send queue: element type: Packet */
58 GQueue secondary_list;
59 /* flag to enqueue unprocessed_connections */
60 bool processing;
61 uint8_t ip_proto;
62 } Connection;
64 uint32_t connection_key_hash(const void *opaque);
65 int connection_key_equal(const void *opaque1, const void *opaque2);
66 int parse_packet_early(Packet *pkt);
67 void fill_connection_key(Packet *pkt, ConnectionKey *key);
68 Connection *connection_new(ConnectionKey *key);
69 void connection_destroy(void *opaque);
70 Connection *connection_get(GHashTable *connection_track_table,
71 ConnectionKey *key,
72 GQueue *conn_list);
73 void connection_hashtable_reset(GHashTable *connection_track_table);
74 Packet *packet_new(const void *data, int size);
75 void packet_destroy(void *opaque, void *user_data);
77 #endif /* QEMU_COLO_PROXY_H */