summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuyang <[email protected]>2018-12-12 16:40:04 +0800
committerliuyang <[email protected]>2018-12-12 16:40:04 +0800
commit0e23a077ddf417fc0656c84b959630323a90e9c8 (patch)
tree22e1abccd583bdc944c7861ce6651be9cd2d866c
parent6339d74779946b5efe1142f11ae606579fe3d38e (diff)
1、thread_num通过tfe_proxy_get_work_thread_count()函数获得;2、每个数据包TCP负载最大长度有MTU更改为mtu-sizeof(struct mesa_tcp_hdr) - sizeof(struct mesa_ip4_hdr);
-rw-r--r--plugin/business/decrypt-mirroring/src/decrypt_mirror_plugin.cpp18
-rw-r--r--plugin/business/decrypt-mirroring/src/mirror_stream.cpp17
2 files changed, 23 insertions, 12 deletions
diff --git a/plugin/business/decrypt-mirroring/src/decrypt_mirror_plugin.cpp b/plugin/business/decrypt-mirroring/src/decrypt_mirror_plugin.cpp
index 481c9c1..697c091 100644
--- a/plugin/business/decrypt-mirroring/src/decrypt_mirror_plugin.cpp
+++ b/plugin/business/decrypt-mirroring/src/decrypt_mirror_plugin.cpp
@@ -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;
}
diff --git a/plugin/business/decrypt-mirroring/src/mirror_stream.cpp b/plugin/business/decrypt-mirroring/src/mirror_stream.cpp
index 6533d39..ba89855 100644
--- a/plugin/business/decrypt-mirroring/src/mirror_stream.cpp
+++ b/plugin/business/decrypt-mirroring/src/mirror_stream.cpp
@@ -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,22 +567,31 @@ 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))