MINOR: stick-tables: Make static_table_key a struct variable instead of a pointer

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.
This commit is contained in:
Christopher Faulet 2017-08-29 15:30:31 +02:00 committed by Willy Tarreau
parent ad405f1714
commit ca20d02ea8
3 changed files with 19 additions and 23 deletions

View File

@ -31,8 +31,6 @@
#define stktable_data_size(type) (sizeof(((union stktable_data*)0)->type)) #define stktable_data_size(type) (sizeof(((union stktable_data*)0)->type))
#define stktable_data_cast(ptr, type) ((union stktable_data*)(ptr))->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); 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_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key);
void stksess_free(struct stktable *t, struct stksess *ts); void stksess_free(struct stktable *t, struct stksess *ts);

View File

@ -1719,7 +1719,6 @@ static void init(int argc, char **argv)
} }
get_http_auth_buff = calloc(1, global.tune.bufsize); 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)); fdinfo = calloc(1, sizeof(struct fdinfo) * (global.maxsock));
fdtab = calloc(1, sizeof(struct fdtab) * (global.maxsock)); fdtab = calloc(1, sizeof(struct fdtab) * (global.maxsock));
@ -2123,7 +2122,6 @@ void deinit(void)
free(fdinfo); fdinfo = NULL; free(fdinfo); fdinfo = NULL;
free(fdtab); fdtab = NULL; free(fdtab); fdtab = NULL;
free(oldpids); oldpids = NULL; free(oldpids); oldpids = NULL;
free(static_table_key); static_table_key = NULL;
free(get_http_auth_buff); get_http_auth_buff = NULL; free(get_http_auth_buff); get_http_auth_buff = NULL;
free(global_listener_queue_task); global_listener_queue_task = NULL; free(global_listener_queue_task); global_listener_queue_task = NULL;

View File

@ -41,7 +41,7 @@
#include <proto/tcp_rules.h> #include <proto/tcp_rules.h>
/* structure used to return a table key built from a sample */ /* 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 * 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) { switch (t->type) {
case SMP_T_IPV4: case SMP_T_IPV4:
static_table_key->key = &smp->data.u.ipv4; static_table_key.key = &smp->data.u.ipv4;
static_table_key->key_len = 4; static_table_key.key_len = 4;
break; break;
case SMP_T_IPV6: case SMP_T_IPV6:
static_table_key->key = &smp->data.u.ipv6; static_table_key.key = &smp->data.u.ipv6;
static_table_key->key_len = 16; static_table_key.key_len = 16;
break; break;
case SMP_T_SINT: 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. * signed 64 it, so we can convert it inplace.
*/ */
*(unsigned int *)&smp->data.u.sint = (unsigned int)smp->data.u.sint; *(unsigned int *)&smp->data.u.sint = (unsigned int)smp->data.u.sint;
static_table_key->key = &smp->data.u.sint; static_table_key.key = &smp->data.u.sint;
static_table_key->key_len = 4; static_table_key.key_len = 4;
break; break;
case SMP_T_STR: case SMP_T_STR:
if (!smp_make_safe(smp)) if (!smp_make_safe(smp))
return NULL; return NULL;
static_table_key->key = smp->data.u.str.str; static_table_key.key = smp->data.u.str.str;
static_table_key->key_len = smp->data.u.str.len; static_table_key.key_len = smp->data.u.str.len;
break; break;
case SMP_T_BIN: 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); t->key_size - smp->data.u.str.len);
smp->data.u.str.len = t->key_size; smp->data.u.str.len = t->key_size;
} }
static_table_key->key = smp->data.u.str.str; static_table_key.key = smp->data.u.str.str;
static_table_key->key_len = smp->data.u.str.len; static_table_key.key_len = smp->data.u.str.len;
break; break;
default: /* impossible case. */ default: /* impossible case. */
return NULL; 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) { switch (px->table.type) {
case SMP_T_IPV4: case SMP_T_IPV4:
uint32_key = htonl(inetaddr_host(args[4])); uint32_key = htonl(inetaddr_host(args[4]));
static_table_key->key = &uint32_key; static_table_key.key = &uint32_key;
break; break;
case SMP_T_IPV6: case SMP_T_IPV6:
inet_pton(AF_INET6, args[4], ip6_key); inet_pton(AF_INET6, args[4], ip6_key);
static_table_key->key = &ip6_key; static_table_key.key = &ip6_key;
break; break;
case SMP_T_SINT: case SMP_T_SINT:
{ {
@ -2382,13 +2382,13 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
return 1; return 1;
} }
uint32_key = (uint32_t) val; uint32_key = (uint32_t) val;
static_table_key->key = &uint32_key; static_table_key.key = &uint32_key;
break; break;
} }
break; break;
case SMP_T_STR: case SMP_T_STR:
static_table_key->key = args[4]; static_table_key.key = args[4];
static_table_key->key_len = strlen(args[4]); static_table_key.key_len = strlen(args[4]);
break; break;
default: default:
switch (appctx->ctx.table.action) { 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)) if (!cli_has_level(appctx, ACCESS_LVL_OPER))
return 1; 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) { switch (appctx->ctx.table.action) {
case STK_CLI_ACT_SHOW: case STK_CLI_ACT_SHOW:
@ -2442,7 +2442,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
if (ts) if (ts)
stktable_touch(&px->table, ts, 1); stktable_touch(&px->table, ts, 1);
else { else {
ts = stksess_new(&px->table, static_table_key); ts = stksess_new(&px->table, &static_table_key);
if (!ts) { if (!ts) {
/* don't delete an entry which is currently referenced */ /* don't delete an entry which is currently referenced */
appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; appctx->ctx.cli.msg = "Unable to allocate a new entry\n";