适配tfe_stream_addr;为了编译通过,注释mirror_stream.cpp中的代码;
This commit is contained in:
@@ -42,7 +42,7 @@ struct tfe_conn
|
||||
|
||||
struct tfe_stream
|
||||
{
|
||||
struct layer_addr addr;
|
||||
struct tfe_stream_addr* addr;
|
||||
enum tfe_stream_proto proto;
|
||||
struct tfe_conn upstream;
|
||||
struct tfe_conn downstream;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
add_library(decrypt-mirroring src/deliver.cpp src/sendpkt.cpp)
|
||||
add_library(decrypt-mirroring src/decrypt_mirror_plugin.cpp src/mirror_stream.cpp src/sendpkt.cpp)
|
||||
target_include_directories(decrypt-mirroring PRIVATE include/internal)
|
||||
target_include_directories(decrypt-mirroring PUBLIC include/external)
|
||||
target_link_libraries(decrypt-mirroring common)
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
#include <tfe_stream.h>
|
||||
|
||||
int decrypt_mirror_init(void *proxy);
|
||||
|
||||
enum tfe_stream_action decrypt_mirror_on_open_cb(const struct tfe_stream * stream, unsigned int thread_id,
|
||||
enum tfe_conn_dir dir, const unsigned char * data, size_t len, void ** pme);
|
||||
|
||||
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);
|
||||
|
||||
void decrypt_mirror_on_close_cb(const struct tfe_stream * stream, unsigned int thread_id,
|
||||
enum tfe_stream_close_reason reason, void ** pme);
|
||||
void decrypt_mirror_deinit(void);
|
||||
|
||||
@@ -41,7 +41,7 @@ Return:
|
||||
0:succes
|
||||
<0:error
|
||||
***************************************************************************/
|
||||
int mirror_stream_open(struct origin_stream_addr* addr,void** pme);
|
||||
int mirror_stream_open(int thread_id, const struct tfe_stream_addr* addr,void** pme);
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ Return:
|
||||
0:succes
|
||||
<0:error
|
||||
***************************************************************************/
|
||||
int mirror_stream_write(enum tfe_conn_dir cur_dir,const unsigned char * data, size_t len, void** pme,int thread_seq);
|
||||
int mirror_stream_write(int cur_dir,const unsigned char * data, size_t len, void** pme,int thread_id);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ struct deliver_comm_info
|
||||
|
||||
struct deliver_pkt_info
|
||||
{
|
||||
enum tfe_conn_dir dir;
|
||||
int dir;
|
||||
unsigned int seq; //host order
|
||||
unsigned int ack; //host order
|
||||
unsigned int len; //host order,tcp payload len
|
||||
@@ -99,7 +99,7 @@ struct deliver_session_info
|
||||
struct deliver_pme_info
|
||||
{
|
||||
unsigned char dst_macaddr[DELIVER_MACADDR_LEN];
|
||||
struct origin_stream_addr addr_info;
|
||||
struct tfe_stream_addr* addr_info;
|
||||
struct deliver_pkt_info pkt_info;
|
||||
struct deliver_session_info session_info;
|
||||
};
|
||||
|
||||
@@ -1,41 +1,53 @@
|
||||
#include "mirror_stream.h"
|
||||
#include <tfe_stream.h>
|
||||
#include <tfe_plugin.h>
|
||||
#include <assert.h>
|
||||
|
||||
int decrypt_mirror_init(void *proxy)
|
||||
int decrypt_mirror_init(struct tfe_proxy * proxy)
|
||||
{
|
||||
const char* filepath="./conf/decrypt_mirror.conf";
|
||||
int thread_num=2;//todo: aquire from proxy;
|
||||
int mirro_stream_init(thread_num, filepath);
|
||||
int thread_num=2, ret=0;//todo: aquire from proxy;
|
||||
ret=mirror_stream_init(thread_num, filepath);
|
||||
assert(ret==0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum tfe_stream_action decrypt_mirror_on_open_cb(const struct tfe_stream * stream, unsigned int thread_id,
|
||||
enum tfe_conn_dir dir, const unsigned char * data, size_t len, void ** pme)
|
||||
int decrypt_mirror_on_open_cb(const struct tfe_stream * stream, unsigned int thread_id,
|
||||
enum tfe_conn_dir dir, void ** pme)
|
||||
{
|
||||
struct layer_addr* addr=NULL; //=stream->addr;
|
||||
int ret=0;
|
||||
ret=mirror_stream_open(thread_id, addr, pme);
|
||||
ret=mirror_stream_open(thread_id, stream->addr, pme);
|
||||
assert(ret==0);
|
||||
return ACTION_FORWARD_DATA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int ret=0;
|
||||
ret=mirror_stream_write(thread_id, data,len, pme, thread_id);
|
||||
ret=mirror_stream_write(dir, data,len, pme, thread_id);
|
||||
return ACTION_FORWARD_DATA;
|
||||
}
|
||||
|
||||
void decrypt_mirror_on_close_cb(const struct tfe_stream * stream, unsigned int thread_id,
|
||||
enum tfe_stream_close_reason reason, void ** pme)
|
||||
{
|
||||
int ret=0;
|
||||
ret=mirror_stream_close(pme, thread_id);
|
||||
mirror_stream_close(pme, thread_id);
|
||||
return;
|
||||
}
|
||||
void decrypt_mirror_deinit(void)
|
||||
void decrypt_mirror_deinit(struct tfe_proxy * proxy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
struct tfe_plugin decrypt_mirror_spec={
|
||||
.symbol=NULL,
|
||||
.type = TFE_PLUGIN_TYPE_BUSINESS,
|
||||
.proto = APP_PROTO_HTTP1, //???
|
||||
.on_init = decrypt_mirror_init,
|
||||
.on_deinit = decrypt_mirror_deinit,
|
||||
.on_open = decrypt_mirror_on_open_cb,
|
||||
.on_data = decrypt_mirror_on_data_cb,
|
||||
.on_close = decrypt_mirror_on_close_cb};
|
||||
TFE_PLUGIN_REGISTER(decrypt_mirror,decrypt_mirror_spec)
|
||||
|
||||
|
||||
|
||||
@@ -128,6 +128,7 @@ int deliver_debug_log_v6(int level,char* module,struct deliver_pme_info* pmeinfo
|
||||
{
|
||||
struct deliver_session_info* session_info=&(pmeinfo->session_info);
|
||||
struct deliver_pkt_info* pkt_info=&(pmeinfo->pkt_info);
|
||||
#if 0
|
||||
struct sockaddr_in6* client_addr=(struct sockaddr_in6*)&(pmeinfo->addr_info.client);
|
||||
struct sockaddr_in6* server_addr=(struct sockaddr_in6*)&(pmeinfo->addr_info.server);
|
||||
|
||||
@@ -157,6 +158,7 @@ int deliver_debug_log_v6(int level,char* module,struct deliver_pme_info* pmeinfo
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -166,6 +168,7 @@ int deliver_debug_log_v4(int level,char* module,struct deliver_pme_info* pmeinfo
|
||||
{
|
||||
struct deliver_session_info* session_info=&(pmeinfo->session_info);
|
||||
struct deliver_pkt_info* pkt_info=&(pmeinfo->pkt_info);
|
||||
#if 0
|
||||
struct sockaddr_in* client_addr=(struct sockaddr_in*)&(pmeinfo->addr_info.client);
|
||||
struct sockaddr_in* server_addr=(struct sockaddr_in*)&(pmeinfo->addr_info.server);
|
||||
|
||||
@@ -194,7 +197,7 @@ int deliver_debug_log_v4(int level,char* module,struct deliver_pme_info* pmeinfo
|
||||
session_info->send_pkt,session_info->recv_byte);
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -240,7 +243,7 @@ int deliver_sendpkt_ether(int thread_seq,int buflen,unsigned char* buf,unsigned
|
||||
}
|
||||
|
||||
|
||||
int deliver_init_pmeinfo(struct origin_stream_addr* addr,void** pme)
|
||||
int deliver_init_pmeinfo(const struct tfe_stream_addr* addr,void** pme)
|
||||
{
|
||||
//TODO:choose dst mac
|
||||
int i=deliver_rand()%(g_deliver_sendinfo.receiver_num);
|
||||
@@ -256,11 +259,11 @@ int deliver_init_pmeinfo(struct origin_stream_addr* addr,void** pme)
|
||||
}
|
||||
|
||||
|
||||
int deliver_send_v6(int thread_seq,struct deliver_pme_info* pmeinfo,int payload_len,char* payload)
|
||||
int deliver_send_v6(int thread_seq,struct deliver_pme_info* pmeinfo,int payload_len,const unsigned char* payload)
|
||||
{
|
||||
int offset = 0;
|
||||
unsigned short eth_type=0x0800;
|
||||
|
||||
#if 0
|
||||
struct sockaddr_in6* client_addr=NULL;
|
||||
struct sockaddr_in6* server_addr=NULL;
|
||||
|
||||
@@ -307,18 +310,18 @@ int deliver_send_v6(int thread_seq,struct deliver_pme_info* pmeinfo,int payload_
|
||||
pmeinfo->session_info.send_byte+=payload_len;
|
||||
|
||||
deliver_debug_log_v6(RLOG_LV_DEBUG,(char*)DELIVER_SENDPKT_DEBUG,pmeinfo,DELIVER_FLAG_SENDPKT,0);
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int deliver_send_v4(int thread_seq,struct deliver_pme_info* pmeinfo,int payload_len,char* payload)
|
||||
int deliver_send_v4(int thread_seq,struct deliver_pme_info* pmeinfo,int payload_len,const unsigned char* payload)
|
||||
{
|
||||
int offset = 0;
|
||||
unsigned short eth_type=0x0800;
|
||||
|
||||
#if 0
|
||||
struct sockaddr_in* client_addr=NULL;
|
||||
struct sockaddr_in* server_addr=NULL;
|
||||
|
||||
@@ -365,7 +368,7 @@ int deliver_send_v4(int thread_seq,struct deliver_pme_info* pmeinfo,int payload_
|
||||
pmeinfo->session_info.send_byte+=payload_len;
|
||||
|
||||
deliver_debug_log_v4(RLOG_LV_DEBUG,(char*)DELIVER_SENDPKT_DEBUG,pmeinfo,DELIVER_FLAG_SENDPKT,0);
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -381,8 +384,7 @@ int deliver_send_syn(int thread_seq,struct deliver_pme_info* pmeinfo)
|
||||
pmeinfo->pkt_info.win = deliver_rand_range(1460, 65500);
|
||||
pmeinfo->pkt_info.ipid = deliver_rand() % 65535;
|
||||
pmeinfo->pkt_info.ttl=deliver_rand_range(32,65);
|
||||
|
||||
if(pmeinfo->addr_info.client.sa_family==AF_INET)
|
||||
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
||||
{
|
||||
deliver_send_v4(thread_seq,pmeinfo,0,NULL);
|
||||
deliver_debug_log_v4(RLOG_LV_INFO,(char*)DELIVER_SENDPKT_START,pmeinfo,DELIVER_FLAG_SENDPKT,0);
|
||||
@@ -404,8 +406,7 @@ int deliver_send_syn_ack(int thread_seq,struct deliver_pme_info* pmeinfo)
|
||||
pmeinfo->pkt_info.seq= deliver_rand();
|
||||
pmeinfo->pkt_info.flag=TH_SYN|TH_ACK;
|
||||
|
||||
|
||||
if(pmeinfo->addr_info.client.sa_family==AF_INET)
|
||||
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
||||
{
|
||||
deliver_send_v4(thread_seq,pmeinfo,0,NULL);
|
||||
}
|
||||
@@ -430,7 +431,7 @@ int deliver_send_ack(int thread_seq,struct deliver_pme_info* pmeinfo)
|
||||
pmeinfo->pkt_info.flag=TH_ACK;
|
||||
|
||||
|
||||
if(pmeinfo->addr_info.client.sa_family==AF_INET)
|
||||
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
||||
{
|
||||
deliver_send_v4(thread_seq,pmeinfo,0,NULL);
|
||||
}
|
||||
@@ -443,7 +444,7 @@ int deliver_send_ack(int thread_seq,struct deliver_pme_info* pmeinfo)
|
||||
}
|
||||
|
||||
|
||||
int deliver_set_pktinfo(struct deliver_pme_info* pmeinfo,int flag,enum tfe_conn_dir cur_dir,int payload_len)
|
||||
int deliver_set_pktinfo(struct deliver_pme_info* pmeinfo,int flag, int cur_dir,int payload_len)
|
||||
{
|
||||
struct deliver_pkt_info last_pkt_info;
|
||||
memcpy((void*)&last_pkt_info,(void*)&(pmeinfo->pkt_info),sizeof(struct deliver_pkt_info));
|
||||
@@ -471,7 +472,7 @@ int deliver_set_pktinfo(struct deliver_pme_info* pmeinfo,int flag,enum tfe_conn_
|
||||
int deliver_send_rst(int thread_seq,struct deliver_pme_info* pmeinfo)
|
||||
{
|
||||
deliver_set_pktinfo(pmeinfo,TH_RST,DELIVER_DIR_C2S,0);
|
||||
if(pmeinfo->addr_info.client.sa_family==AF_INET)
|
||||
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
||||
{
|
||||
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);
|
||||
if(pmeinfo->addr_info.client.sa_family==AF_INET)
|
||||
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
||||
{
|
||||
deliver_send_v4(thread_seq,pmeinfo,0,NULL);
|
||||
deliver_debug_log_v4(RLOG_LV_INFO,(char*)DELIVER_SENDPKT_END,pmeinfo,DELIVER_FLAG_ENT,0);
|
||||
@@ -498,37 +499,37 @@ int deliver_send_rst(int thread_seq,struct deliver_pme_info* pmeinfo)
|
||||
|
||||
|
||||
|
||||
int mirror_stream_open(int thread_seq,struct origin_stream_addr* addr,void** pme)
|
||||
int mirror_stream_open(int thread_id, const struct tfe_stream_addr* addr,void** pme)
|
||||
{
|
||||
struct deliver_pme_info* pmeinfo=NULL;
|
||||
|
||||
deliver_init_pmeinfo(addr,pme);
|
||||
pmeinfo=(struct deliver_pme_info*)*pme;
|
||||
|
||||
deliver_send_syn(thread_seq,pmeinfo);
|
||||
deliver_send_syn_ack(thread_seq,pmeinfo);
|
||||
deliver_send_ack(thread_seq,pmeinfo);
|
||||
deliver_send_syn(thread_id,pmeinfo);
|
||||
deliver_send_syn_ack(thread_id,pmeinfo);
|
||||
deliver_send_ack(thread_id,pmeinfo);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int mirror_stream_write(enum tfe_conn_dir cur_dir,const unsigned char * data, size_t len, void** pme,int thread_seq)
|
||||
int mirror_stream_write(int cur_dir,const unsigned char * data, size_t len, void** pme,int thread_id)
|
||||
{
|
||||
int i=0;
|
||||
char* payload=data;
|
||||
const unsigned char* payload=data;
|
||||
int payload_len=0;
|
||||
int remain_len=len;
|
||||
int pkt_num=(len/(g_deliver_sendinfo.mtu))+1;
|
||||
struct deliver_pme_info* pmeinfo=(struct deliver_pme_info*)*pme;
|
||||
|
||||
|
||||
deliver_set_filestate2(thread_seq,FS2_COLUME_RECVPKT,1);
|
||||
deliver_set_filestate2(thread_seq,FS2_COLUME_RECVBYTE,len);
|
||||
deliver_set_filestate2(thread_id,FS2_COLUME_RECVPKT,1);
|
||||
deliver_set_filestate2(thread_id,FS2_COLUME_RECVBYTE,len);
|
||||
|
||||
pmeinfo->session_info.recv_pkt++;
|
||||
pmeinfo->session_info.recv_byte+=len;
|
||||
if(pmeinfo->addr_info.client.sa_family==AF_INET)
|
||||
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
||||
{
|
||||
deliver_debug_log_v4(RLOG_LV_DEBUG,(char*)DELIVER_RECVPKT_DEBUG,pmeinfo,DELIVER_FLAG_RECVPKT,len);
|
||||
}
|
||||
@@ -544,13 +545,13 @@ int mirror_stream_write(enum tfe_conn_dir cur_dir,const unsigned char * data, si
|
||||
remain_len-=g_deliver_sendinfo.mtu;
|
||||
|
||||
deliver_set_pktinfo(pmeinfo,TH_ACK,cur_dir,payload_len);
|
||||
if(pmeinfo->addr_info.client.sa_family==AF_INET)
|
||||
if(pmeinfo->addr_info->addrtype==ADDR_TYPE_IPV4)
|
||||
{
|
||||
deliver_send_v4(thread_seq,pmeinfo,payload_len,payload);
|
||||
deliver_send_v4(thread_id,pmeinfo,payload_len,payload);
|
||||
}
|
||||
else
|
||||
{
|
||||
deliver_send_v6(thread_seq,pmeinfo,payload_len,payload);
|
||||
deliver_send_v6(thread_id,pmeinfo,payload_len,payload);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user