diff options
| author | fengweihao <[email protected]> | 2023-08-02 16:55:56 +0800 |
|---|---|---|
| committer | fengweihao <[email protected]> | 2023-08-02 16:55:56 +0800 |
| commit | e43b4954b5b75ef5dd27974073b691a68bdbf9f7 (patch) | |
| tree | aa9c528b504f87414fd428cdbb895a070b5df270 /plugin/business/tsg-http/src | |
| parent | 2451bd795c801ac4bf961a28978fdf8a34dfcbfc (diff) | |
TSG-16126 修复Proxy Events日志中存在c2s和s2c有字节数为0的问题
Diffstat (limited to 'plugin/business/tsg-http/src')
| -rw-r--r-- | plugin/business/tsg-http/src/http_lua.cpp | 2 | ||||
| -rw-r--r-- | plugin/business/tsg-http/src/tsg_http.cpp | 13 | ||||
| -rw-r--r-- | plugin/business/tsg-http/src/tsg_logger.cpp | 15 |
3 files changed, 22 insertions, 8 deletions
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 |
