]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: session: make the number of stick counter entries more configurable
authorWilly Tarreau <w@1wt.eu>
Tue, 23 Jul 2013 17:15:30 +0000 (19:15 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 1 Aug 2013 19:17:14 +0000 (21:17 +0200)
In preparation of more flexibility in the stick counters, make their
number configurable. It still defaults to 3 which is the minimum
accepted value. Changing the value alone is not sufficient to get
more counters, some bitfields still need to be updated and the TCP
actions need to be updated as well, but this update tries to be
easier, which is nice for experimentation purposes.

include/common/defaults.h
include/proto/session.h
include/types/proto_tcp.h
include/types/session.h
src/cfgparse.c
src/proto_tcp.c
src/session.c

index 5000d9c3debc929f0b36023b703aaf453e6cbb5f..874d2e2736524238837782cebeaf7306e0170c2c 100644 (file)
 #define MAX_HDR_HISTORY 10
 #endif
 
+// max # of stick counters per session (at least 3 for sc0..sc2)
+// Some changes are needed in TCP_ACT_TRK_SC* and SN_BE_TRACK_SC* if more
+// values are required.
+#ifndef MAX_SESS_STKCTR
+#define MAX_SESS_STKCTR 3
+#endif
+
 // max # of loops we can perform around a read() which succeeds.
 // It's very frequent that the system returns a few TCP segments at a time.
 #ifndef MAX_READ_POLL_LOOPS
index cc1242daab1b064d77afbbc02a67b1d5de63f202..f597d5977892678bcb866334c188f14dc6df2e94 100644 (file)
@@ -59,7 +59,7 @@ static inline void session_store_counters(struct session *s)
        void *ptr;
        int i;
 
-       for (i = 0; i < sizeof(s->stkctr) / sizeof(s->stkctr[0]); i++) {
+       for (i = 0; i < MAX_SESS_STKCTR; i++) {
                if (!s->stkctr[i].entry)
                        continue;
                ptr = stktable_data_ptr(s->stkctr[i].table, s->stkctr[i].entry, STKTABLE_DT_CONN_CUR);
@@ -83,7 +83,7 @@ static inline void session_stop_backend_counters(struct session *s)
        if (likely(!(s->flags & SN_BE_TRACK_ANY)))
                return;
 
-       for (i = 0; i < sizeof(s->stkctr) / sizeof(s->stkctr[0]); i++) {
+       for (i = 0; i < MAX_SESS_STKCTR; i++) {
                if (!s->stkctr[i].entry)
                        continue;
 
@@ -145,7 +145,7 @@ static void inline session_inc_http_req_ctr(struct session *s)
        void *ptr;
        int i;
 
-       for (i = 0; i < sizeof(s->stkctr) / sizeof(s->stkctr[0]); i++) {
+       for (i = 0; i < MAX_SESS_STKCTR; i++) {
                if (!s->stkctr[i].entry)
                        continue;
 
@@ -169,7 +169,7 @@ static void inline session_inc_be_http_req_ctr(struct session *s)
        if (likely(!(s->flags & SN_BE_TRACK_ANY)))
                return;
 
-       for (i = 0; i < sizeof(s->stkctr) / sizeof(s->stkctr[0]); i++) {
+       for (i = 0; i < MAX_SESS_STKCTR; i++) {
                if (!s->stkctr[i].entry)
                        continue;
 
@@ -198,7 +198,7 @@ static void inline session_inc_http_err_ctr(struct session *s)
        void *ptr;
        int i;
 
-       for (i = 0; i < sizeof(s->stkctr) / sizeof(s->stkctr[0]); i++) {
+       for (i = 0; i < MAX_SESS_STKCTR; i++) {
                if (!s->stkctr[i].entry)
                        continue;
 
index a820462cfd1a333124b82a106272596ce038bc16..662cde495455594192d972a4bf25209fb1aedd02 100644 (file)
@@ -33,9 +33,10 @@ enum {
        TCP_ACT_ACCEPT = 1,
        TCP_ACT_REJECT = 2,
        TCP_ACT_EXPECT_PX = 3,
-       TCP_ACT_TRK_SC0 = 4, /* TCP request tracking : must be contiguous */
+       TCP_ACT_TRK_SC0 = 4, /* TCP request tracking : must be contiguous and cover up to MAX_SESS_STKCTR values */
        TCP_ACT_TRK_SC1 = 5,
        TCP_ACT_TRK_SC2 = 6,
+       TCP_ACT_TRK_SCMAX = TCP_ACT_TRK_SC0 + MAX_SESS_STKCTR - 1,
 };
 
 struct tcp_rule {
index 42d37dbedfbb9b21c17eec1a7c6157ae283bd890..8f731ddee6d46a859c24a9327ef676a363517e73 100644 (file)
@@ -90,7 +90,9 @@
 
 #define SN_COMP_READY   0x00100000     /* the compression is initialized */
 
-/* session tracking flags: these ones must absolutely be contiguous. See also s->stkctr */
+/* session tracking flags: these ones must absolutely be contiguous and cover
+ * at least MAX_SESS_STKCTR flags.
+ */
 #define SN_BE_TRACK_SC0 0x00200000     /* backend tracks stick-counter 0 */
 #define SN_BE_TRACK_SC1 0x00400000     /* backend tracks stick-counter 1 */
 #define SN_BE_TRACK_SC2 0x00800000     /* backend tracks stick-counter 2 */
@@ -146,7 +148,7 @@ struct session {
        } store[8];                             /* tracked stickiness values to store */
        int store_count;
 
-       struct stkctr stkctr[3];                /* stick counters */
+       struct stkctr stkctr[MAX_SESS_STKCTR];  /* stick counters */
 
        struct stream_interface si[2];          /* client and server stream interfaces */
        struct {
index a85bbedf0611f285104fa7587a5e727f8692c0ef..d51e1b6da66684a66e85279b744857cb51853b26 100644 (file)
@@ -6367,7 +6367,7 @@ int check_config_validity()
                list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) {
                        struct proxy *target;
 
-                       if (trule->action < TCP_ACT_TRK_SC0 || trule->action > TCP_ACT_TRK_SC2)
+                       if (trule->action < TCP_ACT_TRK_SC0 || trule->action > TCP_ACT_TRK_SCMAX)
                                continue;
 
                        if (trule->act_prm.trk_ctr.table.n)
@@ -6406,7 +6406,7 @@ int check_config_validity()
                list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) {
                        struct proxy *target;
 
-                       if (trule->action < TCP_ACT_TRK_SC0 || trule->action > TCP_ACT_TRK_SC2)
+                       if (trule->action < TCP_ACT_TRK_SC0 || trule->action > TCP_ACT_TRK_SCMAX)
                                continue;
 
                        if (trule->act_prm.trk_ctr.table.n)
index fe4a0d2b57fd19135e07d6670e31a19bf7b57f3e..797f3357e4715bef431c961c1b3fde395c7eec64 100644 (file)
@@ -938,7 +938,7 @@ int tcp_inspect_request(struct session *s, struct channel *req, int an_bit)
                                        s->flags |= SN_FINST_R;
                                return 0;
                        }
-                       else if ((rule->action >= TCP_ACT_TRK_SC0 && rule->action <= TCP_ACT_TRK_SC2) &&
+                       else if ((rule->action >= TCP_ACT_TRK_SC0 && rule->action <= TCP_ACT_TRK_SCMAX) &&
                                 !s->stkctr[tcp_trk_idx(rule->action)].entry) {
                                /* Note: only the first valid tracking parameter of each
                                 * applies.
@@ -1092,7 +1092,7 @@ int tcp_exec_req_rules(struct session *s)
                                result = 0;
                                break;
                        }
-                       else if ((rule->action >= TCP_ACT_TRK_SC0 && rule->action <= TCP_ACT_TRK_SC2) &&
+                       else if ((rule->action >= TCP_ACT_TRK_SC0 && rule->action <= TCP_ACT_TRK_SCMAX) &&
                                 !s->stkctr[tcp_trk_idx(rule->action)].entry) {
                                /* Note: only the first valid tracking parameter of each
                                 * applies.
@@ -1184,7 +1184,9 @@ static int tcp_parse_request_rule(char **args, int arg, int section_type,
                arg++;
                rule->action = TCP_ACT_REJECT;
        }
-       else if (strcmp(args[arg], "track-sc0") == 0 || strcmp(args[arg], "track-sc1") == 0 || strcmp(args[arg], "track-sc2") == 0) {
+       else if (strncmp(args[arg], "track-sc", 8) == 0 &&
+                args[arg][9] == '\0' && args[arg][8] >= '0' &&
+                args[arg][8] <= '0' + MAX_SESS_STKCTR) { /* track-sc 0..9 */
                struct sample_expr *expr;
                int kw = arg;
 
@@ -1246,9 +1248,9 @@ static int tcp_parse_request_rule(char **args, int arg, int section_type,
        }
        else {
                memprintf(err,
-                         "'%s %s' expects 'accept', 'reject', 'track-sc0', 'track-sc1' "
-                         " or 'track-sc2' in %s '%s' (got '%s')",
-                         args[0], args[1], proxy_type_str(curpx), curpx->id, args[arg]);
+                         "'%s %s' expects 'accept', 'reject', 'track-sc0' ... 'track-sc%d' "
+                         " in %s '%s' (got '%s')",
+                         args[0], args[1], MAX_SESS_STKCTR, proxy_type_str(curpx), curpx->id, args[arg]);
                return -1;
        }
 
index 9be5faa21f1e2b8357c56d7c9fc28c193cd85558..ec78be1b3886fbc4f66e23c882a42018e21d9024 100644 (file)
@@ -420,7 +420,7 @@ int session_complete(struct session *s)
        /* Let's count a session now */
        proxy_inc_fe_sess_ctr(l, p);
 
-       for (i = 0; i < sizeof(s->stkctr) / sizeof(s->stkctr[0]); i++) {
+       for (i = 0; i < MAX_SESS_STKCTR; i++) {
                void *ptr;
 
                if (!s->stkctr[i].entry)
@@ -707,7 +707,7 @@ void session_process_counters(struct session *s)
                        if (s->listener->counters)
                                s->listener->counters->bytes_in += bytes;
 
-                       for (i = 0; i < sizeof(s->stkctr) / sizeof(s->stkctr[0]); i++) {
+                       for (i = 0; i < MAX_SESS_STKCTR; i++) {
                                if (!s->stkctr[i].entry)
                                        continue;
 
@@ -741,7 +741,7 @@ void session_process_counters(struct session *s)
                        if (s->listener->counters)
                                s->listener->counters->bytes_out += bytes;
 
-                       for (i = 0; i < sizeof(s->stkctr) / sizeof(s->stkctr[0]); i++) {
+                       for (i = 0; i < MAX_SESS_STKCTR; i++) {
                                if (!s->stkctr[i].entry)
                                        continue;