1405 lines
48 KiB
C++
1405 lines
48 KiB
C++
#ifndef __USE_BSD
|
|
#define __USE_BSD
|
|
#endif
|
|
#ifndef __FAVOR_BSD
|
|
#define __FAVOR_BSD
|
|
#endif
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <netinet/ip.h>
|
|
#include <netinet/tcp.h>
|
|
#include <netinet/udp.h>
|
|
#include <assert.h>
|
|
#include <time.h>
|
|
#include <arpa/inet.h>
|
|
#include <sys/types.h> /* See NOTES */
|
|
#include <sys/socket.h>
|
|
#include <sys/un.h>
|
|
#include <errno.h>
|
|
#include <linux/if_tun.h>
|
|
#include <net/if.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <sys/ioctl.h>
|
|
#include <linux/limits.h>
|
|
#include <linux/if_ether.h>
|
|
#include <pthread.h>
|
|
#include "stream.h"
|
|
#include <gtest/gtest.h>
|
|
#include <pcap/pcap.h>
|
|
#include "MESA_jump_layer.h"
|
|
|
|
#define GTEST_SAPP_ERR (-1)
|
|
#define GTEST_SAPP_SUCC 0
|
|
|
|
static pcap_t *g_jmp_pcap_handle;
|
|
|
|
|
|
static int jump_check_ipv4_pkt(const struct ip *ip4hdr, int expect_tot_len, unsigned char expect_protocol, const char *expect_src_addr_str, const char *expect_dst_addr_str)
|
|
{
|
|
unsigned int expect_src_addr_net, expect_dst_addr_net;
|
|
|
|
/* 简单判断一下ipv4头部是否正确 */
|
|
if(ip4hdr->ip_v != 4){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4 header check version error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
if(ip4hdr->ip_p != expect_protocol){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4 header check protocol error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
if(ip4hdr->ip_hl*4 < 20){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4 header check header length error, iphdr less than 20Byte!\033[0m\n");
|
|
return -1;
|
|
}
|
|
if(ntohs(ip4hdr->ip_len) != expect_tot_len){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4 header check length error, ip len is:%d, but expect:%d!\033[0m\n", ntohs(ip4hdr->ip_len), expect_tot_len);
|
|
return -1;
|
|
}
|
|
|
|
inet_pton(AF_INET, expect_src_addr_str, &expect_src_addr_net);
|
|
if(ip4hdr->ip_src.s_addr != expect_src_addr_net){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4 header check src addr error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
inet_pton(AF_INET, expect_dst_addr_str, &expect_dst_addr_net);
|
|
if(ip4hdr->ip_dst.s_addr != expect_dst_addr_net){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv4 header check dst addr error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int jump_check_ipv6_pkt(const struct ip6_hdr *ip6h, int expect_payload_len, unsigned char expect_protocol, const char *expect_src_addr_str, const char *expect_dst_addr_str)
|
|
{
|
|
if((*(char *)ip6h & 0xF0) != 0x60){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv6 header check version error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
if(ip6h->ip6_nxt != expect_protocol){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv6 header check protocol error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
|
|
if(ntohs(ip6h->ip6_plen) != expect_payload_len){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv6 header check length error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
|
|
struct in6_addr tmp_ip6_addr;
|
|
inet_pton(AF_INET6, expect_src_addr_str, &tmp_ip6_addr);
|
|
if(memcmp(&tmp_ip6_addr, &ip6h->ip6_src, sizeof(struct in6_addr) ) != 0){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv6 header check src addr error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
|
|
inet_pton(AF_INET6, expect_dst_addr_str, &tmp_ip6_addr);
|
|
if(memcmp(&tmp_ip6_addr, &ip6h->ip6_dst, sizeof(struct in6_addr) ) != 0){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv6 header check dst addr error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int jump_check_tcp_pkt(const struct tcphdr *thdr, int expect_tcp_hdr_offset, unsigned short expect_sport_host, unsigned short expect_dport_host)
|
|
{
|
|
if(thdr->doff * 4 != expect_tcp_hdr_offset){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): tcp header offset error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
if(ntohs(thdr->source) != expect_sport_host){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): tcp header sport error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
if(ntohs(thdr->dest) != expect_dport_host){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): tcp header dport error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int jump_check_udp_pkt(const struct udphdr *uhdr, unsigned short expect_udp_tot_len, unsigned short expect_sport_host, unsigned short expect_dport_host)
|
|
{
|
|
if(ntohs(uhdr->len) != expect_udp_tot_len){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): udp header length error, actual:%u, but expect:%u!\033[0m\n", ntohs(uhdr->len), expect_udp_tot_len);
|
|
return -1;
|
|
}
|
|
|
|
if(ntohs(uhdr->source) != expect_sport_host){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): udp header sport error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
if(ntohs(uhdr->dest) != expect_dport_host){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): udp header dport error!\033[0m\n");
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static 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");
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
static int jmp_pcap_init(const char *pcap_file, pcap_handler pcap_cb_fun, u_char *result_val)
|
|
{
|
|
char err_string[PCAP_ERRBUF_SIZE];
|
|
|
|
g_jmp_pcap_handle = pcap_open_offline(pcap_file, err_string);
|
|
if(NULL == g_jmp_pcap_handle){
|
|
printf("open file:%s error, %s\n", pcap_file, err_string);
|
|
return -1;
|
|
}
|
|
|
|
pcap_loop(g_jmp_pcap_handle, -1, pcap_cb_fun, (u_char *)result_val);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int jmp_file_md5_checksum(const char *filename, const char *expect_md5sum)
|
|
{
|
|
FILE *cmd_res_fp;
|
|
char file_real_md5sum[33];
|
|
char cmd_buf[1024];
|
|
int ret = 0;
|
|
|
|
snprintf(cmd_buf, 1024, "%s %s", "md5sum", filename);
|
|
|
|
cmd_res_fp = popen(cmd_buf, "r");
|
|
if(NULL == cmd_res_fp){
|
|
return -1;
|
|
}
|
|
|
|
fgets(file_real_md5sum, 33, cmd_res_fp);
|
|
|
|
if(strncasecmp(file_real_md5sum, expect_md5sum, 32) != 0){
|
|
printf("file md5:%s, but expect md5:%s\n", file_real_md5sum, expect_md5sum);
|
|
ret = -1;
|
|
}
|
|
|
|
fclose(cmd_res_fp);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void jump_layer_eth_ipv4_tcp(u_char *result_val, const struct pcap_pkthdr *hdr, const u_char *data)
|
|
{
|
|
int ret;
|
|
const void *eth_header, *ipv4_header, *tcp_header;
|
|
|
|
eth_header = (void *)data;
|
|
|
|
ipv4_header = MESA_net_jump_to_layer(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
|
if(NULL == ipv4_header){
|
|
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;
|
|
}
|
|
ret = jump_check_ipv4_pkt((struct ip*)ipv4_header, 60, IPPROTO_TCP, "192.168.10.250", "192.168.10.234");
|
|
if(ret < 0){
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
const void *greedy_ipv4_header = MESA_jump_layer_greedy(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
|
if(greedy_ipv4_header != ipv4_header){
|
|
/* 就一层ip, 没有嵌套, greedy结果应该是一样的 */
|
|
printf("\033[1;31;40mjump_layer_eth_ipv4_udp(): greedy jump to ipv4 error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
tcp_header = MESA_net_jump_to_layer((void *)ipv4_header, ADDR_TYPE_IPV4, ADDR_TYPE_TCP);
|
|
if(NULL == tcp_header){
|
|
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);
|
|
if(NULL == tcp_header){
|
|
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);
|
|
if(NULL == tcp_header){
|
|
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;
|
|
ret = jump_check_tcp_pkt(thdr, 40, 58725, 22);
|
|
if(ret < 0){
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
const void *greedy_tcp_header = MESA_jump_layer_greedy(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_TCP);
|
|
if(greedy_tcp_header != tcp_header){
|
|
/* 就一层ip, 没有嵌套, greedy结果应该是一样的 */
|
|
printf("\033[1;31;40mjump_layer_eth_ipv4_udp(): greedy jump to tcp error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
|
|
printf("\033[32mjump_layer_eth_ipv4_tcp_entry() test succ\033[0m\n");
|
|
|
|
*result_val = 0;
|
|
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
}
|
|
|
|
#define __jump_layer_eth_ipv4_tcp 1
|
|
TEST(jump_layer, eth_ipv4_tcp)
|
|
{
|
|
int fun_ret;
|
|
u_char chk_res = -1;
|
|
|
|
fun_ret = jmp_file_md5_checksum("./sample_pcap/tcp_simple.pcap", "eb4b176720c698e86c1acbacf2f30ede");
|
|
ASSERT_EQ(fun_ret, 0);
|
|
|
|
fun_ret = jmp_pcap_init("./sample_pcap/tcp_simple.pcap", jump_layer_eth_ipv4_tcp, (u_char *)&chk_res);
|
|
ASSERT_EQ(fun_ret, 0);
|
|
|
|
ASSERT_EQ(chk_res, 0);
|
|
}
|
|
|
|
|
|
|
|
|
|
static void jump_layer_eth_ipv4_udp(u_char *result_val, const struct pcap_pkthdr *hdr, const u_char *data)
|
|
{
|
|
int ret;
|
|
const void *eth_header = data, *ipv4_header, *udp_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 void *greedy_ipv4_header = MESA_jump_layer_greedy(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_UDP);
|
|
if(greedy_ipv4_header != udp_header){
|
|
/* 就一层udp, 没有嵌套, greedy结果应该是一样的 */
|
|
printf("\033[1;31;40mjump_layer_eth_ipv4_udp(): greedy jump to 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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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)
|
|
{
|
|
int ret;
|
|
int tot_pkt_len;
|
|
const void *pkt_header;
|
|
const void *next_header;
|
|
|
|
if(pstream->pktstate == OP_STATE_PENDING){
|
|
next_header = MESA_net_jump_to_layer((void *)a_packet, ADDR_TYPE_IPV6, ADDR_TYPE_TCP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv6->tcp 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_ipv6_tcp_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_ipv6_tcp_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_IPV6);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv6 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 ip6_hdr* ip6h = (struct ip6_hdr *)next_header;
|
|
|
|
jump_check_ipv6_pkt(ip6h, tot_pkt_len - sizeof(struct ethhdr) - sizeof(struct ip6_hdr), IPPROTO_TCP, "2001::192:168:40:134", "2001::192:168:40:133");
|
|
|
|
next_header = MESA_net_jump_to_layer((void *)ip6h, __ADDR_TYPE_IP_PAIR_V6, ADDR_TYPE_TCP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv6->tcp error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
const struct tcphdr* thdr = (struct tcphdr *)next_header;
|
|
jump_check_tcp_pkt(thdr, 40, 37948, 22);
|
|
|
|
printf("\033[32mjump_layer_eth_ipv6_tcp_entry() test succ\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_SUCC);
|
|
}
|
|
|
|
return APP_STATE_DROPME;
|
|
}
|
|
|
|
|
|
extern "C" char jump_layer_eth_ipv6_udp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
|
|
{
|
|
int ret;
|
|
int tot_pkt_len;
|
|
const void *pkt_header;
|
|
const void *next_header;
|
|
|
|
if(pstream->opstate == OP_STATE_PENDING){
|
|
next_header = MESA_net_jump_to_layer((void *)a_packet, ADDR_TYPE_IPV6, ADDR_TYPE_UDP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): ipv6->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_ipv6_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_ipv6_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_IPV6);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv6 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(): ip6 header is not equal with plug_entry->a_packet!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
const struct ip6_hdr* ip6h = (struct ip6_hdr*)next_header;
|
|
jump_check_ipv6_pkt(ip6h, tot_pkt_len - sizeof(struct ethhdr) - sizeof(struct ip6_hdr), IPPROTO_UDP, "2001::192:168:40:134", "2001::192:168:40:133");
|
|
|
|
next_header = MESA_net_jump_to_layer((void *)ip6h, __ADDR_TYPE_IP_PAIR_V6, 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, 10, 33225, 31337);
|
|
|
|
printf("\033[32mjump_layer_eth_ipv6_udp_entry() test succ\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_SUCC);
|
|
}
|
|
|
|
return APP_STATE_DROPME;
|
|
}
|
|
|
|
|
|
extern "C" char jump_layer_eth_ipv4_gtp_ipv4_tcpall_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
|
|
{
|
|
int ret;
|
|
int tot_pkt_len;
|
|
const void *pkt_header;
|
|
const void *next_header;
|
|
|
|
if(pstream->pktstate == OP_STATE_PENDING){
|
|
ret = get_rawpkt_opt_from_streaminfo(pstream, RAW_PKT_GET_DATA, &pkt_header);
|
|
if(ret < 0){
|
|
printf("\033[1;31;40m jump_layer_eth_ipv4_gtp_ipv4_tcpall_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;40m jump_layer_eth_ipv4_gtp_ipv4_tcpall_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); /* 外层ipv4 */
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40m MESA_net_jump_to_layer(): eth->ipv4 error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct ip* outer_ip4hdr = (struct ip*)next_header;
|
|
jump_check_ipv4_pkt(outer_ip4hdr, 76, IPPROTO_UDP, "10.166.20.10", "10.2.3.35");
|
|
|
|
|
|
next_header = MESA_net_jump_to_layer(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_GPRS_TUNNEL); /* gtp层 */
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40m MESA_net_jump_to_layer(): eth->ipv4->gtp error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct gtp_hdr *net_gtp_hdr = (struct gtp_hdr *)next_header;
|
|
if(net_gtp_hdr->flags != 0x30){
|
|
printf("\033[1;31;40m gtp hdr flags is not 0x30!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
if(net_gtp_hdr->msg_type != 0xFF){
|
|
printf("\033[1;31;40m gtp hdr msg_type is not 0xFF!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
if(ntohs(net_gtp_hdr->len) != 40){
|
|
printf("\033[1;31;40m gtp hdr length is not 40!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
if(ntohl(net_gtp_hdr->teid) != 0xb68311b){
|
|
printf("\033[1;31;40m gtp hdr teid is not 0xb68311b!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4); /* 内层ipv4 */
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40m MESA_net_jump_to_layer(): eth->ipv4->gtp->ipv4 error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct ip* inner_ip4hdr = (struct ip*)next_header;
|
|
if(next_header != a_packet){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): inner ip header is not equal with plug_entry->a_packet!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
jump_check_ipv4_pkt(inner_ip4hdr, 40, IPPROTO_TCP, "10.58.121.62", "217.76.78.112");
|
|
|
|
|
|
next_header = MESA_net_jump_to_layer((void *)pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_TCP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->gtp->ipv4->tcp error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
const struct tcphdr* thdr = (struct tcphdr *)next_header;
|
|
jump_check_tcp_pkt(thdr, 20, 52144, 443);
|
|
|
|
printf("\033[32mjump_layer_eth_ipv4_gtp_ipv4_tcpall_entry() test succ\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_SUCC);
|
|
}
|
|
|
|
return APP_STATE_DROPME;
|
|
}
|
|
|
|
|
|
extern "C" char jump_layer_eth_ipv4_pptp_ipv4_tcpall_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
|
|
{
|
|
int ret;
|
|
int tot_pkt_len;
|
|
const void *pkt_header;
|
|
const void *next_header;
|
|
|
|
if(pstream->pktstate == OP_STATE_PENDING){
|
|
ret = get_rawpkt_opt_from_streaminfo(pstream, RAW_PKT_GET_DATA, &pkt_header);
|
|
if(ret < 0){
|
|
printf("\033[1;31;40mjump_layer_eth_ipv4_tcp_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_tcp_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);
|
|
}
|
|
const struct ip* outer_ip4hdr = (struct ip*)next_header;
|
|
jump_check_ipv4_pkt(outer_ip4hdr, 88, IPPROTO_GRE, "172.16.0.100", "172.16.0.254");
|
|
|
|
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->pptp->ipv4 error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct ip* inner_ip4hdr = (struct ip*)next_header;
|
|
if(next_header != a_packet){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): inner ip header is not equal with plug_entry->a_packet!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
jump_check_ipv4_pkt(inner_ip4hdr, 52, IPPROTO_TCP, "172.16.2.100", "10.0.6.229");
|
|
|
|
|
|
next_header = MESA_net_jump_to_layer((void *)pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_TCP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->pptp->ipv4->tcp error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
const struct tcphdr* thdr = (struct tcphdr *)next_header;
|
|
jump_check_tcp_pkt(thdr, 32, 50072, 80);
|
|
|
|
printf("\033[32mjump_layer_eth_ipv4_pptp_ipv4_tcpall_entry() test succ\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_SUCC);
|
|
}
|
|
|
|
return APP_STATE_DROPME;
|
|
}
|
|
|
|
extern "C" char jump_layer_eth_ip4_l2tp_ip4_tcpall_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
|
|
{
|
|
int ret;
|
|
int tot_pkt_len;
|
|
const void *pkt_header;
|
|
const void *next_header;
|
|
|
|
if(pstream->pktstate == OP_STATE_PENDING){
|
|
ret = get_rawpkt_opt_from_streaminfo(pstream, RAW_PKT_GET_DATA, &pkt_header);
|
|
if(ret < 0){
|
|
printf("\033[1;31;40mjump_layer_eth_ipv4_tcp_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_tcp_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);
|
|
}
|
|
const struct ip* outer_ip4hdr = (struct ip*)next_header;
|
|
jump_check_ipv4_pkt(outer_ip4hdr, 92, IPPROTO_UDP, "172.16.0.100", "172.16.0.254");
|
|
|
|
|
|
next_header = MESA_net_jump_to_layer(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_L2TP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->l2tp error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct l2tp_hdr_v2 *p_l2tp_hdr = (struct l2tp_hdr_v2 *)next_header;
|
|
if(p_l2tp_hdr->length_present != 1){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer():l2tp header length flag is not 1!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
if(p_l2tp_hdr->version != 2){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer():l2tp header version is not 2!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const unsigned short *short_ptr = (unsigned short *)((char *)next_header + sizeof(struct l2tp_hdr_v2));
|
|
if(ntohs(*short_ptr) != 64){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer():l2tp header lenth is not 64!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
short_ptr++;
|
|
if(ntohs(*short_ptr) != 28998){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer():l2tp header tunnel id is not 28998!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
short_ptr++;
|
|
if(ntohs(*short_ptr) != 2){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer():l2tp header session id is not 2!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
/* 跳转到内层ipv4需要用greedy接口 */
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->l2tp->ipv4 error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct ip* inner_ip4hdr = (struct ip*)next_header;
|
|
jump_check_ipv4_pkt(inner_ip4hdr, 52, IPPROTO_TCP, "172.16.2.100", "10.0.6.229");
|
|
|
|
if(inner_ip4hdr != a_packet){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): inner ip4 header is not equal with plug_entry->a_packet!\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_TCP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->l2tp->ipv4->tcp error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
const struct tcphdr* thdr = (struct tcphdr *)next_header;
|
|
jump_check_tcp_pkt(thdr, 32, 49250, 80);
|
|
|
|
printf("\033[32mjump_layer_eth_ip4_l2tp_ip4_tcpall_entry() test succ\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_SUCC);
|
|
}
|
|
|
|
return APP_STATE_DROPME;
|
|
}
|
|
|
|
|
|
extern "C" char jump_layer_eth_ip4_l2tp_ip4_udp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
|
|
{
|
|
int ret, opt_len;
|
|
int tot_pkt_len;
|
|
const void *pkt_header;
|
|
const void *next_header;
|
|
unsigned short tunnel_type = STREAM_TUNNLE_NON;
|
|
|
|
if(pstream->opstate == OP_STATE_PENDING){
|
|
|
|
opt_len = sizeof(short);
|
|
ret = MESA_get_stream_opt(pstream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &opt_len);
|
|
if((ret < 0) || (tunnel_type != STREAM_TUNNLE_L2TP)){
|
|
return APP_STATE_DROPME; /* l2tp隧道外层udp流, 不处理 */
|
|
}
|
|
|
|
ret = get_rawpkt_opt_from_streaminfo(pstream, RAW_PKT_GET_DATA, &pkt_header);
|
|
if(ret < 0){
|
|
printf("\033[1;31;40mjump_layer_eth_ipv4_tcp_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_tcp_entry(), get_rawpkt_opt_from_streaminfo()->RAW_PKT_GET_TOT_LEN error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
/* 跳转到内层ipv4需要用greedy接口 */
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->l2tp->ipv4 error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct ip* inner_ip4hdr = (struct ip*)next_header;
|
|
jump_check_ipv4_pkt(inner_ip4hdr, 66, IPPROTO_UDP, "172.16.2.100", "8.8.8.8");
|
|
|
|
if(inner_ip4hdr != a_packet){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): inner ip4 header is not equal with plug_entry->a_packet!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_UDP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->l2tp->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, 46, 53483, 53);
|
|
|
|
printf("\033[32m jump_layer_eth_ip4_l2tp_ip4_udp_entry() test succ\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_SUCC);
|
|
}
|
|
|
|
return APP_STATE_DROPME;
|
|
}
|
|
|
|
|
|
extern "C" char jump_layer_eth_ip4_l2tp_ppp_compress_ip4_udp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
|
|
{
|
|
int ret;
|
|
int tot_pkt_len;
|
|
const void *pkt_header;
|
|
const void *next_header;
|
|
int opt_len;
|
|
unsigned short tunnel_type = STREAM_TUNNLE_NON;
|
|
|
|
if(pstream->pktstate == OP_STATE_PENDING){
|
|
opt_len = sizeof(short);
|
|
ret = MESA_get_stream_opt(pstream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &opt_len);
|
|
if((ret < 0) || (tunnel_type != STREAM_TUNNLE_L2TP)){
|
|
return APP_STATE_DROPME; /* l2tp隧道外层udp流, 不处理 */
|
|
}
|
|
|
|
ret = get_rawpkt_opt_from_streaminfo(pstream, RAW_PKT_GET_DATA, &pkt_header);
|
|
if(ret < 0){
|
|
printf("\033[1;31;40m jump_layer_eth_ip4_l2tp_ppp_compress_ip4_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;40m jump_layer_eth_ip4_l2tp_ppp_compress_ip4_udp_entry(), get_rawpkt_opt_from_streaminfo()->RAW_PKT_GET_TOT_LEN error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
/* 跳转到内层ipv4需要用greedy接口 */
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40m MESA_net_jump_to_layer(): eth->ipv4->l2tp->ipv4 error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct ip* inner_ip4hdr = (struct ip*)next_header;
|
|
jump_check_ipv4_pkt(inner_ip4hdr, 1378, IPPROTO_UDP, "10.24.0.36", "64.233.185.99");
|
|
|
|
if(inner_ip4hdr != a_packet){
|
|
printf("\033[1;31;40m MESA_net_jump_to_layer(): inner ip4 header is not equal with plug_entry->a_packet!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_UDP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->udp->l2tp->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, 1358, 52139, 443);
|
|
|
|
printf("\033[32m jump_layer_eth_ip4_l2tp_ppp_compress_ip4_udp_entry() test succ\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_SUCC);
|
|
}
|
|
|
|
return APP_STATE_DROPME;
|
|
}
|
|
|
|
|
|
extern "C" char jump_layer_eth_ipv4_gre_ipv4_gre_ipv4_udp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
|
|
{
|
|
int ret;
|
|
int tot_pkt_len;
|
|
const void *pkt_header;
|
|
const void *next_header;
|
|
|
|
if(pstream->opstate == OP_STATE_PENDING){
|
|
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);
|
|
}
|
|
const struct ip* outer_ip4hdr = (struct ip*)next_header;
|
|
jump_check_ipv4_pkt(outer_ip4hdr, 124, IPPROTO_GRE, "115.153.75.246", "122.112.114.66");
|
|
|
|
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->gre->ipv4 error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct ip* inner_ip4hdr = (struct ip*)next_header;
|
|
if(inner_ip4hdr != a_packet){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): inner ip header is not equal with plug_entry->a_packet!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
jump_check_ipv4_pkt(inner_ip4hdr, 72, IPPROTO_UDP, "122.112.114.73", "115.238.253.235");
|
|
|
|
next_header = MESA_net_jump_to_layer((void *)pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_UDP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->gre->ipv4->gre->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, 52, 20755, 53);
|
|
|
|
printf("\033[32mjump_layer_eth_ipv4_gre_ipv4_gre_ipv4_udp_entry() test succ\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_SUCC);
|
|
}
|
|
|
|
return APP_STATE_DROPME;
|
|
}
|
|
|
|
|
|
extern "C" char jump_layer_eth_vlan_ip6_ip4_pptp_ip4_ip6_tcpall_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
|
|
{
|
|
int ret;
|
|
int tot_pkt_len;
|
|
const void *pkt_header;
|
|
const void *next_header;
|
|
|
|
if(pstream->pktstate == OP_STATE_PENDING){
|
|
ret = get_rawpkt_opt_from_streaminfo(pstream, RAW_PKT_GET_DATA, &pkt_header);
|
|
if(ret < 0){
|
|
printf("\033[1;31;40mjump_layer_eth_ipv4_tcp_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_tcp_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_VLAN);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->vlan error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
jump_check_vlan_pkt(next_header, htonl(0x006486DD));
|
|
|
|
next_header = MESA_net_jump_to_layer(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->vlan->ipv6 error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
jump_check_ipv6_pkt((const ip6_hdr *)next_header, 1412, 4, "2607:fcd0:100:2300::b108:2a6b", "2402:f000:1:8e01::5555");
|
|
|
|
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->vlan->ipv6->ipv4 error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct ip* outer_ip4hdr = (struct ip*)next_header;
|
|
jump_check_ipv4_pkt(outer_ip4hdr, 1412, IPPROTO_GRE, "192.52.166.154", "16.0.0.200");
|
|
|
|
/* 跳转到内层ipv4需要用greedy接口 */
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->vlan->ipv6->ipv4->pptp->ipv4 error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct ip* inner_ip4hdr = (struct ip*)next_header;
|
|
jump_check_ipv4_pkt(inner_ip4hdr, 1376, IPPROTO_TCP, "173.194.72.18", "172.16.44.3");
|
|
|
|
if(inner_ip4hdr != a_packet){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): inner ip4 header is not equal with plug_entry->a_packet!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_TCP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->vlan->ipv6->ipv4->pptp->ipv4->tcp error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
const struct tcphdr* thdr = (struct tcphdr *)next_header;
|
|
jump_check_tcp_pkt(thdr, 20, 443, 56461);
|
|
|
|
printf("\033[32mjump_layer_eth_vlan_ip6_ip4_pptp_ip4_ip6_tcpall_entry() test succ\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_SUCC);
|
|
}
|
|
|
|
return APP_STATE_DROPME;
|
|
}
|
|
|
|
|
|
extern "C" char jump_layer_eth_ip4_udp_teredo_udp_ip6_tcpall_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
|
|
{
|
|
int ret;
|
|
int tot_pkt_len;
|
|
const void *pkt_header;
|
|
const void *next_header;
|
|
int opt_len;
|
|
unsigned short tunnel_type = STREAM_TUNNLE_NON;
|
|
|
|
if(pstream->pktstate == OP_STATE_PENDING){
|
|
opt_len = sizeof(short);
|
|
ret = MESA_get_stream_opt(pstream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &opt_len);
|
|
if((ret < 0) || (tunnel_type != STREAM_TUNNLE_TEREDO)){
|
|
return APP_STATE_DROPME; /*teredo隧道外层udp流, 不处理 */
|
|
}
|
|
|
|
ret = get_rawpkt_opt_from_streaminfo(pstream, RAW_PKT_GET_DATA, &pkt_header);
|
|
if(ret < 0){
|
|
printf("\033[1;31;40m jump_layer_eth_ip4_udp_teredo_udp_ip6_tcp_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;40m jump_layer_eth_ip4_udp_teredo_udp_ip6_tcp_entry(), get_rawpkt_opt_from_streaminfo()->RAW_PKT_GET_TOT_LEN error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
/* 跳转到内层ipv6需要用greedy接口 */
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40m MESA_net_jump_to_layer(): eth->ipv4->teredo->ipv6 error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct ip6_hdr* inner_ip6hdr = (struct ip6_hdr*)next_header;
|
|
jump_check_ipv6_pkt(inner_ip6hdr, 489, IPPROTO_TCP, "2001:0:4137:9E76:2463:F227:88D7:DABE", "2001:252:0:2::2000");
|
|
|
|
if(inner_ip6hdr != a_packet){
|
|
printf("\033[1;31;40m MESA_net_jump_to_layer(): inner ip6 header is not equal with plug_entry->a_packet!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_TCP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->udp->teredo->ipv6->tcp error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
const struct tcphdr* thdr = (struct tcphdr *)next_header;
|
|
jump_check_tcp_pkt(thdr, 20, 63622, 80);
|
|
|
|
printf("\033[32m jump_layer_eth_ip4_udp_teredo_udp_ip6_tcp_entry() test succ\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_SUCC);
|
|
}
|
|
|
|
return APP_STATE_DROPME;
|
|
}
|
|
|
|
|
|
extern "C" char jump_layer_eth_ip4_udp_teredo_udp_ip6_udp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
|
|
{
|
|
int ret;
|
|
int tot_pkt_len;
|
|
const void *pkt_header;
|
|
const void *next_header;
|
|
int opt_len;
|
|
unsigned short tunnel_type = STREAM_TUNNLE_NON;
|
|
|
|
if(pstream->opstate == OP_STATE_PENDING){
|
|
opt_len = sizeof(short);
|
|
ret = MESA_get_stream_opt(pstream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &opt_len);
|
|
if((ret < 0) || (tunnel_type != STREAM_TUNNLE_TEREDO)){
|
|
return APP_STATE_DROPME; /*teredo隧道外层udp流, 不处理 */
|
|
}
|
|
|
|
ret = get_rawpkt_opt_from_streaminfo(pstream, RAW_PKT_GET_DATA, &pkt_header);
|
|
if(ret < 0){
|
|
printf("\033[1;31;40m jump_layer_eth_ip4_udp_teredo_udp_ip6_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;40m jump_layer_eth_ip4_udp_teredo_udp_ip6_udp_entry(), get_rawpkt_opt_from_streaminfo()->RAW_PKT_GET_TOT_LEN error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
/* 跳转到内层ipv6需要用greedy接口 */
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40m MESA_net_jump_to_layer(): eth->ipv4->teredo->ipv6 error!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
const struct ip6_hdr* inner_ip6hdr = (struct ip6_hdr*)next_header;
|
|
jump_check_ipv6_pkt(inner_ip6hdr, 56, IPPROTO_UDP, "FE80::8000:F227:3EFF:FFFE", "FE80::FFFF:FFFF:FFFF");
|
|
|
|
if(inner_ip6hdr != a_packet){
|
|
printf("\033[1;31;40m MESA_net_jump_to_layer(): inner ip6 header is not equal with plug_entry->a_packet!\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_ERR);
|
|
exit(1);
|
|
}
|
|
|
|
next_header = MESA_net_jump_to_layer_greedy(pkt_header, ADDR_TYPE_MAC, ADDR_TYPE_UDP);
|
|
if(NULL == next_header){
|
|
printf("\033[1;31;40mMESA_net_jump_to_layer(): eth->ipv4->udp->teredo->ipv6->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, 56, 32768, 20480);
|
|
|
|
printf("\033[32m jump_layer_eth_ip4_udp_teredo_udp_ip6_udp_entry() test succ\033[0m\n");
|
|
sendto_test_result(GTEST_SAPP_SUCC);
|
|
}
|
|
|
|
return APP_STATE_DROPME;
|
|
}
|
|
#endif
|
|
|
|
static void jump_layer_eth_vlan_ip6_udp_gtpext_ip4_tcp(u_char *result_val, const struct pcap_pkthdr *hdr, const u_char *data)
|
|
{
|
|
int ret;
|
|
const void *eth_header = data;
|
|
const void *outer_ipv6_header;
|
|
const void *outer_udp_header;
|
|
const void *gtp_header;
|
|
const void *inner_ipv4_header;
|
|
const void *inner_tcp_header;
|
|
|
|
|
|
outer_ipv6_header = MESA_net_jump_to_layer(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
|
|
if(NULL == outer_ipv6_header){
|
|
printf("\033[1;31;40m jump_layer_eth_vlan_ip6_udp_gtpext_ip4_tcp(): eth->vlan->ipv6 error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
ret = jump_check_ipv6_pkt((struct ip6_hdr*)outer_ipv6_header, 64, IPPROTO_UDP, "2409:8034:4025::1:941", "2409:8034:4040:5300::205");
|
|
if(ret < 0){
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
outer_udp_header = MESA_net_jump_to_layer(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_UDP);
|
|
if(NULL == outer_udp_header){
|
|
printf("\033[1;31;40m jump_layer_eth_vlan_ip6_udp_gtpext_ip4_tcp(): eth->vlan->ipv6->udp error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
ret = jump_check_udp_pkt((const struct udphdr *)outer_udp_header, 64, 2152, 2152);
|
|
if(ret < 0){
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
const void *greedy_udp_hdr = MESA_jump_layer_greedy(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_UDP);
|
|
if(greedy_udp_hdr != outer_udp_header){
|
|
printf("\033[1;31;40m jump_layer_eth_vlan_ip6_udp_gtpext_ip4_tcp(): greedy jump eth->vlan->ipv6->udp error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
gtp_header = MESA_jump_layer_greedy(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_GPRS_TUNNEL);
|
|
if(NULL == gtp_header){
|
|
printf("\033[1;31;40m jump_layer_eth_vlan_ip6_udp_gtpext_ip4_tcp(): greedy jump eth->vlan->ipv6->udp->gtp error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
inner_ipv4_header = ( struct ip *)MESA_net_jump_to_layer(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
|
if(NULL == inner_ipv4_header){
|
|
printf("\033[1;31;jump_layer_eth_vlan_ip6_udp_gtpext_ip4_tcp(): eth->ipv6->udp->gtp->ipv4 error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
ret = jump_check_ipv4_pkt((struct ip *)inner_ipv4_header, 40, IPPROTO_TCP, "10.16.131.196", "112.49.26.208");
|
|
if(ret < 0){
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
const void *greedy_inner_ip4_hdr = MESA_jump_layer_greedy(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
|
if(greedy_inner_ip4_hdr != inner_ipv4_header){
|
|
printf("\033[1;31;40m jump_layer_eth_vlan_ip6_udp_gtpext_ip4_tcp(): greedy jump eth->vlan->ipv6->udp->ipv4 error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
|
|
inner_tcp_header = MESA_net_jump_to_layer(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_TCP);
|
|
if(NULL == inner_tcp_header){
|
|
printf("\033[1;31;jump_layer_eth_vlan_ip6_udp_gtpext_ip4_tcpall_entry(): eth->ipv6->udp->gtp->ipv6->tcp error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
ret = jump_check_tcp_pkt((struct tcphdr *)inner_tcp_header, 20, 47892, 80);
|
|
if(ret < 0){
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
const void *greedy_tcp_hdr = MESA_jump_layer_greedy(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_TCP);
|
|
if(greedy_tcp_hdr != inner_tcp_header){
|
|
printf("\033[1;31;40m jump_layer_eth_vlan_ip6_udp_gtpext_ip4_tcp(): greedy jump eth->vlan->ipv6->udp->ipv4->tcp error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
printf("\033[32m jump_layer_eth_vlan_ip6_udp_gtpext_ip4_tcp() test succ\033[0m\n");
|
|
|
|
*result_val = 0;
|
|
return;
|
|
}
|
|
|
|
|
|
#define __jump_layer_eth_vlan_ip6_udp_gtpext_ip4_tcp 1
|
|
TEST(jump_layer, eth_vlan_ip6_udp_gtpext_ip4_tcp)
|
|
{
|
|
int fun_ret;
|
|
u_char chk_res = -1;
|
|
|
|
fun_ret = jmp_file_md5_checksum("./sample_pcap/eth_vlan_ip6_udp_gtpext_ip4_tcp.pcap", "d51cebb81e70baaf9568f13af867f6c4");
|
|
ASSERT_EQ(fun_ret, 0);
|
|
|
|
fun_ret = jmp_pcap_init("./sample_pcap/eth_vlan_ip6_udp_gtpext_ip4_tcp.pcap", jump_layer_eth_vlan_ip6_udp_gtpext_ip4_tcp, (u_char *)&chk_res);
|
|
ASSERT_EQ(fun_ret, 0);
|
|
|
|
ASSERT_EQ(chk_res, 0);
|
|
}
|
|
|
|
static void jump_layer_eth_vxlan_3vlan_ipv4_udp(u_char *result_val, const struct pcap_pkthdr *hdr, const u_char *data)
|
|
{
|
|
int ret;
|
|
const void *eth_header = data;
|
|
const void *outer_ipv4_header;
|
|
const void *outer_udp_header;
|
|
//const void *gtp_header;
|
|
const void *inner_ipv4_header;
|
|
|
|
outer_ipv4_header = MESA_net_jump_to_layer(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
|
if(NULL == outer_ipv4_header){
|
|
printf("\033[1;31;40m jump_layer_eth_vxlan_3vlan_ipv4_udp(): eth->ipv4 error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
ret = jump_check_ipv4_pkt((struct ip *)outer_ipv4_header, 209, IPPROTO_UDP, "10.10.0.8", "10.252.20.1");
|
|
if(ret < 0){
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
outer_udp_header = MESA_net_jump_to_layer(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_UDP);
|
|
if(NULL == outer_udp_header){
|
|
printf("\033[1;31;40m jump_layer_eth_vxlan_3vlan_ipv4_udp(): eth->vlan->ipv6->udp error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
ret = jump_check_udp_pkt((const struct udphdr *)outer_udp_header, 189, 61717, 4789);
|
|
if(ret < 0){
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
const struct ethhdr *inner_mac_header = (struct ethhdr *)MESA_jump_layer_greedy(outer_ipv4_header, ADDR_TYPE_IPV4, ADDR_TYPE_MAC);
|
|
if(NULL == inner_mac_header){
|
|
printf("\033[1;31;jump_layer_eth_vxlan_3vlan_ipv4_udp(): eth->ipv6->udp->vxlan->mac error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
const unsigned char expect_src_mac[6] = {0x6c, 0x3b, 0x6b, 0xc0, 0x01, 0x1f};
|
|
const unsigned char expect_dst_mac[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
|
|
|
if(memcmp(inner_mac_header->h_source, expect_src_mac, 6) != 0){
|
|
printf("\033[1;31;jump_layer_eth_vxlan_3vlan_ipv4_udp(): eth->ipv6->udp->vxlan->src_mac error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
if(memcmp(inner_mac_header->h_dest, expect_dst_mac, 6) != 0){
|
|
printf("\033[1;31;jump_layer_eth_vxlan_3vlan_ipv4_udp(): eth->ipv6->udp->vxlan->dst_mac error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
inner_ipv4_header = ( struct ip *)MESA_jump_layer_greedy(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
|
if(NULL == inner_ipv4_header){
|
|
printf("\033[1;31;jump_layer_eth_vxlan_3vlan_ipv4_udp(): eth->ipv6->udp->gtp->ipv4 error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
ret = jump_check_ipv4_pkt((struct ip *)inner_ipv4_header, 147, IPPROTO_UDP, "0.0.0.0", "255.255.255.255");
|
|
if(ret < 0){
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
const void *greedy_udp_hdr = MESA_jump_layer_greedy(eth_header, ADDR_TYPE_MAC, ADDR_TYPE_UDP);
|
|
if(NULL == greedy_udp_hdr){
|
|
printf("\033[1;31;40m jump_layer_eth_vxlan_3vlan_ipv4_udp(): greedy jump eth->vlan->ipv6->udp error!\033[0m\n");
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
ret = jump_check_udp_pkt((const struct udphdr *)greedy_udp_hdr, 127, 5678, 5678);
|
|
if(ret < 0){
|
|
*result_val = -1;
|
|
pcap_breakloop(g_jmp_pcap_handle);
|
|
return;
|
|
}
|
|
|
|
printf("\033[32m jump_layer_eth_vxlan_3vlan_ipv4_udp() test succ\033[0m\n");
|
|
|
|
*result_val = 0;
|
|
return;
|
|
}
|
|
|
|
|
|
#define __jump_layer_eth_vxlan_3vlan_ipv4_udp 1
|
|
TEST(jump_layer, eth_vxlan_3vlan_ipv4_udp)
|
|
{
|
|
int fun_ret;
|
|
u_char chk_res = -1;
|
|
|
|
fun_ret = jmp_file_md5_checksum("./sample_pcap/vxlan_inner_3_vlan_udp.pcap", "3d9da66edfe7e8958f797ca57fff9ba5");
|
|
ASSERT_EQ(fun_ret, 0);
|
|
|
|
fun_ret = jmp_pcap_init("./sample_pcap/vxlan_inner_3_vlan_udp.pcap", jump_layer_eth_vxlan_3vlan_ipv4_udp, (u_char *)&chk_res);
|
|
ASSERT_EQ(fun_ret, 0);
|
|
|
|
ASSERT_EQ(chk_res, 0);
|
|
}
|
|
|
|
/*
|
|
TODO:
|
|
基础协议跳转测试用例;
|
|
各种隧道嵌套协议跳转测试用例.
|
|
*/
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
int ret=RUN_ALL_TESTS();
|
|
|
|
return ret;
|
|
}
|
|
|