api: remove transport specific code from handlers
[vpp.git] / src / vnet / lisp-gpe / lisp_gpe_api.c
index 4df743c..97409f5 100644 (file)
@@ -154,13 +154,13 @@ static void
   lisp_fwd_path_t *path;
   vl_api_gpe_fwd_entry_path_details_t *rmp = NULL;
   lisp_gpe_main_t *lgm = &lisp_gpe_main;
-  unix_shared_memory_queue_t *q = NULL;
+  vl_api_registration_t *reg;
   lisp_gpe_fwd_entry_t *lfe;
 
   gpe_fwd_entry_path_dump_t_net_to_host (mp);
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
+  reg = vl_api_client_index_to_registration (mp->client_index);
+  if (!reg)
     return;
 
   if (pool_is_free_index (lgm->lisp_fwd_entry_pool, mp->fwd_entry_index))
@@ -187,7 +187,7 @@ static void
     lisp_api_set_locator (&rmp->lcl_loc, &lgt->key->lcl, path->weight);
 
     rmp->context = mp->context;
-    vl_msg_api_send_shmem (q, (u8 *) & rmp);
+    vl_api_send_msg (reg, (u8 *) rmp);
   }
 }
 
@@ -386,28 +386,30 @@ vl_api_gpe_add_del_iface_t_handler (vl_api_gpe_add_del_iface_t * mp)
 {
   vl_api_gpe_add_del_iface_reply_t *rmp;
   int rv = 0;
+  u32 vni, dp_table;
+
+  vni = clib_net_to_host_u32 (mp->vni);
+  dp_table = clib_net_to_host_u32 (mp->dp_table);
 
   if (mp->is_l2)
     {
       if (mp->is_add)
        {
-         if (~0 ==
-             lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
+         if (~0 == lisp_gpe_tenant_l2_iface_add_or_lock (vni, dp_table))
            rv = 1;
        }
       else
-       lisp_gpe_tenant_l2_iface_unlock (mp->vni);
+       lisp_gpe_tenant_l2_iface_unlock (vni);
     }
   else
     {
       if (mp->is_add)
        {
-         if (~0 ==
-             lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
+         if (~0 == lisp_gpe_tenant_l3_iface_add_or_lock (vni, dp_table, 1))
            rv = 1;
        }
       else
-       lisp_gpe_tenant_l3_iface_unlock (mp->vni);
+       lisp_gpe_tenant_l3_iface_unlock (vni);
     }
 
   REPLY_MACRO (VL_API_GPE_ADD_DEL_IFACE_REPLY);
@@ -441,40 +443,56 @@ static void
   vl_api_gpe_add_del_native_fwd_rpath_t_handler
   (vl_api_gpe_add_del_native_fwd_rpath_t * mp)
 {
-  vl_api_gpe_add_del_fwd_entry_reply_t *rmp;
+  vl_api_gpe_add_del_native_fwd_rpath_reply_t *rmp;
   vnet_gpe_native_fwd_rpath_args_t _a, *a = &_a;
   int rv = 0;
 
   memset (a, 0, sizeof (a[0]));
 
   if (mp->is_ip4)
-    clib_memcpy (&a->rpath.frp_addr, mp->nh_addr, sizeof (ip4_address_t));
+    clib_memcpy (&a->rpath.frp_addr.ip4, mp->nh_addr, sizeof (ip4_address_t));
   else
-    clib_memcpy (&a->rpath.frp_addr, mp->nh_addr, sizeof (ip6_address_t));
+    clib_memcpy (&a->rpath.frp_addr.ip6, mp->nh_addr, sizeof (ip6_address_t));
 
   a->is_add = mp->is_add;
-  a->rpath.frp_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
-  a->rpath.frp_fib_index = fib_table_find (a->rpath.frp_proto,
-                                          clib_net_to_host_u32
-                                          (mp->table_id));
+  a->rpath.frp_proto = mp->is_ip4 ? DPO_PROTO_IP4 : DPO_PROTO_IP6;
+  a->rpath.frp_fib_index =
+    fib_table_find (dpo_proto_to_fib (a->rpath.frp_proto),
+                   clib_net_to_host_u32 (mp->table_id));
+  if (~0 == a->rpath.frp_fib_index)
+    {
+      rv = VNET_API_ERROR_INVALID_VALUE;
+      goto done;
+    }
+
   a->rpath.frp_sw_if_index = clib_net_to_host_u32 (mp->nh_sw_if_index);
   a->rpath.frp_weight = 1;
 
   rv = vnet_gpe_add_del_native_fwd_rpath (a);
+done:
   REPLY_MACRO (VL_API_GPE_ADD_DEL_NATIVE_FWD_RPATH_REPLY);
 }
 
 static void
 gpe_native_fwd_rpaths_copy (vl_api_gpe_native_fwd_rpath_t * dst,
-                           fib_route_path_t * src)
+                           fib_route_path_t * src, u8 is_ip4)
 {
   fib_route_path_t *e;
+  fib_table_t *table;
   u32 i = 0;
 
   vec_foreach (e, src)
   {
     memset (&dst[i], 0, sizeof (*dst));
-    clib_memcpy (&dst[i], e, sizeof (fib_route_path_t *));
+    table = fib_table_get (e->frp_fib_index, dpo_proto_to_fib (e->frp_proto));
+    dst[i].fib_index = table->ft_table_id;
+    dst[i].nh_sw_if_index = e->frp_sw_if_index;
+    dst[i].is_ip4 = is_ip4;
+    if (is_ip4)
+      clib_memcpy (&dst[i].nh_addr, &e->frp_addr.ip4, sizeof (ip4_address_t));
+    else
+      clib_memcpy (&dst[i].nh_addr, &e->frp_addr.ip6, sizeof (ip6_address_t));
+    i++;
   }
 }
 
@@ -509,15 +527,18 @@ vl_api_gpe_native_fwd_rpaths_get_t_handler (vl_api_gpe_native_fwd_rpaths_get_t
   u32 size = 0;
   int rv = 0;
 
-  size = vec_len (lgm->native_fwd_rpath[mp->is_ip4])
+  u8 rpath_index = mp->is_ip4 ? 0 : 1;
+
+  size = vec_len (lgm->native_fwd_rpath[rpath_index])
     * sizeof (vl_api_gpe_native_fwd_rpath_t);
 
   /* *INDENT-OFF* */
   REPLY_MACRO4 (VL_API_GPE_NATIVE_FWD_RPATHS_GET_REPLY, size,
   {
-    rmp->count = vec_len (lgm->native_fwd_rpath[mp->is_ip4]);
+    rmp->count = vec_len (lgm->native_fwd_rpath[rpath_index]);
     gpe_native_fwd_rpaths_copy (rmp->entries,
-                               lgm->native_fwd_rpath[mp->is_ip4]);
+                               lgm->native_fwd_rpath[rpath_index],
+                               mp->is_ip4);
     gpe_native_fwd_rpaths_get_reply_t_host_to_net (rmp);
   });
   /* *INDENT-ON* */