]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: checks/sample: Remove unnecessary tests on the sample session
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 6 May 2020 07:42:04 +0000 (09:42 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 6 May 2020 10:44:46 +0000 (12:44 +0200)
A sample must always have a session defined. Otherwise, it is a bug. So it is
unnecessary to test if it is defined when called from a health checks context.

This patch fixes the issue #616.

src/backend.c
src/http_fetch.c
src/payload.c
src/ssl_sock.c

index 472d905533b73b537630c66c776618fb8f396415..2a592473047dc45a023e586da89cede851ff2617 100644 (file)
@@ -2548,7 +2548,7 @@ smp_fetch_be_id(const struct arg *args, struct sample *smp, const char *kw, void
 
        if (smp->strm)
                px = smp->strm->be;
-       else if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       else if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                px = __objt_check(smp->sess->origin)->proxy;
        if (!px)
                return 0;
@@ -2567,7 +2567,7 @@ smp_fetch_be_name(const struct arg *args, struct sample *smp, const char *kw, vo
 
        if (smp->strm)
                px = smp->strm->be;
-       else if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       else if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                px = __objt_check(smp->sess->origin)->proxy;
        if (!px)
                return 0;
@@ -2591,7 +2591,7 @@ smp_fetch_srv_id(const struct arg *args, struct sample *smp, const char *kw, voi
 
        if (smp->strm)
                srv = objt_server(smp->strm->target);
-       else if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       else if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                srv = __objt_check(smp->sess->origin)->server;
        if (!srv)
                return 0;
@@ -2610,7 +2610,7 @@ smp_fetch_srv_name(const struct arg *args, struct sample *smp, const char *kw, v
 
        if (smp->strm)
                srv = objt_server(smp->strm->target);
-       else if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       else if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                srv = __objt_check(smp->sess->origin)->server;
        if (!srv)
                return 0;
index ff292b624675104cf735ab922f8a870c2e20c956..5fc68a9f227d2dec7eed9a7e9ba4c4b91f1da61c 100644 (file)
@@ -386,7 +386,7 @@ static int smp_fetch_rqver(const struct arg *args, struct sample *smp, const cha
 static int smp_fetch_stver(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
        struct channel *chn = SMP_RES_CHN(smp);
-       struct check *check = (smp->sess ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = objt_check(smp->sess->origin);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        struct htx_sl *sl;
        char *ptr;
@@ -415,7 +415,7 @@ static int smp_fetch_stver(const struct arg *args, struct sample *smp, const cha
 static int smp_fetch_stcode(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
        struct channel *chn = SMP_RES_CHN(smp);
-       struct check *check = (smp->sess ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = objt_check(smp->sess->origin);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        struct htx_sl *sl;
        char *ptr;
@@ -463,7 +463,7 @@ static int smp_fetch_hdrs(const struct arg *args, struct sample *smp, const char
 {
        /* possible keywords: req.hdrs, res.hdrs */
        struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
-       struct check *check = ((kw[2] == 's' && smp->sess) ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        struct buffer *temp;
        int32_t pos;
@@ -510,7 +510,7 @@ static int smp_fetch_hdrs_bin(const struct arg *args, struct sample *smp, const
 {
        /* possible keywords: req.hdrs_bin, res.hdrs_bin */
        struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
-       struct check *check = ((kw[2] == 's' && smp->sess) ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        struct buffer *temp;
        char *p, *end;
@@ -579,7 +579,7 @@ static int smp_fetch_body(const struct arg *args, struct sample *smp, const char
 {
        /* possible keywords: req.body, res.body */
        struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
-       struct check *check = ((kw[2] == 's' && smp->sess) ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        struct buffer *temp;
        int32_t pos;
@@ -614,7 +614,7 @@ static int smp_fetch_body_len(const struct arg *args, struct sample *smp, const
 {
        /* possible keywords: req.body_len, res.body_len */
        struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
-       struct check *check = ((kw[2] == 's' && smp->sess) ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        int32_t pos;
        unsigned long long len = 0;
@@ -647,7 +647,7 @@ static int smp_fetch_body_size(const struct arg *args, struct sample *smp, const
 {
        /* possible keywords: req.body_size, res.body_size */
        struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
-       struct check *check = ((kw[2] == 's' && smp->sess) ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        int32_t pos;
        unsigned long long len = 0;
@@ -744,7 +744,7 @@ static int smp_fetch_fhdr(const struct arg *args, struct sample *smp, const char
 {
        /* possible keywords: req.fhdr, res.fhdr */
        struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
-       struct check *check = ((kw[2] == 's' && smp->sess) ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        struct http_hdr_ctx *ctx = smp->ctx.a[0];
        struct ist name;
@@ -798,7 +798,7 @@ static int smp_fetch_fhdr_cnt(const struct arg *args, struct sample *smp, const
 {
        /* possible keywords: req.fhdr_cnt, res.fhdr_cnt */
        struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
-       struct check *check = ((kw[2] == 's' && smp->sess) ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        struct http_hdr_ctx ctx;
        struct ist name;
@@ -829,7 +829,7 @@ static int smp_fetch_hdr_names(const struct arg *args, struct sample *smp, const
 {
        /* possible keywords: req.hdr_names, res.hdr_names */
        struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
-       struct check *check = ((kw[2] == 's' && smp->sess) ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        struct buffer *temp;
        char del = ',';
@@ -875,7 +875,7 @@ static int smp_fetch_hdr(const struct arg *args, struct sample *smp, const char
 {
        /* possible keywords: req.hdr / hdr, res.hdr / shdr */
        struct channel *chn = ((kw[0] == 'h' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
-       struct check *check = (((kw[0] == 's' || kw[2] == 's') && smp->sess) ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = ((kw[0] == 's' || kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        struct http_hdr_ctx *ctx = smp->ctx.a[0];
        struct ist name;
@@ -939,7 +939,7 @@ static int smp_fetch_hdr_cnt(const struct arg *args, struct sample *smp, const c
 {
        /* possible keywords: req.hdr_cnt / hdr_cnt, res.hdr_cnt / shdr_cnt */
        struct channel *chn = ((kw[0] == 'h' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
-       struct check *check = (((kw[0] == 's' || kw[2] == 's') && smp->sess) ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = ((kw[0] == 's' || kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        struct http_hdr_ctx ctx;
        struct ist name;
@@ -1563,7 +1563,7 @@ static int smp_fetch_cookie(const struct arg *args, struct sample *smp, const ch
 {
        /* possible keywords: req.cookie / cookie / cook, res.cookie / scook / set-cookie */
        struct channel *chn = ((kw[0] == 'c' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
-       struct check *check = (((kw[0] == 's' || kw[2] == 's') && smp->sess) ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = ((kw[0] == 's' || kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        struct http_hdr_ctx *ctx = smp->ctx.a[2];
        struct ist hdr;
@@ -1661,7 +1661,7 @@ static int smp_fetch_cookie_cnt(const struct arg *args, struct sample *smp, cons
 {
        /* possible keywords: req.cook_cnt / cook_cnt, res.cook_cnt / scook_cnt */
        struct channel *chn = ((kw[0] == 'c' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
-       struct check *check = (((kw[0] == 's' || kw[2] == 's') && smp->sess) ? objt_check(smp->sess->origin) : NULL);
+       struct check *check = ((kw[0] == 's' || kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
        struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
        struct http_hdr_ctx ctx;
        struct ist hdr;
index 00e9467cada442f404117c6a2380403b681265b7..05201ffbb3ce84548300717fd7ab008118d9a989 100644 (file)
@@ -58,7 +58,7 @@ smp_fetch_len(const struct arg *args, struct sample *smp, const char *kw, void *
                else
                        smp->data.u.sint = ci_data(chn);
        }
-       else if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) {
+       else if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) {
                struct check *check = __objt_check(smp->sess->origin);
                smp->data.u.sint = ((check->cs && IS_HTX_CS(check->cs)) ? (htxbuf(&check->bi))->data: b_data(&check->bi));
        }
@@ -979,7 +979,7 @@ smp_fetch_payload_lv(const struct arg *arg_p, struct sample *smp, const char *kw
                data = ci_data(chn);
                max  = global.tune.bufsize;
        }
-       else if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) {
+       else if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) {
                struct buffer *buf = &(__objt_check(smp->sess->origin)->bi);
                head = b_head(buf);
                data = b_data(buf);
@@ -1042,7 +1042,7 @@ smp_fetch_payload(const struct arg *arg_p, struct sample *smp, const char *kw, v
                data = ci_data(chn);
                max  = global.tune.bufsize;
        }
-       else if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) {
+       else if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) {
                struct buffer *buf = &(__objt_check(smp->sess->origin)->bi);
                head = b_head(buf);
                data = b_data(buf);
index dfaea05b7bf127ab34ed8a2974c6af97bd0784a6..8b02a1d662144b3ab047ba4f88b72ad0a94dbfff 100644 (file)
@@ -8470,7 +8470,7 @@ smp_fetch_ssl_fc(const struct arg *args, struct sample *smp, const char *kw, voi
 {
        struct connection *conn;
 
-       if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                conn = (kw[4] != 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
        else
                conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) :
@@ -8509,7 +8509,7 @@ smp_fetch_ssl_fc_is_resumed(const struct arg *args, struct sample *smp, const ch
        struct connection *conn;
        struct ssl_sock_ctx *ctx;
 
-       if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                conn = (kw[4] != 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
        else
                conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) :
@@ -8534,7 +8534,7 @@ smp_fetch_ssl_fc_cipher(const struct arg *args, struct sample *smp, const char *
        struct connection *conn;
        struct ssl_sock_ctx *ctx;
 
-       if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                conn = (kw[4] != 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
        else
                conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) :
@@ -8568,7 +8568,7 @@ smp_fetch_ssl_fc_alg_keysize(const struct arg *args, struct sample *smp, const c
        struct ssl_sock_ctx *ctx;
        int sint;
 
-       if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                conn = (kw[4] != 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
        else
                conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) :
@@ -8598,7 +8598,7 @@ smp_fetch_ssl_fc_use_keysize(const struct arg *args, struct sample *smp, const c
        struct connection *conn;
        struct ssl_sock_ctx *ctx;
 
-       if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                conn = (kw[4] != 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
        else
                conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) :
@@ -8629,7 +8629,7 @@ smp_fetch_ssl_fc_npn(const struct arg *args, struct sample *smp, const char *kw,
        smp->flags = SMP_F_CONST;
        smp->data.type = SMP_T_STR;
 
-       if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                conn = (kw[4] != 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
        else
                conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) :
@@ -8663,7 +8663,7 @@ smp_fetch_ssl_fc_alpn(const struct arg *args, struct sample *smp, const char *kw
        smp->flags = SMP_F_CONST;
        smp->data.type = SMP_T_STR;
 
-       if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                conn = (kw[4] != 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
        else
                conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) :
@@ -8696,7 +8696,7 @@ smp_fetch_ssl_fc_protocol(const struct arg *args, struct sample *smp, const char
        struct connection *conn;
        struct ssl_sock_ctx *ctx;
 
-       if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                conn = (kw[4] != 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
        else
                conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) :
@@ -8734,7 +8734,7 @@ smp_fetch_ssl_fc_session_id(const struct arg *args, struct sample *smp, const ch
        smp->flags = SMP_F_CONST;
        smp->data.type = SMP_T_BIN;
 
-       if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                conn = (kw[4] != 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
        else
                conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) :
@@ -8766,7 +8766,7 @@ smp_fetch_ssl_fc_random(const struct arg *args, struct sample *smp, const char *
        struct buffer *data;
        struct ssl_sock_ctx *ctx;
 
-       if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                conn = (kw[4] != 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
        else
                conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) :
@@ -8803,7 +8803,7 @@ smp_fetch_ssl_fc_session_key(const struct arg *args, struct sample *smp, const c
        struct buffer *data;
        struct ssl_sock_ctx *ctx;
 
-       if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                conn = (kw[4] != 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
        else
                conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) :
@@ -8961,7 +8961,7 @@ smp_fetch_ssl_fc_unique_id(const struct arg *args, struct sample *smp, const cha
        struct buffer *finished_trash;
        struct ssl_sock_ctx *ctx;
 
-       if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
                conn = (kw[4] != 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
        else
                conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) :