wireguard: add async mode for encryption packets
[vpp.git] / src / vnet / gre / gre.c
index 83f1283..dc735e6 100644 (file)
@@ -340,7 +340,7 @@ gre46_fixup (vlib_main_t * vm,
   ip0->ip6.payload_length =
     clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) -
                          sizeof (ip0->ip6));
-  tunnel_encap_fixup_4o6 (flags, (ip4_header_t *) (ip0 + 1), &ip0->ip6);
+  tunnel_encap_fixup_4o6 (flags, b0, (ip4_header_t *) (ip0 + 1), &ip0->ip6);
 }
 
 static void
@@ -391,9 +391,9 @@ gre_get_fixup (fib_protocol_t fproto, vnet_link_t lt)
     return (gre64_fixup);
   if (fproto == FIB_PROTOCOL_IP4 && lt == VNET_LINK_IP4)
     return (gre44_fixup);
-  if (fproto == FIB_PROTOCOL_IP6 && lt == VNET_LINK_ETHERNET)
+  if (fproto == FIB_PROTOCOL_IP6)
     return (grex6_fixup);
-  if (fproto == FIB_PROTOCOL_IP4 && lt == VNET_LINK_ETHERNET)
+  if (fproto == FIB_PROTOCOL_IP4)
     return (grex4_fixup);
 
   ASSERT (0);
@@ -410,10 +410,15 @@ gre_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
 
   ti = gm->tunnel_index_by_sw_if_index[sw_if_index];
   t = pool_elt_at_index (gm->tunnels, ti);
-  af = ADJ_FLAG_MIDCHAIN_IP_STACK;
+  af = ADJ_FLAG_NONE;
 
-  if (VNET_LINK_ETHERNET == adj_get_link_type (ai))
-    af |= ADJ_FLAG_MIDCHAIN_NO_COUNT;
+  /*
+   * the user has not requested that the load-balancing be based on
+   * a flow hash of the inner packet. so use the stacking to choose
+   * a path.
+   */
+  if (!(t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_INNER_HASH))
+    af |= ADJ_FLAG_MIDCHAIN_IP_STACK;
 
   adj_nbr_midchain_update_rewrite
     (ai, gre_get_fixup (t->tunnel_dst.fp_proto,
@@ -429,12 +434,23 @@ adj_walk_rc_t
 mgre_mk_complete_walk (adj_index_t ai, void *data)
 {
   mgre_walk_ctx_t *ctx = data;
+  adj_flags_t af;
+
+  af = ADJ_FLAG_NONE;
+
+  /*
+   * the user has not requested that the load-balancing be based on
+   * a flow hash of the inner packet. so use the stacking to choose
+   * a path.
+   */
+  if (!(ctx->t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_INNER_HASH))
+    af |= ADJ_FLAG_MIDCHAIN_IP_STACK;
 
   adj_nbr_midchain_update_rewrite
     (ai, gre_get_fixup (ctx->t->tunnel_dst.fp_proto,
                        adj_get_link_type (ai)),
      uword_to_pointer (ctx->t->flags, void *),
-     ADJ_FLAG_MIDCHAIN_IP_STACK,
+     af,
      gre_build_rewrite (vnet_get_main (),
                        ctx->t->sw_if_index,
                        adj_get_link_type (ai),
@@ -472,11 +488,17 @@ mgre_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
   ti = gm->tunnel_index_by_sw_if_index[sw_if_index];
   t = pool_elt_at_index (gm->tunnels, ti);
 
-  ne = teib_entry_find (sw_if_index, &adj->sub_type.nbr.next_hop);
+  ne = teib_entry_find_46 (sw_if_index,
+                          adj->ia_nh_proto, &adj->sub_type.nbr.next_hop);
 
   if (NULL == ne)
-    // no NHRP entry to provide the next-hop
-    return;
+    {
+      // no TEIB entry to provide the next-hop
+      adj_nbr_midchain_update_rewrite (
+       ai, gre_get_fixup (t->tunnel_dst.fp_proto, adj_get_link_type (ai)),
+       uword_to_pointer (t->flags, void *), ADJ_FLAG_NONE, NULL);
+      return;
+    }
 
   mgre_walk_ctx_t ctx = {
     .t = t,