]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stick-table: implement lookup from a sample fetch
authorWilly Tarreau <w@1wt.eu>
Thu, 3 Jul 2014 15:02:46 +0000 (17:02 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 10 Jul 2014 14:43:44 +0000 (16:43 +0200)
Currently we have stktable_fetch_key() which fetches a sample according
to an expression and returns a stick table key, but we also need a function
which does only the second half of it from a known sample. So let's cut the
function in two and introduce smp_to_stkey() to perform this lookup. The
first function was adapted to make use of it in order to avoid code
duplication.

include/proto/stick_table.h
src/stick_table.c

index 57ca2234317caa2e45828f82db406a6d64b79c68..a121ad5dc6b46678cecec3035c2b518eab3e74d8 100644 (file)
@@ -46,6 +46,7 @@ struct stksess *stktable_touch(struct stktable *t, struct stksess *ts, int local
 struct stksess *stktable_lookup(struct stktable *t, struct stksess *ts);
 struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key);
 struct stksess *stktable_update_key(struct stktable *table, struct stktable_key *key);
+struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t);
 struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px,
                                        struct session *l4, void *l7, unsigned int opt,
                                        struct sample_expr *expr, struct sample *smp);
index a708d3c53386423d000f5dd51c0e217153401b59..57993b3257ca56fe4e3bbbc5ce8d410d7b9f8223 100644 (file)
@@ -597,27 +597,13 @@ static sample_to_key_fct sample_to_key[SMP_TYPES][STKTABLE_TYPES] = {
 };
 
 
-/*
- * Process a fetch + format conversion as defined by the sample expression <expr>
- * on request or response considering the <opt> parameter. Returns either NULL if
- * no key could be extracted, or a pointer to the converted result stored in
- * static_table_key in format <table_type>. If <smp> is not NULL, it will be reset
- * and its flags will be initialized so that the caller gets a copy of the input
- * sample, and knows why it was not accepted (eg: SMP_F_MAY_CHANGE is present).
+/* Prepares a stktable_key from a sample <smp> to search into table <t>.
+ * Returns NULL if the sample could not be converted (eg: no matching type),
+ * otherwise a pointer to the static stktable_key filled with what is needed
+ * for the lookup.
  */
-struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, struct session *l4, void *l7,
-                                        unsigned int opt, struct sample_expr *expr, struct sample *smp)
+struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t)
 {
-       if (smp)
-               memset(smp, 0, sizeof(*smp));
-
-       smp = sample_process(px, l4, l7, opt, expr, smp);
-       if (!smp)
-               return NULL;
-
-       if ((smp->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL))
-               return NULL; /* we can only use stable samples */
-
        if (!sample_to_key[smp->type][t->type])
                return NULL;
 
@@ -659,6 +645,30 @@ struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, st
        return static_table_key;
 }
 
+/*
+ * Process a fetch + format conversion as defined by the sample expression <expr>
+ * on request or response considering the <opt> parameter. Returns either NULL if
+ * no key could be extracted, or a pointer to the converted result stored in
+ * static_table_key in format <table_type>. If <smp> is not NULL, it will be reset
+ * and its flags will be initialized so that the caller gets a copy of the input
+ * sample, and knows why it was not accepted (eg: SMP_F_MAY_CHANGE is present).
+ */
+struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, struct session *l4, void *l7,
+                                        unsigned int opt, struct sample_expr *expr, struct sample *smp)
+{
+       if (smp)
+               memset(smp, 0, sizeof(*smp));
+
+       smp = sample_process(px, l4, l7, opt, expr, smp);
+       if (!smp)
+               return NULL;
+
+       if ((smp->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL))
+               return NULL; /* we can only use stable samples */
+
+       return smp_to_stkey(smp, t);
+}
+
 /*
  * Returns 1 if sample expression <expr> result can be converted to table key of
  * type <table_type>, otherwise zero. Used in configuration check.