colo.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #ifndef NET_COLO_H
  15. #define NET_COLO_H
  16. #include "qemu/jhash.h"
  17. #include "qemu/timer.h"
  18. #include "net/eth.h"
  19. #include "standard-headers/linux/virtio_net.h"
  20. #define HASHTABLE_MAX_SIZE 16384
  21. #ifndef IPPROTO_DCCP
  22. #define IPPROTO_DCCP 33
  23. #endif
  24. #ifndef IPPROTO_SCTP
  25. #define IPPROTO_SCTP 132
  26. #endif
  27. #ifndef IPPROTO_UDPLITE
  28. #define IPPROTO_UDPLITE 136
  29. #endif
  30. typedef struct Packet {
  31. void *data;
  32. union {
  33. uint8_t *network_header;
  34. struct ip *ip;
  35. };
  36. uint8_t *transport_header;
  37. int size;
  38. /* Time of packet creation, in wall clock ms */
  39. int64_t creation_ms;
  40. /* Get vnet_hdr_len from filter */
  41. uint32_t vnet_hdr_len;
  42. uint32_t tcp_seq; /* sequence number */
  43. uint32_t tcp_ack; /* acknowledgement number */
  44. /* the sequence number of the last byte of the packet */
  45. uint32_t seq_end;
  46. uint8_t header_size; /* the header length */
  47. uint16_t payload_size; /* the payload length */
  48. /* record the payload offset(the length that has been compared) */
  49. uint16_t offset;
  50. uint8_t flags; /* Flags(aka Control bits) */
  51. } Packet;
  52. typedef struct ConnectionKey {
  53. /* (src, dst) must be grouped, in the same way than in IP header */
  54. struct in_addr src;
  55. struct in_addr dst;
  56. uint16_t src_port;
  57. uint16_t dst_port;
  58. uint8_t ip_proto;
  59. } QEMU_PACKED ConnectionKey;
  60. typedef struct Connection {
  61. /* connection primary send queue: element type: Packet */
  62. GQueue primary_list;
  63. /* connection secondary send queue: element type: Packet */
  64. GQueue secondary_list;
  65. /* flag to enqueue unprocessed_connections */
  66. bool processing;
  67. uint8_t ip_proto;
  68. /* record the sequence number that has been compared */
  69. uint32_t compare_seq;
  70. /* the maximum of acknowledgement number in primary_list queue */
  71. uint32_t pack;
  72. /* the maximum of acknowledgement number in secondary_list queue */
  73. uint32_t sack;
  74. /* offset = secondary_seq - primary_seq */
  75. uint32_t offset;
  76. int tcp_state; /* TCP FSM state */
  77. uint32_t fin_ack_seq; /* the seq of 'fin=1,ack=1' */
  78. } Connection;
  79. uint32_t connection_key_hash(const void *opaque);
  80. int connection_key_equal(const void *opaque1, const void *opaque2);
  81. int parse_packet_early(Packet *pkt);
  82. void extract_ip_and_port(uint32_t tmp_ports, ConnectionKey *key,
  83. Packet *pkt, bool reverse);
  84. void fill_connection_key(Packet *pkt, ConnectionKey *key, bool reverse);
  85. Connection *connection_new(ConnectionKey *key);
  86. void connection_destroy(void *opaque);
  87. Connection *connection_get(GHashTable *connection_track_table,
  88. ConnectionKey *key,
  89. GQueue *conn_list);
  90. bool connection_has_tracked(GHashTable *connection_track_table,
  91. ConnectionKey *key);
  92. void connection_hashtable_reset(GHashTable *connection_track_table);
  93. Packet *packet_new(const void *data, int size, int vnet_hdr_len);
  94. Packet *packet_new_nocopy(void *data, int size, int vnet_hdr_len);
  95. void packet_destroy(void *opaque, void *user_data);
  96. void packet_destroy_partial(void *opaque, void *user_data);
  97. #endif /* NET_COLO_H */