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"
20 #include "qemu/timer.h"
21 #include "slirp/tcp.h"
23 #define HASHTABLE_MAX_SIZE 16384
26 #define IPPROTO_DCCP 33
30 #define IPPROTO_SCTP 132
33 #ifndef IPPROTO_UDPLITE
34 #define IPPROTO_UDPLITE 136
37 typedef struct Packet
{
40 uint8_t *network_header
;
43 uint8_t *transport_header
;
45 /* Time of packet creation, in wall clock ms */
47 /* Get vnet_hdr_len from filter */
48 uint32_t vnet_hdr_len
;
49 uint32_t tcp_seq
; /* sequence number */
50 uint32_t tcp_ack
; /* acknowledgement number */
51 /* the sequence number of the last byte of the packet */
53 uint8_t header_size
; /* the header length */
54 uint16_t payload_size
; /* the payload length */
55 /* record the payload offset(the length that has been compared) */
57 uint8_t flags
; /* Flags(aka Control bits) */
60 typedef struct ConnectionKey
{
61 /* (src, dst) must be grouped, in the same way than in IP header */
67 } QEMU_PACKED ConnectionKey
;
69 typedef struct Connection
{
70 /* connection primary send queue: element type: Packet */
72 /* connection secondary send queue: element type: Packet */
73 GQueue secondary_list
;
74 /* flag to enqueue unprocessed_connections */
77 /* record the sequence number that has been compared */
79 /* the maximum of acknowledgement number in primary_list queue */
81 /* the maximum of acknowledgement number in secondary_list queue */
83 /* offset = secondary_seq - primary_seq */
86 int tcp_state
; /* TCP FSM state */
87 tcp_seq fin_ack_seq
; /* the seq of 'fin=1,ack=1' */
90 uint32_t connection_key_hash(const void *opaque
);
91 int connection_key_equal(const void *opaque1
, const void *opaque2
);
92 int parse_packet_early(Packet
*pkt
);
93 void extract_ip_and_port(uint32_t tmp_ports
, ConnectionKey
*key
, Packet
*pkt
);
94 void fill_connection_key(Packet
*pkt
, ConnectionKey
*key
);
95 void reverse_connection_key(ConnectionKey
*key
);
96 Connection
*connection_new(ConnectionKey
*key
);
97 void connection_destroy(void *opaque
);
98 Connection
*connection_get(GHashTable
*connection_track_table
,
101 bool connection_has_tracked(GHashTable
*connection_track_table
,
103 void connection_hashtable_reset(GHashTable
*connection_track_table
);
104 Packet
*packet_new(const void *data
, int size
, int vnet_hdr_len
);
105 void packet_destroy(void *opaque
, void *user_data
);
107 #endif /* QEMU_COLO_PROXY_H */