summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--bin/etc/sapp.toml1
-rw-r--r--ctest/CMakeLists.txt5
-rw-r--r--include/private/sapp_global_val.h1
-rw-r--r--src/config/config_parse.cpp4
-rw-r--r--src/packet_io/sapp_inject.c29
-rw-r--r--src/packet_io/sendpacket.c57
7 files changed, 67 insertions, 33 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1dc7ac5..05694a3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -181,6 +181,9 @@ add_subdirectory(./test)
add_subdirectory(./service)
add_subdirectory(./tools)
+enable_testing()
+add_subdirectory(./ctest)
+
#by default, not include sapp_module_test dir
#add_subdirectory(./test/sapp_module_test/src)
diff --git a/bin/etc/sapp.toml b/bin/etc/sapp.toml
index 3ab4135..11c4f65 100644
--- a/bin/etc/sapp.toml
+++ b/bin/etc/sapp.toml
@@ -113,6 +113,7 @@
tcp_drop_pure_ack_pkt=0
tcp_syn_option_parse_enabled=1
skip_not_ip_layer_over_eth=0
+ skip_gtp_seq_field_for_inject=0
[DUPLICATE_PKT]
[dup_pkt.traffic.original]
diff --git a/ctest/CMakeLists.txt b/ctest/CMakeLists.txt
new file mode 100644
index 0000000..0a465b0
--- /dev/null
+++ b/ctest/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required (VERSION 2.8)
+
+project(sapp_ctest)
+
+add_test(NAME FAKE_TEST COMMAND sh -c "pwd") \ No newline at end of file
diff --git a/include/private/sapp_global_val.h b/include/private/sapp_global_val.h
index f1670d4..d272c41 100644
--- a/include/private/sapp_global_val.h
+++ b/include/private/sapp_global_val.h
@@ -361,6 +361,7 @@ typedef struct{
int tcp_syn_option_parse_enabled; /* �Ƿ����tcp syn��ͷ��ѡ�� */
int skip_not_ip_layer_over_eth; /* ������ip��, ��֤�ڲ���ģʽ��, ����ͨ��ϵͳ·�ɷ���rst�� */
int reverse_ethernet_addr_enabled; /* smac��ַ�а���������Ϣʱ���跭ת */
+ int skip_gtp_seq_field_for_inject; /* GTP����ע�����ݰ�ʱ����seq�ֶ� */
}sapp_protocol_feature_t;
diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp
index 8863ed5..c19d250 100644
--- a/src/config/config_parse.cpp
+++ b/src/config/config_parse.cpp
@@ -239,7 +239,7 @@ static const sapp_config_check_t g_sapp_cfg_check_attr[] =
{4404,0,RLOG_LV_DEBUG,"PROTOCOL_FEATURE", "tcp_syn_option_parse_enabled", NULL,NULL, NULL, NULL, 0},
{4405,0,RLOG_LV_DEBUG,"PROTOCOL_FEATURE", "skip_not_ip_layer_over_eth", NULL,NULL, NULL, NULL, 0},
{4406,0,RLOG_LV_DEBUG,"PROTOCOL_FEATURE", "ipv6_decapsulation_enabled", NULL,NULL, NULL, NULL, 0},
- {4407,0,RLOG_LV_DEBUG,"PROTOCOL_FEATURE", "ipv6_decapsulation_enabled", NULL,NULL, NULL, NULL, 0},
+ {4407,0,RLOG_LV_DEBUG,"PROTOCOL_FEATURE", "skip_gtp_seq_field_for_inject", NULL,NULL, NULL, NULL, 0},
{4501,0,RLOG_LV_INFO,"dup_pkt.traffic.original", "original_ipv4_tcp_enabled", NULL,NULL, NULL, NULL, 0},
{4502,0,RLOG_LV_INFO,"dup_pkt.traffic.original", "original_ipv4_udp_enabled", NULL,NULL, NULL, NULL, 0},
@@ -1905,8 +1905,8 @@ int sapp_parse_config(void)
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"PROTOCOL_FEATURE", (char *)"tcp_drop_pure_ack_pkt", (int *)&pconfig->protocol_feature.tcp_drop_pure_ack_pkt, 0);
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"PROTOCOL_FEATURE", (char *)"tcp_syn_option_parse_enabled", (int *)&pconfig->protocol_feature.tcp_syn_option_parse_enabled, 1);
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"PROTOCOL_FEATURE", (char *)"skip_not_ip_layer_over_eth", (int *)&pconfig->protocol_feature.skip_not_ip_layer_over_eth, 0);
- //tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"PROTOCOL_FEATURE", (char *)"treat_vlan_as_mac_in_mac", (int *)&pconfig->protocol_feature.treat_vlan_as_mac_in_mac_enabled, 0);
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"PROTOCOL_FEATURE", (char *)"reverse_ethernet_addr", (int *)&pconfig->protocol_feature.reverse_ethernet_addr_enabled, 1);
+ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"PROTOCOL_FEATURE", (char *)"skip_gtp_seq_field_for_inject", (int *)&pconfig->protocol_feature.skip_gtp_seq_field_for_inject, 0);
/******************************* TOOLS **********************************/
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"tools.signal_handler", (char *)"signal", (int *)&pconfig->tools.signal_handler.signal, 0);
diff --git a/src/packet_io/sapp_inject.c b/src/packet_io/sapp_inject.c
index 94a6817..fdd5e58 100644
--- a/src/packet_io/sapp_inject.c
+++ b/src/packet_io/sapp_inject.c
@@ -25,11 +25,16 @@ extern int __sapp_inject_pkt(struct streaminfo *raw_stream, enum sapp_inject_opt
int sapp_inject_pkt(struct streaminfo *stream, enum sapp_inject_opt sio, const void *payload, int payload_len, unsigned char snd_routedir)
{
+ int ret;
char debug_log_buf[256];
UCHAR send_stream_dir;
const struct streaminfo_private *stream_pr = (struct streaminfo_private *)stream;
+
+ ret = __sapp_inject_pkt(stream, sio, payload, payload_len, snd_routedir, NULL);
if(ABBR_SAPP_LOG_LEVEL <= RLOG_LV_DEBUG){
+ int log_level;
+ const char *string_res;
/* injectʹ�õ���routedir, �˴�ת����stream dir,
ע��: ��������Ķ������ܲ����ɵ�ǰ��������, ����kni, �Ǵ����������յ����ݰ�, ��ע����·��,
���ܴ�raw_pkt��raw_stream->routedir�жϷ���,
@@ -40,34 +45,44 @@ int sapp_inject_pkt(struct streaminfo *stream, enum sapp_inject_opt sio, const v
}else{
send_stream_dir = DIR_S2C;
}
+
+ if(ret < 0){
+ log_level = RLOG_LV_FATAL;
+ string_res = "error";
+ }else{
+ log_level = RLOG_LV_DEBUG;
+ string_res = "succ";
+ }
+
if(SIO_EXCLUDE_THIS_LAYER_HDR & sio){
/* ipԭʼ����ҵ�������й��� */
if(ADDR_TYPE_IPV4 == stream->addr.addrtype){
const struct mesa_ip4_hdr *ip4hdr = (struct mesa_ip4_hdr *)payload;
- sapp_runtime_log(RLOG_LV_DEBUG, "sapp_inject_pkt()->IPV4, exclude ip header, stream:%s, stream_curdir:%d, stream_cur_routedir:%d, stream_C2S_routedir:%d, send_ipv4_pkt_hdr:%s, send_routedir:%d, send_stream_dir:%d, send_payload_len:%d, ttl:%d, ipid:%u, ip_checksum:0x%x",
- printaddr(&stream->addr, stream->threadnum),
+ sapp_runtime_log(log_level, "sapp_inject_pkt()->IPV4 %s, exclude ip header, stream:%s, stream_curdir:%d, stream_cur_routedir:%d, stream_C2S_routedir:%d, send_ipv4_pkt_hdr:%s, send_routedir:%d, send_stream_dir:%d, send_payload_len:%d, ttl:%d, ipid:%u, ip_checksum:0x%x",
+ string_res, printaddr(&stream->addr, stream->threadnum),
stream->curdir, stream->routedir, stream_pr->stream_c2s_route_dir,
sapp_raw_ipv4_ntop(ip4hdr, debug_log_buf, sizeof(debug_log_buf)),
snd_routedir, send_stream_dir, payload_len,
ip4hdr->ip_ttl, ntohs(ip4hdr->ip_id), ntohs(ip4hdr->ip_sum));
}else{
const struct mesa_ip6_hdr *ip6hdr = (struct mesa_ip6_hdr *)payload;
- sapp_runtime_log(RLOG_LV_DEBUG, "sapp_inject_pkt()->IPV6,exclude ip header, stream:%s, stream_curdir:%d, stream_cur_routedir:%d,stream_C2S_routedir:%d, send_ipv6_pkt_hdr:%s, send_routedir:%d, send_stream_dir:%d, send_payload_len:%d,ttl:%d",
- printaddr(&stream->addr, stream->threadnum),
+ sapp_runtime_log(log_level, "sapp_inject_pkt()->IPV6 %s, exclude ip header, stream:%s, stream_curdir:%d, stream_cur_routedir:%d,stream_C2S_routedir:%d, send_ipv6_pkt_hdr:%s, send_routedir:%d, send_stream_dir:%d, send_payload_len:%d,ttl:%d",
+ string_res, printaddr(&stream->addr, stream->threadnum),
stream->curdir, stream->routedir, stream_pr->stream_c2s_route_dir,
sapp_raw_ipv6_ntop(ip6hdr, debug_log_buf, sizeof(debug_log_buf)),
snd_routedir, send_stream_dir, payload_len, ip6hdr->ip6_hop);
}
}else{
/* ���ֻ����Ӧ�ò㸺�ؼ�ָ����������, ip��ͷ��sapp���� */
- sapp_runtime_log(RLOG_LV_DEBUG, "sapp_inject_pkt() by default, stream:%s, stream_curdir:%d, stream_cur_routedir:%d, stream_C2S_routedir:%d, send_routedir:%d, send_stream_dir:%d, send_payload_len:%d",
- printaddr(&stream->addr, stream->threadnum),
+ sapp_runtime_log(log_level, "sapp_inject_pkt() with SIO_DEFAULT %s, stream:%s, stream_curdir:%d, stream_cur_routedir:%d, stream_C2S_routedir:%d, send_routedir:%d, send_stream_dir:%d, send_payload_len:%d",
+ string_res, printaddr(&stream->addr, stream->threadnum),
stream->curdir, stream->routedir, stream_pr->stream_c2s_route_dir,
snd_routedir, send_stream_dir, payload_len);
}
}
- return __sapp_inject_pkt(stream, sio, payload, payload_len, snd_routedir, NULL);
+
+ return ret;
}
diff --git a/src/packet_io/sendpacket.c b/src/packet_io/sendpacket.c
index 1b8642c..1aaff81 100644
--- a/src/packet_io/sendpacket.c
+++ b/src/packet_io/sendpacket.c
@@ -915,10 +915,12 @@ static int calc_gtp_hdr_len(struct streaminfo_private * stream_pr, UCHAR send_st
̫������!
TODO��!!
*/
- if(raw_net_gtp_hdr->flags & 0x02)
+ if(raw_net_gtp_hdr->flags & GTP_HDR_FLAG_SEQ_NUM)
{
- sapp_runtime_log(RLOG_LV_FATAL, "%s, calc_gtp_hdr_len error, inject GTP pkt not support SEQ!", printaddr(&stream_pr->stream_public.addr, stream_pr->stream_public.threadnum));
- return -1;
+ if(0 == sapp_global_val->config.protocol_feature.skip_gtp_seq_field_for_inject){
+ sapp_runtime_log(RLOG_LV_FATAL, "calc_gtp_hdr_len error, inject GTP pkt not support SEQ, you should set 'skip_gtp_seq_field_for_inject' to avoid this!");
+ return -1;
+ }
}
if(g_asymmetric_addr_layer_set.layer_type_index[ADDR_TYPE_GPRS_TUNNEL][stream_pr->layer_index] != 0){
@@ -1829,7 +1831,7 @@ static int build_net_layer_gtp(struct streaminfo_private *stream_pr, int carry_l
sapp_runtime_log(RLOG_LV_FATAL, "build_net_layer_gtp() error, no c2s gtp addr, but asymmetric_addr_layer is set!\n");
return -1;
}else{
- p_gtp_layer_addr->teid_s2c;
+ this_pkt_teid = p_gtp_layer_addr->teid_s2c;
}
}else{
this_pkt_teid = p_gtp_layer_addr->teid_c2s;
@@ -1840,7 +1842,7 @@ static int build_net_layer_gtp(struct streaminfo_private *stream_pr, int carry_l
sapp_runtime_log(RLOG_LV_FATAL, "build_net_layer_gtp() error, no s2c gtp addr, but asymmetric_addr_layer is set!\n");
return -1;
}else{
- p_gtp_layer_addr->teid_c2s;
+ this_pkt_teid = p_gtp_layer_addr->teid_c2s;
}
}else{
this_pkt_teid = p_gtp_layer_addr->teid_s2c;
@@ -2407,19 +2409,19 @@ static int __do_kill_tcp(struct streaminfo *stream, const void *ext_raw_pkt, int
{
int i, ret = -1, reserved_hdr_len, send_len = 0;
MESA_send_handle *send_handle;
- int thread_num = stream->threadnum;
+ int thread_num;
int low_net_layer_type = -1;
tcp_rst_finger_mark_t *tcp_rst_finger;
const raw_pkt_t *raw_pkt = NULL;
struct streaminfo_private *stream_pr;
- sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_num]->sys_stat;
+ sapp_gval_mthread_sys_stat_t *local_sys_stat;
(void)ext_raw_pkt;
if(NULL == stream){
return -1;
}
-
+ thread_num = stream->threadnum;
stream_pr = (struct streaminfo_private *)stream;
send_handle = &g_send_handle[thread_num];
/* ��ı���ijЩ�ص�������ԭʼ������ΪIP��ͷ(����֮ǰpappƽ̨), ���Բ���Ҫ�������ԭʼ��, ��Ϣ���洢��˽�����ṹ���� */
@@ -2427,6 +2429,7 @@ static int __do_kill_tcp(struct streaminfo *stream, const void *ext_raw_pkt, int
if((NULL == raw_pkt) || (RAW_PKT_MAGIC_NUM != raw_pkt->magic_num)){
return -1;
}
+ local_sys_stat = &sapp_global_val->mthread_volatile[thread_num]->sys_stat;
send_handle->user_arg = (void *)stream;
tcp_rst_finger = make_tcp_rst_finger_mark(thread_num, (const raw_pkt_t *)raw_pkt);
@@ -2575,7 +2578,7 @@ int MESA_kill_tcp(struct streaminfo *stream, const void *ext_raw_pkt)
#else //2020-10-05 lijia modify
int MESA_kill_tcp(struct streaminfo *stream, const void *ext_raw_pkt)
{
- int ret;
+ int ret1,ret2;
struct rst_tcp_para rst_paras = {};
struct streaminfo_private *stream_pr = (struct streaminfo_private *)stream;
@@ -2590,11 +2593,10 @@ int MESA_kill_tcp(struct streaminfo *stream, const void *ext_raw_pkt)
rst_paras.signature_seed1 = sapp_global_val->config.stream.tcp.inject.rst_signature_seed1;
rst_paras.signature_seed2 = sapp_global_val->config.stream.tcp.inject.rst_signature_seed2;
- ret = MESA_rst_tcp(stream, &rst_paras, sizeof(struct rst_tcp_para));
-
- /* ������ */
+ ret1 = MESA_rst_tcp(stream, &rst_paras, sizeof(struct rst_tcp_para));
+ /* �˴������Ƿ�������, �������ҲҪ����, ij��������ɹ�Ҳ�ǿ��Բ���ʵ��Ч���� */
rst_paras.dir = stream->curdir ^ DIR_DOUBLE;
- ret = MESA_rst_tcp(stream, &rst_paras, sizeof(struct rst_tcp_para));
+ ret2 = MESA_rst_tcp(stream, &rst_paras, sizeof(struct rst_tcp_para));
/* �����µı�־λ, kill_tcp�Զ�����, ���ֹ��ܸ�֮ǰһ�� */
stream_pr->stream_killed_flag = 1;
@@ -2603,8 +2605,11 @@ int MESA_kill_tcp(struct streaminfo *stream, const void *ext_raw_pkt)
pdetail_pr->auto_remedy_flag = sapp_global_val->config.stream.tcp.inject.auto_remedy;
pdetail_pr->drop_stream_flag = 1;
- /* �ⲿ����, ��һ��FD, ����KILL_TCP_RST_NUM��. */
- return ret;
+ if((ret1 < 0) && (ret2 < 0)){
+ return -1;
+ }
+
+ return 0;
}
#endif
@@ -2647,25 +2652,26 @@ static int __do_kill_tcp_synack(struct streaminfo *stream, const void *ext_raw_p
{
int i, ret, reserved_hdr_len, send_len = 0;
MESA_send_handle *send_handle;
- int thread_num = stream->threadnum;
+ int thread_num;
int low_net_layer_type;
tcp_rst_finger_mark_t *tcp_rst_finger;
const raw_pkt_t *raw_pkt = NULL;
struct streaminfo_private *stream_pr;
- sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_num]->sys_stat;
+ sapp_gval_mthread_sys_stat_t *local_sys_stat;
(void)ext_raw_pkt;
if(NULL == stream){
return -1;
}
-
+ thread_num = stream->threadnum;
stream_pr = (struct streaminfo_private *)stream;
send_handle = &g_send_handle[thread_num];
raw_pkt = (const raw_pkt_t *)stream_pr->raw_pkt;
if((NULL == raw_pkt) || (RAW_PKT_MAGIC_NUM != raw_pkt->magic_num)){
return -1;
}
+ local_sys_stat = &sapp_global_val->mthread_volatile[thread_num]->sys_stat;
//send_handle->user_arg = (void *)stream;
reserved_hdr_len = calc_reserved_hdr_len(stream, &low_net_layer_type, stream_pr->stream_c2s_route_dir ^ 1);
if((reserved_hdr_len < 0) || (-1 == low_net_layer_type)){
@@ -3007,13 +3013,13 @@ int __do_inject_pkt(struct streaminfo *stream, const char *payload, int payload_
{
int ret = -1, reserved_hdr_len, send_len = 0;
MESA_send_handle *send_handle;
- int thread_num = stream->threadnum;
+ int thread_num;
int low_net_layer_type;
int snd_routedir_reverse;
UCHAR stream_send_dir;
const raw_pkt_t *raw_pkt;
struct streaminfo_private *stream_pr;
- sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_num]->sys_stat;
+ sapp_gval_mthread_sys_stat_t *local_sys_stat;
(void)ext_raw_pkt;
@@ -3024,6 +3030,7 @@ int __do_inject_pkt(struct streaminfo *stream, const char *payload, int payload_
if(dir_check(snd_routedir) < 0){
return -1;
}
+ thread_num = stream->threadnum;
stream_pr = (struct streaminfo_private *)stream;
/* ��ı���ijЩ�ص�������ԭʼ������ΪIP��ͷ, ���Բ���Ҫ�������ԭʼ��, ��Ϣ���洢��˽�����ṹ���� */
@@ -3031,6 +3038,8 @@ int __do_inject_pkt(struct streaminfo *stream, const char *payload, int payload_
if((NULL == raw_pkt) || (RAW_PKT_MAGIC_NUM != raw_pkt->magic_num)){
return -1;
}
+
+ local_sys_stat = &sapp_global_val->mthread_volatile[thread_num]->sys_stat;
if(snd_routedir == stream->routedir){
snd_routedir_reverse = 0;
@@ -3239,13 +3248,13 @@ int __sapp_inject_pkt(struct streaminfo *raw_stream, enum sapp_inject_opt sio,
{
int ret = -1, reserved_hdr_len = 0, send_len = 0;
MESA_send_handle *send_handle;
- int thread_num = raw_stream->threadnum;
+ int thread_num;
int low_net_layer_type;
int snd_routedir_reverse;
UCHAR send_stream_dir;
const raw_pkt_t *raw_pkt;
struct streaminfo_private *raw_stream_pr;
- sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_num]->sys_stat;
+ sapp_gval_mthread_sys_stat_t *local_sys_stat;
int carry_layer_type;
struct streaminfo *inject_stream;
struct streaminfo_private *inject_stream_pr;
@@ -3257,11 +3266,11 @@ int __sapp_inject_pkt(struct streaminfo *raw_stream, enum sapp_inject_opt sio,
if(dir_check(snd_routedir) < 0){
return -1;
}
-
+ thread_num = raw_stream->threadnum;
carry_layer_type = raw_stream->addr.addrtype;
inject_stream = raw_stream;
inject_stream_pr = (struct streaminfo_private *)raw_stream;
-
+ local_sys_stat = &sapp_global_val->mthread_volatile[thread_num]->sys_stat;
if((SIO_EXCLUDE_THIS_LAYER_HDR & sio) != 0){
/* ������ǰ�� */
inject_stream = raw_stream->pfather;