From: Willy Tarreau Date: Wed, 11 May 2022 14:11:24 +0000 (+0200) Subject: CLEANUP: conn_stream: merge cs_new_from_{mux,applet} into cs_new_from_endp() X-Git-Tag: v2.6-dev10~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6796a06278767ac71c90c3fe858ad889db78981a;p=thirdparty%2Fhaproxy.git CLEANUP: conn_stream: merge cs_new_from_{mux,applet} into cs_new_from_endp() The two functions became exact copies since there's no more special case for the appctx owner. Let's merge them into a single one, that simplifies the code. --- diff --git a/include/haproxy/conn_stream.h b/include/haproxy/conn_stream.h index ae2d9f0b94..4a567a5dc8 100644 --- a/include/haproxy/conn_stream.h +++ b/include/haproxy/conn_stream.h @@ -38,8 +38,7 @@ struct check; struct cs_endpoint *cs_endpoint_new(); void cs_endpoint_free(struct cs_endpoint *endp); -struct conn_stream *cs_new_from_mux(struct cs_endpoint *endp, struct session *sess, struct buffer *input); -struct conn_stream *cs_new_from_applet(struct cs_endpoint *endp, struct session *sess, struct buffer *input); +struct conn_stream *cs_new_from_endp(struct cs_endpoint *endp, struct session *sess, struct buffer *input); struct conn_stream *cs_new_from_strm(struct stream *strm, unsigned int flags); struct conn_stream *cs_new_from_check(struct check *check, unsigned int flags); void cs_free(struct conn_stream *cs); diff --git a/include/haproxy/mux_quic.h b/include/haproxy/mux_quic.h index 0086909fb1..08ff9a3587 100644 --- a/include/haproxy/mux_quic.h +++ b/include/haproxy/mux_quic.h @@ -91,7 +91,7 @@ static inline int qcc_install_app_ops(struct qcc *qcc, static inline struct conn_stream *qc_attach_cs(struct qcs *qcs, struct buffer *buf) { - if (!cs_new_from_mux(qcs->endp, qcs->qcc->conn->owner, buf)) + if (!cs_new_from_endp(qcs->endp, qcs->qcc->conn->owner, buf)) return NULL; ++qcs->qcc->nb_cs; diff --git a/src/conn_stream.c b/src/conn_stream.c index c13a2a1d1a..a37b4637ee 100644 --- a/src/conn_stream.c +++ b/src/conn_stream.c @@ -156,27 +156,7 @@ static struct conn_stream *cs_new(struct cs_endpoint *endp) * defined. It returns NULL on error. On success, the new conn-stream is * returned. In this case, CS_EP_ORPHAN flag is removed. */ -struct conn_stream *cs_new_from_mux(struct cs_endpoint *endp, struct session *sess, struct buffer *input) -{ - struct conn_stream *cs; - - cs = cs_new(endp); - if (unlikely(!cs)) - return NULL; - if (unlikely(!stream_new(sess, cs, input))) { - pool_free(pool_head_connstream, cs); - cs = NULL; - } - endp->flags &= ~CS_EP_ORPHAN; - return cs; -} - -/* Creates a new conn-stream and its associated stream from an applet. - * must be defined. It returns NULL on error. On success, the new conn-stream is - * returned. In this case, CS_EP_ORPHAN flag is removed. The created CS is used - * to set the appctx owner. - */ -struct conn_stream *cs_new_from_applet(struct cs_endpoint *endp, struct session *sess, struct buffer *input) +struct conn_stream *cs_new_from_endp(struct cs_endpoint *endp, struct session *sess, struct buffer *input) { struct conn_stream *cs; diff --git a/src/dns.c b/src/dns.c index 35ff61a6ad..bfd22c1b9e 100644 --- a/src/dns.c +++ b/src/dns.c @@ -938,7 +938,7 @@ static struct appctx *dns_session_create(struct dns_session *ds) if (!sockaddr_alloc(&addr, &ds->dss->srv->addr, sizeof(ds->dss->srv->addr))) goto out_free_sess; - cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL); + cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL); if (!cs) { ha_alert("Failed to initialize stream in dns_session_create().\n"); goto out_free_addr; diff --git a/src/flt_spoe.c b/src/flt_spoe.c index 59db4280e0..030ba9c8af 100644 --- a/src/flt_spoe.c +++ b/src/flt_spoe.c @@ -2026,7 +2026,7 @@ spoe_create_appctx(struct spoe_config *conf) if (!sess) goto out_free_spoe; - cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL); + cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL); if (!cs) goto out_free_sess; diff --git a/src/hlua.c b/src/hlua.c index 91a9f7cad2..ef967a5154 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -3004,7 +3004,7 @@ __LJMP static int hlua_socket_new(lua_State *L) goto out_fail_appctx; } - cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL); + cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL); if (!cs) { hlua_pusherror(L, "socket: out of memory"); goto out_fail_sess; diff --git a/src/http_client.c b/src/http_client.c index 1efb48496d..4daacea1da 100644 --- a/src/http_client.c +++ b/src/http_client.c @@ -607,7 +607,7 @@ struct appctx *httpclient_start(struct httpclient *hc) if (!sockaddr_alloc(&addr, ss_dst, sizeof(*ss_dst))) goto out_free_sess; - cs = cs_new_from_applet(appctx->endp, sess, &hc->req.buf); + cs = cs_new_from_endp(appctx->endp, sess, &hc->req.buf); if (!cs) { ha_alert("httpclient: Failed to initialize stream %s:%d.\n", __FUNCTION__, __LINE__); goto out_free_addr; diff --git a/src/mux_h1.c b/src/mux_h1.c index e41e6ef4ce..c5f0b03201 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -726,7 +726,7 @@ static struct conn_stream *h1s_new_cs(struct h1s *h1s, struct buffer *input) if (h1s->req.flags & H1_MF_UPG_WEBSOCKET) h1s->endp->flags |= CS_EP_WEBSOCKET; - if (!cs_new_from_mux(h1s->endp, h1c->conn->owner, input)) { + if (!cs_new_from_endp(h1s->endp, h1c->conn->owner, input)) { TRACE_ERROR("CS allocation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1c->conn, h1s); goto err; } diff --git a/src/mux_h2.c b/src/mux_h2.c index 6cb2334ba7..9ed272768c 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -1629,7 +1629,7 @@ static struct h2s *h2c_frt_stream_new(struct h2c *h2c, int id, struct buffer *in */ sess->t_idle = tv_ms_elapsed(&sess->tv_accept, &now) - sess->t_handshake; - if (!cs_new_from_mux(h2s->endp, sess, input)) + if (!cs_new_from_endp(h2s->endp, sess, input)) goto out_close; h2c->nb_cs++; diff --git a/src/mux_pt.c b/src/mux_pt.c index fa92ed6aac..821f558ba6 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -302,7 +302,7 @@ static int mux_pt_init(struct connection *conn, struct proxy *prx, struct sessio ctx->endp->ctx = conn; ctx->endp->flags |= (CS_EP_T_MUX|CS_EP_ORPHAN); - cs = cs_new_from_mux(ctx->endp, sess, input); + cs = cs_new_from_endp(ctx->endp, sess, input); if (!cs) { TRACE_ERROR("CS allocation failure", PT_EV_STRM_NEW|PT_EV_STRM_END|PT_EV_STRM_ERR, conn); goto fail_free_endp; diff --git a/src/peers.c b/src/peers.c index f521b55ea7..58f771b97d 100644 --- a/src/peers.c +++ b/src/peers.c @@ -3194,7 +3194,7 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer if (!sockaddr_alloc(&addr, &peer->addr, sizeof(peer->addr))) goto out_free_sess; - cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL); + cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL); if (!cs) { ha_alert("Failed to initialize stream in peer_session_create().\n"); goto out_free_addr; diff --git a/src/sink.c b/src/sink.c index 3dc4a4df2e..c52afc68dc 100644 --- a/src/sink.c +++ b/src/sink.c @@ -654,7 +654,7 @@ static struct appctx *sink_forward_session_create(struct sink *sink, struct sink if (!sockaddr_alloc(&addr, &sft->srv->addr, sizeof(sft->srv->addr))) goto out_free_sess; - cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL); + cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL); if (!cs) { ha_alert("Failed to initialize stream in sink_forward_session_create().\n"); goto out_free_addr;