MTU: Software interface / Per-protocol MTU support
[vpp.git] / src / vnet / mpls / mpls_tunnel.c
index 2d5521f..a142edf 100644 (file)
@@ -123,23 +123,20 @@ mpls_tunnel_collect_forwarding (fib_node_index_t pl_index,
     path_ext = fib_path_ext_list_find_by_path_index(&ctx->mt->mt_path_exts,
                                                     path_index);
 
-    if (NULL != path_ext)
-    {
-        /*
-         * found a matching extension. stack it to obtain the forwarding
-         * info for this path.
-         */
-        ctx->next_hops = fib_path_ext_stack(path_ext,
-                                            ctx->fct,
-                                            ctx->fct,
-                                            ctx->next_hops);
-    }
-    else
-        ASSERT(0);
     /*
-     * else
-     *   There should be a path-extenios associated with each path
+     * we don't want IP TTL decrements for packets hitting the MPLS labels
+     * we stack on, since the IP TTL decrement is done by the adj
      */
+    path_ext->fpe_mpls_flags |= FIB_PATH_EXT_MPLS_FLAG_NO_IP_TTL_DECR;
+
+    /*
+     * found a matching extension. stack it to obtain the forwarding
+     * info for this path.
+     */
+    ctx->next_hops = fib_path_ext_stack(path_ext,
+                                        ctx->fct,
+                                        ctx->fct,
+                                        ctx->next_hops);
 
     return (FIB_PATH_LIST_WALK_CONTINUE);
 }
@@ -273,9 +270,8 @@ mpls_tunnel_stack (adj_index_t ai)
 
         mpls_tunnel_mk_lb(mt,
                           adj->ia_link,
-                          (VNET_LINK_MPLS == adj_get_link_type(ai) ?
-                           FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
-                           FIB_FORW_CHAIN_TYPE_MPLS_EOS),
+                          fib_forw_chain_type_from_link_type(
+                              adj_get_link_type(ai)),
                           &dpo);
 
         adj_nbr_midchain_stack(ai, &dpo);
