fib: Adjacency flag for midchain to perfom flow hash (on inner packet)
[vpp.git] / src / vnet / adj / adj_midchain.c
index 4741ec9..93cfb55 100644 (file)
@@ -23,6 +23,8 @@
 #include <vnet/dpo/load_balance.h>
 #include <vnet/fib/fib_walk.h>
 #include <vnet/fib/fib_entry.h>
+#include <vnet/ip/ip4_inlines.h>
+#include <vnet/ip/ip6_inlines.h>
 
 /**
  * @brief Trace data for packets traversing the midchain tx node
@@ -327,7 +329,7 @@ adj_midchain_get_feature_arc_index_for_link_type (const ip_adjacency_t *adj)
        }
     case VNET_LINK_NSH:
         {
-          arc = nsh_main_dummy.output_feature_arc_index;
+          arc = nsh_main_placeholder.output_feature_arc_index;
           break;
         }
     case VNET_LINK_ARP:
@@ -361,7 +363,7 @@ adj_midchain_teardown (ip_adjacency_t *adj)
     dpo_reset(&adj->sub_type.midchain.next_dpo);
 
     vlib_worker_thread_barrier_sync(vm);
-    vnet_feature_modify_end_node(
+    adj->ia_cfg_index = vnet_feature_modify_end_node(
         adj_midchain_get_feature_arc_index_for_link_type (adj),
         adj->rewrite_header.sw_if_index,
         vlib_get_node_by_name (vlib_get_main(),
@@ -401,11 +403,15 @@ adj_midchain_setup (adj_index_t adj_index,
     {
         adj->rewrite_header.flags &= ~VNET_REWRITE_FIXUP_IP4_O_4;
     }
+    if (!(flags & ADJ_FLAG_MIDCHAIN_FIXUP_FLOW_HASH))
+    {
+        adj->rewrite_header.flags &= ~VNET_REWRITE_FIXUP_FLOW_HASH;
+    }
 
     tx_node = adj_nbr_midchain_get_tx_node(adj);
 
     vlib_worker_thread_barrier_sync(vm);
-    vnet_feature_modify_end_node(
+    adj->ia_cfg_index = vnet_feature_modify_end_node(
         adj_midchain_get_feature_arc_index_for_link_type (adj),
         adj->rewrite_header.sw_if_index,
         tx_node);
@@ -481,7 +487,7 @@ adj_nbr_midchain_update_next_node (adj_index_t adj_index,
                                                         adj->ia_node_index,
                                                         next_node);
 
-    vnet_feature_modify_end_node(
+    adj->ia_cfg_index = vnet_feature_modify_end_node(
         adj_midchain_get_feature_arc_index_for_link_type (adj),
         adj->rewrite_header.sw_if_index,
         next_node);
@@ -490,7 +496,7 @@ adj_nbr_midchain_update_next_node (adj_index_t adj_index,
 }
 
 void
-adj_nbr_midchain_reset_next_node(adj_index_t adj_index)
+adj_nbr_midchain_reset_next_node (adj_index_t adj_index)
 {
     ip_adjacency_t *adj;
     vlib_main_t * vm;
@@ -507,7 +513,7 @@ adj_nbr_midchain_reset_next_node(adj_index_t adj_index)
                            adj->ia_node_index,
                            adj_nbr_midchain_get_tx_node(adj));
 
-    vnet_feature_modify_end_node(
+    adj->ia_cfg_index = vnet_feature_modify_end_node(
         adj_midchain_get_feature_arc_index_for_link_type (adj),
         adj->rewrite_header.sw_if_index,
         adj_nbr_midchain_get_tx_node(adj));
@@ -580,39 +586,47 @@ adj_nbr_midchain_stack_on_fib_entry (adj_index_t ai,
     {
         fib_entry_contribute_forwarding (fei, fct, &tmp);
 
-        if ((adj->ia_flags & ADJ_FLAG_MIDCHAIN_IP_STACK) &&
-            (DPO_LOAD_BALANCE == tmp.dpoi_type))
+        if (DPO_LOAD_BALANCE == tmp.dpoi_type)
         {
-            /*
-             * do that hash now and stack on the choice.
-             * If the choice is an incomplete adj then we will need a poke when
-             * it becomes complete. This happens since the adj update walk propagates
-             * as far a recursive paths.
-             */
-            const dpo_id_t *choice;
             load_balance_t *lb;
-            int hash;
 
             lb = load_balance_get (tmp.dpoi_index);
 
-            if (FIB_FORW_CHAIN_TYPE_UNICAST_IP4 == fct)
+            if ((adj->ia_flags & ADJ_FLAG_MIDCHAIN_IP_STACK) ||
+                lb->lb_n_buckets == 1)
             {
-                hash = ip4_compute_flow_hash ((ip4_header_t *) adj_get_rewrite (ai),
-                                              lb->lb_hash_config);
+                /*
+                 * do that hash now and stack on the choice.
+                 * If the choice is an incomplete adj then we will need a poke when
+                 * it becomes complete. This happens since the adj update walk propagates
+                 * as far a recursive paths.
+                 */
+                const dpo_id_t *choice;
+                int hash;
+
+                if (FIB_FORW_CHAIN_TYPE_UNICAST_IP4 == fct)
+                {
+                    hash = ip4_compute_flow_hash ((ip4_header_t *) adj_get_rewrite (ai),
+                                                  lb->lb_hash_config);
+                }
+                else if (FIB_FORW_CHAIN_TYPE_UNICAST_IP6 == fct)
+                {
+                    hash = ip6_compute_flow_hash ((ip6_header_t *) adj_get_rewrite (ai),
+                                                  lb->lb_hash_config);
+                }
+                else
+                {
+                    hash = 0;
+                    ASSERT(0);
+                }
+
+                choice = load_balance_get_bucket_i (lb, hash & lb->lb_n_buckets_minus_1);
+                dpo_copy (&tmp, choice);
             }
-            else if (FIB_FORW_CHAIN_TYPE_UNICAST_IP6 == fct)
+            else if (adj->ia_flags & ADJ_FLAG_MIDCHAIN_FIXUP_FLOW_HASH)
             {
-                hash = ip6_compute_flow_hash ((ip6_header_t *) adj_get_rewrite (ai),
-                                              lb->lb_hash_config);
+                adj->rewrite_header.flags |= VNET_REWRITE_FIXUP_FLOW_HASH;
             }
-            else
-            {
-                hash = 0;
-                ASSERT(0);
-            }
-
-            choice = load_balance_get_bucket_i (lb, hash & lb->lb_n_buckets_minus_1);
-            dpo_copy (&tmp, choice);
         }
     }
     adj_nbr_midchain_stack (ai, &tmp);