diff --git a/common/src/tfe_packet_io.cpp b/common/src/tfe_packet_io.cpp index 283c047..ce2cf0b 100644 --- a/common/src/tfe_packet_io.cpp +++ b/common/src/tfe_packet_io.cpp @@ -41,6 +41,8 @@ #define RX_BURST_MAX 128 +#define CURDIR_C2S 0x1 +#define CURDIR_S2C 0x2 #define IS_SINGLE 0x01 #define IS_TUNNEL 0x02 @@ -259,11 +261,6 @@ static struct metadata *metadata_new() return meta; } -static int metadata_is_empty(struct metadata *meta) -{ - return meta->write_ref == 0 ? 1 : 0; -} - static void metadata_deep_copy(struct metadata *dst, struct metadata *src) { dst->write_ref++; @@ -1058,26 +1055,20 @@ static void packet_io_send_fake_pkt(struct packet_io_thread_ctx *thread, struct marsio_send_burst_with_options(packet_io->dev_nf_interface.mr_path, thread->thread_index, tx_buffs, 3, MARSIO_SEND_OPT_REHASH); } -int raw_traffic_decapsulate(struct packet *handler, const char *raw_data, int raw_len, char **header, int *header_len, int *is_ipv4) +int raw_traffic_decapsulate(const char *raw_data, int raw_len, struct packet_info *pkt_info) { const struct layer_record *l3_layer_record = NULL; - const struct layer_record *l4_layer_record = NULL; + struct packet pkt; + packet_parse(&pkt, raw_data, raw_len); - l4_layer_record = packet_get_innermost_layer(handler, LAYER_TYPE_L4); - if (l4_layer_record == NULL) - return -1; - - if (l4_layer_record->type != LAYER_TYPE_TCP) - return -1; - - l3_layer_record = packet_get_innermost_layer(handler, LAYER_TYPE_L3); + l3_layer_record = packet_get_innermost_layer(&pkt, LAYER_TYPE_L3); if (l3_layer_record == NULL) return -1; - *is_ipv4 = l3_layer_record->type == LAYER_TYPE_IPV4 ? 1 : 0; - *header_len = l3_layer_record->hdr_offset; - *header = (char *)calloc(*header_len, sizeof(char)); - memcpy(*header, raw_data, *header_len); + pkt_info->is_ipv4 = l3_layer_record->type == LAYER_TYPE_IPV4 ? 1 : 0; + pkt_info->header_len = l3_layer_record->hdr_offset; + pkt_info->header_data = (char *)calloc(pkt_info->header_len, sizeof(char)); + memcpy(pkt_info->header_data, raw_data, pkt_info->header_len); return 0; } @@ -1103,7 +1094,6 @@ static int handle_session_opening(struct metadata *meta, struct ctrl_pkt_parser unsigned int stream_common_direction; uint8_t stream_protocol_in_char = 0; uint8_t enable_decrypted_traffic_steering = 0; - struct ethhdr *ether_hdr = NULL; struct session_ctx *s_ctx = NULL; struct tuple4 inner_tuple4; struct tcp_restore_info restore_info; @@ -1251,18 +1241,27 @@ passthrough: route_ctx_copy(&s_ctx->ctrl_meta->route_ctx, &meta->route_ctx); if (parser->seq_len > 0) - raw_traffic_decapsulate(&pkt, parser->seq_header, parser->seq_len, &s_ctx->c2s_info.header_data, &s_ctx->c2s_info.header_len, &s_ctx->c2s_info.is_ipv4); + raw_traffic_decapsulate(parser->seq_header, parser->seq_len, &s_ctx->c2s_info); if (parser->ack_len > 0) - raw_traffic_decapsulate(&pkt, parser->ack_header, parser->ack_len, &s_ctx->s2c_info.header_data, &s_ctx->s2c_info.header_len, &s_ctx->s2c_info.is_ipv4); + raw_traffic_decapsulate(parser->ack_header, parser->ack_len, &s_ctx->s2c_info); + + uint8_t packet_cur_dir = CURDIR_C2S; + tfe_cmsg_get_value(parser->cmsg, TFE_CMSG_TCP_RESTORE_INFO_PACKET_CUR_DIR, (unsigned char *)&packet_cur_dir, sizeof(uint8_t), &size); + + if (packet_cur_dir == CURDIR_C2S) { + s_ctx->c2s_info.tuple4 = inner_tuple4; + tuple4_reverse(&inner_tuple4, &s_ctx->s2c_info.tuple4); + } + else { + s_ctx->s2c_info.tuple4 = inner_tuple4; + tuple4_reverse(&inner_tuple4, &s_ctx->c2s_info.tuple4); + } // c2s - s_ctx->c2s_info.is_e2i_dir = meta->is_e2i_dir; - s_ctx->c2s_info.tuple4 = inner_tuple4; sids_copy(&s_ctx->c2s_info.sids, &parser->seq_sids); route_ctx_copy(&s_ctx->c2s_info.route_ctx, &parser->seq_route_ctx); // s2c - tuple4_reverse(&inner_tuple4, &s_ctx->s2c_info.tuple4); sids_copy(&s_ctx->s2c_info.sids, &parser->ack_sids); route_ctx_copy(&s_ctx->s2c_info.route_ctx, &parser->ack_route_ctx); @@ -1941,8 +1940,6 @@ void handle_decryption_packet_from_tap(const char *data, int len, void *args) void handle_raw_packet_from_tap(const char *data, int len, void *args) { - char *src_mac = NULL; - char *dst_mac = NULL; struct packet_io_thread_ctx *thread = (struct packet_io_thread_ctx *)args; struct packet_io *packet_io = thread->ref_io; struct packet_io_fs *packet_io_fs = thread->ret_fs_state; diff --git a/common/test/CMakeLists.txt b/common/test/CMakeLists.txt index 121fc3d..412c12f 100644 --- a/common/test/CMakeLists.txt +++ b/common/test/CMakeLists.txt @@ -22,14 +22,6 @@ add_executable(gtest_session_table test_session_table.cpp) target_include_directories(gtest_session_table PUBLIC ${CMAKE_SOURCE_DIR}/common/include) target_link_libraries(gtest_session_table common gtest) -############################################################################### -# gtest_raw_packet -############################################################################### - -add_executable(gtest_raw_packet test_raw_packet.cpp) -target_include_directories(gtest_raw_packet PUBLIC ${CMAKE_SOURCE_DIR}/common/include) -target_link_libraries(gtest_raw_packet common gtest) - ############################################################################### # gtest_discover_tests ############################################################################### @@ -38,4 +30,3 @@ include(GoogleTest) gtest_discover_tests(gtest_addr) gtest_discover_tests(gtest_cmsg) gtest_discover_tests(gtest_session_table) -gtest_discover_tests(gtest_raw_packet) diff --git a/common/test/test_raw_packet.cpp b/common/test/test_raw_packet.cpp deleted file mode 100644 index 4e328cd..0000000 --- a/common/test/test_raw_packet.cpp +++ /dev/null @@ -1,1161 +0,0 @@ -#include -#include - -#include "packet.h" -#include "tfe_packet_io.h" - -bool g_print_to_stderr = true; -void *g_packet_io_logger = NULL; -void *g_default_logger = NULL; -extern int raw_traffic_decapsulate(struct packet *handler, const char *raw_data, int raw_len, char **header, int *header_len, int *is_ipv4); - -struct tcp_policy_enforcer -{ - int tcp_policy_enforcer; -}; -struct tfe_cmsg -{ - int tfe_cmsg; -}; - -int tcp_policy_enforce(struct tcp_policy_enforcer *tcp_enforcer, struct tfe_cmsg *cmsg) -{ - return 0; -} - -struct chaining_policy_enforcer -{ - int chaining_policy_enforcer; -}; - -void chaining_policy_enforce(struct chaining_policy_enforcer *enforcer, struct tfe_cmsg *cmsg, uint64_t rule_id) -{ - return; -} - -struct tfe_proxy -{ - int tfe_proxy; -}; - -int tfe_proxy_fds_accept(struct tfe_proxy *ctx, int fd_downstream, int fd_upstream, int fd_fake_c, int fd_fake_s, struct tfe_cmsg *cmsg) -{ - return 0; -} - -unsigned int tfe_proxy_get_work_thread_count(void) -{ - return 0; -} - -/****************************************************************************** - * Pcap file: 1-ETH_VLAN_VLAN_IP4_IP4_UDP.pcap - * [Protocols in frame: eth:ethertype:vlan:ethertype:vlan:ethertype:ip:ip:udp:data] - ****************************************************************************** - * - * Frame 1: 170 bytes on wire (1360 bits), 170 bytes captured (1360 bits) - * Ethernet II, Src: HuaweiTe_3b:b3:9a (a4:c6:4f:3b:b3:9a), Dst: 00:00:00_00:00:04 (00:00:00:00:00:04) - * Destination: 00:00:00_00:00:04 (00:00:00:00:00:04) - * Source: HuaweiTe_3b:b3:9a (a4:c6:4f:3b:b3:9a) - * Type: 802.1Q Virtual LAN (0x8100) - * 802.1Q Virtual LAN, PRI: 3, DEI: 0, ID: 1624 - * 011. .... .... .... = Priority: Critical Applications (3) - * ...0 .... .... .... = DEI: Ineligible - * .... 0110 0101 1000 = ID: 1624 - * Type: 802.1Q Virtual LAN (0x8100) - * 802.1Q Virtual LAN, PRI: 3, DEI: 0, ID: 505 - * 011. .... .... .... = Priority: Critical Applications (3) - * ...0 .... .... .... = DEI: Ineligible - * .... 0001 1111 1001 = ID: 505 - * Type: IPv4 (0x0800) - * Internet Protocol Version 4, Src: 69.67.35.146, Dst: 41.202.46.110 - * 0100 .... = Version: 4 - * .... 0101 = Header Length: 20 bytes (5) - * Differentiated Services Field: 0xb8 (DSCP: EF PHB, ECN: Not-ECT) - * Total Length: 148 - * Identification: 0xe858 (59480) - * 000. .... = Flags: 0x0 - * ...0 0000 0000 0000 = Fragment Offset: 0 - * Time to Live: 255 - * Protocol: IPIP (4) - * Header Checksum: 0x1148 [validation disabled] - * [Header checksum status: Unverified] - * Source Address: 69.67.35.146 - * Destination Address: 41.202.46.110 - * Internet Protocol Version 4, Src: 10.10.100.25, Dst: 10.10.101.2 - * 0100 .... = Version: 4 - * .... 0101 = Header Length: 20 bytes (5) - * Differentiated Services Field: 0xb8 (DSCP: EF PHB, ECN: Not-ECT) - * Total Length: 128 - * Identification: 0x0001 (1) - * 000. .... = Flags: 0x0 - * ...0 0000 0000 0000 = Fragment Offset: 0 - * Time to Live: 254 - * Protocol: UDP (17) - * Header Checksum: 0xde84 [validation disabled] - * [Header checksum status: Unverified] - * Source Address: 10.10.100.25 - * Destination Address: 10.10.101.2 - * User Datagram Protocol, Src Port: 62367, Dst Port: 17000 - * Source Port: 62367 - * Destination Port: 17000 - * Length: 108 - * Checksum: 0x4b9a [unverified] - * [Checksum Status: Unverified] - * [Stream index: 0] - * [Timestamps] - * [Time since first frame: 0.000000000 seconds] - * [Time since previous frame: 0.000000000 seconds] - * UDP payload (100 bytes) - * Data (100 bytes) - */ - -unsigned char data1[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xa4, 0xc6, 0x4f, 0x3b, 0xb3, 0x9a, 0x81, 0x00, 0x66, 0x58, 0x81, 0x00, 0x61, 0xf9, 0x08, 0x00, 0x45, 0xb8, 0x00, 0x94, - 0xe8, 0x58, 0x00, 0x00, 0xff, 0x04, 0x11, 0x48, 0x45, 0x43, 0x23, 0x92, 0x29, 0xca, 0x2e, 0x6e, 0x45, 0xb8, 0x00, 0x80, 0x00, 0x01, 0x00, 0x00, 0xfe, 0x11, - 0xde, 0x84, 0x0a, 0x0a, 0x64, 0x19, 0x0a, 0x0a, 0x65, 0x02, 0xf3, 0x9f, 0x42, 0x68, 0x00, 0x6c, 0x4b, 0x9a, 0x00, 0x02, 0x00, 0x00, 0x04, 0x73, 0x6c, 0x10, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, - 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, - 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, - 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd}; - -TEST(RAW_PACKET, ETH_VLAN_VLAN_IP4_IP4_UDP) -{ - char *header = NULL; - int header_len = 0; - int is_ipv4 = 0; - struct packet pkt; - - packet_parse(&pkt, (const char *)data1, sizeof(data1)); - raw_traffic_decapsulate(&pkt, (const char *)data1, sizeof(data1), &header, &header_len, &is_ipv4); - EXPECT_TRUE(header == nullptr); - EXPECT_TRUE(header_len == 0); -} - -/****************************************************************************** - * 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, 0x04, 0x40, 0x20, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x92, 0x01, 0x68, 0x00, 0x40, 0x01, 0x34, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x92, 0x01, 0x68, 0x00, 0x40, - 0x01, 0x33, 0x45, 0x00, 0x02, 0xa0, 0x09, 0x68, 0x00, 0x00, 0xd4, 0x06, 0xd4, 0xea, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0xe1, 0x27, 0x00, 0x16, - 0x59, 0xeb, 0xba, 0xe0, 0xa8, 0x9e, 0x75, 0x5b, 0x50, 0x18, 0x6f, 0xa8, 0xc5, 0x1f, 0x00, 0x00, 0x4f, 0xe3, 0xa9, 0x48, 0x9b, 0xbe, 0xa8, 0x07, 0x0e, 0xbb, - 0x5b, 0xf1, 0x15, 0x1d, 0xc9, 0xbe, 0xdf, 0x78, 0x89, 0xa2, 0x8f, 0x12, 0x5f, 0xad, 0x51, 0xd5, 0xfa, 0xa7, 0x0b, 0xf2, 0x34, 0x00, 0x5b, 0x77, 0xae, 0xab, - 0xe4, 0x49, 0xa7, 0xa5, 0xa7, 0x1f, 0xda, 0x90, 0xcc, 0xe1, 0x8e, 0x9f, 0xe9, 0xee, 0x53, 0x59, 0xa4, 0x17, 0xf8, 0x0d, 0x40, 0xe5, 0x75, 0x97, 0xf0, 0x29, - 0xfa, 0x7c, 0xb8, 0x12, 0x7e, 0x93, 0xbc, 0x7e, 0x0a, 0x69, 0x8f, 0x1d, 0x7b, 0x1a, 0x2e, 0xf6, 0xa6, 0x78, 0x67, 0x26, 0xfe, 0x8f, 0xcf, 0x5a, 0x02, 0x7d, - 0xbb, 0x1b, 0xdb, 0xc7, 0x71, 0xee, 0xe9, 0xd9, 0xc1, 0x48,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, 0xae, 0x46, 0x68, 0x0c, 0x92, 0x22, 0xa4, 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(RAW_PACKET, ETH_IP6_IP4_TCP_SSH) -{ - char *header = NULL; - int header_len = 0; - int is_ipv4 = 0; - struct packet pkt; - unsigned char header_data[] = { - 0x00, 0x22, 0x46, 0x36, 0x51, 0x38, 0x00, 0x22, 0x46, 0x36, 0x51, 0x3c, 0x86, 0xdd, 0x60, 0x00, 0x00, 0x00, 0x02, 0xa0, 0x04, 0x40, 0x20, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x92, 0x01, 0x68, 0x00, 0x40, 0x01, 0x34, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x92, 0x01, 0x68, 0x00, 0x40, - 0x01, 0x33 - }; - - packet_parse(&pkt, (const char *)data2, sizeof(data2)); - raw_traffic_decapsulate(&pkt, (const char *)data2, sizeof(data2), &header, &header_len, &is_ipv4); - EXPECT_TRUE(memcmp(header_data, header, header_len) == 0); - EXPECT_TRUE(header_len == 54); - EXPECT_TRUE(is_ipv4 == 1); -} - -/****************************************************************************** - * Pcap file: 3-ETH_VLAN_IP6_IP4_GRE_PPP_IP4_UDP_DNS.pcap - * [Protocols in frame: eth:ethertype:vlan:ethertype:ipv6:ip:gre:ppp:ip:udp:dns] - ****************************************************************************** - * - * Frame 1: 272 bytes on wire (2176 bits), 272 bytes captured (2176 bits) - * Ethernet II, Src: Cisco_e6:82:c4 (00:19:06:e6:82:c4), Dst: 10:01:00:00:61:3d (10:01:00:00:61:3d) - * Destination: 10:01:00:00:61:3d (10:01:00:00:61:3d) - * Source: Cisco_e6:82:c4 (00:19:06:e6:82:c4) - * Type: 802.1Q Virtual LAN (0x8100) - * 802.1Q Virtual LAN, PRI: 0, DEI: 0, ID: 100 - * 000. .... .... .... = Priority: Best Effort (default) (0) - * ...0 .... .... .... = DEI: Ineligible - * .... 0000 0110 0100 = ID: 100 - * Type: IPv6 (0x86dd) - * Internet Protocol Version 6, Src: 2607:fcd0:100:2300::b108:2a6b, Dst: 2402:f000:1:8e01::5555 - * 0110 .... = Version: 6 - * .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT) - * .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000 - * Payload Length: 214 - * Next Header: IPIP (4) - * Hop Limit: 57 - * Source Address: 2607:fcd0:100:2300::b108:2a6b - * Destination Address: 2402:f000:1:8e01::5555 - * Internet Protocol Version 4, Src: 192.52.166.154, Dst: 16.0.0.200 - * 0100 .... = Version: 4 - * .... 0101 = Header Length: 20 bytes (5) - * Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT) - * Total Length: 214 - * Identification: 0x842f (33839) - * 010. .... = Flags: 0x2, Don't fragment - * ...0 0000 0000 0000 = Fragment Offset: 0 - * Time to Live: 64 - * Protocol: Generic Routing Encapsulation (47) - * Header Checksum: 0x3e33 [validation disabled] - * [Header checksum status: Unverified] - * Source Address: 192.52.166.154 - * Destination Address: 16.0.0.200 - * Generic Routing Encapsulation (PPP) - * Flags and Version: 0x3081 - * Protocol Type: PPP (0x880b) - * Payload Length: 178 - * Call ID: 17 - * Sequence Number: 538640 - * Acknowledgment Number: 429725 - * Point-to-Point Protocol - * Address: 0xff - * Control: 0x03 - * Protocol: Internet Protocol version 4 (0x0021) - * Internet Protocol Version 4, Src: 8.8.8.8, Dst: 172.16.44.3 - * 0100 .... = Version: 4 - * .... 0101 = Header Length: 20 bytes (5) - * Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT) - * Total Length: 174 - * Identification: 0x2f9c (12188) - * 000. .... = Flags: 0x0 - * ...0 0000 0000 0000 = Fragment Offset: 0 - * Time to Live: 50 - * Protocol: UDP (17) - * Header Checksum: 0x7080 [validation disabled] - * [Header checksum status: Unverified] - * Source Address: 8.8.8.8 - * Destination Address: 172.16.44.3 - * User Datagram Protocol, Src Port: 53, Dst Port: 9879 - * Source Port: 53 - * Destination Port: 9879 - * Length: 154 - * Checksum: 0x45d9 [unverified] - * [Checksum Status: Unverified] - * [Stream index: 0] - * [Timestamps] - * UDP payload (146 bytes) - * Domain Name System (response) - */ - -unsigned char data3[] = { - 0x10, 0x01, 0x00, 0x00, 0x61, 0x3d, 0x00, 0x19, 0x06, 0xe6, 0x82, 0xc4, 0x81, 0x00, 0x00, 0x64, 0x86, 0xdd, 0x60, 0x00, 0x00, 0x00, 0x00, 0xd6, 0x04, 0x39, - 0x26, 0x07, 0xfc, 0xd0, 0x01, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x08, 0x2a, 0x6b, 0x24, 0x02, 0xf0, 0x00, 0x00, 0x01, 0x8e, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x45, 0x00, 0x00, 0xd6, 0x84, 0x2f, 0x40, 0x00, 0x40, 0x2f, 0x3e, 0x33, 0xc0, 0x34, 0xa6, 0x9a, 0x10, 0x00, 0x00, 0xc8, - 0x30, 0x81, 0x88, 0x0b, 0x00, 0xb2, 0x00, 0x11, 0x00, 0x08, 0x38, 0x10, 0x00, 0x06, 0x8e, 0x9d, 0xff, 0x03, 0x00, 0x21, 0x45, 0x00, 0x00, 0xae, 0x2f, 0x9c, - 0x00, 0x00, 0x32, 0x11, 0x70, 0x80, 0x08, 0x08, 0x08, 0x08, 0xac, 0x10, 0x2c, 0x03, 0x00, 0x35, 0x26, 0x97, 0x00, 0x9a, 0x45, 0xd9, 0xb4, 0xe2, 0x81, 0x83, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x35, 0x78, 0x71, 0x74, 0x2d, 0x64, 0x65, 0x74, 0x65, 0x63, 0x74, 0x2d, 0x6d, 0x6f, 0x64, 0x65, 0x32, 0x2d, - 0x37, 0x38, 0x63, 0x30, 0x36, 0x64, 0x63, 0x37, 0x2d, 0x30, 0x34, 0x61, 0x37, 0x2d, 0x34, 0x38, 0x35, 0x33, 0x2d, 0x38, 0x34, 0x38, 0x33, 0x2d, 0x61, 0x35, - 0x36, 0x32, 0x38, 0x39, 0x37, 0x36, 0x65, 0x32, 0x33, 0x33, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x02, 0xf0, 0x00, 0x40, - 0x01, 0x61, 0x0c, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x03, 0x6e, 0x65, 0x74, 0x00, 0x05, 0x6e, 0x73, 0x74, 0x6c, 0x64, - 0x0c, 0x76, 0x65, 0x72, 0x69, 0x73, 0x69, 0x67, 0x6e, 0x2d, 0x67, 0x72, 0x73, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x78, 0x0d, 0x09, 0x09, 0x00, 0x00, 0x07, 0x08, - 0x00, 0x00, 0x03, 0x84, 0x00, 0x09, 0x3a, 0x80, 0x00, 0x01, 0x51, 0x80}; - -TEST(RAW_PACKET, ETH_VLAN_IP6_IP4_GRE_PPP_IP4_UDP_DNS) -{ - char *header = NULL; - int header_len = 0; - int is_ipv4 = 0; - struct packet pkt; - - packet_parse(&pkt, (const char *)data3, sizeof(data3)); - raw_traffic_decapsulate(&pkt, (const char *)data3, sizeof(data3), &header, &header_len, &is_ipv4); - EXPECT_TRUE(header == nullptr); - EXPECT_TRUE(header_len == 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(RAW_PACKET, ETH_IP4_IP6_TCP) -{ - char *header = NULL; - int header_len = 0; - int is_ipv4 = 0; - struct packet pkt; - unsigned char header_data[] = { - 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 - }; - - packet_parse(&pkt, (const char *)data4, sizeof(data4)); - raw_traffic_decapsulate(&pkt, (const char *)data4, sizeof(data4), &header, &header_len, &is_ipv4); - EXPECT_TRUE(memcmp(header_data, header, header_len) == 0); - EXPECT_TRUE(header_len == 34); - EXPECT_TRUE(is_ipv4 == 0); -} - -/****************************************************************************** - * Pcap file: 5-ETH_IP6_IP6_UDP.pcap - * [Protocols in frame: eth:ethertype:ipv6:ipv6:udp:data] - ****************************************************************************** - * - * Frame 1: 106 bytes on wire (848 bits), 106 bytes captured (848 bits) - * Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: Broadcast (ff:ff:ff:ff:ff:ff) - * Destination: Broadcast (ff:ff:ff:ff:ff:ff) - * Source: 00:00:00_00:00:00 (00:00:00:00:00:00) - * Type: IPv6 (0x86dd) - * Internet Protocol Version 6, Src: 2001:4f8:4:7:2e0:81ff:fe52:ffff, Dst: 2001:4f8:4:7:2e0:81ff:fe52:9a6b - * 0110 .... = Version: 6 - * .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT) - * .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000 - * Payload Length: 52 - * Next Header: IPv6 (41) - * Hop Limit: 64 - * Source Address: 2001:4f8:4:7:2e0:81ff:fe52:ffff - * Destination Address: 2001:4f8:4:7:2e0:81ff:fe52:9a6b - * [Source SLAAC MAC: TyanComp_52:ff:ff (00:e0:81:52:ff:ff)] - * [Destination SLAAC MAC: TyanComp_52:9a:6b (00:e0:81:52:9a:6b)] - * Internet Protocol Version 6, Src: dead::beef, Dst: cafe::babe - * 0110 .... = Version: 6 - * .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT) - * .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000 - * Payload Length: 12 - * Next Header: UDP (17) - * Hop Limit: 64 - * Source Address: dead::beef - * Destination Address: cafe::babe - * User Datagram Protocol, Src Port: 30000, Dst Port: 13000 - * Source Port: 30000 - * Destination Port: 13000 - * Length: 12 - * Checksum: 0x83d2 [unverified] - * [Checksum Status: Unverified] - * [Stream index: 0] - * [Timestamps] - * UDP payload (4 bytes) - * Data (4 bytes) - */ - -unsigned char data5[] = { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0xdd, 0x60, 0x00, 0x00, 0x00, 0x00, 0x34, 0x29, 0x40, 0x20, 0x01, 0x04, 0xf8, - 0x00, 0x04, 0x00, 0x07, 0x02, 0xe0, 0x81, 0xff, 0xfe, 0x52, 0xff, 0xff, 0x20, 0x01, 0x04, 0xf8, 0x00, 0x04, 0x00, 0x07, 0x02, 0xe0, 0x81, 0xff, 0xfe, 0x52, - 0x9a, 0x6b, 0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x11, 0x40, 0xde, 0xad, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbe, 0xef, - 0xca, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xba, 0xbe, 0x75, 0x30, 0x32, 0xc8, 0x00, 0x0c, 0x83, 0xd2, 0x58, 0x58, - 0x58, 0x58}; - -TEST(RAW_PACKET, ETH_IP6_IP6_UDP) -{ - char *header = NULL; - int header_len = 0; - int is_ipv4 = 0; - struct packet pkt; - - packet_parse(&pkt, (const char *)data5, sizeof(data5)); - raw_traffic_decapsulate(&pkt, (const char *)data5, sizeof(data5), &header, &header_len, &is_ipv4); - EXPECT_TRUE(header == nullptr); - EXPECT_TRUE(header_len == 0); -} - -/****************************************************************************** - * Pcap file: 6-ETH_MPLS_IP4_TCP.pcap - * [Protocols in frame: eth:ethertype:mpls:ip:tcp] - ****************************************************************************** - * - * Frame 1: 70 bytes on wire (560 bits), 70 bytes captured (560 bits) - * Ethernet II, Src: Hangzhou_d9:28:cc (00:23:89:d9:28:cc), Dst: HuaweiTe_7f:eb:f7 (d4:6a:a8:7f:eb:f7) - * Destination: HuaweiTe_7f:eb:f7 (d4:6a:a8:7f:eb:f7) - * Source: Hangzhou_d9:28:cc (00:23:89:d9:28:cc) - * Type: MPLS label switched packet (0x8847) - * MultiProtocol Label Switching Header, Label: 18, Exp: 6, S: 1, TTL: 254 - * 0000 0000 0000 0001 0010 .... .... .... = MPLS Label: 18 (0x00012) - * .... .... .... .... .... 110. .... .... = MPLS Experimental Bits: 6 - * .... .... .... .... .... ...1 .... .... = MPLS Bottom Of Label Stack: 1 - * .... .... .... .... .... .... 1111 1110 = MPLS TTL: 254 - * Internet Protocol Version 4, Src: 119.40.37.65, Dst: 123.125.29.250 - * 0100 .... = Version: 4 - * .... 0101 = Header Length: 20 bytes (5) - * Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT) - * Total Length: 52 - * Identification: 0x02a1 (673) - * 010. .... = Flags: 0x2, Don't fragment - * ...0 0000 0000 0000 = Fragment Offset: 0 - * Time to Live: 126 - * Protocol: TCP (6) - * Header Checksum: 0xc442 [validation disabled] - * [Header checksum status: Unverified] - * Source Address: 119.40.37.65 - * Destination Address: 123.125.29.250 - * Transmission Control Protocol, Src Port: 61853, Dst Port: 80, Seq: 0, Len: 0 - * Source Port: 61853 - * 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): 1710561749 - * [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: 0xa777 [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 data6[] = { - 0xd4, 0x6a, 0xa8, 0x7f, 0xeb, 0xf7, 0x00, 0x23, 0x89, 0xd9, 0x28, 0xcc, 0x88, 0x47, 0x00, 0x01, 0x2d, 0xfe, 0x45, 0x00, 0x00, 0x34, 0x02, 0xa1, 0x40, 0x00, - 0x7e, 0x06, 0xc4, 0x42, 0x77, 0x28, 0x25, 0x41, 0x7b, 0x7d, 0x1d, 0xfa, 0xf1, 0x9d, 0x00, 0x50, 0x65, 0xf5, 0x19, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, - 0x20, 0x00, 0xa7, 0x77, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4, 0x01, 0x03, 0x03, 0x08, 0x01, 0x01, 0x04, 0x02}; - -TEST(RAW_PACKET, ETH_MPLS_IP4_TCP) -{ - char *header = NULL; - int header_len = 0; - int is_ipv4 = 0; - struct packet pkt; - unsigned char header_data[] = { - 0xd4, 0x6a, 0xa8, 0x7f, 0xeb, 0xf7, 0x00, 0x23, 0x89, 0xd9, 0x28, 0xcc, 0x88, 0x47, 0x00, 0x01, 0x2d, 0xfe - }; - - packet_parse(&pkt, (const char *)data6, sizeof(data6)); - raw_traffic_decapsulate(&pkt, (const char *)data6, sizeof(data6), &header, &header_len, &is_ipv4); - EXPECT_TRUE(memcmp(header_data, header, header_len) == 0); - EXPECT_TRUE(header_len == 18); - EXPECT_TRUE(is_ipv4 == 1); -} - -/****************************************************************************** - * Pcap file: 7-ETH_MPLS_MPLS_IP4_TCP.pcap - * [Protocols in frame: eth:ethertype:mpls:ip:tcp] - ****************************************************************************** - * - * Frame 1: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) - * Ethernet II, Src: Cisco_05:28:38 (00:30:96:05:28:38), Dst: Cisco_e6:fc:39 (00:30:96:e6:fc:39) - * Destination: Cisco_e6:fc:39 (00:30:96:e6:fc:39) - * Source: Cisco_05:28:38 (00:30:96:05:28:38) - * Type: MPLS label switched packet (0x8847) - * MultiProtocol Label Switching Header, Label: 18, Exp: 5, S: 0, TTL: 255 - * 0000 0000 0000 0001 0010 .... .... .... = MPLS Label: 18 (0x00012) - * .... .... .... .... .... 101. .... .... = MPLS Experimental Bits: 5 - * .... .... .... .... .... ...0 .... .... = MPLS Bottom Of Label Stack: 0 - * .... .... .... .... .... .... 1111 1111 = MPLS TTL: 255 - * MultiProtocol Label Switching Header, Label: 16, Exp: 5, S: 1, TTL: 255 - * 0000 0000 0000 0001 0000 .... .... .... = MPLS Label: 16 (0x00010) - * .... .... .... .... .... 101. .... .... = MPLS Experimental Bits: 5 - * .... .... .... .... .... ...1 .... .... = MPLS Bottom Of Label Stack: 1 - * .... .... .... .... .... .... 1111 1111 = MPLS TTL: 255 - * Internet Protocol Version 4, Src: 10.31.0.1, Dst: 10.34.0.1 - * 0100 .... = Version: 4 - * .... 0101 = Header Length: 20 bytes (5) - * Differentiated Services Field: 0xb0 (DSCP: Unknown, ECN: Not-ECT) - * Total Length: 44 - * Identification: 0x0000 (0) - * 000. .... = Flags: 0x0 - * ...0 0000 0000 0000 = Fragment Offset: 0 - * Time to Live: 255 - * Protocol: TCP (6) - * Header Checksum: 0xa6d9 [validation disabled] - * [Header checksum status: Unverified] - * Source Address: 10.31.0.1 - * Destination Address: 10.34.0.1 - * Transmission Control Protocol, Src Port: 11001, Dst Port: 23, Seq: 0, Len: 0 - * Source Port: 11001 - * Destination Port: 23 - * [Stream index: 0] - * [Conversation completeness: Incomplete (29)] - * [TCP Segment Len: 0] - * Sequence Number: 0 (relative sequence number) - * Sequence Number (raw): 3481568569 - * [Next Sequence Number: 1 (relative sequence number)] - * Acknowledgment Number: 0 - * Acknowledgment number (raw): 0 - * 0110 .... = Header Length: 24 bytes (6) - * Flags: 0x002 (SYN) - * Window: 4128 - * [Calculated window size: 4128] - * Checksum: 0xf791 [unverified] - * [Checksum Status: Unverified] - * Urgent Pointer: 0 - * Options: (4 bytes), Maximum segment size - * [Timestamps] - */ - -unsigned char data7[] = { - 0x00, 0x30, 0x96, 0xe6, 0xfc, 0x39, 0x00, 0x30, 0x96, 0x05, 0x28, 0x38, 0x88, 0x47, 0x00, 0x01, 0x2a, 0xff, 0x00, 0x01, 0x0b, 0xff, 0x45, 0xb0, 0x00, 0x2c, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x06, 0xa6, 0xd9, 0x0a, 0x1f, 0x00, 0x01, 0x0a, 0x22, 0x00, 0x01, 0x2a, 0xf9, 0x00, 0x17, 0xcf, 0x84, 0x85, 0x39, 0x00, 0x00, - 0x00, 0x00, 0x60, 0x02, 0x10, 0x20, 0xf7, 0x91, 0x00, 0x00, 0x02, 0x04, 0x02, 0x18}; - -TEST(RAW_PACKET, ETH_MPLS_MPLS_IP4_TCP) -{ - char *header = NULL; - int header_len = 0; - int is_ipv4 = 0; - struct packet pkt; - unsigned char header_data[] = { - 0x00, 0x30, 0x96, 0xe6, 0xfc, 0x39, 0x00, 0x30, 0x96, 0x05, 0x28, 0x38, 0x88, 0x47, 0x00, 0x01, 0x2a, 0xff, 0x00, 0x01, 0x0b, 0xff - }; - - packet_parse(&pkt, (const char *)data7, sizeof(data7)); - raw_traffic_decapsulate(&pkt, (const char *)data7, sizeof(data7), &header, &header_len, &is_ipv4); - EXPECT_TRUE(memcmp(header_data, header, header_len) == 0); - EXPECT_TRUE(header_len == 22); - EXPECT_TRUE(is_ipv4 == 1); -} - -/****************************************************************************** - * Pcap file: 8-ETH_VLAN_PPPOE_IP4_TCP.pcap - * [Protocols in frame: eth:ethertype:vlan:ethertype:pppoes:ppp:ip:tcp] - ****************************************************************************** - * - * Frame 55: 78 bytes on wire (624 bits), 78 bytes captured (624 bits) - * Ethernet II, Src: 00:00:00_00:04:46 (00:00:00:00:04:46), Dst: 18:10:04:00:02:27 (18:10:04:00:02:27) - * Destination: 18:10:04:00:02:27 (18:10:04:00:02:27) - * Source: 00:00:00_00:04:46 (00:00:00:00:04:46) - * Type: 802.1Q Virtual LAN (0x8100) - * 802.1Q Virtual LAN, PRI: 3, DEI: 0, ID: 1476 - * 011. .... .... .... = Priority: Critical Applications (3) - * ...0 .... .... .... = DEI: Ineligible - * .... 0101 1100 0100 = ID: 1476 - * Type: PPPoE Session (0x8864) - * PPP-over-Ethernet Session - * 0001 .... = Version: 1 - * .... 0001 = Type: 1 - * Code: Session Data (0x00) - * Session ID: 0xb4bc - * Payload Length: 54 - * Point-to-Point Protocol - * Protocol: Internet Protocol version 4 (0x0021) - * Internet Protocol Version 4, Src: 100.65.55.0, Dst: 91.185.14.33 - * 0100 .... = Version: 4 - * .... 0101 = Header Length: 20 bytes (5) - * Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT) - * Total Length: 52 - * Identification: 0x4ba7 (19367) - * 010. .... = Flags: 0x2, Don't fragment - * ...0 0000 0000 0000 = Fragment Offset: 0 - * Time to Live: 63 - * Protocol: TCP (6) - * Header Checksum: 0xeb01 [validation disabled] - * [Header checksum status: Unverified] - * Source Address: 100.65.55.0 - * Destination Address: 91.185.14.33 - * Transmission Control Protocol, Src Port: 34532, Dst Port: 443, Seq: 491, Ack: 54523, Len: 0 - * Source Port: 34532 - * Destination Port: 443 - * [Stream index: 0] - * [Conversation completeness: Incomplete (12)] - * [TCP Segment Len: 0] - * Sequence Number: 491 (relative sequence number) - * Sequence Number (raw): 3064322674 - * [Next Sequence Number: 491 (relative sequence number)] - * Acknowledgment Number: 54523 (relative ack number) - * Acknowledgment number (raw): 2083649568 - * 1000 .... = Header Length: 32 bytes (8) - * Flags: 0x010 (ACK) - * Window: 4032 - * [Calculated window size: 4032] - * [Window size scaling factor: -1 (unknown)] - * Checksum: 0xc361 [unverified] - * [Checksum Status: Unverified] - * Urgent Pointer: 0 - * Options: (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps - * [Timestamps] - * [SEQ/ACK analysis] - */ - -unsigned char data8[] = { - 0x18, 0x10, 0x04, 0x00, 0x02, 0x27, 0x00, 0x00, 0x00, 0x00, 0x04, 0x46, 0x81, 0x00, 0x65, 0xc4, 0x88, 0x64, 0x11, 0x00, 0xb4, 0xbc, 0x00, 0x36, 0x00, 0x21, - 0x45, 0x00, 0x00, 0x34, 0x4b, 0xa7, 0x40, 0x00, 0x3f, 0x06, 0xeb, 0x01, 0x64, 0x41, 0x37, 0x00, 0x5b, 0xb9, 0x0e, 0x21, 0x86, 0xe4, 0x01, 0xbb, 0xb6, 0xa5, - 0xda, 0x72, 0x7c, 0x31, 0xf8, 0x20, 0x80, 0x10, 0x0f, 0xc0, 0xc3, 0x61, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x00, 0x6f, 0xab, 0xdf, 0x9c, 0x61, 0xc7, 0xc5}; - -TEST(RAW_PACKET, ETH_VLAN_PPPOE_IP4_TCP) -{ - char *header = NULL; - int header_len = 0; - int is_ipv4 = 0; - struct packet pkt; - unsigned char header_data[] = { - 0x18, 0x10, 0x04, 0x00, 0x02, 0x27, 0x00, 0x00, 0x00, 0x00, 0x04, 0x46, 0x81, 0x00, 0x65, 0xc4, 0x88, 0x64, 0x11, 0x00, 0xb4, 0xbc, 0x00, 0x36, 0x00, 0x21 - }; - - packet_parse(&pkt, (const char *)data8, sizeof(data8)); - raw_traffic_decapsulate(&pkt, (const char *)data8, sizeof(data8), &header, &header_len, &is_ipv4); - EXPECT_TRUE(memcmp(header_data, header, header_len) == 0); - EXPECT_TRUE(header_len == 26); - EXPECT_TRUE(is_ipv4 == 1); -} - -/****************************************************************************** - * Pcap file: 9-ETH_IP6_UDP_GTP_IP6_TCP_TLS.pcap - * [Protocols in frame: eth:ethertype:ipv6:udp:gtp:ipv6:tcp:ja3:tls] - ****************************************************************************** - * - * Frame 1: 1442 bytes on wire (11536 bits), 1442 bytes captured (11536 bits) - * Ethernet II, Src: zte_0e:f5:40 (74:4a:a4:0e:f5:40), Dst: HuaweiTe_40:e9:c2 (ac:b3:b5:40:e9:c2) - * Destination: HuaweiTe_40:e9:c2 (ac:b3:b5:40:e9:c2) - * Source: zte_0e:f5:40 (74:4a:a4:0e:f5:40) - * Type: IPv6 (0x86dd) - * Internet Protocol Version 6, Src: 2409:8034:4040:5300::105, Dst: 2409:8034:4025::60:61 - * 0110 .... = Version: 6 - * .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT) - * .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000 - * Payload Length: 1388 - * Next Header: UDP (17) - * Hop Limit: 127 - * Source Address: 2409:8034:4040:5300::105 - * Destination Address: 2409:8034:4025::60:61 - * User Datagram Protocol, Src Port: 2152, Dst Port: 2152 - * Source Port: 2152 - * Destination Port: 2152 - * Length: 1388 - * Checksum: 0xeb00 [unverified] - * [Checksum Status: Unverified] - * [Stream index: 0] - * [Timestamps] - * UDP payload (1380 bytes) - * GPRS Tunneling Protocol - * Flags: 0x30 - * Message Type: T-PDU (0xff) - * Length: 1372 - * TEID: 0x024c3cbd (38550717) - * Internet Protocol Version 6, Src: 2409:8c34:4400:700:0:4:0:3, Dst: 2409:8934:5082:2100:ecad:e0e4:530a:c269 - * 0110 .... = Version: 6 - * .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT) - * .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000 - * Payload Length: 1332 - * Next Header: TCP (6) - * Hop Limit: 56 - * Source Address: 2409:8c34:4400:700:0:4:0:3 - * Destination Address: 2409:8934:5082:2100:ecad:e0e4:530a:c269 - * Transmission Control Protocol, Src Port: 443, Dst Port: 46582, Seq: 1, Ack: 1, Len: 1312 - * Source Port: 443 - * Destination Port: 46582 - * [Stream index: 0] - * [Conversation completeness: Incomplete (8)] - * [TCP Segment Len: 1312] - * Sequence Number: 1 (relative sequence number) - * Sequence Number (raw): 2198097831 - * [Next Sequence Number: 1313 (relative sequence number)] - * Acknowledgment Number: 1 (relative ack number) - * Acknowledgment number (raw): 2264498872 - * 0101 .... = Header Length: 20 bytes (5) - * Flags: 0x010 (ACK) - * Window: 529 - * [Calculated window size: 529] - * [Window size scaling factor: -1 (unknown)] - * Checksum: 0x2c4b [unverified] - * [Checksum Status: Unverified] - * Urgent Pointer: 0 - * [Timestamps] - * [SEQ/ACK analysis] - * TCP payload (1312 bytes) - * Transport Layer Security - */ - -unsigned char data9[] = { - 0xac, 0xb3, 0xb5, 0x40, 0xe9, 0xc2, 0x74, 0x4a, 0xa4, 0x0e, 0xf5, 0x40, 0x86, 0xdd, 0x60, 0x00, 0x00, 0x00, 0x05, 0x6c, 0x11, 0x7f, 0x24, 0x09, 0x80, 0x34, - 0x40, 0x40, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x24, 0x09, 0x80, 0x34, 0x40, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, - 0x00, 0x61, 0x08, 0x68, 0x08, 0x68, 0x05, 0x6c, 0xeb, 0x00, 0x30, 0xff, 0x05, 0x5c, 0x02, 0x4c, 0x3c, 0xbd, 0x60, 0x00, 0x00, 0x00, 0x05, 0x34, 0x06, 0x38, - 0x24, 0x09, 0x8c, 0x34, 0x44, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x24, 0x09, 0x89, 0x34, 0x50, 0x82, 0x21, 0x00, 0xec, 0xad, - 0xe0, 0xe4, 0x53, 0x0a, 0xc2, 0x69, 0x01, 0xbb, 0xb5, 0xf6, 0x83, 0x04, 0x4f, 0xa7, 0x86, 0xf9, 0x82, 0xb8, 0x50, 0x10, 0x02, 0x11, 0x2c, 0x4b, 0x00, 0x00, - 0x17, 0x03, 0x03, 0x3c, 0x8c, 0x87, 0xa0, 0x99, 0x23, 0x5b, 0x53, 0x4a, 0x12, 0x1b, 0xf8, 0xba, 0xe8, 0x83, 0xc2, 0x95, 0xda, 0xb8, 0xea, 0x5b, 0xdc, 0x84, - 0x61, 0xa9, 0x86, 0x7e, 0x43, 0xc7, 0x31, 0x44, 0x6e, 0x11, 0xc1, 0x30, 0x21, 0x03, 0xb4, 0x21, 0x4a, 0xee, 0xc9, 0x2e, 0x14, 0xd2, 0x98, 0x63, 0x12, 0xfe, - 0x79, 0x58, 0xb3, 0x18, 0xa6, 0x8d, 0x0c, 0x62, 0x67, 0x51, 0xef, 0x02, 0x5a, 0xa8, 0xb3, 0x82, 0x1f, 0xe4, 0x51, 0xba, 0xde, 0xee, 0x83, 0x9c, 0x4e, 0xac, - 0x4d, 0xa2, 0xb7, 0x6a, 0x82, 0xe7, 0xbb, 0x00, 0xf7, 0x5a, 0xe7, 0x02, 0x71, 0x7e, 0x7d, 0x6f, 0xf2, 0xe5, 0x47, 0xd0, 0xba, 0x3c, 0x51, 0x09, 0x95, 0xcd, - 0xf6, 0xc9, 0x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 0x62, 0xcf, 0x63, 0xdb, 0x63, 0xd9, 0x21, 0x86, 0xe8, 0x96, 0x54, 0xeb, - 0x6a, 0xa8, 0x78, 0x3c, 0x5b, 0xb6, 0xde, 0xa9, 0x04, 0x48, 0x63, 0xb2, 0x10, 0x02, 0x6a, 0x7f, 0x6d, 0xc8, 0x04, 0xdd, 0x99, 0x25, 0x08, 0xff, 0x80, 0x11, - 0x53, 0xfb, 0x7a, 0x07, 0x39, 0xd9, 0x97, 0xca, 0xf0, 0xa7, 0x46, 0x9c, 0xc2, 0xae, 0x2e, 0x05, 0x62, 0xa0, 0xd5, 0x5d, 0x17, 0x0e, 0x5c, 0x7e, 0x9a, 0xb2, - 0xb7, 0x9d, 0xd4, 0x4f, 0xe3, 0xac, 0x64, 0xdb, 0x6f, 0x1d, 0xdf, 0xd8, 0x41, 0xd7, 0xd9, 0x50, 0x55, 0x30, 0xeb, 0x4b, 0x19, 0xce, 0x78, 0x1f, 0xa8, 0x1e, - 0x87, 0x9c, 0x8f, 0x93, 0x97, 0xd4, 0xa2, 0x28, 0x2c, 0x79, 0x22, 0xc8}; - -TEST(RAW_PACKET, ETH_IP6_UDP_GTP_IP6_TCP_TLS) -{ - char *header = NULL; - int header_len = 0; - int is_ipv4 = 0; - struct packet pkt; - unsigned char header_data[] = { - 0xac, 0xb3, 0xb5, 0x40, 0xe9, 0xc2, 0x74, 0x4a, 0xa4, 0x0e, 0xf5, 0x40, 0x86, 0xdd, 0x60, 0x00, 0x00, 0x00, 0x05, 0x6c, 0x11, 0x7f, 0x24, 0x09, 0x80, 0x34, - 0x40, 0x40, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x24, 0x09, 0x80, 0x34, 0x40, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, - 0x00, 0x61, 0x08, 0x68, 0x08, 0x68, 0x05, 0x6c, 0xeb, 0x00, 0x30, 0xff, 0x05, 0x5c, 0x02, 0x4c, 0x3c, 0xbd - }; - - packet_parse(&pkt, (const char *)data9, sizeof(data9)); - raw_traffic_decapsulate(&pkt, (const char *)data9, sizeof(data9), &header, &header_len, &is_ipv4); - EXPECT_TRUE(memcmp(header_data, header, header_len) == 0); - EXPECT_TRUE(header_len == 70); - EXPECT_TRUE(is_ipv4 == 0); -} - -/****************************************************************************** - * Pcap file: 10-ETH_IP6_UDP_GTP_IP4_TCP_TLS.pcap - * [Protocols in frame: eth:ethertype:ipv6:udp:gtp:ip:tcp:ja3:tls] - ****************************************************************************** - * - * Frame 1: 1470 bytes on wire (11760 bits), 1470 bytes captured (11760 bits) - * Ethernet II, Src: HuaweiTe_62:ee:70 (60:d7:55:62:ee:70), Dst: zte_0e:f5:1c (74:4a:a4:0e:f5:1c) - * Destination: zte_0e:f5:1c (74:4a:a4:0e:f5:1c) - * Source: HuaweiTe_62:ee:70 (60:d7:55:62:ee:70) - * Type: IPv6 (0x86dd) - * Internet Protocol Version 6, Src: 2409:8034:4025::50:a31, Dst: 2409:8034:4040:5301::204 - * 0110 .... = Version: 6 - * .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT) - * .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000 - * Payload Length: 1416 - * Next Header: UDP (17) - * Hop Limit: 252 - * Source Address: 2409:8034:4025::50:a31 - * Destination Address: 2409:8034:4040:5301::204 - * User Datagram Protocol, Src Port: 2152, Dst Port: 2152 - * Source Port: 2152 - * Destination Port: 2152 - * Length: 1416 - * Checksum: 0xc8df [unverified] - * [Checksum Status: Unverified] - * [Stream index: 0] - * [Timestamps] - * UDP payload (1408 bytes) - * GPRS Tunneling Protocol - * Flags: 0x30 - * Message Type: T-PDU (0xff) - * Length: 1400 - * TEID: 0x6c2a4753 (1814710099) - * Internet Protocol Version 4, Src: 10.49.115.138, Dst: 121.196.250.66 - * 0100 .... = Version: 4 - * .... 0101 = Header Length: 20 bytes (5) - * Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT) - * Total Length: 1400 - * Identification: 0x0003 (3) - * 010. .... = Flags: 0x2, Don't fragment - * ...0 0000 0000 0000 = Fragment Offset: 0 - * Time to Live: 64 - * Protocol: TCP (6) - * Header Checksum: 0x43bb [validation disabled] - * [Header checksum status: Unverified] - * Source Address: 10.49.115.138 - * Destination Address: 121.196.250.66 - * Transmission Control Protocol, Src Port: 50081, Dst Port: 443, Seq: 1, Ack: 1, Len: 1348 - * Source Port: 50081 - * Destination Port: 443 - * [Stream index: 0] - * [Conversation completeness: Incomplete (8)] - * [TCP Segment Len: 1348] - * Sequence Number: 1 (relative sequence number) - * Sequence Number (raw): 1522577104 - * [Next Sequence Number: 1349 (relative sequence number)] - * Acknowledgment Number: 1 (relative ack number) - * Acknowledgment number (raw): 3419365570 - * 1000 .... = Header Length: 32 bytes (8) - * Flags: 0x010 (ACK) - * Window: 2038 - * [Calculated window size: 2038] - * [Window size scaling factor: -1 (unknown)] - * Checksum: 0xd3c2 [unverified] - * [Checksum Status: Unverified] - * Urgent Pointer: 0 - * Options: (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps - * [Timestamps] - * [SEQ/ACK analysis] - * TCP payload (1348 bytes) - * Transport Layer Security - */ - -unsigned char data10[] = { - 0x74, 0x4a, 0xa4, 0x0e, 0xf5, 0x1c, 0x60, 0xd7, 0x55, 0x62, 0xee, 0x70, 0x86, 0xdd, 0x60, 0x00, 0x00, 0x00, 0x05, 0x88, 0x11, 0xfc, 0x24, 0x09, 0x80, 0x34, - 0x40, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x0a, 0x31, 0x24, 0x09, 0x80, 0x34, 0x40, 0x40, 0x53, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x04, 0x08, 0x68, 0x08, 0x68, 0x05, 0x88, 0xc8, 0xdf, 0x30, 0xff, 0x05, 0x78, 0x6c, 0x2a, 0x47, 0x53, 0x45, 0x00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 0x7c, - 0x29, 0x34, 0x1a, 0x45, 0x7e, 0x11, 0x68, 0xb4, 0x3a, 0xf6, 0x5b, 0x23, 0xe4, 0x32, 0xa4, 0x11, 0x1a, 0xba, 0xd6, 0x4a, 0x45, 0x42, 0x29, 0xac, 0xb0, 0x17, - 0x05, 0x1b, 0xee, 0xf6, 0x52, 0x6d, 0x8b, 0xb4, 0x3b, 0x63, 0xe2, 0xca, 0xbf, 0x7e, 0xd3, 0xf7, 0x96, 0x75, 0x67, 0x9d, 0x27, 0x15, 0x39, 0xde, 0x5f, 0x66, - 0x74, 0x7c, 0x46, 0x01, 0x48, 0xf7, 0x99, 0x33, 0x7d, 0xc6, 0x81, 0xc4, 0x82, 0x09, 0x00, 0x20, 0x3f, 0x5c, 0xe4, 0x51, 0x88, 0x5b, 0xac, 0x31, 0x17, 0x04, - 0xa4, 0xac, 0xbf, 0x3d, 0xff, 0xad, 0x51, 0x07, 0x0b, 0xc7, 0x26, 0xa7, 0x9f, 0x83, 0x17, 0xd8, 0x2f, 0x6a, 0x47, 0x96, 0x14, 0x47, 0x68, 0xd4, 0xc0, 0xc0, - 0x3b, 0x87, 0x51, 0x30, 0xe9, 0xfa, 0x21, 0x46, 0x80, 0x1a, 0x5a, 0xef, 0x78, 0xd0, 0x3a, 0xac, 0x73, 0x1e, 0x39, 0xba, 0x82, 0x43, 0x5d, 0xef, 0x15, 0x2c, - 0x9a, 0xe5, 0xeb, 0x6a, 0xe7, 0x24, 0x12, 0xe6, 0x2a, 0xd2, 0x09, 0xc2, 0x85, 0x69, 0x9d, 0x73, 0x16, 0xb0, 0xad, 0x51, 0xf8, 0x3d, 0x94, 0x6b, 0xb7, 0xb3, - 0x7f, 0xb4, 0x9e, 0xc1, 0xdc, 0x31, 0x27, 0xa1, 0x2d, 0xfe, 0x30, 0x15, 0x04, 0x20, 0x82, 0xdc, 0xbd, 0x8b, 0xc5, 0xb4, 0xcf, 0x91, 0x85, 0xae, 0x21, 0x5e, - 0x00, 0x10, 0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0x17, 0xc2, 0xd0, 0x78, 0x76, 0x9d, 0x5b, 0x7d, 0x3c, 0xb4, 0xf8, 0xcb, 0x2f, 0x83, 0x23, 0x35, 0x49, 0xc0, 0x78, - 0x2d, 0x44, 0x05, 0x64, 0x0f, 0xaa, 0x84, 0x9d, 0x3f, 0xac, 0xef, 0x5b, 0x46, 0x44, 0xb8, 0x15, 0xbe, 0x4f, 0xe7, 0x25, 0xb7, 0xa0, 0xc8, 0x0f, 0x70, 0x1a, - 0xca, 0x7f, 0xce, 0x79, 0x7b, 0xf5, 0x7e, 0x21, 0x35, 0xc7, 0x0e, 0x99, 0xdc, 0x76, 0xe0, 0x36, 0x09, 0x6e, 0x6d, 0x5f, 0x98, 0x5e, 0xb8, 0xa4, 0x88, 0xea, - 0x0b, 0x4b, 0x21, 0xa2, 0x52, 0x86, 0x95, 0x4e, 0x18, 0xac, 0xa2, 0xaf, 0x29, 0x5b, 0xe7, 0x05, 0xa1, 0xc8, 0xe1, 0x80, 0xfa, 0xb6, 0x5a, 0xed, 0x94, 0x32, - 0x4f, 0xe9, 0xf5, 0xf0, 0x61, 0x5d, 0x7f, 0xc4, 0xc4, 0xd1, 0x05, 0x54, 0x13, 0xdb}; - -TEST(RAW_PACKET, ETH_IP6_UDP_GTP_IP4_TCP_TLS) -{ - char *header = NULL; - int header_len = 0; - int is_ipv4 = 0; - struct packet pkt; - unsigned char header_data[] = { - 0x74, 0x4a, 0xa4, 0x0e, 0xf5, 0x1c, 0x60, 0xd7, 0x55, 0x62, 0xee, 0x70, 0x86, 0xdd, 0x60, 0x00, 0x00, 0x00, 0x05, 0x88, 0x11, 0xfc, 0x24, 0x09, 0x80, 0x34, - 0x40, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x0a, 0x31, 0x24, 0x09, 0x80, 0x34, 0x40, 0x40, 0x53, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x02, 0x04, 0x08, 0x68, 0x08, 0x68, 0x05, 0x88, 0xc8, 0xdf, 0x30, 0xff, 0x05, 0x78, 0x6c, 0x2a, 0x47, 0x53 - }; - - packet_parse(&pkt, (const char *)data10, sizeof(data10)); - raw_traffic_decapsulate(&pkt, (const char *)data10, sizeof(data10), &header, &header_len, &is_ipv4); - EXPECT_TRUE(memcmp(header_data, header, header_len) == 0); - EXPECT_TRUE(header_len == 70); - EXPECT_TRUE(is_ipv4 == 1); -} - -/****************************************************************************** - * Pcap file: 11-ETH_IP4_UDP_VXLAN_ETH_IP4_UDP_DNS.pcap - * [Protocols in frame: eth:ethertype:ip:udp:vxlan:eth:ethertype:ip:udp:dns] - ****************************************************************************** - * - * Frame 1: 124 bytes on wire (992 bits), 124 bytes captured (992 bits) - * Ethernet II, Src: zte_6c:fa:43 (00:1e:73:6c:fa:43), Dst: Shanghai_0d:0a (e4:95:6e:20:0d:0a) - * Destination: Shanghai_0d:0a (e4:95:6e:20:0d:0a) - * Source: zte_6c:fa:43 (00:1e:73:6c:fa:43) - * Type: IPv4 (0x0800) - * Internet Protocol Version 4, Src: 10.1.1.1, Dst: 192.168.1.10 - * 0100 .... = Version: 4 - * .... 0101 = Header Length: 20 bytes (5) - * Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT) - * Total Length: 110 - * Identification: 0x0000 (0) - * 000. .... = Flags: 0x0 - * ...0 0000 0000 0000 = Fragment Offset: 0 - * Time to Live: 254 - * Protocol: UDP (17) - * Header Checksum: 0xefca [validation disabled] - * [Header checksum status: Unverified] - * Source Address: 10.1.1.1 - * Destination Address: 192.168.1.10 - * User Datagram Protocol, Src Port: 50709, Dst Port: 4789 - * Source Port: 50709 - * Destination Port: 4789 - * Length: 90 - * Checksum: 0x0000 [zero-value ignored] - * [Stream index: 0] - * [Timestamps] - * UDP payload (82 bytes) - * Virtual eXtensible Local Area Network - * Flags: 0x0800, VXLAN Network ID (VNI) - * Group Policy ID: 0 - * VXLAN Network Identifier (VNI): 458755 - * Reserved: 0 - * Ethernet II, Src: WistronI_18:18:41 (3c:97:0e:18:18:41), Dst: DawningI_13:70:7a (e8:61:1f:13:70:7a) - * Destination: DawningI_13:70:7a (e8:61:1f:13:70:7a) - * Source: WistronI_18:18:41 (3c:97:0e:18:18:41) - * Type: IPv4 (0x0800) - * Internet Protocol Version 4, Src: 192.168.11.193, Dst: 114.114.114.114 - * 0100 .... = Version: 4 - * .... 0101 = Header Length: 20 bytes (5) - * Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT) - * Total Length: 60 - * Identification: 0x0cb6 (3254) - * 000. .... = Flags: 0x0 - * ...0 0000 0000 0000 = Fragment Offset: 0 - * Time to Live: 64 - * Protocol: UDP (17) - * Header Checksum: 0xbcad [validation disabled] - * [Header checksum status: Unverified] - * Source Address: 192.168.11.193 - * Destination Address: 114.114.114.114 - * User Datagram Protocol, Src Port: 65290, Dst Port: 53 - * Source Port: 65290 - * Destination Port: 53 - * Length: 40 - * Checksum: 0x39e4 [unverified] - * [Checksum Status: Unverified] - * [Stream index: 1] - * [Timestamps] - * UDP payload (32 bytes) - * Domain Name System (query) - */ - -unsigned char data11[] = { - 0xe4, 0x95, 0x6e, 0x20, 0x0d, 0x0a, 0x00, 0x1e, 0x73, 0x6c, 0xfa, 0x43, 0x08, 0x00, 0x45, 0x00, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x11, 0xef, 0xca, - 0x0a, 0x01, 0x01, 0x01, 0xc0, 0xa8, 0x01, 0x0a, 0xc6, 0x15, 0x12, 0xb5, 0x00, 0x5a, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x07, 0x00, 0x03, 0x00, 0xe8, 0x61, - 0x1f, 0x13, 0x70, 0x7a, 0x3c, 0x97, 0x0e, 0x18, 0x18, 0x41, 0x08, 0x00, 0x45, 0x00, 0x00, 0x3c, 0x0c, 0xb6, 0x00, 0x00, 0x40, 0x11, 0xbc, 0xad, 0xc0, 0xa8, - 0x0b, 0xc1, 0x72, 0x72, 0x72, 0x72, 0xff, 0x0a, 0x00, 0x35, 0x00, 0x28, 0x39, 0xe4, 0x86, 0x84, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x03, 0x77, 0x77, 0x77, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01}; - -TEST(RAW_PACKET, ETH_IP4_UDP_VXLAN_ETH_IP4_UDP_DNS) -{ - char *header = NULL; - int header_len = 0; - int is_ipv4 = 0; - struct packet pkt; - - packet_parse(&pkt, (const char *)data11, sizeof(data11)); - raw_traffic_decapsulate(&pkt, (const char *)data11, sizeof(data11), &header, &header_len, &is_ipv4); - EXPECT_TRUE(header == nullptr); - EXPECT_TRUE(header_len == 0); -} - -/****************************************************************************** - * Pcap file: 12-ETH_MPLS_MPLS_PWETHCW_ETH_ARP.pcap - * [Protocols in frame: eth:ethertype:mpls:pwethheuristic:pwethcw:eth:ethertype:arp] - ****************************************************************************** - * - * Frame 1: 90 bytes on wire (720 bits), 90 bytes captured (720 bits) - * Ethernet II, Src: cc:01:0d:5c:00:10 (cc:01:0d:5c:00:10), Dst: cc:00:0d:5c:00:10 (cc:00:0d:5c:00:10) - * Destination: cc:00:0d:5c:00:10 (cc:00:0d:5c:00:10) - * Source: cc:01:0d:5c:00:10 (cc:01:0d:5c:00:10) - * Type: MPLS label switched packet (0x8847) - * MultiProtocol Label Switching Header, Label: 19, Exp: 0, S: 0, TTL: 254 - * 0000 0000 0000 0001 0011 .... .... .... = MPLS Label: 19 (0x00013) - * .... .... .... .... .... 000. .... .... = MPLS Experimental Bits: 0 - * .... .... .... .... .... ...0 .... .... = MPLS Bottom Of Label Stack: 0 - * .... .... .... .... .... .... 1111 1110 = MPLS TTL: 254 - * MultiProtocol Label Switching Header, Label: 16, Exp: 0, S: 1, TTL: 255 - * 0000 0000 0000 0001 0000 .... .... .... = MPLS Label: 16 (0x00010) - * .... .... .... .... .... 000. .... .... = MPLS Experimental Bits: 0 - * .... .... .... .... .... ...1 .... .... = MPLS Bottom Of Label Stack: 1 - * .... .... .... .... .... .... 1111 1111 = MPLS TTL: 255 - * PW Ethernet Control Word - * Sequence Number: 0 - * Ethernet II, Src: Private_66:68:00 (00:50:79:66:68:00), Dst: Broadcast (ff:ff:ff:ff:ff:ff) - * Destination: Broadcast (ff:ff:ff:ff:ff:ff) - * Source: Private_66:68:00 (00:50:79:66:68:00) - * Type: ARP (0x0806) - * Trailer: 00000000000000000000000000000000000000000000 - * Address Resolution Protocol (request) - */ - -unsigned char data12[] = { - 0xcc, 0x00, 0x0d, 0x5c, 0x00, 0x10, 0xcc, 0x01, 0x0d, 0x5c, 0x00, 0x10, 0x88, 0x47, 0x00, 0x01, 0x30, 0xfe, 0x00, 0x01, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x50, 0x79, 0x66, 0x68, 0x00, 0x08, 0x06, 0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0x50, 0x79, 0x66, - 0x68, 0x00, 0xc0, 0xa8, 0x00, 0x0a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xa8, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - -TEST(RAW_PACKET, ETH_MPLS_MPLS_PWETHCW_ETH_ARP) -{ - char *header = NULL; - int header_len = 0; - int is_ipv4 = 0; - struct packet pkt; - - packet_parse(&pkt, (const char *)data12, sizeof(data12)); - raw_traffic_decapsulate(&pkt, (const char *)data12, sizeof(data12), &header, &header_len, &is_ipv4); - EXPECT_TRUE(header == nullptr); - EXPECT_TRUE(header_len == 0); -} - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} \ No newline at end of file