fib: fix crash when create vxlan/vxlan-gpe/geneve/gtpu tunnel.
[vpp.git] / src / vnet / fib / fib_path.c
index 2cee846..8d160d9 100644 (file)
@@ -140,10 +140,6 @@ typedef enum fib_path_oper_attribute_t_ {
      * The path is resolved
      */
     FIB_PATH_OPER_ATTRIBUTE_RESOLVED,
-    /**
-     * The path is attached, despite what the next-hop may say.
-     */
-    FIB_PATH_OPER_ATTRIBUTE_ATTACHED,
     /**
      * The path has become a permanent drop.
      */
@@ -178,7 +174,6 @@ typedef enum fib_path_oper_flags_t_ {
     FIB_PATH_OPER_FLAG_RECURSIVE_LOOP = (1 << FIB_PATH_OPER_ATTRIBUTE_RECURSIVE_LOOP),
     FIB_PATH_OPER_FLAG_DROP = (1 << FIB_PATH_OPER_ATTRIBUTE_DROP),
     FIB_PATH_OPER_FLAG_RESOLVED = (1 << FIB_PATH_OPER_ATTRIBUTE_RESOLVED),
-    FIB_PATH_OPER_FLAG_ATTACHED = (1 << FIB_PATH_OPER_ATTRIBUTE_ATTACHED),
 } __attribute__ ((packed)) fib_path_oper_flags_t;
 
 /**
@@ -245,6 +240,10 @@ typedef struct fib_path_t_ {
            u32 fp_interface;
        } attached_next_hop;
        struct {
+           /**
+            * The Connected local address
+            */
+           fib_prefix_t fp_connected;
            /**
             * The interface
             */
@@ -268,16 +267,10 @@ typedef struct fib_path_t_ {
                     mpls_eos_bit_t fp_eos;
                 };
            } fp_nh;
-            union {
-                /**
-                 * The FIB table index in which to find the next-hop.
-                 */
-                fib_node_index_t fp_tbl_id;
-                /**
-                 * The BIER FIB the fmask is in
-                 */
-                index_t fp_bier_fib;
-            };
+            /**
+             * The FIB table index in which to find the next-hop.
+             */
+            fib_node_index_t fp_tbl_id;
        } recursive;
        struct {
             /**
@@ -355,7 +348,7 @@ typedef struct fib_path_t_ {
     STRUCT_MARK(path_hash_end);
 
     /**
-     * Memebers in this last section represent information that is
+     * Members in this last section represent information that is
      * dervied during resolution. It should not be copied to new paths
      * nor compared.
      */
@@ -671,14 +664,18 @@ fib_path_attached_next_hop_get_adj (fib_path_t *path,
 static void
 fib_path_attached_next_hop_set (fib_path_t *path)
 {
+    dpo_id_t tmp = DPO_INVALID;
+
     /*
      * resolve directly via the adjacency discribed by the
      * interface and next-hop
      */
+    dpo_copy (&tmp, &path->fp_dpo);
     path = fib_path_attached_next_hop_get_adj(path,
                                               dpo_proto_to_link(path->fp_nh_proto),
-                                              &path->fp_dpo);
-
+                                              &tmp);
+    dpo_copy(&path->fp_dpo, &tmp);
+    dpo_reset(&tmp);
     ASSERT(dpo_is_adj(&path->fp_dpo));
 
     /*
@@ -732,7 +729,7 @@ fib_path_attached_get_adj (fib_path_t *path,
 
         ai = adj_glean_add_or_lock(nh_proto, link,
                                    path->attached.fp_interface,
-                                   NULL);
+                                   &path->attached.fp_connected);
         dpo_set(dpo, DPO_ADJACENCY_GLEAN, vnet_link_to_dpo_proto(link), ai);
         adj_unlock(ai);
     }
@@ -1006,6 +1003,7 @@ fib_path_back_walk_notify (fib_node_t *node,
                &path->fp_dpo);
        }
        if ((FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason) ||
+            (FIB_NODE_BW_REASON_FLAG_ADJ_MTU    & ctx->fnbw_reason) ||
             (FIB_NODE_BW_REASON_FLAG_ADJ_DOWN   & ctx->fnbw_reason))
        {
            /*
@@ -1095,16 +1093,20 @@ FIXME comment
             /*
              * restack the DPO to pick up the correct DPO sub-type
              */
+            dpo_id_t tmp = DPO_INVALID;
             uword if_is_up;
 
             if_is_up = vnet_sw_interface_is_up(
                            vnet_get_main(),
                            path->attached_next_hop.fp_interface);
 
+            dpo_copy (&tmp, &path->fp_dpo);
             path = fib_path_attached_next_hop_get_adj(
                 path,
                 dpo_proto_to_link(path->fp_nh_proto),
-                &path->fp_dpo);
+                &tmp);
+            dpo_copy(&path->fp_dpo, &tmp);
+            dpo_reset(&tmp);
 
             path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
             if (if_is_up && adj_is_up(path->fp_dpo.dpoi_index))
@@ -1159,6 +1161,11 @@ FIXME comment
            fib_path_unresolve(path);
            path->fp_oper_flags |= FIB_PATH_OPER_FLAG_DROP;
        }
