diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bc95cf1..a0d219b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,7 +11,8 @@ include_directories(${PROJECT_SOURCE_DIR}/include/) LINK_DIRECTORIES(/opt/MESA/lib) -add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) +#add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) +add_definitions(-D_DEFAULT_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) add_definitions(-DSAPP_V4=1) add_definitions(-fPIC) diff --git a/src/MESA_jump_layer.cpp b/src/MESA_jump_layer.cpp index c24a4f0..958ec20 100644 --- a/src/MESA_jump_layer.cpp +++ b/src/MESA_jump_layer.cpp @@ -290,9 +290,9 @@ static int gtp_jump_to_layer(const char *raw_data, int raw_layer_type, int expe next_ip_layer_hdr = (unsigned char *)raw_data + gtp_hdr_len; - if((*next_ip_layer_hdr & 0x40) == 0x40){ + if((*next_ip_layer_hdr & 0xF0) == 0x40){ skip_len = ipv4_jump_to_layer((char *)next_ip_layer_hdr, __ADDR_TYPE_IP_PAIR_V4, expect_layer_type); - }else if((*next_ip_layer_hdr & 0x60) == 0x60){ + }else if((*next_ip_layer_hdr & 0xF0) == 0x60){ skip_len = ipv6_jump_to_layer((char *)next_ip_layer_hdr, __ADDR_TYPE_IP_PAIR_V6, expect_layer_type); }else{ snprintf(_g_mesa_jump_layer_last_error, PIPE_BUF, "gtp_jump_to_layer() error, unsupport type in GTP, 0x%x!", (*next_ip_layer_hdr)); @@ -1427,8 +1427,23 @@ const void *MESA_jump_layer_greedy(const void *raw_data, int raw_layer_type, int case __ADDR_TYPE_IP_PAIR_V6: { - //TODO2, - goto done; + const struct mesa_ip6_hdr *ip6hdr = (const struct mesa_ip6_hdr *)expect_layer; + if(IPPROTO_UDP == ip6hdr->ip6_nxt_hdr){ + new_next_layer_data = (char *)expect_layer + sizeof(struct mesa_ip6_hdr); + new_raw_layer_type = ADDR_TYPE_UDP; /* IP²ã¼ÌÐøÏòÏÂÒ»²ãÆ«ÒÆ */ + }else if(IPPROTO_GRE == ip6hdr->ip6_nxt_hdr){ + new_next_layer_data = (char *)expect_layer + sizeof(struct mesa_ip6_hdr); + new_raw_layer_type = ADDR_TYPE_GRE; /* GRE */ + }else if(IPPROTO_IPIP == ip6hdr->ip6_nxt_hdr){ + new_next_layer_data = (char *)expect_layer + sizeof(struct mesa_ip6_hdr); + new_raw_layer_type = ADDR_TYPE_IPV4; + }else if(IPPROTO_IPIP == ip6hdr->ip6_nxt_hdr){ + new_next_layer_data = (char *)expect_layer + sizeof(struct mesa_ip6_hdr); + new_raw_layer_type = ADDR_TYPE_IPV6; + }else{ + //TODO 2, IPIP, L2TPv3 + goto done; + } } break; @@ -1476,7 +1491,7 @@ const char *MESA_jump_layer_ipv4_ntop(const struct ip *ip4_hdr, char *out_buf, i inner_thdr = (struct mesa_tcp_hdr *)((char *)ip4_hdr + ip4_hdr->ip_hl*4); sport = ntohs(inner_thdr->th_sport); dport = ntohs(inner_thdr->th_dport); - }else if(IPPROTO_UDP){ + }else if(IPPROTO_UDP == inner_ip_proto){ inner_uhdr = (struct mesa_udp_hdr *)((char *)ip4_hdr + ip4_hdr->ip_hl*4); sport = ntohs(inner_uhdr->uh_sport); dport = ntohs(inner_uhdr->uh_dport); @@ -1509,7 +1524,7 @@ const char *MESA_jump_layer_ipv6_ntop(const struct ip6_hdr *ip6_hdr, char *out_b inner_thdr = (struct tcphdr *)((char *)ip6_hdr + sizeof(struct ip6_hdr)); sport = inner_thdr->source; dport = inner_thdr->dest; - }else if(IPPROTO_UDP){ + }else if(IPPROTO_UDP== inner_ip_proto){ inner_uhdr = (struct udphdr *)((char *)ip6_hdr + sizeof(struct ip6_hdr)); sport = inner_uhdr->source; dport = inner_uhdr->dest; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ec4336b..2473ffc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,7 +5,8 @@ include_directories(${MESA_SDK_PREFIX}/include) include_directories(${MESA_SDK_PREFIX}/include/MESA) -add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) +# add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) +add_definitions(-D_DEFAULT_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H) add_definitions(-fPIC -std=c++11) LINK_DIRECTORIES(/opt/MESA/lib) LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src) diff --git a/test/gtest_jump_layer.cpp b/test/gtest_jump_layer.cpp index bf9103f..51edd4b 100644 --- a/test/gtest_jump_layer.cpp +++ b/test/gtest_jump_layer.cpp @@ -143,7 +143,7 @@ static int jump_check_udp_pkt(const struct udphdr *uhdr, unsigned short expect_u return 0; } -static int jump_check_vlan_pkt(const void *vlan_hdr, unsigned int expect_vlan_hex_data) +int jump_check_vlan_pkt(const void *vlan_hdr, unsigned int expect_vlan_hex_data) { if(memcmp(vlan_hdr, &expect_vlan_hex_data, sizeof(int)) != 0){ printf("\033[1;31;40mMESA_net_jump_to_layer(): vlan header error!\033[0m\n");