diff options
| author | lijia <[email protected]> | 2021-07-23 18:39:20 +0800 |
|---|---|---|
| committer | lijia <[email protected]> | 2021-07-23 18:39:20 +0800 |
| commit | 3177ff98138d5c7216eb7294446add02a80b72e8 (patch) | |
| tree | c1b0664a33db4cf92dfd1f7a8221fd1650f71a17 | |
| parent | 9feef0f69f9784605c88a0b04636747ef37e4218 (diff) | |
TSG-7168, pcap模式支持按内层ip分流.v4.2.43
| -rw-r--r-- | bin/etc/sapp.toml | 3 | ||||
| -rw-r--r-- | include/private/stream_internal.h | 1 | ||||
| -rw-r--r-- | src/config/config_parse.cpp | 4 | ||||
| -rw-r--r-- | src/packet_io/packet_io_pcap.c | 40 |
4 files changed, 38 insertions, 10 deletions
diff --git a/bin/etc/sapp.toml b/bin/etc/sapp.toml index e949655..867919e 100644 --- a/bin/etc/sapp.toml +++ b/bin/etc/sapp.toml @@ -42,6 +42,9 @@ ### note, same as tcpdump -Q/-P arg, possible values are `in', `out' and `inout', default is "in" pcap_capture_direction="in" +### note, support two mode: "inner_tuple2", "outer_tuple2" + pcap_distmode="inner_tuple2" + ### note, depolyment.mode options: [sys_route, vxlan_by_inline_device, raw_ethernet_single_gateway, raw_ethernet_multi_gateway] ### sys_route: send ip(ipv6) packet by system route table, this is default mode in mirror mode; ### vxlan_by_inline_device: encapsulation inject packet with vxlan, and then send to inline device by udp socket. diff --git a/include/private/stream_internal.h b/include/private/stream_internal.h index 70054fd..7c0331d 100644 --- a/include/private/stream_internal.h +++ b/include/private/stream_internal.h @@ -6,6 +6,7 @@ #include "private/sysinfo.h" #include "MESA_handle_logger.h" #include "mesa_pkt_dump.h" +#include "sapp_limits.h" //#define STREAM_BASE_MD5_CHECK "dd09b3b11993cc835200db477dad7d4b" //#define STREAM_CONTROL_MD5_CHECK "75aab0821e489b84355fa22ad02a2e78" diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp index 7439a05..a543ef0 100644 --- a/src/config/config_parse.cpp +++ b/src/config/config_parse.cpp @@ -180,14 +180,13 @@ static int cfg_value_check_stream_id_base_time(const sapp_config_check_t *sapp_c } - - static const char *cfg_chk_value_overlay_mode[2] = {"none", "vxlan"}; static const char *cfg_chk_value_pcap_capture_direction[3] = {"in", "out", "inout"}; static const char *cfg_chk_value_inject_pkt_mode[4] = {"sys_route", "vxlan_by_inline_device", "raw_ethernet_single_gateway", "raw_ethernet_multi_gateway"}; static const char *cfg_chk_value_depolyment_mode[4] = {"mirror", "inline", "transparent", "dumpfile"}; static const char *cfg_chk_value_interface_type[2] = {"pcap", "marsio"}; static const char *cfg_chk_value_pkt_dump_mode[2] = {"storage", "udp_socket"}; +static const char *cfg_chk_value_pcap_distmode[2] = {"inner_tuple2", "outer_tuple2"}; static const sapp_config_check_t g_sapp_cfg_check_attr[] = @@ -215,6 +214,7 @@ static const sapp_config_check_t g_sapp_cfg_check_attr[] = {4208,4204,RLOG_LV_INFO,"packet_io.feature", "inject_mode_single_gateway_dst_mac", "raw_ethernet_single_gateway",cfg_value_check_inject_mode, NULL, NULL, 0}, {4209,0,RLOG_LV_DEBUG,"packet_io.feature", "dumpfile_sleep_time_before_exit", NULL, cfg_value_check_integer_range, NULL, g_interger_range_array, 65535}, {4210,0,RLOG_LV_DEBUG,"packet_io.feature", "extract_linkdir_from_mac_in_mirror_mode", NULL, NULL, NULL, NULL, 0}, + {4211,0,RLOG_LV_DEBUG,"packet_io.feature", "pcap_distmode", NULL,cfg_value_check_string_range, NULL, cfg_chk_value_pcap_distmode, 2}, {4301,1,RLOG_LV_FATAL,"packet_io.depolyment", "mode", NULL,cfg_value_check_string_range, NULL, cfg_chk_value_depolyment_mode, 3}, {4302,1,RLOG_LV_FATAL,"packet_io.internal.interface", "type", NULL,cfg_value_check_string_range, NULL, cfg_chk_value_interface_type, 2}, diff --git a/src/packet_io/packet_io_pcap.c b/src/packet_io/packet_io_pcap.c index 480c152..33b4b4a 100644 --- a/src/packet_io/packet_io_pcap.c +++ b/src/packet_io/packet_io_pcap.c @@ -9,8 +9,8 @@ extern "C" { #define PROCESS_BAR_SW (1)
-int g_pcap_version_VERSION_20190907;
-static int g_pcap_version_internal = 20190907;
+int g_pcap_version_VERSION_20210722;
+static int g_pcap_version_internal = 20210722;
#define PCAP_SNAPLEN_MAX (65535)
@@ -22,6 +22,12 @@ typedef struct{ UINT8 pcap_send_buf[SENDPACKET_BUF_LEN];
}pcap_send_handle;
+/* ����ģʽ, ���ڲ��Ԫ�黹������Ԫ��, TODO:������, �Ժ����֧����Ԫ�� */
+typedef enum{
+ PCAP_DISTMODE_INNER_TUPLE2,
+ PCAP_DISTMODE_OUTER_TUPLE2,
+}pcap_distmode_t;
+
#define PCAP_MALLOC(size) malloc(size)
#define PCAP_FREE(ptr) free(ptr)
@@ -43,10 +49,10 @@ static volatile long pcap_lib_drop_up_num = 0; /* ����ģʽĬ��ʹ�ô˱����洢 */ static volatile long pcap_lib_drop_down_num = 0;
static struct mesa_ethernet_hdr *raw_pkt_hdr[MAX_THREAD_NUM]; /* ��¼ԭʼ��ͷָ��, ���ڷ�����ȡMAC��ַ�� */
static unsigned char raw_pkt_route_dir[MAX_THREAD_NUM]; /* ��¼ԭʼ������, ���ڷ������ݰ� */
-static unsigned int dispatch_thread_rnd_num;
static unsigned long long tot_up_rcv_pkt_num, tot_down_rcv_pkt_num;
static int pcap_device_up_mtu = 1500;
static int pcap_device_down_mtu = 1500;
+static pcap_distmode_t g_pcap_distmode = PCAP_DISTMODE_OUTER_TUPLE2;
extern sapp_global_t *sapp_global_val;
extern int g_PollingFunNum;
@@ -911,8 +917,13 @@ static unsigned int __pcap_dispatch_thread(const u_char *data) unsigned int disp_arg1, disp_arg2;
const struct ip *ipv4_hdr;
const struct ip6_hdr *ipv6_hdr;
+
+ if(PCAP_DISTMODE_OUTER_TUPLE2 == g_pcap_distmode){
+ res = MESA_net_jump_to_layer((const void *)data, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V4);
+ }else{
+ res = MESA_net_jump_to_layer_greedy((const void *)data, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V4);
+ }
- res = MESA_net_jump_to_layer((const void *)data, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V4);
if(res){
ipv4_hdr = (const struct ip *)res;
if(memcmp(&ipv4_hdr->ip_src.s_addr, &ipv4_hdr->ip_dst.s_addr, sizeof(int)) >= 0){
@@ -925,7 +936,11 @@ static unsigned int __pcap_dispatch_thread(const u_char *data) goto disp;
}
- res = MESA_net_jump_to_layer((const void *)data, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V6);
+ if(PCAP_DISTMODE_OUTER_TUPLE2 == g_pcap_distmode){
+ res = MESA_net_jump_to_layer((const void *)data, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V6);
+ }else{
+ res = MESA_net_jump_to_layer_greedy((const void *)data, ADDR_TYPE_MAC, __ADDR_TYPE_IP_PAIR_V6);
+ }
if(res){
ipv6_hdr = (const struct ip6_hdr *)res;
/* ֻʹ��IPv6��ַ��һ���� */
@@ -945,7 +960,7 @@ static unsigned int __pcap_dispatch_thread(const u_char *data) return 0;
disp:
- hash = pcap_dispatch_hash(disp_arg1, disp_arg2, dispatch_thread_rnd_num);
+ hash = pcap_dispatch_hash(disp_arg1, disp_arg2, 0xFEEDBEAF);
hash %= g_pcap_work_thread_num;
return hash;
@@ -1438,8 +1453,6 @@ int pcap_dl_io_init(int argc, char *argv[]) }
pcap_create_work_thread();
-
- dispatch_thread_rnd_num = (unsigned int)sapp_random();
#if 0 /* version3.0 */
MESA_load_profile_string_def("conf/main.conf", "Module", "dumpfile_speed", cfg_buf, sizeof(cfg_buf), "topspeed");
@@ -1457,6 +1470,17 @@ int pcap_dl_io_init(int argc, char *argv[]) }
#endif
+ char conf_pcap_distmode[NAME_MAX];
+ tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.feature", (char *)"pcap_distmode", conf_pcap_distmode, sizeof(conf_pcap_distmode), "inner_tuple2");
+ if(strncasecmp(conf_pcap_distmode, "inner_tuple2", strnlen("inner_tuple2", NAME_MAX)) == 0){
+ g_pcap_distmode = PCAP_DISTMODE_INNER_TUPLE2;
+ }else if(strncasecmp(conf_pcap_distmode, "outer_tuple2", strnlen("outer_tuple2", NAME_MAX)) == 0){
+ g_pcap_distmode = PCAP_DISTMODE_OUTER_TUPLE2;
+ }else{
+ printf("\033[1;31;40m[Error]invalid [packet_io.feature]->pcap_distmode:'%s', only support [\"inner_tuple2\", \"outer_tuple2\"].\033[0m\n");
+ return -1;
+ }
+
return 0;
}
|
