diff options
| author | lijia <[email protected]> | 2024-04-17 15:49:32 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2024-04-21 02:35:56 +0800 |
| commit | 199f3d3749b7ab236f189e3e79095110d37f6ddd (patch) | |
| tree | 64d7e24fc43dcf62e63f7a4dc40de31ab6e3b425 | |
| parent | 32d00d5244c26e129f66f2054a2558cf376c8611 (diff) | |
feat: TSG-20668, add get first packet ip TTL
| -rw-r--r-- | .gitlab-ci.yml | 54 | ||||
| -rw-r--r-- | benchmark_pcap/for_gtest_only/control/get_ip_ttl_hybrid.pcap | bin | 0 -> 1283 bytes | |||
| -rw-r--r-- | include/private/stream_internal.h | 4 | ||||
| -rw-r--r-- | include/public/stream_inc/stream_control.h | 30 | ||||
| -rw-r--r-- | module_test/src/gtest_main.cpp | 9 | ||||
| -rw-r--r-- | module_test/src/gtest_sapp_fun.h | 30 | ||||
| -rw-r--r-- | module_test/src/gtest_sapp_support.cpp | 12 | ||||
| -rw-r--r-- | module_test/src/gtest_sapp_support_plug.cpp | 73 | ||||
| -rw-r--r-- | src/dealpkt/deal_tcp.c | 14 | ||||
| -rw-r--r-- | src/dealpkt/deal_udp.c | 18 | ||||
| -rw-r--r-- | src/dealpkt/plug_support.c | 35 |
11 files changed, 211 insertions, 68 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 456338c..58fdaee 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -229,44 +229,44 @@ benchmark_test_for_centos8: extends: .setup_test_env_for_centos8 script: #run module v2.0 with death test - - ./$TEST_NAME -f control.* - - ./$TEST_NAME -f fake_marsio.* + - ./$TEST_NAME -s -f control.* + - ./$TEST_NAME -s -f fake_marsio.* #run module v3.0 - - ./$TEST_NAME -f benchmark_drop.* - - ./$TEST_NAME -f benchmark_forward.* - - ./$TEST_NAME -f benchmark_inject.tcp* - - ./$TEST_NAME -f benchmark_inject.inline_same_dir - - ./$TEST_NAME -f benchmark_inject.inline_reverse_dir + - ./$TEST_NAME -s -f benchmark_drop.* + - ./$TEST_NAME -s -f benchmark_forward.* + - ./$TEST_NAME -s -f benchmark_inject.tcp* + - ./$TEST_NAME -s -f benchmark_inject.inline_same_dir + - ./$TEST_NAME -s -f benchmark_inject.inline_reverse_dir inline_test_for_centos8: extends: .setup_test_env_for_centos8 script: #run module v2.0 with death test - - ./$TEST_NAME -f inline_mode.* -# - ./$TEST_NAME -f transparent.* + - ./$TEST_NAME -s -f inline_mode.* +# - ./$TEST_NAME -s -f transparent.* basic_test_for_centos8: extends: .setup_test_env_for_centos8 script: #run module v2.0 immediately - - ./$TEST_NAME -f ipv4.* - - ./$TEST_NAME -f ipv6.* - - ./$TEST_NAME -f udp.* - - ./$TEST_NAME -f appstate.* - - ./$TEST_NAME -f timer.* - - ./$TEST_NAME -f proxy.* - - ./$TEST_NAME -f asymmetric.* - - ./$TEST_NAME -f pkt_dump.* - - ./$TEST_NAME -f project.* - - ./$TEST_NAME -f stream_bridge.* - - ./$TEST_NAME -f tunnel.* - - ./$TEST_NAME -f plug_ctrl.* - - ./$TEST_NAME -f jump_layer.* - - ./$TEST_NAME -f hybrid.* -# - ./$TEST_NAME -f inject.* - - ./$TEST_NAME -f offload.* - - ./$TEST_NAME -f tcp.* - - ./$TEST_NAME -f tcpall.* + - ./$TEST_NAME -s -f ipv4.* + - ./$TEST_NAME -s -f ipv6.* + - ./$TEST_NAME -s -f udp.* + - ./$TEST_NAME -s -f appstate.* + - ./$TEST_NAME -s -f timer.* + - ./$TEST_NAME -s -f proxy.* + - ./$TEST_NAME -s -f asymmetric.* + - ./$TEST_NAME -s -f pkt_dump.* + - ./$TEST_NAME -s -f project.* + - ./$TEST_NAME -s -f stream_bridge.* + - ./$TEST_NAME -s -f tunnel.* + - ./$TEST_NAME -s -f plug_ctrl.* + - ./$TEST_NAME -s -f jump_layer.* + - ./$TEST_NAME -s -f hybrid.* +# - ./$TEST_NAME -s -f inject.* + - ./$TEST_NAME -s -f offload.* + - ./$TEST_NAME -s -f tcp.* + - ./$TEST_NAME -s -f tcpall.* ############################################################################### # upload diff --git a/benchmark_pcap/for_gtest_only/control/get_ip_ttl_hybrid.pcap b/benchmark_pcap/for_gtest_only/control/get_ip_ttl_hybrid.pcap Binary files differnew file mode 100644 index 0000000..a18b41d --- /dev/null +++ b/benchmark_pcap/for_gtest_only/control/get_ip_ttl_hybrid.pcap diff --git a/include/private/stream_internal.h b/include/private/stream_internal.h index 0307009..06267b2 100644 --- a/include/private/stream_internal.h +++ b/include/private/stream_internal.h @@ -256,9 +256,11 @@ struct streaminfo_private char __pad2:3; char has_duplicate_pkt; /* ��ǰ�������й��ظ����ݰ�, ����������Ӧ��ÿ������� */ char under_ddos_bypass; - char __pad3[5]; + char __pad3[3]; /* ===8 bytes=== */ + unsigned char ip_ttl_c2s; + unsigned char ip_ttl_s2c; void *stream_bridge; /* 20210425 lijia add, ����project����, ֧��ͬ�����첽����ģʽ, ԭ��project�����첽ģʽ */ }; diff --git a/include/public/stream_inc/stream_control.h b/include/public/stream_inc/stream_control.h index 64af912..0eb3989 100644 --- a/include/public/stream_inc/stream_control.h +++ b/include/public/stream_inc/stream_control.h @@ -63,6 +63,8 @@ enum MESA_stream_opt{ MSO_STREAM_S2C_LINK_ID,
MSO_STREAM_C2S_ROUTE_CTX,
MSO_STREAM_S2C_ROUTE_CTX,
+ MSO_IP_TTL_C2S, /* opt_val type must be unsigned char, IPv4 is TTL, IPv6 is Hop Limit */
+ MSO_IP_TTL_S2C, /* opt_val type must be unsigned char, IPv4 is TTL, IPv6 is Hop Limit */
__MSO_MAX,
};
@@ -158,7 +160,7 @@ enum stream_timer_return_value{ };
-#define MAX_TCP_OPT_LEN (38) /* TCP头部长度最长为60字节, 去除标准头部剩余选项部分最长40字节, 选项数据部分最长38字节 */
+#define MAX_TCP_OPT_LEN (38) /* TCP头部长度最长为60字节, 去除标准头部剩余选项部分最�?40字节, 选项数据部分最�?38字节 */
#define MAX_TCP_OPT_NUM (20) /* 单个TCP包最大选项数量 */
enum tcp_option_value{
@@ -207,20 +209,20 @@ struct tcp_option_ext{ /* 2018-10-24 lijia add, for pangu 项目mac_in_mac回流.
- 理论上, sapp平台不应该关心和业务密切相关的东西, 比如mac里哪个字段是link_id, 哪个是dev_id,
- 但这个玩意太底层了, 平台借用GDEV发送RST包也要填充这些值, 必须平台处理!!
+ 理论�?, sapp平台不应该关心和业务密切相关的东�?, 比如mac里哪个字段是link_id, 哪个是dev_id,
+ 但这个玩意太底层�?, 平台借用GDEV发送RST包也要填充这些�?, 必须平台处理!!
*/
-/* 为了方便业务插件获取mac_in_mac地址里的具体信息, 不再使用原始的bit位域, 转换成变量形式 */
+/* 为了方便业务插件获取mac_in_mac地址里的具体信息, 不再使用原始的bit位域, 转换成变量形�? */
struct vxlan_info{
unsigned char encap_type; /* 原始二层封装格式 */
unsigned char entrance_id; /* 设备所在出入口ID */
unsigned char dev_id; /* 设备ID */
unsigned char link_id; /* 链路ID */
- unsigned char link_dir; /* 链路方向, 指当前四元组的IP被捕获时的传输方向, 对于TCP, SYN包的传输方向; 对于UDP, 端口大IP的传输方向 */
- unsigned char inner_smac[18]; /* 内层真实SMAC, string类型, 例: "11:22:33:44:55:66" */
- unsigned char inner_dmac[18]; /* 内层真实DMAC, string类型, 例: "11:22:33:44:55:66" */
- unsigned char inner_smac_hex[6]; /* 内层真实SMAC, 原始二进制类型 */
- unsigned char inner_dmac_hex[6]; /* 内层真实DMAC, 原始二进制类型 */
+ unsigned char link_dir; /* 链路方向, 指当前四元组的IP被捕获时的传输方�?, 对于TCP, SYN包的传输方向; 对于UDP, 端口大IP的传输方�? */
+ unsigned char inner_smac[18]; /* 内层真实SMAC, string类型, �?: "11:22:33:44:55:66" */
+ unsigned char inner_dmac[18]; /* 内层真实DMAC, string类型, �?: "11:22:33:44:55:66" */
+ unsigned char inner_smac_hex[6]; /* 内层真实SMAC, 原始二进制类�? */
+ unsigned char inner_dmac_hex[6]; /* 内层真实DMAC, 原始二进制类�? */
};
@@ -338,10 +340,10 @@ int sapp_get_device_opt(const char *device, enum sapp_device_opt opt_type, void /***************************************************************************************
NOTE:
- 在被动模式下, 插件无需关心route_dir的绝对值, 只需要理解同向和反向即可,
- 但主动发包必须要精确理解route_dir是0还是1, 因外界网络拓扑模式不同, 可能随时会变化,
+ 在被动模式下, 插件无需关心route_dir的绝对�?, 只需要理解同向和反向即可,
+ 但主动发包必须要精确理解route_dir�?0还是1, 因外界网络拓扑模式不�?, 可能随时会变�?,
所以设置此接口, 插件只需传入人易理解的方向human_dir, 返回当前链路的link route dir,
- 注意首次部署时, etc/sapp.toml->inbound_route_dir一定要设置正确.
+ 注意首次部署�?, etc/sapp.toml->inbound_route_dir一定要设置正确.
args: 表示发包目标相对于当前设备所在的地理位置,
'E' or 'e': 表示数据包传输方向是从Internal to External.
@@ -355,9 +357,9 @@ int MESA_dir_human_to_link(int human_dir); /*
args:
- 链路传输方向: 0或1, 通常来自stream->routedir;
+ 链路传输方向: 0�?1, 通常来自stream->routedir;
- 返回值:
+ 返回�?:
'E' or 'e': 表示数据包传输方向是从Internal to External.
'I' or 'i': 表示数据包传输方向是从External to Internal.
'x': 参数错误;
diff --git a/module_test/src/gtest_main.cpp b/module_test/src/gtest_main.cpp index 5177f72..e121b4d 100644 --- a/module_test/src/gtest_main.cpp +++ b/module_test/src/gtest_main.cpp @@ -936,6 +936,13 @@ TEST(control, get_udp_flow_stat) ASSERT_EQ(GTEST_SAPP_SUCC, gtest_get_libsapp_devel_result()); } +#define control_get_ip_ttl 1 +TEST(control, get_ip_ttl) +{ + control_get_ip_ttl_run(); + ASSERT_EQ(GTEST_SAPP_SUCC, gtest_get_libsapp_devel_result()); +} + /************************ project_requirement.h API test ***********************/ #define project_simple 1 // for SI symbol view @@ -2191,7 +2198,7 @@ int main(int argc, char *argv[]) { int c; int to_gtest_argc = 1; - char *to_gtest_args[4] = {}; + char *to_gtest_args[4] = {(char *)"gtest_sapp_v4", NULL,NULL,NULL}; char temp_string[1024] = {}; int user_log_level = RLOG_LV_DEBUG; diff --git a/module_test/src/gtest_sapp_fun.h b/module_test/src/gtest_sapp_fun.h index 2847903..ee516fa 100644 --- a/module_test/src/gtest_sapp_fun.h +++ b/module_test/src/gtest_sapp_fun.h @@ -12,8 +12,8 @@ /* 说明: - 为了方便测试sapp的某些功�?不得已引用了一些private级别的头文件, - 但是如果sapp的头文件更新�? 但此模块没同步更�? 导致结构体不一�? 可能会测试不通过. + 为了方便测试sapp的某些功�?不得已引用了一些private级别的头文件, + 但是如果sapp的头文件更新�? 但此模块没同步更�? 导致结构体不一�? 可能会测试不通过. */ #include "sapp_limits.h" @@ -45,13 +45,13 @@ #define GTEST_DEV_MTU (2000) #define GTEST_VXLAN_HDR_LEN (8) -#define GTEST_SAPP_ERR (0x0EEEEEEE) /* 检测错误返回�?*/ -#define GTEST_SAPP_SUCC (0x01234567) /* sapp插件检测正确返回�?*/ -#define GTEST_INLINE_TO_SAPP_SUCC (0x07654321) /* inline模式下TAP模拟外部设备检测正确返回�?*/ -#define GTEST_TRANSPARENT_TO_SAPP_SUCC (0x00ABCDEF) /* 双臂模式下TAP模拟外部设备检测正确返回�?*/ -#define GTEST_FAKE_MARSIO_SUCC (0x0FEFEFE0) /* fake marsio模式检测正确返回�?*/ -#define GTEST_SAPP_ERR_SKIP (0x534B4950U) /* 因sapp的内部结构体变化, 无法测试, 跳过此用例的返回�? 即字符SKIP的十六进�?*/ -#define GTEST_RESULT_NONE (0x4E4F4E45) /* "NONE"�?6进制, 不发送或者表示无任何意义的返回�?*/ +#define GTEST_SAPP_ERR (0x0EEEEEEE) /* 检测错误返回�?*/ +#define GTEST_SAPP_SUCC (0x01234567) /* sapp插件检测正确返回�?*/ +#define GTEST_INLINE_TO_SAPP_SUCC (0x07654321) /* inline模式下TAP模拟外部设备检测正确返回�?*/ +#define GTEST_TRANSPARENT_TO_SAPP_SUCC (0x00ABCDEF) /* 双臂模式下TAP模拟外部设备检测正确返回�?*/ +#define GTEST_FAKE_MARSIO_SUCC (0x0FEFEFE0) /* fake marsio模式检测正确返回�?*/ +#define GTEST_SAPP_ERR_SKIP (0x534B4950U) /* 因sapp的内部结构体变化, 无法测试, 跳过此用例的返回�? 即字符SKIP的十六进�?*/ +#define GTEST_RESULT_NONE (0x4E4F4E45) /* "NONE"�?6进制, 不发送或者表示无任何意义的返回�?*/ #define BENCHMARK_PCAP_ROOT_DIR "../benchmark_pcap" @@ -67,7 +67,7 @@ #define SAPP_GTEST_LOG(level, module, fmt, args...) do{MESA_handle_runtime_log(g_sapp_test_log_handle, level, module, fmt, ##args);}while(0) -/* 用于sapp插件上下文空�? 有可能是被fork之后调用sapp, 跟gtest_main函数不在同一个进程里 */ +/* 用于sapp插件上下文空�? 有可能是被fork之后调用sapp, 跟gtest_main函数不在同一个进程里 */ #define SAPP_PLUG_LOG(level, module, fmt, args...) do{MESA_handle_runtime_log(g_sapp_plug_log_handle, level, module, fmt, ##args);}while(0) @@ -147,7 +147,7 @@ enum gtest_inject_type{ GINJECT_UDP_PAYLOAD = GINJECT_TYPE_UDP|0x01, }; -/* 用于指定哪些pcap�? 对应哪些检测函�?*/ +/* 用于指定哪些pcap�? 对应哪些检测函�?*/ typedef struct { const char *pcap_file_md5; unsigned int default_check_result; @@ -158,8 +158,8 @@ typedef struct { typedef struct { const char *pcap_file_md5; const char *keepalive_ip; /* inline 回流 保活ip */ - int inject_reverse; /* 注入包是否反�?*/ - int inject_pkt_trigger_threshold; /* inject超过几个包发送成功结�?*/ + int inject_reverse; /* 注入包是否反�?*/ + int inject_pkt_trigger_threshold; /* inject超过几个包发送成功结�?*/ unsigned int default_check_result; void (*pcap_callback)(u_char *user, const struct pcap_pkthdr *hdr, const u_char *data); const char *description; @@ -223,7 +223,7 @@ void gtest_exec_printf(const char *fmt, ...); void gtest_plug_printf(const char *fmt, ...); -extern "C" void sapp_printf(const char *fmt, ...); /* 在插件的上下文调�?*/ +extern "C" void sapp_printf(const char *fmt, ...); /* 在插件的上下文调�?*/ extern "C" int gtest_sapp_slave_init(void); /*********************************** tcp **************************************/ void tcp_simple_run(void); @@ -372,7 +372,7 @@ void get_linkdir_from_mac_run2(void); void get_deployment_mode_mirror(void); void get_deployment_mode_inline(void); void get_deployment_mode_transparent(void); - +void control_get_ip_ttl_run(void); /****************************** tunnel **************************/ diff --git a/module_test/src/gtest_sapp_support.cpp b/module_test/src/gtest_sapp_support.cpp index 47543d3..0586c96 100644 --- a/module_test/src/gtest_sapp_support.cpp +++ b/module_test/src/gtest_sapp_support.cpp @@ -1096,3 +1096,15 @@ void get_deployment_mode_inline(void) call_libsapp_devel_with_args(1, sapp_inline_start_args); } +void control_get_ip_ttl_run(void) +{ + set_default_config(); + + update_plugin_inf("TCP_ALL", "get_ip_ttl_entry"); + append_plugin_inf("UDP", "get_ip_ttl_entry"); + + set_pcap_dumpfile("for_gtest_only/control/get_ip_ttl_hybrid.pcap"); + + ASSERT_EQ(file_md5_checksum("dumpfile", "434d6a566709f0f78c44c7f3cb7b934b"),0); + call_libsapp_devel_for_dumpfile_topspeed(); +} diff --git a/module_test/src/gtest_sapp_support_plug.cpp b/module_test/src/gtest_sapp_support_plug.cpp index d59a911..a6ec7d2 100644 --- a/module_test/src/gtest_sapp_support_plug.cpp +++ b/module_test/src/gtest_sapp_support_plug.cpp @@ -2423,7 +2423,80 @@ extern "C" char plug_indifferent_not_call_entry(struct streaminfo *pstream,void return APP_STATE_GIVEME; } +extern "C" char get_ip_ttl_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet) +{ + unsigned char ip_ttl_c2s, ip_ttl_s2c; + int opt_len = 1; + static int stream_succ_num = 0; + + if(pstream->opstate == OP_STATE_CLOSE || pstream->pktstate == OP_STATE_CLOSE){ + MESA_get_stream_opt(pstream, MSO_IP_TTL_C2S, &ip_ttl_c2s, &opt_len); + MESA_get_stream_opt(pstream, MSO_IP_TTL_S2C, &ip_ttl_s2c, &opt_len); + + if(STREAM_TYPE_TCP == pstream->type){ + if(ADDR_TYPE_IPV4 == pstream->addr.addrtype){ + if(ip_ttl_c2s != 128){ + printf("\033[1;31;40mget_ip_ttl_entry error: tcpv4 ip_ttl_c2s is not 128!\033[0m\n"); + gtest_set_libsapp_devel_result(GTEST_SAPP_ERR); + return APP_STATE_DROPME; + } + if(ip_ttl_s2c != 43){ + printf("\033[1;31;40mget_ip_ttl_entry error: tcpv4 ip_ttl_s2c is not 43!\033[0m\n"); + gtest_set_libsapp_devel_result(GTEST_SAPP_ERR); + return APP_STATE_DROPME; + } + stream_succ_num++; + }else{ + if(ip_ttl_c2s != 64){ + printf("\033[1;31;40mget_ip_ttl_entry error: tcpv6 ip_ttl_c2s is not 64!\033[0m\n"); + gtest_set_libsapp_devel_result(GTEST_SAPP_ERR); + return APP_STATE_DROPME; + } + if(ip_ttl_s2c != 45){ + printf("\033[1;31;40mget_ip_ttl_entry error: tcpv6 ip_ttl_s2c is not 45!\033[0m\n"); + gtest_set_libsapp_devel_result(GTEST_SAPP_ERR); + return APP_STATE_DROPME; + } + stream_succ_num++; + } + } + + if(STREAM_TYPE_UDP == pstream->type){ + if(ADDR_TYPE_IPV4 == pstream->addr.addrtype){ + if(ip_ttl_c2s != 128){ + printf("\033[1;31;40mget_ip_ttl_entry error: udpv4 ip_ttl_c2s is not 128!\033[0m\n"); + gtest_set_libsapp_devel_result(GTEST_SAPP_ERR); + return APP_STATE_DROPME; + } + if(ip_ttl_s2c != 63){ + printf("\033[1;31;40mget_ip_ttl_entry error: udpv4 ip_ttl_s2c is not 63!\033[0m\n"); + gtest_set_libsapp_devel_result(GTEST_SAPP_ERR); + return APP_STATE_DROPME; + } + stream_succ_num++; + }else{ + if(ip_ttl_c2s != 64){ + printf("\033[1;31;40mget_ip_ttl_entry error: udpv6 ip_ttl_c2s is not 64!\033[0m\n"); + gtest_set_libsapp_devel_result(GTEST_SAPP_ERR); + return APP_STATE_DROPME; + } + if(ip_ttl_s2c != 59){ + printf("\033[1;31;40mget_ip_ttl_entry error: udpv6 ip_ttl_s2c is not 59!\033[0m\n"); + gtest_set_libsapp_devel_result(GTEST_SAPP_ERR); + return APP_STATE_DROPME; + } + stream_succ_num++; + } + } + if(4 == stream_succ_num){ + printf("\033[32mget_ip_ttl_entry test success!\033[0m\n"); + gtest_set_libsapp_devel_result(GTEST_SAPP_SUCC); + } + } + + return APP_STATE_GIVEME; +} #endif diff --git a/src/dealpkt/deal_tcp.c b/src/dealpkt/deal_tcp.c index 06a56f7..2935760 100644 --- a/src/dealpkt/deal_tcp.c +++ b/src/dealpkt/deal_tcp.c @@ -3071,6 +3071,14 @@ static int deal_tcp_stream(struct streamindex *pindex, const void *this_iphdr, s } update_polling_inject_context(SAPP_MEM_DYN_TCP_POLLING_RAW_PKT, pstream_pr, raw_pkt); + + /* update ip ttl */ + if(unlikely(0 == pstream_pr->ip_ttl_c2s) && (DIR_C2S == pstream->curdir)) { + pstream_pr->ip_ttl_c2s = pindex->stream.ip_ttl_c2s; + } + if(unlikely(0 == pstream_pr->ip_ttl_s2c) && (DIR_S2C == pstream->curdir)) { + pstream_pr->ip_ttl_s2c = pindex->stream.ip_ttl_c2s; /* Not a mistake, that's it! */ + } /* note: reset�����ü���, ����clientbytes+=, clientpktnum++����֮�� */ if(1 == lrustream(pindex_tcp)){ @@ -3299,6 +3307,9 @@ int dealipv4tcppkt(struct streamindex *pfindex, const struct mesa_ip4_hdr *this_ } #endif + /* temporarily stored in the stack memory, use fix val c2s */ + pfindex->stream.ip_ttl_c2s = this_iphdr->ip_ttl; + //return dealtcppkt(pfstream, this_tcphdr, thread_num, routedir, datalen, iplen, raw_pkt); return dealtcppkt(pfindex, (const void *)this_iphdr, this_tcphdr, thread_num, routedir, datalen, raw_pkt, offset_to_raw_pkt_hdr); } @@ -3322,6 +3333,9 @@ int dealipv6tcppkt(struct streamindex *pfindex, const struct mesa_ip6_hdr *this_ return PASS; } + /* temporarily stored in the stack memory, use fix val c2s */ + pfindex->stream.ip_ttl_c2s = this_iphdr->ip6_hop; + return dealtcppkt(pfindex,(const void *)this_iphdr, this_tcphdr,thread_num, routedir, datalen, raw_pkt, offset_to_raw_pkt_hdr); } diff --git a/src/dealpkt/deal_udp.c b/src/dealpkt/deal_udp.c index 833e7d5..274c811 100644 --- a/src/dealpkt/deal_udp.c +++ b/src/dealpkt/deal_udp.c @@ -759,6 +759,14 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_ pstream_pr->offset_to_ip_hdr = (char *)udph - (char *)this_iphdr; pstream_pr->raw_pkt = raw_pkt; /* 2014-12-30 lijia add */ + /* update ip ttl */ + if(unlikely(0 == pstream_pr->ip_ttl_c2s) && (DIR_C2S == pstream->curdir)) { + pstream_pr->ip_ttl_c2s = this_iphdr->ip_ttl; + } + if(unlikely(0 == pstream_pr->ip_ttl_s2c) && (DIR_S2C == pstream->curdir)) { + pstream_pr->ip_ttl_s2c = this_iphdr->ip_ttl; + } + if(is_overlay_udp_layer != 0){ if(ulen < (int)(sizeof(struct ethhdr) + sizeof(struct layer_addr_vxlan_private))) { @@ -1054,7 +1062,15 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe pstream_pr->packet_process_context=0; return PASS; } - + + /* update ip ttl */ + if(unlikely(0 == pstream_pr->ip_ttl_c2s) && (DIR_C2S == pstream->curdir)) { + pstream_pr->ip_ttl_c2s = a_packet->ip6_hop; + } + if(unlikely(0 == pstream_pr->ip_ttl_s2c) && (DIR_S2C == pstream->curdir)) { + pstream_pr->ip_ttl_s2c = a_packet->ip6_hop; + } + pstream_pr->offset_to_ip_hdr = (char *)udph - (char *)a_packet; pstream_pr->raw_pkt = raw_pkt; /* 2014-12-30 lijia add */ pdetail_pr=(struct udpdetail_private *)(pstream->pdetail); diff --git a/src/dealpkt/plug_support.c b/src/dealpkt/plug_support.c index 334e4ec..00ff455 100644 --- a/src/dealpkt/plug_support.c +++ b/src/dealpkt/plug_support.c @@ -481,7 +481,7 @@ int get_rawpkt_opt_from_streaminfo(const struct streaminfo *pstream, int type, v return ret;
}
- /* sappv4.2֮��, û��mrtunnat, ����ctrlzone��ȡ��Щvxlan��ص�ֵ, Ҫ��streaminfo->pfatherƫ�ƻ�ȡ */
+ /* sappv4.2֮��, û��mrtunnat, ����ctrlzone��ȡ��Щvxlan��ص��?, Ҫ��streaminfo->pfatherƫ�ƻ�ȡ */
switch(type){
case RAW_PKT_GET_GDEV_IP:
case RAW_PKT_GET_VXLAN_ID:
@@ -1151,7 +1151,7 @@ static void sapp_mac_addr_to_long(const unsigned char *mac_addr, unsigned long l ptr += 5; /* ָ��long long �ĵ�6���ֽ� */
for(i = 0; i < 6; i++){
- *ptr-- = *mac_addr++; /* �������ݰ���mac�����λ, copy��long long���������λ(��ȥ���2���ֽں�) */
+ *ptr-- = *mac_addr++; /* �������ݰ���mac������?, copy��long long����������?(��ȥ���?2���ֽں�) */
}
}
@@ -1207,14 +1207,14 @@ static int sapp_get_vxlan_info_from_streaminfo(const struct streaminfo *pstream, for(i = 0; i < 6; i++, ptr += 3){
sprintf((char *)ptr, "%02x:", mim_addr->inner_src_mac[i]);
}
- vxinfo->inner_smac[17] = '\0'; /* ���һλ���� */
+ vxinfo->inner_smac[17] = '\0'; /* ���һλ����? */
memcpy(vxinfo->inner_smac_hex, mim_addr->inner_src_mac, 6);
ptr = vxinfo->inner_dmac;
for(i = 0; i < 6; i++, ptr += 3){
sprintf((char *)ptr, "%02x:", mim_addr->inner_dst_mac[i]);
}
- vxinfo->inner_dmac[17] = '\0'; /* ���һλ���� */
+ vxinfo->inner_dmac[17] = '\0'; /* ���һλ����? */
memcpy(vxinfo->inner_dmac_hex, mim_addr->inner_dst_mac, 6);
}
else
@@ -1223,14 +1223,14 @@ static int sapp_get_vxlan_info_from_streaminfo(const struct streaminfo *pstream, for(i = 0; i < 6; i++, ptr += 3){
sprintf((char *)ptr, "%02x:", mac_addr->src_addr.h_source[i]);
}
- vxinfo->inner_smac[17] = '\0'; /* ���һλ���� */
+ vxinfo->inner_smac[17] = '\0'; /* ���һλ����? */
memcpy(vxinfo->inner_smac_hex, mac_addr->src_addr.h_source, 6);
ptr = vxinfo->inner_dmac;
for(i = 0; i < 6; i++, ptr += 3){
sprintf((char *)ptr, "%02x:", mac_addr->src_addr.h_dest[i]);
}
- vxinfo->inner_dmac[17] = '\0'; /* ���һλ���� */
+ vxinfo->inner_dmac[17] = '\0'; /* ���һλ����? */
memcpy(vxinfo->inner_dmac_hex, mac_addr->src_addr.h_dest, 6);
}
return 0;
@@ -1337,7 +1337,7 @@ static int MESA_get_stream_dup_pkt_stat(const struct streaminfo *pstream, void * return 0;
}
- /* �������ظ�������,����û�������ظ��� */
+ /* �������ظ�������?,����û�������ظ��� */
if(STREAM_TYPE_TCP == pstream->type){
if(pstream->ptcpdetail->clientpktnum + pstream->ptcpdetail->serverpktnum < SAPP_DUP_FIRST_PKT_NUM){ /* ��̫��, �������ж���û���ظ��� */
*res_val = -2;
@@ -1939,6 +1939,23 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o }
}
break;
+
+ case MSO_IP_TTL_C2S:
+ if(0 == pstream_pr->ip_ttl_c2s){
+ ret = -1;
+ }else{
+ *((unsigned char *)opt_val) = pstream_pr->ip_ttl_c2s;
+ *opt_val_len = sizeof(char);
+ }
+ break;
+ case MSO_IP_TTL_S2C:
+ if(0 == pstream_pr->ip_ttl_s2c){
+ ret = -1;
+ }else{
+ *((unsigned char *)opt_val) = pstream_pr->ip_ttl_s2c;
+ *opt_val_len = sizeof(char);
+ }
+ break;
default:
sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() error:unsupport MESA_stream_opt type:%d!\n",printaddr(&pstream->addr, pstream->threadnum), (int)opt);
ret = -1;
@@ -1996,7 +2013,7 @@ int get_current_thread_cpu_affinity_id(void) int tot_cpu_set_count = CPU_COUNT(¤t_cpu_mask);
if((tot_cpu_set_count == tot_cpu_core) || (tot_cpu_set_count > 1)){
/* ȫ����������, ��ʵ����û�а�,
- �����������isolcpus, ���㲻���, CPU_COUNT���ܺ������������,
+ �����������isolcpus, ���㲻���?, CPU_COUNT���ܺ������������?,
��������1���϶���û�о�ȷ��ij������ */
return -1;
}
@@ -2041,7 +2058,7 @@ void *dictator_realloc(int thread_seq, void *ptr, size_t size) return realloc(ptr, size);
}
-/* ��ҵ�������ص�ֵת����ƽ̨�����ֵ, ����PROT_STATE_xxxת��ΪAPP_STATE_xxx */
+/* ��ҵ�������ص�ֵת����ƽ̨������?, ����PROT_STATE_xxxת��ΪAPP_STATE_xxx */
char biz_retval_to_platform(char biz_ret)
{
char plat_ret = 0;
|
