nat: fixed return values of enable/disable call 95/37695/5
authorFilip Varga <filipvarga89@gmail.com>
Wed, 23 Nov 2022 18:47:56 +0000 (10:47 -0800)
committerMatthew Smith <mgsmith@netgate.com>
Fri, 9 Dec 2022 18:24:08 +0000 (18:24 +0000)
NAT44 enable/disable return status was used
instead of appropriate VNET_API_ERROR_ code.

Type: fix
Signed-off-by: Filip Varga <filipvarga89@gmail.com>
Change-Id: If944866bf3061afdc91284c0ad475135e529bdc4

src/plugins/nat/nat44-ed/nat44_ed.c
src/plugins/nat/nat44-ei/nat44_ei.c
src/plugins/nat/nat44-ei/nat44_ei_api.c
src/vnet/error.h

index 133c39e..348fff2 100644 (file)
@@ -59,7 +59,7 @@ static_always_inline void nat_validate_interface_counters (snat_main_t *sm,
       if (PREDICT_FALSE (sm->enabled))                                        \
        {                                                                     \
          nat_log_err ("plugin enabled");                                     \
-         return 1;                                                           \
+         return VNET_API_ERROR_FEATURE_ALREADY_ENABLED;                      \
        }                                                                     \
     }                                                                         \
   while (0)
@@ -71,7 +71,7 @@ static_always_inline void nat_validate_interface_counters (snat_main_t *sm,
       if (PREDICT_FALSE (!sm->enabled))                                       \
        {                                                                     \
          nat_log_err ("plugin disabled");                                    \
-         return 1;                                                           \
+         return VNET_API_ERROR_FEATURE_ALREADY_DISABLED;                     \
        }                                                                     \
     }                                                                         \
   while (0)
@@ -2626,19 +2626,19 @@ nat44_plugin_disable ()
 
   rc = nat44_ed_del_static_mappings ();
   if (rc)
-    error = 1;
+    error = VNET_API_ERROR_BUG;
 
   rc = nat44_ed_del_addresses ();
   if (rc)
-    error = 1;
+    error = VNET_API_ERROR_BUG;
 
   rc = nat44_ed_del_interfaces ();
   if (rc)
-    error = 1;
+    error = VNET_API_ERROR_BUG;
 
   rc = nat44_ed_del_output_interfaces ();
   if (rc)
-    error = 1;
+    error = VNET_API_ERROR_BUG;
 
   nat44_ed_del_vrf_tables ();
 
index 448566d..171ca7d 100644 (file)
@@ -61,7 +61,7 @@ extern vlib_node_registration_t
       if (PREDICT_FALSE (nm->enabled))                                        \
        {                                                                     \
          nat44_ei_log_err ("plugin enabled");                                \
-         return 1;                                                           \
+         return VNET_API_ERROR_FEATURE_ALREADY_ENABLED;                      \
        }                                                                     \
     }                                                                         \
   while (0)
@@ -73,7 +73,7 @@ extern vlib_node_registration_t
       if (PREDICT_FALSE (!nm->enabled))                                       \
        {                                                                     \
          nat44_ei_log_err ("plugin disabled");                               \
-         return 1;                                                           \
+         return VNET_API_ERROR_FEATURE_ALREADY_DISABLED;                     \
        }                                                                     \
     }                                                                         \
   while (0)
@@ -1221,23 +1221,25 @@ nat44_ei_plugin_disable ()
   nat44_ei_main_per_thread_data_t *tnm;
   int rc, error = 0;
 
+  fail_if_disabled ();
+
   nat_ha_disable ();
 
   rc = nat44_ei_del_static_mappings ();
   if (rc)
-    error = 1;
+    error = VNET_API_ERROR_BUG;
 
   rc = nat44_ei_del_addresses ();
   if (rc)
-    error = 1;
+    error = VNET_API_ERROR_BUG;
 
   rc = nat44_ei_del_interfaces ();
   if (rc)
-    error = 1;
+    error = VNET_API_ERROR_BUG;
 
   rc = nat44_ei_del_output_interfaces ();
   if (rc)
-    error = 1;
+    error = VNET_API_ERROR_BUG;
 
   if (nm->pat)
     {
index 2d83eb7..8671a55 100644 (file)
@@ -173,7 +173,9 @@ vl_api_nat44_ei_plugin_enable_disable_t_handler (
       rv = nat44_ei_plugin_enable (c);
     }
   else
-    rv = nat44_ei_plugin_disable ();
+    {
+      rv = nat44_ei_plugin_disable ();
+    }
 
   REPLY_MACRO (VL_API_NAT44_EI_PLUGIN_ENABLE_DISABLE_REPLY);
 }
index 39a609b..3feb8ff 100644 (file)
   _ (EAGAIN, -165, "Retry stream call with cursor")                           \
   _ (INVALID_VALUE_4, -166, "Invalid value #4")                               \
   _ (BUSY, -167, "Busy")                                                      \
-  _ (BUG, -168, "Bug")
+  _ (BUG, -168, "Bug")                                                        \
+  _ (FEATURE_ALREADY_DISABLED, -169, "Feature already disabled")              \
+  _ (FEATURE_ALREADY_ENABLED, -170, "Feature already enabled")
 
 typedef enum
 {