IPv4/6 reassembly
[vpp.git] / src / vnet / ip / ip_api.c
index 2ea1e41..60fa2fa 100644 (file)
@@ -42,6 +42,8 @@
 #include <vnet/fib/ip4_fib.h>
 #include <vnet/fib/ip6_fib.h>
 #include <vnet/ip/ip6_hop_by_hop.h>
+#include <vnet/ip/ip4_reassembly.h>
+#include <vnet/ip/ip6_reassembly.h>
 
 #include <vnet/vnet_msg_enum.h>
 
@@ -97,7 +99,9 @@ _(IOAM_DISABLE, ioam_disable)                                           \
 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,                               \
   ip_source_and_port_range_check_add_del)                               \
 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,                     \
-  ip_source_and_port_range_check_interface_add_del)
+  ip_source_and_port_range_check_interface_add_del)                     \
+_(IP_REASSEMBLY_SET, ip_reassembly_set)                                 \
+_(IP_REASSEMBLY_GET, ip_reassembly_get)
 
 extern void stats_dslock_with_hint (int hint, int tag);
 extern void stats_dsunlock (void);
@@ -273,14 +277,14 @@ typedef struct vl_api_ip_fib_dump_walk_ctx_t_
   fib_node_index_t *feis;
 } vl_api_ip_fib_dump_walk_ctx_t;
 
-static int
+static fib_table_walk_rc_t
 vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg)
 {
   vl_api_ip_fib_dump_walk_ctx_t *ctx = arg;
 
   vec_add1 (ctx->feis, fei);
 
-  return (1);
+  return (FIB_TABLE_WALK_CONTINUE);
 }
 
 static void
@@ -1022,23 +1026,11 @@ add_del_route_check (fib_protocol_t table_proto,
 {
   vnet_main_t *vnm = vnet_get_main ();
 
-  /* Temporaray whilst I do the CSIT dance */
-  u8 create_missing_tables = 1;
-
   *fib_index = fib_table_find (table_proto, ntohl (table_id));
   if (~0 == *fib_index)
     {
-      if (create_missing_tables)
-       {
-         *fib_index = fib_table_find_or_create_and_lock (table_proto,
-                                                         ntohl (table_id),
-                                                         FIB_SOURCE_API);
-       }
-      else
-       {
-         /* No such VRF, and we weren't asked to create one */
-         return VNET_API_ERROR_NO_SUCH_FIB;
-       }
+      /* No such VRF, and we weren't asked to create one */
+      return VNET_API_ERROR_NO_SUCH_FIB;
     }
 
   if (!is_rpf_id && ~0 != ntohl (next_hop_sw_if_index))
@@ -1067,26 +1059,8 @@ add_del_route_check (fib_protocol_t table_proto,
 
       if (~0 == *next_hop_fib_index)
        {
-         if (create_missing_tables)
-           {
-             if (is_rpf_id)
-               *next_hop_fib_index =
-                 mfib_table_find_or_create_and_lock (fib_nh_proto,
-                                                     ntohl
-                                                     (next_hop_table_id),
-                                                     MFIB_SOURCE_API);
-             else
-               *next_hop_fib_index =
-                 fib_table_find_or_create_and_lock (fib_nh_proto,
-                                                    ntohl
-                                                    (next_hop_table_id),
-                                                    FIB_SOURCE_API);
-           }
-         else
-           {
-             /* No such VRF, and we weren't asked to create one */
-             return VNET_API_ERROR_NO_SUCH_FIB;
-           }
+         /* No such VRF, and we weren't asked to create one */
+         return VNET_API_ERROR_NO_SUCH_FIB;
        }
     }
 
@@ -1688,7 +1662,7 @@ typedef struct api_ip6nd_proxy_fib_table_walk_ctx_t_
   u32 *indices;
 } api_ip6nd_proxy_fib_table_walk_ctx_t;
 
-static int
+static fib_table_walk_rc_t
 api_ip6nd_proxy_fib_table_walk (fib_node_index_t fei, void *arg)
 {
   api_ip6nd_proxy_fib_table_walk_ctx_t *ctx = arg;
@@ -1698,7 +1672,7 @@ api_ip6nd_proxy_fib_table_walk (fib_node_index_t fei, void *arg)
       vec_add1 (ctx->indices, fei);
     }
 
-  return (1);
+  return (FIB_TABLE_WALK_CONTINUE);
 }
 
 static void
