misc: Purge unused pg includes
[vpp.git] / src / vnet / mpls / mpls_tunnel.c
index 27c2a2a..008b590 100644 (file)
@@ -16,7 +16,6 @@
  */
 
 #include <vnet/vnet.h>
-#include <vnet/pg/pg.h>
 #include <vnet/mpls/mpls_tunnel.h>
 #include <vnet/mpls/mpls_types.h>
 #include <vnet/ip/ip.h>
@@ -62,7 +61,7 @@ static u8*
 mpls_tunnel_build_rewrite_i (void)
 {
     /*
-     * passing the adj code a NULL rewirte means 'i don't have one cos
+     * passing the adj code a NULL rewrite means 'i don't have one cos
      * t'other end is unresolved'. That's not the case here. For the mpls
      * tunnel there are just no bytes of encap to apply in the adj. We'll impose
      * the label stack once we choose a path. So return a zero length rewrite.
@@ -242,8 +241,14 @@ mpls_tunnel_stack (adj_index_t ai)
 
     mt = mpls_tunnel_get_from_sw_if_index(sw_if_index);
 
-    if (NULL == mt)
+    if (NULL == mt || FIB_NODE_INDEX_INVALID == mt->mt_path_list)
+        return;
+
+    if (FIB_NODE_INDEX_INVALID == mt->mt_path_list)
+    {
+        adj_nbr_midchain_unstack(ai);
         return;
+    }
 
     /*
      * while we're stacking the adj, remove the tunnel from the child list
@@ -328,7 +333,7 @@ mpls_tunnel_restack (mpls_tunnel_t *mt)
     }
     else
     {
-        FOR_EACH_FIB_PROTOCOL(proto)
+        FOR_EACH_FIB_IP_PROTOCOL(proto)
         {
             adj_nbr_walk(mt->mt_sw_if_index,
                          proto,
@@ -370,7 +375,7 @@ mpls_tunnel_admin_up_down (vnet_main_t * vnm,
  */
 static void
 mpls_tunnel_fixup (vlib_main_t *vm,
-                   ip_adjacency_t *adj,
+                   const ip_adjacency_t *adj,
                    vlib_buffer_t *b0,
                    const void*data)
 {
@@ -600,7 +605,8 @@ vnet_mpls_tunnel_del (u32 sw_if_index)
 
 u32
 vnet_mpls_tunnel_create (u8 l2_only,
-                         u8 is_multicast)
+                         u8 is_multicast,
+                         u8 *tag)
 {
     vnet_hw_interface_t * hi;
     mpls_tunnel_t *mt;
@@ -619,6 +625,10 @@ vnet_mpls_tunnel_create (u8 l2_only,
         mt->mt_flags |= MPLS_TUNNEL_FLAG_MCAST;
     if (l2_only)
         mt->mt_flags |= MPLS_TUNNEL_FLAG_L2;
+    if (tag)
+        memcpy(mt->mt_tag, tag, sizeof(mt->mt_tag));
+    else
+        mt->mt_tag[0] = '\0';
 
     /*
      * Create a new tunnel HW interface
@@ -648,6 +658,7 @@ void
 vnet_mpls_tunnel_path_add (u32 sw_if_index,
                            fib_route_path_t *rpaths)
 {
+    fib_route_path_t *rpath;
     mpls_tunnel_t *mt;
     u32 mti;
 
@@ -689,10 +700,13 @@ vnet_mpls_tunnel_path_add (u32 sw_if_index,
          */
         fib_path_ext_list_resolve(&mt->mt_path_exts, mt->mt_path_list);
     }
-    fib_path_ext_list_insert(&mt->mt_path_exts,
-                             mt->mt_path_list,
-                             FIB_PATH_EXT_MPLS,
-                             rpaths);
+    vec_foreach(rpath, rpaths)
+    {
+        fib_path_ext_list_insert(&mt->mt_path_exts,
+                                 mt->mt_path_list,
+                                 FIB_PATH_EXT_MPLS,
+                                 rpath);
+    }
     mpls_tunnel_restack(mt);
 }
 
@@ -724,6 +738,7 @@ vnet_mpls_tunnel_path_remove (u32 sw_if_index,
 
         old_pl_index = mt->mt_path_list;
 
+        fib_path_list_lock(old_pl_index);
         mt->mt_path_list =
             fib_path_list_copy_and_path_remove(old_pl_index,
                                                FIB_PATH_LIST_FLAG_SHARED,
@@ -735,6 +750,7 @@ vnet_mpls_tunnel_path_remove (u32 sw_if_index,
         if (FIB_NODE_INDEX_INVALID == mt->mt_path_list)
         {
             /* no paths left */
+            fib_path_list_unlock(old_pl_index);
             return (0);
         }
         else
@@ -758,6 +774,7 @@ vnet_mpls_tunnel_path_remove (u32 sw_if_index,
                                   mt->mt_path_list);
 
         mpls_tunnel_restack(mt);
+        fib_path_list_unlock(old_pl_index);
    }
 
     return (fib_path_list_get_n_paths(mt->mt_path_list));
@@ -845,7 +862,7 @@ vnet_create_mpls_tunnel_command_fn (vlib_main_t * vm,
 
         if (~0 == sw_if_index)
         {
-            sw_if_index = vnet_mpls_tunnel_create(l2_only, is_multicast);
+            sw_if_index = vnet_mpls_tunnel_create(l2_only, is_multicast, NULL);
         }
         vnet_mpls_tunnel_path_add(sw_if_index, rpaths);
     }
@@ -878,7 +895,7 @@ format_mpls_tunnel (u8 * s, va_list * args)
     mpls_tunnel_t *mt = va_arg (*args, mpls_tunnel_t *);
     mpls_tunnel_attribute_t attr;
 
-    s = format(s, "mpls_tunnel%d: sw_if_index:%d hw_if_index:%d",
+    s = format(s, "mpls-tunnel%d: sw_if_index:%d hw_if_index:%d",
                mt - mpls_tunnel_pool,
                mt->mt_sw_if_index,
                mt->mt_hw_if_index);