packets.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (c) 2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef NETWORK_TRAFFIC_PACKETS_H
  30. #define NETWORK_TRAFFIC_PACKETS_H
  31. #include <cstdint>
  32. #include <cstddef>
  33. struct Packet{
  34. size_t size;
  35. size_t preL2Size;
  36. size_t l2Size;
  37. size_t l3Size;
  38. size_t payloadSize;
  39. uint8_t* packet;
  40. uint8_t* payload() const {
  41. return packet + preL2Size + l2Size + l3Size;
  42. }
  43. uint8_t* l2Packet() const {
  44. return packet + preL2Size;
  45. }
  46. size_t l2PacketSize() const {
  47. return size - preL2Size;
  48. }
  49. uint8_t* l3Packet() const {
  50. return packet + preL2Size + l2Size;
  51. }
  52. size_t l3PacketSize() const {
  53. return size - preL2Size - l2Size;
  54. }
  55. };
  56. constexpr size_t qmapIpv4TcpPacketArrSize = 139;
  57. uint8_t qmapIpv4TcpPacketArr[qmapIpv4TcpPacketArrSize] = {
  58. 0x40, 0x00, 0x00, 0x83,
  59. 0x06, 0x80, 0x00, 0x20,
  60. 0x45, 0x00, 0x00, 0x83,
  61. 0xf5, 0x7a, 0x40, 0x00,
  62. 0x40, 0x06, 0xc1, 0x70,
  63. 0xc0, 0xa8, 0x01, 0x11,
  64. 0xc0, 0xa8, 0x01, 0x28,
  65. 0xdd, 0xd5, 0xfd, 0x76,
  66. 0x40, 0x35, 0xff, 0xc7,
  67. 0xb8, 0x35, 0xf0, 0xad,
  68. 0x50, 0x18, 0x01, 0xd9,
  69. 0x40, 0xa0, 0x00, 0x00,
  70. 0x48, 0x54, 0x54, 0x50,
  71. 0x2f, 0x31, 0x2e, 0x31,
  72. 0x20, 0x34, 0x30, 0x34,
  73. 0x20, 0x4e, 0x6f, 0x74,
  74. 0x20, 0x46, 0x6f, 0x75,
  75. 0x6e, 0x64, 0x0d, 0x0a,
  76. 0x43, 0x6f, 0x6e, 0x74,
  77. 0x65, 0x6e, 0x74, 0x2d,
  78. 0x54, 0x79, 0x70, 0x65,
  79. 0x3a, 0x20, 0x74, 0x65,
  80. 0x78, 0x74, 0x2f, 0x70,
  81. 0x6c, 0x61, 0x69, 0x6e,
  82. 0x0d, 0x0a, 0x43, 0x6f,
  83. 0x6e, 0x74, 0x65, 0x6e,
  84. 0x74, 0x2d, 0x4c, 0x65,
  85. 0x6e, 0x67, 0x74, 0x68,
  86. 0x3a, 0x20, 0x33, 0x30,
  87. 0x0d, 0x0a, 0x43, 0x6f,
  88. 0x6e, 0x6e, 0x65, 0x63,
  89. 0x74, 0x69, 0x6f, 0x6e,
  90. 0x3a, 0x20, 0x63, 0x6c,
  91. 0x6f, 0x73, 0x65, 0x0d,
  92. 0x0a, 0x0d, 0x0a
  93. };
  94. constexpr size_t ipv4UdpPacketArrSize = 46;
  95. uint8_t ipv4UdpPacketArr[ipv4UdpPacketArrSize] = {
  96. 0x45, 0x00, 0x00, 0x25,
  97. 0xd7, 0xa9, 0x00, 0x00,
  98. 0x72, 0x11, 0xeb, 0x8f,
  99. 0x0a, 0x3f, 0x8d, 0xc4,
  100. 0xac, 0x10, 0x41, 0x7b,
  101. 0x0d, 0x3d, 0xe8, 0x19,
  102. 0x00, 0x11, 0x88, 0xd7,
  103. 0x00, 0x04, 0xc0, 0x1a,
  104. 0x3b, 0x00, 0x00, 0xf0,
  105. 0x00, 0x00, 0x00, 0x00,
  106. 0x00, 0x00, 0x00, 0x00,
  107. 0x00, 0x00
  108. };
  109. constexpr size_t udpPacketArrSize = 80;
  110. uint8_t udpPacketArr[udpPacketArrSize] = {
  111. 0x07, 0xc1, 0x07, 0xc1,
  112. 0x00, 0x50, 0x39, 0x1a,
  113. 0x01, 0x28, 0x02, 0x00,
  114. 0x05, 0x04, 0x00, 0x03,
  115. 0xa0, 0xe0, 0xaf, 0x89,
  116. 0xb7, 0x3f, 0x00, 0x00,
  117. 0x00, 0x5a, 0x00, 0x00,
  118. 0x03, 0xe8, 0x00, 0x00,
  119. 0x0b, 0xb8, 0xac, 0x10,
  120. 0x41, 0x01, 0x61, 0x6e,
  121. 0x2d, 0x72, 0x74, 0x2d,
  122. 0x30, 0x32, 0x2e, 0x71,
  123. 0x75, 0x61, 0x04, 0x1c,
  124. 0x01, 0x00, 0x00, 0x00,
  125. 0xac, 0x10, 0x41, 0x02,
  126. 0x00, 0x00, 0x00, 0x01,
  127. 0x74, 0x18, 0x26, 0xc7,
  128. 0xa5, 0x29, 0x24, 0xa1,
  129. 0xcc, 0x77, 0x76, 0xdc,
  130. 0x6f, 0x52, 0xfb, 0xbf
  131. };
  132. constexpr size_t ipv6UdpPacketArrSize = 64;
  133. uint8_t ipv6UdpPacketArr[ipv6UdpPacketArrSize] = {
  134. 0x60, 0x05, 0xc1, 0xfd,
  135. 0x00, 0x18, 0x11, 0x01,
  136. 0xfe, 0x80, 0x00, 0x00,
  137. 0x00, 0x00, 0x00, 0x00,
  138. 0x8a, 0x51, 0xfb, 0xff,
  139. 0xfe, 0x41, 0xf5, 0xbd,
  140. 0xff, 0x02, 0x00, 0x00,
  141. 0x00, 0x00, 0x00, 0x00,
  142. 0x00, 0x00, 0x00, 0x00,
  143. 0x00, 0x00, 0x00, 0x01,
  144. 0x21, 0xa4, 0x21, 0xa4,
  145. 0x00, 0x18, 0xb2, 0x04,
  146. 0x42, 0x4a, 0x4e, 0x50,
  147. 0x02, 0x01, 0x00, 0x00,
  148. 0x00, 0x00, 0x00, 0x00,
  149. 0x00, 0x00, 0x00, 0x00
  150. };
  151. Packet QmapIpv4TcpPacket{
  152. .size=qmapIpv4TcpPacketArrSize,
  153. .preL2Size=8,
  154. .l2Size=20,
  155. .l3Size=20,
  156. .payloadSize=91,
  157. .packet=qmapIpv4TcpPacketArr
  158. };
  159. Packet ipv4UdpPacket{
  160. .size=ipv4UdpPacketArrSize,
  161. .preL2Size=0,
  162. .l2Size=20,
  163. .l3Size=8,
  164. .payloadSize=18,
  165. .packet=ipv4UdpPacketArr
  166. };
  167. Packet udpPacket{
  168. .size=udpPacketArrSize,
  169. .preL2Size=0,
  170. .l2Size=0,
  171. .l3Size=8,
  172. .payloadSize=72,
  173. .packet=udpPacketArr
  174. };
  175. Packet ipv6UdpPacket{
  176. .size=ipv6UdpPacketArrSize,
  177. .preL2Size=0,
  178. .l2Size=40,
  179. .l3Size=8,
  180. .payloadSize=16,
  181. .packet=ipv6UdpPacketArr
  182. };
  183. #endif //NETWORK_TRAFFIC_PACKETS_H