@@ -1824,7 +1798,7 @@ static void
 }
 
 void
-vl_mfib_signal_send_one (svm_queue_t * q,
+vl_mfib_signal_send_one (vl_api_registration_t * reg,
                         u32 context, const mfib_signal_t * mfs)
 {
   vl_api_mfib_signal_details_t *mp;
@@ -1873,21 +1847,19 @@ vl_mfib_signal_send_one (svm_queue_t * q,
       mp->ip_packet_len = 0;
     }
 
-  vl_msg_api_send_shmem (q, (u8 *) & mp);
+  vl_api_send_msg (reg, (u8 *) mp);
 }
 
 static void
 vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp)
 {
-  svm_queue_t *q;
+  vl_api_registration_t *reg;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
+  reg = vl_api_client_index_to_registration (mp->client_index);
+  if (!reg)
+    return;
 
-  while (q->cursize < q->maxsize && mfib_signal_send_one (q, mp->context))
+  while (vl_api_can_send_msg (reg) && mfib_signal_send_one (reg, mp->context))
     ;
 }
 
@@ -2107,7 +2079,7 @@ handle_ip4_arp_event (u32 pool_index)
   vlib_main_t *vm = vam->vlib_main;
   vl_api_ip4_arp_event_t *event;
   vl_api_ip4_arp_event_t *mp;
-  svm_queue_t *q;
+  vl_api_registration_t *reg;
 
   /* Client can cancel, die, etc. */
   if (pool_is_free_index (vam->arp_events, pool_index))
@@ -2115,8 +2087,8 @@ handle_ip4_arp_event (u32 pool_index)
 
   event = pool_elt_at_index (vam->arp_events, pool_index);
 
