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",
109 affinity_per_service_list_head_index)) !=
114 kv.
key[0] = a->key.as_u64[0];
115 kv.
key[1] = a->key.as_u64[1];
129 u16 service_port,
u8 * backend_index)
138 if (clib_bihash_search_16_8 (&nam->
affinity_hash, &kv, &value))
160 *backend_index = a->backend_index;
193 u16 service_port,
u8 backend_index,
195 u32 affinity_per_service_list_head_index)
205 if (!clib_bihash_search_16_8 (&nam->
affinity_hash, &kv, &value))
215 clib_bihash_add_or_overwrite_stale_16_8 (&nam->
affinity_hash, &kv,
227 a->per_service_index = list_elt - nam->
list_pool;
228 a->backend_index = backend_index;
230 a->sticky_time = sticky_time;
231 a->key.as_u64[0] = kv.
key[0];
232 a->key.as_u64[1] = kv.
key[1];
234 a->per_service_index);
251 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)
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
#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).
ip4_address_t service_addr
#define static_always_inline
clib_bihash_16_8_t affinity_hash
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)
format_function_t format_snat_protocol
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)