diff options
author | Ole Troan <ot@cisco.com> | 2020-09-14 12:21:13 +0200 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2020-09-14 13:06:21 +0000 |
commit | 9459d65ba43c36b3e4117e0df9d07f8e9e2babd1 (patch) | |
tree | 77a4c7539622987d77c5cebf7406d7660e12b62d /src/plugins/nat | |
parent | b509504e6b6eb8590d2d7dad2447c1bd933ce94c (diff) |
nat: delay datastructure allocation until configured
The dslite plugin would on plugin load initialize large bihash datastructures.
Postpone until configured.
Type: improvement
Change-Id: Ie790ab8c5fc39fac18153acd54dcd051805e763a
Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/plugins/nat')
-rw-r--r-- | src/plugins/nat/dslite/dslite.c | 50 | ||||
-rw-r--r-- | src/plugins/nat/dslite/dslite.h | 1 |
2 files changed, 33 insertions, 18 deletions
diff --git a/src/plugins/nat/dslite/dslite.c b/src/plugins/nat/dslite/dslite.c index 4ca24a4bfff..4fe4422df13 100644 --- a/src/plugins/nat/dslite/dslite.c +++ b/src/plugins/nat/dslite/dslite.c @@ -34,11 +34,6 @@ dslite_init (vlib_main_t * vm) vlib_thread_main_t *tm = vlib_get_thread_main (); uword *p; vlib_node_t *node; - dslite_per_thread_data_t *td; - u32 translation_buckets = 1024; - u32 translation_memory_size = 128 << 20; - u32 b4_buckets = 128; - u32 b4_memory_size = 64 << 20; node = vlib_get_node_by_name (vm, (u8 *) "dslite-in2out"); dm->dslite_in2out_node_index = node->index; @@ -74,20 +69,8 @@ dslite_init (vlib_main_t * vm) vec_validate (dm->per_thread_data, tm->n_vlib_mains - 1); - /* *INDENT-OFF* */ - vec_foreach (td, dm->per_thread_data) - { - clib_bihash_init_24_8 (&td->in2out, "in2out", translation_buckets, - translation_memory_size); - - clib_bihash_init_8_8 (&td->out2in, "out2in", translation_buckets, - translation_memory_size); - - clib_bihash_init_16_8 (&td->b4_hash, "b4s", b4_buckets, b4_memory_size); - } - /* *INDENT-ON* */ - dm->is_ce = 0; + dm->is_enabled = 0; /* Init counters */ dm->total_b4s.name = "total-b4s"; @@ -108,6 +91,31 @@ dslite_init (vlib_main_t * vm) return dslite_api_hookup (vm); } +static void +dslite_init_datastructures (void) +{ + dslite_main_t *dm = &dslite_main; + dslite_per_thread_data_t *td; + u32 translation_buckets = 1024; + u32 translation_memory_size = 128 << 20; + u32 b4_buckets = 128; + u32 b4_memory_size = 64 << 20; + + /* *INDENT-OFF* */ + vec_foreach (td, dm->per_thread_data) + { + clib_bihash_init_24_8 (&td->in2out, "dslite in2out", translation_buckets, + translation_memory_size); + + clib_bihash_init_8_8 (&td->out2in, "dslite out2in", translation_buckets, + translation_memory_size); + + clib_bihash_init_16_8 (&td->b4_hash, "dslite b4s", b4_buckets, b4_memory_size); + } + /* *INDENT-ON* */ + dm->is_enabled = 1; +} + void dslite_set_ce (dslite_main_t * dm, u8 set) { @@ -134,6 +142,9 @@ dslite_set_aftr_ip6_addr (dslite_main_t * dm, ip6_address_t * addr) { dpo_id_t dpo = DPO_INVALID; + if (!dm->is_enabled) + dslite_init_datastructures (); + if (dm->is_ce) { dslite_ce_dpo_create (DPO_PROTO_IP4, 0, &dpo); @@ -175,6 +186,9 @@ dslite_set_aftr_ip4_addr (dslite_main_t * dm, ip4_address_t * addr) int dslite_set_b4_ip6_addr (dslite_main_t * dm, ip6_address_t * addr) { + if (!dm->is_enabled) + dslite_init_datastructures (); + if (dm->is_ce) { dpo_id_t dpo = DPO_INVALID; diff --git a/src/plugins/nat/dslite/dslite.h b/src/plugins/nat/dslite/dslite.h index 8cb73d88409..3c798bf54fe 100644 --- a/src/plugins/nat/dslite/dslite.h +++ b/src/plugins/nat/dslite/dslite.h @@ -127,6 +127,7 @@ typedef struct * otherwise it behaves as AFTR */ u8 is_ce; + u8 is_enabled; u16 msg_id_base; } dslite_main_t; |