diff options
author | Nathan Skrzypczak <nathan.skrzypczak@gmail.com> | 2021-02-25 11:14:53 +0100 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2021-02-26 01:55:07 +0000 |
commit | 4d237874e5c9922330c62ac1b003a9a171c1bc3b (patch) | |
tree | 3ce74a3e85659124653e8406635bec29e156b9f2 /src/plugins/cnat/cnat_node.h | |
parent | 27647a27c7b1e800547e3a3ea97b099b25618177 (diff) |
cnat: Add maglev support
* Backend choice in translations is controlled
by lb_type switch allowing to enable Maglev.
* Size of pool is set with cnat { maglev-len 1009 }
Type: feature
Change-Id: I956e19d70bc9f3b997b4f8042831164e4b559d17
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Diffstat (limited to 'src/plugins/cnat/cnat_node.h')
-rw-r--r-- | src/plugins/cnat/cnat_node.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/plugins/cnat/cnat_node.h b/src/plugins/cnat/cnat_node.h index 56a6c612e1b..157287b0cab 100644 --- a/src/plugins/cnat/cnat_node.h +++ b/src/plugins/cnat/cnat_node.h @@ -803,6 +803,35 @@ error: return; } +static_always_inline cnat_ep_trk_t * +cnat_load_balance (const cnat_translation_t *ct, ip_address_family_t af, + ip4_header_t *ip4, ip6_header_t *ip6, u32 *dpoi_index) +{ + cnat_main_t *cm = &cnat_main; + const load_balance_t *lb0; + const dpo_id_t *dpo0; + u32 hash_c0, bucket0; + + lb0 = load_balance_get (ct->ct_lb.dpoi_index); + if (PREDICT_FALSE (!lb0->lb_n_buckets)) + return (NULL); + + /* session table miss */ + hash_c0 = (AF_IP4 == af ? ip4_compute_flow_hash (ip4, lb0->lb_hash_config) : + ip6_compute_flow_hash (ip6, lb0->lb_hash_config)); + + if (PREDICT_FALSE (ct->lb_type == CNAT_LB_MAGLEV)) + bucket0 = ct->lb_maglev[hash_c0 % cm->maglev_len]; + else + bucket0 = hash_c0 % lb0->lb_n_buckets; + + dpo0 = load_balance_get_fwd_bucket (lb0, bucket0); + + *dpoi_index = dpo0->dpoi_index; + + return &ct->ct_active_paths[bucket0]; +} + /** * Create NAT sessions * rsession_location is the location the (return) session will be |