]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stick-tables: Make static_table_key a struct variable instead of a pointer
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 29 Aug 2017 13:30:31 +0000 (15:30 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 5 Sep 2017 08:35:07 +0000 (10:35 +0200)
First, this variable does not need to be publicly exposed because it is only
used by stick_table functions. So we declare it as a global static in
stick_table.c file. Then, it is useless to use a pointer. Using a plain struct
variable avoids any dynamic allocation.

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

index a5fd4000c541150752d1170e4c14b9468624709b..f48b9eb496dbc4d6fac333af17da00eed007848d 100644 (file)
@@ -31,8 +31,6 @@
 #define stktable_data_size(type) (sizeof(((union stktable_data*)0)->type))
 #define stktable_data_cast(ptr, type) ((union stktable_data*)(ptr))->type
 
-extern struct stktable_key *static_table_key;
-
 struct stksess *stksess_new(struct stktable *t, struct stktable_key *key);
 void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key);
 void stksess_free(struct stktable *t, struct stksess *ts);
index 75afd97bdba17a7fb8dc9ecc38128122a6ad52ab..27d4417353ffddc95217224b65d75447f7eaeb10 100644 (file)
@@ -1719,7 +1719,6 @@ static void init(int argc, char **argv)
        }
 
        get_http_auth_buff = calloc(1, global.tune.bufsize);
-       static_table_key = calloc(1, sizeof(*static_table_key));
 
        fdinfo = calloc(1, sizeof(struct fdinfo) * (global.maxsock));
        fdtab = calloc(1, sizeof(struct fdtab) * (global.maxsock));
@@ -2123,7 +2122,6 @@ void deinit(void)
        free(fdinfo);         fdinfo  = NULL;
        free(fdtab);          fdtab   = NULL;
        free(oldpids);        oldpids = NULL;
-       free(static_table_key); static_table_key = NULL;
        free(get_http_auth_buff); get_http_auth_buff = NULL;
        free(global_listener_queue_task); global_listener_queue_task = NULL;
 
index a00f1b64586da90361880398c84dc7dde5e0e3f3..0be95fe5b477acf2f16b18d9b16544bb8dba94b6 100644 (file)
@@ -41,7 +41,7 @@
 #include <proto/tcp_rules.h>
 
 /* structure used to return a table key built from a sample */
-struct stktable_key *static_table_key;
+static struct stktable_key static_table_key;
 
 /*
  * Free an allocated sticky session <ts>, and decrease sticky sessions counter
@@ -510,13 +510,13 @@ struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t)
        switch (t->type) {
 
        case SMP_T_IPV4:
-               static_table_key->key = &smp->data.u.ipv4;
-               static_table_key->key_len = 4;
+               static_table_key.key = &smp->data.u.ipv4;
+               static_table_key.key_len = 4;
                break;
 
        case SMP_T_IPV6:
-               static_table_key->key = &smp->data.u.ipv6;
-               static_table_key->key_len = 16;
+               static_table_key.key = &smp->data.u.ipv6;
+               static_table_key.key_len = 16;
                break;
 
        case SMP_T_SINT:
@@ -524,15 +524,15 @@ struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t)
                 * signed 64 it, so we can convert it inplace.
                 */
                *(unsigned int *)&smp->data.u.sint = (unsigned int)smp->data.u.sint;
-               static_table_key->key = &smp->data.u.sint;
-               static_table_key->key_len = 4;
+               static_table_key.key = &smp->data.u.sint;
+               static_table_key.key_len = 4;
                break;
 
        case SMP_T_STR:
                if (!smp_make_safe(smp))
                        return NULL;
-               static_table_key->key = smp->data.u.str.str;
-               static_table_key->key_len = smp->data.u.str.len;
+               static_table_key.key = smp->data.u.str.str;
+               static_table_key.key_len = smp->data.u.str.len;
                break;
 
        case SMP_T_BIN:
@@ -550,15 +550,15 @@ struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t)
                               t->key_size - smp->data.u.str.len);
                        smp->data.u.str.len = t->key_size;
                }
-               static_table_key->key = smp->data.u.str.str;
-               static_table_key->key_len = smp->data.u.str.len;
+               static_table_key.key = smp->data.u.str.str;
+               static_table_key.key_len = smp->data.u.str.len;
                break;
 
        default: /* impossible case. */
                return NULL;
        }
 
-       return static_table_key;
+       return &static_table_key;
 }
 
 /*
@@ -2362,11 +2362,11 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
        switch (px->table.type) {
        case SMP_T_IPV4:
                uint32_key = htonl(inetaddr_host(args[4]));
-               static_table_key->key = &uint32_key;
+               static_table_key.key = &uint32_key;
                break;
        case SMP_T_IPV6:
                inet_pton(AF_INET6, args[4], ip6_key);
-               static_table_key->key = &ip6_key;
+               static_table_key.key = &ip6_key;
                break;
        case SMP_T_SINT:
                {
@@ -2382,13 +2382,13 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
                                return 1;
                        }
                        uint32_key = (uint32_t) val;
-                       static_table_key->key = &uint32_key;
+                       static_table_key.key = &uint32_key;
                        break;
                }
                break;
        case SMP_T_STR:
-               static_table_key->key = args[4];
-               static_table_key->key_len = strlen(args[4]);
+               static_table_key.key = args[4];
+               static_table_key.key_len = strlen(args[4]);
                break;
        default:
                switch (appctx->ctx.table.action) {
@@ -2413,7 +2413,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
        if (!cli_has_level(appctx, ACCESS_LVL_OPER))
                return 1;
 
-       ts = stktable_lookup_key(&px->table, static_table_key);
+       ts = stktable_lookup_key(&px->table, &static_table_key);
 
        switch (appctx->ctx.table.action) {
        case STK_CLI_ACT_SHOW:
@@ -2442,7 +2442,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
                if (ts)
                        stktable_touch(&px->table, ts, 1);
                else {
-                       ts = stksess_new(&px->table, static_table_key);
+                       ts = stksess_new(&px->table, &static_table_key);
                        if (!ts) {
                                /* don't delete an entry which is currently referenced */
                                appctx->ctx.cli.msg = "Unable to allocate a new entry\n";