* 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");
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)
#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);
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
* 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. */
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 *);