1.修改HTTP2命中block规则后,页面无法显示问题

2.上次漏提代码对ex_data释放接口
This commit is contained in:
fengweihao
2019-05-28 17:38:19 +08:00
parent f106facd7b
commit 3339ffd533
2 changed files with 62 additions and 18 deletions

View File

@@ -92,6 +92,7 @@ enum manipulate_profile_table
struct manipulate_profile
{
int profile_id;
int ref_cnt;
size_t msg_len;
char *profile_name;
char *profile_msg;
@@ -629,8 +630,10 @@ void ma_profile_table_new_cb(int table_id, const char* key, const char* table_li
return;
}
struct manipulate_profile* ply_profile=ALLOC(struct manipulate_profile, 1);
memset(ply_profile, 0, sizeof(struct manipulate_profile));
ply_profile->profile_id=profile_id;
ply_profile->ref_cnt=1;
if(strcasecmp(formate, "template") == 0)
{
ply_profile->tpl = ctemplate::Template::GetTemplate(profile_path, ctemplate::DO_NOT_STRIP);
@@ -652,16 +655,27 @@ void ma_profile_table_new_cb(int table_id, const char* key, const char* table_li
void ma_profile_table_free_cb(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void *argp)
{
struct manipulate_profile* ply_obj=(struct manipulate_profile*)(*ad);
FREE(&ply_obj->profile_type);
FREE(&ply_obj->profile_msg);
FREE(&ply_obj->profile_name);
FREE(&ply_obj);
*ad=NULL;
ply_obj->ref_cnt--;
if (ply_obj->ref_cnt==0)
{
FREE(&ply_obj->profile_type);
FREE(&ply_obj->profile_msg);
FREE(&ply_obj->profile_name);
FREE(&ply_obj);
*ad=NULL;
}
}
void ma_profile_table_free(struct manipulate_profile* ply_obj)
{
ma_profile_table_free_cb(0, (void **)&ply_obj, 0, NULL);
}
void ma_profile_table_dup_cb(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from, long argl, void *argp)
{
struct manipulate_profile* ply_obj=(struct manipulate_profile*)(*from);
ply_obj->ref_cnt++;
*to=ply_obj;
}
@@ -892,7 +906,6 @@ struct pangu_http_ctx
struct cache_mid* cmid;
struct Maat_rule_t * enforce_rules;
size_t n_enforce;
char * enforce_para;
struct policy_action_param *param;
struct evbuffer* log_req_body, *log_resp_body;
@@ -968,7 +981,8 @@ static void pangu_http_ctx_free(struct pangu_http_ctx * ctx)
ctx->ins_ctx = NULL;
}
FREE(&ctx->enforce_rules);
FREE(&ctx->enforce_para);
policy_action_param_free(ctx->param);
ctx->param=NULL;
Maat_clean_status(&(ctx->scan_mid));
ctx->scan_mid = NULL;
@@ -1191,8 +1205,10 @@ static int html_generate(int profile_id, const char* msg, char ** page_buff, siz
*page_size = block_profile->msg_len;
*page_buff = tfe_strdup(block_profile->profile_msg);
}
ma_profile_table_free(block_profile);
block_profile=NULL;
return ret;
return ret;
}
static void html_free(char ** page_buff)
@@ -1523,7 +1539,8 @@ static void http_hijack(const struct tfe_http_session * session, enum tfe_http_e
tfe_http_half_append_body(response, NULL, 0, 0);
tfe_http_session_response_set(to_write_sess, response);
tfe_http_session_detach(session);
hijack_profile=NULL;
ma_profile_table_free(hijack_profile);
hijack_profile = NULL;
return;
}
@@ -1543,7 +1560,8 @@ static int format_insert_rule(int profile_id, const char* insert_position, struc
if (insert_position)
rule->position=tfe_strdup(insert_position);
insert_profile=NULL;
ma_profile_table_free(insert_profile);
insert_profile = NULL;
return ret;
}

View File

@@ -863,8 +863,11 @@ nghttp2_submit_frame_priority(struct tfe_session_info_t *session_info,const nght
dir, nghttp2_strerror(xret));
}
finish:
#ifdef TFE_LOG_HTTP2
TFE_LOG_DEBUG(logger()->handle, "%s, %d, submit priority, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
dir, frame->hd.stream_id, session_info->stream_action);
#endif
session_info->stream_action = stream_action;
return 0;
}
@@ -895,8 +898,11 @@ nghttp2_submit_frame_rst_stream(struct tfe_session_info_t *session_info,const ng
}
finish:
session_info->stream_action = stream_action;
#ifdef TFE_LOG_HTTP2
TFE_LOG_DEBUG(logger()->handle, "%s, %d, submit rst stream, stream_id:%d, action:%d, error_code = %d", session_info->tf_stream->str_stream_info,
dir, frame->hd.stream_id, session_info->stream_action, rst_stream->error_code);
#endif
return 0;
}
@@ -937,9 +943,12 @@ nghttp2_submit_frame_settings(struct tfe_session_info_t *session_info,const nght
}
finish:
session_info->stream_action = stream_action;
#ifdef TFE_LOG_HTTP2
TFE_LOG_DEBUG(logger()->handle, "%s, %d, submit setting, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
dir, frame->hd.stream_id, session_info->stream_action);
return 0;
#endif
return 0;
}
static int
@@ -968,8 +977,11 @@ nghttp2_submit_frame_ping(struct tfe_session_info_t *session_info,const nghttp2_
}
finish:
session_info->stream_action = stream_action;
#ifdef TFE_LOG_HTTP2
TFE_LOG_DEBUG(logger()->handle, "%s, %d, submit ping, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
dir, frame->hd.stream_id, session_info->stream_action);
#endif
return 0;
}
@@ -1107,8 +1119,11 @@ nghttp2_submit_frame_window_update(struct tfe_session_info_t *session_info,const
}
finish:
session_info->stream_action = stream_action;
#ifdef TFE_LOG_HTTP2
TFE_LOG_DEBUG(logger()->handle, "%s, %d, submit window update, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
dir, frame->hd.stream_id, session_info->stream_action);
#endif
return 0;
}
@@ -1161,10 +1176,6 @@ nghttp2_submit_end_data(struct tfe_session_info_t *session_info,
struct http2_half_private *resp = h2_stream->resp;
if (resp->body_state == MANAGE_STAGE_INIT){
nghttp2_submit_end_header(session_info, h2_stream);
}
if (resp->body_state != MANAGE_STAGE_INIT){
if (resp->event_cb) {
resp->event_cb(resp, EV_HTTP_RESP_BODY_END, NULL, 0,
@@ -1188,9 +1199,11 @@ nghttp2_submit_end_data(struct tfe_session_info_t *session_info,
TFE_LOG_ERROR(logger()->handle, "Fatal upstream send error: %s\n",nghttp2_strerror(xret));
}
}
#ifdef TFE_LOG_HTTP2
TFE_LOG_DEBUG(logger()->handle, "%s, 1, End of stream submit, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
h2_stream->stream_id, session_info->stream_action);
#endif
if (stream_action == ACTION_USER_DATA)
stream_action = ACTION_DROP_DATA;
session_info->stream_action = stream_action;
@@ -1354,8 +1367,11 @@ nghttp2_submit_frame_push_promise(struct tfe_session_info_t *session_info,const
}
session_info->stream_action = stream_action;
finish:
#ifdef TFE_LOG_HTTP2
TFE_LOG_DEBUG(logger()->handle, "%s, %d, submit push promise, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
dir, frame->hd.stream_id, session_info->stream_action);
#endif
return 0;
}
@@ -1682,7 +1698,7 @@ tfe_submit_response(struct tfe_session_info_t *session_info,
stream_action = nghttp2_server_frame_submit_response(session_info, h2_stream);
if (stream_action == ACTION_DROP_DATA){
xret = nghttp2_session_send(session_info->as_client);
xret = nghttp2_session_send(session_info->as_server);
if (xret != 0) {
stream_action = ACTION_FORWARD_DATA;
TFE_LOG_ERROR(logger()->handle, "Fatal downstream send error: %s\n",
@@ -1837,13 +1853,17 @@ nghttp2_submit_frame_header(struct tfe_session_info_t *session_info,const nghttp
if (frame->hd.flags & NGHTTP2_FLAG_END_HEADERS){
if (dir == CONN_DIR_UPSTREAM){
xret = nghttp2_server_submit_header(session_info, frame->hd.stream_id);
#ifdef TFE_LOG_HTTP2
TFE_LOG_DEBUG(logger()->handle, "%s, %d, submit response header, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
dir, frame->hd.stream_id, session_info->stream_action);
#endif
}
if (dir == CONN_DIR_DOWNSTREAM){
xret = nghttp2_client_submit_header(session_info, frame->hd.stream_id);
#ifdef TFE_LOG_HTTP2
TFE_LOG_DEBUG(logger()->handle, "%s, %d, submit request header, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
dir, frame->hd.stream_id, session_info->stream_action);
#endif
}
}
return xret;
@@ -2111,11 +2131,14 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
xret = nghttp2_session_send(session_info->as_server);
if (xret != 0) {
stream_action = ACTION_FORWARD_DATA;
TFE_LOG_ERROR(logger()->handle, "Fatal upstream send error: %s\n",nghttp2_strerror(xret));
TFE_LOG_ERROR(logger()->handle, "Fatal upstream(%d) send error: %s\n",stream_id, nghttp2_strerror(xret));
}
}
#ifdef TFE_LOG_HTTP2
TFE_LOG_DEBUG(logger()->handle, "%s, 1, submit data %d, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
(int)input_len, stream_id, stream_action);
#endif
if (stream_action == ACTION_USER_DATA)
stream_action = ACTION_DROP_DATA;
session_info->stream_action = stream_action;
@@ -2402,8 +2425,11 @@ nghttp2_server_on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
TFE_LOG_ERROR(logger()->handle, "Fatal upstream send error: %s\n",nghttp2_strerror(xret));
}
}
#ifdef TFE_LOG_HTTP2
TFE_LOG_INFO(logger()->handle, "%s, %d, submit data %d, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
0, (int)input_len, stream_id, session_info->stream_action);
#endif
if (stream_action == ACTION_USER_DATA)
stream_action = ACTION_DROP_DATA;
session_info->stream_action = stream_action;