aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2018-05-09 04:51:03 -0700
committerDamjan Marion <dmarion.lists@gmail.com>2018-05-10 16:16:33 +0000
commit132dc49ee847a3e3b644de8b36499d73e8a8d37e (patch)
tree6cc60d618c2b74290e821283d49b1e41e39e445b
parenta35cc14d37466f0737fa928d25697fbfe6e7d657 (diff)
NAT44: sessions counters per user fix (VPP-1270)
Change-Id: I6306b81e0e1c3e1c591f929a76bb265c1c1d0859 Signed-off-by: Matus Fabian <matfabia@cisco.com>
-rwxr-xr-xsrc/plugins/nat/nat.c12
-rw-r--r--test/test_nat.py25
2 files changed, 31 insertions, 6 deletions
diff --git a/src/plugins/nat/nat.c b/src/plugins/nat/nat.c
index 68b43c05ea1..4f9b04ad4b0 100755
--- a/src/plugins/nat/nat.c
+++ b/src/plugins/nat/nat.c
@@ -334,6 +334,10 @@ nat_session_alloc_or_recycle (snat_main_t *sm, snat_user_t *u, u32 thread_index)
/* Get the session */
s = pool_elt_at_index (tsm->sessions, session_index);
nat_free_session_data (sm, s, thread_index);
+ if (snat_is_session_static(s))
+ u->nstaticsessions--;
+ else
+ u->nsessions--;
s->outside_address_index = ~0;
s->flags = 0;
s->total_bytes = 0;
@@ -975,12 +979,8 @@ int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr,
if (snat_is_session_static (s))
continue;
- if (!addr_only)
- {
- if ((s->out2in.addr.as_u32 != e_addr.as_u32) &&
- (clib_net_to_host_u16 (s->out2in.port) != e_port))
- continue;
- }
+ if (!addr_only && (clib_net_to_host_u16 (s->out2in.port) != m->local_port))
+ continue;
nat_free_session_data (sm, s, tsm - sm->per_thread_data);
clib_dlist_remove (tsm->list_pool, s->per_user_index);
diff --git a/test/test_nat.py b/test/test_nat.py
index c4018cf66d8..7c841f515c4 100644
--- a/test/test_nat.py
+++ b/test/test_nat.py
@@ -2480,6 +2480,31 @@ class TestNAT44(MethodHolder):
# verify number of translated packet
self.pg1.get_capture(pkts_num)
+ users = self.vapi.nat44_user_dump()
+ for user in users:
+ if user.ip_address == self.pg0.remote_ip4n:
+ self.assertEqual(user.nsessions,
+ nat44_config.max_translations_per_user)
+ self.assertEqual(user.nstaticsessions, 0)
+
+ tcp_port = 22
+ self.nat44_add_static_mapping(self.pg0.remote_ip4, self.nat_addr,
+ tcp_port, tcp_port,
+ proto=IP_PROTOS.tcp)
+ p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
+ IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4) /
+ TCP(sport=tcp_port))
+ self.pg0.add_stream(p)
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+ self.pg1.get_capture(1)
+ users = self.vapi.nat44_user_dump()
+ for user in users:
+ if user.ip_address == self.pg0.remote_ip4n:
+ self.assertEqual(user.nsessions,
+ nat44_config.max_translations_per_user - 1)
+ self.assertEqual(user.nstaticsessions, 1)
+
def test_interface_addr(self):
""" Acquire NAT44 addresses from interface """
self.vapi.nat44_add_interface_addr(self.pg7.sw_if_index)