summaryrefslogtreecommitdiff
path: root/zebra/zebra_rib.c
diff options
context:
space:
mode:
authorJosh Bailey <joshb@google.com>2012-03-21 18:47:51 -0700
committerAvneesh Sachdev <avneesh@opensourcerouting.org>2012-04-08 00:28:50 -0700
commitaf56d404cd56d94ad3b2ec3f159650eb72baef0a (patch)
tree2d923b385dd21a5f0ced95d2430b4c998af18f94 /zebra/zebra_rib.c
parentfc328ac9d3d49b871c1139f36deb702a254c0d4f (diff)
zebra: clean up client routes when client goes away
* zebra/zebra_rib.c: Add code to clean up routes added by a client (as identfied by 'rib type'). * zebra/zserv.[ch]: Maintain the type of the routes added by a client on the 'zserv' structure -- assume that a given client uses a single route type for now. Clean up routes from a client when the client goes away (in zebra_client_close()). From: Josh Bailey <joshb@google.com> Signed-off-by: Avneesh Sachdev <avneesh@opensourcerouting.org> Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'zebra/zebra_rib.c')
-rw-r--r--zebra/zebra_rib.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index 0035eb6e..8da6c84a 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -2905,6 +2905,61 @@ rib_sweep_route (void)
rib_sweep_table (vrf_table (AFI_IP6, SAFI_UNICAST, 0));
}
+/* Delete routes learned from a given client. */
+/* TODO(wsun) May need to split the sweep process into multiple batches,
+ * so that the process won't take too long if the table is large. */
+static void
+rib_sweep_client_table (struct route_table *table, int rib_type)
+{
+ struct route_node *rn;
+ struct rib *rib;
+ struct rib *next;
+ int ret = 0;
+
+ if (table)
+ for (rn = route_top (table); rn; rn = route_next (rn))
+ for (rib = rn->info; rib; rib = next)
+ {
+ next = rib->next;
+
+ if (CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED))
+ continue;
+
+ if (rib->type == rib_type)
+ if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
+ {
+ /* TODO(wsun) Is this mandatory? What about graceful restart/
+ * non-stop forwarding */
+ ret = rib_uninstall_kernel (rn, rib);
+ if (! ret)
+ rib_delnode (rn, rib);
+ else
+ zlog_err ("%s: could not delete routes from kernel!",
+ __func__);
+ }
+ else
+ {
+ /* Always delete the node. */
+ rib_delnode (rn, rib);
+ }
+ }
+}
+
+/* Sweep all routes learned from a given client from RIB tables. */
+void
+rib_sweep_client_route (struct zserv *client)
+{
+ assert(client);
+ int route_type = client->route_type;
+ if (route_type != ZEBRA_ROUTE_MAX)
+ {
+ zlog_debug ("%s: Removing existing routes from client type %d",
+ __func__, route_type);
+ rib_sweep_client_table (vrf_table (AFI_IP, SAFI_UNICAST, 0), route_type);
+ rib_sweep_client_table (vrf_table (AFI_IP6, SAFI_UNICAST, 0), route_type);
+ }
+}
+
/* Close RIB and clean up kernel routes. */
static void
rib_close_table (struct route_table *table)