tls: init session for accepted ctx
[vpp.git] / src / vnet / fib / fib_entry_src_interface.c
index ca04716..c5028dc 100644 (file)
 static void
 fib_entry_src_interface_init (fib_entry_src_t *src)
 {
-    src->interface.fesi_cover = FIB_NODE_INDEX_INVALID;
-    src->interface.fesi_sibling = FIB_NODE_INDEX_INVALID;
+    src->u.interface.fesi_cover = FIB_NODE_INDEX_INVALID;
+    src->u.interface.fesi_sibling = FIB_NODE_INDEX_INVALID;
 }
 
 static void
-fib_entry_src_interface_path_swap (fib_entry_src_t *src,
-                                  const fib_entry_t *entry,
-                                  fib_path_list_flags_t pl_flags,
-                                  const fib_route_path_t *paths)
+fib_entry_src_interface_add (fib_entry_src_t *src,
+                             const fib_entry_t *entry,
+                             fib_entry_flag_t flags,
+                             dpo_proto_t proto,
+                             const dpo_id_t *dpo)
 {
-    ip_adjacency_t *adj;
+    src->fes_pl = fib_path_list_create_special(
+                      proto,
+                      fib_entry_src_flags_2_path_list_flags(flags),
+                      dpo);
+}
 
-    src->fes_pl = fib_path_list_create(pl_flags, paths);
+static void
+fib_entry_src_interface_remove (fib_entry_src_t *src)
+{
+    src->fes_pl = FIB_NODE_INDEX_INVALID;
+    ASSERT(src->u.interface.fesi_sibling == ~0);
+}
 
