colo.h 3.4 KB

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