@@ -377,7 +373,8 @@ mpls_tunnel_admin_up_down (vnet_main_t * vnm,
 static void
 mpls_tunnel_fixup (vlib_main_t *vm,
                    ip_adjacency_t *adj,
-                   vlib_buffer_t *b0)
+                   vlib_buffer_t *b0,
+                   const void*data)
 {
     /*
      * A no-op w.r.t. the header. but reset the 'have we pushed any
@@ -403,6 +400,7 @@ mpls_tunnel_update_adj (vnet_main_t * vnm,
     case IP_LOOKUP_NEXT_ARP:
     case IP_LOOKUP_NEXT_GLEAN:
         adj_nbr_midchain_update_rewrite(ai, mpls_tunnel_fixup,
+                                        NULL,
                                         ADJ_FLAG_NONE,
                                         mpls_tunnel_build_rewrite_i());
         break;
@@ -412,6 +410,7 @@ mpls_tunnel_update_adj (vnet_main_t * vnm,
          * There's no MAC fixup, so the last 2 parameters are 0
          */
         adj_mcast_midchain_update_rewrite(ai, mpls_tunnel_fixup,
+                                          NULL,
                                           ADJ_FLAG_NONE,
                                           mpls_tunnel_build_rewrite_i(),
                                           0, 0);
@@ -518,6 +517,11 @@ mpls_tunnel_tx (vlib_main_t * vm,
           b0 = vlib_get_buffer(vm, bi0);
 
           vnet_buffer(b0)->ip.adj_index[VLIB_TX] = mt->mt_l2_lb.dpoi_index;
+          /* since we are coming out of the L2 world, where the vlib_buffer
+           * union is used for other things, make sure it is clean for
+           * MPLS from now on.
+           */
+          vnet_buffer(b0)->mpls.first = 0;
 
           if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
             {
@@ -639,6 +643,9 @@ vnet_mpls_tunnel_create (u8 l2_only,
         hi = vnet_get_hw_interface (vnm, mt->mt_hw_if_index);
     }
 
+    /* Standard default MPLS tunnel MTU. */
+    vnet_sw_interface_set_mtu (vnm, hi->sw_if_index, 9000);
+
     /*
      * Add the new tunnel to the tunnel DB - key:SW if index
      */
@@ -778,11 +785,11 @@ vnet_create_mpls_tunnel_command_fn (vlib_main_t * vm,
     vnet_main_t * vnm = vnet_get_main();
     u8 is_del = 0, l2_only = 0, is_multicast =0;
     fib_route_path_t rpath, *rpaths = NULL;
-    mpls_label_t out_label = MPLS_LABEL_INVALID;
-    u32 sw_if_index = ~0;
+    u32 sw_if_index = ~0, payload_proto;
     clib_error_t *error = NULL;
 
     memset(&rpath, 0, sizeof(rpath));
+    payload_proto = DPO_PROTO_MPLS;
 
     /* Get a line of input. */
     if (! unformat_user (input, unformat_line_input, line_input))
@@ -800,56 +807,14 @@ vnet_create_mpls_tunnel_command_fn (vlib_main_t * vm,
             is_del = 0;
         else if (unformat (line_input, "add"))
             is_del = 0;
-        else if (unformat (line_input, "out-labels"))
-       {
-            while (unformat (line_input, "%U",
-                             unformat_mpls_unicast_label,
-                             &out_label))
-            {
-                vec_add1 (rpath.frp_label_stack, out_label);
-            }
-       }
-        else if (unformat (line_input, "via %U %U",
-                           unformat_ip4_address,
-                           &rpath.frp_addr.ip4,
-                           unformat_vnet_sw_interface, vnm,
-                           &rpath.frp_sw_if_index))
-        {
-            rpath.frp_weight = 1;
-            rpath.frp_proto = DPO_PROTO_IP4;
-        }
-
-        else if (unformat (line_input, "via %U %U",
-                           unformat_ip6_address,
-                           &rpath.frp_addr.ip6,
-                           unformat_vnet_sw_interface, vnm,
-                           &rpath.frp_sw_if_index))
-        {
-            rpath.frp_weight = 1;
-            rpath.frp_proto = DPO_PROTO_IP6;
-        }
-        else if (unformat (line_input, "via %U",
-                           unformat_ip6_address,
-                           &rpath.frp_addr.ip6))
-        {
-            rpath.frp_fib_index = 0;
-            rpath.frp_weight = 1;
-            rpath.frp_sw_if_index = ~0;
-            rpath.frp_proto = DPO_PROTO_IP6;
-        }
-        else if (unformat (line_input, "via %U",
-                           unformat_ip4_address,
-                           &rpath.frp_addr.ip4))
-        {
-            rpath.frp_fib_index = 0;
-            rpath.frp_weight = 1;
-            rpath.frp_sw_if_index = ~0;
-            rpath.frp_proto = DPO_PROTO_IP4;
-        }
         else if (unformat (line_input, "l2-only"))
             l2_only = 1;
         else if (unformat (line_input, "multicast"))
             is_multicast = 1;
+        else if (unformat (line_input, "via %U",
+                           unformat_fib_route_path,
+                           &rpath, &payload_proto))
+            vec_add1(rpaths, rpath);
         else
         {
             error = clib_error_return (0, "unknown input '%U'",
@@ -858,8 +823,6 @@ vnet_create_mpls_tunnel_command_fn (vlib_main_t * vm,
         }
     }
 
-    vec_add1(rpaths, rpath);
-
     if (is_del)
     {
         if (!vnet_mpls_tunnel_path_remove(sw_if_index, rpaths))
@@ -901,7 +864,7 @@ done:
 VLIB_CLI_COMMAND (create_mpls_tunnel_command, static) = {
   .path = "mpls tunnel",
   .short_help =
-  "mpls tunnel via [addr] [interface] [out-labels]",
+  "mpls tunnel [multicast] [l2-only] via [next-hop-address] [next-hop-interface] [next-hop-table <value>] [weight <value>] [preference <value>] [udp-encap-id <value>] [ip4-lookup-in-table <value>] [ip6-lookup-in-table <value>] [mpls-lookup-in-table <value>] [resolve-via-host] [resolve-via-connected] [rx-ip4 <interface>] [out-labels <value value value>]",
   .function = vnet_create_mpls_tunnel_command_fn,
 };
 
@@ -1005,9 +968,7 @@ VLIB_CLI_COMMAND (show_mpls_tunnel_command, static) = {
 static mpls_tunnel_t *
 mpls_tunnel_from_fib_node (fib_node_t *node)
 {
-#if (CLIB_DEBUG > 0)
     ASSERT(FIB_NODE_TYPE_MPLS_TUNNEL == node->fn_type);
-#endif
     return ((mpls_tunnel_t*) (((char*)node) -
                              STRUCT_OFFSET_OF(mpls_tunnel_t, mt_node)));
 }