+       if (FIB_NODE_BW_REASON_FLAG_INTERFACE_BIND & ctx->fnbw_reason)
+       {
+            /* bind walks should appear here and pass silently up to
+             * to the fib_entry */
+       }
        break;
     case FIB_PATH_TYPE_UDP_ENCAP:
     {
@@ -1262,6 +1269,8 @@ fib_path_route_flags_to_cfg_flags (const fib_route_path_t *rpath)
        cfg_flags |= FIB_PATH_CFG_FLAG_ICMP_UNREACH;
     if (rpath->frp_flags & FIB_ROUTE_PATH_ICMP_PROHIBIT)
        cfg_flags |= FIB_PATH_CFG_FLAG_ICMP_PROHIBIT;
+    if (rpath->frp_flags & FIB_ROUTE_PATH_GLEAN)
+       cfg_flags |= FIB_PATH_CFG_FLAG_GLEAN;
 
     return (cfg_flags);
 }
@@ -1365,6 +1374,12 @@ fib_path_create (fib_node_index_t pl_index,
         path->fp_type = FIB_PATH_TYPE_SPECIAL;
         path->classify.fp_classify_table_id = rpath->frp_classify_table_id;
     }
+    else if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_GLEAN)
+    {
+        path->fp_type = FIB_PATH_TYPE_ATTACHED;
+        path->attached.fp_interface = rpath->frp_sw_if_index;
+        path->attached.fp_connected = rpath->frp_connected;
+    }
     else if (~0 != rpath->frp_sw_if_index)
     {
         if (ip46_address_is_zero(&rpath->frp_addr))
@@ -1492,6 +1507,12 @@ fib_path_copy (fib_node_index_t path_index,
     clib_memset(&path->fp_dpo, 0, sizeof(path->fp_dpo));
     dpo_reset(&path->fp_dpo);
 
+    if (path->fp_type == FIB_PATH_TYPE_EXCLUSIVE)
+    {
+       clib_memset(&path->exclusive.fp_ex_dpo, 0, sizeof(dpo_id_t));
+       dpo_copy(&path->exclusive.fp_ex_dpo, &orig_path->exclusive.fp_ex_dpo);
+    }
+
     return (fib_path_get_index(path));
 }
 
@@ -1977,7 +1998,11 @@ fib_path_resolve (fib_node_index_t path_index)
        }
        else
        {
-           fib_prefix_from_ip46_addr(&path->recursive.fp_nh.fp_ip, &pfx);
+           ASSERT(!ip46_address_is_zero(&path->recursive.fp_nh.fp_ip));
+
+           fib_protocol_t fp = (ip46_address_is_ip4(&path->recursive.fp_nh.fp_ip) ?
+                                        FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
+           fib_prefix_from_ip46_addr(fp, &path->recursive.fp_nh.fp_ip, &pfx);
        }
 
         fib_table_lock(path->recursive.fp_tbl_id,
@@ -2105,7 +2130,7 @@ fib_path_resolve (fib_node_index_t path_index)
         break;
     }
     case FIB_PATH_TYPE_DVR:
-        dvr_dpo_add_or_lock(path->attached.fp_interface,
+        dvr_dpo_add_or_lock(path->dvr.fp_interface,
                             path->fp_nh_proto,
                             &path->fp_dpo);
         break;
@@ -2326,10 +2351,12 @@ fib_path_contribute_urpf (fib_node_index_t path_index,
     case FIB_PATH_TYPE_DVR:
        fib_urpf_list_append(urpf, path->dvr.fp_interface);
        break;
+    case FIB_PATH_TYPE_UDP_ENCAP:
+        fib_urpf_list_append(urpf, path->udp_encap.fp_udp_encap_id);
+       break;
     case FIB_PATH_TYPE_DEAG:
     case FIB_PATH_TYPE_RECEIVE:
     case FIB_PATH_TYPE_INTF_RX:
-    case FIB_PATH_TYPE_UDP_ENCAP:
     case FIB_PATH_TYPE_BIER_FMASK:
     case FIB_PATH_TYPE_BIER_TABLE:
     case FIB_PATH_TYPE_BIER_IMP:
@@ -2404,6 +2431,7 @@ fib_path_stack_mpls_disp (fib_node_index_t path_index,
 void
 fib_path_contribute_forwarding (fib_node_index_t path_index,
                                fib_forward_chain_type_t fct,
+                                dpo_proto_t payload_proto,
                                dpo_id_t *dpo)
 {
     fib_path_t *path;
@@ -2411,7 +2439,6 @@ fib_path_contribute_forwarding (fib_node_index_t path_index,
     path = fib_path_get(path_index);
 
     ASSERT(path);
-    ASSERT(FIB_FORW_CHAIN_TYPE_MPLS_EOS != fct);
 
     /*
      * The DPO stored in the path was created when the path was resolved.
@@ -2429,19 +2456,35 @@ fib_path_contribute_forwarding (fib_node_index_t path_index,
        case FIB_PATH_TYPE_ATTACHED_NEXT_HOP:
            switch (fct)
            {
+           case FIB_FORW_CHAIN_TYPE_MPLS_EOS: {
+                    dpo_id_t tmp = DPO_INVALID;
+                    dpo_copy (&tmp, dpo);
+                    path = fib_path_attached_next_hop_get_adj(
+                           path,
+                           dpo_proto_to_link(payload_proto),
+                           &tmp);
+                    dpo_copy (dpo, &tmp);
+                    dpo_reset(&tmp);
+                    break;
+            }
            case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
            case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
-           case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
            case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
            case FIB_FORW_CHAIN_TYPE_ETHERNET:
            case FIB_FORW_CHAIN_TYPE_NSH:
            case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
            case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
-               path = fib_path_attached_next_hop_get_adj(
-                    path,
-                    fib_forw_chain_type_to_link_type(fct),
-                    dpo);
-               break;
+                {
+                    dpo_id_t tmp = DPO_INVALID;
+                    dpo_copy (&tmp, dpo);
+                    path = fib_path_attached_next_hop_get_adj(
+                           path,
+                           fib_forw_chain_type_to_link_type(fct),
+                           &tmp);
+                    dpo_copy (dpo, &tmp);
+                    dpo_reset(&tmp);
+                    break;
+                }
            case FIB_FORW_CHAIN_TYPE_BIER:
                break;
            }
@@ -2537,10 +2580,25 @@ fib_path_contribute_forwarding (fib_node_index_t path_index,
         case FIB_PATH_TYPE_ATTACHED:
            switch (fct)
            {
+           case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
+                /*
+                 * End of stack traffic via an attacehd path (a glean)
+                 * must forace an IP lookup so that the IP packet can
+                 * match against any installed adj-fibs
+                 */
+                lookup_dpo_add_or_lock_w_fib_index(
+                    fib_table_get_index_for_sw_if_index(
+                        dpo_proto_to_fib(payload_proto),
+                        path->attached.fp_interface),
+                    payload_proto,
+                    LOOKUP_UNICAST,
+                    LOOKUP_INPUT_DST_ADDR,
+                    LOOKUP_TABLE_FROM_CONFIG,
+                    dpo);
+                break;
            case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
            case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
            case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
-           case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
            case FIB_FORW_CHAIN_TYPE_ETHERNET:
            case FIB_FORW_CHAIN_TYPE_NSH:
             case FIB_FORW_CHAIN_TYPE_BIER:
@@ -2586,8 +2644,8 @@ fib_path_contribute_forwarding (fib_node_index_t path_index,
             /*
              * Create the adj needed for sending IP multicast traffic
              */
-            interface_rx_dpo_add_or_lock(fib_forw_chain_type_to_dpo_proto(fct),
-                                         path->attached.fp_interface,
+            interface_rx_dpo_add_or_lock(payload_proto,
+                                         path->intf_rx.fp_interface,
                                          dpo);
             break;
         case FIB_PATH_TYPE_UDP_ENCAP:
@@ -2607,6 +2665,7 @@ fib_path_contribute_forwarding (fib_node_index_t path_index,
 load_balance_path_t *
 fib_path_append_nh_for_multipath_hash (fib_node_index_t path_index,
                                       fib_forward_chain_type_t fct,
+                                       dpo_proto_t payload_proto,
                                       load_balance_path_t *hash_key)
 {
     load_balance_path_t *mnh;
@@ -2623,7 +2682,7 @@ fib_path_append_nh_for_multipath_hash (fib_node_index_t path_index,
 
     if (fib_path_is_resolved(path_index))
     {
-        fib_path_contribute_forwarding(path_index, fct, &mnh->path_dpo);
+        fib_path_contribute_forwarding(path_index, fct, payload_proto, &mnh->path_dpo);
     }
     else
     {
@@ -2820,11 +2879,11 @@ show_fib_path_command (vlib_main_t * vm,
     else
     {
        vlib_cli_output (vm, "FIB Paths");
-       pool_foreach_index (pi, fib_path_pool,
-       ({
+       pool_foreach_index (pi, fib_path_pool)
+        {
            vlib_cli_output (vm, "%U", format_fib_path, pi, 0,
                              FIB_PATH_FORMAT_FLAGS_NONE);
-       }));
+       }
     }
 
     return (NULL);