From dc243ee2bcc4926ec23e71a687bb62b5c52c2fbb Mon Sep 17 00:00:00 2001 From: Klement Sekera Date: Thu, 25 Feb 2021 16:47:23 +0100 Subject: nat: pick outside addr based on local addr Use outside addresses more evenly by using local address to pick from pool of addresses. This ensures stability from POV of remote host - an internal host always gets translated using the same outside address, so it doesn't appear to be "hopping". Also, this avoids all hosts being translated using the first address, which helps avoid needless recaptchas and the like. Exact assignment depends on internal ordering of addresses - local address is used to pick an offset into internal vector. If that address cannot be used, a linear search is performed as a fallback mechanism to find a possible translation. Type: improvement Signed-off-by: Klement Sekera Change-Id: I7ccb1da1dda5537f5d30d2f4cb48024f4b51c1a4 --- src/plugins/nat/nat44-ei/nat44_ei_in2out.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/nat/nat44-ei/nat44_ei_in2out.c') diff --git a/src/plugins/nat/nat44-ei/nat44_ei_in2out.c b/src/plugins/nat/nat44-ei/nat44_ei_in2out.c index 80beb7a49eb..d1a962f5222 100644 --- a/src/plugins/nat/nat44-ei/nat44_ei_in2out.c +++ b/src/plugins/nat/nat44-ei/nat44_ei_in2out.c @@ -336,8 +336,8 @@ slow_path (nat44_ei_main_t *nm, vlib_buffer_t *b0, ip4_header_t *ip0, { /* Try to create dynamic translation */ if (nm->alloc_addr_and_port ( - nm->addresses, rx_fib_index0, thread_index, nat_proto, &sm_addr, - &sm_port, nm->port_per_thread, + nm->addresses, rx_fib_index0, thread_index, nat_proto, + ip0->src_address, &sm_addr, &sm_port, nm->port_per_thread, nm->per_thread_data[thread_index].snat_thread_index)) { b0->error = node->errors[NAT44_EI_IN2OUT_ERROR_OUT_OF_PORTS]; -- cgit 1.2.3-korg