From: Christopher Faulet Date: Mon, 4 Apr 2022 09:06:31 +0000 (+0200) Subject: MINOR: stream: Use conn-stream to report server error X-Git-Tag: v2.6-dev6~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0eb32c0dd19d25730ceddb4daf1acbd8708e4818;p=thirdparty%2Fhaproxy.git MINOR: stream: Use conn-stream to report server error the stream's srv_error callback function now manipulates a conn-stream instead of a stream-interface. --- diff --git a/include/haproxy/http_ana.h b/include/haproxy/http_ana.h index 73425a6447..a23e55832d 100644 --- a/include/haproxy/http_ana.h +++ b/include/haproxy/http_ana.h @@ -50,10 +50,10 @@ int http_res_set_status(unsigned int status, struct ist reason, struct stream *s void http_check_request_for_cacheability(struct stream *s, struct channel *req); void http_check_response_for_cacheability(struct stream *s, struct channel *res); enum rule_result http_wait_for_msg_body(struct stream *s, struct channel *chn, unsigned int time, unsigned int bytes); -void http_perform_server_redirect(struct stream *s, struct stream_interface *si); -void http_server_error(struct stream *s, struct stream_interface *si, int err, int finst, struct http_reply *msg); +void http_perform_server_redirect(struct stream *s, struct conn_stream *cs); +void http_server_error(struct stream *s, struct conn_stream *cs, int err, int finst, struct http_reply *msg); void http_reply_and_close(struct stream *s, short status, struct http_reply *msg); -void http_return_srv_error(struct stream *s, struct stream_interface *si); +void http_return_srv_error(struct stream *s, struct conn_stream *cs); struct http_reply *http_error_message(struct stream *s); int http_reply_to_htx(struct stream *s, struct htx *htx, struct http_reply *reply); int http_reply_message(struct stream *s, struct http_reply *reply); diff --git a/include/haproxy/stream-t.h b/include/haproxy/stream-t.h index 0753200613..592fe0b938 100644 --- a/include/haproxy/stream-t.h +++ b/include/haproxy/stream-t.h @@ -195,7 +195,7 @@ struct stream { void (*do_log)(struct stream *s); /* the function to call in order to log (or NULL) */ void (*srv_error)(struct stream *s, /* the function to call upon unrecoverable server errors (or NULL) */ - struct stream_interface *si); + struct conn_stream *cs); int pcli_next_pid; /* next target PID to use for the CLI proxy */ int pcli_flags; /* flags for CLI proxy */ diff --git a/include/haproxy/stream.h b/include/haproxy/stream.h index 32070178a5..b77c9930f2 100644 --- a/include/haproxy/stream.h +++ b/include/haproxy/stream.h @@ -73,7 +73,7 @@ struct ist stream_generate_unique_id(struct stream *strm, struct list *format); void stream_process_counters(struct stream *s); void sess_change_server(struct stream *strm, struct server *newsrv); struct task *process_stream(struct task *t, void *context, unsigned int state); -void default_srv_error(struct stream *s, struct stream_interface *si); +void default_srv_error(struct stream *s, struct conn_stream *cs); /* Update the stream's backend and server time stats */ void stream_update_time_stats(struct stream *s); diff --git a/src/backend.c b/src/backend.c index 8983e1d010..3232f0e617 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1995,7 +1995,7 @@ void back_try_conn_req(struct stream *s) /* no stream was ever accounted for this server */ cs->state = CS_ST_CLO; if (s->srv_error) - s->srv_error(s, cs->si); + s->srv_error(s, cs); DBG_TRACE_STATE("internal error during connection", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s); goto end; } @@ -2050,7 +2050,7 @@ void back_try_conn_req(struct stream *s) s->conn_err_type = STRM_ET_QUEUE_TO; cs->state = CS_ST_CLO; if (s->srv_error) - s->srv_error(s, cs->si); + s->srv_error(s, cs); DBG_TRACE_STATE("connection request still queued", STRM_EV_STRM_PROC|STRM_EV_CS_ST, s); goto end; } @@ -2107,7 +2107,7 @@ abort_connection: cs_shutw(cs); cs->state = CS_ST_CLO; if (s->srv_error) - s->srv_error(s, cs->si); + s->srv_error(s, cs); DBG_TRACE_DEVEL("leaving on error", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s); return; } @@ -2147,7 +2147,7 @@ void back_handle_st_req(struct stream *s) s->conn_err_type = STRM_ET_CONN_RES; cs->state = CS_ST_CLO; if (s->srv_error) - s->srv_error(s, cs->si); + s->srv_error(s, cs); DBG_TRACE_STATE("failed to register applet", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s); goto end; } @@ -2182,7 +2182,7 @@ void back_handle_st_req(struct stream *s) s->conn_err_type = STRM_ET_CONN_OTHER; cs->state = CS_ST_CLO; if (s->srv_error) - s->srv_error(s, cs->si); + s->srv_error(s, cs); DBG_TRACE_STATE("connection request failed", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s); goto end; } @@ -2220,7 +2220,7 @@ void back_handle_st_con(struct stream *s) cs_shutw(cs); s->conn_err_type |= STRM_ET_CONN_ABRT; if (s->srv_error) - s->srv_error(s, cs->si); + s->srv_error(s, cs); /* Note: state = CS_ST_DIS now */ DBG_TRACE_STATE("client abort during connection attempt", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s); goto end; @@ -2319,7 +2319,7 @@ void back_handle_st_cer(struct stream *s) cs->state = CS_ST_CLO; if (s->srv_error) - s->srv_error(s, cs->si); + s->srv_error(s, cs); DBG_TRACE_STATE("connection failed", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s); goto end; @@ -2353,7 +2353,7 @@ void back_handle_st_cer(struct stream *s) cs->state = CS_ST_CLO; if (s->srv_error) - s->srv_error(s, cs->si); + s->srv_error(s, cs); DBG_TRACE_STATE("error resetting endpoint", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s); goto end; @@ -2436,7 +2436,7 @@ void back_handle_st_rdy(struct stream *s) cs_shutw(cs); s->conn_err_type |= STRM_ET_CONN_ABRT; if (s->srv_error) - s->srv_error(s, cs->si); + s->srv_error(s, cs); DBG_TRACE_STATE("client abort during connection attempt", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s); goto end; } diff --git a/src/cli.c b/src/cli.c index 77d8f0a686..ff1610e6ab 100644 --- a/src/cli.c +++ b/src/cli.c @@ -2759,7 +2759,7 @@ int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit) if (!s->conn_err_type) s->conn_err_type = STRM_ET_CONN_OTHER; if (s->srv_error) - s->srv_error(s, cs_si(s->csb)); + s->srv_error(s, s->csb); return 1; } } diff --git a/src/http_ana.c b/src/http_ana.c index 62befbd1df..bf444051ca 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -4197,7 +4197,7 @@ enum rule_result http_wait_for_msg_body(struct stream *s, struct channel *chn, goto end; } -void http_perform_server_redirect(struct stream *s, struct stream_interface *si) +void http_perform_server_redirect(struct stream *s, struct conn_stream *cs) { struct channel *req = &s->req; struct channel *res = &s->res; @@ -4260,10 +4260,10 @@ void http_perform_server_redirect(struct stream *s, struct stream_interface *si) goto fail; /* return without error. */ - cs_shutr(si->cs); - cs_shutw(si->cs); + cs_shutr(cs); + cs_shutw(cs); s->conn_err_type = STRM_ET_NONE; - si->cs->state = CS_ST_CLO; + cs->state = CS_ST_CLO; if (!(s->flags & SF_ERR_MASK)) s->flags |= SF_ERR_LOCAL; @@ -4586,7 +4586,7 @@ int http_forward_proxy_resp(struct stream *s, int final) return 1; } -void http_server_error(struct stream *s, struct stream_interface *si, int err, +void http_server_error(struct stream *s, struct conn_stream *cs, int err, int finst, struct http_reply *msg) { http_reply_and_close(s, s->txn->status, msg); @@ -4808,50 +4808,50 @@ int http_reply_message(struct stream *s, struct http_reply *reply) * Note that connection errors appearing on the second request of a keep-alive * connection are not reported since this allows the client to retry. */ -void http_return_srv_error(struct stream *s, struct stream_interface *si) +void http_return_srv_error(struct stream *s, struct conn_stream *cs) { int err_type = s->conn_err_type; /* set s->txn->status for http_error_message(s) */ if (err_type & STRM_ET_QUEUE_ABRT) { s->txn->status = -1; - http_server_error(s, si, SF_ERR_CLICL, SF_FINST_Q, NULL); + http_server_error(s, cs, SF_ERR_CLICL, SF_FINST_Q, NULL); } else if (err_type & STRM_ET_CONN_ABRT) { s->txn->status = -1; - http_server_error(s, si, SF_ERR_CLICL, SF_FINST_C, NULL); + http_server_error(s, cs, SF_ERR_CLICL, SF_FINST_C, NULL); } else if (err_type & STRM_ET_QUEUE_TO) { s->txn->status = 503; - http_server_error(s, si, SF_ERR_SRVTO, SF_FINST_Q, + http_server_error(s, cs, SF_ERR_SRVTO, SF_FINST_Q, http_error_message(s)); } else if (err_type & STRM_ET_QUEUE_ERR) { s->txn->status = 503; - http_server_error(s, si, SF_ERR_SRVCL, SF_FINST_Q, + http_server_error(s, cs, SF_ERR_SRVCL, SF_FINST_Q, http_error_message(s)); } else if (err_type & STRM_ET_CONN_TO) { s->txn->status = 503; - http_server_error(s, si, SF_ERR_SRVTO, SF_FINST_C, + http_server_error(s, cs, SF_ERR_SRVTO, SF_FINST_C, (s->txn->flags & TX_NOT_FIRST) ? NULL : http_error_message(s)); } else if (err_type & STRM_ET_CONN_ERR) { s->txn->status = 503; - http_server_error(s, si, SF_ERR_SRVCL, SF_FINST_C, + http_server_error(s, cs, SF_ERR_SRVCL, SF_FINST_C, (s->flags & SF_SRV_REUSED) ? NULL : http_error_message(s)); } else if (err_type & STRM_ET_CONN_RES) { s->txn->status = 503; - http_server_error(s, si, SF_ERR_RESOURCE, SF_FINST_C, + http_server_error(s, cs, SF_ERR_RESOURCE, SF_FINST_C, (s->txn->flags & TX_NOT_FIRST) ? NULL : http_error_message(s)); } else { /* STRM_ET_CONN_OTHER and others */ s->txn->status = 500; - http_server_error(s, si, SF_ERR_INTERNAL, SF_FINST_C, + http_server_error(s, cs, SF_ERR_INTERNAL, SF_FINST_C, http_error_message(s)); } } diff --git a/src/stream.c b/src/stream.c index e74a4cfbd9..40a79d00f8 100644 --- a/src/stream.c +++ b/src/stream.c @@ -2306,7 +2306,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) srv = objt_server(s->target); if (s->csb->state == CS_ST_ASS && srv && srv->rdr_len && (s->flags & SF_REDIRECTABLE)) - http_perform_server_redirect(s, si_b); + http_perform_server_redirect(s, s->csb); } while (s->csb->state == CS_ST_ASS); } @@ -2686,9 +2686,9 @@ void sess_change_server(struct stream *strm, struct server *newsrv) /* Handle server-side errors for default protocols. It is called whenever a a * connection setup is aborted or a request is aborted in queue. It sets the * stream termination flags so that the caller does not have to worry about - * them. It's installed as ->srv_error for the server-side stream_interface. + * them. It's installed as ->srv_error for the server-side conn_stream. */ -void default_srv_error(struct stream *s, struct stream_interface *si) +void default_srv_error(struct stream *s, struct conn_stream *cs) { int err_type = s->conn_err_type; int err = 0, fin = 0;