summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorfengweihao <[email protected]>2023-08-02 16:55:56 +0800
committerfengweihao <[email protected]>2023-08-02 16:55:56 +0800
commite43b4954b5b75ef5dd27974073b691a68bdbf9f7 (patch)
treeaa9c528b504f87414fd428cdbb895a070b5df270 /plugin
parent2451bd795c801ac4bf961a28978fdf8a34dfcbfc (diff)
TSG-16126 修复Proxy Events日志中存在c2s和s2c有字节数为0的问题
Diffstat (limited to 'plugin')
-rw-r--r--plugin/business/tsg-http/include/tsg_proxy_logger.h2
-rw-r--r--plugin/business/tsg-http/src/http_lua.cpp2
-rw-r--r--plugin/business/tsg-http/src/tsg_http.cpp13
-rw-r--r--plugin/business/tsg-http/src/tsg_logger.cpp15
-rw-r--r--plugin/business/tsg-http/test/test_pattern_replace.cpp4
-rw-r--r--plugin/protocol/http2/src/http2_plugin.cpp1
-rw-r--r--plugin/protocol/http2/src/http2_stream.cpp4
7 files changed, 29 insertions, 12 deletions
diff --git a/plugin/business/tsg-http/include/tsg_proxy_logger.h b/plugin/business/tsg-http/include/tsg_proxy_logger.h
index 223ee8d..e8c656e 100644
--- a/plugin/business/tsg-http/include/tsg_proxy_logger.h
+++ b/plugin/business/tsg-http/include/tsg_proxy_logger.h
@@ -27,6 +27,8 @@ struct proxy_log
char *asn_server;
char *location_client;
char *location_server;
+ size_t c2s_byte_num;
+ size_t s2c_byte_num;
};
struct proxy_logger;
struct proxy_logger* proxy_log_handle_create(const char* profile, const char* section, void* local_logger);
diff --git a/plugin/business/tsg-http/src/http_lua.cpp b/plugin/business/tsg-http/src/http_lua.cpp
index aba6204..5894e22 100644
--- a/plugin/business/tsg-http/src/http_lua.cpp
+++ b/plugin/business/tsg-http/src/http_lua.cpp
@@ -462,7 +462,7 @@ static int http_lua_get_5tuple(struct elua_vm *vm)
return 0;
}
- char ip_addr[64]={0};
+ char ip_addr[128]={0};
unsigned int source=0,dest=0,protocol;
char src_ip_str[MAX(INET6_ADDRSTRLEN,INET_ADDRSTRLEN)] = {0};
char dst_ip_str[MAX(INET6_ADDRSTRLEN,INET_ADDRSTRLEN)] = {0};
diff --git a/plugin/business/tsg-http/src/tsg_http.cpp b/plugin/business/tsg-http/src/tsg_http.cpp
index 4d8a287..a72326d 100644
--- a/plugin/business/tsg-http/src/tsg_http.cpp
+++ b/plugin/business/tsg-http/src/tsg_http.cpp
@@ -1272,6 +1272,8 @@ struct proxy_http_ctx
struct cache_write_context* cache_write_ctx;
int cache_wirte_result;
+ size_t c2s_byte_num;
+ size_t s2c_byte_num;
int thread_id;
};
@@ -2027,7 +2029,7 @@ static void http_get_subscriber_id(const struct tfe_stream * stream, char *repla
{
int ret = 0;
uint16_t opt_out_size;
- char source_subscribe_id[TFE_STRING_MAX] = {0};
+ char source_subscribe_id[TFE_SYMBOL_MAX] = {0};
struct tfe_cmsg *cmsg = tfe_stream_get0_cmsg(stream);
if (cmsg != NULL)
{
@@ -2070,7 +2072,7 @@ static int http_regex_replace(const struct tfe_stream * stream, char *message, i
}
if(strcasestr(message,"tsg_subscriber_id") != NULL)
{
- memset(replace_with, TFE_SYMBOL_MAX, 0);
+ memset(replace_with, 0, TFE_SYMBOL_MAX);
rule[n_rule].zone = kZoneRequestUri;
rule[n_rule].find = tfe_strdup("{{tsg_subscriber_id}}");
http_get_subscriber_id(stream, replace_with);
@@ -2079,7 +2081,7 @@ static int http_regex_replace(const struct tfe_stream * stream, char *message, i
}
if(strcasestr(message,"tsg_client_ip") != NULL)
{
- memset(replace_with, TFE_SYMBOL_MAX, 0);
+ memset(replace_with, 0, TFE_SYMBOL_MAX);
rule[n_rule].zone = kZoneRequestUri;
rule[n_rule].find = tfe_strdup("{{tsg_client_ip}}");
http_get_client_id(stream, replace_with);
@@ -2840,6 +2842,9 @@ void enforce_control_policy(const struct tfe_stream * stream, const struct tfe_h
evbuffer_add(ctx->log_resp_body, body_frag, frag_size);
}
+ tfe_stream_info_get(stream, INFO_FROM_DOWNSTREAM_RX_OFFSET, &(ctx->c2s_byte_num), sizeof(ctx->c2s_byte_num));
+ tfe_stream_info_get(stream, INFO_FROM_UPSTREAM_RX_OFFSET, &(ctx->s2c_byte_num), sizeof(ctx->s2c_byte_num));
+
return;
}
#define RESUMED_CB_NO_MORE_CALLS 0
@@ -3341,7 +3346,7 @@ void proxy_on_http_end(const struct tfe_stream * stream,
struct proxy_log log_msg = {.stream=stream, .http=session, .result=(struct log_rule_t *)ctx->enforce_rules, .result_num=ctx->n_enforce,
.req_body=ctx->log_req_body, .resp_body=ctx->log_resp_body, .action=0, .inject_sz=ctx->inject_sz,
.asn_client=ctx->ip_ctx.asn_client, .asn_server=ctx->ip_ctx.asn_server, .location_client=ctx->ip_ctx.location_client,
- .location_server=ctx->ip_ctx.location_server};
+ .location_server=ctx->ip_ctx.location_server, .c2s_byte_num=ctx->c2s_byte_num, .s2c_byte_num=ctx->s2c_byte_num};
if(ctx->action == PX_ACTION_MANIPULATE)
{
log_msg.action = ctx->param->action;
diff --git a/plugin/business/tsg-http/src/tsg_logger.cpp b/plugin/business/tsg-http/src/tsg_logger.cpp
index 55b098d..ec289b4 100644
--- a/plugin/business/tsg-http/src/tsg_logger.cpp
+++ b/plugin/business/tsg-http/src/tsg_logger.cpp
@@ -217,9 +217,18 @@ int proxy_send_log(struct proxy_logger* handle, const struct proxy_log* log_msg)
default:
break;
}
- size_t c2s_byte_num = 0, s2c_byte_num =0;
- tfe_stream_info_get(log_msg->stream, INFO_FROM_DOWNSTREAM_RX_OFFSET, &c2s_byte_num, sizeof(c2s_byte_num));
- tfe_stream_info_get(log_msg->stream, INFO_FROM_UPSTREAM_RX_OFFSET, &s2c_byte_num, sizeof(s2c_byte_num));
+
+ size_t ret=0, c2s_byte_num = 0, s2c_byte_num =0;
+ ret = tfe_stream_info_get(log_msg->stream, INFO_FROM_DOWNSTREAM_RX_OFFSET, &c2s_byte_num, sizeof(c2s_byte_num));
+ if(ret != 0)
+ {
+ c2s_byte_num = log_msg->c2s_byte_num;
+ }
+ ret = tfe_stream_info_get(log_msg->stream, INFO_FROM_UPSTREAM_RX_OFFSET, &s2c_byte_num, sizeof(s2c_byte_num));
+ if(ret !=0)
+ {
+ s2c_byte_num = log_msg->s2c_byte_num;
+ }
cJSON_AddNumberToObject(common_obj, "common_link_id", 0);
cJSON_AddNumberToObject(common_obj, "common_stream_dir", 3); //1:c2s, 2:s2c, 3:double
diff --git a/plugin/business/tsg-http/test/test_pattern_replace.cpp b/plugin/business/tsg-http/test/test_pattern_replace.cpp
index 6e18057..9df3e88 100644
--- a/plugin/business/tsg-http/test/test_pattern_replace.cpp
+++ b/plugin/business/tsg-http/test/test_pattern_replace.cpp
@@ -198,7 +198,7 @@ TEST(PatternReplace, UrlReplace)
}
if(strcasestr(rd_url,"tsg_subscriber_id") != NULL)
{
- memset(replace_with, TFE_SYMBOL_MAX, 0);
+ memset(replace_with, 0, TFE_SYMBOL_MAX);
rule[n_rule].zone = kZoneRequestUri;
rule[n_rule].find = tfe_strdup("{{tsg_subscriber_id}}");
rule[n_rule].replace_with = tfe_strdup(" ");
@@ -206,7 +206,7 @@ TEST(PatternReplace, UrlReplace)
}
if(strcasestr(rd_url,"tsg_client_ip") != NULL)
{
- memset(replace_with, TFE_SYMBOL_MAX, 0);
+ memset(replace_with, 0, TFE_SYMBOL_MAX);
rule[n_rule].zone = kZoneRequestUri;
rule[n_rule].find = tfe_strdup("{{tsg_client_ip}}");
rule[n_rule].replace_with = tfe_strdup("192.168.50.71");
diff --git a/plugin/protocol/http2/src/http2_plugin.cpp b/plugin/protocol/http2/src/http2_plugin.cpp
index 8e69fd5..dd05678 100644
--- a/plugin/protocol/http2/src/http2_plugin.cpp
+++ b/plugin/protocol/http2/src/http2_plugin.cpp
@@ -139,7 +139,6 @@ search_up_stream_data(const unsigned char * data, size_t len)
return 1;
}
-
static enum tfe_stream_action
http2_stream_data(const struct tfe_stream * stream, unsigned int thread_id,
enum tfe_conn_dir dir, const unsigned char * data, size_t len, void ** pme)
diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp
index c96e0fa..13e37e8 100644
--- a/plugin/protocol/http2/src/http2_stream.cpp
+++ b/plugin/protocol/http2/src/http2_stream.cpp
@@ -1928,7 +1928,9 @@ static int http2_on_stream_close(nghttp2_session *session, const nghttp2_frame *
h2_session = TAILQ_LIST_FIND(h2_stream_info, stream_id);
if (!h2_session)
- return 0;
+ {
+ return 0;
+ }
if (error_code != 0){
const char *str = (dir == CONN_DIR_UPSTREAM) ? "Simulation s" : "Simulation c";
TFE_LOG_DEBUG(logger()->handle, "%s close, id = %d, error_code = %d", str,