summaryrefslogtreecommitdiff
path: root/common/test/gtest_packet_inject.cpp
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2023-08-09 18:47:16 +0800
committerluwenpeng <[email protected]>2023-08-10 18:31:38 +0800
commite34aa3f5e23d7fa0b95944269c499d5c1e7c23aa (patch)
treeaf0565991e01741c850d9479850fc58df6f9b509 /common/test/gtest_packet_inject.cpp
parent1063574ca0d3fea91f26b8a6bd76a2d021efd822 (diff)
TSG-16531 PacketAdapter适配容器环境,使用mrzcpd收包,通过RAW Socket注RST包v2.0.0-20230810
Diffstat (limited to 'common/test/gtest_packet_inject.cpp')
-rw-r--r--common/test/gtest_packet_inject.cpp178
1 files changed, 178 insertions, 0 deletions
diff --git a/common/test/gtest_packet_inject.cpp b/common/test/gtest_packet_inject.cpp
new file mode 100644
index 0000000..aad0349
--- /dev/null
+++ b/common/test/gtest_packet_inject.cpp
@@ -0,0 +1,178 @@
+#include <gtest/gtest.h>
+
+#include "packet_inject.h"
+
+/******************************************************************************
+ * Pcap file: 2-ETH_IP6_IP4_TCP_SSH.pcap
+ * [Protocols in frame: eth:ethertype:ipv6:ip:tcp:ssh]
+ ******************************************************************************
+ *
+ * Frame 1: 726 bytes on wire (5808 bits), 726 bytes captured (5808 bits)
+ * Ethernet II, Src: EvocInte_36:51:3c (00:22:46:36:51:3c), Dst: EvocInte_36:51:38 (00:22:46:36:51:38)
+ * Destination: EvocInte_36:51:38 (00:22:46:36:51:38)
+ * Source: EvocInte_36:51:3c (00:22:46:36:51:3c)
+ * Type: IPv6 (0x86dd)
+ * Internet Protocol Version 6, Src: 2001::192:168:40:134, Dst: 2001::192:168:40:133
+ * 0110 .... = Version: 6
+ * .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT)
+ * .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000
+ * Payload Length: 672
+ * Next Header: IPIP (4)
+ * Hop Limit: 64
+ * Source Address: 2001::192:168:40:134
+ * Destination Address: 2001::192:168:40:133
+ * [Source Teredo Server IPv4: 0.0.0.0]
+ * [Source Teredo Port: 65175]
+ * [Source Teredo Client IPv4: 255.191.254.203]
+ * [Destination Teredo Server IPv4: 0.0.0.0]
+ * [Destination Teredo Port: 65175]
+ * [Destination Teredo Client IPv4: 255.191.254.204]
+ * Internet Protocol Version 4, Src: 1.1.1.1, Dst: 2.2.2.2
+ * 0100 .... = Version: 4
+ * .... 0101 = Header Length: 20 bytes (5)
+ * Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
+ * Total Length: 672
+ * Identification: 0x0968 (2408)
+ * 000. .... = Flags: 0x0
+ * ...0 0000 0000 0000 = Fragment Offset: 0
+ * Time to Live: 212
+ * Protocol: TCP (6)
+ * Header Checksum: 0xd4ea [validation disabled]
+ * [Header checksum status: Unverified]
+ * Source Address: 1.1.1.1
+ * Destination Address: 2.2.2.2
+ * Transmission Control Protocol, Src Port: 57639, Dst Port: 22, Seq: 1, Ack: 1, Len: 632
+ * Source Port: 57639
+ * Destination Port: 22
+ * [Stream index: 0]
+ * [Conversation completeness: Incomplete (8)]
+ * [TCP Segment Len: 632]
+ * Sequence Number: 1 (relative sequence number)
+ * Sequence Number (raw): 1508621024
+ * [Next Sequence Number: 633 (relative sequence number)]
+ * Acknowledgment Number: 1 (relative ack number)
+ * Acknowledgment number (raw): 2828957019
+ * 0101 .... = Header Length: 20 bytes (5)
+ * Flags: 0x018 (PSH, ACK)
+ * Window: 28584
+ * [Calculated window size: 28584]
+ * [Window size scaling factor: -1 (unknown)]
+ * Checksum: 0xc51f [unverified]
+ * [Checksum Status: Unverified]
+ * Urgent Pointer: 0
+ * [Timestamps]
+ * [SEQ/ACK analysis]
+ * TCP payload (632 bytes)
+ * SSH Protocol
+ */
+
+unsigned char data2[] = {
+ 0x00, 0x22, 0x46, 0x36, 0x51, 0x38, 0x00, 0x22, 0x46, 0x36, 0x51, 0x3c, 0x86, 0xdd, 0x60, 0x00, 0x00, 0x00, 0x02, 0xa0, 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0xc0, 0xce, 0xf3, 0xc4, 0xf7, 0x83, 0xa9,
+ 0x22, 0x78, 0x74, 0x7f, 0x2e, 0xc1, 0xc6, 0x3b, 0x72, 0x26, 0x4b, 0x45, 0xbd, 0x1b, 0x9f, 0x66, 0x61, 0x46, 0xbb, 0x0f, 0xf3, 0xc5, 0x65, 0x95, 0xbc, 0xae,
+ 0x8f, 0x37, 0xfd, 0xa3, 0x20, 0xb6, 0xe4, 0xa8, 0xff, 0x45, 0xa1, 0x01, 0xa1, 0x76, 0xb3, 0xad, 0x16, 0x07, 0x39, 0x58, 0x3b, 0x34, 0xe9, 0xe6, 0xc0, 0xee,
+ 0x7f, 0x65, 0x6f, 0x68, 0xf4, 0x45, 0xa4, 0x85, 0xa7, 0x50, 0x63, 0xce, 0x0b, 0x0d, 0xbd, 0xd1, 0x20, 0xc8, 0x41, 0x37, 0x05, 0x1f, 0x81, 0xf3, 0x7c, 0xe7,
+ 0x67, 0x15, 0xce, 0xad, 0x76, 0x95, 0x1a, 0x93, 0x4a, 0xab, 0xc4, 0xea, 0x30, 0x44, 0x13, 0x47, 0xec, 0x79, 0xa2, 0x41, 0x0c, 0xdd, 0x42, 0xdf, 0xbf, 0x02,
+ 0xef, 0x9e, 0x67, 0x7e, 0x1e, 0xb0, 0x2a, 0x7f, 0x97, 0xf3, 0x5a, 0xbc, 0x21, 0x8d, 0xf9, 0xc3, 0x30, 0x45, 0xfe, 0x72, 0x74, 0x04, 0x53, 0x99, 0xe7, 0xd1,
+ 0x2b, 0xb6, 0x3a, 0x9c, 0x84, 0x0e, 0x15, 0x5e, 0x75, 0x3b, 0xc9, 0x0e, 0x94, 0xe6, 0x48, 0x0e, 0x37, 0x07, 0xf8, 0xd9, 0x59, 0x4b, 0x04, 0x50};
+
+TEST(PACKET_INJECT, ETH_IP6_IP4_TCP_SSH)
+{
+ struct ip6_hdr *hdr = (struct ip6_hdr *)(data2 + 14);
+ EXPECT_TRUE(packet_inject_ipv6(&hdr->ip6_dst, (const char *)(data2 + 14), sizeof(data2) - 14) == 0);
+}
+
+/******************************************************************************
+ * Pcap file: 4-ETH_IP4_IP6_TCP.pcap
+ * [Protocols in frame: eth:ethertype:ip:ipv6:tcp]
+ ******************************************************************************
+ *
+ * Frame 1: 106 bytes on wire (848 bits), 106 bytes captured (848 bits)
+ * Ethernet II, Src: JuniperN_45:88:29 (2c:6b:f5:45:88:29), Dst: JuniperN_2a:a2:00 (5c:5e:ab:2a:a2:00)
+ * Destination: JuniperN_2a:a2:00 (5c:5e:ab:2a:a2:00)
+ * Source: JuniperN_45:88:29 (2c:6b:f5:45:88:29)
+ * Type: IPv4 (0x0800)
+ * Internet Protocol Version 4, Src: 210.77.88.163, Dst: 59.66.4.50
+ * 0100 .... = Version: 4
+ * .... 0101 = Header Length: 20 bytes (5)
+ * Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
+ * Total Length: 92
+ * Identification: 0x0b4d (2893)
+ * 000. .... = Flags: 0x0
+ * ...0 0000 0000 0000 = Fragment Offset: 0
+ * Time to Live: 59
+ * Protocol: IPv6 (41)
+ * Header Checksum: 0x09c8 [validation disabled]
+ * [Header checksum status: Unverified]
+ * Source Address: 210.77.88.163
+ * Destination Address: 59.66.4.50
+ * Internet Protocol Version 6, Src: 2001:da8:200:900e:200:5efe:d24d:58a3, Dst: 2600:140e:6::1702:1058
+ * 0110 .... = Version: 6
+ * .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT)
+ * .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000
+ * Payload Length: 32
+ * Next Header: TCP (6)
+ * Hop Limit: 64
+ * Source Address: 2001:da8:200:900e:200:5efe:d24d:58a3
+ * Destination Address: 2600:140e:6::1702:1058
+ * [Source ISATAP IPv4: 210.77.88.163]
+ * Transmission Control Protocol, Src Port: 52556, Dst Port: 80, Seq: 0, Len: 0
+ * Source Port: 52556
+ * Destination Port: 80
+ * [Stream index: 0]
+ * [Conversation completeness: Complete, WITH_DATA (31)]
+ * [TCP Segment Len: 0]
+ * Sequence Number: 0 (relative sequence number)
+ * Sequence Number (raw): 2172673142
+ * [Next Sequence Number: 1 (relative sequence number)]
+ * Acknowledgment Number: 0
+ * Acknowledgment number (raw): 0
+ * 1000 .... = Header Length: 32 bytes (8)
+ * Flags: 0x002 (SYN)
+ * Window: 8192
+ * [Calculated window size: 8192]
+ * Checksum: 0xf757 [unverified]
+ * [Checksum Status: Unverified]
+ * Urgent Pointer: 0
+ * Options: (12 bytes), Maximum segment size, No-Operation (NOP), Window scale, No-Operation (NOP), No-Operation (NOP), SACK permitted
+ * [Timestamps]
+ */
+
+unsigned char data4[] = {
+ 0x5c, 0x5e, 0xab, 0x2a, 0xa2, 0x00, 0x2c, 0x6b, 0xf5, 0x45, 0x88, 0x29, 0x08, 0x00, 0x45, 0x00, 0x00, 0x5c, 0x0b, 0x4d, 0x00, 0x00, 0x3b, 0x29, 0x09, 0xc8,
+ 0xd2, 0x4d, 0x58, 0xa3, 0x3b, 0x42, 0x04, 0x32, 0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x06, 0x40, 0x20, 0x01, 0x0d, 0xa8, 0x02, 0x00, 0x90, 0x0e, 0x02, 0x00,
+ 0x5e, 0xfe, 0xd2, 0x4d, 0x58, 0xa3, 0x26, 0x00, 0x14, 0x0e, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x02, 0x10, 0x58, 0xcd, 0x4c, 0x00, 0x50,
+ 0x81, 0x80, 0x5c, 0x76, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x20, 0x00, 0xf7, 0x57, 0x00, 0x00, 0x02, 0x04, 0x04, 0xc4, 0x01, 0x03, 0x03, 0x08, 0x01, 0x01,
+ 0x04, 0x02};
+
+TEST(PACKET_INJECT, ETH_IP4_IP6_TCP)
+{
+ struct ip *hdr = (struct ip *)(data4 + 14);
+ EXPECT_TRUE(packet_inject_ipv4(&hdr->ip_dst, (const char *)(data4 + 14), sizeof(data4) - 14) == 0);
+}
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}