summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faulet <cfaulet@haproxy.com>2020-09-24 10:30:15 +0200
committerChristopher Faulet <cfaulet@haproxy.com>2020-11-20 13:01:26 +0100
commit6650fdfb73319c0cc4c0fa7bf583b48f97f6034f (patch)
tree187c6b33c96927d21f7bb0e430ef982e2d5ab93d
parent8309c32e184ff138c9ab4d56742d2ab6e757e7ea (diff)
downloadhaproxy-6650fdfb73319c0cc4c0fa7bf583b48f97f6034f.tar.gz
MINOR: mux-h1: Split front/back h1 stream creation in 2 functions
Dedicated functions are now used to create frontend and backend H1 streams. h1c_frt_stream_new() is now used to create frontend H1 streams and h1c_bck_stream_new() to create backend ones. Both rely on h1s_new() function to allocate the stream itself. It is a bit easier to add specific processing depending we are on the frontend or the backend side.
-rw-r--r--src/mux_h1.c102
1 files changed, 67 insertions, 35 deletions
diff --git a/src/mux_h1.c b/src/mux_h1.c
index fc4300c31..c8aa52b8f 100644
--- a/src/mux_h1.c
+++ b/src/mux_h1.c
@@ -533,7 +533,7 @@ static struct conn_stream *h1s_new_cs(struct h1s *h1s, struct buffer *input)
return NULL;
}
-static struct h1s *h1s_create(struct h1c *h1c, struct conn_stream *cs, struct session *sess)
+static struct h1s *h1s_new(struct h1c *h1c)
{
struct h1s *h1s;
@@ -542,15 +542,11 @@ static struct h1s *h1s_create(struct h1c *h1c, struct conn_stream *cs, struct se
h1s = pool_alloc(pool_head_h1s);
if (!h1s)
goto fail;
-
h1s->h1c = h1c;
h1c->h1s = h1s;
-
- h1s->sess = sess;
-
- h1s->cs = NULL;
+ h1s->sess = NULL;
+ h1s->cs = NULL;
h1s->flags = H1S_F_WANT_KAL;
-
h1s->subs = NULL;
h1m_init_req(&h1s->req);
@@ -566,36 +562,66 @@ static struct h1s *h1s_create(struct h1c *h1c, struct conn_stream *cs, struct se
h1s->flags |= H1S_F_NOT_FIRST;
h1c->flags &= ~(H1C_F_CS_IDLE|H1C_F_WAIT_NEXT_REQ);
- if (!(h1c->flags & H1C_F_IS_BACK)) {
- if (h1c->px->options2 & PR_O2_REQBUG_OK)
- h1s->req.err_pos = -1;
+ TRACE_LEAVE(H1_EV_H1S_NEW, h1c->conn, h1s);
+ return h1s;
- /* For frontend connections we should always have a session */
- if (!sess)
- h1s->sess = sess = h1c->conn->owner;
- }
- else {
- if (h1c->px->options2 & PR_O2_RSPBUG_OK)
- h1s->res.err_pos = -1;
- }
+ fail:
+ TRACE_DEVEL("leaving in error", H1_EV_H1S_NEW|H1_EV_H1S_END|H1_EV_H1S_ERR, h1c->conn);
+ return NULL;
+}
+
+static struct h1s *h1c_frt_stream_new(struct h1c *h1c)
+{
+ struct session *sess = h1c->conn->owner;
+ struct h1s *h1s;
+
+ TRACE_ENTER(H1_EV_H1S_NEW, h1c->conn);
+
+ h1s = h1s_new(h1c);
+ if (!h1s)
+ goto fail;
+
+ h1s->sess = sess;
+
+ if (h1c->px->options2 & PR_O2_REQBUG_OK)
+ h1s->req.err_pos = -1;
+
+ if (!h1s_new_cs(h1s, &BUF_NULL))
+ goto fail_cs;
- /* If a conn_stream already exists, attach it to this H1S. Otherwise we
- * create a new one.
- */
- if (cs) {
- cs->ctx = h1s;
- h1s->cs = cs;
- }
- else {
- cs = h1s_new_cs(h1s, &BUF_NULL);
- if (!cs)
- goto fail;
- }
TRACE_LEAVE(H1_EV_H1S_NEW, h1c->conn, h1s);
return h1s;
- fail:
+ fail_cs:
pool_free(pool_head_h1s, h1s);
+ fail:
+ sess_log(sess);
+ TRACE_DEVEL("leaving in error", H1_EV_H1S_NEW|H1_EV_H1S_END|H1_EV_H1S_ERR, h1c->conn);
+ return NULL;
+}
+
+static struct h1s *h1c_bck_stream_new(struct h1c *h1c, struct conn_stream *cs, struct session *sess)
+{
+ struct h1s *h1s;
+
+ TRACE_ENTER(H1_EV_H1S_NEW, h1c->conn);
+
+ h1s = h1s_new(h1c);
+ if (!h1s)
+ goto fail;
+
+ h1s->cs = cs;
+ h1s->sess = sess;
+ cs->ctx = h1s;
+
+
+ if (h1c->px->options2 & PR_O2_RSPBUG_OK)
+ h1s->res.err_pos = -1;
+
+ TRACE_LEAVE(H1_EV_H1S_NEW, h1c->conn, h1s);
+ return h1s;
+
+ fail:
TRACE_DEVEL("leaving in error", H1_EV_H1S_NEW|H1_EV_H1S_END|H1_EV_H1S_ERR, h1c->conn);
return NULL;
}
@@ -689,8 +715,14 @@ static int h1_init(struct connection *conn, struct proxy *proxy, struct session
conn->ctx = h1c;
/* Always Create a new H1S */
- if (!h1s_create(h1c, conn_ctx, sess))
- goto fail;
+ if (!(h1c->flags & H1C_F_IS_BACK)) {
+ if (!h1c_frt_stream_new(h1c))
+ goto fail;
+ }
+ else {
+ if (!h1c_bck_stream_new(h1c, conn_ctx, sess))
+ goto fail;
+ }
if (t)
task_queue(t);
@@ -2130,7 +2162,7 @@ static int h1_process(struct h1c * h1c)
goto release;
if (!(h1c->flags & H1C_F_IS_BACK) && (h1c->flags & H1C_F_CS_IDLE)) {
TRACE_STATE("K/A incoming connection, create new H1 stream", H1_EV_H1C_WAKE, conn);
- if (!h1s_create(h1c, NULL, NULL))
+ if (!h1c_frt_stream_new(h1c))
goto release;
}
else
@@ -2331,7 +2363,7 @@ static struct conn_stream *h1_attach(struct connection *conn, struct session *se
goto end;
}
- h1s = h1s_create(h1c, cs, sess);
+ h1s = h1c_bck_stream_new(h1c, cs, sess);
if (h1s == NULL) {
TRACE_DEVEL("leaving on h1s creation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, conn);
goto end;