FIB: encode the label stack in the FIB path during table dump
[vpp.git] / src / vnet / mpls / mpls_api.c
index 18eb748..4ac5ea7 100644 (file)
@@ -202,7 +202,7 @@ mpls_route_add_del_t_handler (vnet_main_t * vnm,
     return (rv);
 
   ip46_address_t nh;
-  memset (&nh, 0, sizeof (nh));
+  clib_memset (&nh, 0, sizeof (nh));
 
   if (DPO_PROTO_IP4 == mp->mr_next_hop_proto)
     memcpy (&nh.ip4, mp->mr_next_hop, sizeof (nh.ip4));
@@ -311,12 +311,12 @@ mpls_table_create (u32 table_id, u8 is_api, const u8 * name)
 static void
 vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
 {
-  u32 tunnel_sw_if_index, tunnel_index, next_hop_via_label;
+  u32 tunnel_sw_if_index = ~0, tunnel_index = ~0, next_hop_via_label;
   vl_api_mpls_tunnel_add_del_reply_t *rmp;
   fib_route_path_t rpath, *rpaths = NULL;
   int ii, rv = 0;
 
-  memset (&rpath, 0, sizeof (rpath));
+  clib_memset (&rpath, 0, sizeof (rpath));
 
   stats_dslock_with_hint (1 /* release hint */ , 5 /* tag */ );
 
@@ -333,7 +333,8 @@ vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
                   mp->mt_next_hop, sizeof (rpath.frp_addr.ip6));
     }
   rpath.frp_sw_if_index = ntohl (mp->mt_next_hop_sw_if_index);
-  rpath.frp_weight = 1;
+  rpath.frp_weight = mp->mt_next_hop_weight;
+  rpath.frp_preference = mp->mt_next_hop_preference;
 
   next_hop_via_label = ntohl (mp->mt_next_hop_via_label);
   if ((MPLS_LABEL_INVALID != next_hop_via_label) && (0 != next_hop_via_label))
@@ -343,6 +344,18 @@ vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
       rpath.frp_eos = MPLS_NON_EOS;
     }
 
+  if (rpath.frp_sw_if_index == ~0)
+    {                          /* recursive path, set fib index */
+      rpath.frp_fib_index =
+       fib_table_find (dpo_proto_to_fib (rpath.frp_proto),
+                       ntohl (mp->mt_next_hop_table_id));
+      if (rpath.frp_fib_index == ~0)
+       {
+         rv = VNET_API_ERROR_NO_SUCH_FIB;
+         goto out;
+       }
+    }
+
   if (mp->mt_is_add)
     {
       for (ii = 0; ii < mp->mt_next_hop_n_out_labels; ii++)
@@ -383,6 +396,7 @@ vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
 
   stats_dsunlock ();
 
+out:
   /* *INDENT-OFF* */
   REPLY_MACRO2(VL_API_MPLS_TUNNEL_ADD_DEL_REPLY,
   ({
@@ -436,7 +450,7 @@ send_mpls_tunnel_entry (u32 mti, void *arg)
   n = fib_path_list_get_n_paths (mt->mt_path_list);
 
   mp = vl_msg_api_alloc (sizeof (*mp) + n * sizeof (vl_api_fib_path_t));
-  memset (mp, 0, sizeof (*mp) + n * sizeof (vl_api_fib_path_t));
+  clib_memset (mp, 0, sizeof (*mp) + n * sizeof (vl_api_fib_path_t));
 
   mp->_vl_msg_id = ntohs (VL_API_MPLS_TUNNEL_DETAILS);
   mp->context = ctx->context;
@@ -445,7 +459,8 @@ send_mpls_tunnel_entry (u32 mti, void *arg)
   mp->mt_sw_if_index = ntohl (mt->mt_sw_if_index);
   mp->mt_count = ntohl (n);
 
-  fib_path_list_walk (mt->mt_path_list, fib_path_encode, &api_rpaths);
+  fib_path_list_walk_w_ext (mt->mt_path_list,
+                           &mt->mt_path_exts, fib_path_encode, &api_rpaths);
 
   fp = mp->mt_paths;
   vec_foreach (api_rpath, api_rpaths)
@@ -490,7 +505,7 @@ send_mpls_fib_details (vpe_api_main_t * am,
   mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp));
   if (!mp)
     return;
-  memset (mp, 0, sizeof (*mp));
+  clib_memset (mp, 0, sizeof (*mp));
   mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS);
   mp->context = context;