|
|
|
@@ -2,6 +2,7 @@
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
@@ -25,26 +26,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
int g_deliver_version_VERSION_20180718;
|
|
|
|
int g_deliver_version_VERSION_20180718;
|
|
|
|
|
|
|
|
|
|
|
|
unsigned char* g_deliver_sendbuf[MAX_THREAD_NUM];
|
|
|
|
struct deliver_globle_info g_deliver_globle_info;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct deliver_comm_info g_deliver_comminfo;
|
|
|
|
|
|
|
|
struct deliver_sendpkt_info g_deliver_sendinfo;
|
|
|
|
|
|
|
|
struct deliver_fs2_info g_deliver_fs2info;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *g_deliver_fs2_name[FS2_COLUMN_NUM] ={"RECV_PKTS","RECV_BYTES","SEND_PKTS","SEND_BYTES","ERROR_PKTS"};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int deliver_set_filestate2(int thread_seq,int colum_index,int value)
|
|
|
|
int deliver_set_filestate2(int thread_seq,int colum_index,int value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(thread_seq>=g_deliver_comminfo.threadnum)
|
|
|
|
if(thread_seq>=g_deliver_globle_info.comminfo.threadnum)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,RLOG_LV_FATAL,"deliver_set_filestate2","thread_seq:%d,thread_num:%d",thread_seq,g_deliver_comminfo.threadnum);
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,RLOG_LV_FATAL,"deliver_set_filestate2","thread_seq:%d,thread_num:%d",thread_seq,g_deliver_globle_info.comminfo.threadnum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
g_deliver_fs2info.column_value[thread_seq][colum_index]+=value;
|
|
|
|
g_deliver_globle_info.fs2info.column_value[thread_seq][colum_index]+=value;
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -65,27 +59,27 @@ int deliver_filestate2_init(char* filepath)
|
|
|
|
MESA_load_profile_uint_def((char*)filepath,(char*)DELIVER_CONF_MODE,(char*)"filestat2_sport",(unsigned int*)&fs2_sport,8125);
|
|
|
|
MESA_load_profile_uint_def((char*)filepath,(char*)DELIVER_CONF_MODE,(char*)"filestat2_sport",(unsigned int*)&fs2_sport,8125);
|
|
|
|
MESA_load_profile_uint_def((char*)filepath,(char*)DELIVER_CONF_MODE,(char*)"filestat2_trans_switch",(unsigned int*)&trans_switch,0);
|
|
|
|
MESA_load_profile_uint_def((char*)filepath,(char*)DELIVER_CONF_MODE,(char*)"filestat2_trans_switch",(unsigned int*)&trans_switch,0);
|
|
|
|
|
|
|
|
|
|
|
|
g_deliver_fs2info.handler=FS_create_handle();
|
|
|
|
g_deliver_globle_info.fs2info.handler=FS_create_handle();
|
|
|
|
|
|
|
|
|
|
|
|
FS_set_para(g_deliver_fs2info.handler, OUTPUT_DEVICE,fs2_filename, strlen(fs2_filename)+1);
|
|
|
|
FS_set_para(g_deliver_globle_info.fs2info.handler, OUTPUT_DEVICE,fs2_filename, strlen(fs2_filename)+1);
|
|
|
|
FS_set_para(g_deliver_fs2info.handler, PRINT_MODE, &value, sizeof(value));
|
|
|
|
FS_set_para(g_deliver_globle_info.fs2info.handler, PRINT_MODE, &value, sizeof(value));
|
|
|
|
FS_set_para(g_deliver_fs2info.handler, STAT_CYCLE, &value, sizeof(value));
|
|
|
|
FS_set_para(g_deliver_globle_info.fs2info.handler, STAT_CYCLE, &value, sizeof(value));
|
|
|
|
FS_set_para(g_deliver_fs2info.handler, CREATE_THREAD, &value, sizeof(value));
|
|
|
|
FS_set_para(g_deliver_globle_info.fs2info.handler, CREATE_THREAD, &value, sizeof(value));
|
|
|
|
FS_set_para(g_deliver_fs2info.handler, APP_NAME, FS2_APPNAME, strlen(FS2_APPNAME)+1);
|
|
|
|
FS_set_para(g_deliver_globle_info.fs2info.handler, APP_NAME, FS2_APPNAME, strlen(FS2_APPNAME)+1);
|
|
|
|
|
|
|
|
|
|
|
|
if(trans_switch==1)
|
|
|
|
if(trans_switch==1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FS_set_para(g_deliver_fs2info.handler, STATS_SERVER_IP, fs2_sip, strlen(fs2_sip)+1);
|
|
|
|
FS_set_para(g_deliver_globle_info.fs2info.handler, STATS_SERVER_IP, fs2_sip, strlen(fs2_sip)+1);
|
|
|
|
FS_set_para(g_deliver_fs2info.handler, STATS_SERVER_PORT,&fs2_sport,sizeof(int));
|
|
|
|
FS_set_para(g_deliver_globle_info.fs2info.handler, STATS_SERVER_PORT,&fs2_sport,sizeof(int));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(i=0;i<FS2_COLUMN_NUM;i++)
|
|
|
|
for(i=0;i<FS2_COLUMN_NUM;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
g_deliver_fs2info.column_id[i]=FS_register(g_deliver_fs2info.handler, FS_STYLE_FIELD, FS_CALC_CURRENT,g_deliver_fs2_name[i]);
|
|
|
|
g_deliver_globle_info.fs2info.column_id[i]=FS_register(g_deliver_globle_info.fs2info.handler, FS_STYLE_FIELD, FS_CALC_CURRENT,g_deliver_globle_info.fs2_name[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FS_start(g_deliver_fs2info.handler);
|
|
|
|
FS_start(g_deliver_globle_info.fs2info.handler);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -108,12 +102,12 @@ void* deliver_filestat2(void* arg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
column_value[i]=0;
|
|
|
|
column_value[i]=0;
|
|
|
|
|
|
|
|
|
|
|
|
for(j=0;j<g_deliver_comminfo.threadnum;j++)
|
|
|
|
for(j=0;j<g_deliver_globle_info.comminfo.threadnum;j++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
column_value[i]+=g_deliver_fs2info.column_value[j][i];
|
|
|
|
column_value[i]+=g_deliver_globle_info.fs2info.column_value[j][i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FS_operate(g_deliver_fs2info.handler,g_deliver_fs2info.column_id[i], 0,FS_OP_SET,column_value[i]);
|
|
|
|
FS_operate(g_deliver_globle_info.fs2info.handler,g_deliver_globle_info.fs2info.column_id[i], 0,FS_OP_SET,column_value[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
sleep(1);
|
|
|
|
@@ -143,16 +137,16 @@ int deliver_debug_log_v6(int level,char* module,struct deliver_pme_info* pmeinfo
|
|
|
|
switch(flag)
|
|
|
|
switch(flag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case DELIVER_FLAG_SENDPKT:
|
|
|
|
case DELIVER_FLAG_SENDPKT:
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,level,module,"addr:%s,%d,%s,%d,len:%d,dir:%d,seq:%u,ack:%u,ipid:%d,win:%d,flag:%d",
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,level,module,"addr:%s,%d,%s,%d,len:%d,dir:%d,seq:%u,ack:%u,ipid:%d,win:%d,flag:%d",
|
|
|
|
saddr_v6,sport,daddr_v6,dport,pkt_info->len,pkt_info->dir,
|
|
|
|
saddr_v6,sport,daddr_v6,dport,pkt_info->len,pkt_info->dir,
|
|
|
|
pkt_info->seq,pkt_info->ack,pkt_info->ipid,pkt_info->win,pkt_info->flag);
|
|
|
|
pkt_info->seq,pkt_info->ack,pkt_info->ipid,pkt_info->win,pkt_info->flag);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case DELIVER_FLAG_RECVPKT:
|
|
|
|
case DELIVER_FLAG_RECVPKT:
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,level,module,"addr:%s,%d,%s,%d,dir:%d,recv_len:%d",
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,level,module,"addr:%s,%d,%s,%d,dir:%d,recv_len:%d",
|
|
|
|
saddr_v6,sport,daddr_v6,dport,pkt_info->dir,recv_len);
|
|
|
|
saddr_v6,sport,daddr_v6,dport,pkt_info->dir,recv_len);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case DELIVER_FLAG_ENT:
|
|
|
|
case DELIVER_FLAG_ENT:
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,level,module,"addr:%s,%d,%s,%d,recvpkt:%d,recvbyte:%lld,sendpkt:%d,sendbytes:%lld",
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,level,module,"addr:%s,%d,%s,%d,recvpkt:%d,recvbyte:%lld,sendpkt:%d,sendbytes:%lld",
|
|
|
|
saddr_v6,sport,daddr_v6,dport,session_info->recv_pkt,session_info->recv_byte,
|
|
|
|
saddr_v6,sport,daddr_v6,dport,session_info->recv_pkt,session_info->recv_byte,
|
|
|
|
session_info->send_pkt,session_info->recv_byte);
|
|
|
|
session_info->send_pkt,session_info->recv_byte);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
@@ -183,16 +177,16 @@ int deliver_debug_log_v4(int level,char* module,struct deliver_pme_info* pmeinfo
|
|
|
|
switch(flag)
|
|
|
|
switch(flag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case DELIVER_FLAG_SENDPKT:
|
|
|
|
case DELIVER_FLAG_SENDPKT:
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,level,module,"addr:%s,%d,%s,%d,len:%d,dir:%d,seq:%u,ack:%u,ipid:%d,win:%d,flag:%d",
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,level,module,"addr:%s,%d,%s,%d,len:%d,dir:%d,seq:%u,ack:%u,ipid:%d,win:%d,flag:%d",
|
|
|
|
saddr_v4,sport,daddr_v4,dport,pkt_info->len,pkt_info->dir,
|
|
|
|
saddr_v4,sport,daddr_v4,dport,pkt_info->len,pkt_info->dir,
|
|
|
|
pkt_info->seq,pkt_info->ack,pkt_info->ipid,pkt_info->win,pkt_info->flag);
|
|
|
|
pkt_info->seq,pkt_info->ack,pkt_info->ipid,pkt_info->win,pkt_info->flag);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case DELIVER_FLAG_RECVPKT:
|
|
|
|
case DELIVER_FLAG_RECVPKT:
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,level,module,"addr:%s,%d,%s,%d,dir:%d,recv_len:%d",
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,level,module,"addr:%s,%d,%s,%d,dir:%d,recv_len:%d",
|
|
|
|
saddr_v4,sport,daddr_v4,dport,pkt_info->dir,recv_len);
|
|
|
|
saddr_v4,sport,daddr_v4,dport,pkt_info->dir,recv_len);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case DELIVER_FLAG_ENT:
|
|
|
|
case DELIVER_FLAG_ENT:
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,level,module,"addr:%s,%d,%s,%d,recvpkt:%d,recvbyte:%lld,sendpkt:%d,sendbytes:%lld",
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,level,module,"addr:%s,%d,%s,%d,recvpkt:%d,recvbyte:%lld,sendpkt:%d,sendbytes:%lld",
|
|
|
|
saddr_v4,sport,daddr_v4,dport,session_info->recv_pkt,session_info->recv_byte,
|
|
|
|
saddr_v4,sport,daddr_v4,dport,session_info->recv_pkt,session_info->recv_byte,
|
|
|
|
session_info->send_pkt,session_info->recv_byte);
|
|
|
|
session_info->send_pkt,session_info->recv_byte);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
@@ -206,9 +200,9 @@ int deliver_sendpkt_ether(int thread_seq,int buflen,unsigned char* buf,unsigned
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret=0;
|
|
|
|
int ret=0;
|
|
|
|
|
|
|
|
|
|
|
|
if(-1==ioctl(g_deliver_sendinfo.send_socket[thread_seq],SIOCGIFINDEX,&(g_deliver_sendinfo.ifr)))
|
|
|
|
if(-1==ioctl(g_deliver_globle_info.sendinfo.send_socket[thread_seq],SIOCGIFINDEX,&(g_deliver_globle_info.sendinfo.ifr)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,RLOG_LV_FATAL,DELIVER_MODULE_INIT,"get if index error:%d,%s,name:%d",errno,strerror(errno),g_deliver_sendinfo.senddevice);
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,RLOG_LV_FATAL,DELIVER_MODULE_INIT,"get if index error:%d,%s,name:%d",errno,strerror(errno),g_deliver_globle_info.sendinfo.senddevice);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -216,21 +210,21 @@ int deliver_sendpkt_ether(int thread_seq,int buflen,unsigned char* buf,unsigned
|
|
|
|
struct sockaddr_ll addr;
|
|
|
|
struct sockaddr_ll addr;
|
|
|
|
addr.sll_family=AF_PACKET;
|
|
|
|
addr.sll_family=AF_PACKET;
|
|
|
|
addr.sll_halen=ETHER_ADDR_LEN;
|
|
|
|
addr.sll_halen=ETHER_ADDR_LEN;
|
|
|
|
addr.sll_ifindex=g_deliver_sendinfo.ifr.ifr_ifindex;
|
|
|
|
addr.sll_ifindex=g_deliver_globle_info.sendinfo.ifr.ifr_ifindex;
|
|
|
|
addr.sll_protocol=htons(ETH_P_IP);
|
|
|
|
addr.sll_protocol=htons(ETH_P_IP);
|
|
|
|
memcpy(addr.sll_addr,dmac,ETHER_ADDR_LEN);
|
|
|
|
memcpy(addr.sll_addr,dmac,ETHER_ADDR_LEN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ioctl(g_deliver_sendinfo.send_socket[thread_seq],SIOCGIFHWADDR,&(g_deliver_sendinfo.ifr))==-1)
|
|
|
|
if(ioctl(g_deliver_globle_info.sendinfo.send_socket[thread_seq],SIOCGIFHWADDR,&(g_deliver_globle_info.sendinfo.ifr))==-1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ret=sendto(g_deliver_sendinfo.send_socket[thread_seq],buf,buflen,0,(struct sockaddr*)&addr,sizeof(addr));
|
|
|
|
ret=sendto(g_deliver_globle_info.sendinfo.send_socket[thread_seq],buf,buflen,0,(struct sockaddr*)&addr,sizeof(addr));
|
|
|
|
if(ret<0)
|
|
|
|
if(ret<0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
deliver_set_filestate2(thread_seq,FS2_COLUME_ERROR,1);
|
|
|
|
deliver_set_filestate2(thread_seq,FS2_COLUME_ERROR,1);
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,RLOG_LV_FATAL,DELIVER_MODULE_SENDPKT,"sendto() error,errno:%d,msg:%s!",errno,strerror(errno));
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,RLOG_LV_FATAL,DELIVER_MODULE_SENDPKT,"sendto() error,errno:%d,msg:%s!",errno,strerror(errno));
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -246,12 +240,12 @@ int deliver_sendpkt_ether(int thread_seq,int buflen,unsigned char* buf,unsigned
|
|
|
|
int deliver_init_pmeinfo(const struct tfe_stream_addr* addr,void** pme)
|
|
|
|
int deliver_init_pmeinfo(const struct tfe_stream_addr* addr,void** pme)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//TODO:choose dst mac
|
|
|
|
//TODO:choose dst mac
|
|
|
|
int i=deliver_rand()%(g_deliver_sendinfo.receiver_num);
|
|
|
|
int i=deliver_rand()%(g_deliver_globle_info.sendinfo.receiver_num);
|
|
|
|
|
|
|
|
|
|
|
|
struct deliver_pme_info* pmeinfo=(struct deliver_pme_info*)malloc(sizeof(struct deliver_pme_info));
|
|
|
|
struct deliver_pme_info* pmeinfo=(struct deliver_pme_info*)malloc(sizeof(struct deliver_pme_info));
|
|
|
|
memset(pmeinfo,0,sizeof(struct deliver_pme_info));
|
|
|
|
memset(pmeinfo,0,sizeof(struct deliver_pme_info));
|
|
|
|
memcpy((void*)&pmeinfo->addr_info,(void*)addr,sizeof(struct origin_stream_addr));
|
|
|
|
pmeinfo->addr_info = addr;
|
|
|
|
memcpy(pmeinfo->dst_macaddr,g_deliver_sendinfo.receiver_info[i].dst_macaddr,DELIVER_MACADDR_LEN);
|
|
|
|
memcpy(pmeinfo->dst_macaddr,g_deliver_globle_info.sendinfo.receiver_info[i].dst_macaddr,DELIVER_MACADDR_LEN);
|
|
|
|
|
|
|
|
|
|
|
|
*pme=pmeinfo;
|
|
|
|
*pme=pmeinfo;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -263,54 +257,59 @@ int deliver_send_v6(int thread_seq,struct deliver_pme_info* pmeinfo,int payload_
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int offset = 0;
|
|
|
|
int offset = 0;
|
|
|
|
unsigned short eth_type=0x0800;
|
|
|
|
unsigned short eth_type=0x0800;
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
struct sockaddr_in6* client_addr=NULL;
|
|
|
|
|
|
|
|
struct sockaddr_in6* server_addr=NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cur_dir=pmeinfo->pkt_info.dir;
|
|
|
|
int cur_dir=pmeinfo->pkt_info.dir;
|
|
|
|
|
|
|
|
const struct tfe_stream_addr* addr_info = pmeinfo->addr_info;
|
|
|
|
struct deliver_pkt_info* curpkt_info=&(pmeinfo->pkt_info);
|
|
|
|
struct deliver_pkt_info* curpkt_info=&(pmeinfo->pkt_info);
|
|
|
|
|
|
|
|
|
|
|
|
if(cur_dir==DELIVER_DIR_C2S)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
client_addr=(struct sockaddr_in6*)&(pmeinfo->addr_info.client);
|
|
|
|
|
|
|
|
server_addr=(struct sockaddr_in6*)&(pmeinfo->addr_info.server);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
client_addr=(struct sockaddr_in6*)&(pmeinfo->addr_info.server);
|
|
|
|
|
|
|
|
server_addr=(struct sockaddr_in6*)&(pmeinfo->addr_info.client);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
offset = sizeof(struct mesa_ethernet_hdr);
|
|
|
|
offset = sizeof(struct mesa_ethernet_hdr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(cur_dir==CONN_DIR_DOWNSTREAM)
|
|
|
|
deliver_build_tcp(ntohs(client_addr->sin6_port), ntohs(server_addr->sin6_port),
|
|
|
|
{
|
|
|
|
|
|
|
|
deliver_build_tcp(ntohs(addr_info->tuple4_v6->source), ntohs(addr_info->tuple4_v6->dest),
|
|
|
|
curpkt_info->seq, curpkt_info->ack,curpkt_info->flag, curpkt_info->win, 0,
|
|
|
|
curpkt_info->seq, curpkt_info->ack,curpkt_info->flag, curpkt_info->win, 0,
|
|
|
|
payload,payload_len,
|
|
|
|
payload,payload_len,
|
|
|
|
g_deliver_sendbuf[thread_seq]+offset+sizeof(struct mesa_ip6_hdr));
|
|
|
|
g_deliver_globle_info.sendbuf[thread_seq]+offset+sizeof(struct mesa_ip6_hdr));
|
|
|
|
|
|
|
|
|
|
|
|
deliver_build_ipv6(0, 0, payload_len + sizeof(struct mesa_tcp_hdr), IPPROTO_TCP, curpkt_info->ttl,
|
|
|
|
deliver_build_ipv6(0, 0, payload_len + sizeof(struct mesa_tcp_hdr), IPPROTO_TCP, curpkt_info->ttl,
|
|
|
|
&(client_addr->sin6_addr),&(server_addr->sin6_addr),NULL, 0,
|
|
|
|
&(addr_info->tuple4_v6->saddr),&(addr_info->tuple4_v6->daddr),NULL, 0,
|
|
|
|
g_deliver_sendbuf[thread_seq]+offset);
|
|
|
|
g_deliver_globle_info.sendbuf[thread_seq]+offset);
|
|
|
|
|
|
|
|
|
|
|
|
deliver_do_checksum(g_deliver_sendbuf[thread_seq]+offset, IPPROTO_TCP, SENDPACKET_TCP_H+payload_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
deliver_build_tcp(ntohs(addr_info->tuple4_v6->dest), ntohs(addr_info->tuple4_v6->source),
|
|
|
|
|
|
|
|
curpkt_info->seq, curpkt_info->ack,curpkt_info->flag, curpkt_info->win, 0,
|
|
|
|
|
|
|
|
payload,payload_len,
|
|
|
|
|
|
|
|
g_deliver_globle_info.sendbuf[thread_seq]+offset+sizeof(struct mesa_ip6_hdr));
|
|
|
|
|
|
|
|
|
|
|
|
deliver_do_checksum(g_deliver_sendbuf[thread_seq]+offset, IPPROTO_IP, SENDPACKET_IP_H);
|
|
|
|
deliver_build_ipv6(0, 0, payload_len + sizeof(struct mesa_tcp_hdr), IPPROTO_TCP, curpkt_info->ttl,
|
|
|
|
|
|
|
|
&(addr_info->tuple4_v6->daddr),&(addr_info->tuple4_v6->saddr),NULL, 0,
|
|
|
|
|
|
|
|
g_deliver_globle_info.sendbuf[thread_seq]+offset);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deliver_build_ethernet((unsigned char*)(pmeinfo->dst_macaddr),(unsigned char*)(g_deliver_sendinfo.src_macaddr),
|
|
|
|
|
|
|
|
eth_type,NULL,0,(unsigned char*)g_deliver_sendbuf[thread_seq]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deliver_do_checksum(g_deliver_globle_info.sendbuf[thread_seq]+offset, IPPROTO_TCP, SENDPACKET_TCP_H+payload_len);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deliver_do_checksum(g_deliver_globle_info.sendbuf[thread_seq]+offset, IPPROTO_IP, SENDPACKET_IP_H);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deliver_build_ethernet((unsigned char*)(pmeinfo->dst_macaddr),(unsigned char*)(g_deliver_globle_info.sendinfo.src_macaddr),
|
|
|
|
|
|
|
|
eth_type,NULL,0,(unsigned char*)g_deliver_globle_info.sendbuf[thread_seq]);
|
|
|
|
|
|
|
|
|
|
|
|
deliver_sendpkt_ether(thread_seq,SENDPACKET_TCP_H+SENDPACKET_IP_H+SENDPACKET_ETH_H+payload_len,
|
|
|
|
deliver_sendpkt_ether(thread_seq,SENDPACKET_TCP_H+SENDPACKET_IP_H+SENDPACKET_ETH_H+payload_len,
|
|
|
|
g_deliver_sendbuf[thread_seq],pmeinfo->dst_macaddr);
|
|
|
|
g_deliver_globle_info.sendbuf[thread_seq],pmeinfo->dst_macaddr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pmeinfo->session_info.send_pkt++;
|
|
|
|
pmeinfo->session_info.send_pkt++;
|
|
|
|
pmeinfo->session_info.send_byte+=payload_len;
|
|
|
|
pmeinfo->session_info.send_byte+=payload_len;
|
|
|
|
|
|
|
|
|
|
|
|
deliver_debug_log_v6(RLOG_LV_DEBUG,(char*)DELIVER_SENDPKT_DEBUG,pmeinfo,DELIVER_FLAG_SENDPKT,0);
|
|
|
|
deliver_debug_log_v6(RLOG_LV_DEBUG,(char*)DELIVER_SENDPKT_DEBUG,pmeinfo,DELIVER_FLAG_SENDPKT,0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -321,54 +320,56 @@ int deliver_send_v4(int thread_seq,struct deliver_pme_info* pmeinfo,int payload_
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int offset = 0;
|
|
|
|
int offset = 0;
|
|
|
|
unsigned short eth_type=0x0800;
|
|
|
|
unsigned short eth_type=0x0800;
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
struct sockaddr_in* client_addr=NULL;
|
|
|
|
|
|
|
|
struct sockaddr_in* server_addr=NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cur_dir=pmeinfo->pkt_info.dir;
|
|
|
|
int cur_dir=pmeinfo->pkt_info.dir;
|
|
|
|
|
|
|
|
const struct tfe_stream_addr* addr_info = pmeinfo->addr_info;
|
|
|
|
struct deliver_pkt_info* curpkt_info=&(pmeinfo->pkt_info);
|
|
|
|
struct deliver_pkt_info* curpkt_info=&(pmeinfo->pkt_info);
|
|
|
|
|
|
|
|
|
|
|
|
if(cur_dir==DELIVER_DIR_C2S)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
client_addr=(struct sockaddr_in*)&(pmeinfo->addr_info.client);
|
|
|
|
|
|
|
|
server_addr=(struct sockaddr_in*)&(pmeinfo->addr_info.server);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
client_addr=(struct sockaddr_in*)&(pmeinfo->addr_info.server);
|
|
|
|
|
|
|
|
server_addr=(struct sockaddr_in*)&(pmeinfo->addr_info.client);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
offset = sizeof(struct mesa_ethernet_hdr);
|
|
|
|
offset = sizeof(struct mesa_ethernet_hdr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(cur_dir==CONN_DIR_DOWNSTREAM)
|
|
|
|
deliver_build_tcp(ntohs(client_addr->sin_port), ntohs(server_addr->sin_port),
|
|
|
|
{
|
|
|
|
|
|
|
|
deliver_build_tcp(ntohs(addr_info->tuple4_v4->source), ntohs(addr_info->tuple4_v4->dest),
|
|
|
|
curpkt_info->seq, curpkt_info->ack,curpkt_info->flag, curpkt_info->win, 0,
|
|
|
|
curpkt_info->seq, curpkt_info->ack,curpkt_info->flag, curpkt_info->win, 0,
|
|
|
|
payload,payload_len,
|
|
|
|
payload,payload_len,
|
|
|
|
g_deliver_sendbuf[thread_seq]+offset+sizeof(struct mesa_ip4_hdr));
|
|
|
|
g_deliver_globle_info.sendbuf[thread_seq]+offset+sizeof(struct mesa_ip4_hdr));
|
|
|
|
|
|
|
|
|
|
|
|
deliver_build_ipv4(SENDPACKET_TCP_H+payload_len, 0, curpkt_info->ipid, 0, 64, IPPROTO_TCP,
|
|
|
|
deliver_build_ipv4(SENDPACKET_TCP_H+payload_len, 0, curpkt_info->ipid, 0, 64, IPPROTO_TCP,
|
|
|
|
client_addr->sin_addr.s_addr,server_addr->sin_addr.s_addr, NULL, 0,
|
|
|
|
addr_info->tuple4_v4->saddr.s_addr,addr_info->tuple4_v4->daddr.s_addr, NULL, 0,
|
|
|
|
g_deliver_sendbuf[thread_seq]+offset);
|
|
|
|
g_deliver_globle_info.sendbuf[thread_seq]+offset);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
deliver_build_tcp(ntohs(addr_info->tuple4_v4->dest), ntohs(addr_info->tuple4_v4->source),
|
|
|
|
|
|
|
|
curpkt_info->seq, curpkt_info->ack,curpkt_info->flag, curpkt_info->win, 0,
|
|
|
|
|
|
|
|
payload,payload_len,
|
|
|
|
|
|
|
|
g_deliver_globle_info.sendbuf[thread_seq]+offset+sizeof(struct mesa_ip4_hdr));
|
|
|
|
|
|
|
|
|
|
|
|
deliver_do_checksum(g_deliver_sendbuf[thread_seq]+offset, IPPROTO_TCP, SENDPACKET_TCP_H+payload_len);
|
|
|
|
deliver_build_ipv4(SENDPACKET_TCP_H+payload_len, 0, curpkt_info->ipid, 0, 64, IPPROTO_TCP,
|
|
|
|
|
|
|
|
addr_info->tuple4_v4->daddr.s_addr,addr_info->tuple4_v4->saddr.s_addr, NULL, 0,
|
|
|
|
deliver_do_checksum(g_deliver_sendbuf[thread_seq]+offset, IPPROTO_IP, SENDPACKET_IP_H);
|
|
|
|
g_deliver_globle_info.sendbuf[thread_seq]+offset);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deliver_build_ethernet((unsigned char*)(pmeinfo->dst_macaddr),(unsigned char*)(g_deliver_sendinfo.src_macaddr),
|
|
|
|
deliver_do_checksum(g_deliver_globle_info.sendbuf[thread_seq]+offset, IPPROTO_TCP, SENDPACKET_TCP_H+payload_len);
|
|
|
|
eth_type,NULL,0,(unsigned char*)g_deliver_sendbuf[thread_seq]);
|
|
|
|
|
|
|
|
|
|
|
|
deliver_do_checksum(g_deliver_globle_info.sendbuf[thread_seq]+offset, IPPROTO_IP, SENDPACKET_IP_H);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deliver_build_ethernet((unsigned char*)(pmeinfo->dst_macaddr),(unsigned char*)(g_deliver_globle_info.sendinfo.src_macaddr),
|
|
|
|
|
|
|
|
eth_type,NULL,0,(unsigned char*)g_deliver_globle_info.sendbuf[thread_seq]);
|
|
|
|
|
|
|
|
|
|
|
|
deliver_sendpkt_ether(thread_seq,SENDPACKET_TCP_H+SENDPACKET_IP_H+SENDPACKET_ETH_H+payload_len,
|
|
|
|
deliver_sendpkt_ether(thread_seq,SENDPACKET_TCP_H+SENDPACKET_IP_H+SENDPACKET_ETH_H+payload_len,
|
|
|
|
g_deliver_sendbuf[thread_seq],pmeinfo->dst_macaddr);
|
|
|
|
g_deliver_globle_info.sendbuf[thread_seq],pmeinfo->dst_macaddr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pmeinfo->session_info.send_pkt++;
|
|
|
|
pmeinfo->session_info.send_pkt++;
|
|
|
|
pmeinfo->session_info.send_byte+=payload_len;
|
|
|
|
pmeinfo->session_info.send_byte+=payload_len;
|
|
|
|
|
|
|
|
|
|
|
|
deliver_debug_log_v4(RLOG_LV_DEBUG,(char*)DELIVER_SENDPKT_DEBUG,pmeinfo,DELIVER_FLAG_SENDPKT,0);
|
|
|
|
deliver_debug_log_v4(RLOG_LV_DEBUG,(char*)DELIVER_SENDPKT_DEBUG,pmeinfo,DELIVER_FLAG_SENDPKT,0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -376,7 +377,7 @@ int deliver_send_v4(int thread_seq,struct deliver_pme_info* pmeinfo,int payload_
|
|
|
|
|
|
|
|
|
|
|
|
int deliver_send_syn(int thread_seq,struct deliver_pme_info* pmeinfo)
|
|
|
|
int deliver_send_syn(int thread_seq,struct deliver_pme_info* pmeinfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pmeinfo->pkt_info.dir=DELIVER_DIR_C2S;
|
|
|
|
pmeinfo->pkt_info.dir=CONN_DIR_DOWNSTREAM;
|
|
|
|
pmeinfo->pkt_info.len=0;
|
|
|
|
pmeinfo->pkt_info.len=0;
|
|
|
|
pmeinfo->pkt_info.seq= deliver_rand();
|
|
|
|
pmeinfo->pkt_info.seq= deliver_rand();
|
|
|
|
pmeinfo->pkt_info.ack=0;
|
|
|
|
pmeinfo->pkt_info.ack=0;
|
|
|
|
@@ -400,7 +401,7 @@ int deliver_send_syn(int thread_seq,struct deliver_pme_info* pmeinfo)
|
|
|
|
|
|
|
|
|
|
|
|
int deliver_send_syn_ack(int thread_seq,struct deliver_pme_info* pmeinfo)
|
|
|
|
int deliver_send_syn_ack(int thread_seq,struct deliver_pme_info* pmeinfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pmeinfo->pkt_info.dir=DELIVER_DIR_S2C;
|
|
|
|
pmeinfo->pkt_info.dir=CONN_DIR_UPSTREAM;
|
|
|
|
pmeinfo->pkt_info.len=0;
|
|
|
|
pmeinfo->pkt_info.len=0;
|
|
|
|
pmeinfo->pkt_info.ack=pmeinfo->pkt_info.seq+1;
|
|
|
|
pmeinfo->pkt_info.ack=pmeinfo->pkt_info.seq+1;
|
|
|
|
pmeinfo->pkt_info.seq= deliver_rand();
|
|
|
|
pmeinfo->pkt_info.seq= deliver_rand();
|
|
|
|
@@ -424,7 +425,7 @@ int deliver_send_ack(int thread_seq,struct deliver_pme_info* pmeinfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned int ack_tmp=pmeinfo->pkt_info.ack;
|
|
|
|
unsigned int ack_tmp=pmeinfo->pkt_info.ack;
|
|
|
|
|
|
|
|
|
|
|
|
pmeinfo->pkt_info.dir=DELIVER_DIR_C2S;
|
|
|
|
pmeinfo->pkt_info.dir=CONN_DIR_DOWNSTREAM;
|
|
|
|
pmeinfo->pkt_info.len=0;
|
|
|
|
pmeinfo->pkt_info.len=0;
|
|
|
|
pmeinfo->pkt_info.ack=pmeinfo->pkt_info.seq+1;
|
|
|
|
pmeinfo->pkt_info.ack=pmeinfo->pkt_info.seq+1;
|
|
|
|
pmeinfo->pkt_info.seq= ack_tmp;
|
|
|
|
pmeinfo->pkt_info.seq= ack_tmp;
|
|
|
|
@@ -471,7 +472,7 @@ int deliver_set_pktinfo(struct deliver_pme_info* pmeinfo,int flag, int cur_dir,i
|
|
|
|
|
|
|
|
|
|
|
|
int deliver_send_rst(int thread_seq,struct deliver_pme_info* pmeinfo)
|
|
|
|
int deliver_send_rst(int thread_seq,struct deliver_pme_info* pmeinfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
deliver_set_pktinfo(pmeinfo,TH_RST,DELIVER_DIR_C2S,0);
|
|
|
|
deliver_set_pktinfo(pmeinfo,TH_RST,CONN_DIR_DOWNSTREAM,0);
|
|
|
|
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
|
|
|
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
deliver_send_v4(thread_seq,pmeinfo,0,NULL);
|
|
|
|
deliver_send_v4(thread_seq,pmeinfo,0,NULL);
|
|
|
|
@@ -482,7 +483,7 @@ int deliver_send_rst(int thread_seq,struct deliver_pme_info* pmeinfo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deliver_set_pktinfo(pmeinfo,TH_RST,DELIVER_DIR_S2C,0);
|
|
|
|
deliver_set_pktinfo(pmeinfo,TH_RST,CONN_DIR_UPSTREAM,0);
|
|
|
|
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
|
|
|
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
deliver_send_v4(thread_seq,pmeinfo,0,NULL);
|
|
|
|
deliver_send_v4(thread_seq,pmeinfo,0,NULL);
|
|
|
|
@@ -520,7 +521,7 @@ int mirror_stream_write(int cur_dir,const unsigned char * data, size_t len, void
|
|
|
|
const unsigned char* payload=data;
|
|
|
|
const unsigned char* payload=data;
|
|
|
|
int payload_len=0;
|
|
|
|
int payload_len=0;
|
|
|
|
int remain_len=len;
|
|
|
|
int remain_len=len;
|
|
|
|
int pkt_num=(len/(g_deliver_sendinfo.mtu))+1;
|
|
|
|
int pkt_num=(len/(g_deliver_globle_info.sendinfo.mtu))+1;
|
|
|
|
struct deliver_pme_info* pmeinfo=(struct deliver_pme_info*)*pme;
|
|
|
|
struct deliver_pme_info* pmeinfo=(struct deliver_pme_info*)*pme;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -540,9 +541,9 @@ int mirror_stream_write(int cur_dir,const unsigned char * data, size_t len, void
|
|
|
|
|
|
|
|
|
|
|
|
for(i=0;i<pkt_num;i++)
|
|
|
|
for(i=0;i<pkt_num;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
payload_len=remain_len<(g_deliver_sendinfo.mtu)?remain_len:(g_deliver_sendinfo.mtu);
|
|
|
|
payload_len=remain_len<(g_deliver_globle_info.sendinfo.mtu)?remain_len:(g_deliver_globle_info.sendinfo.mtu);
|
|
|
|
payload=data+(len-remain_len);
|
|
|
|
payload=data+(len-remain_len);
|
|
|
|
remain_len-=g_deliver_sendinfo.mtu;
|
|
|
|
remain_len-=g_deliver_globle_info.sendinfo.mtu;
|
|
|
|
|
|
|
|
|
|
|
|
deliver_set_pktinfo(pmeinfo,TH_ACK,cur_dir,payload_len);
|
|
|
|
deliver_set_pktinfo(pmeinfo,TH_ACK,cur_dir,payload_len);
|
|
|
|
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
|
|
|
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
|
|
|
@@ -577,22 +578,22 @@ void mirror_stream_close(void** pme, int thread_id)
|
|
|
|
|
|
|
|
|
|
|
|
int deliver_device_init()
|
|
|
|
int deliver_device_init()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char* if_name=g_deliver_sendinfo.senddevice;
|
|
|
|
char* if_name=g_deliver_globle_info.sendinfo.senddevice;
|
|
|
|
|
|
|
|
|
|
|
|
//init socket
|
|
|
|
//init socket
|
|
|
|
size_t ifname_len=strlen(if_name);
|
|
|
|
size_t ifname_len=strlen(if_name);
|
|
|
|
if(ifname_len<sizeof(g_deliver_sendinfo.ifr.ifr_name))
|
|
|
|
if(ifname_len<sizeof(g_deliver_globle_info.sendinfo.ifr.ifr_name))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
memset(g_deliver_sendinfo.ifr.ifr_name,0,IFNAMSIZ);
|
|
|
|
memset(g_deliver_globle_info.sendinfo.ifr.ifr_name,0,IFNAMSIZ);
|
|
|
|
memcpy(g_deliver_sendinfo.ifr.ifr_name,if_name,ifname_len);
|
|
|
|
memcpy(g_deliver_globle_info.sendinfo.ifr.ifr_name,if_name,ifname_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,RLOG_LV_FATAL,DELIVER_MODULE_INIT,"interface name :%s is too long\n",if_name);
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,RLOG_LV_FATAL,DELIVER_MODULE_INIT,"interface name :%s is too long\n",if_name);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
deliver_get_dev_mac(g_deliver_sendinfo.senddevice,g_deliver_sendinfo.src_macaddr);
|
|
|
|
deliver_get_dev_mac(g_deliver_globle_info.sendinfo.senddevice,g_deliver_globle_info.sendinfo.src_macaddr);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -610,12 +611,12 @@ int deliver_profile_init(const char* filepath,int* logger_level,char* logger_fil
|
|
|
|
MESA_load_profile_string_def(filepath,(char*)DELIVER_CONF_MODE,(char*)"logger_filepath",logger_filepath,DELIVER_CONF_MAXLEN,"./log/deliver.log");
|
|
|
|
MESA_load_profile_string_def(filepath,(char*)DELIVER_CONF_MODE,(char*)"logger_filepath",logger_filepath,DELIVER_CONF_MAXLEN,"./log/deliver.log");
|
|
|
|
|
|
|
|
|
|
|
|
//sendpkt info
|
|
|
|
//sendpkt info
|
|
|
|
MESA_load_profile_int_def(filepath,(char*)DELIVER_CONF_MODE,(char*)"mtu",&(g_deliver_sendinfo.mtu),DELIVER_DEFAULT_MTU);
|
|
|
|
MESA_load_profile_int_def(filepath,(char*)DELIVER_CONF_MODE,(char*)"mtu",&(g_deliver_globle_info.sendinfo.mtu),DELIVER_DEFAULT_MTU);
|
|
|
|
MESA_load_profile_int_def(filepath,(char*)DELIVER_CONF_MODE,(char*)"receiver_num",&(g_deliver_sendinfo.receiver_num),1);
|
|
|
|
MESA_load_profile_int_def(filepath,(char*)DELIVER_CONF_MODE,(char*)"receiver_num",&(g_deliver_globle_info.sendinfo.receiver_num),1);
|
|
|
|
MESA_load_profile_string_nodef(filepath,(char*)DELIVER_CONF_MODE,(char*)"senddevice",g_deliver_sendinfo.senddevice,DELIVER_CARDNAME_LEN);
|
|
|
|
MESA_load_profile_string_nodef(filepath,(char*)DELIVER_CONF_MODE,(char*)"senddevice",g_deliver_globle_info.sendinfo.senddevice,DELIVER_CARDNAME_LEN);
|
|
|
|
|
|
|
|
|
|
|
|
g_deliver_sendinfo.receiver_info=(struct deliver_recver_info*)malloc(g_deliver_sendinfo.receiver_num*sizeof(struct deliver_recver_info));
|
|
|
|
g_deliver_globle_info.sendinfo.receiver_info=(struct deliver_recver_info*)malloc(g_deliver_globle_info.sendinfo.receiver_num*sizeof(struct deliver_recver_info));
|
|
|
|
for(i=1;i<=g_deliver_sendinfo.receiver_num;i++)
|
|
|
|
for(i=1;i<=g_deliver_globle_info.sendinfo.receiver_num;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
memset(mac_addr_str,0,DELIVER_MACADDR_STR_LEN);
|
|
|
|
memset(mac_addr_str,0,DELIVER_MACADDR_STR_LEN);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -624,7 +625,7 @@ int deliver_profile_init(const char* filepath,int* logger_level,char* logger_fil
|
|
|
|
|
|
|
|
|
|
|
|
MESA_load_profile_string_nodef(filepath,(char*)DELIVER_CONF_MODE,(char*)receiver_mac_name,(char*)mac_addr_str,DELIVER_MACADDR_STR_LEN);
|
|
|
|
MESA_load_profile_string_nodef(filepath,(char*)DELIVER_CONF_MODE,(char*)receiver_mac_name,(char*)mac_addr_str,DELIVER_MACADDR_STR_LEN);
|
|
|
|
|
|
|
|
|
|
|
|
if(deliver_mac_pton(mac_addr_str, ':', (char *)(g_deliver_sendinfo.receiver_info[i-1].dst_macaddr)) < 0)
|
|
|
|
if(deliver_mac_pton(mac_addr_str, ':', (char *)(g_deliver_globle_info.sendinfo.receiver_info[i-1].dst_macaddr)) < 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("error, receiver %d mac:%s is not correct, for example:00:11:22:33:44:55\n", i,mac_addr_str);
|
|
|
|
printf("error, receiver %d mac:%s is not correct, for example:00:11:22:33:44:55\n", i,mac_addr_str);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
@@ -639,8 +640,8 @@ int deliver_socket_error(int n)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for(int i=0;i<n;i++)
|
|
|
|
for(int i=0;i<n;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
close(g_deliver_sendinfo.send_socket[i]);
|
|
|
|
close(g_deliver_globle_info.sendinfo.send_socket[i]);
|
|
|
|
g_deliver_sendinfo.send_socket[i]=0;
|
|
|
|
g_deliver_globle_info.sendinfo.send_socket[i]=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
@@ -655,22 +656,22 @@ int deliver_init_log()
|
|
|
|
|
|
|
|
|
|
|
|
for(j = 0; j < 6; j++)
|
|
|
|
for(j = 0; j < 6; j++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sprintf(mac_str+3*j, "%02x:", (unsigned char)g_deliver_sendinfo.src_macaddr[j]);
|
|
|
|
sprintf(mac_str+3*j, "%02x:", (unsigned char)g_deliver_globle_info.sendinfo.src_macaddr[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mac_str[DELIVER_MACADDR_STR_LEN]=0;
|
|
|
|
mac_str[DELIVER_MACADDR_STR_LEN]=0;
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,RLOG_LV_FATAL,DELIVER_MODULE_INIT,"mtu:%d,receiver_num:%d,senddevice:%s,mac:%s",
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,RLOG_LV_FATAL,DELIVER_MODULE_INIT,"mtu:%d,receiver_num:%d,senddevice:%s,mac:%s",
|
|
|
|
g_deliver_sendinfo.mtu,g_deliver_sendinfo.receiver_num,g_deliver_sendinfo.senddevice,mac_str);
|
|
|
|
g_deliver_globle_info.sendinfo.mtu,g_deliver_globle_info.sendinfo.receiver_num,g_deliver_globle_info.sendinfo.senddevice,mac_str);
|
|
|
|
|
|
|
|
|
|
|
|
for(i=0;i<g_deliver_sendinfo.receiver_num;i++)
|
|
|
|
for(i=0;i<g_deliver_globle_info.sendinfo.receiver_num;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
for(j = 0; j < 6; j++)
|
|
|
|
for(j = 0; j < 6; j++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sprintf(mac_str+3*j, "%02x:", (unsigned char)g_deliver_sendinfo.receiver_info[i].dst_macaddr[j]);
|
|
|
|
sprintf(mac_str+3*j, "%02x:", (unsigned char)g_deliver_globle_info.sendinfo.receiver_info[i].dst_macaddr[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mac_str[DELIVER_MACADDR_STR_LEN]=0;
|
|
|
|
mac_str[DELIVER_MACADDR_STR_LEN]=0;
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,RLOG_LV_FATAL,DELIVER_MODULE_INIT,"reveiver_mac:%s",mac_str);
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,RLOG_LV_FATAL,DELIVER_MODULE_INIT,"reveiver_mac:%s",mac_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
@@ -680,38 +681,53 @@ int deliver_init_log()
|
|
|
|
int mirror_stream_init(int thread_num, const char* filepath)
|
|
|
|
int mirror_stream_init(int thread_num, const char* filepath)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i=0;
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
int flag=0;
|
|
|
|
int logger_level;
|
|
|
|
int logger_level;
|
|
|
|
char logger_filepath[DELIVER_CONF_MAXLEN]={0};
|
|
|
|
char logger_filepath[DELIVER_CONF_MAXLEN]={0};
|
|
|
|
|
|
|
|
|
|
|
|
pthread_t pid_deliver_filestat2;
|
|
|
|
pthread_t pid_deliver_filestat2;
|
|
|
|
|
|
|
|
|
|
|
|
g_deliver_comminfo.threadnum=thread_num;
|
|
|
|
g_deliver_globle_info.comminfo.threadnum=thread_num;
|
|
|
|
|
|
|
|
g_deliver_globle_info.fs2_name[FS2_COLUME_RECVPKT] = (char*)"RECV_PKTS";
|
|
|
|
|
|
|
|
g_deliver_globle_info.fs2_name[FS2_COLUME_RECVBYTE] = (char*)"RECV_BYTES";
|
|
|
|
|
|
|
|
g_deliver_globle_info.fs2_name[FS2_COLUME_SENDPKT] = (char*)"SEND_PKTS";
|
|
|
|
|
|
|
|
g_deliver_globle_info.fs2_name[FS2_COLUME_SENDBYTE] = (char*)"SEND_BYTES";
|
|
|
|
|
|
|
|
g_deliver_globle_info.fs2_name[FS2_COLUME_ERROR] = (char*)"ERROR_PKTS";
|
|
|
|
|
|
|
|
|
|
|
|
//profile
|
|
|
|
//profile
|
|
|
|
deliver_profile_init(filepath,&logger_level,logger_filepath);
|
|
|
|
deliver_profile_init(filepath,&logger_level,logger_filepath);
|
|
|
|
|
|
|
|
|
|
|
|
//init runtime log
|
|
|
|
//init runtime log
|
|
|
|
g_deliver_comminfo.logger=MESA_create_runtime_log_handle(logger_filepath,logger_level);
|
|
|
|
g_deliver_globle_info.comminfo.logger=MESA_create_runtime_log_handle(logger_filepath,logger_level);
|
|
|
|
if(g_deliver_comminfo.logger==NULL)
|
|
|
|
if(g_deliver_globle_info.comminfo.logger==NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("MESA_create_runtime_log_handle() error!exit...\n");
|
|
|
|
printf("MESA_create_runtime_log_handle() error!exit...\n");
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//socket init
|
|
|
|
//socket init
|
|
|
|
g_deliver_sendinfo.thread_num=thread_num;
|
|
|
|
g_deliver_globle_info.sendinfo.thread_num=thread_num;
|
|
|
|
g_deliver_sendinfo.send_socket=(int*)malloc(g_deliver_sendinfo.thread_num*sizeof(int));
|
|
|
|
g_deliver_globle_info.sendinfo.send_socket=(int*)malloc(g_deliver_globle_info.sendinfo.thread_num*sizeof(int));
|
|
|
|
for(i=0;i<g_deliver_sendinfo.thread_num;i++)
|
|
|
|
for(i=0;i<g_deliver_globle_info.sendinfo.thread_num;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
g_deliver_sendbuf[i] = (unsigned char*)malloc(g_deliver_sendinfo.mtu);
|
|
|
|
g_deliver_globle_info.sendbuf[i] = (unsigned char*)malloc(g_deliver_globle_info.sendinfo.mtu);
|
|
|
|
|
|
|
|
|
|
|
|
g_deliver_sendinfo.send_socket[i]=socket(AF_PACKET,SOCK_RAW,htons(ETH_P_IP));
|
|
|
|
g_deliver_globle_info.sendinfo.send_socket[i]=socket(AF_PACKET,SOCK_RAW,htons(ETH_P_IP));
|
|
|
|
if((g_deliver_sendinfo.send_socket[i]<0) ||(g_deliver_sendbuf[i]==NULL))
|
|
|
|
if((g_deliver_globle_info.sendinfo.send_socket[i]<0) ||(g_deliver_globle_info.sendbuf[i]==NULL))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
deliver_socket_error(i);
|
|
|
|
deliver_socket_error(i);
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger, RLOG_LV_FATAL,DELIVER_MODULE_INIT,"ipv4_raw_socket error,i:%d",i);
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger, RLOG_LV_FATAL,DELIVER_MODULE_INIT,"ipv4_raw_socket error,i:%d",i);
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flag= fcntl(g_deliver_globle_info.sendinfo.send_socket[i], F_GETFL, 0);
|
|
|
|
|
|
|
|
if(flag<0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger, RLOG_LV_FATAL,DELIVER_MODULE_INIT,"fcntl():getfl error,errno is:%d,%s",errno,strerror(errno));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fcntl( g_deliver_globle_info.sendinfo.send_socket[i], F_SETFL, flag|O_NONBLOCK ) < 0 )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger, RLOG_LV_FATAL,DELIVER_MODULE_INIT,"fcntl():setfl error,errno is:%d,%s",errno,strerror(errno));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pthread_create(&pid_deliver_filestat2,NULL,deliver_filestat2,(void*)filepath);
|
|
|
|
pthread_create(&pid_deliver_filestat2,NULL,deliver_filestat2,(void*)filepath);
|
|
|
|
@@ -720,7 +736,7 @@ int mirror_stream_init(int thread_num, const char* filepath)
|
|
|
|
|
|
|
|
|
|
|
|
deliver_init_log();
|
|
|
|
deliver_init_log();
|
|
|
|
|
|
|
|
|
|
|
|
MESA_handle_runtime_log(g_deliver_comminfo.logger,RLOG_LV_FATAL,DELIVER_MODULE_INIT,"thread_num:%d,filepath:%s,deliver.so init sucess!",thread_num,filepath);
|
|
|
|
MESA_handle_runtime_log(g_deliver_globle_info.comminfo.logger,RLOG_LV_FATAL,DELIVER_MODULE_INIT,"thread_num:%d,filepath:%s,deliver.so init sucess!",thread_num,filepath);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|