1、thread_num通过tfe_proxy_get_work_thread_count()函数获得;2、每个数据包TCP负载最大长度有MTU更改为mtu-sizeof(struct mesa_tcp_hdr) - sizeof(struct mesa_ip4_hdr);

This commit is contained in:
liuyang
2018-12-12 16:40:04 +08:00
parent 6339d74779
commit 0e23a077dd
2 changed files with 23 additions and 12 deletions

View File

@@ -1,32 +1,32 @@
#include "mirror_stream.h"
#include <tfe_stream.h>
#include <tfe_utils.h>
#include <tfe_plugin.h>
#include <assert.h>
extern unsigned int tfe_proxy_get_work_thread_count(void);
int decrypt_mirror_init(struct tfe_proxy * proxy)
{
const char* filepath="./conf/tfe/decrypt_mirror.conf";
int thread_num=2;
UNUSED int ret=0;//todo: aquire from proxy;
int ret=0;
int thread_num = tfe_proxy_get_work_thread_count();
ret=mirror_stream_init(thread_num, filepath);
// assert(ret==0);
return 0;
return ret;
}
int decrypt_mirror_on_open_cb(const struct tfe_stream * stream, unsigned int thread_id,
enum tfe_conn_dir dir, void ** pme)
{
UNUSED int ret=0;
int ret=0;
ret=mirror_stream_open(thread_id, stream->addr, pme);
// assert(ret==0);
return 0;
return ret;
}
enum tfe_stream_action decrypt_mirror_on_data_cb(const struct tfe_stream * stream, unsigned int thread_id,
enum tfe_conn_dir dir, const unsigned char * data, size_t len, void ** pme)
{
UNUSED int ret=0;
int ret=0;
ret=mirror_stream_write(dir, data,len, pme, thread_id);
return ACTION_FORWARD_DATA;
}

View File

@@ -553,7 +553,9 @@ int mirror_stream_write(int cur_dir,const unsigned char * data, size_t len, void
const unsigned char* payload=data;
int payload_len=0;
int remain_len=len;
int pkt_num=(len/(g_deliver_globle_info.sendinfo.mtu))+1;
int max_payloadlen_per=0;
int pkt_num=0;
// int pkt_num=(len/(g_deliver_globle_info.sendinfo.mtu))+1;
struct deliver_pme_info* pmeinfo=(struct deliver_pme_info*)*pme;
@@ -565,21 +567,30 @@ int mirror_stream_write(int cur_dir,const unsigned char * data, size_t len, void
if(pmeinfo->addr_info->addrtype==TFE_ADDR_STREAM_TUPLE4_V4)
{
deliver_debug_log_v4(RLOG_LV_DEBUG,(char*)DELIVER_RECVPKT_DEBUG,pmeinfo,DELIVER_FLAG_RECVPKT,len);
max_payloadlen_per=g_deliver_globle_info.sendinfo.mtu-sizeof(struct mesa_tcp_hdr)-sizeof(struct mesa_ip4_hdr);
}
else if(pmeinfo->addr_info->addrtype==TFE_ADDR_STREAM_TUPLE4_V6)
{
deliver_debug_log_v6(RLOG_LV_DEBUG,(char*)DELIVER_RECVPKT_DEBUG,pmeinfo,DELIVER_FLAG_RECVPKT,len);
max_payloadlen_per=g_deliver_globle_info.sendinfo.mtu-sizeof(struct mesa_tcp_hdr)-sizeof(struct mesa_ip6_hdr);
}
else
{
//TODO
}
pkt_num=(len/(max_payloadlen_per))+1;
for(i=0;i<pkt_num;i++)
{
/*
payload_len=remain_len<(g_deliver_globle_info.sendinfo.mtu)?remain_len:(g_deliver_globle_info.sendinfo.mtu);
payload=data+(len-remain_len);
remain_len-=g_deliver_globle_info.sendinfo.mtu;
*/
payload_len=remain_len<max_payloadlen_per?remain_len:max_payloadlen_per;
payload=data+(len-remain_len);
remain_len-=max_payloadlen_per;
deliver_set_pktinfo(pmeinfo,TH_ACK,cur_dir,payload_len);
if(pmeinfo->addr_info->addrtype==TFE_ADDR_STREAM_TUPLE4_V4)
@@ -760,7 +771,7 @@ int mirror_stream_init(int thread_num, const char* filepath)
g_deliver_globle_info.sendinfo.send_socket=(int*)malloc(g_deliver_globle_info.sendinfo.thread_num*sizeof(int));
for(i=0;i<g_deliver_globle_info.sendinfo.thread_num;i++)
{
g_deliver_globle_info.sendbuf[i] = (unsigned char*)malloc(g_deliver_globle_info.sendinfo.mtu);
g_deliver_globle_info.sendbuf[i] = (unsigned char*)malloc(g_deliver_globle_info.sendinfo.mtu + sizeof(struct mesa_ethernet_hdr));
g_deliver_globle_info.sendinfo.send_socket[i]=socket(AF_PACKET,SOCK_RAW,htons(ETH_P_IP));
if((g_deliver_globle_info.sendinfo.send_socket[i]<0) ||(g_deliver_globle_info.sendbuf[i]==NULL))