]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: Combine name comparison function
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 31 Mar 2016 16:07:34 +0000 (12:07 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 31 Mar 2016 18:00:29 +0000 (14:00 -0400)
The vrf name comparison function was the same as the interface
comparison function.  Combine the forces for the goodness of
mankind.

Ticket: CM-10184
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by: Daniel Walton <dwalton@cumulusnetworks.com>
lib/if.c
lib/if.h
lib/vrf.c
lib/vrf.h

index 443cd419bedfab01a540c7e0af97846f9dd62feb..420215d8b7894c5f43bfb2f1ae84b9136a92f463 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -57,16 +57,12 @@ struct if_master
  * devpty0, de0 < del0
  */         
 int
-if_cmp_func (struct interface *ifp1, struct interface *ifp2)
+if_cmp_name_func (char *p1, char *p2)
 {
   unsigned int l1, l2;
   long int x1, x2;
-  char *p1, *p2;
   int res;
 
-  p1 = ifp1->name;
-  p2 = ifp2->name;
-
   while (*p1 && *p2) {
     /* look up to any number */
     l1 = strcspn(p1, "0123456789");
@@ -113,6 +109,12 @@ if_cmp_func (struct interface *ifp1, struct interface *ifp2)
   return 0;
 }
 
+static int
+if_cmp_func (struct interface *ifp1, struct interface *ifp2)
+{
+  return if_cmp_name_func (ifp1->name, ifp2->name);
+}
+
 /* Create new interface structure. */
 struct interface *
 if_create_vrf (const char *name, int namelen, vrf_id_t vrf_id)
index f9c4cd5063b926008062060f2f5db38db88116d0..b65d9551524e92b968c8624ee7ef0054e8d24fb2 100644 (file)
--- a/lib/if.h
+++ b/lib/if.h
@@ -262,7 +262,7 @@ struct nbr_connected
 #endif /* IFF_VIRTUAL */
 
 /* Prototypes. */
-extern int if_cmp_func (struct interface *, struct interface *);
+extern int if_cmp_name_func (char *, char *);
 extern struct interface *if_create (const char *name, int namelen);
 extern struct interface *if_lookup_by_index (unsigned int);
 extern struct interface *if_lookup_exact_address (void *matchaddr, int family);
index 491f27edf12ac5174eacd81fad2954ba3f57bc01..4b7a2800544e8ee2b63c66be531f912e6395d058 100644 (file)
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -606,7 +606,6 @@ vrf_bitmap_check (vrf_bitmap_t bmap, vrf_id_t vrf_id)
                      VRF_BITMAP_FLAG (offset)) ? 1 : 0;
 }
 
-//Pending: See if combining the common parts with if_cmp_func() make sense.
 /* Compare interface names, returning an integer greater than, equal to, or
  * less than 0, (following the strcmp convention), according to the
  * relationship between vrfp1 and vrfp2.  Interface names consist of an
@@ -615,61 +614,10 @@ vrf_bitmap_check (vrf_bitmap_t bmap, vrf_id_t vrf_id)
  * before all numbers.  Examples: de0 < de1, de100 < fxp0 < xl0, devpty <
  * devpty0, de0 < del0
  */
-int
+static int
 vrf_cmp_func (struct vrf *vrfp1, struct vrf *vrfp2)
 {
-  unsigned int l1, l2;
-  long int x1, x2;
-  char *p1, *p2;
-  int res;
-
-  p1 = vrfp1->name;
-  p2 = vrfp2->name;
-
-  while (*p1 && *p2) {
-    /* look up to any number */
-    l1 = strcspn(p1, "0123456789");
-    l2 = strcspn(p2, "0123456789");
-
-    /* name lengths are different -> compare names */
-    if (l1 != l2)
-      return (strcmp(p1, p2));
-
-    /* Note that this relies on all numbers being less than all letters, so
-     * that de0 < del0.
-     */
-    res = strncmp(p1, p2, l1);
-
-    /* names are different -> compare them */
-    if (res)
-      return res;
-
-    /* with identical name part, go to numeric part */
-    p1 += l1;
-    p2 += l1;
-
-    if (!*p1)
-      return -1;
-    if (!*p2)
-      return 1;
-
-    x1 = strtol(p1, &p1, 10);
-    x2 = strtol(p2, &p2, 10);
-
-    /* let's compare numbers now */
-    if (x1 < x2)
-      return -1;
-    if (x1 > x2)
-      return 1;
-
-    /* numbers were equal, lets do it again..
-    (it happens with name like "eth123.456:789") */
-  }
-  if (*p1)
-    return 1;
-  if (*p2)
-    return -1;
-  return 0;
+  return if_cmp_name_func (vrfp1->name, vrfp2->name);
 }
 
 /* Initialize VRF module. */
index 0d2c142bea1583b0df5f6c2331dc7062db75c5ee..b2493020b7ab441c68676c2184205405b8a7cd2e 100644 (file)
--- a/lib/vrf.h
+++ b/lib/vrf.h
@@ -106,7 +106,6 @@ extern void vrf_add_hook (int, int (*)(vrf_id_t, const char *, void **));
 typedef void *              vrf_iter_t;
 #define VRF_ITER_INVALID    NULL    /* invalid value of the iterator */
 
-extern int vrf_cmp_func (struct vrf *, struct vrf *);
 extern struct vrf *vrf_lookup (vrf_id_t);
 extern struct vrf *vrf_lookup_by_name (const char *);
 extern struct vrf *vrf_list_lookup_by_name (const char *);