]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MAJOR: stick-tables: remove key storage from the key struct
authorThierry FOURNIER <tfournier@arpalert.org>
Fri, 24 Jul 2015 17:31:59 +0000 (19:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 20 Aug 2015 15:13:47 +0000 (17:13 +0200)
Now, the key struct only points to the storage provided by the
sample as input.

include/proto/proto_tcp.h
include/types/stick_table.h
src/haproxy.c
src/stick_table.c
src/stream.c

index 66df33c3f753b1ecd1776db199d1eb01f323bc90..17404d44a8fc0e07c6ba7f11e1422347b6ffe84e 100644 (file)
@@ -47,49 +47,6 @@ void tcp_res_cont_keywords_register(struct action_kw_list *kw_list);
 /* Export some samples. */
 int smp_fetch_src(const struct arg *args, struct sample *smp, const char *kw, void *private);
 
-/* Converts the INET/INET6 source address to a stick_table key usable for table
- * lookups. <type> can be SMP_T_IPV4 or SMP_T_IPV6. The function
- * try to convert the incoming IP to the type expected by the sticktable.
- * Returns either NULL if the source cannot be converted (eg: not IPv4) or a
- * pointer to the converted result in static_table_key in the appropriate format
- * (IP).
- */
-static inline struct stktable_key *addr_to_stktable_key(struct sockaddr_storage *addr, long type)
-{
-       switch (addr->ss_family) {
-       case AF_INET:
-               /* Convert IPv4 to IPv4 key. */
-               if (type == SMP_T_IPV4) {
-                       static_table_key->key = (void *)&((struct sockaddr_in *)addr)->sin_addr;
-                       break;
-               }
-               /* Convert IPv4 to IPv6 key. */
-               if (type == SMP_T_IPV6) {
-                       v4tov6(&static_table_key->data.ipv6, &((struct sockaddr_in *)addr)->sin_addr);
-                       static_table_key->key = &static_table_key->data.ipv6;
-                       break;
-               }
-               return NULL;
-
-       case AF_INET6:
-               /* Convert IPv6 to IPv4 key. This conversion can be failed. */
-               if (type == SMP_T_IPV4) {
-                       if (!v6tov4(&static_table_key->data.ipv4, &((struct sockaddr_in6 *)addr)->sin6_addr))
-                               return NULL;
-                       static_table_key->key = &static_table_key->data.ipv4;
-                       break;
-               }
-               /* Convert IPv6 to IPv6 key. */
-               if (type == SMP_T_IPV6) {
-                       static_table_key->key = (void *)&((struct sockaddr_in6 *)addr)->sin6_addr;
-                       break;
-               }
-               return NULL;
-       default:
-               return NULL;
-       }
-       return static_table_key;
-}
 
 /* for a tcp-request action ACT_TCP_TRK_*, return a tracking index starting at
  * zero for SC0. Unknown actions also return zero.
index e6fbfc23f7d843349aff7f9c229d3b51963c164b..2800add11eeba6cd4b27405320384450982f21bb 100644 (file)
@@ -175,7 +175,6 @@ extern struct stktable_data_type stktable_data_types[STKTABLE_DATA_TYPES];
 struct stktable_key {
        void *key;                      /* pointer on key buffer */
        size_t key_len;                 /* data len to read in buff in case of null terminated string */
-       union sample_value data;
 };
 
 /* WARNING: if new fields are added, they must be initialized in stream_accept()
index 4110893384a19282b81c53b249b56279e5b58555..4ff05abd8e883aa3d89173e3bdcfefd1cdfb990e 100644 (file)
@@ -1051,7 +1051,7 @@ void init(int argc, char **argv)
 
        swap_buffer = (char *)calloc(1, global.tune.bufsize);
        get_http_auth_buff = (char *)calloc(1, global.tune.bufsize);
-       static_table_key = calloc(1, sizeof(*static_table_key) + global.tune.bufsize);
+       static_table_key = calloc(1, sizeof(*static_table_key));
 
        fdinfo = (struct fdinfo *)calloc(1,
                                       sizeof(struct fdinfo) * (global.maxsock));
index e9e9304232f18c1169274ee02c70940473a0b499..9c053bc22797fabc1892723f9a0f2e5d93d477b3 100644 (file)
@@ -521,7 +521,6 @@ struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t)
        default: /* impossible case. */
                return NULL;
        }
-       static_table_key->data = smp->data.u;
 
        return static_table_key;
 }
index 5280e372f2a9c5b14472005acd8fd8e7270b2efa..278bdb8567206e01bc02fa57135454e0605d4c93 100644 (file)
@@ -2597,11 +2597,20 @@ smp_fetch_sc_stkctr(struct session *sess, struct stream *strm, const struct arg
        else if (num > 9) { /* src_* variant, args[0] = table */
                struct stktable_key *key;
                struct connection *conn = objt_conn(sess->origin);
+               struct sample smp;
 
                if (!conn)
                        return NULL;
 
-               key = addr_to_stktable_key(&conn->addr.from, args->data.prx->table.type);
+               /* Fetch source adress in a sample. */
+               smp.px = NULL;
+               smp.sess = sess;
+               smp.strm = strm;
+               if (!smp_fetch_src(NULL, &smp, NULL, NULL))
+                       return NULL;
+
+               /* Converts into key. */
+               key = smp_to_stkey(&smp, &args->data.prx->table);
                if (!key)
                        return NULL;
 
@@ -2647,6 +2656,7 @@ smp_create_src_stkctr(struct session *sess, struct stream *strm, const struct ar
        static struct stkctr stkctr;
        struct stktable_key *key;
        struct connection *conn = objt_conn(sess->origin);
+       struct sample smp;
 
        if (strncmp(kw, "src_", 4) != 0)
                return NULL;
@@ -2654,7 +2664,15 @@ smp_create_src_stkctr(struct session *sess, struct stream *strm, const struct ar
        if (!conn)
                return NULL;
 
-       key = addr_to_stktable_key(&conn->addr.from, args->data.prx->table.type);
+       /* Fetch source adress in a sample. */
+       smp.px = NULL;
+       smp.sess = sess;
+       smp.strm = strm;
+       if (!smp_fetch_src(NULL, &smp, NULL, NULL))
+               return NULL;
+
+       /* Converts into key. */
+       key = smp_to_stkey(&smp, &args->data.prx->table);
        if (!key)
                return NULL;
 
@@ -2867,7 +2885,12 @@ smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const ch
        if (!conn)
                return 0;
 
-       key = addr_to_stktable_key(&conn->addr.from, smp->px->table.type);
+       /* Fetch source adress in a sample. */
+       if (!smp_fetch_src(NULL, smp, NULL, NULL))
+               return 0;
+
+       /* Converts into key. */
+       key = smp_to_stkey(smp, &args->data.prx->table);
        if (!key)
                return 0;