blob: 679314b1cadd747b83ea3ce5281dc758930346c4 [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
Markus Armbruster58ea30f2019-03-15 15:51:20 +010015#ifndef NET_COLO_H
16#define NET_COLO_H
Zhang Chen59509ec2016-09-27 10:22:27 +080017
Zhang Chenccf04262016-09-27 10:22:28 +080018#include "qemu/jhash.h"
Zhang Chen0682e152016-09-27 10:22:30 +080019#include "qemu/timer.h"
Marc-André Lureaue05ae1d2018-11-14 16:36:40 +040020#include "net/eth.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;
Mao Zhongyif449c9e2017-12-25 10:54:12 +080048 uint32_t tcp_seq; /* sequence number */
49 uint32_t tcp_ack; /* acknowledgement number */
50 /* the sequence number of the last byte of the packet */
51 uint32_t seq_end;
52 uint8_t header_size; /* the header length */
53 uint16_t payload_size; /* the payload length */
54 /* record the payload offset(the length that has been compared) */
55 uint16_t offset;
56 uint8_t flags; /* Flags(aka Control bits) */
Zhang Chen59509ec2016-09-27 10:22:27 +080057} Packet;
58
Zhang Chenb6540d42016-09-27 10:22:29 +080059typedef struct ConnectionKey {
60 /* (src, dst) must be grouped, in the same way than in IP header */
61 struct in_addr src;
62 struct in_addr dst;
63 uint16_t src_port;
64 uint16_t dst_port;
65 uint8_t ip_proto;
66} QEMU_PACKED ConnectionKey;
67
68typedef struct Connection {
69 /* connection primary send queue: element type: Packet */
70 GQueue primary_list;
71 /* connection secondary send queue: element type: Packet */
72 GQueue secondary_list;
73 /* flag to enqueue unprocessed_connections */
74 bool processing;
75 uint8_t ip_proto;
Mao Zhongyif449c9e2017-12-25 10:54:12 +080076 /* record the sequence number that has been compared */
77 uint32_t compare_seq;
78 /* the maximum of acknowledgement number in primary_list queue */
79 uint32_t pack;
80 /* the maximum of acknowledgement number in secondary_list queue */
81 uint32_t sack;
Zhang Chen30656b02016-09-27 10:22:34 +080082 /* offset = secondary_seq - primary_seq */
Marc-André Lureaue05ae1d2018-11-14 16:36:40 +040083 uint32_t offset;
Zhang Chen62142312018-09-14 01:47:53 +000084
85 int tcp_state; /* TCP FSM state */
Marc-André Lureaue05ae1d2018-11-14 16:36:40 +040086 uint32_t fin_ack_seq; /* the seq of 'fin=1,ack=1' */
Zhang Chenb6540d42016-09-27 10:22:29 +080087} Connection;
88
89uint32_t connection_key_hash(const void *opaque);
90int connection_key_equal(const void *opaque1, const void *opaque2);
Zhang Chen59509ec2016-09-27 10:22:27 +080091int parse_packet_early(Packet *pkt);
Mao Zhongyi8fa5ad62017-10-13 14:32:09 +080092void extract_ip_and_port(uint32_t tmp_ports, ConnectionKey *key, Packet *pkt);
Zhang Chenb6540d42016-09-27 10:22:29 +080093void fill_connection_key(Packet *pkt, ConnectionKey *key);
Zhang Chenafe46122016-09-27 10:22:33 +080094void reverse_connection_key(ConnectionKey *key);
Zhang Chenb6540d42016-09-27 10:22:29 +080095Connection *connection_new(ConnectionKey *key);
96void connection_destroy(void *opaque);
97Connection *connection_get(GHashTable *connection_track_table,
98 ConnectionKey *key,
99 GQueue *conn_list);
Zhang Chen24525e92018-09-03 12:38:57 +0800100bool connection_has_tracked(GHashTable *connection_track_table,
101 ConnectionKey *key);
Zhang Chen59509ec2016-09-27 10:22:27 +0800102void connection_hashtable_reset(GHashTable *connection_track_table);
Zhang Chenada1a332017-07-04 14:53:50 +0800103Packet *packet_new(const void *data, int size, int vnet_hdr_len);
Zhang Chen59509ec2016-09-27 10:22:27 +0800104void packet_destroy(void *opaque, void *user_data);
105
Markus Armbruster58ea30f2019-03-15 15:51:20 +0100106#endif /* NET_COLO_H */