修复编译错误, 增加test stage.
This commit is contained in:
@@ -13,13 +13,13 @@ stages:
|
||||
google_test:
|
||||
stage: test
|
||||
script:
|
||||
- yum makecache
|
||||
- pwd
|
||||
- ls -l /opt/MESA/lib
|
||||
- echo "/opt/MESA/lib" >> /etc/ld.so.conf
|
||||
- ldconfig
|
||||
- cd /home/mesasoft/sapp_run
|
||||
- cp -r test/sample_pcap /tmp
|
||||
- cp test/gtest_jump_layer /tmp
|
||||
- ulimit -c 0
|
||||
- cd /tmp
|
||||
- ./gtest_jump_layer
|
||||
tags:
|
||||
- share
|
||||
|
||||
@@ -38,7 +38,8 @@ add_subdirectory(./vendor)
|
||||
add_subdirectory(./src)
|
||||
add_subdirectory(./test)
|
||||
|
||||
install(TARGETS ${lib_name} LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARY)
|
||||
#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)
|
||||
|
||||
@@ -21,3 +21,5 @@ add_library(${lib_name} SHARED MESA_jump_layer.cpp)
|
||||
target_link_libraries(${lib_name} m)
|
||||
|
||||
|
||||
install(FILES ${CMAKE_BINARY_DIR}/src/libMESA_jump_layer.so DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARY)
|
||||
|
||||
|
||||
@@ -215,6 +215,7 @@ static void jump_layer_eth_ipv4_tcp(u_char *result_val, const struct pcap_pkthdr
|
||||
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4 error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
const struct ip* ip4hdr = (struct ip*)ipv4_header;
|
||||
@@ -225,6 +226,7 @@ static void jump_layer_eth_ipv4_tcp(u_char *result_val, const struct pcap_pkthdr
|
||||
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4->tcp error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
tcp_header = MESA_net_jump_to_layer(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_TCP);
|
||||
@@ -232,6 +234,7 @@ static void jump_layer_eth_ipv4_tcp(u_char *result_val, const struct pcap_pkthdr
|
||||
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->tcp error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
tcp_header = MESA_net_jump_to_layer(ipv4_header, __ADDR_TYPE_IP_PAIR_V4, ADDR_TYPE_TCP);
|
||||
@@ -239,6 +242,7 @@ static void jump_layer_eth_ipv4_tcp(u_char *result_val, const struct pcap_pkthdr
|
||||
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4->tcp error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
const struct tcphdr* thdr = (struct tcphdr *)tcp_header;
|
||||
@@ -251,6 +255,7 @@ static void jump_layer_eth_ipv4_tcp(u_char *result_val, const struct pcap_pkthdr
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
}
|
||||
|
||||
#define __jump_layer_eth_ipv4_tcp 1
|
||||
TEST(jump_layer, eth_ipv4_tcp)
|
||||
{
|
||||
int fun_ret;
|
||||
@@ -265,69 +270,80 @@ TEST(jump_layer, eth_ipv4_tcp)
|
||||
ASSERT_EQ(chk_res, 0);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
extern "C" char jump_layer_eth_ipv4_udp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
|
||||
|
||||
|
||||
static void jump_layer_eth_ipv4_udp(u_char *result_val, const struct pcap_pkthdr *hdr, const u_char *data)
|
||||
{
|
||||
int ret;
|
||||
int tot_pkt_len;
|
||||
const void *pkt_header;
|
||||
const void *eth_header = data, *ipv4_header, *udp_header;
|
||||
const void *next_header;
|
||||
|
||||
ipv4_header = MESA_net_jump_to_layer(data, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
||||
if(NULL == ipv4_header){
|
||||
printf("\033[1;31;40mjump_layer_eth_ipv4_udp(): eth->ipv4 error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
udp_header = MESA_net_jump_to_layer((void *)ipv4_header, ADDR_TYPE_IPV4, ADDR_TYPE_UDP);
|
||||
if(NULL == udp_header){
|
||||
printf("\033[1;31;40mjump_layer_eth_ipv4_udp(): ipv4->udp error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
udp_header = MESA_net_jump_to_layer((void *)eth_header, ADDR_TYPE_MAC, ADDR_TYPE_UDP);
|
||||
if(NULL == udp_header){
|
||||
printf("\033[1;31;40mjump_layer_eth_ipv4_udp(): ethernet->udp error!\033[0m\n");
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
const struct ip* ip4hdr = (struct ip*)ipv4_header;
|
||||
ret = jump_check_ipv4_pkt(ip4hdr, 175, IPPROTO_UDP, "192.168.210.153", "111.161.107.181");
|
||||
if(ret < 0){
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
if(pstream->opstate == OP_STATE_PENDING){
|
||||
next_header = MESA_net_jump_to_layer((void *)a_packet, ADDR_TYPE_IPV4, ADDR_TYPE_UDP);
|
||||
if(NULL == next_header){
|
||||
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4->udp error!\033[0m\n");
|
||||
sendto_test_result(GTEST_SAPP_ERR);
|
||||
exit(1);
|
||||
}
|
||||
ret = get_rawpkt_opt_from_streaminfo(pstream, RAW_PKT_GET_DATA, &pkt_header);
|
||||
if(ret < 0){
|
||||
printf("\033[1;31;40mjump_layer_eth_ipv4_udp_entry(), get_rawpkt_opt_from_streaminfo()->RAW_PKT_GET_DATA error!\033[0m\n");
|
||||
sendto_test_result(GTEST_SAPP_ERR);
|
||||
exit(1);
|
||||
}
|
||||
ret = get_rawpkt_opt_from_streaminfo(pstream, RAW_PKT_GET_TOT_LEN, &tot_pkt_len);
|
||||
if(ret < 0){
|
||||
printf("\033[1;31;40mjump_layer_eth_ipv4_udp_entry(), get_rawpkt_opt_from_streaminfo()->RAW_PKT_GET_TOT_LEN error!\033[0m\n");
|
||||
sendto_test_result(GTEST_SAPP_ERR);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
next_header = MESA_net_jump_to_layer(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
||||
if(NULL == next_header){
|
||||
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4 error!\033[0m\n");
|
||||
sendto_test_result(GTEST_SAPP_ERR);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(next_header != a_packet){
|
||||
printf("\033[1;31;40mMESA_net_jump_to_layer(): ip header is not equal with plug_entry->a_packet!\033[0m\n");
|
||||
sendto_test_result(GTEST_SAPP_ERR);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const struct ip* ip4hdr = (struct ip*)next_header;
|
||||
|
||||
jump_check_ipv4_pkt(ip4hdr, tot_pkt_len-sizeof(struct ethhdr), IPPROTO_UDP, "192.168.210.153", "111.161.107.181");
|
||||
|
||||
next_header = MESA_net_jump_to_layer((void *)ip4hdr, __ADDR_TYPE_IP_PAIR_V4, ADDR_TYPE_UDP);
|
||||
if(NULL == next_header){
|
||||
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4->udp error!\033[0m\n");
|
||||
sendto_test_result(GTEST_SAPP_ERR);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const struct udphdr* uhdr = (struct udphdr *)next_header;
|
||||
jump_check_udp_pkt(uhdr, 155, 4001, 8000);
|
||||
|
||||
printf("\033[32mjump_layer_eth_ipv4_udp_entry() test succ\033[0m\n");
|
||||
sendto_test_result(GTEST_SAPP_SUCC);
|
||||
const struct udphdr* uhdr = (struct udphdr *)udp_header;
|
||||
ret = jump_check_udp_pkt(uhdr, 155, 4001, 8000);
|
||||
if(ret < 0){
|
||||
*result_val = -1;
|
||||
pcap_breakloop(g_jmp_pcap_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
return APP_STATE_DROPME;
|
||||
printf("\033[32mjump_layer_eth_ipv4_udp() test succ\033[0m\n");
|
||||
*result_val = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#define __jump_layer_eth_ipv4_udp 1
|
||||
TEST(jump_layer, eth_ipv4_udp)
|
||||
{
|
||||
int fun_ret;
|
||||
u_char chk_res = -1;
|
||||
|
||||
fun_ret = jmp_file_md5_checksum("./sample_pcap/udp_simple.pcap", "d218d9a401588f7ba324d8a02c2d8360");
|
||||
ASSERT_EQ(fun_ret, 0);
|
||||
|
||||
fun_ret = jmp_pcap_init("./sample_pcap/udp_simple.pcap", jump_layer_eth_ipv4_udp, (u_char *)&chk_res);
|
||||
ASSERT_EQ(fun_ret, 0);
|
||||
|
||||
ASSERT_EQ(chk_res, 0);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
|
||||
|
||||
extern "C" char jump_layer_eth_ipv6_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
|
||||
{
|
||||
|
||||
BIN
test/sample_pcap/udp_simple.pcap
Normal file
BIN
test/sample_pcap/udp_simple.pcap
Normal file
Binary file not shown.
Reference in New Issue
Block a user