From 214f1b5c16a691a428614ed103535e719a7d384e Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 13 Apr 2023 16:44:18 +0200 Subject: [PATCH] MINOR: tree-wide: Replace several chn_prod() by the corresponding SC At many places, call to chn_prod() can be easily replaced by the corresponding SC. It is a bit easier to understand which side is manipulated. --- src/cli.c | 4 ++-- src/http_act.c | 2 +- src/http_ana.c | 25 ++++++++++++------------- src/stats.c | 2 +- src/tcp_rules.c | 16 ++++++++-------- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/cli.c b/src/cli.c index 5ac493580..1dc160da8 100644 --- a/src/cli.c +++ b/src/cli.c @@ -2692,7 +2692,7 @@ send_status: goto read_again; missing_data: - if (chn_prod(req)->flags & SC_FL_ABRT_DONE) { + if (s->scf->flags & SC_FL_ABRT_DONE) { /* There is no more request or a only a partial one and we * receive a close from the client, we can leave */ sc_schedule_shutdown(s->scf); @@ -2741,7 +2741,7 @@ int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit) return 0; } - if (chn_prod(rep)->flags & SC_FL_ABRT_DONE) { + if (s->scb->flags & SC_FL_ABRT_DONE) { /* stream cleanup */ pcli_write_prompt(s); diff --git a/src/http_act.c b/src/http_act.c index c80bc51fc..596e68c54 100644 --- a/src/http_act.c +++ b/src/http_act.c @@ -719,7 +719,7 @@ static enum act_parse_ret parse_http_set_status(const char **args, int *orig_arg static enum act_return http_action_reject(struct act_rule *rule, struct proxy *px, struct session *sess, struct stream *s, int flags) { - sc_must_kill_conn(chn_prod(&s->req)); + sc_must_kill_conn(s->scf); stream_abort(s); s->req.analysers &= AN_REQ_FLT_END; s->res.analysers &= AN_RES_FLT_END; diff --git a/src/http_ana.c b/src/http_ana.c index 3c46f2af9..4ec3a389b 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -114,7 +114,7 @@ int http_wait_for_request(struct stream *s, struct channel *req, int an_bit) /* An abort at this stage means we are performing a "destructive" * HTTP upgrade (TCP>H2). In this case, we can leave. */ - if (chn_prod(req)->flags & SC_FL_ABRT_DONE) { + if (s->scf->flags & SC_FL_ABRT_DONE) { s->logs.logwait = 0; s->logs.level = 0; stream_abort(s); @@ -766,7 +766,7 @@ int http_process_tarpit(struct stream *s, struct channel *req, int an_bit) * there and that the timeout has not expired. */ channel_dont_connect(req); - if (!(chn_prod(req)->flags & SC_FL_ABRT_DONE) && + if (!(s->scf->flags & SC_FL_ABRT_DONE) && !tick_is_expired(req->analyse_exp, now_ms)) { /* Be sure to drain all data from the request channel */ channel_htx_erase(req, htxbuf(&req->buf)); @@ -1002,7 +1002,7 @@ int http_request_forward_body(struct stream *s, struct channel *req, int an_bit) * it can be abused to exhaust source ports. */ if (s->be->options & PR_O_ABRT_CLOSE) { channel_auto_read(req); - if ((chn_prod(req)->flags & SC_FL_ABRT_DONE) && !(txn->flags & TX_CON_WANT_TUN)) + if ((s->scf->flags & SC_FL_ABRT_DONE) && !(txn->flags & TX_CON_WANT_TUN)) s->scb->flags |= SC_FL_NOLINGER; channel_auto_close(req); } @@ -1018,7 +1018,7 @@ int http_request_forward_body(struct stream *s, struct channel *req, int an_bit) missing_data_or_waiting: /* stop waiting for data if the input is closed before the end */ - if (msg->msg_state < HTTP_MSG_ENDING && chn_prod(req)->flags & SC_FL_ABRT_DONE) + if (msg->msg_state < HTTP_MSG_ENDING && (s->scf->flags & SC_FL_ABRT_DONE)) goto return_cli_abort; waiting: @@ -1294,9 +1294,8 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit) } /* 3: client abort with an abortonclose */ - else if ((chn_prod(rep)->flags & SC_FL_ABRT_DONE) && - (chn_prod(&s->req)->flags & SC_FL_ABRT_DONE) && - (s->scb->flags & SC_FL_SHUT_DONE)) { + else if ((s->scb->flags & (SC_FL_ABRT_DONE|SC_FL_SHUT_DONE)) == (SC_FL_ABRT_DONE|SC_FL_SHUT_DONE) && + (s->scf->flags & SC_FL_ABRT_DONE)) { _HA_ATOMIC_INC(&sess->fe->fe_counters.cli_aborts); _HA_ATOMIC_INC(&s->be->be_counters.cli_aborts); if (sess->listener && sess->listener->counters) @@ -1318,7 +1317,7 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit) } /* 4: close from server, capture the response if the server has started to respond */ - else if (chn_prod(rep)->flags & SC_FL_ABRT_DONE) { + else if (s->scb->flags & SC_FL_ABRT_DONE) { if ((txn->flags & TX_L7_RETRY) && (s->be->retry_type & PR_RE_DISCONNECTED)) { if (co_data(rep) || do_l7_retry(s, s->scb) == 0) { @@ -2060,7 +2059,7 @@ int http_response_forward_body(struct stream *s, struct channel *res, int an_bit if (htx->data != co_data(res)) goto missing_data_or_waiting; - if (!(msg->flags & HTTP_MSGF_XFER_LEN) && (chn_prod(res)->flags & SC_FL_ABRT_DONE)) { + if (!(msg->flags & HTTP_MSGF_XFER_LEN) && (s->scb->flags & SC_FL_ABRT_DONE)) { msg->msg_state = HTTP_MSG_ENDING; goto ending; } @@ -2128,8 +2127,8 @@ int http_response_forward_body(struct stream *s, struct channel *res, int an_bit * so we don't want to count this as a server abort. Otherwise it's a * server abort. */ - if (msg->msg_state < HTTP_MSG_ENDING && (chn_prod(res)->flags & SC_FL_ABRT_DONE)) { - if ((chn_prod(&s->req)->flags & SC_FL_ABRT_DONE) && + if (msg->msg_state < HTTP_MSG_ENDING && (s->scb->flags & SC_FL_ABRT_DONE)) { + if ((s->scf->flags & SC_FL_ABRT_DONE) && (s->scb->flags & SC_FL_SHUT_DONE)) goto return_cli_abort; /* If we have some pending data, we continue the processing */ @@ -2674,7 +2673,7 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis /* Always call the action function if defined */ if (rule->action_ptr) { if (sc_ep_test(s->scf, SE_FL_ERROR) || - ((chn_prod(&s->req)->flags & SC_FL_ABRT_DONE) && + ((s->scf->flags & SC_FL_ABRT_DONE) && (px->options & PR_O_ABRT_CLOSE))) act_opts |= ACT_OPT_FINAL; @@ -2837,7 +2836,7 @@ resume_execution: /* Always call the action function if defined */ if (rule->action_ptr) { if (sc_ep_test(s->scf, SE_FL_ERROR) || - ((chn_prod(&s->req)->flags & SC_FL_ABRT_DONE) && + ((s->scf->flags & SC_FL_ABRT_DONE) && (px->options & PR_O_ABRT_CLOSE))) act_opts |= ACT_OPT_FINAL; diff --git a/src/stats.c b/src/stats.c index 515c26003..529f7e6d4 100644 --- a/src/stats.c +++ b/src/stats.c @@ -4493,7 +4493,7 @@ static void http_stats_io_handler(struct appctx *appctx) if (appctx->st0 == STAT_HTTP_POST) { if (stats_process_http_post(sc)) appctx->st0 = STAT_HTTP_LAST; - else if (chn_prod(req)->flags & SC_FL_ABRT_DONE) + else if (s->scf->flags & SC_FL_ABRT_DONE) appctx->st0 = STAT_HTTP_DONE; } diff --git a/src/tcp_rules.c b/src/tcp_rules.c index ad86ac803..d6ba9fbc1 100644 --- a/src/tcp_rules.c +++ b/src/tcp_rules.c @@ -117,7 +117,7 @@ int tcp_inspect_request(struct stream *s, struct channel *req, int an_bit) */ if ((s->scf->flags & (SC_FL_EOI|SC_FL_ABRT_DONE)) || channel_full(req, global.tune.maxrewrite) || - sc_waiting_room(chn_prod(req)) || + sc_waiting_room(s->scf) || !s->be->tcp_req.inspect_delay || tick_is_expired(s->rules_exp, now_ms)) { partial = SMP_OPT_FINAL; /* Action may yield while the inspect_delay is not expired and there is no read error */ @@ -254,7 +254,7 @@ resume_execution: _HA_ATOMIC_INC(&sess->listener->counters->failed_req); reject: - sc_must_kill_conn(chn_prod(req)); + sc_must_kill_conn(s->scf); stream_abort(s); abort: @@ -299,7 +299,7 @@ int tcp_inspect_response(struct stream *s, struct channel *rep, int an_bit) * - if one rule returns KO, then return KO */ if ((s->scb->flags & (SC_FL_EOI|SC_FL_ABRT_DONE)) || channel_full(rep, global.tune.maxrewrite) || - sc_waiting_room(chn_prod(rep)) || + sc_waiting_room(s->scb) || !s->be->tcp_rep.inspect_delay || tick_is_expired(s->rules_exp, now_ms)) { partial = SMP_OPT_FINAL; /* Action may yield while the inspect_delay is not expired and there is no read error */ @@ -391,10 +391,10 @@ resume_execution: goto deny; } else if (rule->action == ACT_TCP_CLOSE) { - chn_prod(rep)->flags |= SC_FL_NOLINGER | SC_FL_NOHALF; - sc_must_kill_conn(chn_prod(rep)); - sc_abort(chn_prod(rep)); - sc_shutdown(chn_prod(rep)); + s->scb->flags |= SC_FL_NOLINGER | SC_FL_NOHALF; + sc_must_kill_conn(s->scb); + sc_abort(s->scb); + sc_shutdown(s->scb); s->last_rule_file = rule->conf.file; s->last_rule_line = rule->conf.line; goto end; @@ -451,7 +451,7 @@ resume_execution: _HA_ATOMIC_INC(&__objt_server(s->target)->counters.failed_resp); reject: - sc_must_kill_conn(chn_prod(rep)); + sc_must_kill_conn(s->scb); stream_abort(s); abort: