X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnat%2Fnat.c;h=c3583cabc218ac8b730f58e732614792e1f35d23;hb=df865200c769e31b5fe8f4b246516f07b80f4004;hp=fe6d6cae82f87e19497a65dc0df0db6e6237e04e;hpb=5d28c7afbc0abd172d0053768b2ebe37b7a6c348;p=vpp.git diff --git a/src/plugins/nat/nat.c b/src/plugins/nat/nat.c index fe6d6cae82f..c3583cabc21 100755 --- a/src/plugins/nat/nat.c +++ b/src/plugins/nat/nat.c @@ -742,6 +742,7 @@ int snat_add_address (snat_main_t *sm, ip4_address_t *addr, u32 vrf_id, #define _(N, i, n, s) \ clib_bitmap_alloc (ap->busy_##n##_port_bitmap, 65535); \ ap->busy_##n##_ports = 0; \ + ap->busy_##n##_ports_per_thread = 0;\ vec_validate_init_empty (ap->busy_##n##_ports_per_thread, tm->n_vlib_mains - 1, 0); foreach_snat_protocol #undef _ @@ -816,6 +817,17 @@ snat_add_static_mapping_when_resolved (snat_main_t * sm, rp->is_add = is_add; rp->tag = vec_dup (tag); } + +static u32 get_thread_idx_by_port(u16 e_port) +{ + snat_main_t * sm = &snat_main; + u32 thread_idx = sm->num_workers; + if (sm->num_workers > 1) + { + thread_idx = sm->first_worker_index + sm->workers[(e_port - 1024) / sm->port_per_thread]; + } + return thread_idx; +} /** * @brief Add static mapping. @@ -1003,7 +1015,7 @@ int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, if (e_port > 1024) \ { \ a->busy_##n##_ports++; \ - a->busy_##n##_ports_per_thread[(e_port - 1024) / sm->port_per_thread]++; \ + a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]++; \ } \ break; foreach_snat_protocol @@ -1148,7 +1160,7 @@ int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, if (e_port > 1024) \ { \ a->busy_##n##_ports--; \ - a->busy_##n##_ports_per_thread[(e_port - 1024) / sm->port_per_thread]--; \ + a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]--; \ } \ break; foreach_snat_protocol @@ -1320,7 +1332,7 @@ int nat44_add_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port, if (e_port > 1024) \ { \ a->busy_##n##_ports++; \ - a->busy_##n##_ports_per_thread[(e_port - 1024) / sm->port_per_thread]++; \ + a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]++; \ } \ break; foreach_snat_protocol @@ -1423,7 +1435,7 @@ int nat44_add_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port, if (e_port > 1024) \ { \ a->busy_##n##_ports--; \ - a->busy_##n##_ports_per_thread[(e_port - 1024) / sm->port_per_thread]--; \ + a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]--; \ } \ break; foreach_snat_protocol @@ -1596,6 +1608,12 @@ snat_del_address (snat_main_t *sm, ip4_address_t addr, u8 delete_sm, } } +#define _(N, i, n, s) \ + clib_bitmap_free (a->busy_##n##_port_bitmap); \ + vec_free (a->busy_##n##_ports_per_thread); + foreach_snat_protocol +#undef _ + if (twice_nat) { vec_del1 (sm->twice_nat_addresses, i); @@ -2067,6 +2085,7 @@ static clib_error_t * snat_init (vlib_main_t * vm) sm->log_class = vlib_log_register_class ("nat", 0); error_drop_node = vlib_get_node_by_name (vm, (u8 *) "error-drop"); sm->error_node_index = error_drop_node->index; + sm->mss_clamping = 0; p = hash_get_mem (tm->thread_registrations_by_name, "workers"); if (p)