1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef NET_COLO_H
16#define NET_COLO_H
17
18#include "qemu/jhash.h"
19#include "qemu/timer.h"
20#include "net/eth.h"
21#include "standard-headers/linux/virtio_net.h"
22
23#define HASHTABLE_MAX_SIZE 16384
24
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
37typedef 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;
45
46 int64_t creation_ms;
47
48 uint32_t vnet_hdr_len;
49 uint32_t tcp_seq;
50 uint32_t tcp_ack;
51
52 uint32_t seq_end;
53 uint8_t header_size;
54 uint16_t payload_size;
55
56 uint16_t offset;
57 uint8_t flags;
58} Packet;
59
60typedef struct ConnectionKey {
61
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
69typedef struct Connection {
70
71 GQueue primary_list;
72
73 GQueue secondary_list;
74
75 bool processing;
76 uint8_t ip_proto;
77
78 uint32_t compare_seq;
79
80 uint32_t pack;
81
82 uint32_t sack;
83
84 uint32_t offset;
85
86 int tcp_state;
87 uint32_t fin_ack_seq;
88} Connection;
89
90uint32_t connection_key_hash(const void *opaque);
91int connection_key_equal(const void *opaque1, const void *opaque2);
92int parse_packet_early(Packet *pkt);
93void extract_ip_and_port(uint32_t tmp_ports, ConnectionKey *key,
94 Packet *pkt, bool reverse);
95void fill_connection_key(Packet *pkt, ConnectionKey *key, bool reverse);
96Connection *connection_new(ConnectionKey *key);
97void connection_destroy(void *opaque);
98Connection *connection_get(GHashTable *connection_track_table,
99 ConnectionKey *key,
100 GQueue *conn_list);
101bool connection_has_tracked(GHashTable *connection_track_table,
102 ConnectionKey *key);
103void connection_hashtable_reset(GHashTable *connection_track_table);
104Packet *packet_new(const void *data, int size, int vnet_hdr_len);
105Packet *packet_new_nocopy(void *data, int size, int vnet_hdr_len);
106void packet_destroy(void *opaque, void *user_data);
107void packet_destroy_partial(void *opaque, void *user_data);
108
109#endif
110