From 421d4ed459f6656f7f67c301530891e332b49959 Mon Sep 17 00:00:00 2001 From: yangwei Date: Tue, 12 Nov 2024 13:24:11 +0800 Subject: 馃敡 build(integrate tcpdump_mesa): in tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchmark/include/sapp_bchmk_inner.h | 33 +++--- benchmark/include/sapp_benchmark.h | 8 +- benchmark/src/sapp_benchmark.cpp | 14 +-- benchmark/src/sapp_benchmark_utils.cpp | 64 ++++++----- include/private/mesa_net.h | 37 +++--- include/private/sapp_declaration.h | 1 + include/private/stream_internal.h | 6 +- include/public/stream_inc/MESA_jump_layer.h | 57 ---------- include/public/stream_inc/stream_base.h | 168 ++++++++++++++-------------- include/public/stream_inc/stream_rawpkt.h | 27 ++++- module_test/src/gtest_sapp_comm.cpp | 2 - module_test/src/gtest_sapp_fun.h | 11 +- src/common/MESA_jump_layer.cpp | 7 +- tools/CMakeLists.txt | 15 +++ tools/tcpdumpmesa.zip | Bin 0 -> 1465218 bytes 15 files changed, 201 insertions(+), 249 deletions(-) delete mode 100644 include/public/stream_inc/MESA_jump_layer.h create mode 100644 tools/tcpdumpmesa.zip diff --git a/benchmark/include/sapp_bchmk_inner.h b/benchmark/include/sapp_bchmk_inner.h index 935bde3..76a7f5b 100644 --- a/benchmark/include/sapp_bchmk_inner.h +++ b/benchmark/include/sapp_bchmk_inner.h @@ -1,29 +1,20 @@ #ifndef _SAPP_BCHMK_INNER_H_ #define _SAPP_BCHMK_INNER_H_ 1 -#include #include #include #include #include #include -#include -#include #include #include /* See NOTES */ #include #include #include -#include -#include "stream.h" -#include #include #include #include #include #include "wrap_cJSON.h" -#include "MESA_jump_layer.h" -#include "MESA_handle_logger.h" -#include "MESA_prof_load.h" #ifdef __cplusplus extern "C" { #endif @@ -58,10 +49,11 @@ extern "C" { #define SAPP_BCHMK_DEFAULT_CFG_FILE_DIR "sapp_default_config" +#include "MESA_handle_logger.h" extern void * __g_sapp_benchmark_log_handle; #define sapp_bchmk_log(h, log_level, format, args...) do{if(((benchmark_engine_t *)h)->plug_opt.MESA_log_handle) {MESA_handle_runtime_log(((benchmark_engine_t *)h)->plug_opt.MESA_log_handle, log_level, "sapp_benchmark", format, ##args);} }while(0) -/* 内存里的index从0开始, 但是为了方便和wireshark对比方便, 所有配置文件的index都从1开始, 需要做一次转换 */ +/* 锟节达拷锟斤拷锟絠ndex锟斤拷0锟斤拷始, 锟斤拷锟斤拷为锟剿凤拷锟斤拷锟絯ireshark锟皆比凤拷锟斤拷, 锟斤拷锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷index锟斤拷锟斤拷1锟斤拷始, 锟斤拷要锟斤拷一锟斤拷转锟斤拷 */ #define ADJUST_ARRAY_INDEX_to_WIRESHARK(n) do{ n = n + 1;}while(0) #define ADJUST_WIRESHARK_INDEX_to_ARRAY(n) do{ n = n + 1;}while(0) @@ -88,23 +80,24 @@ typedef struct{ typedef struct{ - int pkt_len; /* pcap每个eth包的长度 */ - const struct ethhdr *pkt_data; /* 存储pcap包内容的指针数组 */ - //char md5sum_with_timestamp[MD5_STRING_MAX_LEN]; /* 因为重复包、重传包md5可能完全是一样的, 要加上时间戳 */ + int pkt_len; /* pcap每锟斤拷eth锟斤拷锟侥筹拷锟斤拷 */ + const struct ethhdr *pkt_data; /* 锟芥储pcap锟斤拷锟斤拷锟捷碉拷指锟斤拷锟斤拷锟斤拷 */ + //char md5sum_with_timestamp[MD5_STRING_MAX_LEN]; /* 锟斤拷为锟截革拷锟斤拷锟斤拷锟截达拷锟斤拷md5锟斤拷锟斤拷锟斤拷全锟斤拷一锟斤拷锟斤拷, 要锟斤拷锟斤拷时锟斤拷锟 */ }pcap_pkt_detail_t; typedef struct{ - int pkt_num; /* 这个pcap包里一共多少个数据包 */ + int pkt_num; /* 锟斤拷锟絧cap锟斤拷锟斤拷一锟斤拷锟斤拷锟劫革拷锟斤拷锟捷帮拷 */ pcap_pkt_detail_t *pkt_array; }pcap_pkt_image_t; +#include "stream.h" typedef struct{ enum sapp_deploment_mode_t sapp_deploy_mode; int tap_internal_fd; int tap_external_fd; - int last_replay_fd; /* 记录是从哪个网卡发出去的, 只有双臂模式有意义, inline和mirror肯定都是tap_up */ + int last_replay_fd; /* 锟斤拷录锟角达拷锟侥革拷锟斤拷锟斤拷锟斤拷锟斤拷去锟斤拷, 只锟斤拷双锟斤拷模式锟斤拷锟斤拷锟斤拷, inline锟斤拷mirror锟较讹拷锟斤拷锟斤拷tap_up */ }pkt_process_engine_t; @@ -118,8 +111,8 @@ typedef struct{ }plug_opt_t; -/* 用于debug, 原始包注入后, 又从网卡收到的数据包, (不包括协议栈自动发出的广播、组播包), - 可能是forward的, 可能是插件新注入的, 也可能一个都没有, 都被DROP了! +/* 锟斤拷锟斤拷debug, 原始锟斤拷注锟斤拷锟, 锟街达拷锟斤拷锟斤拷锟秸碉拷锟斤拷锟斤拷锟捷帮拷, (锟斤拷锟斤拷锟斤拷协锟斤拷栈锟皆讹拷锟斤拷锟斤拷锟侥广播锟斤拷锟介播锟斤拷), + 锟斤拷锟斤拷锟斤拷forward锟斤拷, 锟斤拷锟斤拷锟角诧拷锟斤拷锟阶拷锟斤拷, 也锟斤拷锟斤拷一锟斤拷锟斤拷没锟斤拷, 锟斤拷锟斤拷DROP锟斤拷! */ typedef struct{ int pkt_index; @@ -168,9 +161,9 @@ int sapp_bchmk_create_process_engine(benchmark_engine_t *bch_engine); int sapp_bchmk_md5_checksum(const char *filename, const char *expect_md5sum); /* - 注意: - 此函数实际返回的是TRUE和FALSE, - 0表示不一样, 1表示一样!! + 注锟斤拷: + 锟剿猴拷锟斤拷实锟绞凤拷锟截碉拷锟斤拷TRUE锟斤拷FALSE, + 0锟斤拷示锟斤拷一锟斤拷, 1锟斤拷示一锟斤拷!! */ cJSON_bool sapp_bchmk_json_file_compare(benchmark_engine_t *, const char *json_file1, const char *json_file2, cJSON_Compare_Opt_t opt); diff --git a/benchmark/include/sapp_benchmark.h b/benchmark/include/sapp_benchmark.h index 0067149..401078f 100644 --- a/benchmark/include/sapp_benchmark.h +++ b/benchmark/include/sapp_benchmark.h @@ -1,23 +1,17 @@ #ifndef _SAPP_BENCHMARK_H_ #define _SAPP_BENCHMARK_H_ 1 -#include -#include #include #include +#include #include #include -#include -#include #include #include #include #include -#include -#include #include #include -#include "stream.h" #ifdef __cplusplus diff --git a/benchmark/src/sapp_benchmark.cpp b/benchmark/src/sapp_benchmark.cpp index d122591..554cdbc 100644 --- a/benchmark/src/sapp_benchmark.cpp +++ b/benchmark/src/sapp_benchmark.cpp @@ -1,16 +1,18 @@ -#include "wrap_cJSON.h" +#ifdef __cplusplus +extern "C" { +#endif +#include "wrap_cJSON.h" #include "sapp_benchmark.h" #include "sapp_bchmk_inner.h" -#include "stream.h" #include "stream_entry.h" #include #include #include #include +#include #include #include -#include #include #include #include /* See NOTES */ @@ -21,10 +23,9 @@ #include #include +#include "MESA_prof_load.h" + -#ifdef __cplusplus -extern "C" { -#endif /* 鍥犱负sapp鎻掍欢鑾峰彇涓嶅埌 benchmark_engine_t 鍙ユ焺, 鍙兘鏆傛椂闈犲叏灞鍙橀噺浼犻掍竴涓, TODO: 鏈変粈涔堟洿濂界殑鏂瑰紡? @@ -470,7 +471,6 @@ static int sapp_bchmk_env_prepare(benchmark_engine_t *bch_engine) return 0; } - /* 鏍规嵁鍐呭眰ip纭畾涓涓紶杈撴柟鍚, 鐢ㄤ簬鍙岃噦涓茶仈妯″紡浠庡摢涓綉鍗″彂鍑. */ diff --git a/benchmark/src/sapp_benchmark_utils.cpp b/benchmark/src/sapp_benchmark_utils.cpp index 40aec01..6c80c7e 100644 --- a/benchmark/src/sapp_benchmark_utils.cpp +++ b/benchmark/src/sapp_benchmark_utils.cpp @@ -1,8 +1,13 @@ +#ifdef __cplusplus +extern "C" { +#endif + #include "sapp_benchmark.h" #include #include #include #include +#include #include #include #include @@ -12,8 +17,6 @@ #include #include #include -#include "stream.h" -#include #include #include #include @@ -26,9 +29,8 @@ #include "wrap_cJSON.h" #include "sapp_bchmk_inner.h" -#ifdef __cplusplus -extern "C" { -#endif +#include "MESA_prof_load.h" + @@ -102,9 +104,9 @@ static int ifconfig_device_up(const char *interface_name) printf("Create Socket Failed.\n"); return -2; } - //指定网卡名称且up + //指锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷up sprintf(ifr.ifr_name, "%s", interface_name); - /* 获得接口的标志 */ + /* 锟斤拷媒涌诘谋锟街 */ if ((err = ioctl(socket_fd, SIOCGIFFLAGS, (void *)&ifr)) < 0) { fprintf(stderr, "ifconfig_device_up(%s), ioctl SIOCGIFFLAGS: %s\n", interface_name, strerror(errno)); close(socket_fd); @@ -143,7 +145,7 @@ int ifconfig_device_mtu(const char *interface_name, int mtu_val) return -2; } sprintf(ifr.ifr_name, "%s", interface_name); - /* 获得接口的标志 */ + /* 锟斤拷媒涌诘谋锟街 */ if ((err = ioctl(socket_fd, SIOCGIFMTU, (void *)&ifr)) < 0) { fprintf(stderr, "ifconfig_device_mtu(%s), ioctl SIOCGIFMTU: %s\n", interface_name, strerror(errno)); close(socket_fd); @@ -191,14 +193,14 @@ static int tuntap_dev_create(char *dev, int flags) ifconfig_device_up(dev); - ifconfig_device_mtu(dev, 2000); /* 某些pcap包可能开启了offload, 或者vlan, vxlan等, 增加MTU */ + ifconfig_device_mtu(dev, 2000); /* 某些pcap锟斤拷锟斤拷锟杰匡拷锟斤拷锟斤拷offload, 锟斤拷锟斤拷vlan, vxlan锟斤拷, 锟斤拷锟斤拷MTU */ return fd; } /* - 根据情况, 如果mirror, inline模式是创建一个TAP, transparent是创建两个TAP, - 直接读取解析sapp.toml文件. + 锟斤拷锟斤拷锟斤拷锟, 锟斤拷锟絤irror, inline模式锟角达拷锟斤拷一锟斤拷TAP, transparent锟角达拷锟斤拷锟斤拷锟斤拷TAP, + 直锟接讹拷取锟斤拷锟斤拷sapp.toml锟侥硷拷. */ int sapp_bchmk_create_process_engine(benchmark_engine_t *bch_engine) { @@ -289,9 +291,9 @@ int sapp_bchmk_md5_checksum(const char *filename, const char *expect_md5sum) } /* - 注意: - 此函数实际返回的是TRUE和FALSE, - 0表示不一样, 1表示一样!! + 注锟斤拷: + 锟剿猴拷锟斤拷实锟绞凤拷锟截碉拷锟斤拷TRUE锟斤拷FALSE, + 0锟斤拷示锟斤拷一锟斤拷, 1锟斤拷示一锟斤拷!! */ cJSON_bool sapp_bchmk_json_file_compare(benchmark_engine_t *bchmk_engine, const char *json_file1, const char *json_file2, cJSON_Compare_Opt_t opt) { @@ -429,7 +431,7 @@ int sapp_bchmk_gen_pcap_file(benchmark_engine_t *bchmk_engine, const pcap_pkt_de /* - 将内存中的一个原始报文, 先生成pcap文件, 再调用tshark -T 生成一个json文件. + 锟斤拷锟节达拷锟叫碉拷一锟斤拷原始锟斤拷锟斤拷, 锟斤拷锟斤拷锟斤拷pcap锟侥硷拷, 锟劫碉拷锟斤拷tshark -T 锟斤拷锟斤拷一锟斤拷json锟侥硷拷. */ int sapp_bchmk_gen_tshark_json(benchmark_engine_t *bchmk_engine, const pcap_pkt_detail_t *pkt_detail, int pkt_num, const char *tshark_json_filename) { @@ -478,7 +480,7 @@ int sapp_bchmk_need_drop_cur_pkt(benchmark_engine_t *bchmk_engine, int pkt_index array_size = cJSON_GetArraySize(sub_pkt_index_item); - /* 将C数组下标转换为wireshark的数据包序号, 其实就是加1 */ + /* 锟斤拷C锟斤拷锟斤拷锟铰憋拷转锟斤拷为wireshark锟斤拷锟斤拷锟捷帮拷锟斤拷锟, 锟斤拷实锟斤拷锟角硷拷1 */ ADJUST_ARRAY_INDEX_to_WIRESHARK(pkt_index); for(i = 0; i < array_size; i++){ @@ -492,9 +494,9 @@ int sapp_bchmk_need_drop_cur_pkt(benchmark_engine_t *bchmk_engine, int pkt_index } /* - 返回值: 要检查此包具体参数的json file name. + 锟斤拷锟斤拷值: 要锟斤拷锟剿帮拷锟斤拷锟斤拷锟斤拷锟斤拷锟絡son file name. - 如果是NULL, 需要额外判断一下errno, 是否是因为json格式错误, 没有写packet_detail_json_file. + 锟斤拷锟斤拷锟絅ULL, 锟斤拷要锟斤拷锟斤拷锟叫讹拷一锟斤拷errno, 锟角凤拷锟斤拷锟斤拷为json锟斤拷式锟斤拷锟斤拷, 没锟斤拷写packet_detail_json_file. */ const char *sapp_bchmk_need_check_forward_pkt(benchmark_engine_t *bchmk_engine, int pkt_index) { @@ -520,7 +522,7 @@ const char *sapp_bchmk_need_check_forward_pkt(benchmark_engine_t *bchmk_engine, array_size = cJSON_GetArraySize(sub_pkt_detail_item); - /* 注意: 为了方便和wireshark对比, pkt index从1开始计算, 数组下标从0开始 */ + /* 注锟斤拷: 为锟剿凤拷锟斤拷锟絯ireshark锟皆憋拷, pkt index锟斤拷1锟斤拷始锟斤拷锟斤拷, 锟斤拷锟斤拷锟铰憋拷锟0锟斤拷始 */ ADJUST_ARRAY_INDEX_to_WIRESHARK(pkt_index); for(i = 0; i < array_size; i++){ @@ -546,7 +548,7 @@ const char *sapp_bchmk_need_check_forward_pkt(benchmark_engine_t *bchmk_engine, } /* - 返回值: 指向inject块的cjson结构体指针. + 锟斤拷锟斤拷值: 指锟斤拷inject锟斤拷锟絚json锟结构锟斤拷指锟斤拷. */ const cJSON *sapp_bchmk_need_check_inject_pkt(benchmark_engine_t *bchmk_engine, int carray_pkt_index) { @@ -566,9 +568,9 @@ const cJSON *sapp_bchmk_need_check_inject_pkt(benchmark_engine_t *bchmk_engine, return NULL; } - /* 注意: 为了方便和wireshark对比, pkt index从1开始计算, 此处数组从0开始 */ + /* 注锟斤拷: 为锟剿凤拷锟斤拷锟絯ireshark锟皆憋拷, pkt index锟斤拷1锟斤拷始锟斤拷锟斤拷, 锟剿达拷锟斤拷锟斤拷锟0锟斤拷始 */ if(sub_array_pkt_index_item->valueint != (carray_pkt_index+1)){ - /* 当前包不会触发inject动作, do nothing */ + /* 锟斤拷前锟斤拷锟斤拷锟结触锟斤拷inject锟斤拷锟斤拷, do nothing */ sapp_bchmk_log(bchmk_engine,RLOG_LV_DEBUG, "pkt index:%d, don't need check inject json, ignore it", carray_pkt_index+1); errno = 0; return NULL; @@ -578,7 +580,7 @@ const cJSON *sapp_bchmk_need_check_inject_pkt(benchmark_engine_t *bchmk_engine, } /* - 返回值: 指向control块的cjson结构体指针. + 锟斤拷锟斤拷值: 指锟斤拷control锟斤拷锟絚json锟结构锟斤拷指锟斤拷. */ const cJSON *sapp_bchmk_need_process_control(benchmark_engine_t *bchmk_engine, int carray_pkt_index) { @@ -604,13 +606,13 @@ const cJSON *sapp_bchmk_need_process_control(benchmark_engine_t *bchmk_engine, i /* - 每次测试前, 都用sapp的默认配置覆盖运行环境, - 需要修改的配置参数, 每次也要现场修改, - 避免因默认参数错误导致测试不通过. + 每锟轿诧拷锟斤拷前, 锟斤拷锟斤拷sapp锟斤拷默锟斤拷锟斤拷锟矫革拷锟斤拷锟斤拷锟叫伙拷锟斤拷, + 锟斤拷要锟睫改碉拷锟斤拷锟矫诧拷锟斤拷, 每锟斤拷也要锟街筹拷锟睫革拷, + 锟斤拷锟斤拷锟斤拷默锟较诧拷锟斤拷锟斤拷锟斤拷锟铰诧拷锟皆诧拷通锟斤拷. - 将sapp的配置文件直接翻译成了.c数组, 这样cmake install, 即rpm -i时就不用装一堆文件了, - 而且如果安装时使用--prefix参数, 程序就找不到这些文件了. - 直接从程序里copy即可. + 锟斤拷sapp锟斤拷锟斤拷锟斤拷锟侥硷拷直锟接凤拷锟斤拷锟斤拷锟.c锟斤拷锟斤拷, 锟斤拷锟斤拷cmake install, 锟斤拷rpm -i时锟酵诧拷锟斤拷装一锟斤拷锟侥硷拷锟斤拷, + 锟斤拷锟斤拷锟斤拷锟斤拷锟阶笆笔癸拷锟--prefix锟斤拷锟斤拷, 锟斤拷锟斤拷锟斤拷也锟斤拷锟斤拷锟叫╋拷募锟斤拷锟. + 直锟接从筹拷锟斤拷锟斤拷copy锟斤拷锟斤拷. */ static void sapp_bchmk_write_to_file(const char *config_name, const void *content, int content_len) @@ -657,7 +659,7 @@ void sapp_bchmk_set_default_config(void) sapp_bchmk_write_to_file("etc/send_raw_pkt.conf", templete_send_raw_pkt, templete_send_raw_pkt_len); sapp_bchmk_write_to_file("etc/send_log.conf", templete_sapp_log, templete_sapp_log_len); - /* 情况插件plug.inf内容, 只保留最基本头部字段 */ + /* 锟斤拷锟斤拷锟斤拷plug.inf锟斤拷锟斤拷, 只锟斤拷锟斤拷锟斤拷锟斤拷锟酵凤拷锟斤拷侄锟 */ system("mkdir -p ./plug/business/gtest_sapp"); system("echo \"[PLUGINFO]\" > ./plug/business/gtest_sapp/gtest_sapp.inf"); system("echo \"PLUGNAME=xxxx\" >> ./plug/business/gtest_sapp/gtest_sapp.inf"); @@ -734,7 +736,7 @@ const char *sapp_bchmk_rawpkt_ntop_v6(const struct ip6_hdr *ip6hdr, char *res_bu dport = inner_uhdr->dest; snprintf(res_buf, buf_len, "%s.%u --> %s.%u, %s", ip_src_str, ntohs(sport), ip_dst_str, ntohs(dport), "UDP"); - }else if(IPPROTO_ICMPV6 == inner_ip_proto){ /* 注意: ipv6的icmp头部字段与ipv4不一致!! */ + }else if(IPPROTO_ICMPV6 == inner_ip_proto){ /* 注锟斤拷: ipv6锟斤拷icmp头锟斤拷锟街讹拷锟斤拷ipv4锟斤拷一锟斤拷!! */ snprintf(res_buf, buf_len, "%s --> %s,ICMP", ip_src_str, ip_dst_str); }else{ snprintf(res_buf, buf_len, "%s --> %s, unknown protocol:%u", ip_src_str, ip_dst_str, inner_ip_proto); diff --git a/include/private/mesa_net.h b/include/private/mesa_net.h index ceff7cc..4da2513 100644 --- a/include/private/mesa_net.h +++ b/include/private/mesa_net.h @@ -1,7 +1,5 @@ -#ifndef _MESA_NET_H_ -#define _MESA_NET_H_ +#pragma once -#include #include #include #include @@ -412,8 +410,8 @@ struct mesa_pppoe_session_hdr{ unsigned short session_id; unsigned short len; /* to do: - ppp应该单独作为一层存在, 为了简化处理, 强制将其和PPPOE_SES绑在一起, - 如果需要监听PPP协商过程, 此结构需要改动. + ppp应锟矫碉拷锟斤拷锟斤拷为一锟斤拷锟斤拷锟, 为锟剿简化达拷锟斤拷, 强锟狡斤拷锟斤拷锟絇PPOE_SES锟斤拷锟斤拷一锟斤拷, + 锟斤拷锟斤拷锟揭拷锟斤拷锟絇PP协锟教癸拷锟斤拷, 锟剿结构锟斤拷要锟侥讹拷. */ unsigned short ppp_protocol; }BYTE_ALIGNED(1); @@ -500,11 +498,11 @@ enum pptp_control_message_type{ }; struct mesa_pptp_control_hdr{ - unsigned short length; /* 全部数据长度, 包括本头部 */ + unsigned short length; /* 全锟斤拷锟斤拷锟捷筹拷锟斤拷, 锟斤拷锟斤拷锟斤拷头锟斤拷 */ unsigned short pptp_message_type; unsigned int magic_cookie; unsigned short control_message_type; - char ignore_bytes[0]; /* 后续字段暂不关心, 长度也不一定 */ + char ignore_bytes[0]; /* 锟斤拷锟斤拷锟街讹拷锟捷诧拷锟斤拷锟斤拷, 锟斤拷锟斤拷也锟斤拷一锟斤拷 */ }; struct mesa_vlan_hdr{ @@ -520,7 +518,7 @@ struct mesa_vlan_detail_hdr{ unsigned short type; }; -/* 2018-08-28 lijia add, for pangu 项目mac_in_mac回流 */ +/* 2018-08-28 lijia add, for pangu 锟斤拷目mac_in_mac锟斤拷锟斤拷 */ struct mesa_mac_in_mac_net_hdr{ unsigned int route_dir:1; unsigned int link_id:3; @@ -595,7 +593,7 @@ struct mesa_gre_base_hdr_v1{ unsigned short protocol; }; -#define GRE_SRE_MAX_LEN (256) /* 长度最长为一个字节, 256 */ +#define GRE_SRE_MAX_LEN (256) /* 锟斤拷锟斤拷锟筋长为一锟斤拷锟街斤拷, 256 */ struct gre_source_route_entry_hdr{ unsigned short address_family; unsigned char sre_offset; @@ -603,7 +601,7 @@ struct gre_source_route_entry_hdr{ unsigned char sre_entry_list[GRE_SRE_MAX_LEN]; }; -/* 所有可能的值均在, 需要根据mesa_gre_base_hdr各个bit的值, 判断是否含有如下值 */ +/* 锟斤拷锟叫匡拷锟杰碉拷值锟斤拷锟斤拷, 锟斤拷要锟斤拷锟斤拷mesa_gre_base_hdr锟斤拷锟斤拷bit锟斤拷值, 锟叫讹拷锟角凤拷锟斤拷锟斤拷锟斤拷值 */ struct mesa_gre_extend_hdr{ unsigned short checksum; //version0 unsigned short offset; //version0, if checksum present, then offset also present @@ -616,7 +614,7 @@ struct mesa_gre_extend_hdr{ }; struct mesa_gre_hdr{ - /* version0和version1的头部中, version字段时一致的, 其他有小区别, 默认使用v0方式解析 */ + /* version0锟斤拷version1锟斤拷头锟斤拷锟斤拷, version锟街讹拷时一锟铰碉拷, 锟斤拷锟斤拷锟斤拷小锟斤拷锟斤拷, 默锟斤拷使锟斤拷v0锟斤拷式锟斤拷锟斤拷 */ struct mesa_gre_base_hdr_v0 gre_base; struct mesa_gre_extend_hdr gre_extend; }; @@ -732,8 +730,8 @@ struct l2tp_avp{ #define ISAKMP_EXCHANGE_TYPE_AUTH (3) #define ISAKMP_EXCHANGE_TYPE_AGGRESS (4)/* RFC-2409 page8, Aggressive mode is instantiation os ISAKMP Aggressive Exchange */ #define ISAKMP_EXCHANGE_TYPE_INFO (5) -#define ISAKMP_EXCHANGE_TYPE_FEATURE_USE_BEGIN (6) /* 6-31的值暂不可用 */ -#define ISAKMP_EXCHANGE_TYPE_FEATURE_USE_END (31) /* 6-31的值暂不可用 */ +#define ISAKMP_EXCHANGE_TYPE_FEATURE_USE_BEGIN (6) /* 6-31锟斤拷值锟捷诧拷锟斤拷锟斤拷 */ +#define ISAKMP_EXCHANGE_TYPE_FEATURE_USE_END (31) /* 6-31锟斤拷值锟捷诧拷锟斤拷锟斤拷 */ struct mesa_isakmp_hdr{ /* RFC2408-Page22 */ unsigned long long init_cookie; @@ -807,14 +805,14 @@ struct teredo_auth_hdr{ #define MAX_ADDR_TYPE_STRING_LEN (64) #define MAX_ADDR_LIST_STRING_LEN (2048) -#define MAX_ADDR_EMBED_LAYER_NUM (20) /* 最大地址嵌套层数 */ -#define MAX_ADDR_BIN_VALUE_LEN (40) /* paddr实际内容最大长度, 目前是tuple4v6最长 */ +#define MAX_ADDR_EMBED_LAYER_NUM (20) /* 锟斤拷锟斤拷址嵌锟阶诧拷锟斤拷 */ +#define MAX_ADDR_BIN_VALUE_LEN (40) /* paddr实锟斤拷锟斤拷锟斤拷锟斤拷蟪ざ锟, 目前锟斤拷tuple4v6锟筋长 */ -/* 串联模式下, 记录MAC地址用于发包 */ +/* 锟斤拷锟斤拷模式锟斤拷, 锟斤拷录MAC锟斤拷址锟斤拷锟节凤拷锟斤拷 */ struct packet_io_mac_addr{ struct mesa_ethernet_hdr eth_hdr; char route_dir; - char __pad__; /* 整体结构8字节对齐 */ + char __pad__; /* 锟斤拷锟斤拷峁8锟街节讹拷锟斤拷 */ }; @@ -827,7 +825,7 @@ struct hdlc_net_hdr{ -/* 关于网络相关字段, 均为网络序, network order */ +/* 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷侄锟, 锟斤拷为锟斤拷锟斤拷锟斤拷, network order */ #define VXLAN_KEEPALIVE_PKT_PORT (3784) #define VXLAN_OVERLAY_PKT_PORT (4789) @@ -843,7 +841,7 @@ struct __inline_vxlan_hdr{ unsigned char reserved[3]; /*--------int delim -------*/ unsigned char vlan_id_half_high; - unsigned char link_layer_type : 4; /* 二层报文封装格式 */ + unsigned char link_layer_type : 4; /* 锟斤拷锟姐报锟侥凤拷装锟斤拷式 */ unsigned char vlan_id_half_low : 4; unsigned int dir : 1; @@ -879,5 +877,4 @@ const char *sapp_raw_ipv6_ntop(const struct mesa_ip6_hdr *ip6_hdr, char *out_buf } #endif -#endif diff --git a/include/private/sapp_declaration.h b/include/private/sapp_declaration.h index 4d11b23..6b9c21c 100644 --- a/include/private/sapp_declaration.h +++ b/include/private/sapp_declaration.h @@ -98,6 +98,7 @@ extern volatile long long g_current_time_ms; #define g_ipv6_send_packet_enabled sapp_global_val->config.protocol_feature.ipv6_send_packet_enabled #define G_SKIP_NOT_IP_LAYER sapp_global_val->config.protocol_feature.skip_not_ip_layer_over_eth +#include "MESA_handle_logger.h" #define sapp_runtime_log(log_level, format, ...) \ do \ { \ diff --git a/include/private/stream_internal.h b/include/private/stream_internal.h index e103920..f68b518 100644 --- a/include/private/stream_internal.h +++ b/include/private/stream_internal.h @@ -2,14 +2,10 @@ #define _APP_STREAM_INTERNAL_H_ #include "mesa_net.h" -#include "public/stream.h" #include "private/mesa_net.h" -#include "private/sysinfo.h" -#include "MESA_handle_logger.h" #include "mesa_pkt_dump.h" #include "sapp_limits.h" -#include "sapp_mem.h" -#include "MESA_jump_layer.h" +#include "stream.h" //#define STREAM_BASE_MD5_CHECK "dd09b3b11993cc835200db477dad7d4b" //#define STREAM_CONTROL_MD5_CHECK "75aab0821e489b84355fa22ad02a2e78" diff --git a/include/public/stream_inc/MESA_jump_layer.h b/include/public/stream_inc/MESA_jump_layer.h deleted file mode 100644 index d5715fe..0000000 --- a/include/public/stream_inc/MESA_jump_layer.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef __MESA_JUMP_LAYER_H_ -#define __MESA_JUMP_LAYER_H_ 1 -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#include "stream.h" -#include -#include - - -const char *MESA_jump_layer_get_last_error(void); - - -/* - CHN : 数据包头部偏移函数. - - 参数: - raw_data: 当前层的头部指针; - raw_layer_type: 当前层的地址类型, 详见: enum addr_type_t ; - expect_layer_type: 期望跳转到的地址类型, 详见: enum addr_type_t ; - - 返回值: - NULL: 无此地址; - NON-NULL: 对应层的头部地址. - - 举例: - 假设当前层为Ethernet, 起始包头地址为this_layer_hdr, 想跳转到IPv6层头部: - 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与MESA_jump_layer的区别: - 对于隧道嵌套协议来说, - MESA_jump_layer跳转到第一个expect_layer_type; - MESA_jump_layer_greedy跳转到最内层的expect_layer_type; -*/ -const void *MESA_jump_layer_greedy(const void *raw_data, int raw_layer_type, int expect_layer_type); - - - -/* 向前兼容以前的接口名称, 作用同上 */ -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 diff --git a/include/public/stream_inc/stream_base.h b/include/public/stream_inc/stream_base.h index 0bf8f55..58d78d4 100644 --- a/include/public/stream_inc/stream_base.h +++ b/include/public/stream_inc/stream_base.h @@ -5,13 +5,7 @@ #include #include -#include -#include -#include -#include #include -#include -#include #ifndef UINT8 typedef unsigned char UINT8; @@ -30,28 +24,28 @@ typedef unsigned int UINT32; typedef unsigned long long UINT64; #endif -/* CHN : 流的方向定义 */ +/* CHN : 锟斤拷锟侥凤拷锟斤拷锟斤拷 */ /* ENG : stream direction definition*/ #define DIR_C2S 0x01 #define DIR_S2C 0x02 #define DIR_DOUBLE 0x03 -/* CHN : 网络底层传输方向定义,串联模式有意义 */ +/* CHN : 锟斤拷锟斤拷撞愦拷浞斤拷锟斤拷锟,锟斤拷锟斤拷模式锟斤拷锟斤拷锟斤拷 */ /* ENG : network topology route direction, is valid in serial mode */ #define DIR_ROUTE_UP 0x00 #define DIR_ROUTE_DOWN 0x01 -/* CHN : 单包的类型定义 */ +/* CHN : 锟斤拷锟斤拷锟斤拷锟斤拷锟酵讹拷锟斤拷 */ /* ENG : single packet type definition */ #define PKT_TYPE_NORMAL (0x0) /* normal, common */ -#define PKT_TYPE_IPREBUILD (1<<0) /* ip frag reassembled packet; ip碎片重组报文 */ -#define PKT_TYPE_TCPUNORDER (1<<1) /* TCP out of order packet; TCP乱序报文 */ -#define PKT_TYPE_TCPREORDER (1<<2) /* TCP sequential packet; TCP乱序排序好的数据包 */ -#define PKT_TYPE_TCPRETRANS (1<<3) /* TCP retransmit packet; TCP重传报文 */ -#define PKT_TYPE_IP_FRAG (1<<4) /* IP frag packet; IP分片包 */ -#define PKT_TYPE_IP_FRAG_LAST (1<<5) /* last IP frag packet; 同属于一个原始完整IP包的最后一个IP分片包 */ - -/* CHN : 地址类型定义, 可通过函数 addr_type_to_string() 转成字符串形式. */ +#define PKT_TYPE_IPREBUILD (1<<0) /* ip frag reassembled packet; ip锟斤拷片锟斤拷锟介报锟斤拷 */ +#define PKT_TYPE_TCPUNORDER (1<<1) /* TCP out of order packet; TCP锟斤拷锟斤拷锟斤拷 */ +#define PKT_TYPE_TCPREORDER (1<<2) /* TCP sequential packet; TCP锟斤拷锟斤拷锟斤拷锟斤拷玫锟斤拷锟斤拷莅锟 */ +#define PKT_TYPE_TCPRETRANS (1<<3) /* TCP retransmit packet; TCP锟截达拷锟斤拷锟斤拷 */ +#define PKT_TYPE_IP_FRAG (1<<4) /* IP frag packet; IP锟斤拷片锟斤拷 */ +#define PKT_TYPE_IP_FRAG_LAST (1<<5) /* last IP frag packet; 同锟斤拷锟斤拷一锟斤拷原始锟斤拷锟斤拷IP锟斤拷锟斤拷锟斤拷锟揭伙拷锟絀P锟斤拷片锟斤拷 */ + +/* CHN : 锟斤拷址锟斤拷锟酵讹拷锟斤拷, 锟斤拷通锟斤拷锟斤拷锟斤拷 addr_type_to_string() 转锟斤拷锟街凤拷锟斤拷锟斤拷式. */ /* ENG : address type, transform to string mode by call addr_type_to_string(). */ enum addr_type_t{ __ADDR_TYPE_INIT = 0, @@ -80,14 +74,14 @@ enum addr_type_t{ #define TCP_TAKEOVER_STATE_FLAG_ON 1 -/* CHN : 应用层看到的链接状态定义 */ +/* CHN : 应锟矫层看锟斤拷锟斤拷锟斤拷锟斤拷状态锟斤拷锟斤拷 */ /* ENG : stream state for protocol or business plug*/ #define OP_STATE_PENDING 0 #define OP_STATE_TIMED 1 /* is obsolete */ #define OP_STATE_CLOSE 2 #define OP_STATE_DATA 3 -/* CHN : 应用层返回结果定义 */ +/* CHN : 应锟矫层返锟截斤拷锟斤拷锟斤拷锟 */ /* ENG : return value of plug */ #define APP_STATE_GIVEME 0x00 #define APP_STATE_FAWPKT 0x00 @@ -98,14 +92,14 @@ enum addr_type_t{ #define APP_STATE_DROPPKT 0x10 -#define APP_STATE_KILL_FOLLOW 0x40 /* 强制CLOSE当前插件后续的所有插件 */ -#define APP_STATE_KILL_OTHER 0x80 /* 强制CLOSE除当前插件外的所有插件 */ +#define APP_STATE_KILL_FOLLOW 0x40 /* 强锟斤拷CLOSE锟斤拷前锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷胁锟斤拷 */ +#define APP_STATE_KILL_OTHER 0x80 /* 强锟斤拷CLOSE锟斤拷锟斤拷前锟斤拷锟斤拷锟斤拷锟斤拷锟叫诧拷锟 */ -/* CHN : 流的类型定义 */ +/* CHN : 锟斤拷锟斤拷锟斤拷锟酵讹拷锟斤拷 */ /* ENG : stream type */ enum stream_type_t{ - STREAM_TYPE_NON = 0, /* No stream concept indeed, such as vlan, IP, etc.; 无流的概念, 如VLAN, IP层等 */ + STREAM_TYPE_NON = 0, /* No stream concept indeed, such as vlan, IP, etc.; 锟斤拷锟斤拷锟侥革拷锟斤拷, 锟斤拷VLAN, IP锟斤拷锟 */ STREAM_TYPE_TCP, STREAM_TYPE_UDP, /* there is no stream of UDP in RFC, but in MESA platform, we build a UDP stream with same tuple4 packet */ STREAM_TYPE_VLAN, @@ -120,12 +114,12 @@ enum stream_type_t{ }; /* - CHN: 流的底层承载隧道类型, - 不同于stream_type_t, 比如当前流为STREAM_TYPE_TCP, 但底层隧道类型可能是STREAM_TUNNLE_PPTP. - 因为隧道可能是多种不同类型嵌套组合, 只记录最底层(离MAC层最近的)隧道类型. + CHN: 锟斤拷锟侥底诧拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟, + 锟斤拷同锟斤拷stream_type_t, 锟斤拷锟界当前锟斤拷为STREAM_TYPE_TCP, 锟斤拷锟阶诧拷锟斤拷锟斤拷锟斤拷锟酵匡拷锟斤拷锟斤拷STREAM_TUNNLE_PPTP. + 锟斤拷为锟斤拷锟斤拷锟斤拷锟斤拷锟角讹拷锟街诧拷同锟斤拷锟斤拷嵌锟斤拷锟斤拷锟, 只锟斤拷录锟斤拷撞锟(锟斤拷MAC锟斤拷锟斤拷锟斤拷锟)锟斤拷锟斤拷锟斤拷锟斤拷. */ enum stream_carry_tunnel_t{ - STREAM_TUNNLE_NON = 0, /* default is 0, not tunnel; 默认为0, 非隧道; */ + STREAM_TUNNLE_NON = 0, /* default is 0, not tunnel; 默锟斤拷为0, 锟斤拷锟斤拷锟斤拷; */ STREAM_TUNNLE_6OVER4 = 1 << 0, STREAM_TUNNLE_4OVER6 = 1 << 1, STREAM_TUNNLE_GRE = 1 << 2, @@ -138,7 +132,7 @@ enum stream_carry_tunnel_t{ }; typedef struct raw_ipfrag_list{ - void *frag_packet; /* 非ip包头, 从底层网卡获取的原始包头 */ + void *frag_packet; /* 锟斤拷ip锟斤拷头, 锟接底诧拷锟斤拷锟斤拷锟斤拷取锟斤拷原始锟斤拷头 */ int pkt_len; int type; /* IPv4 or IPv6 */ struct raw_ipfrag_list *next; @@ -147,7 +141,7 @@ typedef struct raw_ipfrag_list{ #ifndef STRUCT_TUPLE4_DEFINED #define STRUCT_TUPLE4_DEFINED (1) -/* compat for start, papp; 兼容start, papp */ +/* compat for start, papp; 锟斤拷锟斤拷start, papp */ struct tuple4 { u_int saddr; u_int daddr; @@ -235,9 +229,9 @@ struct layer_addr_pppoe_session struct layer_addr_mac { /* - C2S和S2C方向来自不同的链路和设备, 会导致两个方向的mac地址全不一样, 反向注入时不能用传统方式, 即简单的颠倒src和dst, - 修改定义如下, mirror模式下, 还是存储在src_addr中, - API不同了, ABI还是向前兼容的, 结构体内存分布与之前的一致. + C2S锟斤拷S2C锟斤拷锟斤拷锟斤拷锟皆诧拷同锟斤拷锟斤拷路锟斤拷锟借备, 锟结导锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟絤ac锟斤拷址全锟斤拷一锟斤拷, 锟斤拷锟斤拷注锟斤拷时锟斤拷锟斤拷锟矫达拷统锟斤拷式, 锟斤拷锟津单的颠碉拷src锟斤拷dst, + 锟睫改讹拷锟斤拷锟斤拷锟斤拷, mirror模式锟斤拷, 锟斤拷锟角存储锟斤拷src_addr锟斤拷, + API锟斤拷同锟斤拷, ABI锟斤拷锟斤拷锟斤拷前锟斤拷锟捷碉拷, 锟结构锟斤拷锟节达拷植锟斤拷锟街帮拷锟揭伙拷锟. */ struct ethhdr src_addr; struct ethhdr dst_addr; @@ -251,9 +245,9 @@ struct layer_addr_ipv4 UINT32 saddr; /* network order */ UINT32 daddr; /* network order */ /* 2014-04-21 lijia add, - 为了节约内存空间、和处理效率, 不强制按协议层次处理, - IP层和TCP层做为一个层, - 对于隧道外层IP, 端口信息为0; + 为锟剿斤拷约锟节达拷占洹拷痛锟斤拷锟叫э拷锟, 锟斤拷强锟狡帮拷协锟斤拷锟轿达拷锟斤拷, + IP锟斤拷锟絋CP锟斤拷锟斤拷为一锟斤拷锟斤拷, + 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟絀P, 锟剿匡拷锟斤拷息为0; */ UINT16 source; /* network order */ UINT16 dest; /* network order */ @@ -264,9 +258,9 @@ struct layer_addr_ipv6 UCHAR saddr[IPV6_ADDR_LEN] ; /* network order */ UCHAR daddr[IPV6_ADDR_LEN] ; /* network order */ /* 2014-04-21 lijia add, - 为了节约内存空间、和处理效率, 不强制按协议层次处理, - IP层和TCP层做为一个层, - 对于隧道外层IP, 端口信息为0; + 为锟剿斤拷约锟节达拷占洹拷痛锟斤拷锟叫э拷锟, 锟斤拷强锟狡帮拷协锟斤拷锟轿达拷锟斤拷, + IP锟斤拷锟絋CP锟斤拷锟斤拷为一锟斤拷锟斤拷, + 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟絀P, 锟剿匡拷锟斤拷息为0; */ UINT16 source;/* network order */ UINT16 dest;/* network order */ @@ -291,17 +285,17 @@ struct layer_ppp_hdr{ unsigned short protocol; /* network order */ }__attribute__((packed)); -/* 一般情况下, address,control都是固定不变的,都是0xFF,0x03, ppp hdr是可以压缩以节约贷款,只传输一个字节的protocol字段 */ +/* 一锟斤拷锟斤拷锟斤拷锟, address,control锟斤拷锟角固讹拷锟斤拷锟斤拷锟,锟斤拷锟斤拷0xFF,0x03, ppp hdr锟角匡拷锟斤拷压锟斤拷锟皆斤拷约锟斤拷锟斤拷,只锟斤拷锟斤拷一锟斤拷锟街节碉拷protocol锟街讹拷 */ struct layer_compress_ppp_hdr{ unsigned char protocol; }; struct layer_addr_l2tp_v2_t{ - UINT16 tunnelid_C2S; /* network order, 以传输层创建流的方向为准 */ - UINT16 tunnelid_S2C; /* network order, 以传输层创建流的方向为准 */ - UINT16 sessionid_C2S; /* network order, 以传输层创建流的方向为准 */ - UINT16 sessionid_S2C; /* network order, 以传输层创建流的方向为准 */ + UINT16 tunnelid_C2S; /* network order, 锟皆达拷锟斤拷愦达拷锟斤拷锟斤拷姆锟斤拷锟轿 */ + UINT16 tunnelid_S2C; /* network order, 锟皆达拷锟斤拷愦达拷锟斤拷锟斤拷姆锟斤拷锟轿 */ + UINT16 sessionid_C2S; /* network order, 锟皆达拷锟斤拷愦达拷锟斤拷锟斤拷姆锟斤拷锟轿 */ + UINT16 sessionid_S2C; /* network order, 锟皆达拷锟斤拷愦达拷锟斤拷锟斤拷姆锟斤拷锟轿 */ unsigned char seq_present_C2S; unsigned char seq_present_S2C; unsigned char ppp_hdr_compress_enable; @@ -335,15 +329,15 @@ struct single_layer_mpls_addr{ /* refer to RFC3032 */ }; /* - MPLS有可能是多层嵌套, sapp把多层合并处理, 目前最大支持4层, 层次序号由外到内排列, 0表示最外层, 3表示最内层 - 对于一个内层TCP/UDP流来说, 底层MPLS两个方向的地址可能不一样, 分别记为cs2_addr, s2c_addr. + MPLS锟叫匡拷锟斤拷锟角讹拷锟角讹拷锟, sapp锟窖讹拷锟较诧拷锟斤拷锟斤拷, 目前锟斤拷锟街э拷锟4锟斤拷, 锟斤拷锟斤拷锟斤拷锟斤拷锟解到锟斤拷锟斤拷锟斤拷, 0锟斤拷示锟斤拷锟斤拷锟, 3锟斤拷示锟斤拷锟节诧拷 + 锟斤拷锟斤拷一锟斤拷锟节诧拷TCP/UDP锟斤拷锟斤拷说, 锟阶诧拷MPLS锟斤拷锟斤拷锟斤拷锟斤拷牡锟街凤拷锟斤拷懿锟揭伙拷锟, 锟街憋拷锟轿猚s2_addr, s2c_addr. */ struct layer_addr_mpls { struct single_layer_mpls_addr c2s_addr_array[MAX_MPLS_ADDR_LAYER]; struct single_layer_mpls_addr s2c_addr_array[MAX_MPLS_ADDR_LAYER]; - char c2s_layer_num; /* 实际mpls层数 */ - char s2c_layer_num; /* 实际mpls层数 */ + char c2s_layer_num; /* 实锟斤拷mpls锟斤拷锟斤拷 */ + char s2c_layer_num; /* 实锟斤拷mpls锟斤拷锟斤拷 */ char c2s_has_ctrl_word; char s2c_has_ctrl_word; unsigned int c2s_mpls_ctrl_word; /* refer to RFC4623 */ @@ -353,8 +347,8 @@ struct layer_addr_mpls struct layer_addr_pptp { - UINT16 C2S_call_id; /* C2S以传输层协议方向为准, TCP SYN为C2S, UDP源端口大的为C2S, callid, network order */ - UINT16 S2C_call_id; /* S2Ck以传输层协议方向为准, TCP SYN/ACK为S2C, UDP目的端口大的为S2C, callid, network order */ + UINT16 C2S_call_id; /* C2S锟皆达拷锟斤拷锟叫拷榉斤拷锟轿, TCP SYN为C2S, UDP源锟剿口达拷锟轿狢2S, callid, network order */ + UINT16 S2C_call_id; /* S2Ck锟皆达拷锟斤拷锟叫拷榉斤拷锟轿, TCP SYN/ACK为S2C, UDP目锟侥端口达拷锟轿猄2C, callid, network order */ }; struct layer_addr_gtp @@ -366,10 +360,10 @@ struct layer_addr_gtp #define MAC_IN_MAC_HDR_LEN (sizeof(struct mesa_ethernet_hdr) + sizeof(struct mesa_ethernet_hdr)) struct layer_addr_mac_in_mac { - UCHAR outer_dst_mac[MAC_ADDR_LEN]; /* 最外层mac地址, network order */ - UCHAR outer_src_mac[MAC_ADDR_LEN]; /* 最外层mac地址, network order */ - UCHAR inner_dst_mac[MAC_ADDR_LEN]; /* 内层mac地址, network order */ - UCHAR inner_src_mac[MAC_ADDR_LEN]; /* 内层mac地址, network order */ + UCHAR outer_dst_mac[MAC_ADDR_LEN]; /* 锟斤拷锟斤拷锟絤ac锟斤拷址, network order */ + UCHAR outer_src_mac[MAC_ADDR_LEN]; /* 锟斤拷锟斤拷锟絤ac锟斤拷址, network order */ + UCHAR inner_dst_mac[MAC_ADDR_LEN]; /* 锟节诧拷mac锟斤拷址, network order */ + UCHAR inner_src_mac[MAC_ADDR_LEN]; /* 锟节诧拷mac锟斤拷址, network order */ }; struct single_layer_addr_vxlan @@ -420,7 +414,7 @@ struct layer_addr }; -/* CHN : 保留此结构用于和papp兼容, 用作指针时, 可与struct layer_addr强转 */ +/* CHN : 锟斤拷锟斤拷锟剿结构锟斤拷锟节猴拷papp锟斤拷锟斤拷, 锟斤拷锟斤拷指锟斤拷时, 锟斤拷锟斤拷struct layer_addr强转 */ /* ENG : compat for papp, can be transform to struct layer_addr pointer */ struct ipaddr { @@ -467,7 +461,7 @@ struct udpdetail struct streaminfo { struct layer_addr addr; - struct streaminfo *pfather; /* this stream's carry layer stream; 上层流结构体 */ + struct streaminfo *pfather; /* this stream's carry layer stream; 锟较诧拷锟斤拷锟结构锟斤拷 */ UCHAR type; /* stream type, definition in enum stream_type_t */ UCHAR threadnum; UCHAR dir; /* valid in all stream life, current stream direction state, 0x01:c-->s; 0x02:s-->c; 0x03 c<-->s; */ @@ -504,13 +498,13 @@ typedef struct { extern "C" { #endif -/* CHN : 内存管理相关函数, 基于平台的插件必须使用此类函数申请或释放内存 */ +/* CHN : 锟节达拷锟斤拷锟斤拷锟截猴拷锟斤拷, 锟斤拷锟斤拷平台锟侥诧拷锟斤拷锟斤拷锟绞癸拷么锟斤拷嗪拷锟斤拷锟斤拷锟斤拷锟酵凤拷锟节达拷 */ /* ENG : memory management function, plugs must call these functions instead of malloc, free in */ void *dictator_malloc(int thread_seq,size_t size); void dictator_free(int thread_seq,void *pbuf); void *dictator_realloc(int thread_seq, void* pbuf, size_t size); -/* CHN : 获取当前系统运行的并发处理线程总数 */ +/* CHN : 锟斤拷取锟斤拷前系统锟斤拷锟叫的诧拷锟斤拷锟斤拷锟斤拷锟竭筹拷锟斤拷锟斤拷 */ /* ENG : get current total thread of platfomr */ int get_thread_count(void); @@ -520,19 +514,19 @@ long long get_timestamp_ms(void); //if return -1, it means caller not in worker thread context int get_current_worker_thread_id(); -/* CHN : 将地enum addr_type_t址类型转换成可打印的字符串形式 */ +/* CHN : 锟斤拷锟斤拷enum addr_type_t址锟斤拷锟斤拷转锟斤拷锟缴可达拷印锟斤拷锟街凤拷锟斤拷锟斤拷式 */ /* ENG : transform binary addr_type_t to string mode */ const char *addr_type_to_string(enum addr_type_t type); /* ENG : transform tuple4 to string mode, must used in packet process thread context; - CHN : 将layer_addr地址转换成字符串形式, 必须用在包处理线程. + CHN : 锟斤拷layer_addr锟斤拷址转锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷式, 锟斤拷锟斤拷锟斤拷锟节帮拷锟斤拷锟斤拷锟竭筹拷. */ const char *printaddr (const struct layer_addr *paddrinfo, int threadindex); /* ENG : a reentrant version of printaddr, thread safe; - CHN : printaddr的可重入版本, 是线程安全的. + CHN : printaddr锟侥匡拷锟斤拷锟斤拷姹, 锟斤拷锟竭程帮拷全锟斤拷. */ const char *printaddr_r(const struct layer_addr *paddrinfo, char *out_buf, int out_buf_len); @@ -540,45 +534,45 @@ const char *printaddr_r(const struct layer_addr *paddrinfo, char *out_buf, int o /* ENG : transform layer address to string mode, must used in packet process thread context, the return value is read-only, user can't free it; - CHN : 将layer_addr地址转换成字符串形式, 必须用在包处理线程, 返回的指针为只读, 使用者不必free. + CHN : 锟斤拷layer_addr锟斤拷址转锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷式, 锟斤拷锟斤拷锟斤拷锟节帮拷锟斤拷锟斤拷锟竭筹拷, 锟斤拷锟截碉拷指锟斤拷为只锟斤拷, 使锟斤拷锟竭诧拷锟斤拷free. */ const char *layer_addr_ntop(const struct streaminfo *pstream); /* ENG : a reentrant version of layer_addr_ntop, thread safe, return a pointer to the destination string 'out_buf'; - CHN : layer_addr_ntop_r的可重入版本, 是线程安全的, 返回的指针执向使用者提供的out_buf, 便于代码组织. + CHN : layer_addr_ntop_r锟侥匡拷锟斤拷锟斤拷姹, 锟斤拷锟竭程帮拷全锟斤拷, 锟斤拷锟截碉拷指锟斤拷执锟斤拷使锟斤拷锟斤拷锟结供锟斤拷out_buf, 锟斤拷锟节达拷锟斤拷锟斤拷织. */ char *layer_addr_ntop_r(const struct streaminfo *pstream, char *out_buf, int out_buf_len); /* ENG : transform layer type to abbr string mode, is reentrant, the return value is read-only, user can't free it;. - CHN : 将layer_addr地址类型转换成缩写字符串形式, 可重入线程安全, 返回的指针为只读, 使用者不必free.. + CHN : 锟斤拷layer_addr锟斤拷址锟斤拷锟斤拷转锟斤拷锟斤拷锟斤拷写锟街凤拷锟斤拷锟斤拷式, 锟斤拷锟斤拷锟斤拷锟竭程帮拷全, 锟斤拷锟截碉拷指锟斤拷为只锟斤拷, 使锟斤拷锟竭诧拷锟斤拷free.. */ const char *layer_addr_prefix_ntop(const struct streaminfo *pstream); /* ENG : duplicate a same layer_addr struct, memory obtained with malloc(3); - CHN : 复制一个完全相同的layer_addr结构体, 内存通过malloc(3)获取. + CHN : 锟斤拷锟斤拷一锟斤拷锟斤拷全锟斤拷同锟斤拷layer_addr锟结构锟斤拷, 锟节达拷通锟斤拷malloc(3)锟斤拷取. */ struct layer_addr * layer_addr_dup(const struct layer_addr *paddrinfo); /* ENG: used to free all memory of paddrinfo; - CHN: 用于释放paddrinfo内存. + CHN: 锟斤拷锟斤拷锟酵凤拷paddrinfo锟节达拷. */ void layer_addr_free(struct layer_addr *paddrinfo); /* ENG : duplicate a same streaminfo list, memory obtained with malloc(3); - CHN : 复制一个完全相同的streaminfo结构体及父流结构, 内存通过malloc(3)获取. + CHN : 锟斤拷锟斤拷一锟斤拷锟斤拷全锟斤拷同锟斤拷streaminfo锟结构锟藉及锟斤拷锟斤拷锟结构, 锟节达拷通锟斤拷malloc(3)锟斤拷取. */ struct streaminfo *streaminfo_dup(const struct streaminfo *stream); /* ENG: used to free all memory of streaminfo; - CHN: 用于释放结构体及父流结构的内存. + CHN: 锟斤拷锟斤拷锟酵放结构锟藉及锟斤拷锟斤拷锟结构锟斤拷锟节达拷. */ void streaminfo_free(struct streaminfo *stream); @@ -598,46 +592,46 @@ void streaminfo_free(struct streaminfo *stream); addr_list_str: addr list string; thread_index : thread index; - 返回值: - >0:转换后的结果实际占用内存长度, stream_addr_list_ntop()包含了字符串末尾的'\0'; - -1:dst缓存空间长度不足; - -2:格式错误; - -3:其他错误; + 锟斤拷锟斤拷值: + >0:转锟斤拷锟斤拷慕锟斤拷实锟斤拷占锟斤拷锟节存长锟斤拷, stream_addr_list_ntop()锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷末尾锟斤拷'\0'; + -1:dst锟斤拷锟斤拷占涑わ拷炔锟斤拷锟; + -2:锟斤拷式锟斤拷锟斤拷; + -3:锟斤拷锟斤拷锟斤拷锟斤拷; */ int stream_addr_list_ntop(const struct streaminfo *pstream, char *dst, int size); int stream_addr_list_pton(const char *addr_list_str, void *dst, int size, int thread_index); /* - TCP,UDP流模式下, 获取当前IP包的原始分片包. + TCP,UDP锟斤拷模式锟斤拷, 锟斤拷取锟斤拷前IP锟斤拷锟斤拷原始锟斤拷片锟斤拷. */ const raw_ipfrag_list_t *get_raw_frag_list(const struct streaminfo *stream); /* - IP插件模式下, 获取当前IP包的原始分片包. + IP锟斤拷锟侥J斤拷锟, 锟斤拷取锟斤拷前IP锟斤拷锟斤拷原始锟斤拷片锟斤拷. */ const raw_ipfrag_list_t *ip_plug_get_raw_ipfrag_list(int thread_num, enum addr_type_t addr_type); /* - 因为隧道、嵌套协议等原因, 输入一个纯四元组, 实际有可能查询到多个streaminfo, - 比如以下两个流: + 锟斤拷为锟斤拷锟斤拷锟斤拷嵌锟斤拷协锟斤拷锟皆拷锟, 锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷元锟斤拷, 实锟斤拷锟叫匡拷锟杰诧拷询锟斤拷锟斤拷锟絪treaminfo, + 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷: (1) tuple4->gtp->ip->udp->ethernet; (2) tuple4->l2tp->ip->udp->ethernet; - 如果隧道内层使用私有地址, 在一些极端凑巧的情况下, 流1和流2的内层tuple4可能是一样的, 但sapp会创建两个不同的streaminfo. + 锟斤拷锟斤拷锟斤拷锟斤拷诓锟绞癸拷锟剿斤拷械锟街, 锟斤拷一些锟斤拷锟剿达拷锟缴碉拷锟斤拷锟斤拷锟, 锟斤拷1锟斤拷锟斤拷2锟斤拷锟节诧拷tuple4锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷, 锟斤拷sapp锟结创锟斤拷锟斤拷锟斤拷锟斤拷同锟斤拷streaminfo. - 输入参数: - thread_index: 线程id; - tuple4v4 or tuple4v6: 四元组地址, 源、目的地址顺序无要求, C2S, S2c方向均可; - streamtype: 只支持两种类型, STREAM_TYPE_TCP or STREAM_TYPE_UDP; - array_max_num: 数组streaminfo_array的最大元素个数. + 锟斤拷锟斤拷锟斤拷锟: + thread_index: 锟竭筹拷id; + tuple4v4 or tuple4v6: 锟斤拷元锟斤拷锟街, 源锟斤拷目锟侥碉拷址顺锟斤拷锟斤拷要锟斤拷, C2S, S2c锟斤拷锟斤拷锟斤拷锟; + streamtype: 只支锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷, STREAM_TYPE_TCP or STREAM_TYPE_UDP; + array_max_num: 锟斤拷锟斤拷streaminfo_array锟斤拷锟斤拷锟皆拷馗锟斤拷锟. - 输出参数: - streaminfo_array: 查询到的符合输入四元组地址的streaminfo结构体指针. + 锟斤拷锟斤拷锟斤拷锟: + streaminfo_array: 锟斤拷询锟斤拷锟侥凤拷锟斤拷锟斤拷锟斤拷锟斤拷元锟斤拷锟街凤拷锟絪treaminfo锟结构锟斤拷指锟斤拷. - 返回值: + 锟斤拷锟斤拷值: -1: error; - 0: 没有对应的streaminfo结构; - >0: 实际找到streaminfo结构的数量; + 0: 没锟叫讹拷应锟斤拷streaminfo锟结构; + >0: 实锟斤拷锟揭碉拷streaminfo锟结构锟斤拷锟斤拷锟斤拷; */ int find_streaminfo_by_addrv4(int thread_index, const struct stream_tuple4_v4 *tuplev4, enum stream_type_t streamtype, struct streaminfo *streaminfo_array[], int array_max_num); int find_streaminfo_by_addrv6(int thread_index, const struct stream_tuple4_v6 *tuplev6, enum stream_type_t streamtype, struct streaminfo *streaminfo_array[], int array_max_num); diff --git a/include/public/stream_inc/stream_rawpkt.h b/include/public/stream_inc/stream_rawpkt.h index 7c709c2..500f860 100644 --- a/include/public/stream_inc/stream_rawpkt.h +++ b/include/public/stream_inc/stream_rawpkt.h @@ -86,16 +86,35 @@ const void *get_current_layer3_header(const struct streaminfo *pstream); const void *get_current_layer4_header(const struct streaminfo *pstream); /* - NULL: layer not exist; - NON-NULL: layer start buff - - Ethernet, jump to ipv6 header: + parameters: + raw_data: current layer header address; + raw_layer_type: current layer type, enum addr_type_t define in stream_base.h; + expect_layer_type: except layer type, enum addr_type_t define in stream_base.h; + + return value: + NULL: no expect layer; + NON-NULL: expect layer header. + + example: + For ethernet data, jump to ipv6 hdr: struct ip6_hdr *ip6_header; ip6_header = MESA_jump_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 vs MESA_jump_layer: + for tunnels, + MESA_jump_layer return to first expect_layer_type; + MESA_jump_layer_greedy return to inner most expect_layer_type; +*/ +const void *MESA_jump_layer_greedy(const void *raw_data, int raw_layer_type, int expect_layer_type); + +/* same as MESA_jump_layer_ */ +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 void *get_current_rawpkt_from_streaminfo(const struct streaminfo *pstream); const void *get_rawpkt_from_streaminfo(const struct streaminfo *pstream, int route_direction); diff --git a/module_test/src/gtest_sapp_comm.cpp b/module_test/src/gtest_sapp_comm.cpp index 6fe2062..5533c85 100644 --- a/module_test/src/gtest_sapp_comm.cpp +++ b/module_test/src/gtest_sapp_comm.cpp @@ -27,9 +27,7 @@ #include #include -#include "stream.h" #include "gtest_sapp_fun.h" -#include "MESA_jump_layer.h" static int gtest_sapp_master_fd; diff --git a/module_test/src/gtest_sapp_fun.h b/module_test/src/gtest_sapp_fun.h index f597a0e..96f76d1 100644 --- a/module_test/src/gtest_sapp_fun.h +++ b/module_test/src/gtest_sapp_fun.h @@ -8,7 +8,11 @@ #include #include #include -#include "MESA_jump_layer.h" + +#include +#include +#include +#include /* 璇存槑: @@ -26,10 +30,7 @@ #define SAPP_MAX_PLUG_ENTRY_NUM (256) #endif -#include "stream.h" -#include "packet_io.h" -#include "sapp_cla_private.h" -//#include "sapp_global_val.h" +#include "stream_internal.h" #include "mesa_net.h" #include "MESA_handle_logger.h" diff --git a/src/common/MESA_jump_layer.cpp b/src/common/MESA_jump_layer.cpp index b603949..c8cbd11 100644 --- a/src/common/MESA_jump_layer.cpp +++ b/src/common/MESA_jump_layer.cpp @@ -1,14 +1,11 @@ -#include "stream.h" #include "mesa_net.h" #include "deal_ipv6.h" /* Linux OS std */ #include #include #include -#include #include #include -#include #include #include #include @@ -23,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -1429,6 +1425,9 @@ const void *MESA_net_jump_to_layer_greedy(const void *raw_data, int raw_layer_ty return MESA_jump_layer_greedy(raw_data, raw_layer_type, expect_layer_type); } +#include +#include + /* 模锟斤拷tcpdump锟斤拷式: 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 ) { diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 0e8edf8..407196d 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -11,3 +11,18 @@ add_definitions(-D_DEFAULT_SOURCE -D__FAVOR_BSD -D_XOPEN_SOURCE -D_ISOC99_SOURCE add_executable(stream_id_decode stream_id_decode.c) +set(TCPDUMPMESA_LIBS "-L${CMAKE_BINARY_DIR}/src/common -lMESA_jump_layer") +set(TCPDUMPMESA_CFLAGS "-I${CMAKE_SOURCE_DIR}/include/public/stream_inc -Wall -O2") +ExternalProject_Add(tcpdump_mesa + PREFIX tcpdump_mesa + URL ${CMAKE_CURRENT_SOURCE_DIR}/tcpdumpmesa.zip + CONFIGURE_COMMAND env ADDITIONAL_LIBS=${TCPDUMPMESA_LIBS} ./configure + BUILD_COMMAND make CFLAGS+=${TCPDUMPMESA_CFLAGS} + INSTALL_COMMAND "" + BUILD_IN_SOURCE 1 +) +ExternalProject_Get_Property(tcpdump_mesa BINARY_DIR) +install(PROGRAMS ${BINARY_DIR}/tcpdump + DESTINATION ./tools/ + RENAME tcpdump_mesa + COMPONENT EXECUTABLE) \ No newline at end of file diff --git a/tools/tcpdumpmesa.zip b/tools/tcpdumpmesa.zip new file mode 100644 index 0000000..c760289 Binary files /dev/null and b/tools/tcpdumpmesa.zip differ -- cgit v1.2.3