Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b30b6d6a2 | ||
|
|
e1bf15c222 | ||
|
|
e683d478a8 | ||
|
|
7a0b7d2316 | ||
|
|
004a1d3b00 | ||
|
|
86ccc7b43a | ||
|
|
3cdcf375e9 | ||
|
|
ab48f907bf | ||
|
|
7bea6fa98e | ||
|
|
d722113df2 | ||
|
|
caf7e5a32d | ||
|
|
bde81dcec6 | ||
|
|
ff7877d432 | ||
|
|
108c79ff68 | ||
|
|
0307f185fd | ||
|
|
637887fddb | ||
|
|
eee615c453 | ||
|
|
ed151c0c0e | ||
|
|
0fb6a5c61d | ||
|
|
b99651da62 | ||
|
|
5bcadbe078 | ||
|
|
daef36bc33 | ||
|
|
9c1e57d6f8 |
@@ -7,6 +7,22 @@ variables:
|
||||
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
|
||||
google_test:
|
||||
stage: test
|
||||
script:
|
||||
- cp -r test/sample_pcap /tmp
|
||||
- ulimit -c 0
|
||||
- cp /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer /tmp/
|
||||
- mkdir -p /opt/MESA/lib
|
||||
- cp /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so /opt/MESA/lib/
|
||||
- echo "/opt/MESA/lib" >> /etc/ld.so.conf
|
||||
- ldconfig
|
||||
- cd /tmp
|
||||
- ./gtest_jump_layer
|
||||
tags:
|
||||
- share
|
||||
|
||||
.build_by_travis:
|
||||
before_script:
|
||||
@@ -26,6 +42,10 @@ branch_build_debug:
|
||||
extends: .build_by_travis
|
||||
variables:
|
||||
BUILD_TYPE: Debug
|
||||
artifacts:
|
||||
paths:
|
||||
- /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer
|
||||
- /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so
|
||||
except:
|
||||
- /^develop.*$/i
|
||||
- /^master.*$/i
|
||||
@@ -36,6 +56,10 @@ branch_build_release:
|
||||
variables:
|
||||
BUILD_TYPE: RelWithDebInfo
|
||||
extends: .build_by_travis
|
||||
artifacts:
|
||||
paths:
|
||||
- /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer
|
||||
- /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so
|
||||
except:
|
||||
- /^develop.*$/i
|
||||
- /^master.*$/i
|
||||
@@ -53,8 +77,10 @@ develop_build_debug:
|
||||
PULP3_REPO_NAME: framework-testing-x86_64.el7
|
||||
PULP3_DIST_NAME: framework-testing-x86_64.el7
|
||||
artifacts:
|
||||
name: MESA_jump_layer-$CI_COMMIT_REF_NAME-debug"
|
||||
name: libMESA_jump_layer-$CI_COMMIT_REF_NAME-debug"
|
||||
paths:
|
||||
- /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer
|
||||
- /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so
|
||||
- build/*.rpm
|
||||
only:
|
||||
- /^develop.*$/i
|
||||
@@ -72,9 +98,11 @@ develop_build_release:
|
||||
PULP3_REPO_NAME: framework-testing-x86_64.el7
|
||||
PULP3_DIST_NAME: framework-testing-x86_64.el7
|
||||
artifacts:
|
||||
name: MESA_jump_layer-$CI_COMMIT_REF_NAME-release"
|
||||
name: libMESA_jump_layer-$CI_COMMIT_REF_NAME-release"
|
||||
paths:
|
||||
- build/*.rpm
|
||||
- /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer
|
||||
- /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so
|
||||
only:
|
||||
- /^develop.*$/i
|
||||
- /^master.*$/i
|
||||
@@ -89,9 +117,11 @@ release_build_debug:
|
||||
PULP3_DIST_NAME: framework-stable-x86_64.el7
|
||||
extends: .build_by_travis
|
||||
artifacts:
|
||||
name: MESA_jump_layer-$CI_COMMIT_REF_NAME-release"
|
||||
name: libMESA_jump_layer-$CI_COMMIT_REF_NAME-release"
|
||||
paths:
|
||||
- build/*.rpm
|
||||
- /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer
|
||||
- /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so
|
||||
only:
|
||||
- tags
|
||||
|
||||
@@ -107,8 +137,10 @@ release_build_release:
|
||||
PULP3_DIST_NAME: framework-stable-x86_64.el7
|
||||
extends: .build_by_travis
|
||||
artifacts:
|
||||
name: MESA_jump_layer-$CI_COMMIT_REF_NAME-release"
|
||||
name: libMESA_jump_layer-$CI_COMMIT_REF_NAME-release"
|
||||
paths:
|
||||
- build/*.rpm
|
||||
- /builds/MESA_framework/mesa_jump_layer/build/test/gtest_jump_layer
|
||||
- /builds/MESA_framework/mesa_jump_layer/build/src/libMESA_jump_layer.so
|
||||
only:
|
||||
- tags
|
||||
|
||||
@@ -34,23 +34,10 @@ elseif(ASAN_OPTION MATCHES "THREAD")
|
||||
endif()
|
||||
# end of for ASAN
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include/)
|
||||
add_subdirectory(./vendor)
|
||||
add_subdirectory(./src)
|
||||
add_subdirectory(./test)
|
||||
|
||||
file(GLOB SRC
|
||||
"src/*.c"
|
||||
"src/*.cpp"
|
||||
)
|
||||
|
||||
# Shared Library Output
|
||||
add_library(${lib_name}_shared SHARED ${SRC})
|
||||
target_link_libraries(${lib_name}_shared m)
|
||||
if(DEFINED MESA_SHARED_INSTALL_DIR)
|
||||
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name} LIBRARY_OUTPUT_DIRECTORY ${MESA_SHARED_INSTALL_DIR})
|
||||
else()
|
||||
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name})
|
||||
endif()
|
||||
|
||||
install(TARGETS ${lib_name}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARY)
|
||||
install(FILES inc/MESA_jump_layer.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT HEADER)
|
||||
|
||||
include(Package)
|
||||
|
||||
@@ -26,24 +26,28 @@ set(CPACK_RPM_COMPONENT_INSTALL ON)
|
||||
set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
|
||||
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
|
||||
set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "develop")
|
||||
set(CPACK_COMPONENT_LIBRARY_REQUIRED TRUE)
|
||||
|
||||
set(CPACK_COMPONENT_LIBRARIES_REQUIRED TRUE)
|
||||
set(CPACK_RPM_LIBRARIES_PACKAGE_NAME ${MY_RPM_NAME_PREFIX})
|
||||
set(CPACK_RPM_LIBRARIES_FILE_NAME "${CPACK_RPM_LIBRARIES_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
||||
set(CPACK_RPM_LIBRARIES_DEBUGINFO_FILE_NAME "${CPACK_RPM_LIBRARIES_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
||||
|
||||
set(CPACK_COMPONENT_PROFILE_GROUP "libraries")
|
||||
set(CPACK_COMPONENT_LIBRARIES_GROUP "libraries")
|
||||
|
||||
set(CPACK_COMPONENT_HEADER_REQUIRED TRUE)
|
||||
set(CPACK_RPM_HEADER_PACKAGE_NAME "${MY_RPM_NAME_PREFIX}-devel")
|
||||
set(CPACK_RPM_LIBRARY_PACKAGE_NAME ${MY_RPM_NAME_PREFIX})
|
||||
|
||||
set(CPACK_RPM_FILE_NAME "${CPACK_RPM_LIBRARY_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
||||
set(CPACK_RPM_LIBRARY_DEBUGINFO_FILE_NAME "${CPACK_RPM_LIBRARY_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
||||
set(CPACK_COMPONENT_LIBRARY_GROUP "library")
|
||||
|
||||
set(CPACK_RPM_HEADER_FILE_NAME "${CPACK_RPM_HEADER_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
||||
set(CPACK_RPM_HEADER_DEBUGINFO_FILE_NAME "${CPACK_RPM_HEADER_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
|
||||
set(CPACK_COMPONENT_HEADER_GROUP "header")
|
||||
|
||||
set(CPACK_RPM_HEADER_PACKAGE_REQUIRES_PRE ${CPACK_RPM_LIBRARY_PACKAGE_NAME})
|
||||
set(CPACK_RPM_HEADER_PACKAGE_REQUIRES_PRE ${CPACK_RPM_LIBRARIES_PACKAGE_NAME})
|
||||
set(CPACK_RPM_HEADER_PACKAGE_CONFLICTS ${CPACK_RPM_HEADER_PACKAGE_NAME})
|
||||
|
||||
set(CPACK_COMPONENTS_ALL LIBRARY HEADER)
|
||||
set(CPACK_COMPONENTS_ALL HEADER PROFILE LIBRARIES)
|
||||
|
||||
set(CPACK_RPM_PACKAGE_AUTOREQPROV "no")
|
||||
set(CPACK_RPM_PACKAGE_AUTOREQ "no")
|
||||
|
||||
set(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR}")
|
||||
|
||||
|
||||
@@ -13,18 +13,45 @@ extern "C" {
|
||||
|
||||
const char *MESA_jump_layer_get_last_error(void);
|
||||
|
||||
|
||||
/*
|
||||
The raw_layer_type and expect_layer_type refer to sapp_base.h->enum addr_type_t
|
||||
CHN : <20><><EFBFBD>ݰ<EFBFBD>ͷ<EFBFBD><CDB7>ƫ<EFBFBD>ƺ<EFBFBD><C6BA><EFBFBD>.
|
||||
|
||||
<09><><EFBFBD><EFBFBD>:
|
||||
raw_data: <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ָ<EFBFBD><D6B8>;
|
||||
raw_layer_type: <20><>ǰ<EFBFBD><C7B0><EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>: enum addr_type_t ;
|
||||
expect_layer_type: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>: enum addr_type_t ;
|
||||
|
||||
<09><><EFBFBD><EFBFBD>ֵ:
|
||||
NULL: <20>˵<DEB4>ַ;
|
||||
NON-NULL: <20><>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ַ.
|
||||
|
||||
<09><><EFBFBD><EFBFBD>:
|
||||
<09><><EFBFBD>赱ǰ<E8B5B1><C7B0>ΪEthernet, <20><>ʼ<EFBFBD><CABC>ͷ<EFBFBD><CDB7>ַΪthis_layer_hdr, <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>IPv6<76><36>ͷ<EFBFBD><CDB7>:
|
||||
struct ip6_hdr *ip6_header;
|
||||
ip6_header = MESA_net_jump_to_layer(this_layer_hdr, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
|
||||
*/
|
||||
const void *MESA_jump_layer(const void *raw_data, int raw_layer_type, int expect_layer_type);
|
||||
|
||||
/*
|
||||
MESA_jump_layer_greedy<64><79>MESA_jump_layer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><C7B6>Э<EFBFBD><D0AD><EFBFBD><EFBFBD>˵,
|
||||
MESA_jump_layer<65><72>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>expect_layer_type;
|
||||
MESA_jump_layer_greedy<64><79>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>expect_layer_type;
|
||||
*/
|
||||
const void *MESA_jump_layer_greedy(const void *raw_data, int raw_layer_type, int expect_layer_type);
|
||||
|
||||
|
||||
const char *MESA_jump_layer_ipv4_ntop(const struct ip *ip4_hdr, char *out_buf, int buf_len );
|
||||
|
||||
/* <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>Ľӿ<C4BD><D3BF><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC> */
|
||||
const void *MESA_net_jump_to_layer(const void *raw_data, int raw_layer_type, int expect_layer_type);
|
||||
const void *MESA_net_jump_to_layer_greedy(const void *raw_data, int raw_layer_type, int expect_layer_type);
|
||||
|
||||
|
||||
|
||||
const char *MESA_jump_layer_ipv4_ntop(const struct ip *ip4_hdr, char *out_buf, int buf_len );
|
||||
const char *MESA_jump_layer_ipv6_ntop(const struct ip6_hdr *ip6_hdr, char *out_buf, int buf_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
36
src/CMakeLists.txt
Normal file
36
src/CMakeLists.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(MESA_SDK_PREFIX "/opt/MESA" CACHE STRING "MESA Framework Prefix")
|
||||
|
||||
include_directories(${MESA_SDK_PREFIX}/include)
|
||||
include_directories(${MESA_SDK_PREFIX}/include/MESA)
|
||||
include_directories(${MESA_SDK_PREFIX}/include/MESA/include)
|
||||
include_directories(${MESA_SDK_PREFIX}/include/MESA/stream_inc)
|
||||
|
||||
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(-DSAPP_V4=1)
|
||||
|
||||
add_definitions(-fPIC)
|
||||
add_definitions(-std=c++11)
|
||||
|
||||
set(SRC MESA_jump_layer.cpp)
|
||||
|
||||
# Shared Library Output
|
||||
add_library(${lib_name}_shared SHARED ${SRC})
|
||||
target_link_libraries(${lib_name}_shared m)
|
||||
if(DEFINED MESA_SHARED_INSTALL_DIR)
|
||||
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name} LIBRARY_OUTPUT_DIRECTORY ${MESA_SHARED_INSTALL_DIR})
|
||||
else()
|
||||
set_target_properties(${lib_name}_shared PROPERTIES OUTPUT_NAME ${lib_name})
|
||||
endif()
|
||||
|
||||
target_link_libraries(${lib_name}_shared m)
|
||||
|
||||
install(TARGETS ${lib_name}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES)
|
||||
#install(FILES ${CMAKE_BINARY_DIR}/src/libMESA_jump_layer.so DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES)
|
||||
|
||||
include(Package)
|
||||
@@ -290,6 +290,10 @@ static int gtp_jump_to_layer(const char *raw_data, int raw_layer_type, int expe
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(skip_len < 0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return gtp_hdr_len + skip_len;
|
||||
}
|
||||
|
||||
@@ -425,6 +429,10 @@ static int l2tp_jump_to_layer(const char *raw_data, int raw_layer_type, int exp
|
||||
skip_len = ipv6_jump_to_layer((char *)next_layer_hdr, __ADDR_TYPE_IP_PAIR_V6, expect_layer_type);
|
||||
}
|
||||
}
|
||||
|
||||
if(skip_len < 0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return l2tp_hdr_len + skip_len;
|
||||
}
|
||||
@@ -1020,6 +1028,10 @@ static int mpls_jump_to_layer(const char *raw_data, int raw_layer_type, int exp
|
||||
}
|
||||
}
|
||||
|
||||
if(skip_len < 0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return skip_len + mpls_layer_len;
|
||||
}
|
||||
|
||||
@@ -1175,6 +1187,7 @@ static int vlan8021q_jump_to_layer(const char *raw_data, int raw_layer_type, in
|
||||
/* QinQ */
|
||||
case ETH_P_8021Q:
|
||||
snprintf(_g_mesa_jump_layer_last_error, PIPE_BUF, "vlan8021q_jump_to_layer(): multiple VLAN combine to one layer!");
|
||||
skip_len = -1;
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
@@ -1332,6 +1345,11 @@ const void *MESA_jump_layer(const void *raw_data, int raw_layer_type, int expec
|
||||
return ((const char *)raw_data + ret);
|
||||
}
|
||||
|
||||
const void *MESA_net_jump_to_layer(const void *raw_data, int raw_layer_type, int expect_layer_type)
|
||||
{
|
||||
return MESA_jump_layer(raw_data, raw_layer_type, expect_layer_type);
|
||||
}
|
||||
|
||||
/*
|
||||
<09><>MESA_jump_layer()<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
|
||||
MESA_jump_layer()<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㿪ʼ, <20>ҵ<EFBFBD><D2B5><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD>˳<EFBFBD>;
|
||||
@@ -1425,6 +1443,11 @@ done:
|
||||
return success_layer;
|
||||
}
|
||||
|
||||
const void *MESA_net_jump_to_layer_greedy(const void *raw_data, int raw_layer_type, int expect_layer_type)
|
||||
{
|
||||
return MESA_jump_layer_greedy(raw_data, raw_layer_type, expect_layer_type);
|
||||
}
|
||||
|
||||
/* ģ<><C4A3>tcpdump<6D><70>ʽ: 192.168.40.137.22 > 192.168.36.40.49429 */
|
||||
const char *MESA_jump_layer_ipv4_ntop(const struct ip *ip4_hdr, char *out_buf, int buf_len )
|
||||
{
|
||||
|
||||
16
test/CMakeLists.txt
Normal file
16
test/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/inc)
|
||||
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(-fPIC -std=c++11)
|
||||
LINK_DIRECTORIES(/opt/MESA/lib)
|
||||
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src)
|
||||
|
||||
add_executable(gtest_jump_layer gtest_jump_layer.cpp)
|
||||
target_link_libraries(gtest_jump_layer pcap gtest-static MESA_jump_layer)
|
||||
|
||||
|
||||
@@ -1,2 +1,9 @@
|
||||
all: test_jump_layer gtest_jump_layer
|
||||
|
||||
CFLAGS = -g -Wall -fPIC -std=c++11 -DSAPP_V4=1 -D_XOPEN_SOURCE
|
||||
|
||||
test_jump_layer:test_jump_layer.c
|
||||
gcc -g -o $@ test_jump_layer.c -D_GNU_SOURCE -L/opt/MESA/lib -lMESA_jump_layer -I ../inc -I/opt/MESA/include/MESA -l pcap
|
||||
|
||||
gtest_jump_layer:gtest_jump_layer.cpp
|
||||
g++ -g -o $@ $^ $(CFLAGS) -D_GNU_SOURCE -L/opt/MESA/lib -lMESA_jump_layer -I ../inc -I/opt/MESA/include/MESA -lpcap -lgtest -lpthread
|
||||
|
||||
1404
test/gtest_jump_layer.cpp
Normal file
1404
test/gtest_jump_layer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
BIN
test/sample_pcap/eth_vlan_ip6_udp_gtpext_ip4_tcp.pcap
Normal file
BIN
test/sample_pcap/eth_vlan_ip6_udp_gtpext_ip4_tcp.pcap
Normal file
Binary file not shown.
BIN
test/sample_pcap/tcp_simple.pcap
Normal file
BIN
test/sample_pcap/tcp_simple.pcap
Normal file
Binary file not shown.
BIN
test/sample_pcap/udp_simple.pcap
Normal file
BIN
test/sample_pcap/udp_simple.pcap
Normal file
Binary file not shown.
BIN
test/sample_pcap/vxlan_inner_3_vlan_udp.pcap
Normal file
BIN
test/sample_pcap/vxlan_inner_3_vlan_udp.pcap
Normal file
Binary file not shown.
@@ -11,6 +11,9 @@ static char *g_input_pcap_name;
|
||||
static char *g_input_bpf_string;
|
||||
static struct bpf_program g_bpf_filter;
|
||||
|
||||
static int g_raw_input_layer_type = (int )ADDR_TYPE_MAC;
|
||||
static int g_expect_layer_type = (int )ADDR_TYPE_IPV4;
|
||||
|
||||
static void usage(const char *prog)
|
||||
{
|
||||
printf("Usage:\n");
|
||||
@@ -59,39 +62,109 @@ static int pcap_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _pcap_pkt_handle(u_char *user, const struct pcap_pkthdr *hdr, const u_char *data)
|
||||
static void _jump_from_udp(const void *uhdr)
|
||||
{
|
||||
const void *next_hdr;
|
||||
|
||||
next_hdr = MESA_jump_layer(uhdr, ADDR_TYPE_UDP, ADDR_TYPE_GPRS_TUNNEL);
|
||||
if(next_hdr){
|
||||
printf("bingo! jump to gtp from udp succ!\n");
|
||||
}
|
||||
|
||||
next_hdr = MESA_jump_layer(uhdr, ADDR_TYPE_UDP, ADDR_TYPE_L2TP);
|
||||
if(next_hdr){
|
||||
printf("bingo! jump to l2tp from udp succ!\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void _jump_from_ipv4(const void *ip4_hdr)
|
||||
{
|
||||
const void *next_hdr;
|
||||
|
||||
next_hdr = MESA_jump_layer(ip4_hdr, ADDR_TYPE_IPV4, ADDR_TYPE_TCP);
|
||||
if(next_hdr){
|
||||
printf("bingo! jump to tcp from ipv4 succ!\n");
|
||||
}
|
||||
|
||||
next_hdr = MESA_jump_layer(ip4_hdr, ADDR_TYPE_IPV4, ADDR_TYPE_UDP);
|
||||
if(next_hdr){
|
||||
printf("bingo! jump to udp from ipv4 succ!\n");
|
||||
_jump_from_udp(next_hdr);
|
||||
}
|
||||
}
|
||||
|
||||
static void _jump_from_ipv6(const void *ip4_hdr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void _jump_from_ethernet(const void *ehdr)
|
||||
{
|
||||
const void *next_hdr;
|
||||
|
||||
next_hdr = MESA_jump_layer(ehdr, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
||||
if(next_hdr){
|
||||
printf("bingo! jump to ipv4 from ethernet succ!\n");
|
||||
_jump_from_ipv4(next_hdr);
|
||||
}
|
||||
|
||||
next_hdr = MESA_jump_layer(ehdr, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
|
||||
if(next_hdr){
|
||||
printf("bingo! jump to ipv6 from ethernet succ!\n");
|
||||
_jump_from_ipv6(next_hdr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void _jump_greedy(const struct pcap_pkthdr *hdr, const u_char *data)
|
||||
{
|
||||
const void *ip4_hdr, *ip6_h;
|
||||
|
||||
char print_buf[128];
|
||||
int offset_to_eth;
|
||||
static int pkt_index = 0;
|
||||
|
||||
ip4_hdr = MESA_jump_layer_greedy(data, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
||||
ip6_h = MESA_jump_layer_greedy(data, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
|
||||
|
||||
|
||||
printf("-----------------------------packet index:%d------------------------------------------\n", pkt_index++);
|
||||
if(ip4_hdr){
|
||||
offset_to_eth = (u_char *)ip4_hdr-data;
|
||||
if(g_input_bpf_string
|
||||
&& (0 == bpf_filter(g_bpf_filter.bf_insns, (const unsigned char *)ip4_hdr, hdr->caplen-offset_to_eth, hdr->caplen-offset_to_eth))){
|
||||
goto done;
|
||||
printf("-----------------------------packet index:%d------------------------------------------\n", pkt_index++);
|
||||
if(ip4_hdr){
|
||||
offset_to_eth = (u_char *)ip4_hdr-data;
|
||||
if(g_input_bpf_string
|
||||
&& (0 == bpf_filter(g_bpf_filter.bf_insns, (const unsigned char *)ip4_hdr, hdr->caplen-offset_to_eth, hdr->caplen-offset_to_eth))){
|
||||
goto done;
|
||||
}
|
||||
printf("Innermost layer ipv4 offset:%d, addr: %s\n", offset_to_eth, MESA_jump_layer_ipv4_ntop((struct ip *)ip4_hdr, print_buf, sizeof(print_buf)));
|
||||
}
|
||||
printf("Innermost layer ipv4 offset:%d, addr: %s\n", offset_to_eth, MESA_jump_layer_ipv4_ntop((struct ip *)ip4_hdr, print_buf, sizeof(print_buf)));
|
||||
}
|
||||
|
||||
if(ip6_h){
|
||||
offset_to_eth = (u_char *)ip6_h-data;
|
||||
if(g_input_bpf_string
|
||||
&& (0 == bpf_filter(g_bpf_filter.bf_insns, (const unsigned char *)ip6_h, hdr->caplen-offset_to_eth, hdr->caplen-offset_to_eth))){
|
||||
goto done;
|
||||
|
||||
if(ip6_h){
|
||||
offset_to_eth = (u_char *)ip6_h-data;
|
||||
if(g_input_bpf_string
|
||||
&& (0 == bpf_filter(g_bpf_filter.bf_insns, (const unsigned char *)ip6_h, hdr->caplen-offset_to_eth, hdr->caplen-offset_to_eth))){
|
||||
goto done;
|
||||
}
|
||||
|
||||
printf("Innermost layer ipv6 offset:%d, addr: %s\n", offset_to_eth, MESA_jump_layer_ipv6_ntop((struct ip6_hdr *)ip6_h, print_buf, sizeof(print_buf)));
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
printf("--------------------------------------------------------------------------------------\n\n");
|
||||
|
||||
printf("Innermost layer ipv6 offset:%d, addr: %s\n", offset_to_eth, MESA_jump_layer_ipv6_ntop((struct ip6_hdr *)ip6_h, print_buf, sizeof(print_buf)));
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
static void _pcap_pkt_handle(u_char *user, const struct pcap_pkthdr *hdr, const u_char *data)
|
||||
{
|
||||
|
||||
_jump_from_ethernet(data);
|
||||
|
||||
_jump_greedy(hdr, data);
|
||||
|
||||
printf("--------------------------------------------------------------------------------------\n\n");
|
||||
}
|
||||
|
||||
static void pcap_run(void)
|
||||
|
||||
21
vendor/CMakeLists.txt
vendored
Normal file
21
vendor/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# CMakeFiles for 3rd vendor library
|
||||
|
||||
include(ExternalProject)
|
||||
# libgtest
|
||||
ExternalProject_Add(libgtest PREFIX libgtest
|
||||
URL ${CMAKE_SOURCE_DIR}/vendor/googletest-release-1.10.0.tar.gz
|
||||
URL_MD5 ecd1fa65e7de707cd5c00bdac56022cd
|
||||
#CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=RELWITHDEBINFO)
|
||||
ExternalProject_Get_Property(libgtest INSTALL_DIR)
|
||||
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
|
||||
add_library(gtest-static STATIC IMPORTED GLOBAL)
|
||||
add_dependencies(gtest-static libgtest)
|
||||
set_property(TARGET gtest-static PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib64/libgtest.a)
|
||||
set_property(TARGET gtest-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)
|
||||
set_property(TARGET gtest-static PROPERTY INTERFACE_LINK_LIBRARIES pthread)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
vendor/googletest-release-1.10.0.tar.gz
vendored
Normal file
BIN
vendor/googletest-release-1.10.0.tar.gz
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user