mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
[MINOR] stktable: add a stktable_update_key() function
This function looks up a key, updates its expiration date, or creates it if it was not found. acl_fetch_src_updt_conn_cnt() was updated to make use of it.
This commit is contained in:
parent
6c59e0a942
commit
1f7e925d6a
@ -42,6 +42,7 @@ struct stksess *stktable_store(struct stktable *t, struct stksess *ts);
|
|||||||
struct stksess *stktable_touch(struct stktable *t, struct stksess *ts);
|
struct stksess *stktable_touch(struct stktable *t, struct stksess *ts);
|
||||||
struct stksess *stktable_lookup(struct stktable *t, struct stksess *ts);
|
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_lookup_key(struct stktable *t, struct stktable_key *key);
|
||||||
|
struct stksess *stktable_update_key(struct stktable *table, struct stktable_key *key);
|
||||||
struct stktable_key *stktable_fetch_key(struct proxy *px, struct session *l4,
|
struct stktable_key *stktable_fetch_key(struct proxy *px, struct session *l4,
|
||||||
void *l7, int dir, struct pattern_expr *expr,
|
void *l7, int dir, struct pattern_expr *expr,
|
||||||
unsigned long table_type);
|
unsigned long table_type);
|
||||||
|
@ -2222,15 +2222,9 @@ acl_fetch_src_updt_conn_cnt(struct proxy *px, struct session *l4, void *l7, int
|
|||||||
if (!px)
|
if (!px)
|
||||||
return 0; /* table not found */
|
return 0; /* table not found */
|
||||||
|
|
||||||
if ((ts = stktable_lookup_key(&px->table, key)) == NULL) {
|
if ((ts = stktable_update_key(&px->table, key)) == NULL)
|
||||||
/* entry does not exist, initialize a new one */
|
/* entry does not exist and could not be created */
|
||||||
ts = stksess_new(&px->table, key);
|
return 0;
|
||||||
if (!ts)
|
|
||||||
return 0;
|
|
||||||
stktable_store(&px->table, ts);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
stktable_touch(&px->table, ts);
|
|
||||||
|
|
||||||
ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CNT);
|
ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CNT);
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
|
@ -180,6 +180,26 @@ struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key
|
|||||||
return ebmb_entry(eb, struct stksess, key);
|
return ebmb_entry(eb, struct stksess, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Lookup and touch <key> in <table>, or create the entry if it does not exist.
|
||||||
|
* This is mainly used for situations where we want to refresh a key's usage so
|
||||||
|
* that it does not expire, and we want to have it created if it was not there.
|
||||||
|
* The stksess is returned, or NULL if it could not be created.
|
||||||
|
*/
|
||||||
|
struct stksess *stktable_update_key(struct stktable *table, struct stktable_key *key)
|
||||||
|
{
|
||||||
|
struct stksess *ts;
|
||||||
|
|
||||||
|
ts = stktable_lookup_key(table, key);
|
||||||
|
if (likely(ts))
|
||||||
|
return stktable_touch(table, ts);
|
||||||
|
|
||||||
|
/* entry does not exist, initialize a new one */
|
||||||
|
ts = stksess_new(table, key);
|
||||||
|
if (likely(ts))
|
||||||
|
stktable_store(table, ts);
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Looks in table <t> for a sticky session with same key as <ts>.
|
* Looks in table <t> for a sticky session with same key as <ts>.
|
||||||
* Returns pointer on requested sticky session or NULL if none was found.
|
* Returns pointer on requested sticky session or NULL if none was found.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user