25 #define AFFINITY_HASH_BUCKETS 65536 26 #define AFFINITY_HASH_MEMORY (2 << 25) 37 s =
format (s,
"client %U backend %U:%d proto %U index %llu",
122 affinity_per_service_list_head_index)) !=
127 kv.
key[0] = a->key.as_u64[0];
128 kv.
key[1] = a->key.as_u64[1];
142 u16 service_port,
u8 * backend_index)
151 if (clib_bihash_search_16_8 (&nam->
affinity_hash, &kv, &value))
173 *backend_index = a->backend_index;
206 u16 service_port,
u8 backend_index,
208 u32 affinity_per_service_list_head_index)
218 if (!clib_bihash_search_16_8 (&nam->
affinity_hash, &kv, &value))
228 clib_bihash_add_or_overwrite_stale_16_8 (&nam->
affinity_hash, &kv,
240 a->per_service_index = list_elt - nam->
list_pool;
241 a->backend_index = backend_index;
243 a->sticky_time = sticky_time;
244 a->key.as_u64[0] = kv.
key[0];
245 a->key.as_u64[1] = kv.
key[1];
247 a->per_service_index);
264 if (clib_bihash_search_16_8 (&nam->
affinity_hash, &kv, &value))
int nat_affinity_create_and_lock(ip4_address_t client_addr, ip4_address_t service_addr, u8 proto, u16 service_port, u8 backend_index, u32 sticky_time, u32 affinity_per_service_list_head_index)
Create affinity record and take reference counting lock.
ip4_address_t client_addr
nat_affinity_main_t nat_affinity_main
static void clib_dlist_init(dlist_elt_t *pool, u32 index)
u8 * format_affinity_kvp(u8 *s, va_list *args)
#define nat_elog_notice(nat_elog_str)
static f64 vlib_time_now(vlib_main_t *vm)
void nat_affinity_enable()
NAT affinity enable.
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
format_function_t format_nat_protocol
#define AFFINITY_HASH_BUCKETS
#define nat_elog_warn(nat_elog_str)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static void clib_spinlock_free(clib_spinlock_t *p)
ip4_address_t service_addr
#define static_always_inline
clib_bihash_16_8_t affinity_hash
description fragment has unexpected format
void nat_affinity_unlock(ip4_address_t client_addr, ip4_address_t service_addr, u8 proto, u16 service_port)
Release a reference counting lock for affinity.
static void clib_spinlock_init(clib_spinlock_t *p)
clib_spinlock_t affinity_lock
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void clib_dlist_addtail(dlist_elt_t *pool, u32 head_index, u32 new_index)
#define pool_put(P, E)
Free an object E in pool P.
static int affinity_is_expired_cb(clib_bihash_kv_16_8_t *kv, void *arg)
nat_affinity_t * affinity_pool
u32 nat_affinity_get_per_service_list_head_index(void)
Get new affinity per service list head index.
int nat_affinity_find_and_lock(ip4_address_t client_addr, ip4_address_t service_addr, u8 proto, u16 service_port, u8 *backend_index)
Find service backend index for client-IP and take a reference counting lock.
static_always_inline void make_affinity_kv(clib_bihash_kv_16_8_t *kv, ip4_address_t client_addr, ip4_address_t service_addr, u8 proto, u16 service_port)
#define pool_put_index(p, i)
Free pool element with given index.
clib_error_t * nat_affinity_init(vlib_main_t *vm)
Initialize NAT client-IP based affinity.
static void clib_dlist_remove(dlist_elt_t *pool, u32 index)
void nat_affinity_disable()
NAT affinity disable.
void nat_affinity_flush_service(u32 affinity_per_service_list_head_index)
Flush all service affinity data.
static vlib_thread_main_t * vlib_get_thread_main()
NAT plugin client-IP based session affinity for load-balancing.
#define AFFINITY_HASH_MEMORY
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
static u32 clib_dlist_remove_head(dlist_elt_t *pool, u32 head_index)