diff options
| author | 李佳 <[email protected]> | 2020-11-24 15:30:56 +0800 |
|---|---|---|
| committer | 李佳 <[email protected]> | 2020-11-24 15:30:56 +0800 |
| commit | 03d1a6f45ee92dbb362e594914e485adf987bd6d (patch) | |
| tree | 77c1db27ad1a7b1e9197c2dd4709bdd4e82455e6 | |
| parent | 5f789f63d66c65916a13788d54f3097b9202b4b8 (diff) | |
🐞fix(deal_ethernet.c): 修复Q-in-Q处理逻辑v4.2.8
close #50
| -rw-r--r-- | bin/etc/sapp.toml | 3 | ||||
| -rw-r--r-- | include/private/mesa_net.h | 6 | ||||
| -rw-r--r-- | include/private/packet_io.h | 4 | ||||
| -rw-r--r-- | include/private/packet_io_internal.h | 4 | ||||
| -rw-r--r-- | include/private/sapp_global_val.h | 2 | ||||
| -rw-r--r-- | include/private/stream_internal.h | 2 | ||||
| -rw-r--r-- | include/public/stream_inc/stream_base.h | 2 | ||||
| -rw-r--r-- | src/common/net_common.c | 88 | ||||
| -rw-r--r-- | src/config/config_parse.cpp | 8 | ||||
| -rw-r--r-- | src/dealpkt/deal_ethernet.c | 23 | ||||
| -rw-r--r-- | src/dealpkt/deal_vlan.c | 19 | ||||
| -rw-r--r-- | src/entry/sapp_init.c | 6 | ||||
| -rw-r--r-- | src/packet_io/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/packet_io/packet_io.c | 23 | ||||
| -rw-r--r-- | src/packet_io/pkt_dispatch_new.c | 71 | ||||
| -rw-r--r-- | src/packet_io/sendpacket.c | 31 |
16 files changed, 126 insertions, 168 deletions
diff --git a/bin/etc/sapp.toml b/bin/etc/sapp.toml index 3bd26f4..115ead4 100644 --- a/bin/etc/sapp.toml +++ b/bin/etc/sapp.toml @@ -60,6 +60,8 @@ dictator_enable=1 ### inject_mode_single_gateway_src_mac has lower priority than get smac from inject_mode_single_gateway_device inject_mode_single_gateway_src_mac="00:11:22:77:88:99" inject_mode_single_gateway_dst_mac="00:11:22:33:44:55" + + dumpfile_sleep_time_before_exit=3 ### note, depolyment.mode options: [mirror, inline, transparent] [packet_io.depolyment] @@ -87,7 +89,6 @@ dictator_enable=1 tcp_drop_pure_ack_pkt=0 tcp_syn_option_parse_enabled=1 skip_not_ip_layer_over_eth=0 - treat_vlan_as_mac_in_mac=0 reverse_ethernet_addr=1 diff --git a/include/private/mesa_net.h b/include/private/mesa_net.h index 5c47847..1bd9af0 100644 --- a/include/private/mesa_net.h +++ b/include/private/mesa_net.h @@ -39,9 +39,8 @@ extern "C" #define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging */ #define ETHERTYPE_LOOPBACK 0x9000 /* used to test interfaces */ -#define ETH_P_MAC_IN_MAC 0x88A8 /* pangu��Ŀ����88a8����, ���ڻ���MAC_IN_MAC���ݰ�, ��linux��0x88A8��ETH_P_8021AD���� */ - -#define ETHERTYPE_PANGU_MAC_IN_MAC 0x88A8 /* 2018-08-16 lijia add, for pangu MAC-in-MAC */ +//#define ETH_P_8021AD 0x88A8 +//#define ETHERTYPE_PANGU_MAC_IN_MAC 0x88A8 /* 2018-08-16 lijia add, for pangu MAC-in-MAC */ @@ -812,6 +811,7 @@ struct packet_io_mac_addr{ unsigned char net_layer_to_ipv4_protocol(int addr_type); unsigned char net_layer_to_ipv6_protocol(int addr_type); unsigned short net_layer_to_ethernet_protocol(int addr_type); +UINT16 net_layer_to_ethernet_protocol_by_stream(const struct streaminfo *pstream); enum addr_type_t ethernet_protocol_to_net_layer(UINT16 ether_type_host); int net_common_build_send_mac(unsigned char *buf, const struct mesa_ethernet_hdr *raw_eth_hdr, int addr_type, int dir_reverse, int net_topology_mode); int net_common_adjust_forward_mac(struct mesa_ethernet_hdr *raw_eth_hdr,int net_topology_mode); diff --git a/include/private/packet_io.h b/include/private/packet_io.h index c0d837d..3c26839 100644 --- a/include/private/packet_io.h +++ b/include/private/packet_io.h @@ -152,8 +152,8 @@ extern int ipv6_entry(struct streaminfo_private *pfstream, const void *this_laye unsigned char routedir, const raw_pkt_t *raw_pkt, int);
int eth_entry(struct streaminfo_private *fstream, const void *this_layer_hdr,
int thread_num, unsigned char dir, const raw_pkt_t *raw_pkt, int offset_to_raw_hdr);
-int vlan_8021q_entry(struct streaminfo_private *pfstream,const void *this_layer_hdr,int thread_num,
- unsigned char routedir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr);
+int IEEE_8021_entry(struct streaminfo_private *pfstream,const void *this_layer_hdr,int thread_num,
+ unsigned char routedir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr, unsigned short ethtype);
int arp_entry(struct streaminfo_private *fstream, const void *this_layer_hdr,
int thread_num, unsigned char dir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr);
extern int ppp_entry(struct streaminfo_private*pfstream, const void *this_layer_data, int thread_num,
diff --git a/include/private/packet_io_internal.h b/include/private/packet_io_internal.h index 82ec0f0..9101580 100644 --- a/include/private/packet_io_internal.h +++ b/include/private/packet_io_internal.h @@ -9,6 +9,10 @@ extern "C" {
#endif
+/* 802.1Q��802.1AD ͷ����ʽ��ʵ��һ��, ֻ��ethernet type��һ��, ���Dz����ֵĻ�, ע�����ݰ����д�, ͨ����Щֵ����addr.pkttype�ֶ�,������������ */
+#define ADDR_TYPE_8021Q_ABBR (0x81)
+#define ADDR_TYPE_8021AD_ABBR (0x88)
+
#ifndef RTE_CACHE_LINE_SIZE
#define RTE_CACHE_LINE_SIZE 64
#define __sapp_aligned(a) __attribute__((__aligned__(a)))
diff --git a/include/private/sapp_global_val.h b/include/private/sapp_global_val.h index 542eaa3..ea0483c 100644 --- a/include/private/sapp_global_val.h +++ b/include/private/sapp_global_val.h @@ -258,6 +258,7 @@ typedef struct{ char inject_mode_single_gateway_dst_mac_string[20]; char inject_mode_single_gateway_dst_mac[6]; /* gateway��MAC */ char inject_mode_single_gateway_src_mac[6]; /* inject_mode_single_gateway_device������MAC */ + int dumpfile_sleep_time_before_exit; /* ����ģʽ�˳�֮ǰ, Ϊ��ijЩ�߳��ܻ�д��־, �첽�������ݵȲ���, ��sleepһ�� */ }sapp_config_packet_io_t; typedef struct{ @@ -274,7 +275,6 @@ typedef struct{ int tcp_drop_pure_ack_pkt; /* ����û�и��صĴ�ack��, ���Խ�Լһ��������ѯ, ����ҵ���������� */ int tcp_syn_option_parse_enabled; /* �Ƿ����tcp syn��ͷ��ѡ�� */ int skip_not_ip_layer_over_eth; /* ������ip��, ��֤�ڲ���ģʽ��, ����ͨ��ϵͳ·�ɷ���rst�� */ - int treat_vlan_as_mac_in_mac_enabled; /* MAC-in-MAC��װ��ʽ��tcpdump�����洢��, �����0x8100, ��������ʱ������vlan����, �����, ͨ�������ļ�ǿ��ָ��0x8100��Ϊmac-in-mac���� */ int reverse_ethernet_addr_enabled; /* smac��ַ�а���������Ϣʱ���跭ת */ }sapp_protocol_feature_t; diff --git a/include/private/stream_internal.h b/include/private/stream_internal.h index 055b3fc..6c73886 100644 --- a/include/private/stream_internal.h +++ b/include/private/stream_internal.h @@ -326,8 +326,6 @@ struct sapp_global_single_t{ //int send_fake_pkt_mode; /* 2018-10-26 lijia add, for PanGu, ����ȱ��FD·��, ����ô���GDEV����rst��, DNS-fake����,mode 0�� Э��ջ���㷢���� 1��Э��ջ���㷢����3��gdevע�뷢������ģʽ��send_fake_pkt_gdev_sport��Ч */ //int send_fake_pkt_gdev_sport; /* 2018-10-26 lijia add, for PanGu, ����ѡ��vxlanԴ�˿� */ int send_fake_pkt_sip; - int treat_vlan_as_mac_in_mac_sw; /* MAC_IN_MAC���ᱻЭ��ջ��Ϊvlan��, ���߲���debug�ܲ�����, ���Ӵ�����, ǿ�ƽ�vlan����ΪMAC_IN_MAC��ʽ���� */ - //int create_mpls_anyway;/*��������MAC��IP��֮�䴴��MPLS��*/ }; diff --git a/include/public/stream_inc/stream_base.h b/include/public/stream_inc/stream_base.h index 8581e82..f657842 100644 --- a/include/public/stream_inc/stream_base.h +++ b/include/public/stream_inc/stream_base.h @@ -57,7 +57,7 @@ enum addr_type_t{ __ADDR_TYPE_INIT = 0, ADDR_TYPE_IPV4, /* 1, struct stream_tuple4_v4 */ ADDR_TYPE_IPV6, /* 2, struct stream_tuple4_v6 */ - ADDR_TYPE_VLAN, /* 3 */ + ADDR_TYPE_VLAN, /* 3, 802.1Q */ ADDR_TYPE_MAC, /* 4 */ ADDR_TYPE_ARP = 5, /* 5 */ ADDR_TYPE_GRE, /* 6 */ diff --git a/src/common/net_common.c b/src/common/net_common.c index 5cdb99a..174d00d 100644 --- a/src/common/net_common.c +++ b/src/common/net_common.c @@ -440,14 +440,11 @@ static int __common_eth_type_dispatch(UINT16 eth_type, const char *next_layer_da break; case ETH_P_8021Q: + case ETH_P_8021AD: if(ADDR_TYPE_VLAN == expect_layer_type){ break; }else{ - if(sapp_global_val->config.protocol_feature.treat_vlan_as_mac_in_mac_enabled){ - skip_len = eth_jump_to_layer(next_layer_data, ADDR_TYPE_MAC, expect_layer_type); - }else{ - skip_len = vlan8021q_jump_to_layer(next_layer_data, ADDR_TYPE_VLAN, expect_layer_type); - } + skip_len = vlan8021q_jump_to_layer(next_layer_data, ADDR_TYPE_VLAN, expect_layer_type); } break; @@ -475,11 +472,7 @@ static int __common_eth_type_dispatch(UINT16 eth_type, const char *next_layer_da } break; - case 0x88A8: /* MAC_IN_MAC */ - skip_len = eth_jump_to_layer(next_layer_data, ADDR_TYPE_MAC, expect_layer_type); - break; - - case 0x8847: /* MPLS, ETH_P_MPLS_UC */ + case ETH_P_MPLS_UC: /* MPLS, ETH_P_MPLS_UC */ skip_len = mpls_jump_to_layer(next_layer_data, ADDR_TYPE_MPLS, expect_layer_type); break; @@ -651,11 +644,7 @@ const void *MESA_net_jump_to_layer(const void *raw_data, int raw_layer_type, in ret = arp_jump_to_layer((const char *)raw_data, raw_layer_type, expect_layer_type); break; case ADDR_TYPE_VLAN: - if(sapp_global_val->config.protocol_feature.treat_vlan_as_mac_in_mac_enabled){ - ret = mac_in_mac_jump_to_layer((const char *)raw_data, raw_layer_type, expect_layer_type); - }else{ - ret = vlan8021q_jump_to_layer((const char *)raw_data, raw_layer_type, expect_layer_type); - } + ret = vlan8021q_jump_to_layer((const char *)raw_data, raw_layer_type, expect_layer_type); break; case __ADDR_TYPE_IP_PAIR_V4: @@ -853,14 +842,65 @@ UINT16 net_layer_to_ethernet_protocol(int addr_type) ether_type = ETH_P_ARP; break; - case ADDR_TYPE_MAC: - if(sapp_global_val->config.protocol_feature.treat_vlan_as_mac_in_mac_enabled){ - ether_type = ETHERTYPE_VLAN; + default: + /* to do, unknown type */ + sapp_runtime_log(RLOG_LV_FATAL, "%s:%d: unknown ethernet carry addr type:%d!\n", __FILE__, __LINE__, addr_type); + ether_type = -1; + break; + } + + return ether_type; +} + +/* + ��MESA��ַ����ת��Ϊ��Ethernet����; + + return value: + ethernet type, host order. +*/ +UINT16 net_layer_to_ethernet_protocol_by_stream(const struct streaminfo *pstream) +{ + UINT16 ether_type = 0; + int addr_type = pstream->addr.addrtype; + + switch(addr_type){ + case __ADDR_TYPE_IP_PAIR_V4: + case ADDR_TYPE_IPV4: + ether_type = ETH_P_IP; + break; + + case __ADDR_TYPE_IP_PAIR_V6: + case ADDR_TYPE_IPV6: + ether_type = ETH_P_IPV6; + break; + + case ADDR_TYPE_VLAN: + if(ADDR_TYPE_8021Q_ABBR == pstream->addr.pkttype){ + ether_type = ETH_P_8021Q; }else{ - ether_type = ETHERTYPE_PANGU_MAC_IN_MAC; + ether_type = ETH_P_8021AD; } break; - + + case ADDR_TYPE_TCP: + case ADDR_TYPE_UDP: + sapp_runtime_log(RLOG_LV_FATAL, "%s:%d: Ethernet can't carry addr type:%d directly!\n", __FILE__, __LINE__,addr_type); + //assert(0); + ether_type = -1; + break; + + case ADDR_TYPE_PPPOE_SES: + ether_type = ETH_P_PPP_SES; + break; + + case ADDR_TYPE_MPLS: + ether_type = ETH_P_MPLS_UC; + break; + + case ADDR_TYPE_ARP: + ether_type = ETH_P_ARP; + break; + default: /* to do, unknown type */ sapp_runtime_log(RLOG_LV_FATAL, "%s:%d: unknown ethernet carry addr type:%d!\n", __FILE__, __LINE__, addr_type); @@ -888,7 +928,8 @@ enum addr_type_t ethernet_protocol_to_net_layer(UINT16 ether_type_host) addrtype = __ADDR_TYPE_IP_PAIR_V6; break; - case ETHERTYPE_VLAN: + case ETH_P_8021Q: + case ETH_P_8021AD: addrtype = ADDR_TYPE_VLAN; break; @@ -903,11 +944,12 @@ enum addr_type_t ethernet_protocol_to_net_layer(UINT16 ether_type_host) case ETH_P_ARP: addrtype = ADDR_TYPE_ARP; break; - +#if 0 case ETHERTYPE_PANGU_MAC_IN_MAC: addrtype = ADDR_TYPE_MAC_IN_MAC; break; - +#endif + default: /* to do, unknown type */ sapp_runtime_log(RLOG_LV_INFO, "%s:%d: unknown ethernet carry addr type:0x%x\n", __FILE__, __LINE__, ether_type_host); diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp index b20918e..86b245c 100644 --- a/src/config/config_parse.cpp +++ b/src/config/config_parse.cpp @@ -1014,11 +1014,6 @@ static int config_sanity_check(void) old_config_file_detect("./conf/main.conf", "./etc/sapp.toml"); - if(pconfig->protocol_feature.treat_vlan_as_mac_in_mac_enabled != 0){ - sapp_log(30, ~0, ~0, "[Warning]'treat_vlan_as_mac_in_mac' is enable, vlan packet will be treat as MAC_IN_MAC!"); - usleep(10000); - } - return 0; } @@ -1130,6 +1125,7 @@ int sapp_parse_config(void) }else{ pconfig->packet_io.inject_mode_inline_device_sport = tmp_int; } + tomlc99_wrap_load_int_def(default_config_file, (char *)"packet_io.feature", (char *)"dumpfile_sleep_time_before_exit", &pconfig->packet_io.dumpfile_sleep_time_before_exit, 1); tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.depolyment", (char *)"mode", pconfig->packet_io.depolyment_mode_str, NAME_MAX, "mirror"); tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.internal.interface", (char *)"type", pconfig->packet_io.internal.interface.type_str, NAME_MAX, "pcap"); @@ -1234,7 +1230,7 @@ int sapp_parse_config(void) tomlc99_wrap_load_int_def(default_config_file, (char *)"PROTOCOL_FEATURE", (char *)"tcp_drop_pure_ack_pkt", (int *)&pconfig->protocol_feature.tcp_drop_pure_ack_pkt, 0); tomlc99_wrap_load_int_def(default_config_file, (char *)"PROTOCOL_FEATURE", (char *)"tcp_syn_option_parse_enabled", (int *)&pconfig->protocol_feature.tcp_syn_option_parse_enabled, 1); tomlc99_wrap_load_int_def(default_config_file, (char *)"PROTOCOL_FEATURE", (char *)"skip_not_ip_layer_over_eth", (int *)&pconfig->protocol_feature.skip_not_ip_layer_over_eth, 0); - tomlc99_wrap_load_int_def(default_config_file, (char *)"PROTOCOL_FEATURE", (char *)"treat_vlan_as_mac_in_mac", (int *)&pconfig->protocol_feature.treat_vlan_as_mac_in_mac_enabled, 0); + //tomlc99_wrap_load_int_def(default_config_file, (char *)"PROTOCOL_FEATURE", (char *)"treat_vlan_as_mac_in_mac", (int *)&pconfig->protocol_feature.treat_vlan_as_mac_in_mac_enabled, 0); tomlc99_wrap_load_int_def(default_config_file, (char *)"PROTOCOL_FEATURE", (char *)"reverse_ethernet_addr", (int *)&pconfig->protocol_feature.reverse_ethernet_addr_enabled, 1); /******************************* TOOLS **********************************/ diff --git a/src/dealpkt/deal_ethernet.c b/src/dealpkt/deal_ethernet.c index 47b0ebb..90f6dc0 100644 --- a/src/dealpkt/deal_ethernet.c +++ b/src/dealpkt/deal_ethernet.c @@ -138,7 +138,7 @@ int eth_entry(struct streaminfo_private *fstream_pr, const void *this_layer_hdr, //else
{
switch(eth_type){
- case ETHERTYPE_IP:
+ case ETH_P_IP:
if(g_skip_ethernet_layer_sw){
((raw_pkt_t *)raw_pkt)->low_layer_type = (enum addr_type_t)CAP_LEVEL_IPV4;
}
@@ -146,7 +146,7 @@ int eth_entry(struct streaminfo_private *fstream_pr, const void *this_layer_hdr, ret = ipv4_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
break;
- case ETHERTYPE_IPv6:
+ case ETH_P_IPV6:
if(g_skip_ethernet_layer_sw){
((raw_pkt_t *)raw_pkt)->low_layer_type = (enum addr_type_t)CAP_LEVEL_IPV6;
}
@@ -154,15 +154,13 @@ int eth_entry(struct streaminfo_private *fstream_pr, const void *this_layer_hdr, ret = ipv6_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
break;
- case ETHERTYPE_VLAN:
+ case ETH_P_8021Q:
+ /* 2020-11-23 lijia add, ����֧��2018��panguһ��ʹ��0x88a8��ΪMAC-IN-MAC��ʽ���ݰ���ʹ��802.1adԭʼ��ʽ���� */
+ case ETH_P_8021AD:
((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- if(sapp_global_val->config.protocol_feature.treat_vlan_as_mac_in_mac_enabled){
- //ret = mac_in_mac_entry(pstream_pr,next_layer_data,thread_num,dir,raw_pkt, next_layer_offset);
- ret = eth_entry(pstream_pr,next_layer_data,thread_num,dir,raw_pkt, next_layer_offset);
- }else{
- ret = vlan_8021q_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- }
+ ret = IEEE_8021_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset, eth_type);
break;
+
case ETH_P_PPP_SES:
((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
@@ -179,13 +177,6 @@ int eth_entry(struct streaminfo_private *fstream_pr, const void *this_layer_hdr, ret = arp_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
break;
- /* 2018-08-19 lijia add, for PanGu��Ŀ��������������ʽ, ������ETH_P_8021AD(0x88A8)�ֶ�, ʵ����MAC-IN-MAC��ʽ���ݰ� */
- case ETHERTYPE_PANGU_MAC_IN_MAC:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- //ret = mac_in_mac_entry(pstream_pr,next_layer_data,thread_num,dir,raw_pkt, next_layer_offset);
- ret = eth_entry(pstream_pr,next_layer_data,thread_num,dir,raw_pkt, next_layer_offset);
- break;
-
default:
/* unknown protocol */
diff --git a/src/dealpkt/deal_vlan.c b/src/dealpkt/deal_vlan.c index 52f3dbf..ba47233 100644 --- a/src/dealpkt/deal_vlan.c +++ b/src/dealpkt/deal_vlan.c @@ -35,8 +35,11 @@ int set_vlan_addr(struct layer_addr_vlan *addr, const unsigned char *vlan_tag) return vlan_layer_len;
}
-int vlan_8021q_entry(struct streaminfo_private *pfstream_pr,const void *this_layer_data,int thread_num,
- unsigned char routedir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr)
+/*
+ 802.1Q��802.1AD����һ����ں���, ʹ��eth_type��������.
+*/
+int IEEE_8021_entry(struct streaminfo_private *pfstream_pr,const void *this_layer_data,int thread_num,
+ unsigned char routedir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr, unsigned short eth_type)
{
int ret = PASS;
struct streamindex tmp_index;
@@ -59,8 +62,12 @@ int vlan_8021q_entry(struct streaminfo_private *pfstream_pr,const void *this_lay pstream->addr.addrtype = ADDR_TYPE_VLAN;
pstream->addr.addrlen = sizeof(struct layer_addr_vlan);
pstream_pr->addr_use_as_hash = 0;//��ַ������hash�ȶԣ��������
- //ptmp->stream.p_layer_header = this_layer_data;
- //ptmp->stream.offset_to_raw_pkt_hdr = (char *)this_layer_data - (char *)raw_pkt->raw_pkt_data;
+ if(ETH_P_8021Q == eth_type){
+ pstream->addr.pkttype = ADDR_TYPE_8021Q_ABBR;
+ }else{
+ pstream->addr.pkttype = ADDR_TYPE_8021AD_ABBR;
+ }
+
pstream_pr->offset_to_raw_pkt_hdr = offset_to_raw_pkt_hdr;
pstream_pr->raw_pkt = raw_pkt; /* 2014-12-30 lijia add */
@@ -99,9 +106,7 @@ int vlan_8021q_entry(struct streaminfo_private *pfstream_pr,const void *this_lay break;
case ETH_P_8021Q:
- //((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- //ret=vlan_8021q_entry(pstream_pr, next_layer_hdr,thread_num, routedir,raw_pkt, next_layer_offset);
- sapp_runtime_log(30, "vlan_8021q_entry(): VLAN combine to one layer!\n");
+ sapp_runtime_log(30, "IEEE_8021_entry(): consecutive VLAN layer combine to one layer!\n");
assert(0);
break;
diff --git a/src/entry/sapp_init.c b/src/entry/sapp_init.c index 9b81857..4eddd49 100644 --- a/src/entry/sapp_init.c +++ b/src/entry/sapp_init.c @@ -412,11 +412,7 @@ int MESA_platform_init(int argc, char *argv[]) sapp_assistant_init(); MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"Module", (char *)"send_tcp_offload", &sapp_global_single.cfg_send_tcp_offload_sw, 0); - //MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"Module", (char *)"treat_vlan_as_mac_in_mac", &sapp_global_single.treat_vlan_as_mac_in_mac_sw, 0); - //if(sapp_global_single.treat_vlan_as_mac_in_mac_sw){ - //printf("\n\033[33m[Warning]'treat_vlan_as_mac_in_mac' is enable, vlan packet will be treat as MAC_IN_MAC!\033[0m\n"); - //usleep(10000); - //} + sapp_set_current_state(SAPP_STATE_PLATFORM_INITED); /* 2017-02-24 lijia modify, diff --git a/src/packet_io/CMakeLists.txt b/src/packet_io/CMakeLists.txt index c6d90b2..966c36e 100644 --- a/src/packet_io/CMakeLists.txt +++ b/src/packet_io/CMakeLists.txt @@ -65,7 +65,7 @@ if(CAPTURE_MODE MATCHES "TUN") endif() endif() -set(PACKET_IO_STATIC_SOURCE cycle_pkt_dump_through_write_offset.c packet_io_lib_load.c pkt_dispatch_new.c +set(PACKET_IO_STATIC_SOURCE cycle_pkt_dump_through_write_offset.c packet_io_lib_load.c iknow_info.c packet_io_log.c sendpacket.c packet_io.c packet_io_status.cpp packet_io_status_new.c diff --git a/src/packet_io/packet_io.c b/src/packet_io/packet_io.c index 0f3a818..51e8251 100644 --- a/src/packet_io/packet_io.c +++ b/src/packet_io/packet_io.c @@ -713,11 +713,7 @@ void packet_io_exit(void) { /* ����ģʽ��, �������߳�һЩʱ��, ����δ�������, ����MESA_tcp�첽�������ݵȵ�. */ sapp_set_current_state(SAPP_STATE_READY_TO_EXIT); - sched_yield(); - sleep(1); - sched_yield(); - sleep(1); - + sleep(sapp_global_val->config.packet_io.dumpfile_sleep_time_before_exit); plugctrl_destroy_all_plug(); exit(1); @@ -864,12 +860,7 @@ static int packet_io_calc_ethernet_offset_to_ip(const unsigned char *sendbuf) break; case CAP_LEVEL_MAC: - outer_ehdr = (struct mesa_ethernet_hdr *)sendbuf; - if(ETHERTYPE_PANGU_MAC_IN_MAC == ntohs(outer_ehdr->ether_type)){ - offset = MAC_IN_MAC_HDR_LEN; - }else{ offset = sizeof(struct mesa_ethernet_hdr); - } break; default: @@ -1148,10 +1139,14 @@ int packet_io_send_fake_pkt(MESA_send_handle *send_handle,int datalen,int send_t char *feedback_buf, int *feedback_buf_len, const raw_pkt_t *raw_pkt) { int ret; - UINT16 ether_type; + UINT16 low_layer_ether_hproto; + const struct mesa_ethernet_hdr *ehdr = (struct mesa_ethernet_hdr *)send_handle->send_buf; if(g_topology_mode & __NET_CONN_PARALLEL) { + + low_layer_ether_hproto = ntohs(ehdr->ether_type); + if(sapp_global_val->config.packet_io.inject_pkt_mode == SEND_PKT_MODE_GDEV) { ret = packet_io_send_fake_pkt_by_gdev(send_handle, (enum addr_type_t)low_layer_type, @@ -1160,8 +1155,7 @@ int packet_io_send_fake_pkt(MESA_send_handle *send_handle,int datalen,int send_t else if(sapp_global_val->config.packet_io.inject_pkt_mode == SEND_PKT_MODE_STACK_2_LAYER_1_ROUTE || sapp_global_val->config.packet_io.inject_pkt_mode == SEND_PKT_MODE_STACK_2_LAYER_MUTI_ROUTE) { - ether_type = net_layer_to_ethernet_protocol(low_layer_type); - ret = packet_io_send_by_manual_conf(send_handle, datalen, dir, ether_type); + ret = packet_io_send_by_manual_conf(send_handle, datalen, dir, low_layer_ether_hproto); } else { @@ -1179,8 +1173,7 @@ int packet_io_send_fake_pkt(MESA_send_handle *send_handle,int datalen,int send_t default: /* ����ģʽ�µķ�IPЭ��, ����ʹ��ϵͳ·�ɷ���, ����ʹ��raw_eth_fdͨ��ָ���������� */ - ether_type = net_layer_to_ethernet_protocol(low_layer_type); - ret = packet_io_send_by_manual_conf(send_handle, datalen, dir, ether_type); + ret = packet_io_send_by_manual_conf(send_handle, datalen, dir, low_layer_ether_hproto); break; } } diff --git a/src/packet_io/pkt_dispatch_new.c b/src/packet_io/pkt_dispatch_new.c deleted file mode 100644 index 514f30d..0000000 --- a/src/packet_io/pkt_dispatch_new.c +++ /dev/null @@ -1,71 +0,0 @@ -#ifdef __cplusplus -extern "C" { -#endif - -#include "sapp_api.h" -#include "sapp_private_api.h" - -#if 0 -static inline void set_mac_addr(struct layer_addr_mac *addr, const struct mesa_ethernet_hdr *p_eth_hdr) -{ - memcpy(addr->src_mac, p_eth_hdr->ether_shost, ETHER_ADDR_LEN); - memcpy(addr->dst_mac, p_eth_hdr->ether_dhost, ETHER_ADDR_LEN); -} - - -int eth_entry(struct streaminfo *fstream, void *raw_data, - int thread_num, unsigned char dir) -{ - int ret = PASS; - const struct mesa_ethernet_hdr *p_eth_hdr = (struct mesa_ethernet_hdr *)raw_data; - unsigned short eth_type = ntohs(p_eth_hdr->ether_type); - unsigned char *next_layer_data =(unsigned char *)raw_data + sizeof(struct mesa_ethernet_hdr); - //int next_layer_len = datalen - sizeof(struct ethhdr); - - struct streamindex tmp_index; - struct streamindex *ptmp = &tmp_index; - struct layer_addr_mac addr; - - memset(ptmp,0,sizeof(struct streamindex)); - set_mac_addr(&addr, p_eth_hdr); - ptmp->stream.addr.paddr = &addr; - ptmp->stream.addr.addrtype = ADDR_TYPE_MAC; - - ptmp->stream.pfather = fstream; - ptmp->stream.type = STREAM_TYPE_NON; - ptmp->stream.routedir = dir; - ptmp->stream.threadnum = thread_num; - - switch(eth_type){ - case ETH_P_ARP: - arp_entry(&(ptmp->stream), next_layer_data, thread_num, dir); - break; - - case ETH_P_8021Q: - vlan_8021q_entry(&(ptmp->stream), next_layer_data, thread_num, dir); - break; - - case ETH_P_IP: - ipv4_entry(&(ptmp->stream), next_layer_data, thread_num, dir); - break; - - case ETH_P_IPV6: - ipv6_entry(&(ptmp->stream), next_layer_data, thread_num, dir); - break; - - default: - /* unknown protocol */ - ret = PASS; - break; - } - - return ret; -} -#endif - - -#ifdef __cplusplus -} -#endif - - diff --git a/src/packet_io/sendpacket.c b/src/packet_io/sendpacket.c index b37255b..710d191 100644 --- a/src/packet_io/sendpacket.c +++ b/src/packet_io/sendpacket.c @@ -1807,19 +1807,21 @@ static int build_net_layer_l2tp(struct streaminfo_private *stream_pr, int carry_ send_stream_dir: ��ʾ��ǰ������������, DIR_C2S����DIR_S2C, ��ΪMPLS, GTP�Ȳ�ԭʼ����ֻ�е����ַ, reverse�ĺ��岻�ܾ�ȷ��ʾmpls, gtp�Ȳ㵽��ʹ���ĸ�����ĵ�ַ. */ -static int build_net_layer_pkt(struct streaminfo_private *stream_pr, int carry_layer_type, +static int build_net_layer_pkt(const struct streaminfo *up_stream, struct streaminfo_private *stream_pr, int carry_layer_type, int carry_layer_len, unsigned char *buf, int reverse, const raw_pkt_t *raw_pkt, UCHAR send_stream_dir) { int this_layer_len = 0, ret; int transport_layer_len; struct streaminfo *stream; char debug_print_buf[256]; + const struct streaminfo *carry_layer_stream; if(NULL == stream_pr){ return carry_layer_len; } stream = &stream_pr->stream_public; + carry_layer_stream = stream; if(is_proxy_stream(stream)){ /* �������ṹΪ����ṹ, ʵ�ʵİ������ڴ˲�, �����ʱ���������� */ this_layer_len = 0; @@ -1928,7 +1930,7 @@ static int build_net_layer_pkt(struct streaminfo_private *stream_pr, int carry_l /* ����Dz���ģʽ, �˴����Բ�����mac��ַ, ����֪packet_io_send_fake_pkt�����ײ�����, MAC����MAC_IN_MAC ����ģʽ��Ҫ���ݵ�ǰԭʼ��, ��send_dir����mac��ַ. */ - unsigned short eth_type_host = net_layer_to_ethernet_protocol(carry_layer_type); + unsigned short eth_type_host = net_layer_to_ethernet_protocol_by_stream(up_stream); if((unsigned short)-1 == eth_type_host){ sapp_runtime_log(20, "build_net_layer_pkt()-->ADDR_TYPE_MAC, unsupport carry_layer_type:0x%x!\n", carry_layer_type); return -1; @@ -1964,6 +1966,7 @@ static int build_net_layer_pkt(struct streaminfo_private *stream_pr, int carry_l if(0 == this_layer_len){ /* �ǶԳ�MPLS, Ϊ�����������������һ��, ������ʵ�ʰ�ͷ */ sapp_runtime_log(10, "build_net_layer_mpls() send streamdir:%d, skip fake mpls layer.\n", send_stream_dir); + carry_layer_stream = up_stream; break; }else{ buf -= this_layer_len; @@ -2024,10 +2027,10 @@ static int build_net_layer_pkt(struct streaminfo_private *stream_pr, int carry_l case ADDR_TYPE_PPP: assert(0); /* PPTP������gre��ppp�ϲ�Ϊһ��, ���벻����ִ�е��˴� */ - this_layer_len = sizeof(struct mesa_ppp_hdr); - buf -= sizeof(struct mesa_ppp_hdr); - build_net_layer_ppp(stream_pr, carry_layer_type, carry_layer_len, buf, reverse, raw_pkt, 0); - carry_layer_type = ADDR_TYPE_PPP; + //this_layer_len = sizeof(struct mesa_ppp_hdr); + //buf -= sizeof(struct mesa_ppp_hdr); + //build_net_layer_ppp(stream_pr, carry_layer_type, carry_layer_len, buf, reverse, raw_pkt, 0); + //carry_layer_type = ADDR_TYPE_PPP; break; case ADDR_TYPE_PPTP: @@ -2062,7 +2065,7 @@ static int build_net_layer_pkt(struct streaminfo_private *stream_pr, int carry_l this_layer_len = gre_layer_len + ppp_hdr_len; } break; - +#if 0 case ADDR_TYPE_MAC_IN_MAC: { buf -= sizeof(struct mesa_ethernet_hdr); @@ -2078,7 +2081,7 @@ static int build_net_layer_pkt(struct streaminfo_private *stream_pr, int carry_l sapp_runtime_log(10, "build_net_layer_pkt()-->ADDR_TYPE_MAC_IN_MAC, buf start addr:%p, this_layer_len:%d", buf, this_layer_len); } break; - +#endif default: sapp_runtime_log(30, "build_net_layer_pkt(): unsupport addr type:%d!\n", stream->addr.addrtype); goto err; @@ -2086,7 +2089,7 @@ static int build_net_layer_pkt(struct streaminfo_private *stream_pr, int carry_l } done: - return build_net_layer_pkt((struct streaminfo_private *)stream->pfather,carry_layer_type, + return build_net_layer_pkt(carry_layer_stream, (struct streaminfo_private *)stream->pfather,carry_layer_type, this_layer_len+carry_layer_len, buf, reverse, raw_pkt, send_stream_dir); err: @@ -2188,7 +2191,7 @@ static int __do_kill_tcp(struct streaminfo *stream, const void *ext_raw_pkt, int send_handle->send_buf = packet_io_get_sendbuf(SEND_TYPE_LINK_INJECT, thread_num); sapp_runtime_log(10, "before build_net_layer_pkt(), buf addr:%p, streamdir:%d, total layer len:%d", send_handle->send_buf, stream->curdir, reserved_hdr_len); - send_len = build_net_layer_pkt(stream_pr, ADDR_TYPE_TCP, 0, send_handle->send_buf + reserved_hdr_len, 0, raw_pkt, stream->curdir); + send_len = build_net_layer_pkt(stream, stream_pr, ADDR_TYPE_TCP, 0, send_handle->send_buf + reserved_hdr_len, 0, raw_pkt, stream->curdir); if(send_len > 0){ /* �Ĵ����ж���, ����ʧ�ܲ��˳�, �������Է�������� */ ret = packet_io_send(send_handle, reserved_hdr_len, SEND_TYPE_LINK_INJECT, @@ -2238,7 +2241,7 @@ static int __do_kill_tcp(struct streaminfo *stream, const void *ext_raw_pkt, int send_handle->send_buf = packet_io_get_sendbuf(SEND_TYPE_LINK_INJECT, thread_num); sapp_runtime_log(10, "before build_net_layer_pkt(), buf addr:%p, streamdir:%d, total layer len:%d", send_handle->send_buf, stream->curdir ^ DIR_DOUBLE, reserved_hdr_len); - send_len = build_net_layer_pkt(stream_pr, ADDR_TYPE_TCP, 0, send_handle->send_buf + reserved_hdr_len, 1, raw_pkt, stream->curdir ^ DIR_DOUBLE); + send_len = build_net_layer_pkt(stream, stream_pr, ADDR_TYPE_TCP, 0, send_handle->send_buf + reserved_hdr_len, 1, raw_pkt, stream->curdir ^ DIR_DOUBLE); if(send_len > 0){ /* �Ĵ����ж���, ����ʧ�ܲ��˳�, �������Է�������� */ ret = packet_io_send(send_handle, reserved_hdr_len, SEND_TYPE_LINK_INJECT, @@ -2408,7 +2411,7 @@ static int __do_kill_tcp_synack(struct streaminfo *stream, const void *ext_raw_p for(i = 0; i < KILL_TCP_SYN_ACK_NUM; i++){ send_handle->send_buf = packet_io_get_sendbuf(SEND_TYPE_LINK_INJECT, thread_num); - send_len = build_net_layer_pkt(stream_pr, ADDR_TYPE_TCP, 0, send_handle->send_buf + reserved_hdr_len, 1, raw_pkt, stream->curdir ^ DIR_DOUBLE); + send_len = build_net_layer_pkt(stream, stream_pr, ADDR_TYPE_TCP, 0, send_handle->send_buf + reserved_hdr_len, 1, raw_pkt, stream->curdir ^ DIR_DOUBLE); if(send_len < 0){ ret = -1; goto fun_exit; @@ -2792,7 +2795,7 @@ int __do_inject_pkt(struct streaminfo *stream, const char *payload, int payload_ memcpy(send_handle->send_buf + reserved_hdr_len, payload, payload_len); - send_len = build_net_layer_pkt(stream_pr, stream->addr.addrtype, payload_len, + send_len = build_net_layer_pkt(stream, stream_pr, stream->addr.addrtype, payload_len, send_handle->send_buf + reserved_hdr_len, snd_routedir_reverse, raw_pkt, stream_send_dir); if(send_len < 0){ ret = -1; @@ -3043,7 +3046,7 @@ int __sapp_inject_pkt(struct streaminfo *raw_stream, enum sapp_inject_opt sio, memcpy(send_handle->send_buf + reserved_hdr_len, payload, payload_len); - send_len = build_net_layer_pkt(inject_stream_pr, carry_layer_type, payload_len, + send_len = build_net_layer_pkt(raw_stream, inject_stream_pr, carry_layer_type, payload_len, send_handle->send_buf + reserved_hdr_len, snd_routedir_reverse, raw_pkt, send_stream_dir); if(send_len < 0){ ret = -1; |
