diff options
| author | 杨威 <[email protected]> | 2022-05-11 20:19:50 +0800 |
|---|---|---|
| committer | 杨威 <[email protected]> | 2022-05-16 19:20:42 +0800 |
| commit | 81f1be372a53b9eff2bda12246015cf59bdb7993 (patch) | |
| tree | 9b7dc8939d72bba30694f4b6ab3b796a95cd23ef | |
| parent | 7dd2d7ef389d75c375bbf01e9af76ec1761312e5 (diff) | |
🌈 style(deal_mpls.c): 移除注释代码,格式对齐
| -rw-r--r-- | .gitlab-ci.yml | 27 | ||||
| -rw-r--r-- | src/dealpkt/deal_mpls.c | 271 |
2 files changed, 124 insertions, 174 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4ec1cc7..6f1be1e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -72,27 +72,30 @@ sapp_module_test_for_centos7: - sed -i '14 i__log_test_sapp_benchmark_log.debug >stdout; other' etc/sapp_log.conf - sed -i '11 i__log_runtimelog.info >stdout; other' etc/sapp_log.conf - ulimit -c unlimited +#using module v1.0 +# - ./gtest_sapp_v4 -f tcpall.* +# - ./gtest_sapp_v4 -f control.* +# - ./gtest_sapp_v4 -f project.* +# - ./gtest_sapp_v4 -f stream_bridge.* +# - ./gtest_sapp_v4 -f tunnel.* +# - ./gtest_sapp_v4 -f inject.* +# - ./gtest_sapp_v4 -f plug_ctrl.* +# - ./gtest_sapp_v4 -f jump_layer.* +# - ./gtest_sapp_v4 -f inline_mode.* +# - ./gtest_sapp_v4 -f fake_marsio.* +# - ./gtest_sapp_v4 -f hybrid.* +#using module v2.0 - ./gtest_sapp_v4 -f ipv4.* - ./gtest_sapp_v4 -f ipv6.* - ./gtest_sapp_v4 -f udp.* - - ./gtest_sapp_v4 -f tcpall.* - ./gtest_sapp_v4 -f tcp.* - - ./gtest_sapp_v4 -f control.* - - ./gtest_sapp_v4 -f project.* - - ./gtest_sapp_v4 -f stream_bridge.* - - ./gtest_sapp_v4 -f tunnel.* - ./gtest_sapp_v4 -f appstate.* - ./gtest_sapp_v4 -f timer.* - - ./gtest_sapp_v4 -f inject.* - - ./gtest_sapp_v4 -f plug_ctrl.* - - ./gtest_sapp_v4 -f jump_layer.* - - ./gtest_sapp_v4 -f inline_mode.* - - ./gtest_sapp_v4 -f asymmetric.* - ./gtest_sapp_v4 -f proxy.* - - ./gtest_sapp_v4 -f fake_marsio.* + - ./gtest_sapp_v4 -f asymmetric.* - ./gtest_sapp_v4 -f transparent.* - - ./gtest_sapp_v4 -f hybrid.* - ./gtest_sapp_v4 -f pkt_dump.* +#using module v3.0 - ./gtest_sapp_v4 -f benchmark_drop.* - ./gtest_sapp_v4 -f benchmark_forward.* - ./gtest_sapp_v4 -f benchmark_inject.tcp* diff --git a/src/dealpkt/deal_mpls.c b/src/dealpkt/deal_mpls.c index f830d23..1a6a93c 100644 --- a/src/dealpkt/deal_mpls.c +++ b/src/dealpkt/deal_mpls.c @@ -71,33 +71,38 @@ static int guess_mpls_with_control_word(const unsigned char *maybe_eth_hdr) int set_mpls_addr(struct layer_addr_mpls *addr, const unsigned char *raw_mpls_pkt_data) { - const struct mesa_mpls_hdr *this_mpls_hdr; + assert(raw_mpls_pkt_data != NULL); + const struct mesa_mpls_hdr *this_mpls_hdr = NULL; int i; - - memset(addr, 0, sizeof(struct layer_addr_mpls)); - for(i = 0; i < MAX_MPLS_ADDR_LAYER; i++) + + memset(addr, 0, sizeof(struct layer_addr_mpls)); + for (i = 0; i < MAX_MPLS_ADDR_LAYER; i++) { this_mpls_hdr = (const struct mesa_mpls_hdr *)raw_mpls_pkt_data; - //memcpy(&addr->src_mpls_pkt[i], raw_mpls_pkt_data, sizeof(struct mesa_mpls_hdr)); + // memcpy(&addr->src_mpls_pkt[i], raw_mpls_pkt_data, sizeof(struct mesa_mpls_hdr)); mpls_addr_net_to_mem(this_mpls_hdr, &addr->c2s_addr_array[i]); /* ����ջ��ĵ�ַ, ÿ���ݴ���c2s����, TCP/UDP���ٸ���������ת */ - + addr->c2s_layer_num += 1; - if(1 == this_mpls_hdr->mpls_bls){ + if (1 == this_mpls_hdr->mpls_bls) + { raw_mpls_pkt_data += sizeof(struct mesa_mpls_hdr); /* Ϊ�˺��淽���ж��Ƿ���ctrl word */ break; } raw_mpls_pkt_data += sizeof(struct mesa_mpls_hdr); } - if(1 != this_mpls_hdr->mpls_bls) /* ����MAX_MPLS_ADDR_LAYER, MPLS��û�н��� */ + assert(this_mpls_hdr != NULL); + if (1 != this_mpls_hdr->mpls_bls) /* ����MAX_MPLS_ADDR_LAYER, MPLS��û�н��� */ { sapp_runtime_log(RLOG_LV_FATAL, "MPLS layer number over load, only support %d\n", MAX_MPLS_ADDR_LAYER); return -1; } - if(((*raw_mpls_pkt_data & 0xF0) != 0x40) && ((*raw_mpls_pkt_data & 0xF0) != 0x60)){ //VPLS, MPLS with Control Word - if(guess_mpls_with_control_word(raw_mpls_pkt_data) > 0){ - memcpy(&addr->c2s_mpls_ctrl_word, raw_mpls_pkt_data, sizeof(int)); + if (((*raw_mpls_pkt_data & 0xF0) != 0x40) && ((*raw_mpls_pkt_data & 0xF0) != 0x60)) + { // VPLS, MPLS with Control Word + if (guess_mpls_with_control_word(raw_mpls_pkt_data) > 0) + { + memcpy(&addr->c2s_mpls_ctrl_word, raw_mpls_pkt_data, sizeof(int)); addr->c2s_has_ctrl_word = 1; } } @@ -105,215 +110,157 @@ int set_mpls_addr(struct layer_addr_mpls *addr, const unsigned char *raw_mpls_pk return 0; } -//MESA_htable_handle g_mpls_info_hash[MAX_THREAD_NUM]; - int mpls_uc_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) { -#if COMPAT_PAPP_FOR_BENCHMARK - return PASS; -#endif int ret = PASS; struct streamindex tmp_index; struct layer_addr_mpls addr; - struct streamindex *ptmp=&tmp_index; + struct streamindex *ptmp = &tmp_index; struct streaminfo_private *pstream_pr = &ptmp->stream; - struct streaminfo *pstream = &pstream_pr->stream_public; + struct streaminfo *pstream = &pstream_pr->stream_public; char *next_layer_hdr = NULL; int next_layer_offset = 0, i = 0; int inject_to_eth_flag = 0; sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_num]->sys_stat; - local_sys_stat->count_per_layer[ADDR_TYPE_MPLS][pfstream_pr->layer_index+1]++; - local_sys_stat->length_per_layer[ADDR_TYPE_MPLS][pfstream_pr->layer_index+1] += raw_pkt->raw_pkt_len - offset_to_raw_pkt_hdr; + local_sys_stat->count_per_layer[ADDR_TYPE_MPLS][pfstream_pr->layer_index + 1]++; + local_sys_stat->length_per_layer[ADDR_TYPE_MPLS][pfstream_pr->layer_index + 1] += raw_pkt->raw_pkt_len - offset_to_raw_pkt_hdr; - if(set_mpls_addr(&addr, (unsigned char *)this_layer_data) < 0){ + if (set_mpls_addr(&addr, (unsigned char *)this_layer_data) < 0) + { local_sys_stat->count[SAPP_STAT_RCV_UNKNOWN]++; - local_sys_stat->length[SAPP_STAT_RCV_UNKNOWN]+= raw_pkt->raw_pkt_len; + local_sys_stat->length[SAPP_STAT_RCV_UNKNOWN] += raw_pkt->raw_pkt_len; ((raw_pkt_t *)raw_pkt)->diagnose_error_to_dump = 1; return PASS; } - next_layer_offset = offset_to_raw_pkt_hdr + sizeof(struct mesa_mpls_hdr)*addr.c2s_layer_num; - next_layer_hdr = (char *)this_layer_data+ sizeof(struct mesa_mpls_hdr)*addr.c2s_layer_num; + next_layer_offset = offset_to_raw_pkt_hdr + sizeof(struct mesa_mpls_hdr) * addr.c2s_layer_num; + next_layer_hdr = (char *)this_layer_data + sizeof(struct mesa_mpls_hdr) * addr.c2s_layer_num; -#if 0 - this_mpls_hdr.mpls_label = (ntohl(*mpls_pkt_data) & MPLS_LABEL_MASK) >> 12; - this_mpls_hdr.mpls_exp = (ntohl(*mpls_pkt_data) & MPLS_EXP_MASK) >> 9; - this_mpls_hdr.mpls_bls = (ntohl(*mpls_pkt_data) & MPLS_BLS_MASK) >> 8; - this_mpls_hdr.mpls_ttl = (ntohl(*mpls_pkt_data) & MPLS_TTL_MASK); -#endif - - if(0 == G_SKIP_NOT_IP_LAYER){ - memset(ptmp,0,sizeof(struct streamindex)); - pstream->addr.paddr=&addr; + if (0 == G_SKIP_NOT_IP_LAYER) + { + memset(ptmp, 0, sizeof(struct streamindex)); + pstream->addr.paddr = &addr; pstream->addr.addrtype = ADDR_TYPE_MPLS; pstream->addr.addrlen = sizeof(struct layer_addr_mpls); - //pstream_pr->addr_skip_for_layer_cmp = 0;//Ϊ�˵�ַ�Ƚ�, �����Ŀ�MPLS��Ϊ1, �˴���ʵ��mpls��ַ, ��Ϊ0 - //pstream_pr->fake_layer_dir_for_asymmetric_cmp = 0; - //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; pstream_pr->offset_to_raw_pkt_hdr = offset_to_raw_pkt_hdr; pstream_pr->raw_pkt = raw_pkt; - - pstream->pfather=&pfstream_pr->stream_public; - pstream_pr->pfather_pr=pfstream_pr; - pstream->type=STREAM_TYPE_NON; - pstream->routedir=routedir; - pstream->threadnum=thread_num; + + pstream->pfather = &pfstream_pr->stream_public; + pstream_pr->pfather_pr = pfstream_pr; + pstream->type = STREAM_TYPE_NON; + pstream->routedir = routedir; + pstream->threadnum = thread_num; pstream_pr->layer_index = pfstream_pr->layer_index + 1; - if(g_asymmetric_addr_layer_set.layer_type_index[ADDR_TYPE_MPLS][pstream_pr->layer_index] != 0){ - pstream_pr->need_update_opposite_addr = 1;//�����ַ��һ������Ҫ���¶Բ���Ϣ - }else{ + if (g_asymmetric_addr_layer_set.layer_type_index[ADDR_TYPE_MPLS][pstream_pr->layer_index] != 0) + { + pstream_pr->need_update_opposite_addr = 1; //�����ַ��һ������Ҫ���¶Բ���Ϣ + } + else + { pstream_pr->need_update_opposite_addr = 0; - } - + } + pstream_pr->addr_use_as_hash = g_stream_compare_layer_set.layer_type_index[ADDR_TYPE_MPLS][pstream_pr->layer_index]; - }else{ + } + else + { pstream_pr = pfstream_pr; } ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; unsigned char guess_ip_version = (*next_layer_hdr & 0xF0) >> 4; - if(4 == guess_ip_version) - { - /* ֱ��ע��ipv4_entry(), ����´���Ҳûʲô����, checkipv4pkt()Ҳ�ܼ�����, - ������һ��mac��ַ��0x4x��ͷ, ��û������ע��ethernet���ٴ���һ����, ���ܶ�ʧijЩ����, - ����, �˴���ǰ���һЩ���� - */ - struct mesa_ip4_hdr *ip4_hdr = (struct mesa_ip4_hdr *)next_layer_hdr; - - if(ip4_hdr->ip_p >= 0x8F){ /* IPЭ���ֶδ���0x8f��Ŀǰ���Ϸ� */ + if (4 == guess_ip_version) + { + /* ֱ��ע��ipv4_entry(), ����´���Ҳûʲô����, checkipv4pkt()Ҳ�ܼ�����, + ������һ��mac��ַ��0x4x��ͷ, ��û������ע��ethernet���ٴ���һ����, ���ܶ�ʧijЩ����, + ����, �˴���ǰ���һЩ���� + */ + struct mesa_ip4_hdr *ip4_hdr = (struct mesa_ip4_hdr *)next_layer_hdr; + + if (ip4_hdr->ip_p >= 0x8F) + { /* IPЭ���ֶδ���0x8f��Ŀǰ���Ϸ� */ inject_to_eth_flag = 1; - } - - int left_pkt_len = raw_pkt->raw_pkt_len - next_layer_offset; - if(left_pkt_len < ntohs(ip4_hdr->ip_len)) + } + + int left_pkt_len = raw_pkt->raw_pkt_len - next_layer_offset; + if (left_pkt_len < ntohs(ip4_hdr->ip_len)) { local_sys_stat->count[SAPP_STAT_RCV_UNKNOWN]++; - local_sys_stat->length[SAPP_STAT_RCV_UNKNOWN]+= raw_pkt->raw_pkt_len; + local_sys_stat->length[SAPP_STAT_RCV_UNKNOWN] += raw_pkt->raw_pkt_len; ((raw_pkt_t *)raw_pkt)->diagnose_error_to_dump = 1; - sapp_runtime_log(20, "illegal left Ipv4 len %d, total len %d!\n", left_pkt_len, ntohs(ip4_hdr->ip_len)); + sapp_runtime_log(20, "illegal left Ipv4 len %d, total len %d!\n", left_pkt_len, ntohs(ip4_hdr->ip_len)); inject_to_eth_flag = 1; } - if(0 == inject_to_eth_flag){ - ret = ipv4_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset); - } - } - else if(6 == guess_ip_version) - { - /* ֱ��ע��ipv6_entry(), ����´���Ҳûʲô����, checkipv6pkt()Ҳ�ܼ�����, - ������һ��mac��ַ��0x6x��ͷ, ��û������ע��ethernet���ٴ���һ����, ���ܶ�ʧijЩ����, + if (0 == inject_to_eth_flag) + { + ret = ipv4_entry(pstream_pr, next_layer_hdr, thread_num, routedir, raw_pkt, next_layer_offset); + } + } + else if (6 == guess_ip_version) + { + /* ֱ��ע��ipv6_entry(), ����´���Ҳûʲô����, checkipv6pkt()Ҳ�ܼ�����, + ������һ��mac��ַ��0x6x��ͷ, ��û������ע��ethernet���ٴ���һ����, ���ܶ�ʧijЩ����, ����, �˴���ǰ���һЩ���� */ - struct mesa_ip6_hdr *ip6_hdr = (struct mesa_ip6_hdr *)next_layer_hdr; - if(ip6_hdr->ip6_nxt_hdr >= 0x8F){ /* IPЭ���ֶδ���0x8f��Ŀǰ���Ϸ� */ + struct mesa_ip6_hdr *ip6_hdr = (struct mesa_ip6_hdr *)next_layer_hdr; + if (ip6_hdr->ip6_nxt_hdr >= 0x8F) + { /* IPЭ���ֶδ���0x8f��Ŀǰ���Ϸ� */ inject_to_eth_flag = 1; } - - int left_pkt_len = raw_pkt->raw_pkt_len - next_layer_offset; - if(left_pkt_len < sizeof(struct mesa_ip6_hdr) + ntohs(ip6_hdr->ip6_payload_len)) + + int left_pkt_len = raw_pkt->raw_pkt_len - next_layer_offset; + if (left_pkt_len < sizeof(struct mesa_ip6_hdr) + ntohs(ip6_hdr->ip6_payload_len)) { local_sys_stat->count[SAPP_STAT_RCV_UNKNOWN]++; - local_sys_stat->length[SAPP_STAT_RCV_UNKNOWN]+= raw_pkt->raw_pkt_len; + local_sys_stat->length[SAPP_STAT_RCV_UNKNOWN] += raw_pkt->raw_pkt_len; ((raw_pkt_t *)raw_pkt)->diagnose_error_to_dump = 1; - sapp_runtime_log(20, "illegal left Ipv6 len %d, total len %d!\n", left_pkt_len, ntohs(ip6_hdr->ip6_payload_len)); + sapp_runtime_log(20, "illegal left Ipv6 len %d, total len %d!\n", left_pkt_len, ntohs(ip6_hdr->ip6_payload_len)); inject_to_eth_flag = 1; } - if(0 == inject_to_eth_flag){ - ret = ipv6_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset); - } - }else{ - inject_to_eth_flag = 1; - } - - if(inject_to_eth_flag != 0){ - if(addr.c2s_has_ctrl_word != 0){ - ret = eth_entry(pstream_pr,next_layer_hdr+4,thread_num,routedir,raw_pkt, next_layer_offset+4); - }else{ - int left_pkt_len = raw_pkt->raw_pkt_len - next_layer_offset; - if(left_pkt_len < sizeof(struct mesa_ethernet_hdr) + sizeof(struct mesa_ip4_hdr) + sizeof(struct mesa_udp_hdr)){ /* С����С�Ϸ�ethernet+ip+udp���ݰ����� */ - local_sys_stat->count[SAPP_STAT_RCV_UNKNOWN]++; - local_sys_stat->length[SAPP_STAT_RCV_UNKNOWN]+= raw_pkt->raw_pkt_len; - ((raw_pkt_t *)raw_pkt)->diagnose_error_to_dump = 1; - - sapp_runtime_log(20, "MPLS next layer type: 0x%x, but left len only:%d, pkt seq:%llu\n", *next_layer_hdr,left_pkt_len, local_sys_stat->count[SAPP_STAT_RCV_LINE]); - return PASS; - } - - ret = eth_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset); + if (0 == inject_to_eth_flag) + { + ret = ipv6_entry(pstream_pr, next_layer_hdr, thread_num, routedir, raw_pkt, next_layer_offset); } - } - - return ret; -} - -/* 2021-05-06 lijia close, �ǶԳ�mpls�ijɶ�̬����streaminfo�ķ�ʽ���. - �������: streaminfo_layer_alignment() -*/ -#if 0 -int mpls_empty_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) -{ - int ret = PASS; - struct streamindex tmp_index; - struct layer_addr_mpls addr; - struct streamindex *ptmp=&tmp_index; - struct streaminfo_private *pstream_pr = &ptmp->stream; - struct streaminfo *pstream = &pstream_pr->stream_public; - - char *next_layer_hdr = NULL; - int next_layer_offset = 0; - - memset(&addr, 0, sizeof(addr)); - - next_layer_offset = offset_to_raw_pkt_hdr; - next_layer_hdr = (char *)this_layer_data; - - - if(0 == G_SKIP_NOT_IP_LAYER){ - memset(ptmp,0,sizeof(struct streamindex)); - pstream->addr.paddr=&addr; - pstream->addr.addrtype = ADDR_TYPE_MPLS; - pstream->addr.addrlen = sizeof(struct layer_addr_mpls); - pstream_pr->addr_skip_for_layer_cmp = 1;//MPLS����һ���б�ǩ��һ��û�е�����������ղ�, �ñ�־λ���1 - //pstream_pr->fake_layer_dir_for_asymmetric_cmp = DIR_C2S; //todo, ����g_asymmetric_presence_layer_set�ж� - pstream_pr->need_update_opposite_addr = 1;//�����ַ��һ������Ҫ���¶Բ���Ϣ - pstream_pr->offset_to_raw_pkt_hdr = offset_to_raw_pkt_hdr; - pstream_pr->raw_pkt = raw_pkt; - pstream->pfather=&pfstream_pr->stream_public; - pstream_pr->pfather_pr=pfstream_pr; - pstream->type=STREAM_TYPE_NON; - pstream->routedir=routedir; - pstream->threadnum=thread_num; - pstream_pr->layer_index = pfstream_pr->layer_index + 1; - pstream_pr->addr_use_as_hash = g_stream_compare_layer_set.layer_type_index[ADDR_TYPE_MPLS][pstream_pr->layer_index]; - }else{ - pstream_pr = pfstream_pr; - } - - /* MPLSû���ֶα�ʾ���ص�Э������, ���MPLS���ص���IPv6Э�飬���� */ - ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; - if((*next_layer_hdr & 0xF0) == 0x40) - { - ret = ipv4_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset); } - else if((*next_layer_hdr & 0xF0) == 0x60) + else { - ret = ipv6_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset); + inject_to_eth_flag = 1; } - else + + if (inject_to_eth_flag != 0) { - sapp_runtime_log(20, "mpls_empty_entry MPLS next layer not IPv4 or IPv6, drop pkt !\n"); - return PASS; + if (addr.c2s_has_ctrl_word != 0) + { + ret = eth_entry(pstream_pr, next_layer_hdr + 4, thread_num, routedir, raw_pkt, next_layer_offset + 4); + } + else + { + int left_pkt_len = raw_pkt->raw_pkt_len - next_layer_offset; + if (left_pkt_len < sizeof(struct mesa_ethernet_hdr) + sizeof(struct mesa_ip4_hdr) + sizeof(struct mesa_udp_hdr)) + { /* С����С�Ϸ�ethernet+ip+udp���ݰ����� */ + local_sys_stat->count[SAPP_STAT_RCV_UNKNOWN]++; + local_sys_stat->length[SAPP_STAT_RCV_UNKNOWN] += raw_pkt->raw_pkt_len; + ((raw_pkt_t *)raw_pkt)->diagnose_error_to_dump = 1; + + sapp_runtime_log(20, "MPLS next layer type: 0x%x, but left len only:%d, pkt seq:%llu\n", *next_layer_hdr, left_pkt_len, local_sys_stat->count[SAPP_STAT_RCV_LINE]); + return PASS; + } + + ret = eth_entry(pstream_pr, next_layer_hdr, thread_num, routedir, raw_pkt, next_layer_offset); + } } return ret; } -#endif + +/* 2021-05-06 lijia close, �ǶԳ�mpls�ijɶ�̬����streaminfo�ķ�ʽ���. + �������: streaminfo_layer_alignment() +*/ #ifdef __cplusplus } |
