]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: add way to determine VRF/AFI/SAFI of table
authorAvneesh Sachdev <avneesh@opensourcerouting.org>
Tue, 13 Nov 2012 22:48:54 +0000 (22:48 +0000)
committerDavid Lamparter <equinox@opensourcerouting.org>
Fri, 30 Nov 2012 20:41:16 +0000 (21:41 +0100)
Add some code that allows us to determine which VRF and AFI/SAFI a
given RIB table corresponds to.

  * zebra/rib.h

    Add rib_table_info_t structure, which contains information about
    the VRF, AFI and SAFI that a table is for.

  * zebra/zebra_rib.c

    - Add the vrf_table_create() function, which creates a table and
      sets its 'info' pointer to a newly created rib_table_info_t.
      The 'info' pointer allows us to go from a route_node or a table
      to the associated vrf.

    - vrf_alloc(): Use vrf_create_table() to create tables.

  * lib/memtypes.c

    Add memory type for rib_table_info_t.

Signed-off-by: Avneesh Sachdev <avneesh@opensourcerouting.org>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/memtypes.c
zebra/rib.h
zebra/zebra_rib.c

index 76dece298f8ed33fa5c9a69cb7d9a067dcb43bd5..50b6fa42715eb0ccbdb44502265c6014982c726c 100644 (file)
@@ -83,6 +83,7 @@ struct memory_list memory_list_zebra[] =
   { MTYPE_STATIC_IPV4,         "Static IPv4 route"             },
   { MTYPE_STATIC_IPV6,         "Static IPv6 route"             },
   { MTYPE_RIB_DEST,            "RIB destination"               },
+  { MTYPE_RIB_TABLE_INFO,      "RIB table info"                },
   { -1, NULL },
 };
 
index 084f35166293f1ce73ca3867875823228dd966b5..c98d99a4d008a1933402a8c80eaa5079694bc381 100644 (file)
@@ -268,6 +268,24 @@ struct vrf
   struct route_table *stable[AFI_MAX][SAFI_MAX];
 };
 
+/*
+ * rib_table_info_t
+ *
+ * Structure that is hung off of a route_table that holds information about
+ * the table.
+ */
+typedef struct rib_table_info_t_
+{
+
+  /*
+   * Back pointer to vrf.
+   */
+  struct vrf *vrf;
+  afi_t afi;
+  safi_t safi;
+
+} rib_table_info_t;
+
 extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
 extern struct nexthop *nexthop_ifname_add (struct rib *, char *);
 extern struct nexthop *nexthop_blackhole_add (struct rib *);
@@ -361,6 +379,15 @@ extern int rib_gc_dest (struct route_node *rn);
  * Inline functions.
  */
 
+/*
+ * rib_table_info
+ */
+static inline rib_table_info_t *
+rib_table_info (struct route_table *table)
+{
+  return (rib_table_info_t *) table->info;
+}
+
 /*
  * rib_dest_from_rnode
  */
@@ -417,4 +444,13 @@ rib_dest_table (rib_dest_t *dest)
   return dest->rnode->table;
 }
 
+/*
+ * rib_dest_vrf
+ */
+static inline struct vrf *
+rib_dest_vrf (rib_dest_t *dest)
+{
+  return rib_table_info (rib_dest_table (dest))->vrf;
+}
+
 #endif /*_ZEBRA_RIB_H */
index f0d5c9d9318ba6fac588ac23380bf570a9b96172..2cbee9355759a7563313af02209d8b20c01e12cf 100644 (file)
@@ -74,6 +74,27 @@ static const struct
 /* Vector for routing table.  */
 static vector vrf_vector;
 
+/*
+ * vrf_table_create
+ */
+static void
+vrf_table_create (struct vrf *vrf, afi_t afi, safi_t safi)
+{
+  rib_table_info_t *info;
+  struct route_table *table;
+
+  assert (!vrf->table[afi][safi]);
+
+  table = route_table_init ();
+  vrf->table[afi][safi] = table;
+
+  info = XCALLOC (MTYPE_RIB_TABLE_INFO, sizeof (*info));
+  info->vrf = vrf;
+  info->afi = afi;
+  info->safi = safi;
+  table->info = info;
+}
+
 /* Allocate new VRF.  */
 static struct vrf *
 vrf_alloc (const char *name)
@@ -87,12 +108,12 @@ vrf_alloc (const char *name)
     vrf->name = XSTRDUP (MTYPE_VRF_NAME, name);
 
   /* Allocate routing table and static table.  */
-  vrf->table[AFI_IP][SAFI_UNICAST] = route_table_init ();
-  vrf->table[AFI_IP6][SAFI_UNICAST] = route_table_init ();
+  vrf_table_create (vrf, AFI_IP, SAFI_UNICAST);
+  vrf_table_create (vrf, AFI_IP6, SAFI_UNICAST);
   vrf->stable[AFI_IP][SAFI_UNICAST] = route_table_init ();
   vrf->stable[AFI_IP6][SAFI_UNICAST] = route_table_init ();
-  vrf->table[AFI_IP][SAFI_MULTICAST] = route_table_init ();
-  vrf->table[AFI_IP6][SAFI_MULTICAST] = route_table_init ();
+  vrf_table_create (vrf, AFI_IP, SAFI_MULTICAST);
+  vrf_table_create (vrf, AFI_IP6, SAFI_MULTICAST);
   vrf->stable[AFI_IP][SAFI_MULTICAST] = route_table_init ();
   vrf->stable[AFI_IP6][SAFI_MULTICAST] = route_table_init ();