From fc1a6aacbdf3aa10eb8af12cf7dc131f12a6f2ea Mon Sep 17 00:00:00 2001 From: lijia Date: Fri, 29 Jan 2021 20:44:58 +0800 Subject: 修复无需mrtunnat模式下,发包选项错误, 设置为TUNNAT_CZ_ACTION_ENCAP_NO_SESSION. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cycle_pkt_dump_through_write_offset.c | 32 +++++++++++----------- src/packet_io/packet_io_marsio.c | 17 ++++++++++-- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/packet_io/cycle_pkt_dump_through_write_offset.c b/src/packet_io/cycle_pkt_dump_through_write_offset.c index ebab603..5547b4d 100644 --- a/src/packet_io/cycle_pkt_dump_through_write_offset.c +++ b/src/packet_io/cycle_pkt_dump_through_write_offset.c @@ -40,7 +40,7 @@ typedef struct{ unsigned long long discard_pkt_bytes; char __pad__[32]; /* 64ֽcache */ }pkt_dump_status_t; -static pkt_dump_status_t PKT_DISCARD_STAT[MAX_THREAD_NUM]; +static pkt_dump_status_t PKT_DISCARD_STAT[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; /* ߳, tcpdump_mesaģʽΪINJECTʱҲҪ */ #endif @@ -56,21 +56,21 @@ static char G_PKT_DUMP_ROOT_DIR[PATH_MAX]; /* static long G_PKT_DUMP_FILE_SIZE = 104857600; /* Ĭ100MB, ߳ */ int G_PKT_DUMP_SW = 0; /* ĬϹر */ int G_PKT_DUMP_MODE = PKT_DUMP_LOCAL_FILE; /* Ĭдļ */ -static int G_PKT_DUMP_PER_THREAD_SW[MAX_THREAD_NUM]; +static int G_PKT_DUMP_PER_THREAD_SW[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; static int pkt_dump_thread_num = 1; -static FILE *G_PKT_DUMP_FP[MAX_THREAD_NUM]; -static int G_FILENAME_INDEX[MAX_THREAD_NUM]; -static long G_PCAP_SIZE[MAX_THREAD_NUM]; +static FILE *G_PKT_DUMP_FP[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; +static int G_FILENAME_INDEX[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; +static long G_PCAP_SIZE[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; static char G_PKT_DUMP_FILTER_STR[PATH_MAX]; -static struct bpf_program G_PKT_DUMP_BPF_FILTER[MAX_THREAD_NUM]; +static struct bpf_program G_PKT_DUMP_BPF_FILTER[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; static unsigned short pkt_dump_data_offset = 0; /* ʱָƫ, vxlan²ڲݰ */ static unsigned short pkt_dump_tcp_bind_port = 12345; /* ĬTCP˿, ڽⲿtcpdump */ static int pkt_dump_tcp_cmd_sd = -1;/* TCP fd, ڽⲿtcpdump */ static volatile int pkt_dump_udp_socket_peer_alive = 0; /* ⲿtcpdumpǷ */ -static int pkt_dump_udp_pkt_sd[MAX_THREAD_NUM]; /* UDPݰfd */ +static int pkt_dump_udp_pkt_sd[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; /* UDPݰfd */ static struct sockaddr_in udp_recv_addr; static int tcpdump_perceptive_flag = 0; /* ģʽ, Էֶ */ static int greedy_seek_flag = 0; /* ƫƵڲIP, ģʽ²BUG */ @@ -92,7 +92,7 @@ typedef struct{ char __cache_alignment[56]; }pkt_dump_mthread_t; -static pkt_dump_mthread_t pkt_dump_mthread_info[MAX_THREAD_NUM]; +static pkt_dump_mthread_t pkt_dump_mthread_info[MAX_THREAD_NUM+INDEPENDENT_SEND_QUEUE_MAX_NUM]; static int raw_cfg_pkt_dump_ratio = 30; /* ȫĬϲ, ʾÿNһ, ֹtcpdump_mesaƽ̨ */ static int cur_conn_pkt_dump_ratio = 30; /* ǰӵIJ, host, portbpf, Ϊȫģʽ, debugŴ */ @@ -363,7 +363,7 @@ static int cycle_pkt_dump_seek_to_inner_ip(char *pkt_buf, int pktlen, int thread ûй, ȫģʽ, Ϊ˾Ӱ߳, ݲֻһְ. */ if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ - bpf_match_ipv4 == bpf_filter(G_PKT_DUMP_BPF_FILTER[thread_seq].bf_insns, + bpf_match_ipv4 = bpf_filter(G_PKT_DUMP_BPF_FILTER[thread_seq].bf_insns, (const unsigned char *)pkt_buf, (unsigned int)bpf_match_pkt_len, (unsigned int)bpf_match_pkt_len); } }else{ @@ -395,7 +395,7 @@ static int cycle_pkt_dump_seek_to_inner_ip(char *pkt_buf, int pktlen, int thread ûй, ȫģʽ, Ϊ˾Ӱ߳, ݲֻһְ. */ if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ - bpf_match_ipv6 == bpf_filter(G_PKT_DUMP_BPF_FILTER[thread_seq].bf_insns, + bpf_match_ipv6 = bpf_filter(G_PKT_DUMP_BPF_FILTER[thread_seq].bf_insns, (const unsigned char *)pkt_buf, (unsigned int)bpf_match_pkt_len, (unsigned int)bpf_match_pkt_len); } @@ -780,7 +780,7 @@ static int cycle_pkt_dump_child_init(void) #endif -#if DEBUG +#if 0 static long ifuncb_show_pktdump_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg, const char *cmd_args) { int i; @@ -1235,7 +1235,7 @@ static void cycle_pkt_dump_command_parse(int connfd) } int pcap_link_type = DLT_EN10MB; if(greedy_seek_flag == 1)pcap_link_type = DLT_RAW; - for(i = 0; i < (unsigned int )g_packet_io_thread_num; i++){ + for(i = 0; i < (unsigned int )g_packet_io_thread_num + sapp_global_val->config.cpu.send_only_threads_max_num; i++){ if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ /* ûfilter, ȫ */ if(pcap_compile_nopcap(65535, pcap_link_type, &G_PKT_DUMP_BPF_FILTER[i], G_PKT_DUMP_FILTER_STR, 100, 0) < 0){ @@ -1282,7 +1282,7 @@ err_exit: /* ɵָ߳, ÿλָĬֵ */ memset(G_PKT_DUMP_PER_THREAD_SW, 0, sizeof(G_PKT_DUMP_PER_THREAD_SW)); usleep(1000 * 500); /* ʱͷ, ߳ʹBPF */ - for(i = 0; i < (unsigned int )g_packet_io_thread_num; i++){ + for(i = 0; i < (unsigned int )g_packet_io_thread_num + sapp_global_val->config.cpu.send_only_threads_max_num; i++){ pcap_freecode(&G_PKT_DUMP_BPF_FILTER[i]); pkt_dump_mthread_info[i].sample_pkt_num = 0; pkt_dump_mthread_info[i].perceptive_mode_pkt_seq = 0; @@ -1338,7 +1338,7 @@ static int cycle_pkt_dump_socket_init(void) } listen(pkt_dump_tcp_cmd_sd, 1); /* ֲ֧, ʱֻ֧һͻ˲ */ - for(i = 0; i < g_packet_io_thread_num; i++){ + for(i = 0; i < g_packet_io_thread_num + sapp_global_val->config.cpu.send_only_threads_max_num; i++){ pkt_dump_udp_pkt_sd[i] = socket(AF_INET, SOCK_DGRAM, 0); } @@ -1373,10 +1373,10 @@ int cycle_pkt_dump_init(int argc, char *argv[]) strncpy(G_PKT_DUMP_FILTER_STR, pktdump_cfg->bpf_filter, sizeof(G_PKT_DUMP_FILTER_STR)-1); } if(PKT_DUMP_LOCAL_FILE == G_PKT_DUMP_MODE){ - cycle_pkt_dump_set_thread_num(g_packet_io_thread_num); + cycle_pkt_dump_set_thread_num(g_packet_io_thread_num + sapp_global_val->config.cpu.send_only_threads_max_num); if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ - for(i = 0; i < g_packet_io_thread_num; i++){ + for(i = 0; i < g_packet_io_thread_num + sapp_global_val->config.cpu.send_only_threads_max_num; i++){ if(pcap_compile_nopcap(65535,DLT_EN10MB, &G_PKT_DUMP_BPF_FILTER[i], G_PKT_DUMP_FILTER_STR, 100, 0) < 0){ sapp_log(30, 1, 1, "Compile pcap filter '%s' error\n", pktdump_cfg->bpf_filter); return -1; diff --git a/src/packet_io/packet_io_marsio.c b/src/packet_io/packet_io_marsio.c index 0b1e575..d542e59 100644 --- a/src/packet_io/packet_io_marsio.c +++ b/src/packet_io/packet_io_marsio.c @@ -356,6 +356,7 @@ int marsio_dl_io_raw_pkt_send(void *phandle, unsigned char *data,int datalen, vo marsio_buff_t *send_mbuf[1]; char *real_buf; struct mr_tunnat_ctrlzone mr_ctrlzone = {}; + uint16_t send_option = 0; ret = ptr_marsio_buff_malloc_global(sapp_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_seq); if((ret < 0) || (NULL == send_mbuf[0])){ @@ -372,12 +373,22 @@ int marsio_dl_io_raw_pkt_send(void *phandle, unsigned char *data,int datalen, vo memcpy(real_buf, data, datalen); - mr_ctrlzone.action = TUNNAT_CZ_ACTION_ENCAP_INNER | TUNNAT_CZ_ACTION_ENCAP_OUTER; - packet_io_hook_sendto(raw_pkt, route_dir, real_buf, (void *)send_mbuf[0]); + if(0 == sapp_global_val->config.packet_io.packet_io_tunnel.l2_l3_tunnel_support){ + mr_ctrlzone.action = TUNNAT_CZ_ACTION_ENCAP_INNER | TUNNAT_CZ_ACTION_ENCAP_OUTER; + send_option = MARSIO_SEND_OPT_FAST|MARSIO_SEND_OPT_REHASH; + }else{ + /* v4.2֮, sappmrtunnat֧, ֱӷԭʼ, Ҫװײ·Ϣ */ + mr_ctrlzone.action = TUNNAT_CZ_ACTION_ENCAP_NO_SESSION; + send_option = MARSIO_SEND_OPT_FAST; + } + + if(raw_pkt){ + packet_io_hook_sendto(raw_pkt, route_dir, real_buf, (void *)send_mbuf[0]); + } ptr_marsio_buff_ctrlzone_set(send_mbuf[0], 0, &mr_ctrlzone, sizeof(struct mr_tunnat_ctrlzone)); - ret = ptr_marsio_send_burst_with_options((struct mr_sendpath *)arg, thread_seq, send_mbuf, 1, MARSIO_SEND_OPT_FAST|MARSIO_SEND_OPT_REHASH); + ret = ptr_marsio_send_burst_with_options((struct mr_sendpath *)arg, thread_seq, send_mbuf, 1, send_option); if(ret < 0){ //ʧmarsioԶfree //ptr_marsio_buff_free(sapp_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_seq); -- cgit v1.2.3