misc: move to new pool_foreach macros
[vpp.git] / src / plugins / nat / nat44_api.c
index 2028b35..5bc4b4c 100644 (file)
@@ -18,9 +18,6 @@
  * @brief NAT44 plugin API implementation
  */
 
-#define vl_api_nat44_lb_static_mapping_details_t_endian vl_noop_handler
-#define vl_api_nat44_add_del_lb_static_mapping_t_endian vl_noop_handler
-
 #include <vnet/ip/ip_types_api.h>
 #include <vlibmemory/api.h>
 
@@ -129,6 +126,15 @@ vl_api_nat44_show_running_config_t_handler (vl_api_nat44_show_running_config_t
     rmp->user_buckets = htonl (sm->user_buckets);
     rmp->translation_buckets = htonl (sm->translation_buckets);
 
+    rmp->timeouts.udp = htonl (sm->timeouts.udp);
+    rmp->timeouts.tcp_established = htonl (sm->timeouts.tcp.established);
+    rmp->timeouts.tcp_transitory = htonl (sm->timeouts.tcp.transitory);
+    rmp->timeouts.icmp = htonl (sm->timeouts.icmp);
+
+    rmp->forwarding_enabled = sm->forwarding_enabled == 1;
+    // consider how to split functionality between subplugins
+    rmp->ipfix_logging_enabled = nat_ipfix_logging_enabled ();
+
     if (rc->endpoint_dependent)
       rmp->flags |= NAT44_IS_ENDPOINT_DEPENDENT;
     else
@@ -300,10 +306,10 @@ vl_api_nat_set_timeouts_t_handler (vl_api_nat_set_timeouts_t * mp)
   vl_api_nat_set_timeouts_reply_t *rmp;
   int rv = 0;
 
-  sm->udp_timeout = ntohl (mp->udp);
-  sm->tcp_established_timeout = ntohl (mp->tcp_established);
-  sm->tcp_transitory_timeout = ntohl (mp->tcp_transitory);
-  sm->icmp_timeout = ntohl (mp->icmp);
+  sm->timeouts.udp = ntohl (mp->udp);
+  sm->timeouts.tcp.established = ntohl (mp->tcp_established);
+  sm->timeouts.tcp.transitory = ntohl (mp->tcp_transitory);
+  sm->timeouts.icmp = ntohl (mp->icmp);
 
   REPLY_MACRO (VL_API_NAT_SET_TIMEOUTS_REPLY);
 }
@@ -318,10 +324,10 @@ vl_api_nat_get_timeouts_t_handler (vl_api_nat_get_timeouts_t * mp)
   /* *INDENT-OFF* */
   REPLY_MACRO2 (VL_API_NAT_GET_TIMEOUTS_REPLY,
   ({
-    rmp->udp = htonl (sm->udp_timeout);
-    rmp->tcp_established = htonl (sm->tcp_established_timeout);
-    rmp->tcp_transitory = htonl (sm->tcp_transitory_timeout);
-    rmp->icmp = htonl (sm->icmp_timeout);
+    rmp->udp = htonl (sm->timeouts.udp);
+    rmp->tcp_established = htonl (sm->timeouts.tcp.established);
+    rmp->tcp_transitory = htonl (sm->timeouts.tcp.transitory);
+    rmp->icmp = htonl (sm->timeouts.icmp);
   }))
   /* *INDENT-ON* */
 }
@@ -335,6 +341,12 @@ static void
   int rv = 0;
   u16 port_start, port_end;
 
+  if (sm->endpoint_dependent)
+    {
+      rv = VNET_API_ERROR_UNSUPPORTED;
+      goto send_reply;
+    }
+
   switch (mp->alg)
     {
     case NAT_ADDR_AND_PORT_ALLOC_ALG_DEFAULT:
@@ -713,10 +725,10 @@ vl_api_nat44_interface_dump_t_handler (vl_api_nat44_interface_dump_t * mp)
     return;
 
   /* *INDENT-OFF* */
-  pool_foreach (i, sm->interfaces,
-  ({
+  pool_foreach (i, sm->interfaces)
+   {
     send_nat44_interface_details(i, reg, mp->context);
-  }));
+  }
   /* *INDENT-ON* */
 }
 
@@ -773,10 +785,10 @@ static void
     return;
 
   /* *INDENT-OFF* */
-  pool_foreach (i, sm->output_feature_interfaces,
-  ({
+  pool_foreach (i, sm->output_feature_interfaces)
+   {
     send_nat44_interface_output_feature_details(i, reg, mp->context);
-  }));
+  }
   /* *INDENT-ON* */
 }
 
