]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: counters: provide a generic function to retrieve a stkctr for sc* and src.
authorWilly Tarreau <w@1wt.eu>
Mon, 22 Jul 2013 20:40:11 +0000 (22:40 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 1 Aug 2013 19:17:13 +0000 (21:17 +0200)
This function aims at simplifying the prefetching of the table and entry
when using any of the session counters fetches. The principle is that the
src_* variant produces a stkctr that is used instead of the one from the
session. That way we can call the same function from all session counter
fetch functions and always have a single function to support sc[0-9]_/src_.

src/session.c

index aa42c313b31c071901fc87f9952db0a09eac39ac..35643eb46806129c881809e71978470a0c1fcb44 100644 (file)
@@ -2578,6 +2578,33 @@ void session_shutdown(struct session *session, int why)
 /*           All supported ACL keywords must be declared here.          */
 /************************************************************************/
 
+/* Returns a pointer to an stkctr depending on the fetch keyword name.
+ * It is designed to be called as sc[0-9]_* or src_* exclusively.
+ * sc[0-9]_* will return a pointer to the respective field in the
+ * session <l4>. src_* will fill a locally allocated structure with
+ * the table and entry corresponding to what is specified with src_*.
+ * NULL may be returned if the designated stkctr is not tracked.
+ */
+static struct stkctr *
+smp_fetch_sc_stkctr(struct session *l4, const struct arg *args, const char *kw)
+{
+       static struct stkctr stkctr;
+       unsigned char num = kw[2];
+
+       if (num - '0' <= 9) { /* sc[0-9]_* variant */
+               return l4->stkctr[num - '0'].entry ? &l4->stkctr[num - '0'] : NULL;
+       }
+       else { /* src_* variant, arg[0] = table */
+               struct stktable_key *key = addr_to_stktable_key(&l4->si[0].conn->addr.from);
+
+               if (!key)
+                       return NULL;
+               stkctr.table = &args->data.prx->table;
+               stkctr.entry = stktable_lookup_key(stkctr.table, key);
+               return &stkctr;
+       }
+}
+
 /* set return a boolean indicating if the requested session counter is
  * currently being tracked or not.
  * Supports being called as "sc[0-9]_tracked" only.