nat: report correct EI per-user session limit 01/32301/5
authorMatthew Smith <mgsmith@netgate.com>
Thu, 13 May 2021 16:11:33 +0000 (11:11 -0500)
committerMatthew Smith <mgsmith@netgate.com>
Tue, 25 May 2021 13:12:01 +0000 (13:12 +0000)
Type: fix

When enabling the endpoint independent NAT44 plugin, user_sessions
determines the maximum number of translations that can be active for
a single inside address. If 0 is passed in, a default value is used
but 0 is still stored in the field that is used to populate reply
messages to nat44_ei_show_running_config,

At the time of enabling the plugin, if user_sessions is 0, update the
field which is used by nat44_ei_show_running_config to contain the
default per-user limit which gets used by the EI nodes.

Change-Id: I6b060d85bcd42d91db879b95a8b07c6844bcd2a5
Signed-off-by: Matthew Smith <mgsmith@netgate.com>
src/plugins/nat/nat44-ei/nat44_ei.api
src/plugins/nat/nat44-ei/nat44_ei.c
test/test_nat44_ei.py

index 38251b0..9ea1a3a 100644 (file)
@@ -13,7 +13,7 @@
  * limitations under the License.
  */
 
-option version = "1.1.0";
+option version = "1.1.1";
 import "vnet/ip/ip_types.api";
 import "vnet/interface_types.api";
 import "plugins/nat/lib/nat_types.api";
index 77c224d..3c9a9a8 100644 (file)
@@ -428,6 +428,9 @@ nat44_ei_plugin_enable (nat44_ei_config_t c)
   if (!c.sessions)
     c.sessions = 10 * 1024;
 
+  if (!c.user_sessions)
+    c.user_sessions = c.sessions;
+
   nm->rconfig = c;
 
   if (!nm->frame_queue_nelts)
@@ -448,8 +451,7 @@ nat44_ei_plugin_enable (nat44_ei_config_t c)
 
   nm->max_users_per_thread = c.users;
   nm->max_translations_per_thread = c.sessions;
-  nm->max_translations_per_user =
-    c.user_sessions ? c.user_sessions : nm->max_translations_per_thread;
+  nm->max_translations_per_user = c.user_sessions;
 
   nm->inside_vrf_id = c.inside_vrf;
   nm->inside_fib_index = fib_table_find_or_create_and_lock (
index 4160ea2..74a082e 100644 (file)
@@ -3806,6 +3806,12 @@ class TestNAT44EI(MethodHolder):
                 "Invalid packet (src IP %s translated to %s, but expected %s)"
                 % (p_sent[IP].src, p_recvd[IP].src, a))
 
+    def test_default_user_sessions(self):
+        """ NAT44EI default per-user session limit is used and reported """
+        nat44_ei_config = self.vapi.nat44_ei_show_running_config()
+        # a nonzero default should be reported for user_sessions
+        self.assertNotEqual(nat44_ei_config.user_sessions, 0)
+
 
 class TestNAT44Out2InDPO(MethodHolder):
     """ NAT44EI Test Cases using out2in DPO """