-    /*
-     * this is a hack to get the entry's prefix into the glean adjacnecy
-     * so that it is available for fast retreival in the switch path.
-     */
-    if (!(FIB_ENTRY_FLAG_LOCAL & src->fes_entry_flags))
+static int
+fib_entry_src_interface_update_glean (fib_entry_t *cover,
+                                      const fib_entry_t *local)
+{
+    fib_entry_src_t *src;
+    adj_index_t ai;
+
+    src = fib_entry_src_find (cover, FIB_SOURCE_INTERFACE);
+
+    if (NULL == src)
     {
-        adj = adj_get(fib_path_list_get_adj(
-                         src->fes_pl,
-                         fib_entry_get_default_chain_type(entry)));
+        /*
+         * The cover is not an interface source, no work
+         */
+        return 0;
+    }
 
-       if (IP_LOOKUP_NEXT_GLEAN == adj->lookup_next_index)
+    ai = fib_path_list_get_adj(src->fes_pl,
+                               fib_entry_get_default_chain_type(cover));
+
+    if (INDEX_INVALID != ai)
+    {
+        ip_adjacency_t *adj;
+
+        adj = adj_get(ai);
+
+        if (IP_LOOKUP_NEXT_GLEAN == adj->lookup_next_index)
         {
             /*
              * the connected prefix will link to a glean on a non-p2p
              * interface.
+             * Ensure we are updating with a host in the connected's subnet
              */
-            adj->sub_type.glean.receive_addr = entry->fe_prefix.fp_addr;
+            if (fib_prefix_is_cover(&adj->sub_type.glean.rx_pfx,
+                                    &local->fe_prefix))
+            {
+               fib_entry_src_t *local_src;
+
+               local_src = fib_entry_src_find (local, FIB_SOURCE_INTERFACE);
+               if (local_src != NULL)
+                 {
+                   adj->sub_type.glean.rx_pfx.fp_addr =
+                     local->fe_prefix.fp_addr;
+                   local_src->fes_flags |= FIB_ENTRY_SRC_FLAG_PROVIDES_GLEAN;
+                   return (1);
+                 }
+            }
         }
     }
+
+    return (0);
+}
+
+static walk_rc_t
+fib_entry_src_interface_update_glean_walk (fib_entry_t *cover,
+                                           fib_node_index_t covered,
+                                           void *ctx)
+{
+    if (fib_entry_src_interface_update_glean(cover, fib_entry_get(covered)))
+        return (WALK_STOP);
+
+    return (WALK_CONTINUE);
+}
+
+static void
+fib_entry_src_interface_path_swap (fib_entry_src_t *src,
+                                  const fib_entry_t *entry,
+                                  fib_path_list_flags_t pl_flags,
+                                  const fib_route_path_t *paths)
+{
+    src->fes_pl = fib_path_list_create(pl_flags, paths);
+}
+
+typedef struct fesi_find_glean_ctx_t_ {
+  fib_node_index_t glean_node_index;
+} fesi_find_glean_ctx_t;
+
+static walk_rc_t
+fib_entry_src_interface_find_glean_walk (fib_entry_t *cover,
+                                        fib_node_index_t covered,
+                                        void *ctx)
+{
+  fesi_find_glean_ctx_t *find_glean_ctx = ctx;
+  fib_entry_t *covered_entry;
+  fib_entry_src_t *covered_src;
+
+  covered_entry = fib_entry_get (covered);
+  covered_src = fib_entry_src_find (covered_entry, FIB_SOURCE_INTERFACE);
+  if ((covered_src != NULL) &&
+      (covered_src->fes_flags & FIB_ENTRY_SRC_FLAG_PROVIDES_GLEAN))
+    {
+      find_glean_ctx->glean_node_index = covered;
+      return WALK_STOP;
+    }
+
+  return WALK_CONTINUE;
+}
+
+static fib_entry_t *
+fib_entry_src_interface_find_glean (fib_entry_t *cover)
+{
+  fib_entry_src_t *src;
+
+  src = fib_entry_src_find (cover, FIB_SOURCE_INTERFACE);
+  if (src == NULL)
+    /* the cover is not an interface source */
+    return NULL;
+
+  fesi_find_glean_ctx_t ctx = {
+    .glean_node_index = ~0,
+  };
+
+  fib_entry_cover_walk (cover, fib_entry_src_interface_find_glean_walk,
+                       &ctx);
+
+  return (ctx.glean_node_index == ~0) ? NULL :
+                                       fib_entry_get (ctx.glean_node_index);
 }
 
 /*
@@ -74,21 +182,32 @@ fib_entry_src_interface_activate (fib_entry_src_t *src,
 
     if (FIB_ENTRY_FLAG_LOCAL & src->fes_entry_flags)
     {
+       u8 update_glean;
+
        /*
         * Track the covering attached/connected cover. This is so that
         * during an attached export of the cover, this local prefix is
         * also exported
         */
-       src->interface.fesi_cover =
+       src->u.interface.fesi_cover =
            fib_table_get_less_specific(fib_entry->fe_fib_index,
                                        &fib_entry->fe_prefix);
 
-       ASSERT(FIB_NODE_INDEX_INVALID != src->interface.fesi_cover);
+       ASSERT(FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover);
 
-       cover = fib_entry_get(src->interface.fesi_cover);
+       cover = fib_entry_get(src->u.interface.fesi_cover);
 
-       src->interface.fesi_sibling =
+       /*
+        * Before adding as a child of the cover, check whether an existing
+        * child has already been used to populate the glean adjacency. If so,
+        * we don't need to update the adjacency.
+        */
+       update_glean = (fib_entry_src_interface_find_glean (cover) == NULL);
+       src->u.interface.fesi_sibling =
            fib_entry_cover_track(cover, fib_entry_get_index(fib_entry));
+
+       if (update_glean)
+         fib_entry_src_interface_update_glean(cover, fib_entry);
     }
 
     return (!0);
