]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: stick-table: uniformize the different action_inc_gpc*()
authorWilly Tarreau <w@1wt.eu>
Sun, 17 May 2026 21:03:35 +0000 (23:03 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 17 May 2026 21:10:27 +0000 (23:10 +0200)
While action_inc_gpc1() explicitly checks if s->stkctr or sess->stkctr
are set since 2.8 with commit 6c0117168 ("MEDIUM: stick-table: set the
track-sc limit at boottime via tune.stick-counters"), action_inc_gpc0()
and the generic action_inc_gpc() still stuck to the old approach of not
checking them, causing confusion when reviewing the code.

Upon closer inspection, the only case where the pointer may be NULL is
when global.tune.nb_stk_ctr is zero, which happens when the global
section contains "tune.stick-counters 0". However in this case, the
config parser "parse_inc_gpc()" will reject any reference to any stick
counter, so in theory there is no problem.

Regardless, the difference of treatment between sibling functions remains
confusing and the check is cheap, so let's generalize it, it will save a
future reader from the need to inspect stream_new() and session_new().

src/stick_table.c

index f94d674ba5494d471d798e3c6fd60e6ee3a00f5e..dfe1cbae41b9cab45e30513bf9387321ea01f98a 100644 (file)
@@ -2675,10 +2675,12 @@ static enum act_return action_inc_gpc(struct act_rule *rule, struct proxy *px,
        struct stkctr *stkctr;
 
        /* Extract the stksess, return OK if no stksess available. */
-       if (s)
+       if (s && s->stkctr)
                stkctr = &s->stkctr[rule->arg.gpc.sc];
-       else
+       else if (sess->stkctr)
                stkctr = &sess->stkctr[rule->arg.gpc.sc];
+       else
+               return ACT_RET_CONT;
 
        ts = stkctr_entry(stkctr);
        if (ts) {
@@ -2716,10 +2718,12 @@ static enum act_return action_inc_gpc0(struct act_rule *rule, struct proxy *px,
        unsigned int period = 0;
 
        /* Extract the stksess, return OK if no stksess available. */
-       if (s)
+       if (s && s->stkctr)
                stkctr = &s->stkctr[rule->arg.gpc.sc];
-       else
+       else if (sess->stkctr)
                stkctr = &sess->stkctr[rule->arg.gpc.sc];
+       else
+               return ACT_RET_CONT;
 
        ts = stkctr_entry(stkctr);
        if (ts) {