+adj_walk_rc_t
+mgre_mk_complete_walk (adj_index_t ai, void *data)
+{
+ mgre_walk_ctx_t *ctx = data;
+
+ 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,
+ gre_build_rewrite (vnet_get_main (),
+ ctx->t->sw_if_index,
+ adj_get_link_type (ai),
+ &teib_entry_get_nh (ctx->ne)->fp_addr));
+
+ teib_entry_adj_stack (ctx->ne, ai);
+
+ return (ADJ_WALK_RC_CONTINUE);
+}
+
+adj_walk_rc_t
+mgre_mk_incomplete_walk (adj_index_t ai, void *data)
+{
+ gre_tunnel_t *t = data;
+
+ adj_nbr_midchain_update_rewrite (ai, gre_get_fixup (t->tunnel_dst.fp_proto,
+ adj_get_link_type (ai)),
+ NULL, ADJ_FLAG_NONE, NULL);
+
+ adj_midchain_delegate_unstack (ai);
+
+ return (ADJ_WALK_RC_CONTINUE);
+}
+
+void
+mgre_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
+{
+ gre_main_t *gm = &gre_main;
+ ip_adjacency_t *adj;
+ teib_entry_t *ne;
+ gre_tunnel_t *t;
+ u32 ti;
+
+ adj = adj_get (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);
+
+ if (NULL == ne)
+ // no NHRP entry to provide the next-hop
+ return;
+
+ mgre_walk_ctx_t ctx = {
+ .t = t,
+ .ne = ne
+ };
+ adj_nbr_walk_nh (sw_if_index,
+ adj->ia_nh_proto,
+ &adj->sub_type.nbr.next_hop, mgre_mk_complete_walk, &ctx);
+}
+#endif /* CLIB_MARCH_VARIANT */
+
+typedef enum
+{
+ GRE_ENCAP_NEXT_L2_MIDCHAIN,
+ GRE_ENCAP_N_NEXT,
+} gre_encap_next_t;
+