@@ -106,15 +225,24 @@ fib_entry_src_interface_deactivate (fib_entry_src_t *src,
     fib_entry_t *cover;
 
     /*
-     * remove the depednecy on the covering entry
+     * remove the dependency on the covering entry
      */
-    if (FIB_NODE_INDEX_INVALID != src->interface.fesi_cover)
+    if (FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover)
     {
-       cover = fib_entry_get(src->interface.fesi_cover);
+       cover = fib_entry_get(src->u.interface.fesi_cover);
+       fib_entry_cover_untrack(cover, src->u.interface.fesi_sibling);
 
-       fib_entry_cover_untrack(cover, src->interface.fesi_sibling);
+       src->u.interface.fesi_cover = FIB_NODE_INDEX_INVALID;
+       src->u.interface.fesi_sibling = ~0;
 
-       src->interface.fesi_cover = FIB_NODE_INDEX_INVALID;
+       /* If this was the glean address, find a new one */
+       if (src->fes_flags & FIB_ENTRY_SRC_FLAG_PROVIDES_GLEAN)
+         {
+           fib_entry_cover_walk(cover,
+                               fib_entry_src_interface_update_glean_walk,
+                               NULL);
+           src->fes_flags &= ~FIB_ENTRY_SRC_FLAG_PROVIDES_GLEAN;
+         }
     }
 }
 
@@ -127,7 +255,7 @@ fib_entry_src_interface_cover_change (fib_entry_src_t *src,
        .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
     };
 
-    if (FIB_NODE_INDEX_INVALID == src->interface.fesi_cover)
+    if (FIB_NODE_INDEX_INVALID == src->u.interface.fesi_cover)
     {
        /*
         * not tracking the cover. surprised we got poked?
@@ -140,8 +268,9 @@ fib_entry_src_interface_cover_change (fib_entry_src_t *src,
      * entry inserted benaeth it. That does not necessarily mean that this
      * entry is covered by the new prefix. check that
      */
-    if (src->rr.fesr_cover != fib_table_get_less_specific(fib_entry->fe_fib_index,
-                                                         &fib_entry->fe_prefix))
+    if (src->u.interface.fesi_cover !=
+        fib_table_get_less_specific(fib_entry->fe_fib_index,
+                                    &fib_entry->fe_prefix))
     {
        fib_entry_src_interface_deactivate(src, fib_entry);
        fib_entry_src_interface_activate(src, fib_entry);
@@ -158,9 +287,9 @@ fib_entry_src_interface_installed (fib_entry_src_t *src,
      */
     fib_entry_t *cover;
 
-    if (FIB_NODE_INDEX_INVALID != src->interface.fesi_cover)
+    if (FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover)
     {
-       cover = fib_entry_get(src->interface.fesi_cover);
+       cover = fib_entry_get(src->u.interface.fesi_cover);
 
        fib_attached_export_covered_added(cover,
                                          fib_entry_get_index(fib_entry));
@@ -171,11 +300,13 @@ static u8*
 fib_entry_src_interface_format (fib_entry_src_t *src,
                                u8* s)
 {
-    return (format(s, "cover:%d", src->interface.fesi_cover));
+    return (format(s, " cover:%d", src->u.interface.fesi_cover));
 }
 
 const static fib_entry_src_vft_t interface_src_vft = {
     .fesv_init = fib_entry_src_interface_init,
+    .fesv_add = fib_entry_src_interface_add,
+    .fesv_remove = fib_entry_src_interface_remove,
     .fesv_path_swap = fib_entry_src_interface_path_swap,
     .fesv_activate = fib_entry_src_interface_activate,
     .fesv_deactivate = fib_entry_src_interface_deactivate,
@@ -191,5 +322,6 @@ const static fib_entry_src_vft_t interface_src_vft = {
 void
 fib_entry_src_interface_register (void)
 {
-    fib_entry_src_register(FIB_SOURCE_INTERFACE, &interface_src_vft);    
+    fib_entry_src_behaviour_register(FIB_SOURCE_BH_INTERFACE,
+                                     &interface_src_vft);
 }