diff options
| author | 杨威 <[email protected]> | 2023-02-02 17:26:24 +0800 |
|---|---|---|
| committer | 杨威 <[email protected]> | 2023-02-08 18:43:04 +0800 |
| commit | b692f67a1db697f0150c65978d3b63c99e8971aa (patch) | |
| tree | 2ff3a3dec8ea879af7f360932f7d30c04ab3b165 | |
| parent | fcbeedf9d724ebab0e7f87f3310a23e2d403192e (diff) | |
🐞 fix(get raw meta): 修复传入的meta长度为0的bug
| -rw-r--r-- | include/private/packet_io.h | 4 | ||||
| -rw-r--r-- | include/private/packet_io_internal.h | 8 | ||||
| -rw-r--r-- | src/dealpkt/deal_udp.c | 2 | ||||
| -rw-r--r-- | src/dealpkt/stream_manage.c | 12 | ||||
| -rw-r--r-- | src/packet_io/packet_io_hook.c | 11 | ||||
| -rw-r--r-- | src/packet_io/packet_io_marsio.c | 38 | ||||
| -rw-r--r-- | src/packet_io/packet_io_pcap.c | 4 | ||||
| -rw-r--r-- | test/test_app_sapp.c | 111 |
8 files changed, 115 insertions, 75 deletions
diff --git a/include/private/packet_io.h b/include/private/packet_io.h index 8f6dd8e..ec8f23c 100644 --- a/include/private/packet_io.h +++ b/include/private/packet_io.h @@ -118,8 +118,8 @@ typedef struct{ int (*dl_io_smart_offload)(int device_index, unsigned char *pkt_ptr, int pkt_len, unsigned char dir, int thread_num);
int (*dl_io_forward_rawpkt)(const raw_pkt_t *raw_pkt, int thread_seq);
void (*dl_io_free_rawpkt)(const raw_pkt_t *raw_pkt, int thread_seq);
- struct rawpkt_metadata *(*dl_io_get1_rawpkt_meta)(const raw_pkt_t *raw_pkt);
- void (*dl_io_free_rawpkt_meta)(struct rawpkt_metadata *);
+ struct rawpkt_metadata *(*dl_io_get1_rawpkt_meta)(const raw_pkt_t *raw_pkt, int thread_seq);
+ void (*dl_io_free_rawpkt_meta)(struct rawpkt_metadata *, int thread_seq);
}dl_io_fun_list_t;
diff --git a/include/private/packet_io_internal.h b/include/private/packet_io_internal.h index 8cab102..bc8e214 100644 --- a/include/private/packet_io_internal.h +++ b/include/private/packet_io_internal.h @@ -251,8 +251,8 @@ void pcap_dl_io_device_alias_free(unsigned int target_id, char *dev_args); extern int pcap_dl_io_smart_offload(int device_index, unsigned char *pkt_ptr, int pkt_len, unsigned char dir, int thread_num);
extern int pcap_dl_io_forward_rawpkt(const raw_pkt_t *raw_pkt, int thread_seq);
extern void pcap_dl_io_free_rawpkt(const raw_pkt_t *raw_pkt, int thread_seq);
-extern struct rawpkt_metadata *pcap_dl_io_get1_rawpkt_meta(const raw_pkt_t *raw_pkt);
-extern void pcap_dl_io_free_rawpkt_meta(struct rawpkt_metadata *);
+extern struct rawpkt_metadata *pcap_dl_io_get1_rawpkt_meta(const raw_pkt_t *raw_pkt,int thread_seq);
+extern void pcap_dl_io_free_rawpkt_meta(struct rawpkt_metadata *, int thread_seq);
/********************** pcap funcitons for dynamic link ***********************/
@@ -314,8 +314,8 @@ extern void marsio_dl_io_destroy(void); extern int marsio_dl_io_smart_offload(int device_index, unsigned char *pkt_ptr, int pkt_len, unsigned char dir, int thread_num);
extern int marsio_dl_io_forward_rawpkt(const raw_pkt_t *raw_pkt, int thread_seq);
extern void marsio_dl_io_free_rawpkt(const raw_pkt_t *raw_pkt, int thread_seq);
-extern struct rawpkt_metadata *marsio_dl_io_get1_rawpkt_meta(const raw_pkt_t *raw_pkt);
-extern void marsio_dl_io_free_rawpkt_meta(struct rawpkt_metadata *);
+extern struct rawpkt_metadata *marsio_dl_io_get1_rawpkt_meta(const raw_pkt_t *raw_pkt, int thread_seq);
+extern void marsio_dl_io_free_rawpkt_meta(struct rawpkt_metadata *, int thread_seq);
/********************** marsio funcitons for dynamic link *********************/
diff --git a/src/dealpkt/deal_udp.c b/src/dealpkt/deal_udp.c index 31a5e8f..710bd15 100644 --- a/src/dealpkt/deal_udp.c +++ b/src/dealpkt/deal_udp.c @@ -372,7 +372,9 @@ static int udp_reset_stream_bytime(struct streamindex *pindex) stream_process_udp(pstream,NULL,NULL,NULL,&(pdetail_pr->apme),&(pstream->opstate)); project_requirement_destroy(SAPP_MEM_DYN_UDP_PROJECT, threadnum, pstream_pr->pproject); + pstream_pr->pproject=NULL; stream_bridge_destroy_per_stream(SAPP_MEM_DYN_UDP_BRIDGE, pstream, pstream_pr->stream_bridge); + pstream_pr->stream_bridge=NULL; free_polling_inject_context(SAPP_MEM_DYN_UDP_POLLING_RAW_PKT, pstream_pr); //2020-06-08 lijia add, for memory leak if (pstream_pr->sid_append_list) diff --git a/src/dealpkt/stream_manage.c b/src/dealpkt/stream_manage.c index 231e4dc..d0aa173 100644 --- a/src/dealpkt/stream_manage.c +++ b/src/dealpkt/stream_manage.c @@ -2389,12 +2389,12 @@ int update_polling_inject_context(int mem_used_type,struct streaminfo_private *p if((DIR_ROUTE_DOWN & pstream_pr->stream_public.routedir) == DIR_ROUTE_DOWN){ if(NULL == pstream_pr->polling_inject_context->raw_pkt_down){ pstream_pr->polling_inject_context->raw_pkt_down = sapp_raw_pkt_dup(mem_used_type,thread_index, raw_pkt); - pstream_pr->polling_inject_context->meta[1] = dl_io_fun_list.dl_io_get1_rawpkt_meta(raw_pkt); + pstream_pr->polling_inject_context->meta[1] = dl_io_fun_list.dl_io_get1_rawpkt_meta(raw_pkt, thread_index); } }else{ if(NULL == pstream_pr->polling_inject_context->raw_pkt_up){ pstream_pr->polling_inject_context->raw_pkt_up = sapp_raw_pkt_dup(mem_used_type,thread_index, raw_pkt); - pstream_pr->polling_inject_context->meta[0] = dl_io_fun_list.dl_io_get1_rawpkt_meta(raw_pkt); + pstream_pr->polling_inject_context->meta[0] = dl_io_fun_list.dl_io_get1_rawpkt_meta(raw_pkt, thread_index); } } @@ -2420,10 +2420,10 @@ int save_polling_inject_context(int mem_used_type, struct streaminfo_private *ps ����������IJ���������private�ṹ��, ��������ԭʼ�� */ if((DIR_ROUTE_DOWN & pstream_pr->stream_public.routedir) == DIR_ROUTE_DOWN){ pstream_pr->polling_inject_context->raw_pkt_down = sapp_raw_pkt_dup(mem_used_type, thread_index, raw_pkt); - pstream_pr->polling_inject_context->meta[1] = dl_io_fun_list.dl_io_get1_rawpkt_meta(raw_pkt); + pstream_pr->polling_inject_context->meta[1] = dl_io_fun_list.dl_io_get1_rawpkt_meta(raw_pkt, thread_index); }else{ pstream_pr->polling_inject_context->raw_pkt_up = sapp_raw_pkt_dup(mem_used_type, thread_index, raw_pkt); - pstream_pr->polling_inject_context->meta[0] = dl_io_fun_list.dl_io_get1_rawpkt_meta(raw_pkt); + pstream_pr->polling_inject_context->meta[0] = dl_io_fun_list.dl_io_get1_rawpkt_meta(raw_pkt, thread_index); } return 0; @@ -2457,12 +2457,12 @@ void free_polling_inject_context(int mem_used_type, struct streaminfo_private *p if(pstream_pr->polling_inject_context->meta[0]!=NULL) { - dl_io_fun_list.dl_io_free_rawpkt_meta(pstream_pr->polling_inject_context->meta[0]); + dl_io_fun_list.dl_io_free_rawpkt_meta(pstream_pr->polling_inject_context->meta[0], thread_index); pstream_pr->polling_inject_context->meta[0]=NULL; } if(pstream_pr->polling_inject_context->meta[1]!=NULL) { - dl_io_fun_list.dl_io_free_rawpkt_meta(pstream_pr->polling_inject_context->meta[1]); + dl_io_fun_list.dl_io_free_rawpkt_meta(pstream_pr->polling_inject_context->meta[1], thread_index); pstream_pr->polling_inject_context->meta[1]=NULL; } diff --git a/src/packet_io/packet_io_hook.c b/src/packet_io/packet_io_hook.c index 618fbd2..d1b5777 100644 --- a/src/packet_io/packet_io_hook.c +++ b/src/packet_io/packet_io_hook.c @@ -17,7 +17,7 @@ extern "C" { #endif - +extern int marsio_get_route_dir_from_mbuff(void *pkt_reference); extern unsigned int marsio_get_vlan_id_from_mbuff(void *pkt_reference); extern int marsio_set_vlan_id_to_mbuff(void *pkt_reference, unsigned int vlan_id_host_order); extern void marsio_dl_io_set_rawpkt_meta(const raw_pkt_t *raw_pkt, void *send_pkt_io_reference, unsigned char route_dir); @@ -228,6 +228,11 @@ int packet_io_hook_input(raw_pkt_t *raw_pkt, unsigned char dir, int thread_num) }else if(OVERLAY_MODE_NONE == sapp_global_val->config.packet_io.packet_io_tunnel.overlay_mode_bin){ ret = 0; }else if(OVERLAY_MODE_NF == sapp_global_val->config.packet_io.packet_io_tunnel.overlay_mode_bin){ + ret = marsio_get_route_dir_from_mbuff((void *)raw_pkt->io_lib_pkt_reference); + if(ret >= 0) + { + raw_pkt->route_dir = ret; + } ret = 0; }else{ sapp_runtime_log(RLOG_LV_INFO, "packet_io_hook_input() error, unsupport overlay_mode:%d\n", @@ -268,6 +273,8 @@ int packet_io_hook_forward(raw_pkt_t *raw_pkt, unsigned char route_dir, int thre ret = packet_io_hook_output_vxlan(raw_pkt, (void *)raw_pkt->raw_pkt_data, route_dir); }else if(OVERLAY_MODE_NONE == sapp_global_val->config.packet_io.packet_io_tunnel.overlay_mode_bin){ ret = 0; + }else if(OVERLAY_MODE_NF == sapp_global_val->config.packet_io.packet_io_tunnel.overlay_mode_bin){ + ret = 0; }else{ sapp_runtime_log(20, "packet_io_hook_forward() error, unsupport overlay_mode:%d\n", sapp_global_val->config.packet_io.packet_io_tunnel.overlay_mode_bin); } @@ -288,7 +295,7 @@ int packet_io_hook_sendto(const raw_pkt_t *raw_pkt, unsigned char route_dir, cha if(OVERLAY_MODE_VXLAN == sapp_global_val->config.packet_io.packet_io_tunnel.overlay_mode_bin){ ret = packet_io_hook_output_vxlan((raw_pkt_t *)raw_pkt, (void *)send_pkt_data, route_dir); - }else if(OVERLAY_MODE_NONE == sapp_global_val->config.packet_io.packet_io_tunnel.overlay_mode_bin){ + }else if(OVERLAY_MODE_NONE == sapp_global_val->config.packet_io.packet_io_tunnel.overlay_mode_bin || OVERLAY_MODE_NF == sapp_global_val->config.packet_io.packet_io_tunnel.overlay_mode_bin){ ret = 0; }else{ sapp_runtime_log(20, "packet_io_hook_sendto() error, unsupport overlay_mode:%d\n", sapp_global_val->config.packet_io.packet_io_tunnel.overlay_mode_bin); diff --git a/src/packet_io/packet_io_marsio.c b/src/packet_io/packet_io_marsio.c index ac5a9fe..ca043c0 100644 --- a/src/packet_io/packet_io_marsio.c +++ b/src/packet_io/packet_io_marsio.c @@ -36,7 +36,6 @@ typedef struct{ struct rawpkt_metadata { - enum mr_buff_metadata_type type; char data[MAX_METADATA_LEN]; unsigned int sz_data; struct segment_id_list raw_sid_list; @@ -439,7 +438,7 @@ void marsio_dl_io_free_rawpkt(const raw_pkt_t *raw_pkt, int thread_seq) } -struct rawpkt_metadata *marsio_dl_io_get1_rawpkt_meta(const raw_pkt_t *raw_pkt) +struct rawpkt_metadata *marsio_dl_io_get1_rawpkt_meta(const raw_pkt_t *raw_pkt, int thread_seq) { struct rawpkt_metadata *meta = NULL; int ret = 0; @@ -447,14 +446,14 @@ struct rawpkt_metadata *marsio_dl_io_get1_rawpkt_meta(const raw_pkt_t *raw_pkt) { if (ptr_marsio_buff_get_sid_list != NULL || ptr_marsio_buff_get_metadata != NULL) { - meta = (struct rawpkt_metadata *)calloc(sizeof(struct rawpkt_metadata), 1); + meta = (struct rawpkt_metadata *)sapp_mem_calloc(SAPP_MEM_DYN_SID_LIST, thread_seq,sizeof(struct rawpkt_metadata)); if (ptr_marsio_buff_get_metadata) { ret = ptr_marsio_buff_get_metadata((marsio_buff_t *)raw_pkt->io_lib_pkt_reference, - MR_BUFF_ROUTE_CTX, meta->data, meta->sz_data); + MR_BUFF_ROUTE_CTX, meta->data, MAX_METADATA_LEN); if (ret <= 0) { - free(meta); + sapp_mem_free(SAPP_MEM_DYN_SID_LIST, thread_seq,meta); return NULL; } else @@ -477,7 +476,7 @@ struct rawpkt_metadata *marsio_dl_io_get1_rawpkt_meta(const raw_pkt_t *raw_pkt) } if (meta->sz_data == 0 && meta->raw_sid_list.sz_sidlist == 0) { - free(meta); + sapp_mem_free(SAPP_MEM_DYN_SID_LIST, thread_seq,meta); meta = NULL; } } @@ -503,7 +502,7 @@ void marsio_dl_io_set_rawpkt_meta(const raw_pkt_t *raw_pkt, void *send_pkt_io_re } if(ptr_marsio_buff_set_metadata) { - ptr_marsio_buff_set_metadata((marsio_buff_t *)send_pkt_io_reference, snd_meta->type, (void *)snd_meta->data, snd_meta->sz_data); + ptr_marsio_buff_set_metadata((marsio_buff_t *)send_pkt_io_reference, MR_BUFF_ROUTE_CTX, (void *)snd_meta->data, snd_meta->sz_data); } if(ptr_marsio_buff_set_sid_list) { @@ -515,11 +514,11 @@ void marsio_dl_io_set_rawpkt_meta(const raw_pkt_t *raw_pkt, void *send_pkt_io_re return; } -void marsio_dl_io_free_rawpkt_meta(struct rawpkt_metadata * meta) +void marsio_dl_io_free_rawpkt_meta(struct rawpkt_metadata * meta, int thread_seq) { if(meta != NULL) { - free(meta); + sapp_mem_free(SAPP_MEM_DYN_SID_LIST, thread_seq,meta); meta=NULL; } return; @@ -710,7 +709,14 @@ static inline int marsio4_pkt_hand(int tid, marsio_buff_t *rx_buff, raw_pkt_t *r struct mr_tunnat_ctrlzone *mr_ctrlzone = (struct mr_tunnat_ctrlzone *)ptr_marsio_buff_ctrlzone(rx_buff, 0); /* index */ raw_pkt->is_overlay_pkt = mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD; }else{ - raw_pkt->is_overlay_pkt = 0; /* ��mrtunnatʱ, ���յ�������ȷ��, ��packet_io_hook�����Ƿ���overlay�İ� */ + if(OVERLAY_MODE_NF == sapp_global_val->config.packet_io.packet_io_tunnel.overlay_mode_bin) + { + raw_pkt->is_overlay_pkt = 1; + } + else + { + raw_pkt->is_overlay_pkt = 0; /* ��mrtunnatʱ, ���յ�������ȷ��, ��packet_io_hook�����Ƿ���overlay�İ� */ + } } /* clear pkt status */ @@ -1182,6 +1188,18 @@ unsigned int marsio_get_vlan_id_from_mbuff(void *pkt_reference) return vlan_id; } +int marsio_get_route_dir_from_mbuff(void *pkt_reference) +{ + int dir = -1; + + if(ptr_marsio_buff_get_metadata){ + ptr_marsio_buff_get_metadata((marsio_buff_t *)pkt_reference, MR_BUFF_DIR, &dir, sizeof(int)); + } + + return dir; +} + + int marsio_set_vlan_id_to_mbuff(void *pkt_reference, unsigned int vlan_id_host_order) { int ret = 0; diff --git a/src/packet_io/packet_io_pcap.c b/src/packet_io/packet_io_pcap.c index f4ee9de..a82f526 100644 --- a/src/packet_io/packet_io_pcap.c +++ b/src/packet_io/packet_io_pcap.c @@ -751,12 +751,12 @@ void pcap_dl_io_free_rawpkt(const raw_pkt_t *raw_pkt, int thread_seq) return;
}
-struct rawpkt_metadata *pcap_dl_io_get1_rawpkt_meta(const raw_pkt_t *raw_pkt)
+struct rawpkt_metadata *pcap_dl_io_get1_rawpkt_meta(const raw_pkt_t *raw_pkt, int thread_seq)
{
return NULL;
}
-void pcap_dl_io_free_rawpkt_meta(struct rawpkt_metadata * meta)
+void pcap_dl_io_free_rawpkt_meta(struct rawpkt_metadata * meta, int thread_seq)
{
return;
}
diff --git a/test/test_app_sapp.c b/test/test_app_sapp.c index bc22e38..2a511c2 100644 --- a/test/test_app_sapp.c +++ b/test/test_app_sapp.c @@ -44,8 +44,8 @@ typedef struct{ int test_bridge_id; }test_app_val_t; -/* ����һЩȫ�ֱ���, �и��ֲ�ͬ������, ��������������ݲ���, - �����������ɸ��������Լ����� +/* ����һЩȫ�ֱ���, �и��ֲ�ͬ������, ��������������ݲ���, + �����������ɸ��������Լ����� */ static test_app_val_t g_test_app_val; static const char *g_test_app_cfg_file="./etc/test_app.conf"; @@ -139,7 +139,7 @@ static void show_hierarchical_layer_stat(void) static int update_hierarchical_layer_stat(const struct hierarchical_layer *stream_hierarchical_layer_stat) { - if(search_g_hierarchical_layer_stat(stream_hierarchical_layer_stat) == 0){ //不存�? �?新的流结�? + if(search_g_hierarchical_layer_stat(stream_hierarchical_layer_stat) == 0){ //不存�? �?新的流结�? memcpy(&g_hierarchical_layer_stat[hierarchical_layer_stat_num], stream_hierarchical_layer_stat, sizeof(struct hierarchical_layer) * MAX_LAYER_DEPTH); hierarchical_layer_stat_num++; show_hierarchical_layer_stat(); @@ -208,7 +208,7 @@ void phony_protocol_get_plugid(unsigned short plugid) phony_protocol_plugid= plugid; } -/* ģ�������, �������ļ�PLUGNAME=xxxʶ�� */ +/* ģ�������, �������ļ�PLUGNAME=xxxʶ�� */ char phony_protocol_test(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a_packet) { stSessionInfo stinfo; @@ -356,7 +356,7 @@ char test_get_pkt_tcp_opts_ext(struct streaminfo *a_tcp, void **pme, int thread return APP_STATE_GIVEME; } -/* ���Ե�����ͳ�� */ +/* ���Ե�����ͳ�� */ char test_tcp_uni_stream_stats(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a_packet) { struct tcpdetail *raw_pdetail; @@ -371,7 +371,7 @@ char test_tcp_uni_stream_stats(struct streaminfo *a_tcp, void **pme, int thread if(OP_STATE_CLOSE == a_tcp->opstate){ if(DIR_DOUBLE == a_tcp->dir){ - /* ֻ�������� */ + /* ֻ�������� */ return APP_STATE_DROPME; } @@ -456,10 +456,10 @@ char test_set_stream_timeout(struct streaminfo *pstream, void **pme, int thread if(pstream->opstate== OP_STATE_PENDING){ /* for test, port 11111=timeout=11s, port 22222=timeout=22s, - ������nc����3��udp����, �˿ڷֱ�Ϊ11111, 22222, 33333, - ��11s֮��, 11111Ӧ�ý���, - 22s֮��, 22222Ӧ�ý���, - 33333����Ĭ��ȫ�ֳ�ʱ��̭ʱ��, �������ȫ�ֳ�ʱ��̭, Ӧ�ò������(dumpfileģʽ����). + ������nc����3��udp����, �˿ڷֱ�Ϊ11111, 22222, 33333, + ��11s֮��, 11111Ӧ�ý���, + 22s֮��, 22222Ӧ�ý���, + 33333����Ĭ��ȫ�ֳ�ʱ��̭ʱ��, �������ȫ�ֳ�ʱ��̭, Ӧ�ò������(dumpfileģʽ����). */ if((pstream->addr.tuple4_v4->source == ntohs(11111)) || (pstream->addr.tuple4_v4->dest == ntohs(11111))){ @@ -1087,7 +1087,7 @@ test_set_stream_timeout(pstream, pme, thread_seq, a_packet); } -/* 关于网络相关字�??, 均为网络�? network order */ +/* 关于网络相关字�??, 均为网络�? network order */ struct __test_inline_vxlan_hdr{ unsigned char flags; @@ -1095,12 +1095,12 @@ struct __test_inline_vxlan_hdr{ #if 0 unsigned char reserved[3]; #else - unsigned char nat_type; /* 复用�?�?保留字�?? 表示NAT类型 */ + unsigned char nat_type; /* 复用�?�?保留字�?? 表示NAT类型 */ unsigned char reserved[2]; #endif /*--------int delim -------*/ unsigned char vlan_id_half_high; - unsigned char link_layer_type : 4; /* 二层报文封�?�格�? */ + unsigned char link_layer_type : 4; /* 二层报文封�?�格�? */ unsigned char vlan_id_half_low : 4; unsigned int dir : 1; unsigned int link_id : 6; @@ -1447,7 +1447,7 @@ static void print_tuple4(struct streaminfo *stream) } -/* ����ֵ 1:���Լ��İ� 0:�����Լ��İ� -1:�������ݴ��� */ +/* ����ֵ 1:���Լ��İ� 0:�����Լ��İ� -1:�������ݴ��� */ static int check_rst_ip_new (unsigned int dip_net_order,unsigned short dport_net_order, unsigned short ipid_host_order, unsigned short win_host_order, int iMaxRandVal, int iRandKey) { @@ -1463,7 +1463,7 @@ static int check_rst_ip_new (unsigned int dip_net_order,unsigned short dport_net return 1; } -/* ����ֵ 1:���Լ��İ� 0:�����Լ��İ� -1:�������ݴ��� */ +/* ����ֵ 1:���Լ��İ� 0:�����Լ��İ� -1:�������ݴ��� */ static int check_rst_ip_old (unsigned int sip_net_order, unsigned int dip_net_order, unsigned short ipid, unsigned short window, int iMaxRandVal, int iRandKey) { @@ -1480,7 +1480,7 @@ static int check_rst_ip_old (unsigned int sip_net_order, unsigned int dip_net_or if (window == 0) return 0; - if ((iMaxRandVal - ipid + sip_net_order%window)%iRandKey != 0) // ������������ + if ((iMaxRandVal - ipid + sip_net_order%window)%iRandKey != 0) // ������������ return 0; int val = (iMaxRandVal - ipid + sip_net_order%window)/iRandKey; window_compute = (unsigned short)(val+dip_net_order%iRandKey); @@ -1488,7 +1488,7 @@ static int check_rst_ip_old (unsigned int sip_net_order, unsigned int dip_net_or if (window_compute == 0 || window_compute == 1 ) return 1; } - if (window == window_compute) { // ����ȣ�������������Լ������� + if (window == window_compute) { // ����ȣ�������������Լ������� return 1; } return 0; @@ -1747,7 +1747,7 @@ char test_kill_connection( struct streaminfo *stream,void **pme, int thread_seq, char ip1[16], ip2[16]; struct stream_tuple4_v4 *tuple_v4; - if(OP_STATE_DATA != stream->opstate){ /* ֻ��DATA״̬����KILL */ + if(OP_STATE_DATA != stream->opstate){ /* ֻ��DATA״̬����KILL */ return APP_STATE_GIVEME; } @@ -1888,7 +1888,7 @@ static void test_inject_tcp_pkt_with_this_hdr(struct streaminfo *stream,void **p raw_thdr = (struct mesa_tcp_hdr *)((char *)raw_ihdr + raw_ihdr->ip_hl*4); raw_tcp_payload_len = ntohs(raw_ihdr->ip_len) - raw_ihdr->ip_hl*4 - raw_thdr->th_off * 4; - /* 当前包是C2S方向的GET, �?要回复一�?虚假的S2C方向的RESPONSE */ + /* 当前包是C2S方向的GET, �?要回复一�?虚假的S2C方向的RESPONSE */ send_ihdr = (struct mesa_ip4_hdr *)pkt_header_payload; send_thdr = (struct mesa_tcp_hdr *)((char *)send_ihdr + sizeof(struct mesa_ip4_hdr)); @@ -1992,7 +1992,7 @@ char test_inject_tcp_pkt2(struct streaminfo *stream,void **pme, int thread_seq,c -/* ʹ���µķ����ӿ� sapp_inject_pkt()����α��� */ +/* ʹ���µķ����ӿ� sapp_inject_pkt()����α��� */ static int send_by_sapp_inject_pkt(struct streaminfo *a_tcp, const struct mesa_ip4_hdr *raw_ip4hdr) { #define HIJACK_RESPONSE_HDR "HTTP/1.1 200 OK\r\nServer: hijack.com\r\nContent-Length:%d\r\nContent-Type: text/html; charset=UTF-8\r\nConnection: close\r\n\r\n" @@ -2045,7 +2045,7 @@ static int send_by_sapp_inject_pkt(struct streaminfo *a_tcp, const struct mesa_i char MESA_inject_pkt_for_l2_l3_tcp(struct streaminfo *stream,void **pme, int thread_seq,const void *raw_pkt) { - const char *modify_raw_data_c2s = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"; //C2Sԭʼ�ַ������� + const char *modify_raw_data_c2s = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"; //C2Sԭʼ�ַ������� const char *modify_inject_data_s2c = "HTTP/1.1 200 OK\r\nServer: Microsoft-IIS/8.5\r\nContent-Type: text/html\r\nContent-Length: 4000\r\n\r\n<html><pre> sapp test inject data........."; int ret; @@ -2058,7 +2058,7 @@ char MESA_inject_pkt_for_l2_l3_tcp(struct streaminfo *stream,void **pme, int thr if(DIR_C2S == stream->curdir){ if(memmem(stream->ptcpdetail->pdata, stream->ptcpdetail->datalen, modify_raw_data_c2s, strlen(modify_raw_data_c2s)) != NULL){ - //������һ��get����, ������һ�����Ӧ�� + //������һ��get����, ������һ�����Ӧ�� ret = MESA_inject_pkt(stream, modify_inject_data_s2c, 1460, raw_pkt, stream->routedir ^ 1); if(ret < 0){ DPRINT("%s, MESA_inject_pkt S2C error!\n", printaddr(&stream->addr, thread_seq)); @@ -2067,12 +2067,12 @@ char MESA_inject_pkt_for_l2_l3_tcp(struct streaminfo *stream,void **pme, int thr } if(stream->ptcpdetail->serverpktnum <= 3){ - ret_flag = APP_STATE_DROPPKT;//����C2S�����һ��GET��, ��MESA_inject_pkt_for_l2_l3_tcpall()�ᷢ��һ���ٵ� + ret_flag = APP_STATE_DROPPKT;//����C2S�����һ��GET��, ��MESA_inject_pkt_for_l2_l3_tcpall()�ᷢ��һ���ٵ� } } }else{ if(memmem(stream->ptcpdetail->pdata, stream->ptcpdetail->datalen, "<html><pre>******", strlen("<html><pre>******")) != NULL){ - /* ��һ��S2CӦ����Ѿ���α�췢��, �˴�����Ҫ */ + /* ��һ��S2CӦ����Ѿ���α�췢��, �˴�����Ҫ */ ret_flag = APP_STATE_DROPPKT; return APP_STATE_DROPME | ret_flag; } @@ -2096,12 +2096,12 @@ char MESA_inject_pkt_for_l2_l3_tcpall(struct streaminfo *stream,void **pme, int if((DIR_C2S == stream->curdir) && (stream->ptcpdetail->serverpktnum == 2) - && (stream->ptcpdetail->datalen == 0)){ /* ֻ���������ָո���ɺ�, �յ�ACK������һ��get����,������ŶԲ��� */ + && (stream->ptcpdetail->datalen == 0)){ /* ֻ���������ָո���ɺ�, �յ�ACK������һ��get����,������ŶԲ��� */ inet_ntop(AF_INET, &stream->addr.tuple4_v4->daddr, server_ip, 32); DSPRINT(raw_data_c2s, modify_inject_data_c2s, server_ip); if(strlen(raw_data_c2s) != 197){ - DPRINT("MESA_inject_pkt_for_l2_l3_tcpall(), C2S inject len is not 197, %d\n", (int)strlen(raw_data_c2s)); //Ҫ���DZ������������һ��, ������SEQ���ܲ��� + DPRINT("MESA_inject_pkt_for_l2_l3_tcpall(), C2S inject len is not 197, %d\n", (int)strlen(raw_data_c2s)); //Ҫ���DZ������������һ��, ������SEQ���ܲ��� return APP_STATE_DROPME; } ret = MESA_inject_pkt(stream, raw_data_c2s, strlen(raw_data_c2s), raw_pkt, stream->routedir); @@ -2202,7 +2202,7 @@ char test_sapp_inject_pkt_reverse_dir(struct streaminfo *stream,void **pme, int static struct streaminfo *g_polling_stream = NULL; char polling_inject_tcpall_entry(struct streaminfo *stream,void **pme, int thread_seq,const void *raw_pkt) { - /* polling_inject_tcp_entry��polling������, �ò���stream, ��tcpall_entry����ȫ�ֱ���g_polling_stream,�Ի�ȡij���������� */ + /* polling_inject_tcp_entry��polling������, �ò���stream, ��tcpall_entry����ȫ�ֱ���g_polling_stream,�Ի�ȡij���������� */ if((OP_STATE_DATA == stream->pktstate) && (stream->addr.tuple4_v4->dest == htons(22))){ DPRINT("update polling stream %p: %s \n", stream, printaddr(&stream->addr, thread_seq)); @@ -2664,7 +2664,7 @@ char test_get_rawpkt_opt_from_streaminfo(struct streaminfo *f_stream,unsigned ch int tot_len = -1, this_layer_remain_len = -1; int ret; - if((OP_STATE_DATA != f_stream->opstate) && (OP_STATE_DATA != f_stream->pktstate)){ /* ��ͬʱ���ص�tcp,tcpall */ + if((OP_STATE_DATA != f_stream->opstate) && (OP_STATE_DATA != f_stream->pktstate)){ /* ��ͬʱ���ص�tcp,tcpall */ return APP_STATE_GIVEME; } @@ -2739,7 +2739,7 @@ char stream_bridge_tcp_entry(struct streaminfo *pstream,void **pme, int thread_s } if(OP_STATE_CLOSE == pstream->opstate){ - /* tcp�Ƚ���, �������� */ + /* tcp�Ƚ���, �������� */ void *data = calloc(1, 100); strncpy(data, "abcdefg1234567", 100); stream_bridge_async_data_put(pstream, bridge_id, data); @@ -2916,20 +2916,20 @@ char TEST_TCP_LOST(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a if(a_tcp->ptcpdetail->datalen > 0){ ipv4_hdr = (const struct mesa_ip4_hdr *)a_packet; tcp_hdr = (const struct mesa_tcp_hdr *)((char *)ipv4_hdr + ipv4_hdr->ip_hl * 4); - pkt_raw_data = (char *)tcp_hdr + tcp_hdr->th_off * 4; /* ���ݰ�ԭʼ����ָ�� */ - /* �����ش������ݵ�ԭ��, ƽ̨�����������a_tcp->ptcpdetail->pdata����һ������pkt_raw_data, �������ƫ���� */ + pkt_raw_data = (char *)tcp_hdr + tcp_hdr->th_off * 4; /* ���ݰ�ԭʼ����ָ�� */ + /* �����ش������ݵ�ԭ��, ƽ̨�����������a_tcp->ptcpdetail->pdata����һ������pkt_raw_data, �������ƫ���� */ actual_data_seq = ntohl(tcp_hdr->th_seq) + ((char *)a_tcp->ptcpdetail->pdata - pkt_raw_data); DPRINT("stream:%s, dir:%d, pkt-seq:%u, actual-data-seq:%u\n", printaddr(&a_tcp->addr, a_tcp->threadnum),a_tcp->curdir, ntohl(tcp_hdr->th_seq), actual_data_seq); if(DIR_C2S == a_tcp->curdir){ - /* ����ʵ����� == ���ϴμ���ó�������Ӧ�õ������ + ���μ���ó��Ķ������� */ + /* ����ʵ����� == ���ϴμ���ó�������Ӧ�õ������ + ���μ���ó��Ķ������� */ if(actual_data_seq != tcp_status->seq_next_c2s + a_tcp->ptcpdetail->lostlen){ DPRINT("\033[41mstream:%s, seq check fail!\033[0m\n", printaddr(&a_tcp->addr, a_tcp->threadnum)); //assert(0); goto err_exit; } - /* ��һ���ڴ��������: ��ǰʵ����� + ʵ�����ݳ��� */ + /* ��һ���ڴ��������: ��ǰʵ����� + ʵ�����ݳ��� */ tcp_status->seq_next_c2s = actual_data_seq + a_tcp->ptcpdetail->datalen; }else{ if(actual_data_seq != tcp_status->seq_next_s2c + a_tcp->ptcpdetail->lostlen){ @@ -2937,7 +2937,7 @@ char TEST_TCP_LOST(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a //assert(0); goto err_exit; } - /* ��һ���ڴ��������: ��ǰʵ����� + ʵ�����ݳ��� */ + /* ��һ���ڴ��������: ��ǰʵ����� + ʵ�����ݳ��� */ tcp_status->seq_next_s2c = actual_data_seq + a_tcp->ptcpdetail->datalen; } } @@ -3172,22 +3172,22 @@ char RST_STREAM(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a_pa if((sport_host >= 10000) && (sport_host <= 19999)){ if(DIR_C2S == a_tcp->curdir){ - RST_STREAM_C2S(a_tcp, pme, thread_seq, a_packet); /* C2Sԭʼ������C2Sע��RST */ + RST_STREAM_C2S(a_tcp, pme, thread_seq, a_packet); /* C2Sԭʼ������C2Sע��RST */ DPRINT("inject C2S rst by raw C2S pkt\n"); } }else if((sport_host >= 20000) && (sport_host <= 29999)){ if(DIR_C2S == a_tcp->curdir){ - RST_STREAM_S2C(a_tcp, pme, thread_seq, a_packet); /* C2Sԭʼ������S2Cע��RST */ + RST_STREAM_S2C(a_tcp, pme, thread_seq, a_packet); /* C2Sԭʼ������S2Cע��RST */ DPRINT("inject S2C rst by raw C2S pkt\n"); } }else if((sport_host >= 30000) && (sport_host <= 39999)){ if(DIR_S2C == a_tcp->curdir){ - RST_STREAM_C2S(a_tcp, pme, thread_seq, a_packet); /* S2Cԭʼ������C2Sע��RST */ + RST_STREAM_C2S(a_tcp, pme, thread_seq, a_packet); /* S2Cԭʼ������C2Sע��RST */ DPRINT("inject C2S rst by raw S2C pkt\n"); } }else if((sport_host >= 40000) && (sport_host <= 49999)){ if(DIR_S2C == a_tcp->curdir){ - RST_STREAM_S2C(a_tcp, pme, thread_seq, a_packet); /* S2Cԭʼ������S2Cע��RST */ + RST_STREAM_S2C(a_tcp, pme, thread_seq, a_packet); /* S2Cԭʼ������S2Cע��RST */ DPRINT("inject S2C rst by raw S2C pkt\n"); } }else{ @@ -3207,34 +3207,47 @@ char INJECT_STREAM(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a const char *inject_C2S_by_S2C = "sapp inject_C2S_by_S2C payload......"; const char *inject_S2C_by_S2C = "sapp inject_S2C_by_S2C payload......"; - if((OP_STATE_CLOSE != a_tcp->opstate) && (DIR_DOUBLE == a_tcp->dir)){ + //if((OP_STATE_CLOSE != a_tcp->opstate) && (DIR_DOUBLE == a_tcp->dir)){ + if((OP_STATE_CLOSE != a_tcp->opstate)){ sport_host = ntohs(a_tcp->addr.tuple4_v4->source); - + + if (a_tcp->routedir == DIR_ROUTE_UP) + { + sapp_inject_pkt(a_tcp, SIO_DEFAULT, inject_S2C_by_C2S, strlen(inject_S2C_by_C2S), a_tcp->routedir ^ 1); + DPRINT("Get Outbound pkt:%s, CurDir:%d, inject to S2C by raw C2S pkt, raw payload len:%d\n", printaddr(&a_tcp->addr, thread_seq), a_tcp->curdir, a_tcp->ptcpdetail->datalen); + } + else + { + sapp_inject_pkt(a_tcp, SIO_DEFAULT, inject_S2C_by_S2C, strlen(inject_S2C_by_S2C), a_tcp->routedir); + DPRINT("Get Inbound pkt:%s, CurDir:%d, inject S2C pkt by raw S2C pkt, raw payload len:%d\n", printaddr(&a_tcp->addr, thread_seq), a_tcp->curdir, a_tcp->ptcpdetail->datalen); + } +#if 0 if((sport_host >= 10000) && (sport_host <= 19999)){ if(DIR_C2S == a_tcp->curdir){ - sapp_inject_pkt(a_tcp, SIO_DEFAULT, inject_C2S_by_C2S, strlen(inject_C2S_by_C2S), a_tcp->routedir); /* C2Sԭʼ������C2Sע�� */ + sapp_inject_pkt(a_tcp, SIO_DEFAULT, inject_C2S_by_C2S, strlen(inject_C2S_by_C2S), a_tcp->routedir); /* C2Sԭʼ������C2Sע�� */ DPRINT("inject C2S pkt by raw C2S pkt\n"); } }else if((sport_host >= 20000) && (sport_host <= 29999)){ if(DIR_C2S == a_tcp->curdir){ - sapp_inject_pkt(a_tcp, SIO_DEFAULT, inject_S2C_by_C2S, strlen(inject_S2C_by_C2S), a_tcp->routedir ^ 1); /* C2Sԭʼ������S2Cע�� */ + sapp_inject_pkt(a_tcp, SIO_DEFAULT, inject_S2C_by_C2S, strlen(inject_S2C_by_C2S), a_tcp->routedir ^ 1); /* C2Sԭʼ������S2Cע�� */ DPRINT("inject S2C pkt by raw C2S pkt\n"); } }else if((sport_host >= 30000) && (sport_host <= 39999)){ if(DIR_S2C == a_tcp->curdir){ - sapp_inject_pkt(a_tcp, SIO_DEFAULT, inject_C2S_by_S2C, strlen(inject_C2S_by_S2C), a_tcp->routedir ^ 1); /* S2Cԭʼ������C2Sע�� */ + sapp_inject_pkt(a_tcp, SIO_DEFAULT, inject_C2S_by_S2C, strlen(inject_C2S_by_S2C), a_tcp->routedir ^ 1); /* S2Cԭʼ������C2Sע�� */ DPRINT("inject C2S pkt by raw S2C pkt\n"); } }else if((sport_host >= 40000) && (sport_host <= 49999)){ if(DIR_S2C == a_tcp->curdir){ - sapp_inject_pkt(a_tcp, SIO_DEFAULT, inject_S2C_by_S2C, strlen(inject_S2C_by_S2C), a_tcp->routedir); /* S2Cԭʼ������S2Cע�� */ + sapp_inject_pkt(a_tcp, SIO_DEFAULT, inject_S2C_by_S2C, strlen(inject_S2C_by_S2C), a_tcp->routedir); /* S2Cԭʼ������S2Cע�� */ DPRINT("inject S2C pkt by raw S2C pkt\n"); } }else{ return APP_STATE_DROPME; } +#endif } - + return APP_STATE_GIVEME; } @@ -3251,7 +3264,7 @@ char TEST_STREAM(struct streaminfo *stream, void **pme, int thread_seq, const v return APP_STATE_DROPME; } - int min_num = MIN(65535, g_test_app_val.ivalue1+1); //�������ļ���ȡ + int min_num = MIN(65535, g_test_app_val.ivalue1+1); //�������ļ���ȡ for(i = 0; i < min_num; i++){ local_data[i] = rand(); @@ -3267,7 +3280,7 @@ char TEST_STREAM(struct streaminfo *stream, void **pme, int thread_seq, const v return APP_STATE_GIVEME; } - /* ���д�㶫��, �ķ�CPU */ + /* ���д�㶫��, �ķ�CPU */ if(datalen > 0){ for(i = 0; i < datalen; i++){ result1[i] = (long)memchr(local_data, data[i], min_num); @@ -3487,7 +3500,7 @@ char POLLING_ENTRY(struct streaminfo *stream, void **pme, int thread_seq,void * extern long long sapp_random(void); char fake_deadlock(struct streaminfo *pstream,void **pme, int thread_seq,void *a_packet) { - /* ����������߳�, ģ������ */ + /* ����������߳�, ģ������ */ int opt_val_len = sizeof(int); int tid; int tot_thread_cnt; @@ -3562,7 +3575,7 @@ int CHAR_INIT() int i; CHAR_CONFIG_INIT(); - /* �������ڳ�ʼ��ʱ����ע��project */ + /* �������ڳ�ʼ��ʱ����ע��project */ g_test_app_val.test_project_id = project_producer_register("test_project", "struct", __fake_project_free_cb); if(g_test_app_val.test_project_id < 0){ DPRINT("##### project_producer_register error!\n"); |
