Zhang Chen | 59509ec | 2016-09-27 10:22:27 +0800 | [diff] [blame] | 1 | /* |
| 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 Armbruster | 58ea30f | 2019-03-15 15:51:20 +0100 | [diff] [blame] | 15 | #ifndef NET_COLO_H |
| 16 | #define NET_COLO_H |
Zhang Chen | 59509ec | 2016-09-27 10:22:27 +0800 | [diff] [blame] | 17 | |
Zhang Chen | ccf0426 | 2016-09-27 10:22:28 +0800 | [diff] [blame] | 18 | #include "qemu/jhash.h" |
Zhang Chen | 0682e15 | 2016-09-27 10:22:30 +0800 | [diff] [blame] | 19 | #include "qemu/timer.h" |
Marc-André Lureau | e05ae1d | 2018-11-14 16:36:40 +0400 | [diff] [blame] | 20 | #include "net/eth.h" |
Zhang Chen | 3772cf0 | 2022-08-22 16:14:36 +0800 | [diff] [blame] | 21 | #include "standard-headers/linux/virtio_net.h" |
Zhang Chen | 59509ec | 2016-09-27 10:22:27 +0800 | [diff] [blame] | 22 | |
| 23 | #define HASHTABLE_MAX_SIZE 16384 |
| 24 | |
Zhang Chen | b6540d4 | 2016-09-27 10:22:29 +0800 | [diff] [blame] | 25 | #ifndef IPPROTO_DCCP |
| 26 | #define IPPROTO_DCCP 33 |
| 27 | #endif |
| 28 | |
| 29 | #ifndef IPPROTO_SCTP |
| 30 | #define IPPROTO_SCTP 132 |
| 31 | #endif |
| 32 | |
| 33 | #ifndef IPPROTO_UDPLITE |
| 34 | #define IPPROTO_UDPLITE 136 |
| 35 | #endif |
| 36 | |
Zhang Chen | 59509ec | 2016-09-27 10:22:27 +0800 | [diff] [blame] | 37 | typedef struct Packet { |
| 38 | void *data; |
| 39 | union { |
| 40 | uint8_t *network_header; |
| 41 | struct ip *ip; |
| 42 | }; |
| 43 | uint8_t *transport_header; |
| 44 | int size; |
Zhang Chen | 0682e15 | 2016-09-27 10:22:30 +0800 | [diff] [blame] | 45 | /* Time of packet creation, in wall clock ms */ |
| 46 | int64_t creation_ms; |
Zhang Chen | ada1a33 | 2017-07-04 14:53:50 +0800 | [diff] [blame] | 47 | /* Get vnet_hdr_len from filter */ |
| 48 | uint32_t vnet_hdr_len; |
Mao Zhongyi | f449c9e | 2017-12-25 10:54:12 +0800 | [diff] [blame] | 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 */ |
| 52 | uint32_t seq_end; |
| 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) */ |
| 56 | uint16_t offset; |
| 57 | uint8_t flags; /* Flags(aka Control bits) */ |
Zhang Chen | 59509ec | 2016-09-27 10:22:27 +0800 | [diff] [blame] | 58 | } Packet; |
| 59 | |
Zhang Chen | b6540d4 | 2016-09-27 10:22:29 +0800 | [diff] [blame] | 60 | typedef struct ConnectionKey { |
| 61 | /* (src, dst) must be grouped, in the same way than in IP header */ |
| 62 | struct in_addr src; |
| 63 | struct in_addr dst; |
| 64 | uint16_t src_port; |
| 65 | uint16_t dst_port; |
| 66 | uint8_t ip_proto; |
| 67 | } QEMU_PACKED ConnectionKey; |
| 68 | |
| 69 | typedef struct Connection { |
| 70 | /* connection primary send queue: element type: Packet */ |
| 71 | GQueue primary_list; |
| 72 | /* connection secondary send queue: element type: Packet */ |
| 73 | GQueue secondary_list; |
| 74 | /* flag to enqueue unprocessed_connections */ |
| 75 | bool processing; |
| 76 | uint8_t ip_proto; |
Mao Zhongyi | f449c9e | 2017-12-25 10:54:12 +0800 | [diff] [blame] | 77 | /* record the sequence number that has been compared */ |
| 78 | uint32_t compare_seq; |
| 79 | /* the maximum of acknowledgement number in primary_list queue */ |
| 80 | uint32_t pack; |
| 81 | /* the maximum of acknowledgement number in secondary_list queue */ |
| 82 | uint32_t sack; |
Zhang Chen | 30656b0 | 2016-09-27 10:22:34 +0800 | [diff] [blame] | 83 | /* offset = secondary_seq - primary_seq */ |
Marc-André Lureau | e05ae1d | 2018-11-14 16:36:40 +0400 | [diff] [blame] | 84 | uint32_t offset; |
Zhang Chen | 6214231 | 2018-09-14 01:47:53 +0000 | [diff] [blame] | 85 | |
| 86 | int tcp_state; /* TCP FSM state */ |
Marc-André Lureau | e05ae1d | 2018-11-14 16:36:40 +0400 | [diff] [blame] | 87 | uint32_t fin_ack_seq; /* the seq of 'fin=1,ack=1' */ |
Zhang Chen | b6540d4 | 2016-09-27 10:22:29 +0800 | [diff] [blame] | 88 | } Connection; |
| 89 | |
| 90 | uint32_t connection_key_hash(const void *opaque); |
| 91 | int connection_key_equal(const void *opaque1, const void *opaque2); |
Zhang Chen | 59509ec | 2016-09-27 10:22:27 +0800 | [diff] [blame] | 92 | int parse_packet_early(Packet *pkt); |
Rao, Lei | 64153ca | 2021-11-03 10:21:12 +0800 | [diff] [blame] | 93 | void extract_ip_and_port(uint32_t tmp_ports, ConnectionKey *key, |
| 94 | Packet *pkt, bool reverse); |
| 95 | void fill_connection_key(Packet *pkt, ConnectionKey *key, bool reverse); |
Zhang Chen | b6540d4 | 2016-09-27 10:22:29 +0800 | [diff] [blame] | 96 | Connection *connection_new(ConnectionKey *key); |
| 97 | void connection_destroy(void *opaque); |
| 98 | Connection *connection_get(GHashTable *connection_track_table, |
| 99 | ConnectionKey *key, |
| 100 | GQueue *conn_list); |
Zhang Chen | 24525e9 | 2018-09-03 12:38:57 +0800 | [diff] [blame] | 101 | bool connection_has_tracked(GHashTable *connection_track_table, |
| 102 | ConnectionKey *key); |
Zhang Chen | 59509ec | 2016-09-27 10:22:27 +0800 | [diff] [blame] | 103 | void connection_hashtable_reset(GHashTable *connection_track_table); |
Zhang Chen | ada1a33 | 2017-07-04 14:53:50 +0800 | [diff] [blame] | 104 | Packet *packet_new(const void *data, int size, int vnet_hdr_len); |
Rao, Lei | 9b49271 | 2021-06-08 16:23:29 +0800 | [diff] [blame] | 105 | Packet *packet_new_nocopy(void *data, int size, int vnet_hdr_len); |
Zhang Chen | 59509ec | 2016-09-27 10:22:27 +0800 | [diff] [blame] | 106 | void packet_destroy(void *opaque, void *user_data); |
Lukas Straub | 9c55fe9 | 2020-05-22 15:53:53 +0800 | [diff] [blame] | 107 | void packet_destroy_partial(void *opaque, void *user_data); |
Zhang Chen | 59509ec | 2016-09-27 10:22:27 +0800 | [diff] [blame] | 108 | |
Markus Armbruster | 58ea30f | 2019-03-15 15:51:20 +0100 | [diff] [blame] | 109 | #endif /* NET_COLO_H */ |