blob: caedb0dca7c4c86fd5b38ec284cbbe1c2f1562f3 [file] [log] [blame]
Zhang Chen59509ec2016-09-27 10:22:27 +08001/*
2 * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO)
3 * (a.k.a. Fault Tolerance or Continuous Replication)
4 *
5 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
6 * Copyright (c) 2016 FUJITSU LIMITED
7 * Copyright (c) 2016 Intel Corporation
8 *
9 * Author: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
10 *
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.
13 */
14
15#ifndef QEMU_COLO_PROXY_H
16#define QEMU_COLO_PROXY_H
17
18#include "slirp/slirp.h"
Zhang Chenccf04262016-09-27 10:22:28 +080019#include "qemu/jhash.h"
Zhang Chen0682e152016-09-27 10:22:30 +080020#include "qemu/timer.h"
Zhang Chen59509ec2016-09-27 10:22:27 +080021
22#define HASHTABLE_MAX_SIZE 16384
23
Zhang Chenb6540d42016-09-27 10:22:29 +080024#ifndef IPPROTO_DCCP
25#define IPPROTO_DCCP 33
26#endif
27
28#ifndef IPPROTO_SCTP
29#define IPPROTO_SCTP 132
30#endif
31
32#ifndef IPPROTO_UDPLITE
33#define IPPROTO_UDPLITE 136
34#endif
35
Zhang Chen59509ec2016-09-27 10:22:27 +080036typedef struct Packet {
37 void *data;
38 union {
39 uint8_t *network_header;
40 struct ip *ip;
41 };
42 uint8_t *transport_header;
43 int size;
Zhang Chen0682e152016-09-27 10:22:30 +080044 /* Time of packet creation, in wall clock ms */
45 int64_t creation_ms;
Zhang Chenada1a332017-07-04 14:53:50 +080046 /* Get vnet_hdr_len from filter */
47 uint32_t vnet_hdr_len;
Zhang Chen59509ec2016-09-27 10:22:27 +080048} Packet;
49
Zhang Chenb6540d42016-09-27 10:22:29 +080050typedef struct ConnectionKey {
51 /* (src, dst) must be grouped, in the same way than in IP header */
52 struct in_addr src;
53 struct in_addr dst;
54 uint16_t src_port;
55 uint16_t dst_port;
56 uint8_t ip_proto;
57} QEMU_PACKED ConnectionKey;
58
59typedef struct Connection {
60 /* connection primary send queue: element type: Packet */
61 GQueue primary_list;
62 /* connection secondary send queue: element type: Packet */
63 GQueue secondary_list;
64 /* flag to enqueue unprocessed_connections */
65 bool processing;
66 uint8_t ip_proto;
Zhang Chen30656b02016-09-27 10:22:34 +080067 /* offset = secondary_seq - primary_seq */
68 tcp_seq offset;
69 /*
70 * we use this flag update offset func
71 * run once in independent tcp connection
72 */
73 int syn_flag;
Zhang Chenb6540d42016-09-27 10:22:29 +080074} Connection;
75
76uint32_t connection_key_hash(const void *opaque);
77int connection_key_equal(const void *opaque1, const void *opaque2);
Zhang Chen59509ec2016-09-27 10:22:27 +080078int parse_packet_early(Packet *pkt);
Zhang Chenb6540d42016-09-27 10:22:29 +080079void fill_connection_key(Packet *pkt, ConnectionKey *key);
Zhang Chenafe46122016-09-27 10:22:33 +080080void reverse_connection_key(ConnectionKey *key);
Zhang Chenb6540d42016-09-27 10:22:29 +080081Connection *connection_new(ConnectionKey *key);
82void connection_destroy(void *opaque);
83Connection *connection_get(GHashTable *connection_track_table,
84 ConnectionKey *key,
85 GQueue *conn_list);
Zhang Chen59509ec2016-09-27 10:22:27 +080086void connection_hashtable_reset(GHashTable *connection_track_table);
Zhang Chenada1a332017-07-04 14:53:50 +080087Packet *packet_new(const void *data, int size, int vnet_hdr_len);
Zhang Chen59509ec2016-09-27 10:22:27 +080088void packet_destroy(void *opaque, void *user_data);
89
90#endif /* QEMU_COLO_PROXY_H */