-  q = vl_api_client_index_to_input_queue (event->client_index);
-  if (!q)
+  reg = vl_api_client_index_to_registration (event->client_index);
+  if (!reg)
     {
       (void) vnet_add_del_ip4_arp_change_event
        (vnm, arp_change_delete_callback,
@@ -2126,11 +2098,11 @@ handle_ip4_arp_event (u32 pool_index)
       return;
     }
 
-  if (q->cursize < q->maxsize)
+  if (vl_api_can_send_msg (reg))
     {
       mp = vl_msg_api_alloc (sizeof (*mp));
       clib_memcpy (mp, event, sizeof (*mp));
-      vl_msg_api_send_shmem (q, (u8 *) & mp);
+      vl_api_send_msg (reg, (u8 *) mp);
     }
   else
     {
@@ -2156,7 +2128,7 @@ handle_ip6_nd_event (u32 pool_index)
   vlib_main_t *vm = vam->vlib_main;
   vl_api_ip6_nd_event_t *event;
   vl_api_ip6_nd_event_t *mp;
-  svm_queue_t *q;
+  vl_api_registration_t *reg;
 
   /* Client can cancel, die, etc. */
   if (pool_is_free_index (vam->nd_events, pool_index))
@@ -2164,8 +2136,8 @@ handle_ip6_nd_event (u32 pool_index)
 
   event = pool_elt_at_index (vam->nd_events, pool_index);
 
-  q = vl_api_client_index_to_input_queue (event->client_index);
-  if (!q)
+  reg = vl_api_client_index_to_registration (event->client_index);
+  if (!reg)
     {
       (void) vnet_add_del_ip6_nd_change_event
        (vnm, nd_change_delete_callback,
@@ -2175,11 +2147,11 @@ handle_ip6_nd_event (u32 pool_index)
       return;
     }
 
-  if (q->cursize < q->maxsize)
+  if (vl_api_can_send_msg (reg))
     {
       mp = vl_msg_api_alloc (sizeof (*mp));
       clib_memcpy (mp, event, sizeof (*mp));
-      vl_msg_api_send_shmem (q, (u8 *) & mp);
+      vl_api_send_msg (reg, (u8 *) mp);
     }
   else
     {
@@ -2331,9 +2303,9 @@ wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
             /* *INDENT-OFF* */
             pool_foreach(reg, vpe_api_main.wc_ip4_arp_events_registrations,
             ({
-             svm_queue_t *q;
-              q = vl_api_client_index_to_input_queue (reg->client_index);
-             if (q && q->cursize < q->maxsize)
+             vl_api_registration_t *vl_reg;
+              vl_reg = vl_api_client_index_to_registration (reg->client_index);
+             if (reg && vl_api_can_send_msg (vl_reg))
                {
                  vl_api_ip4_arp_event_t * event = vl_msg_api_alloc (sizeof *event);
                  memset (event, 0, sizeof *event);
@@ -2344,7 +2316,7 @@ wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
                  event->address = arp_events[i].ip4;
                  event->sw_if_index = htonl(arp_events[i].sw_if_index);
                  memcpy(event->new_mac, arp_events[i].mac, sizeof event->new_mac);
-                 vl_msg_api_send_shmem (q, (u8 *) &event);
+                 vl_api_send_msg (vl_reg, (u8 *) event);
                }
             }));
             /* *INDENT-ON* */
@@ -2370,9 +2342,9 @@ wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
               /* *INDENT-OFF* */
               pool_foreach(reg, vpe_api_main.wc_ip6_nd_events_registrations,
               ({
-               svm_queue_t *q;
-                q = vl_api_client_index_to_input_queue (reg->client_index);
-               if (q && q->cursize < q->maxsize)
+               vl_api_registration_t *vl_reg;
+                vl_reg = vl_api_client_index_to_registration (reg->client_index);
+               if (vl_reg && vl_api_can_send_msg (vl_reg))
                  {
                    vl_api_ip6_nd_event_t * event = vl_msg_api_alloc (sizeof *event);
                    memset (event, 0, sizeof *event);
@@ -2383,7 +2355,7 @@ wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
                    memcpy(event->address, nd_events[i].ip6.as_u8, sizeof event->address);
                    event->sw_if_index = htonl(nd_events[i].sw_if_index);
                    memcpy(event->new_mac, nd_events[i].mac, sizeof event->new_mac);
-                   vl_msg_api_send_shmem (q, (u8 *) &event);
+                   vl_api_send_msg (vl_reg, (u8 *) event);
                  }
               }));
             /* *INDENT-ON* */
@@ -2818,6 +2790,61 @@ vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp)
   REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY);
 }
 
+void
+vl_api_ip_reassembly_set_t_handler (vl_api_ip_reassembly_set_t * mp)
+{
+  vl_api_ip_reassembly_set_reply_t *rmp;
+  int rv = 0;
+  if (mp->is_ip6)
+    {
+      rv = ip6_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
+                         clib_net_to_host_u32 (mp->max_reassemblies),
+                         clib_net_to_host_u32 (mp->expire_walk_interval_ms));
+    }
+  else
+    {
+      rv = ip4_reass_set (clib_net_to_host_u32 (mp->timeout_ms),
+                         clib_net_to_host_u32 (mp->max_reassemblies),
+                         clib_net_to_host_u32 (mp->expire_walk_interval_ms));
+    }
+
+  REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY);
+}
+
+void
+vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp)
+{
+  unix_shared_memory_queue_t *q;
+
+  q = vl_api_client_index_to_input_queue (mp->client_index);
+
+  if (q == 0)
+    return;
+
+  vl_api_ip_reassembly_get_reply_t *rmp = vl_msg_api_alloc (sizeof (*rmp));
+  memset (rmp, 0, sizeof (*rmp));
+  rmp->_vl_msg_id = ntohs (VL_API_IP_REASSEMBLY_GET_REPLY);
+  rmp->context = mp->context;
+  rmp->retval = 0;
+  if (mp->is_ip6)
+    {
+      rmp->is_ip6 = 1;
+      ip6_reass_get (&rmp->timeout_ms, &rmp->max_reassemblies,
+                    &rmp->expire_walk_interval_ms);
+    }
+  else
+    {
+      rmp->is_ip6 = 0;
+      ip4_reass_get (&rmp->timeout_ms, &rmp->max_reassemblies,
+                    &rmp->expire_walk_interval_ms);
+    }
+  rmp->timeout_ms = clib_host_to_net_u32 (rmp->timeout_ms);
+  rmp->max_reassemblies = clib_host_to_net_u32 (rmp->max_reassemblies);
+  rmp->expire_walk_interval_ms =
+    clib_host_to_net_u32 (rmp->expire_walk_interval_ms);
+  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+}
+
 #define vl_msg_name_crc_list
 #include <vnet/ip/ip.api.h>
 #undef vl_msg_name_crc_list