fib: add invalid source type and fix debug log 66/20766/3
authorBenoît Ganne <bganne@cisco.com>
Wed, 17 Jul 2019 12:47:23 +0000 (14:47 +0200)
committerNeale Ranns <nranns@cisco.com>
Sun, 28 Jul 2019 14:24:29 +0000 (14:24 +0000)
Add the FIB_SOURCE_INVALID fib source type. This allows to spot
uninitialized fib source more easily (0 no longer means special) and we
can use it as placeholder when no source is present.
Use it to fix FIB_ENTRY_DBG() which was accessing the 1st source, even
when no sources were present.

Type: fix
Fixes: 710071bf0e

Change-Id: I980b6a6a07616d4a8d6f2db166a1dd335721c74d
Signed-off-by: Benoît Ganne <bganne@cisco.com>
src/vnet/fib/fib_entry.h
src/vnet/fib/fib_entry_src.c
src/vnet/fib/fib_entry_src.h

index 70c6621..8bd87e9 100644 (file)
  * The lower the value the higher the priority
  */
 typedef enum fib_source_t_ {
+    /**
+     * An invalid source
+     * This is not a real source, so don't use it to source a prefix.
+     * It exists here to provide a value for inexistant/uninitialized source
+     */
+    FIB_SOURCE_INVALID = 0,
     /**
      * Marker. Add new values after this one.
      */
@@ -156,6 +162,7 @@ STATIC_ASSERT (sizeof(fib_source_t) == 1,
 #define FIB_SOURCE_MAX (FIB_SOURCE_LAST+1)
 
 #define FIB_SOURCES {                                  \
+    [FIB_SOURCE_INVALID] = "invalid",                  \
     [FIB_SOURCE_SPECIAL] = "special",                  \
     [FIB_SOURCE_INTERFACE] = "interface",              \
     [FIB_SOURCE_PROXY] = "proxy",                       \
index 067733f..6ed13a3 100644 (file)
@@ -1827,27 +1827,22 @@ fib_entry_get_flags_for_source (fib_node_index_t entry_index,
     return (FIB_ENTRY_FLAG_NONE);
 }
 
+fib_source_t
+fib_entry_get_source_i (const fib_entry_t *fib_entry)
+{
+    /* the vector of sources is deliberately arranged in priority order */
+    if (0 == vec_len(fib_entry->fe_srcs))
+        return (FIB_SOURCE_INVALID);
+    return (vec_elt(fib_entry->fe_srcs, 0).fes_src);
+}
+
 fib_entry_flag_t
 fib_entry_get_flags_i (const fib_entry_t *fib_entry)
 {
-    fib_entry_flag_t flags;
-
-    /*
-     * the vector of sources is deliberately arranged in priority order
-     */
+    /* the vector of sources is deliberately arranged in priority order */
     if (0 == vec_len(fib_entry->fe_srcs))
-    {
-       flags = FIB_ENTRY_FLAG_NONE;
-    }
-    else
-    {
-       fib_entry_src_t *esrc;
-
-       esrc = vec_elt_at_index(fib_entry->fe_srcs, 0);
-       flags = esrc->fes_entry_flags;
-    }
-
-    return (flags);
+        return (FIB_ENTRY_FLAG_NONE);
+    return (vec_elt(fib_entry->fe_srcs, 0).fes_entry_flags);
 }
 
 void
index 1d5f252..a859b9c 100644 (file)
@@ -33,9 +33,9 @@ extern vlib_log_class_t fib_entry_logger;
                    format_fib_prefix,                   \
                    &_e->fe_prefix,                      \
                    format_fib_entry_flags,              \
-                    _e->fe_srcs[0].fes_entry_flags,     \
+                   fib_entry_get_flags_i(_e),           \
                    format_fib_source,                   \
-                   _e->fe_srcs[0].fes_src,              \
+                   fib_entry_get_source_i(_e),          \
                    ##_args);                            \
 }
 
@@ -316,6 +316,7 @@ extern void fib_entry_src_inherit (const fib_entry_t *cover,
 
 extern fib_forward_chain_type_t fib_entry_get_default_chain_type(
     const fib_entry_t *fib_entry);
+extern fib_source_t fib_entry_get_source_i(const fib_entry_t *fib_entry);
 extern fib_entry_flag_t fib_entry_get_flags_i(const fib_entry_t *fib_entry);
 
 extern fib_path_list_flags_t fib_entry_src_flags_2_path_list_flags(