summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijia <[email protected]>2021-06-10 16:46:42 +0800
committerlijia <[email protected]>2021-06-10 16:46:42 +0800
commit7864ebe152842d43c478cdc33f701972f309dff7 (patch)
treef57b43f19a6b62f46ef75ec17370bd789bffc582
parent640b6119583c0734ac6543ba712ac53fb08df285 (diff)
修复TCP带SYN包创建流时, 不能受well_known_port.conf配置影响.v4.2.38
-rw-r--r--include/private/stream_internal.h1
-rw-r--r--src/dealpkt/deal_tcp.c20
-rw-r--r--src/dealpkt/deal_udp.c12
3 files changed, 23 insertions, 10 deletions
diff --git a/include/private/stream_internal.h b/include/private/stream_internal.h
index 81d5ae1..df2caab 100644
--- a/include/private/stream_internal.h
+++ b/include/private/stream_internal.h
@@ -404,6 +404,7 @@ int sapp_is_absolute_path(const char *filename);
char *sapp_memmove_for_blank_table(char *data, int max_len);
void del_last_rn(char *data, int max_len);
void sapp_printf_colorful(int level, const char *format, ...);
+int set_transport_addr(struct streaminfo *this_stream, int enable_well_known_port, UINT16 sport, UINT16 dport);
#ifdef __cplusplus
}
diff --git a/src/dealpkt/deal_tcp.c b/src/dealpkt/deal_tcp.c
index bdddd18..90095d0 100644
--- a/src/dealpkt/deal_tcp.c
+++ b/src/dealpkt/deal_tcp.c
@@ -40,7 +40,6 @@
#ifdef __cplusplus
extern "C" {
#endif
-int set_transport_addr(struct streaminfo *pfstream, UINT16 sport, UINT16 dport);
extern void free_heap_stream_info(struct streaminfo *heap_stream, int layer);
extern struct streaminfo_private *copy_stream_info_to_heap(const struct streaminfo_private *stack_stream_pr, int reverse);
@@ -1030,6 +1029,11 @@ static struct streamindex *tcp_add_new_stream_bydata(struct streamindex *pindex,
pdetail_pr->auto_remedy_flag = sapp_global_val->config.stream.tcp.inject.auto_remedy;
+ if(pstream_pr->create_dir_by_well_known_port){
+ sapp_runtime_log(RLOG_LV_DEBUG, "create new TCP stream without SYN:%s by well known port, the first packet curdir is:%d",
+ printaddr(&pstream->addr, threadnum), pstream->curdir);
+ }
+
return pindex_tcp;
}
@@ -2941,7 +2945,7 @@ static int dealtcppkt(struct streamindex *pfindex, const void *this_iphdr, struc
}
pstream->type=STREAM_TYPE_TCP;
- set_transport_addr(pstream, this_tcphdr->th_sport, this_tcphdr->th_dport);
+ set_transport_addr(pstream, !(this_tcphdr->th_flags & TH_SYN), this_tcphdr->th_sport, this_tcphdr->th_dport);
pstream->addr.pkttype = PKT_TYPE_NORMAL;//add by lqy 20151222, init pkttype
@@ -3167,17 +3171,19 @@ int set_stream_addr(struct streaminfo *pfstream, UINT16 sport, UINT16 dport, str
return 0;
}
#else
-int set_transport_addr(struct streaminfo *this_stream, UINT16 sport, UINT16 dport)
+int set_transport_addr(struct streaminfo *this_stream, int enable_well_known_port, UINT16 sport, UINT16 dport)
{
struct streaminfo_private *this_stream_pr = (struct streaminfo_private *)this_stream;
struct layer_addr *this_addr = &this_stream->addr;
- unsigned char dir_by_well_known_port;
+ unsigned char dir_by_well_known_port = 0;
if(__ADDR_TYPE_IP_PAIR_V4 == this_addr->addrtype){
struct stream_tuple4_v4 *ip4_addr = this_addr->tuple4_v4;
/* ���ö˿�, ��IP-PORT-union�汾��port˳����Ϊlayer_dir�IJ���,
ͬʱ����layer_dir, ���ڼ���HASHʱ, ��ַ����˳�� */
- dir_by_well_known_port = adjust_stream_dir_by_well_known_ports(this_stream->type, ntohs(sport), ntohs(dport));
+ if(enable_well_known_port){
+ dir_by_well_known_port = adjust_stream_dir_by_well_known_ports(this_stream->type, ntohs(sport), ntohs(dport));
+ }
if(dir_by_well_known_port != 0){
if(DIR_C2S == dir_by_well_known_port){
this_stream_pr->layer_dir = 1;
@@ -3212,7 +3218,9 @@ int set_transport_addr(struct streaminfo *this_stream, UINT16 sport, UINT16 dpor
this_addr->addrlen = sizeof(struct stream_tuple4_v4);
}else if(__ADDR_TYPE_IP_PAIR_V6 == this_addr->addrtype){
struct stream_tuple4_v6 *ip6_addr = this_addr->tuple4_v6;
- dir_by_well_known_port = adjust_stream_dir_by_well_known_ports(this_stream->type,ntohs(sport), ntohs(dport));
+ if(enable_well_known_port){
+ dir_by_well_known_port = adjust_stream_dir_by_well_known_ports(this_stream->type,ntohs(sport), ntohs(dport));
+ }
if(dir_by_well_known_port != 0){
if(DIR_C2S == dir_by_well_known_port){
this_stream_pr->layer_dir = 1;
diff --git a/src/dealpkt/deal_udp.c b/src/dealpkt/deal_udp.c
index 9c2ddf8..25134b3 100644
--- a/src/dealpkt/deal_udp.c
+++ b/src/dealpkt/deal_udp.c
@@ -13,7 +13,6 @@ extern "C" {
extern int udp_stream_table_size;
extern int raw_ip_frag_list_stream_attach(struct streaminfo *stream);
extern int raw_ip_frag_list_stream_detach(struct streaminfo *stream);
-extern int set_transport_addr(struct streaminfo *pfstream, UINT16 sport, UINT16 dport);
extern void free_heap_stream_info(struct streaminfo *heap_stream, int layer);
extern void reverse_addr(void *addr, int addrtype);
int copy_ipport_union_addr(struct streaminfo *pstream_heap, struct streaminfo *pstream_stack, int reverse);
@@ -219,6 +218,11 @@ static struct streamindex *udp_add_new_stream(struct streamindex *pindex,
}else{
pstream_udp_pr->stream_c2s_route_dir = raw_pkt->route_dir ^ 1;
}
+
+ if(pstream_udp_pr->create_dir_by_well_known_port){
+ sapp_runtime_log(RLOG_LV_DEBUG, "create new UDP stream:%s by well known port, the first packet curdir is:%d",
+ printaddr(&pstream_udp->addr, threadnum), pstream_udp->curdir);
+ }
return pindex_udp;
}
@@ -578,7 +582,7 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_
memset(&pdetail_pr, 0, sizeof(struct udpdetail_private));
pdetail = (struct udpdetail *)&pdetail_pr;
- set_transport_addr(pstream, udph->uh_sport, udph->uh_dport);
+ set_transport_addr(pstream, 1, udph->uh_sport, udph->uh_dport);
pstream_pr->offset_to_ip_hdr = (char *)udph - (char *)this_iphdr;
@@ -621,7 +625,7 @@ int dealipv4udppkt(struct streamindex *pindex, const struct mesa_ip4_hdr * this_
}
else
{
- set_transport_addr(pstream, udph->uh_sport, udph->uh_dport);
+ set_transport_addr(pstream, 1, udph->uh_sport, udph->uh_dport);
a_index =(struct streamindex * ) findstreamindex (pindex, raw_pkt);
if (unlikely(!a_index)){
@@ -826,7 +830,7 @@ int dealipv6udppkt(struct streamindex *pindex,const struct mesa_ip6_hdr *a_packe
}
#endif
- set_transport_addr(pstream, udph->uh_sport, udph->uh_dport);
+ set_transport_addr(pstream, 1, udph->uh_sport, udph->uh_dport);
a_index =(struct streamindex * ) findstreamindex (pindex, raw_pkt);
if(unlikely(!a_index)){