@@ -970,11 +982,11 @@ vl_api_nat44_static_mapping_dump_t_handler (vl_api_nat44_static_mapping_dump_t
     return;
 
   /* *INDENT-OFF* */
-  pool_foreach (m, sm->static_mappings,
-  ({
+  pool_foreach (m, sm->static_mappings)
+   {
       if (!is_identity_static_mapping(m) && !is_lb_static_mapping (m))
         send_nat44_static_mapping_details (m, reg, mp->context);
-  }));
+  }
   /* *INDENT-ON* */
 
   for (j = 0; j < vec_len (sm->to_resolve); j++)
@@ -1092,16 +1104,16 @@ static void
     return;
 
   /* *INDENT-OFF* */
-  pool_foreach (m, sm->static_mappings,
-  ({
+  pool_foreach (m, sm->static_mappings)
+   {
       if (is_identity_static_mapping(m) && !is_lb_static_mapping (m))
         {
-          pool_foreach_index (j, m->locals,
-          ({
+          pool_foreach_index (j, m->locals)
+           {
             send_nat44_identity_mapping_details (m, j, reg, mp->context);
-          }));
+          }
         }
-  }));
+  }
   /* *INDENT-ON* */
 
   for (j = 0; j < vec_len (sm->to_resolve); j++)
@@ -1239,7 +1251,7 @@ nat_ed_users_create (snat_main_per_thread_data_t * tsm)
 {
   snat_session_t *s;
   /* *INDENT-OFF* */
-  pool_foreach (s, tsm->sessions, { nat_ed_user_create_helper (tsm, s); });
+  pool_foreach (s, tsm->sessions) { nat_ed_user_create_helper (tsm, s); }
   /* *INDENT-ON* */
 }
 
@@ -1274,10 +1286,10 @@ vl_api_nat44_user_dump_t_handler (vl_api_nat44_user_dump_t * mp)
        {
          nat_ed_users_create (tsm);
        }
-      pool_foreach (u, tsm->users,
-      ({
+      pool_foreach (u, tsm->users)
+       {
         send_nat44_user_details (u, reg, mp->context);
-      }));
+      }
       if (sm->endpoint_dependent)
        {
          nat_ed_users_destroy (tsm);
@@ -1395,12 +1407,12 @@ vl_api_nat44_user_session_dump_t_handler (vl_api_nat44_user_session_dump_t *
   else
     {
       /* *INDENT-OFF* */
-      pool_foreach (s, tsm->sessions, {
+      pool_foreach (s, tsm->sessions) {
         if (s->in2out.addr.as_u32 == ukey.addr.as_u32)
           {
             send_nat44_user_session_details (s, reg, mp->context);
           }
-      });
+      }
       /* *INDENT-ON* */
     }
 }
@@ -1497,10 +1509,9 @@ static void
 
   rv =
     nat44_lb_static_mapping_add_del_local (e_addr,
-                                          clib_net_to_host_u16
-                                          (mp->external_port), l_addr,
-                                          clib_net_to_host_u16 (mp->
-                                                                local.port),
+                                          mp->external_port,
+                                          l_addr,
+                                          mp->local.port,
                                           proto,
                                           clib_net_to_host_u32 (mp->
                                                                 local.vrf_id),
@@ -1545,15 +1556,15 @@ send_nat44_lb_static_mapping_details (snat_static_mapping_t * m,
 
   locals = (vl_api_nat44_lb_addr_port_t *) rmp->locals;
   /* *INDENT-OFF* */
-  pool_foreach (ap, m->locals,
-  ({
+  pool_foreach (ap, m->locals)
+   {
     clib_memcpy (locals->addr, &(ap->addr), 4);
     locals->port = ap->port;
     locals->probability = ap->probability;
     locals->vrf_id = ntohl (ap->vrf_id);
     locals++;
     local_num++;
-  }));
+  }
   /* *INDENT-ON* */
   rmp->local_num = ntohl (local_num);
 
@@ -1576,11 +1587,11 @@ static void
     return;
 
   /* *INDENT-OFF* */
-  pool_foreach (m, sm->static_mappings,
-  ({
+  pool_foreach (m, sm->static_mappings)
+   {
       if (is_lb_static_mapping(m))
         send_nat44_lb_static_mapping_details (m, reg, mp->context);
-  }));
+  }
   /* *INDENT-ON* */
 }
 
@@ -1633,13 +1644,13 @@ static void
       /* *INDENT-OFF* */
       vec_foreach (tsm, sm->per_thread_data)
       {
-        pool_foreach (s, tsm->sessions,
-        ({
+        pool_foreach (s, tsm->sessions)
+         {
           if (is_fwd_bypass_session(s))
             {
               vec_add1 (ses_to_be_removed, s - tsm->sessions);
             }
-        }));
+        }
        if(sm->endpoint_dependent){
            vec_foreach (ses_index, ses_to_be_removed)
              {