From 1dfcde11001f9e5999b9363160d304557ab99f4d Mon Sep 17 00:00:00 2001 From: lijia Date: Fri, 30 Oct 2020 22:05:52 +0800 Subject: 1.修改layer_addr_prefix_ntop(), 对于MPLS空造的层加上标识, 输出日志时不显示; 2.修复非inline原始链路的数据包注入链路, 如STP包导致交换机端口down掉的问题. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/private/stream_internal.h | 1 + src/common/stream_addr_inet.c | 25 +++++++++++++++++++++++++ src/dealpkt/deal_arp.c | 2 ++ src/dealpkt/deal_ethernet.c | 1 + src/dealpkt/deal_vlan.c | 1 + src/inner_plug/sapp_assistant.cpp | 6 ++++-- src/packet_io/packet_io.c | 16 ++++++++-------- src/packet_io/packet_io_hook.c | 10 +++++++--- src/packet_io/packet_io_marsio.c | 8 +++++++- 9 files changed, 56 insertions(+), 14 deletions(-) diff --git a/include/private/stream_internal.h b/include/private/stream_internal.h index 7b06310..31e991c 100644 --- a/include/private/stream_internal.h +++ b/include/private/stream_internal.h @@ -71,6 +71,7 @@ typedef struct { const void *io_lib_pkt_reference; /* õײI/Oԭʼṹ, :marsio˵, ײmbufṹ */ int route_dir; int device_index;/* жʱ, Ҫ֤ĸʹĸ */ + int is_overlay_pkt; /* ʾʵ·еݰ, Ҫע, һ; Ҫ */ unsigned short vlan_flipping_couple[2]; /*2020-09-28 lijia add, in host order, vlan flipping for adev, index0ʾյǰvlan_id, index1ʾԭתvlan_id */ unsigned char mac_flipping_enable; char diagnose_error_to_dump; /* ijִݰ, pkt_dump洢udp socket͸tcpdump_mesa */ diff --git a/src/common/stream_addr_inet.c b/src/common/stream_addr_inet.c index a6abb06..13c3c65 100644 --- a/src/common/stream_addr_inet.c +++ b/src/common/stream_addr_inet.c @@ -1865,16 +1865,41 @@ char *layer_addr_ntop_r(const struct streaminfo *pstream, char *out_buf, int out return NULL; } +/* + sappΪ˲׼, ijЩ鹹, ʱҵӡ־ȽԻ, ˴ʹ"_PAD"ʶһ, ڵ. +*/ +const char *__layer_addr_prefix_ntop_pad(const struct streaminfo_private *pstream_pr) +{ + const char *addr_prefix = NULL; + + switch(pstream_pr->stream_public.addr.addrtype){ + case ADDR_TYPE_MPLS: + addr_prefix = "_PAD_MPLS"; + break; + + case ADDR_TYPE_VLAN: + addr_prefix = "_PAD_VLAN"; + break; + } + + return addr_prefix; +} + const char *layer_addr_prefix_ntop(const struct streaminfo *pstream) { int i; const char *addr_type_str = NULL; + const struct streaminfo_private *pstream_pr = (struct streaminfo_private *)pstream; if(NULL == pstream){ return NULL; } + if(pstream_pr->addr_skip_for_layer_cmp){ + return __layer_addr_prefix_ntop_pad(pstream_pr); + } + for(i = __ADDR_TYPE_INIT+1; G_ADDR_CONVERT_HANDLE[i].addr_type_bin!= __ADDR_TYPE_MAX; i++){ if((G_ADDR_CONVERT_HANDLE[i].addr_type_bin == pstream->addr.addrtype) &&(G_ADDR_CONVERT_HANDLE[i].stream_type == pstream->type)){ diff --git a/src/dealpkt/deal_arp.c b/src/dealpkt/deal_arp.c index 385c608..3661fe5 100644 --- a/src/dealpkt/deal_arp.c +++ b/src/dealpkt/deal_arp.c @@ -28,6 +28,8 @@ extern "C" { /* ڲARP, Ӧ·CS˫ARP, Ҫע */ if(sapp_identify_tunnel_inner_pkt(raw_pkt) != 0){ return PASS; + }else{ + sapp_runtime_log(RLOG_LV_DEBUG, "is not raw inline arp pkt, drop it."); } /* TODO, mrtunnat֮, ˴ҪжDzǸİ, Dzoverlayԭʼ·ϵarp, ӦDROP, ˴ĬϷPASS */ diff --git a/src/dealpkt/deal_ethernet.c b/src/dealpkt/deal_ethernet.c index b54ff6c..47b0ebb 100644 --- a/src/dealpkt/deal_ethernet.c +++ b/src/dealpkt/deal_ethernet.c @@ -198,6 +198,7 @@ int eth_entry(struct streaminfo_private *fstream_pr, const void *this_layer_hdr, /* GDEVģʽ, ʲôʱ򶼲Ӧðѷڲʶİתȥ, ߷ְSPTЭעȥ, */ local_sys_stat->count[SAPP_STAT_DROP_ETHERNET]++; ret = DROP; + sapp_runtime_log(RLOG_LV_DEBUG, "is not raw inline ethernet pkt, type is:0x%x, drop it.", eth_type); } } sapp_runtime_log(20, "eth_entry() recv unknown pkt, protocol is:0x%04x, pkt seq:%llu", eth_type, local_sys_stat->count[SAPP_STAT_RCV_RAW]); diff --git a/src/dealpkt/deal_vlan.c b/src/dealpkt/deal_vlan.c index 6f512be..52f3dbf 100644 --- a/src/dealpkt/deal_vlan.c +++ b/src/dealpkt/deal_vlan.c @@ -132,6 +132,7 @@ int vlan_8021q_entry(struct streaminfo_private *pfstream_pr,const void *this_lay }else{ /* GDEVģʽ, ʲôʱ򶼲ӦðѲʶİתȥ, ߷ְSPTЭעȥ, */ ret = DROP; + sapp_runtime_log(RLOG_LV_DEBUG, "is not raw inline vlan pkt, upper layer type is:0x%x, drop it.", next_layer_type); } }else{ ret = PASS; diff --git a/src/inner_plug/sapp_assistant.cpp b/src/inner_plug/sapp_assistant.cpp index 8dcb4d5..292365c 100644 --- a/src/inner_plug/sapp_assistant.cpp +++ b/src/inner_plug/sapp_assistant.cpp @@ -75,8 +75,10 @@ int sapp_identify_tunnel_inner_pkt(const raw_pkt_t *raw_pkt) } } }else{ - /* TODO: ûmrtunnatʱ, ҪжǷǸ, Ƿoverlayİ */ - ret = 1; + /* ûmrtunnatʱ, ҪжǷǸ, Ƿoverlayİ */ + if(raw_pkt->is_overlay_pkt){ + ret = 1; + } } } #endif diff --git a/src/packet_io/packet_io.c b/src/packet_io/packet_io.c index 3cf3c3a..9910956 100644 --- a/src/packet_io/packet_io.c +++ b/src/packet_io/packet_io.c @@ -679,14 +679,14 @@ static int mesa_default_pkt_cb(const raw_pkt_t *p_raw_pkt, unsigned char dir, in //cycle_diagnose_pkt_dump(thread_num, p_raw_pkt); - if((DEPOLYMENT_MODE_INLINE == sapp_global_val->config.packet_io.depolyment_mode_bin) - && (PASS == ret)){ - packet_io_hook_forward((raw_pkt_t *)p_raw_pkt, p_raw_pkt->route_dir, thread_num); - - /* 2020-10-30 lijia add, in/out/injectİtcpdump_mesa, debug. */ - { - cycle_pkt_dump(thread_num, p_raw_pkt); - } + if(DEPOLYMENT_MODE_INLINE == sapp_global_val->config.packet_io.depolyment_mode_bin){ + if((p_raw_pkt->is_overlay_pkt)&& (PASS == ret)){ + packet_io_hook_forward((raw_pkt_t *)p_raw_pkt, p_raw_pkt->route_dir, thread_num); + }else{ + /* inlineģʽ, ԭʼ·еİ, DROPİ, ע· */ + ret = DROP; + //todo, pkt_dump for DROP + } } return ret; diff --git a/src/packet_io/packet_io_hook.c b/src/packet_io/packet_io_hook.c index 0e4cc7e..e3da6d1 100644 --- a/src/packet_io/packet_io_hook.c +++ b/src/packet_io/packet_io_hook.c @@ -97,6 +97,9 @@ static int packet_io_hook_update_vlan_couple(raw_pkt_t *raw_pkt, unsigned short raw_pkt->route_dir = sapp_global_val->config.packet_io.inbound_route_dir; } + sapp_runtime_log(RLOG_LV_DEBUG, "packet_io_hook_update_vlan(), this packet vlan:%u, the couple vlan:%u\n", vlan_id, vlan_map[vlan_id].couple_vlan_id); + raw_pkt->is_overlay_pkt = 1; + return 0; } @@ -112,19 +115,20 @@ static unsigned short get_vlan_id_from_rawpkt(raw_pkt_t *raw_pkt) static int packet_io_hook_input_vlan_flipping(raw_pkt_t *raw_pkt, unsigned char dir, int thread_num) { unsigned short vlan_id = 1; + const sapp_vlan_flipping_map_t *vlan_map = sapp_global_val->config.packet_io.packet_io_tunnel.vlan_flipping_map_array; int ret; vlan_id = marsio_get_vlan_id_from_mbuff((void *)raw_pkt->io_lib_pkt_reference); - if(vlan_id > 1){ + if((vlan_id > 1) && (vlan_map[vlan_id].couple_vlan_id > 1)){ /* vlan_id 不在vlan flipping表中, 不算作overlay packet */ packet_io_hook_update_vlan_couple(raw_pkt, vlan_id); ret= 0; }else{ vlan_id = get_vlan_id_from_rawpkt(raw_pkt); - if(vlan_id > 1){ + if((vlan_id > 1) && (vlan_map[vlan_id].couple_vlan_id > 1)){ /* vlan_id 不在vlan flipping表中, 不算作overlay packet */ packet_io_hook_update_vlan_couple(raw_pkt, vlan_id); }else{ - sapp_runtime_log(RLOG_LV_DEBUG, "warning: packet_io_hook_input(), not found vlan_id:%u\n", vlan_id); + sapp_runtime_log(RLOG_LV_DEBUG, "packet_io_hook_input(), not found vlan_id:%u in vlan flipping table\n", vlan_id); ret = -1; } } diff --git a/src/packet_io/packet_io_marsio.c b/src/packet_io/packet_io_marsio.c index 9b4d115..855f13f 100644 --- a/src/packet_io/packet_io_marsio.c +++ b/src/packet_io/packet_io_marsio.c @@ -556,6 +556,12 @@ static inline int marsio4_pkt_hand(int tid, marsio_buff_t *rx_buff, raw_pkt_t *r raw_pkt->io_lib_pkt_reference = rx_buff; raw_pkt->route_dir = mr_ctrlzone->route_dir; + /* clear pkt status */ + raw_pkt->is_overlay_pkt = 0; + raw_pkt->diagnose_error_to_dump = 0; + raw_pkt->vlan_flipping_couple[0] = 0; + raw_pkt->vlan_flipping_couple[1] = 0; + ret = (*g_marsio4_work_fun)((const raw_pkt_t *)raw_pkt, mr_ctrlzone->route_dir, tid); return ret; @@ -744,7 +750,7 @@ static void *marsio4_worker(void *arg) usleep(1000); } - while(1){ + while(1){ if(marsio4_process_packet(tid, &raw_pkt) > 0){ rcv_pkt_tims++; }else{ -- cgit v1.2.3