+typedef struct mipip_walk_ctx_t_
+{
+ const ipip_tunnel_t *t;
+ const teib_entry_t *ne;
+} mipip_walk_ctx_t;
+
+static adj_walk_rc_t
+mipip_mk_complete_walk (adj_index_t ai, void *data)
+{
+ adj_midchain_fixup_t fixup;
+ mipip_walk_ctx_t *ctx = data;
+ adj_flags_t af;
+
+ af = ADJ_FLAG_NONE;
+ fixup = ipip_get_fixup (ctx->t, adj_get_link_type (ai), &af);
+
+ if (ctx->t->flags & TUNNEL_ENCAP_DECAP_FLAG_ENCAP_INNER_HASH)
+ af = ADJ_FLAG_MIDCHAIN_FIXUP_FLOW_HASH;
+ else
+ af = ADJ_FLAG_MIDCHAIN_IP_STACK;
+
+ adj_nbr_midchain_update_rewrite
+ (ai, fixup,
+ uword_to_pointer (ctx->t->flags, void *),
+ af, ipip_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);
+}
+
+static adj_walk_rc_t
+mipip_mk_incomplete_walk (adj_index_t ai, void *data)
+{
+ adj_midchain_fixup_t fixup;
+ ipip_tunnel_t *t = data;
+ adj_flags_t af;
+
+ af = ADJ_FLAG_NONE;
+ fixup = ipip_get_fixup (t, adj_get_link_type (ai), &af);
+
+ adj_nbr_midchain_update_rewrite (ai, fixup, NULL, ADJ_FLAG_NONE, NULL);
+
+ adj_midchain_delegate_unstack (ai);
+
+ return (ADJ_WALK_RC_CONTINUE);
+}
+
+void
+mipip_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
+{
+ ipip_main_t *gm = &ipip_main;
+ adj_midchain_fixup_t fixup;
+ ip_adjacency_t *adj;
+ teib_entry_t *ne;
+ ipip_tunnel_t *t;
+ adj_flags_t af;
+ u32 ti;
+
+ af = ADJ_FLAG_NONE;
+ 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_46 (sw_if_index,
+ adj->ia_nh_proto, &adj->sub_type.nbr.next_hop);
+
+ if (NULL == ne)
+ {
+ // no TEIB entry to provide the next-hop
+ fixup = ipip_get_fixup (t, adj_get_link_type (ai), &af);
+ adj_nbr_midchain_update_rewrite
+ (ai, fixup, uword_to_pointer (t->flags, void *), ADJ_FLAG_NONE, NULL);
+ return;
+ }
+
+ mipip_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, mipip_mk_complete_walk, &ctx);
+}
+