ADJ: midchain delegate to performing stacking

this can be used by e.g. tunnels so it doesn't need to be
implemented for each tunnel type.

Change-Id: I0790f89aa49f83421612b35108cce67693285999
Signed-off-by: Neale Ranns <nranns@cisco.com>
diff --git a/src/vnet/gre/interface.c b/src/vnet/gre/interface.c
index b9bfb79..4f5f528 100644
--- a/src/vnet/gre/interface.c
+++ b/src/vnet/gre/interface.c
@@ -112,14 +112,6 @@
   t->key = NULL;
 }
 
-static gre_tunnel_t *
-gre_tunnel_from_fib_node (fib_node_t * node)
-{
-  ASSERT (FIB_NODE_TYPE_GRE_TUNNEL == node->fn_type);
-  return ((gre_tunnel_t *) (((char *) node) -
-			    STRUCT_OFFSET_OF (gre_tunnel_t, node)));
-}
-
 /**
  * gre_tunnel_stack
  *
@@ -146,14 +138,11 @@
   if ((vnet_hw_interface_get_flags (vnet_get_main (), gt->hw_if_index) &
        VNET_HW_INTERFACE_FLAG_LINK_UP) == 0)
     {
-      adj_nbr_midchain_unstack (ai);
+      adj_midchain_delegate_unstack (ai);
     }
   else
     {
-      adj_nbr_midchain_stack_on_fib_entry (ai,
-					   gt->fib_entry_index,
-					   fib_forw_chain_type_from_fib_proto
-					   (gt->tunnel_dst.fp_proto));
+      adj_midchain_delegate_stack (ai, gt->outer_fib_index, &gt->tunnel_dst);
     }
 }
 
@@ -182,55 +171,6 @@
   }
 }
 
-/**
- * Function definition to backwalk a FIB node
- */
-static fib_node_back_walk_rc_t
-gre_tunnel_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
-{
-  gre_tunnel_restack (gre_tunnel_from_fib_node (node));
-
-  return (FIB_NODE_BACK_WALK_CONTINUE);
-}
-
-/**
- * Function definition to get a FIB node from its index
- */
-static fib_node_t *
-gre_tunnel_fib_node_get (fib_node_index_t index)
-{
-  gre_tunnel_t *gt;
-  gre_main_t *gm;
-
-  gm = &gre_main;
-  gt = pool_elt_at_index (gm->tunnels, index);
-
-  return (&gt->node);
-}
-
-/**
- * Function definition to inform the FIB node that its last lock has gone.
- */
-static void
-gre_tunnel_last_lock_gone (fib_node_t * node)
-{
-  /*
-   * The MPLS GRE tunnel is a root of the graph. As such
-   * it never has children and thus is never locked.
-   */
-  ASSERT (0);
-}
-
-/*
- * Virtual function table registered by MPLS GRE tunnels
- * for participation in the FIB object graph.
- */
-const static fib_node_vft_t gre_vft = {
-  .fnv_get = gre_tunnel_fib_node_get,
-  .fnv_last_lock = gre_tunnel_last_lock_gone,
-  .fnv_back_walk = gre_tunnel_back_walk,
-};
-
 static int
 vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t * a,
 		     u32 outer_fib_index, u32 * sw_if_indexp)
@@ -267,7 +207,6 @@
 
   t->dev_instance = t_idx;	/* actual */
   t->user_instance = u_idx;	/* name */
-  fib_node_init (&t->node, FIB_NODE_TYPE_GRE_TUNNEL);
 
   t->type = a->tunnel_type;
   if (t->type == GRE_TUNNEL_TYPE_ERSPAN)
@@ -357,11 +296,6 @@
 	}
     }
 
-  t->fib_entry_index = fib_table_entry_special_add
-    (outer_fib_index, &t->tunnel_dst, FIB_SOURCE_RR, FIB_ENTRY_FLAG_NONE);
-  t->sibling_index = fib_entry_child_add
-    (t->fib_entry_index, FIB_NODE_TYPE_GRE_TUNNEL, t_idx);
-
   if (t->type != GRE_TUNNEL_TYPE_L3)
     {
       t->l2_adj_index = adj_nbr_add_or_lock
@@ -403,10 +337,10 @@
     ethernet_delete_interface (vnm, t->hw_if_index);
 
   if (t->l2_adj_index != ADJ_INDEX_INVALID)
-    adj_unlock (t->l2_adj_index);
-
-  fib_entry_child_remove (t->fib_entry_index, t->sibling_index);
-  fib_table_entry_delete_index (t->fib_entry_index, FIB_SOURCE_RR);
+    {
+      adj_midchain_delegate_unstack (t->l2_adj_index);
+      adj_unlock (t->l2_adj_index);
+    }
 
   ASSERT ((t->type != GRE_TUNNEL_TYPE_ERSPAN) || (t->gre_sn != NULL));
   if ((t->type == GRE_TUNNEL_TYPE_ERSPAN) && (t->gre_sn->ref_count-- == 1))
@@ -419,7 +353,6 @@
 
   hash_unset (gm->instance_used, t->user_instance);
   gre_tunnel_db_remove (t);
-  fib_node_deinit (&t->node);
   pool_put (gm->tunnels, t);
 
   if (sw_if_indexp)
@@ -690,9 +623,7 @@
 clib_error_t *
 gre_interface_init (vlib_main_t * vm)
 {
-  fib_node_register_type (FIB_NODE_TYPE_GRE_TUNNEL, &gre_vft);
-
-  return 0;
+  return (NULL);
 }
 
 VLIB_INIT_FUNCTION (gre_interface_init);