]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib/zebra: remove code duplication in redist_del_instance()
authorRenato Westphal <renato@opensourcerouting.org>
Thu, 13 Oct 2016 16:06:10 +0000 (13:06 -0300)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 18 Oct 2016 12:51:24 +0000 (08:51 -0400)
Change redist_check_instance() to return a pointer instead of returning 1
on success. This way this function can be reused in redist_del_instance()
instead of duplicating the same logic there.

Also, remove unnecessary call to redist_check_instance() in
zebra_redistribute_delete().

While here, remove unnecessary cast from void* in redist_add_instance().

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
lib/zclient.c
lib/zclient.h
zebra/redistribute.c

index fa8150c5a1042b77e002f499546926cd425d03bd..8c7448dd71bc327ab7b8a3cf727a536cbc726103 100644 (file)
@@ -80,20 +80,20 @@ zclient_free (struct zclient *zclient)
   XFREE (MTYPE_ZCLIENT, zclient);
 }
 
-int
+u_short *
 redist_check_instance (struct redist_proto *red, u_short instance)
 {
   struct listnode *node;
   u_short *id;
 
   if (!red->instances)
-    return 0;
+    return NULL;
 
   for (ALL_LIST_ELEMENTS_RO (red->instances, node, id))
     if (*id == instance)
-      return 1;
+      return id;
 
-  return 0;
+  return NULL;
 }
 
 void
@@ -106,7 +106,7 @@ redist_add_instance (struct redist_proto *red, u_short instance)
   if (!red->instances)
     red->instances = list_new();
 
-  in = (u_short *)calloc(1, sizeof(u_short));
+  in = calloc (1, sizeof(u_short));
   *in = instance;
   listnode_add (red->instances, in);
 }
@@ -114,25 +114,18 @@ redist_add_instance (struct redist_proto *red, u_short instance)
 void
 redist_del_instance (struct redist_proto *red, u_short instance)
 {
-  struct listnode *node;
-  u_short *id = NULL;
+  u_short *id;
 
-  if (!red->instances)
+  id = redist_check_instance (red, instance);
+  if (! id)
     return;
 
-  for (ALL_LIST_ELEMENTS_RO (red->instances, node, id))
-    if (*id == instance)
-        break;
-
-  if (id)
+  listnode_delete(red->instances, id);
+  if (!red->instances->count)
     {
-      listnode_delete(red->instances, id);
-      if (!red->instances->count)
-        {
-          red->enabled = 0;
-          list_free(red->instances);
-          red->instances = NULL;
-        }
+      red->enabled = 0;
+      list_free(red->instances);
+      red->instances = NULL;
     }
 }
 
index f122b233b9569da196fd479afe4a0e2a375a2871..7ea5bc963acf6a7738ce3807c3559620e41d1c07 100644 (file)
@@ -169,7 +169,7 @@ extern int  zclient_socket_connect (struct zclient *);
 extern void zclient_serv_path_set  (char *path);
 extern const char *zclient_serv_path_get (void);
 
-extern int redist_check_instance (struct redist_proto *, u_short);
+extern u_short *redist_check_instance (struct redist_proto *, u_short);
 extern void redist_add_instance (struct redist_proto *, u_short);
 extern void redist_del_instance (struct redist_proto *, u_short);
 
index 061224461ef047efb37df70ee3ffecde2d58d01c..c74485bb35e0ea70c5df54cc3fcf85a3479a7e41 100644 (file)
@@ -294,10 +294,7 @@ zebra_redistribute_delete (int command, struct zserv *client, int length,
    * withdraw them when necessary.
    */
   if (instance)
-    {
-      if (redist_check_instance (&client->mi_redist[afi][type], instance))
-       redist_del_instance (&client->mi_redist[afi][type], instance);
-    }
+    redist_del_instance (&client->mi_redist[afi][type], instance);
   else
     vrf_bitmap_unset (client->redist[afi][type], zvrf->vrf_id);
 }