diff options
author | Josh Bailey <joshb@google.com> | 2012-03-21 18:47:51 -0700 |
---|---|---|
committer | Avneesh Sachdev <avneesh@opensourcerouting.org> | 2012-04-08 00:28:50 -0700 |
commit | af56d404cd56d94ad3b2ec3f159650eb72baef0a (patch) | |
tree | 2d923b385dd21a5f0ced95d2430b4c998af18f94 /zebra/zserv.c | |
parent | fc328ac9d3d49b871c1139f36deb702a254c0d4f (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/zserv.c')
-rw-r--r-- | zebra/zserv.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/zebra/zserv.c b/zebra/zserv.c index 9e6f6253..2330135a 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -750,6 +750,13 @@ zread_ipv4_add (struct zserv *client, u_short length) /* Type, flags, message. */ rib->type = stream_getc (s); + /* Update client's route type if it is not done yet. */ + /* It is done here since only zread_ipv4/6_add() and + * zread_ipv4/6_delete() decode Zebra messages and retrieve + * route types. */ + if (client->route_type == ZEBRA_ROUTE_MAX) + client->route_type = rib->type; + rib->flags = stream_getc (s); message = stream_getc (s); rib->uptime = time (NULL); @@ -924,6 +931,11 @@ zread_ipv6_add (struct zserv *client, u_short length) /* Type, flags, message. */ api.type = stream_getc (s); + /* Update the route type of the client. + * Same as in zread_ipv4_add(). */ + if (client->route_type == ZEBRA_ROUTE_MAX) + client->route_type = api.type; + api.flags = stream_getc (s); api.message = stream_getc (s); @@ -1077,6 +1089,14 @@ zread_router_id_delete (struct zserv *client, u_short length) static void zebra_client_close (struct zserv *client) { + struct stream *s; + + /* Sweep all routes learned from the client first. */ + rib_sweep_client_route(client); + /* Reset the route type. It may not be necessary since the + * whole client will be freed. */ + client->route_type = ZEBRA_ROUTE_MAX; + /* Close file descriptor. */ if (client->sock) { @@ -1115,6 +1135,9 @@ zebra_client_create (int sock) /* Make client input/output buffer. */ client->sock = sock; + /* Set the default route type to ZEBRA_ROUTE_MAX; it will be updated + * once new routes are received. */ + client->route_type = ZEBRA_ROUTE_MAX; client->ibuf = stream_new (ZEBRA_MAX_PACKET_SIZ); client->obuf = stream_new (ZEBRA_MAX_PACKET_SIZ); client->wb = buffer_new(0); |