nat: NAT44-ED api fix and improvement 42/33742/7
authorFilip Varga <fivarga@cisco.com>
Fri, 17 Sep 2021 12:11:59 +0000 (14:11 +0200)
committerOle Tr�an <otroan@employees.org>
Wed, 20 Oct 2021 10:46:13 +0000 (10:46 +0000)
This patch fixes issue with NAT_API_IS_TWICE_NAT and
NAT_API_IS_ADDR_ONLY flags. Because of control plane
code change - move from boolean parameters to flags
in https://gerrit.fd.io/r/c/vpp/+/32796 patch these
api flags weren't correctly set.

Type: fix

Change-Id: Ieec5fe6bdcca314da027f2d23e3a24f174391a6f
Signed-off-by: Filip Varga <fivarga@cisco.com>
src/plugins/nat/nat44-ed/nat44_ed.c
src/plugins/nat/nat44-ed/nat44_ed.h
src/plugins/nat/nat44-ed/nat44_ed_api.c
src/plugins/nat/nat44-ed/nat44_ed_format.c

index b1917f3..f58002c 100644 (file)
@@ -3068,7 +3068,7 @@ nat44_ed_add_del_static_mapping_addr_only_cb (
   for (i = 0; i < vec_len (sm->to_resolve); i++)
     {
       rp = sm->to_resolve + i;
-      if (rp->addr_only && rp->sw_if_index == sw_if_index)
+      if (is_sm_addr_only (rp->flags) && rp->sw_if_index == sw_if_index)
        {
          match = 1;
          break;
@@ -3079,8 +3079,8 @@ nat44_ed_add_del_static_mapping_addr_only_cb (
       return;
     }
 
-  m = nat44_ed_sm_o2i_lookup (sm, *address, rp->addr_only ? 0 : rp->e_port, 0,
-                             rp->proto);
+  m = nat44_ed_sm_o2i_lookup (
+    sm, *address, is_sm_addr_only (rp->flags) ? 0 : rp->e_port, 0, rp->proto);
 
   if (is_delete)
     {
@@ -3171,7 +3171,7 @@ nat44_ed_add_del_interface_address_cb (ip4_main_t *im, uword opaque,
       for (i = 0; i < vec_len (sm->to_resolve); i++)
        {
          rp = sm->to_resolve + i;
-         if (rp->addr_only)
+         if (is_sm_addr_only (rp->flags))
            {
              continue;
            }
index 4665f7c..9fb34aa 100644 (file)
@@ -455,11 +455,6 @@ typedef struct
   u32 vrf_id;
   ip_protocol_t proto;
   u32 flags;
-  int addr_only;
-  int twice_nat;
-  int out2in_only;
-  int identity_nat;
-  int exact;
   u8 *tag;
 } snat_static_map_resolve_t;
 
index 759cfd3..1505975 100644 (file)
@@ -840,10 +840,12 @@ send_nat44_static_map_resolve_details (snat_static_map_resolve_t * m,
   rmp->vrf_id = htonl (m->vrf_id);
   rmp->context = context;
 
-  if (m->twice_nat)
-    rmp->flags |= NAT_API_IS_TWICE_NAT;
+  if (is_sm_twice_nat (m->flags))
+    {
+      rmp->flags |= NAT_API_IS_TWICE_NAT;
+    }
 
-  if (m->addr_only)
+  if (is_sm_addr_only (m->flags))
     {
       rmp->flags |= NAT_API_IS_ADDR_ONLY;
     }
@@ -853,6 +855,7 @@ send_nat44_static_map_resolve_details (snat_static_map_resolve_t * m,
       rmp->external_port = m->e_port;
       rmp->local_port = m->l_port;
     }
+
   if (m->tag)
     strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
 
@@ -882,7 +885,7 @@ vl_api_nat44_static_mapping_dump_t_handler (vl_api_nat44_static_mapping_dump_t
   for (j = 0; j < vec_len (sm->to_resolve); j++)
     {
       rp = sm->to_resolve + j;
-      if (!rp->identity_nat)
+      if (!is_sm_identity_nat (rp->flags))
        send_nat44_static_map_resolve_details (rp, reg, mp->context);
     }
 }
@@ -985,7 +988,7 @@ send_nat44_identity_map_resolve_details (snat_static_map_resolve_t * m,
   rmp->_vl_msg_id =
     ntohs (VL_API_NAT44_IDENTITY_MAPPING_DETAILS + sm->msg_id_base);
 
-  if (m->addr_only)
+  if (is_sm_addr_only (m->flags))
     rmp->flags = (vl_api_nat_config_flags_t) NAT_API_IS_ADDR_ONLY;
 
   rmp->port = m->l_port;
@@ -1027,7 +1030,7 @@ static void
   for (j = 0; j < vec_len (sm->to_resolve); j++)
     {
       rp = sm->to_resolve + j;
-      if (rp->identity_nat)
+      if (is_sm_identity_nat (rp->flags))
        send_nat44_identity_map_resolve_details (rp, reg, mp->context);
     }
 }
index 5eb683d..81e743f 100644 (file)
@@ -191,7 +191,7 @@ format_snat_static_map_to_resolve (u8 * s, va_list * args)
   snat_static_map_resolve_t *m = va_arg (*args, snat_static_map_resolve_t *);
   vnet_main_t *vnm = vnet_get_main ();
 
-  if (m->addr_only)
+  if (is_sm_addr_only (m->flags))
     s = format (s, "local %U external %U vrf %d",
                format_ip4_address, &m->l_addr,
                format_vnet_sw_if_index_name, vnm, m->sw_if_index, m->vrf_id);