MINOR: counters: make it easier to extend the amount of tracked counters

By properly affecting the flags and values, it becomes easier to add
more tracked counters, for example for experimentation. It also slightly
reduces the code and the number of tests. No counters were added with
this patch.
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 9907bfd..18fcedc 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -6335,7 +6335,7 @@
 		list_for_each_entry(trule, &curproxy->tcp_req.l4_rules, list) {
 			struct proxy *target;
 
-			if (trule->action != TCP_ACT_TRK_SC1 && trule->action != TCP_ACT_TRK_SC2)
+			if (trule->action < TCP_ACT_TRK_SC1 || trule->action > TCP_ACT_TRK_SC2)
 				continue;
 
 			if (trule->act_prm.trk_ctr.table.n)
@@ -6346,7 +6346,7 @@
 			if (!target) {
 				Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n",
 				      curproxy->id, trule->act_prm.trk_ctr.table.n,
-				      trule->action == TCP_ACT_TRK_SC1 ? 1 : 2);
+				      1 + tcp_trk_idx(trule->action));
 				cfgerr++;
 			}
 			else if (target->table.size == 0) {
@@ -6357,7 +6357,7 @@
 			else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr,  target->table.type)) {
 				Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n",
 				      curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id,
-				      trule->action == TCP_ACT_TRK_SC1 ? 1 : 2);
+				      1 + tcp_trk_idx(trule->action));
 				cfgerr++;
 			}
 			else {
@@ -6374,7 +6374,7 @@
 		list_for_each_entry(trule, &curproxy->tcp_req.inspect_rules, list) {
 			struct proxy *target;
 
-			if (trule->action != TCP_ACT_TRK_SC1 && trule->action != TCP_ACT_TRK_SC2)
+			if (trule->action < TCP_ACT_TRK_SC1 || trule->action > TCP_ACT_TRK_SC2)
 				continue;
 
 			if (trule->act_prm.trk_ctr.table.n)
@@ -6385,7 +6385,7 @@
 			if (!target) {
 				Alert("Proxy '%s': unable to find table '%s' referenced by track-sc%d.\n",
 				      curproxy->id, trule->act_prm.trk_ctr.table.n,
-				      trule->action == TCP_ACT_TRK_SC1 ? 1 : 2);
+				      1 + tcp_trk_idx(trule->action));
 				cfgerr++;
 			}
 			else if (target->table.size == 0) {
@@ -6396,7 +6396,7 @@
 			else if (!stktable_compatible_sample(trule->act_prm.trk_ctr.expr,  target->table.type)) {
 				Alert("Proxy '%s': stick-table '%s' uses a type incompatible with the 'track-sc%d' rule.\n",
 				      curproxy->id, trule->act_prm.trk_ctr.table.n ? trule->act_prm.trk_ctr.table.n : curproxy->id,
-				      trule->action == TCP_ACT_TRK_SC1 ? 1 : 2);
+				      1 + tcp_trk_idx(trule->action));
 				cfgerr++;
 			}
 			else {
diff --git a/src/peers.c b/src/peers.c
index 5e4ff35..61fb938 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -1178,8 +1178,7 @@
 
 	/* init store persistence */
 	s->store_count = 0;
-	s->stkctr[0].entry = NULL;
-	s->stkctr[1].entry = NULL;
+	memset(s->stkctr, 0, sizeof(s->stkctr));
 
 	/* FIXME: the logs are horribly complicated now, because they are
 	 * defined in <p>, <p>, and later <be> and <be>.
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index 5638257..86a67c4 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -901,8 +901,8 @@
 					s->flags |= SN_FINST_R;
 				return 0;
 			}
-			else if ((rule->action == TCP_ACT_TRK_SC1 && !s->stkctr[0].entry) ||
-			         (rule->action == TCP_ACT_TRK_SC2 && !s->stkctr[1].entry)) {
+			else if ((rule->action >= TCP_ACT_TRK_SC1 && rule->action <= TCP_ACT_TRK_SC2) &&
+				 !s->stkctr[tcp_trk_idx(rule->action)].entry) {
 				/* Note: only the first valid tracking parameter of each
 				 * applies.
 				 */
@@ -912,15 +912,9 @@
 				key = stktable_fetch_key(t, s->be, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->act_prm.trk_ctr.expr);
 
 				if (key && (ts = stktable_get_entry(t, key))) {
-					if (rule->action == TCP_ACT_TRK_SC1) {
-						session_track_stkctr(&s->stkctr[0], t, ts);
-						if (s->fe != s->be)
-							s->flags |= SN_BE_TRACK_SC1;
-					} else {
-						session_track_stkctr(&s->stkctr[1], t, ts);
-						if (s->fe != s->be)
-							s->flags |= SN_BE_TRACK_SC2;
-					}
+					session_track_stkctr(&s->stkctr[tcp_trk_idx(rule->action)], t, ts);
+					if (s->fe != s->be)
+						s->flags |= SN_BE_TRACK_SC1 << tcp_trk_idx(rule->action);
 				}
 			}
 			else {
@@ -1061,8 +1055,8 @@
 				result = 0;
 				break;
 			}
-			else if ((rule->action == TCP_ACT_TRK_SC1 && !s->stkctr[0].entry) ||
-			         (rule->action == TCP_ACT_TRK_SC2 && !s->stkctr[1].entry)) {
+			else if ((rule->action >= TCP_ACT_TRK_SC1 && rule->action <= TCP_ACT_TRK_SC2) &&
+				 !s->stkctr[tcp_trk_idx(rule->action)].entry) {
 				/* Note: only the first valid tracking parameter of each
 				 * applies.
 				 */
@@ -1071,12 +1065,8 @@
 				t = rule->act_prm.trk_ctr.table.t;
 				key = stktable_fetch_key(t, s->be, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->act_prm.trk_ctr.expr);
 
-				if (key && (ts = stktable_get_entry(t, key))) {
-					if (rule->action == TCP_ACT_TRK_SC1)
-						session_track_stkctr(&s->stkctr[0], t, ts);
-					else
-						session_track_stkctr(&s->stkctr[1], t, ts);
-				}
+				if (key && (ts = stktable_get_entry(t, key)))
+					session_track_stkctr(&s->stkctr[tcp_trk_idx(rule->action)], t, ts);
 			}
 			else {
 				/* otherwise it's an accept */
@@ -1193,11 +1183,7 @@
 			arg++;
 		}
 		rule->act_prm.trk_ctr.expr = expr;
-
-		if (args[kw][8] == '1')
-			rule->action = TCP_ACT_TRK_SC1;
-		else
-			rule->action = TCP_ACT_TRK_SC2;
+		rule->action = TCP_ACT_TRK_SC1 + args[kw][8] - '1';
 	}
 	else {
 		memprintf(err,
diff --git a/src/session.c b/src/session.c
index d44583b..404fd06 100644
--- a/src/session.c
+++ b/src/session.c
@@ -97,10 +97,8 @@
 	 */
 	s->flags = 0;
 	s->logs.logwait = p->to_log;
-	s->stkctr[0].entry = NULL;
-	s->stkctr[1].entry = NULL;
-	s->stkctr[0].table = NULL;
-	s->stkctr[1].table = NULL;
+
+	memset(s->stkctr, 0, sizeof(s->stkctr));
 
 	s->listener = l;
 	s->fe  = p;