]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample/arg: Be able to resolve args found in defaults sections
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 12 Oct 2021 16:48:05 +0000 (18:48 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 15 Oct 2021 12:12:19 +0000 (14:12 +0200)
It is not yet used but thanks to this patch, it will be possible to resolve
arguments found in defaults sections. However, there is some restrictions:

  * For FE (frontend) or BE (backend) arguments, if the proxy is explicity
    defined, there is no change. But for implicit proxy (not specified), the
    argument points on the default proxy. when a sample fetch using this
    kind of argument is evaluated, the default proxy replaced by the current
    one.

  * For SRV (server) and TAB (stick-table)arguments, the proxy must always
    be specified. Otherwise an error is reported.

This patch is mandatory to support TCP/HTTP rules in defaults sections.

src/backend.c
src/frontend.c
src/sample.c

index 6ec85ae1f8ff7dc074e381204d44b800cf9a6fc6..0a7875cdf311009536bb347ad4cd7f2ab2ca2eab 100644 (file)
@@ -2669,11 +2669,15 @@ int backend_parse_balance(const char **args, char **err, struct proxy *curproxy)
 static int
 smp_fetch_nbsrv(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-       struct proxy *px;
+       struct proxy *px = args->data.prx;
+
+       if (px == NULL)
+               return 0;
+       if (px->cap & PR_CAP_DEF)
+               px = smp->px;
 
        smp->flags = SMP_F_VOL_TEST;
        smp->data.type = SMP_T_SINT;
-       px = args->data.prx;
 
        smp->data.u.sint = be_usable_srv(px);
 
@@ -2708,12 +2712,18 @@ static int
 smp_fetch_connslots(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
        struct server *iterator;
+       struct proxy *px = args->data.prx;
+
+       if (px == NULL)
+               return 0;
+       if (px->cap & PR_CAP_DEF)
+               px = smp->px;
 
        smp->flags = SMP_F_VOL_TEST;
        smp->data.type = SMP_T_SINT;
        smp->data.u.sint = 0;
 
-       for (iterator = args->data.prx->srv; iterator; iterator = iterator->next) {
+       for (iterator = px->srv; iterator; iterator = iterator->next) {
                if (iterator->cur_state == SRV_ST_STOPPED)
                        continue;
 
@@ -2822,9 +2832,16 @@ smp_fetch_srv_name(const struct arg *args, struct sample *smp, const char *kw, v
 static int
 smp_fetch_be_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
+       struct proxy *px = args->data.prx;
+
+       if (px == NULL)
+               return 0;
+       if (px->cap & PR_CAP_DEF)
+               px = smp->px;
+
        smp->flags = SMP_F_VOL_TEST;
        smp->data.type = SMP_T_SINT;
-       smp->data.u.sint = read_freq_ctr(&args->data.prx->be_sess_per_sec);
+       smp->data.u.sint = read_freq_ctr(&px->be_sess_per_sec);
        return 1;
 }
 
@@ -2835,9 +2852,16 @@ smp_fetch_be_sess_rate(const struct arg *args, struct sample *smp, const char *k
 static int
 smp_fetch_be_conn(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
+       struct proxy *px = args->data.prx;
+
+       if (px == NULL)
+               return 0;
+       if (px->cap & PR_CAP_DEF)
+               px = smp->px;
+
        smp->flags = SMP_F_VOL_TEST;
        smp->data.type = SMP_T_SINT;
-       smp->data.u.sint = args->data.prx->beconn;
+       smp->data.u.sint = px->beconn;
        return 1;
 }
 
@@ -2850,14 +2874,19 @@ static int
 smp_fetch_be_conn_free(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
        struct server *iterator;
-       struct proxy *px;
+       struct proxy *px = args->data.prx;
        unsigned int maxconn;
 
+       if (px == NULL)
+               return 0;
+       if (px->cap & PR_CAP_DEF)
+               px = smp->px;
+
        smp->flags = SMP_F_VOL_TEST;
        smp->data.type = SMP_T_SINT;
        smp->data.u.sint = 0;
 
-       for (iterator = args->data.prx->srv; iterator; iterator = iterator->next) {
+       for (iterator = px->srv; iterator; iterator = iterator->next) {
                if (iterator->cur_state == SRV_ST_STOPPED)
                        continue;
 
@@ -2888,9 +2917,16 @@ smp_fetch_be_conn_free(const struct arg *args, struct sample *smp, const char *k
 static int
 smp_fetch_queue_size(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
+       struct proxy *px = args->data.prx;
+
+       if (px == NULL)
+               return 0;
+       if (px->cap & PR_CAP_DEF)
+               px = smp->px;
+
        smp->flags = SMP_F_VOL_TEST;
        smp->data.type = SMP_T_SINT;
-       smp->data.u.sint = args->data.prx->totpend;
+       smp->data.u.sint = px->totpend;
        return 1;
 }
 
@@ -2905,12 +2941,16 @@ smp_fetch_queue_size(const struct arg *args, struct sample *smp, const char *kw,
 static int
 smp_fetch_avg_queue_size(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
+       struct proxy *px = args->data.prx;
        int nbsrv;
-       struct proxy *px;
+
+       if (px == NULL)
+               return 0;
+       if (px->cap & PR_CAP_DEF)
+               px = smp->px;
 
        smp->flags = SMP_F_VOL_TEST;
        smp->data.type = SMP_T_SINT;
-       px = args->data.prx;
 
        nbsrv = be_usable_srv(px);
 
index 6aa1027013a5560a5ea5a69bde662a344d0a4907..f976cc83125422803d27833812a84a78c10fa47b 100644 (file)
@@ -211,9 +211,16 @@ smp_fetch_fe_defbe(const struct arg *args, struct sample *smp, const char *kw, v
 static int
 smp_fetch_fe_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
+       struct proxy *px = args->data.prx;
+
+       if (px == NULL)
+               return 0;
+       if (px->cap & PR_CAP_DEF)
+               px = smp->px;
+
        smp->flags = SMP_F_VOL_TEST;
        smp->data.type = SMP_T_SINT;
-       smp->data.u.sint = read_freq_ctr(&args->data.prx->fe_req_per_sec);
+       smp->data.u.sint = read_freq_ctr(&px->fe_req_per_sec);
        return 1;
 }
 
@@ -224,9 +231,16 @@ smp_fetch_fe_req_rate(const struct arg *args, struct sample *smp, const char *kw
 static int
 smp_fetch_fe_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
+       struct proxy *px = args->data.prx;
+
+       if (px == NULL)
+               return 0;
+       if (px->cap & PR_CAP_DEF)
+               px = smp->px;
+
        smp->flags = SMP_F_VOL_TEST;
        smp->data.type = SMP_T_SINT;
-       smp->data.u.sint = read_freq_ctr(&args->data.prx->fe_sess_per_sec);
+       smp->data.u.sint = read_freq_ctr(&px->fe_sess_per_sec);
        return 1;
 }
 
@@ -237,9 +251,16 @@ smp_fetch_fe_sess_rate(const struct arg *args, struct sample *smp, const char *k
 static int
 smp_fetch_fe_conn(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
+       struct proxy *px = args->data.prx;
+
+       if (px == NULL)
+               return 0;
+       if (px->cap & PR_CAP_DEF)
+               px = smp->px;
+
        smp->flags = SMP_F_VOL_TEST;
        smp->data.type = SMP_T_SINT;
-       smp->data.u.sint = args->data.prx->feconn;
+       smp->data.u.sint = px->feconn;
        return 1;
 }
 
index d5ce8ad6ce1191c6ad71eba65d32bd70b9732c13..9200ca30346b6e001b06bc3e4e379d7bf7625b1a 100644 (file)
@@ -1217,8 +1217,16 @@ int smp_resolve_args(struct proxy *p, char **err)
                                        break;
                                }
                        }
-                       else
+                       else {
+                               if (px->cap & PR_CAP_DEF) {
+                                       memprintf(err, "%sparsing [%s:%d]: backend name must be set in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n",
+                                                 *err ? *err : "", cur->file, cur->line,
+                                                 cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id);
+                                       cfgerr++;
+                                       break;
+                               }
                                sname = arg->data.str.area;
+                       }
 
                        srv = findserver(px, sname);
                        if (!srv) {
@@ -1293,8 +1301,16 @@ int smp_resolve_args(struct proxy *p, char **err)
                case ARGT_TAB:
                        if (arg->data.str.data)
                                stktname = arg->data.str.area;
-                       else
+                       else {
+                               if (px->cap & PR_CAP_DEF) {
+                                       memprintf(err, "%sparsing [%s:%d]: table name must be set in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n",
+                                                 *err ? *err : "", cur->file, cur->line,
+                                                 cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id);
+                                       cfgerr++;
+                                       break;
+                               }
                                stktname = px->id;
+                       }
 
                        t = stktable_find_by_name(stktname);
                        if (!t) {