+
+static adj_walk_rc_t
+mgre_mk_complete_walk (adj_index_t ai, void *ctx)
+{
+ nhrp_entry_adj_stack (ctx, 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;
+ nhrp_entry_t *ne;
+ gre_tunnel_t *t;
+ adj_flags_t af;
+ u8 is_ipv6;
+ 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);
+ is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
+ af = ADJ_FLAG_MIDCHAIN_IP_STACK;
+
+ adj_nbr_midchain_update_rewrite
+ (ai, !is_ipv6 ? gre4_fixup : gre6_fixup, NULL, af,
+ gre_build_rewrite (vnm, sw_if_index, adj_get_link_type (ai),
+ &adj->sub_type.nbr.next_hop));
+
+ ne = nhrp_entry_find (sw_if_index, &adj->sub_type.nbr.next_hop);
+
+ if (NULL == ne)
+ // no NHRP entry to provide the next-hop
+ return;
+
+ adj_nbr_walk_nh (sw_if_index, t->tunnel_dst.fp_proto,
+ &adj->sub_type.nbr.next_hop, mgre_mk_complete_walk, ne);
+}