From 897844d1e96797f69e3e7e11d237d847fe4e46bf Mon Sep 17 00:00:00 2001 From: Nathan Skrzypczak Date: Fri, 4 Jun 2021 18:37:27 +0200 Subject: cnat: add ip/client bihash This replace the cnat ip4/ip6 to client lookups previously done with a regular hash, by a bihash lookup. Type: improvement Do the client lookup in a bihash instead of a hash. Change-Id: I730c1893525c002b44ada8e290a36802835e88e9 Signed-off-by: Nathan Skrzypczak --- src/plugins/cnat/cnat_client.h | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'src/plugins/cnat/cnat_client.h') diff --git a/src/plugins/cnat/cnat_client.h b/src/plugins/cnat/cnat_client.h index d6e3631d868..db6933c3b95 100644 --- a/src/plugins/cnat/cnat_client.h +++ b/src/plugins/cnat/cnat_client.h @@ -17,6 +17,7 @@ #define __CNAT_CLIENT_H__ #include +#include /** * A client is a representation of an IP address behind the NAT. @@ -132,8 +133,7 @@ extern void cnat_client_throttle_pool_process (); */ typedef struct cnat_client_db_t_ { - uword *crd_cip4; - uword *crd_cip6; + clib_bihash_16_8_t cc_ip_id_hash; /* Pool of addresses that have been throttled and need to be refcounted before calling cnat_client_free_by_ip */ @@ -149,27 +149,15 @@ extern cnat_client_db_t cnat_client_db; static_always_inline cnat_client_t * cnat_client_ip4_find (const ip4_address_t * ip) { - uword *p; + clib_bihash_kv_16_8_t bkey, bval; - p = hash_get (cnat_client_db.crd_cip4, ip->as_u32); + bkey.key[0] = ip->as_u32; + bkey.key[1] = 0; - if (p) - return (pool_elt_at_index (cnat_client_pool, p[0])); + if (clib_bihash_search_16_8 (&cnat_client_db.cc_ip_id_hash, &bkey, &bval)) + return (NULL); - return (NULL); -} - -static_always_inline u32 -cnat_client_ip4_find_index (const ip4_address_t * ip) -{ - uword *p; - - p = hash_get (cnat_client_db.crd_cip4, ip->as_u32); - - if (p) - return p[0]; - - return -1; + return (pool_elt_at_index (cnat_client_pool, bval.value)); } /** @@ -178,14 +166,15 @@ cnat_client_ip4_find_index (const ip4_address_t * ip) static_always_inline cnat_client_t * cnat_client_ip6_find (const ip6_address_t * ip) { - uword *p; + clib_bihash_kv_16_8_t bkey, bval; - p = hash_get_mem (cnat_client_db.crd_cip6, ip); + bkey.key[0] = ip->as_u64[0]; + bkey.key[1] = ip->as_u64[1]; - if (p) - return (pool_elt_at_index (cnat_client_pool, p[0])); + if (clib_bihash_search_16_8 (&cnat_client_db.cc_ip_id_hash, &bkey, &bval)) + return (NULL); - return (NULL); + return (pool_elt_at_index (cnat_client_pool, bval.value)); } /** -- cgit 1.2.3-korg