From: Donald Sharp Date: Thu, 31 Mar 2016 16:07:34 +0000 (-0400) Subject: lib: Combine name comparison function X-Git-Tag: frr-2.0-rc1~1001 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=974fc9d251d9b940d3e813839603d9946baedd80;p=mirror_frr.git lib: Combine name comparison function 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 Reviewed-by: Daniel Walton --- diff --git a/lib/if.c b/lib/if.c index 443cd419b..420215d8b 100644 --- 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) diff --git a/lib/if.h b/lib/if.h index f9c4cd506..b65d95515 100644 --- 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); diff --git a/lib/vrf.c b/lib/vrf.c index 491f27edf..4b7a28005 100644 --- 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. */ diff --git a/lib/vrf.h b/lib/vrf.h index 0d2c142be..b2493020b 100644 --- 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 *);