return -1; // not found
}
+/* Perform a lookup in <table> based on <smp> and returns stksess entry or NULL
+ * if not found. Set <create> to force the entry creation if it doesn't exist.
+ *
+ * <smp> may be modified by underlying functions
+ */
+static struct stksess *smp_fetch_stksess(struct stktable *table, struct sample *smp, int create)
+{
+ struct stktable_key *key;
+
+ /* Converts smp into key. */
+ key = smp_to_stkey(smp, table);
+ if (!key)
+ return NULL;
+
+ if (create)
+ return stktable_get_entry(table, key);
+ return stktable_lookup_key(table, key);
+}
+
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
* it up into this table. Returns true if found, false otherwise. The input
* type is STR so that input samples are converted to string (since all types
static int sample_conv_in_table(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->data.type = SMP_T_BOOL;
smp->data.u.sint = !!ts;
static int sample_conv_table_bytes_in_rate(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_conn_cnt(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_conn_cur(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_conn_rate(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_expire(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_idle(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_bytes_out_rate(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_glitch_cnt(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_glitch_rate(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_gpt(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
unsigned int idx;
t = arg_p[1].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_gpt0(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_gpc(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
unsigned int idx;
t = arg_p[1].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_gpc_rate(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
unsigned int idx;
t = arg_p[1].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_gpc0(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_gpc0_rate(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_gpc1(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_gpc1_rate(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_http_err_cnt(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_http_err_rate(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_http_fail_cnt(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_http_fail_rate(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_http_req_cnt(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_http_req_rate(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_kbytes_in(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_kbytes_out(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_server_id(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_sess_cnt(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_sess_rate(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
void *ptr;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
static int sample_conv_table_trackers(const struct arg *arg_p, struct sample *smp, void *private)
{
struct stktable *t;
- struct stktable_key *key;
struct stksess *ts;
t = arg_p[0].data.t;
- key = smp_to_stkey(smp, t);
- if (!key)
- return 0;
-
- ts = stktable_lookup_key(t, key);
+ ts = smp_fetch_stksess(t, smp, 0);
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
num = args[arg++].data.sint;
}
else if (num > 9) { /* src_* variant, args[0] = table */
- struct stktable_key *key;
+ struct stksess *entry;
struct connection *conn = objt_conn(sess->origin);
struct sample smp;
if (!smp_fetch_src || !smp_fetch_src(empty_arg_list, &smp, "src", NULL))
return NULL;
- /* Converts into key. */
- key = smp_to_stkey(&smp, args->data.t);
- if (!key)
- return NULL;
+ entry = smp_fetch_stksess(args->data.t, &smp, 0);
stkctr->table = args->data.t;
- stkctr_set_entry(stkctr, stktable_lookup_key(stkctr->table, key));
+ stkctr_set_entry(stkctr, entry);
return stkctr;
}
struct stkctr *
smp_create_src_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw, struct stkctr *stkctr)
{
- struct stktable_key *key;
+ struct stksess *entry;
struct connection *conn = objt_conn(sess->origin);
struct sample smp;
if (!smp_fetch_src || !smp_fetch_src(empty_arg_list, &smp, "src", NULL))
return NULL;
- /* Converts into key. */
- key = smp_to_stkey(&smp, args->data.t);
- if (!key)
- return NULL;
+ entry = smp_fetch_stksess(args->data.t, &smp, 1);
stkctr->table = args->data.t;
- stkctr_set_entry(stkctr, stktable_get_entry(stkctr->table, key));
+ stkctr_set_entry(stkctr, entry);
return stkctr;
}
{
struct connection *conn = objt_conn(smp->sess->origin);
struct stksess *ts;
- struct stktable_key *key;
void *ptr;
struct stktable *t;
if (!smp_fetch_src || !smp_fetch_src(empty_arg_list, smp, "src", NULL))
return 0;
- /* Converts into key. */
- key = smp_to_stkey(smp, args->data.t);
- if (!key)
- return 0;
-
t = args->data.t;
- if ((ts = stktable_get_entry(t, key)) == NULL)
+ if ((ts = smp_fetch_stksess(t, smp, 1)) == NULL)
/* entry does not exist and could not be created */
return 0;