diff options
| author | yangwei <[email protected]> | 2019-07-31 19:21:21 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2019-07-31 19:21:21 +0800 |
| commit | 3f89bc26cd7efc3e30699fac0c0595fab483fd9d (patch) | |
| tree | ec4e8e05094c7d8ac81cc3e6c9f3acc7b0c541db | |
| parent | 0972a436cadf55c89eef9f6924b7216e9f9c1492 (diff) | |
1、更新iknow默认参数,修正为从[ShowStatInfo]读取,默认关闭,移除多处注册时的assert
2、调整sapp_init.c中初始化顺序,将sapp_assist_init函数提前至plug_ctrl函数前
3、增加threadnum读取出来小于0时的判断
4、fs2输出增加plug初始化时间的统计,以status形式输出,不发往SERVER
5、更新g_plugin_plugid为g_plugin_proto_plugid,用于记录全局protocol插件id
6、新增g_plugin_other_plugid,用于记录全局非protocol插件编号
a.对于protocol插件,pluginfo中的plugid即对应的g_plugin_proto_plugid
b.对于其他插件,pluginfo中的plugid=g_plugin_other_plugid+MAX_FUN_NUM(sapp定义的最大protocol插件个数)
| -rw-r--r-- | dealpkt/deal_ethernet.c | 496 | ||||
| -rw-r--r-- | dealpkt/deal_tcp.c | 8 | ||||
| -rw-r--r-- | dealpkt/deal_vlan.c | 450 | ||||
| -rw-r--r-- | dealpkt/stream_manage.c | 4 | ||||
| -rw-r--r-- | entry/sapp_init.c | 8 | ||||
| -rw-r--r-- | include/stream_internal.h | 5 | ||||
| -rw-r--r-- | inner_plug/sapp_assistant.cpp | 96 | ||||
| -rw-r--r-- | plugin/src/plugin.c | 35 | ||||
| -rw-r--r-- | plugin/src/plugin_protocol.c | 336 | ||||
| -rw-r--r-- | run/conf/main.conf | 14 |
10 files changed, 757 insertions, 695 deletions
diff --git a/dealpkt/deal_ethernet.c b/dealpkt/deal_ethernet.c index 9043c04..00004e8 100644 --- a/dealpkt/deal_ethernet.c +++ b/dealpkt/deal_ethernet.c @@ -1,248 +1,248 @@ -#ifdef __cplusplus
-extern "C" {
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <pthread.h>
-#include <netinet/ip.h>
-#include <netinet/ip6.h>
-#include <linux/if_ether.h>
-#include "stream_manage.h"
-#include "sendpacket.h"
-#include "deal_ipv6.h"
-#include "packet_io.h"
-#include "mesa_net.h"
-#include "sysinfo.h"
-#include "stream_internal.h"
-#include "packet_io_internal.h"
-
-#if DEBUG
-#include "iknow.h"
-extern packet_io_status_t *g_packet_io_status_pool[MAX_THREAD_NUM];
-extern int g_packet_io_thread_num;
-static inline void packet_io_eth_status_update(int thread_seq, int raw_pkt_len);
-#endif
-
-static const unsigned char G_BROADCAST_ADDR[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
-
-extern int g_topology_mode;
-extern int g_skip_ethernet_layer_sw;
-
-static inline void set_mac_addr(struct layer_addr_mac *addr, const struct mesa_ethernet_hdr *p_eth_hdr)
-{
- memcpy(&(addr->dst_mac[0]), &(p_eth_hdr->ether_dhost[0]), ETHER_ADDR_LEN);
- memcpy(&(addr->src_mac[0]), &(p_eth_hdr->ether_shost[0]), ETHER_ADDR_LEN);
-}
-
-
-int eth_entry(struct streaminfo_private *fstream_pr, const void *this_layer_hdr,int thread_num,
- unsigned char dir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr)
-{
- int ret;
- const unsigned char *next_layer_data = (const unsigned char *)this_layer_hdr + sizeof(struct mesa_ethernet_hdr);
- const struct mesa_ethernet_hdr *p_eth_hdr = (const struct mesa_ethernet_hdr *)this_layer_hdr;
- //unsigned short eth_type = ntohs(p_eth_hdr->ether_type);
- unsigned short eth_type = ntohs(p_eth_hdr->ether_type); /* ʹ��������ֱ���ж�, ����ÿ�ζ�����ntohs() */
- int next_layer_offset;
- struct streamindex tmp_index;
- struct streamindex *ptmp;
- struct streaminfo_private *pstream_pr;
- struct streaminfo *pstream;
-
- if(g_topology_mode & __NET_CONN_GDEV){
- if(memcmp(G_BROADCAST_ADDR, p_eth_hdr->ether_dhost, 6) == 0){
- /* G����ģʽ�£���ARPЭ��Ĺ㲥����ֱ�Ӷ���! ��ֹ�ٻ�ע��������, ��ɹ㲥�籩���������� */
- if(eth_type != ETH_P_ARP){
- return DROP;
- }
- }else{
- /* 2017-10-10 lijia add, �鲥MAC��ַ, ͨ��Ϊ�������ڿ��������ݰ�, ��LLMNR, SPT��Э��, һ�����账��, Ҳ����ת�� */
- if((p_eth_hdr->ether_dhost[0] & 0x01) == 0x01){
- return DROP;
- }
- }
- }
-
- if(unlikely(0 == g_skip_ethernet_layer_sw)){
- ptmp = &tmp_index;
- pstream_pr = &ptmp->stream;
- pstream = &pstream_pr->stream_public;
- next_layer_offset = offset_to_raw_pkt_hdr + sizeof(struct mesa_ethernet_hdr);
-
-#if DEBUG
- packet_io_eth_status_update(thread_num, raw_pkt->raw_pkt_len);
-#endif
- memset(ptmp, 0, sizeof(struct streamindex));
- //set_mac_addr(&addr, p_eth_hdr);
- pstream->addr.mac = (struct layer_addr_mac *)this_layer_hdr;
- pstream->addr.addrlen = sizeof(struct layer_addr_mac);
- pstream->addr.addrtype = ADDR_TYPE_MAC;
- pstream_pr->addr_use_as_hash = 0;
- //ptmp->stream.p_layer_header = this_layer_hdr;
- //ptmp->stream.offset_to_raw_pkt_hdr = (char *)this_layer_hdr - (char *)raw_pkt->raw_pkt_data;
- pstream_pr->offset_to_raw_pkt_hdr = offset_to_raw_pkt_hdr;
- pstream_pr->raw_pkt = raw_pkt; /* 2014-12-30 lijia add */
-
- pstream->pfather = (struct streaminfo *)fstream_pr;
- pstream->type = STREAM_TYPE_NON;
- pstream->routedir = dir;
- pstream->threadnum = thread_num;
- /* LiJia add, ��Ϊ����һ������, ��ΪԴ��ַ�����ΪClient�� */
- if(memcmp(p_eth_hdr->ether_shost, p_eth_hdr->ether_dhost, ETHER_ADDR_LEN) >= 0){
- pstream_pr->layer_dir = 1;
- pstream->curdir = DIR_C2S;
- }else{
- pstream_pr->layer_dir = 0;
- pstream->curdir = DIR_S2C;
- }
-
- g_SysInputInfo[thread_num][PKT_ETHERNET]++;
- g_SysInputInfo[thread_num][PKT_ETHERNET_LEN] += (unsigned long long)raw_pkt->raw_pkt_len;
- }else{
- pstream_pr = NULL; /* ʹ�ϲ����Э���pfatherΪNULL */
- next_layer_offset = 0;
- if((int)CAP_LEVEL_MAC == (int)raw_pkt->low_layer_type){
- ((raw_pkt_t *)raw_pkt)->raw_pkt_data = (char *)raw_pkt->__lib_raw_pkt_data + sizeof(struct mesa_ethernet_hdr);
- ((raw_pkt_t *)raw_pkt)->raw_pkt_len = raw_pkt->__lib_raw_pkt_len - sizeof(struct mesa_ethernet_hdr);
- }
- }
- if(sapp_global_single.create_mpls_anyway != 0)
- {
- if(eth_type == ETHERTYPE_IP || eth_type == ETHERTYPE_IPv6)
- {
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = mpls_empty_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- }
- }
- else
- {
- switch(eth_type){
- case ETHERTYPE_IP:
- if(g_skip_ethernet_layer_sw){
- ((raw_pkt_t *)raw_pkt)->low_layer_type = (enum addr_type_t)CAP_LEVEL_IPV4;
- }
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = ipv4_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- break;
-
- case ETHERTYPE_IPv6:
- if(g_skip_ethernet_layer_sw){
- ((raw_pkt_t *)raw_pkt)->low_layer_type = (enum addr_type_t)CAP_LEVEL_IPV6;
- }
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = ipv6_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- break;
-
- case ETHERTYPE_VLAN:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- if(sapp_global_single.treat_vlan_as_mac_in_mac_sw){
- ret = mac_in_mac_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);
- }
- break;
-
- case ETH_P_PPP_SES:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = pppoe_session_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- break;
-
- case ETH_P_MPLS_UC: /* 2014-12-08 add */
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = mpls_uc_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- break;
-
- case ETH_P_ARP:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- 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 ETH_P_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);
- break;
-
- default:
- /* unknown protocol */
- g_SysInputInfo[thread_num][PKT_UNKNOWN]++;
- g_SysInputInfo[thread_num][PKT_UNKNOWN_LEN] += raw_pkt->raw_pkt_len;
- if(NET_CONN_SERIAL_GDEV == g_topology_mode){
- /* GDEV����ģʽ��, ʲôʱ��Ӧ�ðѲ���ʶ�İ��ٻ�ע, ���߷��ְ�SPT������Э����ע��ȥ, ����������� */
- ret = DROP;
- }else{
- ret = PASS;
- }
- break;
- }
- }
-
- return ret;
-}
-
-#if DEBUG
-static packet_io_status_base_t g_io_eth_last_status, g_io_eth_cur_status, g_io_eth_realtime_status;
-long ifuncb_show_eth_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg, const char *cmd_args)
-{
- iprintf(ihandle, iconn,"NOTE: unit of byte for total is 'byte', for realtime is 'bps, bit per second'!\n");
- iprintf(ihandle, iconn, "%8s %8s %12s\n", " ", "packet", "byte");
- iprintf(ihandle, iconn, "%8s %8llu %12llu\n%8s %8llu %12llu\n",
- "total", g_io_eth_cur_status.pkt_num, g_io_eth_cur_status.pkt_byte,
- "realtime", g_io_eth_realtime_status.pkt_num, g_io_eth_realtime_status.pkt_byte*8);
-
- return 0;
-}
-
-void *packet_io_status_eth_mem_init(void)
-{
- void *eth_mem;
-
- eth_mem = malloc(sizeof(packet_io_status_base_t));
- memset(eth_mem, 0, sizeof(packet_io_status_base_t));
-
- return eth_mem;
-}
-
-void iknow_register_eth_cb(void *ihandle)
-{
- int ret;
-
- ret = iknow_register_cmd(ihandle, "show eth summary", "display eth flow summary", ifuncb_show_eth_summary, NULL, 0, NULL);
- assert(0 == ret);
-}
-
-static inline void packet_io_eth_status_update(int thread_seq, int raw_pkt_len)
-{
- packet_io_status_base_t *p_eth_status;
-
- p_eth_status = (packet_io_status_base_t *)(g_packet_io_status_pool[thread_seq]->packet_io_status[IO_STATUS_ETH]);
-
- p_eth_status->pkt_num++;
- p_eth_status->pkt_byte += raw_pkt_len;
-}
-
-void packet_io_status_eth_time_cb(void)
-{
- /* ȫ���ܰ���, ���ֽ���, ƽ������, ��ǰʵʱ���� */
- int i;
- packet_io_status_base_t *p_eth_status;
-
- memcpy((void *)&g_io_eth_last_status, (void *)&g_io_eth_cur_status, sizeof(packet_io_status_base_t)); /* ������һ���ֵ */
- memset((void *)&g_io_eth_cur_status, 0, sizeof(packet_io_status_base_t)); /* ���� */
-
- for(i = 0; i < g_packet_io_thread_num; i++){
- p_eth_status = (packet_io_status_base_t *)(g_packet_io_status_pool[i]->packet_io_status[IO_STATUS_ETH]);
- g_io_eth_cur_status.pkt_num += p_eth_status->pkt_num;
- g_io_eth_cur_status.pkt_byte += p_eth_status->pkt_byte;
- }
-
- g_io_eth_realtime_status.pkt_num = g_io_eth_cur_status.pkt_num - g_io_eth_last_status.pkt_num;
- g_io_eth_realtime_status.pkt_byte = g_io_eth_cur_status.pkt_byte - g_io_eth_last_status.pkt_byte;
-}
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
+#ifdef __cplusplus +extern "C" { +#endif +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <pthread.h> +#include <netinet/ip.h> +#include <netinet/ip6.h> +#include <linux/if_ether.h> +#include "stream_manage.h" +#include "sendpacket.h" +#include "deal_ipv6.h" +#include "packet_io.h" +#include "mesa_net.h" +#include "sysinfo.h" +#include "stream_internal.h" +#include "packet_io_internal.h" + +#if DEBUG +#include "iknow.h" +extern packet_io_status_t *g_packet_io_status_pool[MAX_THREAD_NUM]; +extern int g_packet_io_thread_num; +static inline void packet_io_eth_status_update(int thread_seq, int raw_pkt_len); +#endif + +static const unsigned char G_BROADCAST_ADDR[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + +extern int g_topology_mode; +extern int g_skip_ethernet_layer_sw; + +static inline void set_mac_addr(struct layer_addr_mac *addr, const struct mesa_ethernet_hdr *p_eth_hdr) +{ + memcpy(&(addr->dst_mac[0]), &(p_eth_hdr->ether_dhost[0]), ETHER_ADDR_LEN); + memcpy(&(addr->src_mac[0]), &(p_eth_hdr->ether_shost[0]), ETHER_ADDR_LEN); +} + + +int eth_entry(struct streaminfo_private *fstream_pr, const void *this_layer_hdr,int thread_num, + unsigned char dir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr) +{ + int ret; + const unsigned char *next_layer_data = (const unsigned char *)this_layer_hdr + sizeof(struct mesa_ethernet_hdr); + const struct mesa_ethernet_hdr *p_eth_hdr = (const struct mesa_ethernet_hdr *)this_layer_hdr; + //unsigned short eth_type = ntohs(p_eth_hdr->ether_type); + unsigned short eth_type = ntohs(p_eth_hdr->ether_type); /* ʹ��������ֱ���ж�, ����ÿ�ζ�����ntohs() */ + int next_layer_offset; + struct streamindex tmp_index; + struct streamindex *ptmp; + struct streaminfo_private *pstream_pr; + struct streaminfo *pstream; + + if(g_topology_mode & __NET_CONN_GDEV){ + if(memcmp(G_BROADCAST_ADDR, p_eth_hdr->ether_dhost, 6) == 0){ + /* G����ģʽ�£���ARPЭ��Ĺ㲥����ֱ�Ӷ���! ��ֹ�ٻ�ע��������, ��ɹ㲥�籩���������� */ + if(eth_type != ETH_P_ARP){ + return DROP; + } + }else{ + /* 2017-10-10 lijia add, �鲥MAC��ַ, ͨ��Ϊ�������ڿ��������ݰ�, ��LLMNR, SPT��Э��, һ�����账��, Ҳ����ת�� */ + if((p_eth_hdr->ether_dhost[0] & 0x01) == 0x01){ + return DROP; + } + } + } + + if(unlikely(0 == g_skip_ethernet_layer_sw)){ + ptmp = &tmp_index; + pstream_pr = &ptmp->stream; + pstream = &pstream_pr->stream_public; + next_layer_offset = offset_to_raw_pkt_hdr + sizeof(struct mesa_ethernet_hdr); + +#if DEBUG + packet_io_eth_status_update(thread_num, raw_pkt->raw_pkt_len); +#endif + memset(ptmp, 0, sizeof(struct streamindex)); + //set_mac_addr(&addr, p_eth_hdr); + pstream->addr.mac = (struct layer_addr_mac *)this_layer_hdr; + pstream->addr.addrlen = sizeof(struct layer_addr_mac); + pstream->addr.addrtype = ADDR_TYPE_MAC; + pstream_pr->addr_use_as_hash = 0; + //ptmp->stream.p_layer_header = this_layer_hdr; + //ptmp->stream.offset_to_raw_pkt_hdr = (char *)this_layer_hdr - (char *)raw_pkt->raw_pkt_data; + pstream_pr->offset_to_raw_pkt_hdr = offset_to_raw_pkt_hdr; + pstream_pr->raw_pkt = raw_pkt; /* 2014-12-30 lijia add */ + + pstream->pfather = (struct streaminfo *)fstream_pr; + pstream->type = STREAM_TYPE_NON; + pstream->routedir = dir; + pstream->threadnum = thread_num; + /* LiJia add, ��Ϊ����һ������, ��ΪԴ��ַ�����ΪClient�� */ + if(memcmp(p_eth_hdr->ether_shost, p_eth_hdr->ether_dhost, ETHER_ADDR_LEN) >= 0){ + pstream_pr->layer_dir = 1; + pstream->curdir = DIR_C2S; + }else{ + pstream_pr->layer_dir = 0; + pstream->curdir = DIR_S2C; + } + + g_SysInputInfo[thread_num][PKT_ETHERNET]++; + g_SysInputInfo[thread_num][PKT_ETHERNET_LEN] += (unsigned long long)raw_pkt->raw_pkt_len; + }else{ + pstream_pr = NULL; /* ʹ�ϲ����Э���pfatherΪNULL */ + next_layer_offset = 0; + if((int)CAP_LEVEL_MAC == (int)raw_pkt->low_layer_type){ + ((raw_pkt_t *)raw_pkt)->raw_pkt_data = (char *)raw_pkt->__lib_raw_pkt_data + sizeof(struct mesa_ethernet_hdr); + ((raw_pkt_t *)raw_pkt)->raw_pkt_len = raw_pkt->__lib_raw_pkt_len - sizeof(struct mesa_ethernet_hdr); + } + } + if(sapp_global_single.create_mpls_anyway != 0) + { + if(eth_type == ETHERTYPE_IP || eth_type == ETHERTYPE_IPv6) + { + ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; + ret = mpls_empty_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset); + } + } + else + { + switch(eth_type){ + case ETHERTYPE_IP: + if(g_skip_ethernet_layer_sw){ + ((raw_pkt_t *)raw_pkt)->low_layer_type = (enum addr_type_t)CAP_LEVEL_IPV4; + } + ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; + ret = ipv4_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset); + break; + + case ETHERTYPE_IPv6: + if(g_skip_ethernet_layer_sw){ + ((raw_pkt_t *)raw_pkt)->low_layer_type = (enum addr_type_t)CAP_LEVEL_IPV6; + } + ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; + ret = ipv6_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset); + break; + + case ETHERTYPE_VLAN: + ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; + if(sapp_global_single.treat_vlan_as_mac_in_mac_sw){ + ret = mac_in_mac_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); + } + break; + + case ETH_P_PPP_SES: + ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; + ret = pppoe_session_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset); + break; + + case ETH_P_MPLS_UC: /* 2014-12-08 add */ + ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; + ret = mpls_uc_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset); + break; + + case ETH_P_ARP: + ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; + 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 ETH_P_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); + break; + + default: + /* unknown protocol */ + g_SysInputInfo[thread_num][PKT_UNKNOWN]++; + g_SysInputInfo[thread_num][PKT_UNKNOWN_LEN] += raw_pkt->raw_pkt_len; + if(NET_CONN_SERIAL_GDEV == g_topology_mode){ + /* GDEV����ģʽ��, ʲôʱ��Ӧ�ðѲ���ʶ�İ��ٻ�ע, ���߷��ְ�SPT������Э����ע��ȥ, ����������� */ + ret = DROP; + }else{ + ret = PASS; + } + break; + } + } + + return ret; +} + +#if DEBUG +static packet_io_status_base_t g_io_eth_last_status, g_io_eth_cur_status, g_io_eth_realtime_status; +long ifuncb_show_eth_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg, const char *cmd_args) +{ + iprintf(ihandle, iconn,"NOTE: unit of byte for total is 'byte', for realtime is 'bps, bit per second'!\n"); + iprintf(ihandle, iconn, "%8s %8s %12s\n", " ", "packet", "byte"); + iprintf(ihandle, iconn, "%8s %8llu %12llu\n%8s %8llu %12llu\n", + "total", g_io_eth_cur_status.pkt_num, g_io_eth_cur_status.pkt_byte, + "realtime", g_io_eth_realtime_status.pkt_num, g_io_eth_realtime_status.pkt_byte*8); + + return 0; +} + +void *packet_io_status_eth_mem_init(void) +{ + void *eth_mem; + + eth_mem = malloc(sizeof(packet_io_status_base_t)); + memset(eth_mem, 0, sizeof(packet_io_status_base_t)); + + return eth_mem; +} + +void iknow_register_eth_cb(void *ihandle) +{ + int ret; + + ret = iknow_register_cmd(ihandle, "show eth summary", "display eth flow summary", ifuncb_show_eth_summary, NULL, 0, NULL); + //assert(0 == ret); +} + +static inline void packet_io_eth_status_update(int thread_seq, int raw_pkt_len) +{ + packet_io_status_base_t *p_eth_status; + + p_eth_status = (packet_io_status_base_t *)(g_packet_io_status_pool[thread_seq]->packet_io_status[IO_STATUS_ETH]); + + p_eth_status->pkt_num++; + p_eth_status->pkt_byte += raw_pkt_len; +} + +void packet_io_status_eth_time_cb(void) +{ + /* ȫ���ܰ���, ���ֽ���, ƽ������, ��ǰʵʱ���� */ + int i; + packet_io_status_base_t *p_eth_status; + + memcpy((void *)&g_io_eth_last_status, (void *)&g_io_eth_cur_status, sizeof(packet_io_status_base_t)); /* ������һ���ֵ */ + memset((void *)&g_io_eth_cur_status, 0, sizeof(packet_io_status_base_t)); /* ���� */ + + for(i = 0; i < g_packet_io_thread_num; i++){ + p_eth_status = (packet_io_status_base_t *)(g_packet_io_status_pool[i]->packet_io_status[IO_STATUS_ETH]); + g_io_eth_cur_status.pkt_num += p_eth_status->pkt_num; + g_io_eth_cur_status.pkt_byte += p_eth_status->pkt_byte; + } + + g_io_eth_realtime_status.pkt_num = g_io_eth_cur_status.pkt_num - g_io_eth_last_status.pkt_num; + g_io_eth_realtime_status.pkt_byte = g_io_eth_cur_status.pkt_byte - g_io_eth_last_status.pkt_byte; +} +#endif + +#ifdef __cplusplus +} +#endif + diff --git a/dealpkt/deal_tcp.c b/dealpkt/deal_tcp.c index f0eec88..c4a8c8a 100644 --- a/dealpkt/deal_tcp.c +++ b/dealpkt/deal_tcp.c @@ -3421,11 +3421,11 @@ void iknow_register_tcp_pkt_cb(void *ihandle) int ret; ret = iknow_register_cmd(ihandle, "show tcp pkt summary", "display tcp pkt summary", ifuncb_show_tcp_pkt_summary, NULL, 0, NULL); - assert(0 == ret); + //assert(0 == ret); ret = iknow_register_cmd(ihandle, "show tcp pkt detail total", "display tcp pkt detail total", ifuncb_show_tcp_pkt_detail_total, NULL, 0, NULL); - assert(0 == ret); + //assert(0 == ret); ret = iknow_register_cmd(ihandle, "show tcp pkt detail realtime", "display tcp pkt detail realtime", ifuncb_show_tcp_pkt_detail_realtime, NULL, 0, NULL); - assert(0 == ret); + //assert(0 == ret); } void *packet_io_status_tcp_stream_mem_init(void) @@ -3508,7 +3508,7 @@ void iknow_register_tcp_stream_cb(void *ihandle) int ret; ret = iknow_register_cmd(ihandle, "show tcp stream summary", "display tcp stream summary", ifuncb_show_tcp_stream_summary, NULL, 0, NULL); - assert(0 == ret); + //assert(0 == ret); //ret = iknow_register_cmd(ihandle, "show tcp stream detail total", "display tcp stream detail total", ifuncb_show_tcp_stream_detail, NULL, 0, NULL); //assert(0 == ret); //ret = iknow_register_cmd(ihandle, "show tcp stream detail realtime", "display tcp stream detail realtime", ifuncb_show_tcp_stream_detail, NULL, 0, NULL); diff --git a/dealpkt/deal_vlan.c b/dealpkt/deal_vlan.c index b749567..472c4b7 100644 --- a/dealpkt/deal_vlan.c +++ b/dealpkt/deal_vlan.c @@ -1,225 +1,225 @@ -#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "stream_internal.h"
-#include "sendpacket.h"
-#include "stream_manage.h"
-#include "packet_io.h"
-#include "packet_io_internal.h"
-#include <linux/if_ether.h>
-
-#define VLAN_ID_MAX (4096) /* vlan id is 12bit, max is 4096 */
-
-#if DEBUG
-static inline void packet_io_vlan_status_update(int thread_seq, const struct layer_addr_vlan *addr, int raw_pkt_len);
-#endif
-
-static inline void set_vlanid(struct layer_addr_vlan *addr, unsigned short *vlan_tag)
-{
- addr->vlan_id = ntohs(*vlan_tag) & VLAN_ID_MASK;
- return;
-}
-
-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)
-{
- int ret = PASS;
- struct streamindex tmp_index;
- struct streamindex *ptmp=&tmp_index;
- struct streaminfo_private *pstream_pr = &ptmp->stream;
- struct streaminfo *pstream = &pstream_pr->stream_public;
- struct layer_addr_vlan addr;
- u_short ether_type;
- char *next_layer_hdr = (char *)this_layer_data+ VLAN_TAG_LEN;
- int next_layer_offset = offset_to_raw_pkt_hdr + VLAN_TAG_LEN;
-
- if(unlikely(0 == G_SKIP_NOT_IP_LAYER)){
- memset(ptmp,0,sizeof(struct streamindex));
- set_vlanid(&addr, (unsigned short *)this_layer_data);
-#if DEBUG
- packet_io_vlan_status_update(thread_num, &addr, raw_pkt->raw_pkt_len);
-#endif
- pstream->addr.paddr=&addr;
- pstream->addr.addrtype = ADDR_TYPE_VLAN;
- pstream->addr.addrlen = sizeof(struct layer_addr_vlan);
- pstream_pr->addr_use_as_hash = 1;
- //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; /* 2014-12-30 lijia add */
-
- pstream->pfather=&pfstream_pr->stream_public;
- pstream->type=STREAM_TYPE_NON;
- pstream->routedir=routedir;
- pstream->threadnum=thread_num;
- }else{
- pstream_pr = pfstream_pr; /* 2015-07-03 lijia add, skip this layer */
- }
-
- ether_type=*((unsigned short *)((char *)this_layer_data + 2));
- ether_type = ntohs(ether_type);
-
- switch(ether_type)
- {
- case ETH_P_IP:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret=ipv4_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset);
- break;
- case ETH_P_IPV6:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret=ipv6_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset);
- 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);
- break;
-
- case ETH_P_PPP_SES:
-#if COMPAT_PAPP_FOR_BENCHMARK
- return PASS;
-#endif
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret=pppoe_session_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset);
- break;
-
- case ETH_P_MPLS_UC:
- case ETH_P_MPLS_MC:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = mpls_uc_entry(pstream_pr, (const void *)next_layer_hdr, thread_num, routedir, raw_pkt, next_layer_offset);
- break;
-
- default:
- /* unknown protocol */
- g_SysInputInfo[thread_num][PKT_UNKNOWN]++;
- g_SysInputInfo[thread_num][PKT_UNKNOWN_LEN] += raw_pkt->raw_pkt_len;
-
- sapp_runtime_log(20, "VLAN unknown protocol: 0x%x\n", ether_type);
-
- if(NET_CONN_SERIAL_GDEV == g_topology_mode){
- /* GDEVģʽ��, ʲôʱ��Ӧ�ðѲ���ʶ�İ���ת����ȥ, ���߷��ְ�SPT������Э����ע��ȥ, ����������� */
- ret = DROP;
- }else{
- ret = PASS;
- }
- break;
- }
-
- return ret;
-}
-
-#if DEBUG
-#include "iknow.h"
-
-extern int g_packet_io_thread_num;
-extern packet_io_status_t *g_packet_io_status_pool[MAX_THREAD_NUM];
-
-/*
- sysinfo֮ǰ�Ǽ�ά����, ���ܱ�ʾ���̡߳���Э�顢��Э��ľ������.
-
- �µļܹ���, ÿ��Э�������ṹ, ��packet_io_status_base_t��������չ,
- ��֮ǰ��sysinfo�ļ�ά���鲻ͬ,
- �½ṹÿ��Э��洢�����Ͳ�ͬ, �ṹҲ��ͬ,
- ������, �ڴ�ʹ�����Ż�.
-*/
-typedef struct{
- packet_io_status_base_t io_base_status; /* VLAN���ܼ��� */
- unsigned long long vlan_pkt_num[VLAN_ID_MAX]; /* ÿ��VLAN�İ��� */
- unsigned long long vlan_pkt_byte[VLAN_ID_MAX]; /* ÿ��VLAN���ֽ��� */
-}packet_io_status_vlan_t;
-
-/* ����: ��һ��:1000B, ��ǰ:5000B, �ɼ�������һ���ʵʱ����:4000B/s */
-static volatile packet_io_status_vlan_t g_io_vlan_last_status, g_io_vlan_cur_status, g_io_vlan_realtime_status;
-
-static long ifuncb_show_vlan_id_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg,const char *cmd_args)
-{
- int i;
- /* ȫ��vlan-id�ܰ���, ���ֽ��� */
- iprintf(ihandle, iconn, "vlan id summary:\n %7s %9s %10s\n", "VLAN-ID", "Total-pkt", "Total-byte");
- for(i = 0; i < VLAN_ID_MAX; i++){
- if(g_io_vlan_cur_status.vlan_pkt_num[i] > 0){
- iprintf(ihandle, iconn, "%7d %9llu %10llu\n", i, g_io_vlan_cur_status.vlan_pkt_num[i], g_io_vlan_cur_status.vlan_pkt_byte[i] );
- }
- }
-
- return 0;
-}
-
-static long ifuncb_show_vlan_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg, const char *cmd_args)
-{
- /* ȫ���ܰ���, ���ֽ��� */
- iprintf(ihandle, iconn,"NOTE: unit of byte for total is 'byte', for realtime is 'bps, bit per second'!\n");
- iprintf(ihandle, iconn, "%8s %8s %12s\n", " ", "packet", "byte");
- iprintf(ihandle, iconn, "%8s %8llu %12llu\n%8s %8llu %12llu\n",
- "total", g_io_vlan_cur_status.io_base_status.pkt_num, g_io_vlan_cur_status.io_base_status.pkt_byte,
- "realtime", g_io_vlan_realtime_status.io_base_status.pkt_num, g_io_vlan_realtime_status.io_base_status.pkt_byte*8);
-
- return 0;
-}
-
-void iknow_register_vlan_cb(void *ihandle)
-{
- int ret;
-
- ret = iknow_register_cmd(ihandle, "show vlan summary", "display vlan flow summary", ifuncb_show_vlan_summary, NULL, 0, NULL);
- assert(0 == ret);
-
- ret = iknow_register_cmd(ihandle, "show vlan id summary", "display vlan flow summary by id", ifuncb_show_vlan_id_summary, NULL, 0, NULL);
- assert(0 == ret);
-}
-
-void packet_io_status_vlan_time_cb(void)
-{
- int i, j;
- packet_io_status_vlan_t *global_vlan_status;
-
- memcpy((void *)&g_io_vlan_last_status, (void *)&g_io_vlan_cur_status, sizeof(packet_io_status_vlan_t)); /* ������һ���ֵ */
- memset((void *)&g_io_vlan_cur_status, 0, sizeof(packet_io_status_vlan_t)); /* ���� */
-
- for(i = 0; i < g_packet_io_thread_num; i++){
- global_vlan_status = (packet_io_status_vlan_t *)(g_packet_io_status_pool[i]->packet_io_status[IO_STATUS_VLAN]);
- g_io_vlan_cur_status.io_base_status.pkt_num += global_vlan_status->io_base_status.pkt_num;
- g_io_vlan_cur_status.io_base_status.pkt_byte += global_vlan_status->io_base_status.pkt_byte;
- for(j = 0; j < VLAN_ID_MAX; j++){
- g_io_vlan_cur_status.vlan_pkt_num[j] += global_vlan_status->vlan_pkt_num[j];
- g_io_vlan_cur_status.vlan_pkt_byte[j] += global_vlan_status->vlan_pkt_byte[j];
- }
- }
-
- g_io_vlan_realtime_status.io_base_status.pkt_num = g_io_vlan_cur_status.io_base_status.pkt_num - g_io_vlan_last_status.io_base_status.pkt_num;
- g_io_vlan_realtime_status.io_base_status.pkt_byte = g_io_vlan_cur_status.io_base_status.pkt_byte - g_io_vlan_last_status.io_base_status.pkt_byte;
-}
-
-void *packet_io_status_vlan_mem_init(void)
-{
- void *vlan_mem;
-
- vlan_mem = malloc(sizeof(packet_io_status_vlan_t));
- memset(vlan_mem, 0, sizeof(packet_io_status_vlan_t));
-
- return vlan_mem;
-}
-
-static inline void packet_io_vlan_status_update(int thread_seq, const struct layer_addr_vlan *addr, int raw_pkt_len)
-{
- packet_io_status_vlan_t *io_vlan_status = (packet_io_status_vlan_t *)(g_packet_io_status_pool[thread_seq]->packet_io_status[IO_STATUS_VLAN]);
-
- io_vlan_status->io_base_status.pkt_num++;
- io_vlan_status->io_base_status.pkt_byte += raw_pkt_len;
-
- io_vlan_status->vlan_pkt_num[addr->vlan_id]++;
- io_vlan_status->vlan_pkt_byte[addr->vlan_id] += raw_pkt_len;
-}
-#else
-int packet_io_status_vlan_init(void)
-{
- return 0;
-}
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
+#ifdef __cplusplus +extern "C" { +#endif + +#include "stream_internal.h" +#include "sendpacket.h" +#include "stream_manage.h" +#include "packet_io.h" +#include "packet_io_internal.h" +#include <linux/if_ether.h> + +#define VLAN_ID_MAX (4096) /* vlan id is 12bit, max is 4096 */ + +#if DEBUG +static inline void packet_io_vlan_status_update(int thread_seq, const struct layer_addr_vlan *addr, int raw_pkt_len); +#endif + +static inline void set_vlanid(struct layer_addr_vlan *addr, unsigned short *vlan_tag) +{ + addr->vlan_id = ntohs(*vlan_tag) & VLAN_ID_MASK; + return; +} + +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) +{ + int ret = PASS; + struct streamindex tmp_index; + struct streamindex *ptmp=&tmp_index; + struct streaminfo_private *pstream_pr = &ptmp->stream; + struct streaminfo *pstream = &pstream_pr->stream_public; + struct layer_addr_vlan addr; + u_short ether_type; + char *next_layer_hdr = (char *)this_layer_data+ VLAN_TAG_LEN; + int next_layer_offset = offset_to_raw_pkt_hdr + VLAN_TAG_LEN; + + if(unlikely(0 == G_SKIP_NOT_IP_LAYER)){ + memset(ptmp,0,sizeof(struct streamindex)); + set_vlanid(&addr, (unsigned short *)this_layer_data); +#if DEBUG + packet_io_vlan_status_update(thread_num, &addr, raw_pkt->raw_pkt_len); +#endif + pstream->addr.paddr=&addr; + pstream->addr.addrtype = ADDR_TYPE_VLAN; + pstream->addr.addrlen = sizeof(struct layer_addr_vlan); + pstream_pr->addr_use_as_hash = 1; + //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; /* 2014-12-30 lijia add */ + + pstream->pfather=&pfstream_pr->stream_public; + pstream->type=STREAM_TYPE_NON; + pstream->routedir=routedir; + pstream->threadnum=thread_num; + }else{ + pstream_pr = pfstream_pr; /* 2015-07-03 lijia add, skip this layer */ + } + + ether_type=*((unsigned short *)((char *)this_layer_data + 2)); + ether_type = ntohs(ether_type); + + switch(ether_type) + { + case ETH_P_IP: + ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; + ret=ipv4_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset); + break; + case ETH_P_IPV6: + ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; + ret=ipv6_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset); + 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); + break; + + case ETH_P_PPP_SES: +#if COMPAT_PAPP_FOR_BENCHMARK + return PASS; +#endif + ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; + ret=pppoe_session_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset); + break; + + case ETH_P_MPLS_UC: + case ETH_P_MPLS_MC: + ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset; + ret = mpls_uc_entry(pstream_pr, (const void *)next_layer_hdr, thread_num, routedir, raw_pkt, next_layer_offset); + break; + + default: + /* unknown protocol */ + g_SysInputInfo[thread_num][PKT_UNKNOWN]++; + g_SysInputInfo[thread_num][PKT_UNKNOWN_LEN] += raw_pkt->raw_pkt_len; + + sapp_runtime_log(20, "VLAN unknown protocol: 0x%x\n", ether_type); + + if(NET_CONN_SERIAL_GDEV == g_topology_mode){ + /* GDEVģʽ��, ʲôʱ��Ӧ�ðѲ���ʶ�İ���ת����ȥ, ���߷��ְ�SPT������Э����ע��ȥ, ����������� */ + ret = DROP; + }else{ + ret = PASS; + } + break; + } + + return ret; +} + +#if DEBUG +#include "iknow.h" + +extern int g_packet_io_thread_num; +extern packet_io_status_t *g_packet_io_status_pool[MAX_THREAD_NUM]; + +/* + sysinfo֮ǰ�Ǽ�ά����, ���ܱ�ʾ���̡߳���Э�顢��Э��ľ������. + + �µļܹ���, ÿ��Э�������ṹ, ��packet_io_status_base_t��������չ, + ��֮ǰ��sysinfo�ļ�ά���鲻ͬ, + �½ṹÿ��Э��洢�����Ͳ�ͬ, �ṹҲ��ͬ, + ������, �ڴ�ʹ�����Ż�. +*/ +typedef struct{ + packet_io_status_base_t io_base_status; /* VLAN���ܼ��� */ + unsigned long long vlan_pkt_num[VLAN_ID_MAX]; /* ÿ��VLAN�İ��� */ + unsigned long long vlan_pkt_byte[VLAN_ID_MAX]; /* ÿ��VLAN���ֽ��� */ +}packet_io_status_vlan_t; + +/* ����: ��һ��:1000B, ��ǰ:5000B, �ɼ�������һ���ʵʱ����:4000B/s */ +static volatile packet_io_status_vlan_t g_io_vlan_last_status, g_io_vlan_cur_status, g_io_vlan_realtime_status; + +static long ifuncb_show_vlan_id_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg,const char *cmd_args) +{ + int i; + /* ȫ��vlan-id�ܰ���, ���ֽ��� */ + iprintf(ihandle, iconn, "vlan id summary:\n %7s %9s %10s\n", "VLAN-ID", "Total-pkt", "Total-byte"); + for(i = 0; i < VLAN_ID_MAX; i++){ + if(g_io_vlan_cur_status.vlan_pkt_num[i] > 0){ + iprintf(ihandle, iconn, "%7d %9llu %10llu\n", i, g_io_vlan_cur_status.vlan_pkt_num[i], g_io_vlan_cur_status.vlan_pkt_byte[i] ); + } + } + + return 0; +} + +static long ifuncb_show_vlan_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg, const char *cmd_args) +{ + /* ȫ���ܰ���, ���ֽ��� */ + iprintf(ihandle, iconn,"NOTE: unit of byte for total is 'byte', for realtime is 'bps, bit per second'!\n"); + iprintf(ihandle, iconn, "%8s %8s %12s\n", " ", "packet", "byte"); + iprintf(ihandle, iconn, "%8s %8llu %12llu\n%8s %8llu %12llu\n", + "total", g_io_vlan_cur_status.io_base_status.pkt_num, g_io_vlan_cur_status.io_base_status.pkt_byte, + "realtime", g_io_vlan_realtime_status.io_base_status.pkt_num, g_io_vlan_realtime_status.io_base_status.pkt_byte*8); + + return 0; +} + +void iknow_register_vlan_cb(void *ihandle) +{ + int ret; + + ret = iknow_register_cmd(ihandle, "show vlan summary", "display vlan flow summary", ifuncb_show_vlan_summary, NULL, 0, NULL); +// assert(0 == ret); + + ret = iknow_register_cmd(ihandle, "show vlan id summary", "display vlan flow summary by id", ifuncb_show_vlan_id_summary, NULL, 0, NULL); +// assert(0 == ret); +} + +void packet_io_status_vlan_time_cb(void) +{ + int i, j; + packet_io_status_vlan_t *global_vlan_status; + + memcpy((void *)&g_io_vlan_last_status, (void *)&g_io_vlan_cur_status, sizeof(packet_io_status_vlan_t)); /* ������һ���ֵ */ + memset((void *)&g_io_vlan_cur_status, 0, sizeof(packet_io_status_vlan_t)); /* ���� */ + + for(i = 0; i < g_packet_io_thread_num; i++){ + global_vlan_status = (packet_io_status_vlan_t *)(g_packet_io_status_pool[i]->packet_io_status[IO_STATUS_VLAN]); + g_io_vlan_cur_status.io_base_status.pkt_num += global_vlan_status->io_base_status.pkt_num; + g_io_vlan_cur_status.io_base_status.pkt_byte += global_vlan_status->io_base_status.pkt_byte; + for(j = 0; j < VLAN_ID_MAX; j++){ + g_io_vlan_cur_status.vlan_pkt_num[j] += global_vlan_status->vlan_pkt_num[j]; + g_io_vlan_cur_status.vlan_pkt_byte[j] += global_vlan_status->vlan_pkt_byte[j]; + } + } + + g_io_vlan_realtime_status.io_base_status.pkt_num = g_io_vlan_cur_status.io_base_status.pkt_num - g_io_vlan_last_status.io_base_status.pkt_num; + g_io_vlan_realtime_status.io_base_status.pkt_byte = g_io_vlan_cur_status.io_base_status.pkt_byte - g_io_vlan_last_status.io_base_status.pkt_byte; +} + +void *packet_io_status_vlan_mem_init(void) +{ + void *vlan_mem; + + vlan_mem = malloc(sizeof(packet_io_status_vlan_t)); + memset(vlan_mem, 0, sizeof(packet_io_status_vlan_t)); + + return vlan_mem; +} + +static inline void packet_io_vlan_status_update(int thread_seq, const struct layer_addr_vlan *addr, int raw_pkt_len) +{ + packet_io_status_vlan_t *io_vlan_status = (packet_io_status_vlan_t *)(g_packet_io_status_pool[thread_seq]->packet_io_status[IO_STATUS_VLAN]); + + io_vlan_status->io_base_status.pkt_num++; + io_vlan_status->io_base_status.pkt_byte += raw_pkt_len; + + io_vlan_status->vlan_pkt_num[addr->vlan_id]++; + io_vlan_status->vlan_pkt_byte[addr->vlan_id] += raw_pkt_len; +} +#else +int packet_io_status_vlan_init(void) +{ + return 0; +} +#endif + + +#ifdef __cplusplus +} +#endif + diff --git a/dealpkt/stream_manage.c b/dealpkt/stream_manage.c index b95a299..ac8c3c6 100644 --- a/dealpkt/stream_manage.c +++ b/dealpkt/stream_manage.c @@ -2541,9 +2541,9 @@ void iknow_register_stream_hash_cb(void *ihandle) int ret; ret = iknow_register_cmd(ihandle, "show stream summary", "display stream hash summary", ifuncb_show_stream_hash_summary, NULL, 0, NULL); - assert(0 == ret); + //assert(0 == ret); ret = iknow_register_cmd(ihandle, "show stream detail", "display stream hash detail", ifuncb_show_stream_hash_detail, NULL, 0, NULL); - assert(0 == ret); + //assert(0 == ret); } void packet_io_status_stream_hash_update(int thread_seq, unsigned long hash_list_num) diff --git a/entry/sapp_init.c b/entry/sapp_init.c index 0b285c8..2efc9e1 100644 --- a/entry/sapp_init.c +++ b/entry/sapp_init.c @@ -139,7 +139,7 @@ int MESA_platform_init(int argc, char *argv[]) exit(1); } - if(MESA_load_profile_int_def("conf/main.conf", "Module", "threadnum", &threadnum, 1) < 0){ + if(MESA_load_profile_int_def("conf/main.conf", "Module", "threadnum", &threadnum, 1) < 0 || threadnum <= 0){ printf("read conf 'threadnum' error!\n"); exit(1); } @@ -340,7 +340,7 @@ int MESA_platform_init(int argc, char *argv[]) init_stream_manage(threadnum); #if DEBUG - MESA_load_profile_int_def("conf/main.conf", "Module", "iknow_switch", &int_tmp, 1); + MESA_load_profile_int_def("conf/main.conf", "ShowStatInfo", "iknow_switch", &int_tmp, 0); if(int_tmp != 0){ iknow_info_init(); } @@ -348,6 +348,8 @@ int MESA_platform_init(int argc, char *argv[]) timestamp_record_init(); #endif + sapp_assistant_init(); + MESA_load_profile_int_def("conf/main.conf","Module", "load_plug_switch", &load_plug_sw, 1); if(load_plug_sw){ plugctrl_proc(); @@ -411,8 +413,6 @@ int MESA_platform_init(int argc, char *argv[]) MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"Module", (char *)"create_mpls_anyway", &sapp_global_single.create_mpls_anyway, 0); MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"Module", (char *)"send_fake_pkt_mode", &sapp_global_single.send_fake_pkt_mode, 0); MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"Module", (char *)"send_fake_pkt_gdev_sport", &sapp_global_single.send_fake_pkt_gdev_sport, 15); - - 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); diff --git a/include/stream_internal.h b/include/stream_internal.h index de383e8..049ef2e 100644 --- a/include/stream_internal.h +++ b/include/stream_internal.h @@ -287,10 +287,13 @@ struct sapp_global_single_t{ const char *fs2_server_ip; unsigned short fs2_server_port_host; short __pad1; - int fs2_filed_id_array[COUNTER_NUM]; + int fs2_sysinfo_id_array[COUNTER_NUM]; int fs2_latency_id_array[COUNTER_NUM]; + int fs2_plug_init_time_id_array[COUNTER_NUM]; + int fs2_plug_lantency_id_array[COUNTER_NUM][MAX_THREAD_NUM]; + 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Դ�˿� */ diff --git a/inner_plug/sapp_assistant.cpp b/inner_plug/sapp_assistant.cpp index 7f1d0ac..9e42577 100644 --- a/inner_plug/sapp_assistant.cpp +++ b/inner_plug/sapp_assistant.cpp @@ -336,36 +336,36 @@ static int sapp_fs2_init(void) FS_set_para(sapp_global_single.fs2_handle, STATS_SERVER_PORT, &sapp_global_single.fs2_server_port_host, sizeof(short)); - sapp_global_single.fs2_filed_id_array[PKT_ETHERNET] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ethernet_pps"); - sapp_global_single.fs2_filed_id_array[PKT_ETHERNET_LEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ethernet_bps"); + sapp_global_single.fs2_sysinfo_id_array[PKT_ETHERNET] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ethernet_pps"); + sapp_global_single.fs2_sysinfo_id_array[PKT_ETHERNET_LEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ethernet_bps"); - sapp_global_single.fs2_filed_id_array[PKT_IP] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv4_pps"); - sapp_global_single.fs2_filed_id_array[PKT_IPLEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv4_bps"); + sapp_global_single.fs2_sysinfo_id_array[PKT_IP] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv4_pps"); + sapp_global_single.fs2_sysinfo_id_array[PKT_IPLEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv4_bps"); - sapp_global_single.fs2_filed_id_array[PKT_IPV6] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv6_pps"); - sapp_global_single.fs2_filed_id_array[PKT_IPV6LEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv6_bps"); + sapp_global_single.fs2_sysinfo_id_array[PKT_IPV6] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv6_pps"); + sapp_global_single.fs2_sysinfo_id_array[PKT_IPV6LEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv6_bps"); - sapp_global_single.fs2_filed_id_array[PKT_TCP] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_pps"); - sapp_global_single.fs2_filed_id_array[PKT_TCPLEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_bps"); + sapp_global_single.fs2_sysinfo_id_array[PKT_TCP] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_pps"); + sapp_global_single.fs2_sysinfo_id_array[PKT_TCPLEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_bps"); - sapp_global_single.fs2_filed_id_array[PKT_UDP] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "UDP_pps"); - sapp_global_single.fs2_filed_id_array[PKT_UDPLEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "UDP_bps"); + sapp_global_single.fs2_sysinfo_id_array[PKT_UDP] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "UDP_pps"); + sapp_global_single.fs2_sysinfo_id_array[PKT_UDPLEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "UDP_bps"); - sapp_global_single.fs2_filed_id_array[SYS_TCP_LINK_NEW] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_NEW"); - sapp_global_single.fs2_filed_id_array[SYS_TCP_LINK_DEL] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_DEL"); - sapp_global_single.fs2_filed_id_array[SYS_TCP_LINK_DATA] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_CONCURRENT"); + sapp_global_single.fs2_sysinfo_id_array[SYS_TCP_LINK_NEW] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_NEW"); + sapp_global_single.fs2_sysinfo_id_array[SYS_TCP_LINK_DEL] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_DEL"); + sapp_global_single.fs2_sysinfo_id_array[SYS_TCP_LINK_DATA] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_CONCURRENT"); - sapp_global_single.fs2_filed_id_array[LINK_DOUBLE] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, - FS_CALC_CURRENT, "TCP_LINK_DOUBLE"); - sapp_global_single.fs2_filed_id_array[LINK_SINGLE_C2S] = FS_register(sapp_global_single.fs2_handle, - FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_C2S"); - sapp_global_single.fs2_filed_id_array[LINK_SINGLE_S2C] = FS_register(sapp_global_single.fs2_handle, - FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_S2C"); + sapp_global_single.fs2_sysinfo_id_array[LINK_DOUBLE] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, + FS_CALC_CURRENT, "TCP_LINK_DOUBLE"); + sapp_global_single.fs2_sysinfo_id_array[LINK_SINGLE_C2S] = FS_register(sapp_global_single.fs2_handle, + FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_C2S"); + sapp_global_single.fs2_sysinfo_id_array[LINK_SINGLE_S2C] = FS_register(sapp_global_single.fs2_handle, + FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_S2C"); - sapp_global_single.fs2_filed_id_array[SEND_TCP_RST] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "SEND_TCP_RST"); - sapp_global_single.fs2_filed_id_array[SEND_TCP_SYN_ACK] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "SEND_TCP_S/A"); - sapp_global_single.fs2_filed_id_array[SEND_UDP_PKT] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "SEND_UDP"); + sapp_global_single.fs2_sysinfo_id_array[SEND_TCP_RST] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "SEND_TCP_RST"); + sapp_global_single.fs2_sysinfo_id_array[SEND_TCP_SYN_ACK] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "SEND_TCP_S/A"); + sapp_global_single.fs2_sysinfo_id_array[SEND_UDP_PKT] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "SEND_UDP"); if(unlikely(g_timestamp_record_sw)) { for(int i = 0; i < g_packet_io_thread_num; i++) @@ -440,16 +440,62 @@ void sapp_statsd_add_para(const char *key, unsigned long long value) } #endif +void sapp_fs2_register_plug_id(int plug_id, const char *plug_name) +{ + if(sapp_global_single.fs2_handle != NULL) + { + char status_name[NAME_MAX]; + sprintf(status_name, "%s(us)", plug_name); + sapp_global_single.fs2_plug_init_time_id_array[plug_id] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_STATUS, FS_CALC_CURRENT, status_name); + FS_set_para(sapp_global_single.fs2_handle, NOT_SEND_METRIC_TO_SERVER, &sapp_global_single + .fs2_plug_init_time_id_array[plug_id], sizeof(int)); + if(unlikely(g_timestamp_record_sw)) + { + for(int i = 0; i < g_packet_io_thread_num; i++) + { + char histogram_name[NAME_MAX]; + sprintf(histogram_name, "%s_%d(ns)", plug_name, i); + sapp_global_single.fs2_plug_lantency_id_array[plug_id][i] = FS_register_histogram(sapp_global_single.fs2_handle, //Field Stat��� + FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ + histogram_name, //ͳ�������ƣ��ַ��� + 1, //���ٵ���Сֵ + 1000000, //���ٵ����ֵ + 2); //���ȣ���С�����λ����Χ1~4 + FS_set_para(sapp_global_single.fs2_handle, NOT_SEND_METRIC_TO_SERVER, &sapp_global_single + .fs2_plug_lantency_id_array[plug_id][i], sizeof(int)); + } + } + } +} + +void sapp_fs2_set_plug_init_time(int plug_id, long long time_us) +{ + if(sapp_global_single.fs2_handle != NULL) + { + FS_operate(sapp_global_single.fs2_handle, sapp_global_single.fs2_plug_init_time_id_array[plug_id], 0, FS_OP_SET, (long long)time_us); + } +} + +void sapp_fs2_set_plug_lantency(int plug_id, int thread_seq, long long time_cost) +{ + if(likely(sapp_global_single.fs2_handle != NULL) && unlikely(g_timestamp_record_sw)) + { + FS_operate(sapp_global_single.fs2_handle, sapp_global_single.fs2_plug_lantency_id_array[plug_id][thread_seq], 0, FS_OP_SET, time_cost); + } +} + void sapp_fs2_update(int field_index, unsigned long long value) { - if(sapp_global_single.fs2_handle != NULL){ - FS_operate(sapp_global_single.fs2_handle, sapp_global_single.fs2_filed_id_array[field_index], 0, FS_OP_SET, (long long)value); + if(sapp_global_single.fs2_handle != NULL) + { + FS_operate(sapp_global_single.fs2_handle, sapp_global_single.fs2_sysinfo_id_array[field_index], 0, FS_OP_SET, (long long)value); } } void sapp_fs2_set_latency(int thead_seq, long long time_cost) { - if(sapp_global_single.fs2_handle != NULL){ + if(sapp_global_single.fs2_handle != NULL) + { FS_operate(sapp_global_single.fs2_handle, sapp_global_single.fs2_latency_id_array[thead_seq], 0, FS_OP_SET, time_cost); } } diff --git a/plugin/src/plugin.c b/plugin/src/plugin.c index 71624ba..7cba2ca 100644 --- a/plugin/src/plugin.c +++ b/plugin/src/plugin.c @@ -95,6 +95,9 @@ int stream_register_fun(int funtype,char (*x)(void)); #include <unistd.h> #include <dlfcn.h> #include <assert.h> +#include <bits/time.h> +#include <time.h> +#include <stream_register.h> //#include <readline/readline.h> //#include <readline/history.h> #include "MESA_prof_load.h" @@ -111,8 +114,10 @@ extern stBusinessPlugInfo* g_business_plug_info; extern stProtocolPlugInfo **g_protocol_plug_info_array; extern int g_timestamp_record_sw; extern long long g_timedelay_threshold; - -int g_plugin_plugid ; +extern sapp_fs2_register_plug_id(int plug_id, const char *plug_name); +extern sapp_fs2_set_plug_init_time(int plug_id, long long time_us); +int g_plugin_proto_plugid ; +int g_plugin_other_plugid ; stEntryNameInfo* g_entryname_info; /* @@ -693,16 +698,20 @@ int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo* } - + struct timespec start, end; + long elapsed = 0; + clock_gettime(CLOCK_MONOTONIC, &start); + rec = fun_init(); if(rec < 0) { MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s init error,don't load it\n",buf_sofilename); return -1; } + clock_gettime(CLOCK_MONOTONIC, &end); + elapsed = (end.tv_sec - start.tv_sec)*1000000 + (end.tv_nsec - start.tv_nsec)/1000; - - //load FUNNAME_DESTROY + //load FUNNAME_DESTROY memset(buf_funname,0,PLUGIN_MAX_CONFLEN); MESA_load_profile_string_nodef(filename,SECTION_PLUGINFO,KEYWORD_FUNDESTROY,buf_funname,PLUGIN_MAX_CONFLEN); if(buf_funname[0] !='\0') @@ -745,7 +754,6 @@ int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo* pluginfo_pro->filepoint = filepoint; pluginfo_pro->fun_destroy = fun_destroy; - //dlsym GET_PLUGID() memset(buf_funname,0,PLUGIN_MAX_CONFLEN); MESA_load_profile_string_nodef(filename,SECTION_PLUGINFO,KEYWORD_FUNGETID,buf_funname,PLUGIN_MAX_CONFLEN); @@ -767,10 +775,11 @@ int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo* } - - g_plugin_plugid++; - fun_getplugid(g_plugin_plugid); - pluginfo_pro->plugid = g_plugin_plugid; + g_plugin_proto_plugid++; + fun_getplugid(g_plugin_proto_plugid); + pluginfo_pro->plugid = g_plugin_proto_plugid; + sapp_fs2_register_plug_id(g_plugin_proto_plugid, pluginfo_pro->plugname); + sapp_fs2_set_plug_init_time(g_plugin_proto_plugid, elapsed); //dlsym flag_change memset(buf_funname,0,PLUGIN_MAX_CONFLEN); @@ -793,7 +802,6 @@ int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo* } - //dlsym flag_state memset(buf_funname,0,PLUGIN_MAX_CONFLEN); MESA_load_profile_string_nodef(filename,SECTION_PLUGINFO,KEYWORD_FUNSTATE,buf_funname,PLUGIN_MAX_CONFLEN); @@ -817,8 +825,13 @@ int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo* //business plug else { + g_plugin_other_plugid+=1; + sapp_fs2_register_plug_id(g_plugin_other_plugid + MAX_FUN_NUM, pluginfo_bus->plugname); + sapp_fs2_set_plug_init_time(g_plugin_other_plugid + MAX_FUN_NUM, elapsed); + pluginfo_bus->filepoint = filepoint; pluginfo_bus->fun_destroy = fun_destroy; + pluginfo_bus->plugid = g_plugin_other_plugid+MAX_FUN_NUM; // pluginfo_bus->fun_update = (int (*)(int,int,char*,char*))(dlsym(filepoint,FUNNAME_UPDATE)); } diff --git a/plugin/src/plugin_protocol.c b/plugin/src/plugin_protocol.c index a8e1064..a11f1f3 100644 --- a/plugin/src/plugin_protocol.c +++ b/plugin/src/plugin_protocol.c @@ -1,168 +1,168 @@ -#include <stdio.h>
-#include <string.h>
-#include <dlfcn.h>
-#include "MESA_prof_load.h"
-#include "MESA_handle_logger.h"
-#include "stream.h"
-#include "plugin_proc.h"
-#include "plugin_platform.h"
-#include "plugin_protocol.h"
-#include "plugin_business.h"
-#include "plugin.h"
-
-stProtocolPlugInfo* g_protocol_plug_info;
-stProtocolPlugInfo **g_protocol_plug_info_array;
-extern int g_plugin_plugid;
-extern int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo* pluginfo_pro,stBusinessPlugInfo* pluginfo_bus);
-extern int process_confelem_platentry(char* filename,void* fp_dlopen,char* plugname);
-
-
-/* 2016-05-30 lijia add, Ϊ�˸��Ƶ��ò������, ����ÿ�ζ���������, ��ָ��洢������, ֱ��ȡ�±� */
-static void plugin_protocol_info_convert(void)
-{
- int i;
- stProtocolPlugInfo *tmp_plug_info = g_protocol_plug_info;
-
- if(NULL == g_protocol_plug_info){
- return;
- }
-
- g_protocol_plug_info_array = malloc(sizeof(void *) * (g_plugin_plugid + 1));
- memset(g_protocol_plug_info_array, 0, sizeof(void *) * (g_plugin_plugid + 1));
-
- while(tmp_plug_info->next){
- tmp_plug_info = tmp_plug_info->next;
- }
-
- for(i = 1; i <= g_plugin_plugid; i++){
- g_protocol_plug_info_array[i] = tmp_plug_info;
- if(NULL == tmp_plug_info){
- break;
- }
- tmp_plug_info = tmp_plug_info->pre;
- }
-}
-
-/****************************************************************************
-������:plugin_load_protocol()
-���ܣ������������������ļ��б�
-���룺�������������ļ��б�ȫ·����
-�����0:sucess
- -1:error
-*****************************************************************************/
-int plugin_load_protocol(char* conflist_filename)
-{
- int rec;
-
- rec = process_conflist(conflist_filename,PLUGTYPE_PROTOCOL);
- if(rec < 0)
- {
- return -1;
- }
-
- plugin_protocol_info_convert();
-
- return 0;
-}
-
-
-
-/****************************************************************************
-������:init_pluginfo_elem_pro()
-���ܣ���������������Ϣ
-���룺
-�����
-*****************************************************************************/
-void init_pluginfo_elem_pro(stProtocolPlugInfo** protocol_plug_info)
-{
- stProtocolPlugInfo* plug_info = (stProtocolPlugInfo*)malloc(sizeof(stProtocolPlugInfo));
- memset(plug_info,0,sizeof(stProtocolPlugInfo));
-
- *protocol_plug_info = plug_info;
-
- return;
-}
-
-/****************************************************************************
-������:destroy_pluginfo_elem_pro()
-���ܣ��ͷŽ���������Ϣ
-���룺
-�����
-*****************************************************************************/
-void destroy_pluginfo_elem_pro(stProtocolPlugInfo* plug_info)
-{
- if(plug_info->plugname != NULL)
- {
- free(plug_info->plugname);
- plug_info->plugname = NULL;
- }
-
- free(plug_info);
- plug_info = NULL;
-
- return;
-
-}
-
-/****************************************************************************
-������:process_confelem_protocol()
-���ܣ����������������������ļ�������̬���ز������
-���룺�������������ļ�ȫ·����
-�����0:sucess
- -1:error
-*****************************************************************************/
-int process_confelem_protocol(char* confelem_filename)
-{
- int rec;
- stProtocolPlugInfo* plug_info;
-
-
- init_pluginfo_elem_pro(&plug_info);
-
-
- //PLUGNAME
- rec = process_confelem_plugname(confelem_filename,PLUGTYPE_PROTOCOL,&(plug_info->plugname));
- if(rec < 0)
- {
- destroy_pluginfo_elem_pro(plug_info);
- return -1;
- }
-
- //FILENAME
- rec = process_confelem_sofilename(confelem_filename,PLUGTYPE_PROTOCOL,plug_info,NULL);
- if(rec < 0)
- {
- destroy_pluginfo_elem_pro(plug_info);
- return -1;
- }
-
-
- //[IP],[IPV6],[TCP],[UDP]
- rec = process_confelem_platentry(confelem_filename,plug_info->filepoint,plug_info->plugname);
-
- if(rec < 0)
- {
- destroy_pluginfo_elem_pro(plug_info);
- return -1;
- }
-
-
- //add plug_info to protocol_plug_info's double dir link table
- if(g_protocol_plug_info == NULL)
- {
- g_protocol_plug_info = plug_info;
- }
- else
- {
- plug_info->next = g_protocol_plug_info;
- g_protocol_plug_info->pre = plug_info;
- g_protocol_plug_info = plug_info;
- }
-
- printf("\033[32m[Notice]%s, load %s success!\033[0m\n", PLUGIN_LOGNAME, plug_info->plugname);
- MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"load %s success!\n",plug_info->plugname);
-
- return 0;
-
-}
-
+#include <stdio.h> +#include <string.h> +#include <dlfcn.h> +#include "MESA_prof_load.h" +#include "MESA_handle_logger.h" +#include "stream.h" +#include "plugin_proc.h" +#include "plugin_platform.h" +#include "plugin_protocol.h" +#include "plugin_business.h" +#include "plugin.h" + +stProtocolPlugInfo* g_protocol_plug_info; +stProtocolPlugInfo **g_protocol_plug_info_array; +extern int g_plugin_proto_plugid; +extern int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo* pluginfo_pro,stBusinessPlugInfo* pluginfo_bus); +extern int process_confelem_platentry(char* filename,void* fp_dlopen,char* plugname); + + +/* 2016-05-30 lijia add, Ϊ�˸��Ƶ��ò������, ����ÿ�ζ���������, ��ָ��洢������, ֱ��ȡ�±� */ +static void plugin_protocol_info_convert(void) +{ + int i; + stProtocolPlugInfo *tmp_plug_info = g_protocol_plug_info; + + if(NULL == g_protocol_plug_info){ + return; + } + + g_protocol_plug_info_array = malloc(sizeof(void *) * (g_plugin_proto_plugid + 1)); + memset(g_protocol_plug_info_array, 0, sizeof(void *) * (g_plugin_proto_plugid + 1)); + + while(tmp_plug_info->next){ + tmp_plug_info = tmp_plug_info->next; + } + + for(i = 1; i <= g_plugin_proto_plugid; i++){ + g_protocol_plug_info_array[i] = tmp_plug_info; + if(NULL == tmp_plug_info){ + break; + } + tmp_plug_info = tmp_plug_info->pre; + } +} + +/**************************************************************************** +������:plugin_load_protocol() +���ܣ������������������ļ��б� +���룺�������������ļ��б�ȫ·���� +�����0:sucess + -1:error +*****************************************************************************/ +int plugin_load_protocol(char* conflist_filename) +{ + int rec; + + rec = process_conflist(conflist_filename,PLUGTYPE_PROTOCOL); + if(rec < 0) + { + return -1; + } + + plugin_protocol_info_convert(); + + return 0; +} + + + +/**************************************************************************** +������:init_pluginfo_elem_pro() +���ܣ���������������Ϣ +���룺 +����� +*****************************************************************************/ +void init_pluginfo_elem_pro(stProtocolPlugInfo** protocol_plug_info) +{ + stProtocolPlugInfo* plug_info = (stProtocolPlugInfo*)malloc(sizeof(stProtocolPlugInfo)); + memset(plug_info,0,sizeof(stProtocolPlugInfo)); + + *protocol_plug_info = plug_info; + + return; +} + +/**************************************************************************** +������:destroy_pluginfo_elem_pro() +���ܣ��ͷŽ���������Ϣ +���룺 +����� +*****************************************************************************/ +void destroy_pluginfo_elem_pro(stProtocolPlugInfo* plug_info) +{ + if(plug_info->plugname != NULL) + { + free(plug_info->plugname); + plug_info->plugname = NULL; + } + + free(plug_info); + plug_info = NULL; + + return; + +} + +/**************************************************************************** +������:process_confelem_protocol() +���ܣ����������������������ļ�������̬���ز������ +���룺�������������ļ�ȫ·���� +�����0:sucess + -1:error +*****************************************************************************/ +int process_confelem_protocol(char* confelem_filename) +{ + int rec; + stProtocolPlugInfo* plug_info; + + + init_pluginfo_elem_pro(&plug_info); + + + //PLUGNAME + rec = process_confelem_plugname(confelem_filename,PLUGTYPE_PROTOCOL,&(plug_info->plugname)); + if(rec < 0) + { + destroy_pluginfo_elem_pro(plug_info); + return -1; + } + + //FILENAME + rec = process_confelem_sofilename(confelem_filename,PLUGTYPE_PROTOCOL,plug_info,NULL); + if(rec < 0) + { + destroy_pluginfo_elem_pro(plug_info); + return -1; + } + + + //[IP],[IPV6],[TCP],[UDP] + rec = process_confelem_platentry(confelem_filename,plug_info->filepoint,plug_info->plugname); + + if(rec < 0) + { + destroy_pluginfo_elem_pro(plug_info); + return -1; + } + + + //add plug_info to protocol_plug_info's double dir link table + if(g_protocol_plug_info == NULL) + { + g_protocol_plug_info = plug_info; + } + else + { + plug_info->next = g_protocol_plug_info; + g_protocol_plug_info->pre = plug_info; + g_protocol_plug_info = plug_info; + } + + printf("\033[32m[Notice]%s, load %s success!\033[0m\n", PLUGIN_LOGNAME, plug_info->plugname); + MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"load %s success!\n",plug_info->plugname); + + return 0; + +} + diff --git a/run/conf/main.conf b/run/conf/main.conf index 53558c1..7915c2e 100644 --- a/run/conf/main.conf +++ b/run/conf/main.conf @@ -1,11 +1,11 @@ [Module] -threadnum=8 +threadnum=1 #cpu_bind_core_mask=1,2,3,4,5 -cpu_bind_core_mask=0xFF0 +#cpu_bind_core_mask=0xFF0 app_instance_name=sapp MaxTcpStreams=900 -MaxUdpStreams=900 +axUdpStreams=900 LinkTimeout=10 UdpResetTime=10 CreatLinkMode=3 @@ -24,9 +24,9 @@ kill_tcp_with_gdev=0 signal_take_over_switch=0 -timestamp_record=1 -#timedelay_threshold unit: CPU CYCLE -timedelay_threshold=1000 +timestamp_record=0 +#timedelay_threshold unit: ns +timedelay_threshold=100000 analyse_tcp_option=0 @@ -100,7 +100,7 @@ FS_app_name=sapp_test FS_send_histogram=0 [pkt_dump] -pkt_dump_switch=1 +pkt_dump_switch=0 #1:local file; 2:udp socket pkt_dump_mode=2 pkt_dump_cmd_port=12345 |
