]> git.puffer.fish Git - matthieu/frr.git/commitdiff
2003-08-01 Cougar <cougar@random.ee>
authorpaul <paul>
Fri, 1 Aug 2003 00:24:13 +0000 (00:24 +0000)
committerpaul <paul>
Fri, 1 Aug 2003 00:24:13 +0000 (00:24 +0000)
* lib/if.c: (if_cmp_func) new function, compare interface names in
alphabetical order.
(if_create) Take name as argument and add interface in sorted order.
(if_get_by_name),(interface_cmd) fixup calls to if_create - see
above.
(if_init) register list comparison function.
* lib/if.h: Add comparison function, modify if_create prototype.
* lib/zclient.c: Modify call to if_create.
* ospfd/ospf_interface.c: (ospf_vl_new) modify call to if_create.
change sprintf to snprintf.
* zebra/kernel_socket.c: (ifm_read) modify call to if_create.

lib/if.c
lib/if.h
lib/zclient.c
ospfd/ospf_interface.c
zebra/kernel_socket.c

index f003754ad0368e9b4922fb68df4ab7b7d705af91..30de6805ce65a9c100959848c001bf59737721dd 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -1,3 +1,4 @@
+
 /* 
  * Interface functions.
  * Copyright (C) 1997, 98 Kunihiro Ishiguro
@@ -46,6 +47,52 @@ struct if_master
   int (*if_delete_hook) (struct interface *);
 } if_master;
 \f
+/* Compare interface names */
+int
+if_cmp_func (struct interface *ifp1, struct interface *ifp2)
+{
+  unsigned int l1, l2;
+  long int x1, x2;
+  char *p1, *p2;
+  int res;
+
+  p1 = ifp1->name;
+  p2 = ifp2->name;
+
+  while (1) {
+    /* 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));
+
+    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;
+
+    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") */
+  }
+}
+
 /* Create new interface structure. */
 struct interface *
 if_new ()
@@ -58,13 +105,17 @@ if_new ()
 }
 
 struct interface *
-if_create ()
+if_create (char *name, int namelen)
 {
   struct interface *ifp;
 
   ifp = if_new ();
   
-  listnode_add (iflist, ifp);
+  assert (name);
+  assert (namelen <= (INTERFACE_NAMSIZ + 1));
+  strncpy (ifp->name, name, namelen);
+  ifp->name[INTERFACE_NAMSIZ] = '\0';
+  listnode_add_sort (iflist, ifp);
   ifp->connected = list_new ();
   ifp->connected->del = (void (*) (void *)) connected_free;
 
@@ -248,10 +299,7 @@ if_get_by_name (char *name)
 
   ifp = if_lookup_by_name (name);
   if (ifp == NULL)
-    {
-      ifp = if_create ();
-      strncpy (ifp->name, name, IFNAMSIZ);
-    }
+    ifp = if_create (name, INTERFACE_NAMSIZ);
   return ifp;
 }
 
@@ -430,10 +478,7 @@ DEFUN (interface,
   ifp = if_lookup_by_name (argv[0]);
 
   if (ifp == NULL)
-    {
-      ifp = if_create ();
-      strncpy (ifp->name, argv[0], INTERFACE_NAMSIZ);
-    }
+    ifp = if_create (argv[0], INTERFACE_NAMSIZ);
   vty->index = ifp;
   vty->node = INTERFACE_NODE;
 
@@ -803,8 +848,10 @@ if_init ()
   iflist = list_new ();
   ifaddr_ipv4_table = route_table_init ();
 
-  if (iflist)
+  if (iflist) {
+    iflist->cmp = (int (*)(void *, void *))if_cmp_func;
     return;
+  }
 
   memset (&if_master, 0, sizeof if_master);
 }
index 9ffe74cfbf5045a8715e19af81b44f367cdfde45..3fbeed9a8fa7778b993ee8912222f477cd6ed506 100644 (file)
--- a/lib/if.h
+++ b/lib/if.h
@@ -180,8 +180,9 @@ struct connected
 #endif /* IFF_LINK2 */
 
 /* Prototypes. */
+int if_cmp_func (struct interface *, struct interface *);
 struct interface *if_new (void);
-struct interface *if_create (void);
+struct interface *if_create (char *name, int namelen);
 struct interface *if_lookup_by_index (unsigned int);
 struct interface *if_lookup_by_name (char *);
 struct interface *if_lookup_exact_address (struct in_addr);
index bb7747fae9f40e9a171aebb2f20f07b7326fce34..bba06ee4be3957a15fb2c9bb849f7dcafb4683d6 100644 (file)
@@ -555,10 +555,7 @@ zebra_interface_add_read (struct stream *s)
 
   /* If such interface does not exist, make new one. */
   if (! ifp)
-    {
-      ifp = if_create ();
-      strncpy (ifp->name, ifname_tmp, IFNAMSIZ);
-    }
+    ifp = if_create (ifname_tmp, INTERFACE_NAMSIZ);
 
   /* Read interface's index. */
   ifp->ifindex = stream_getl (s);
index 8fa3fd6305ff6425f8cbe6bc042cd6421a9cbfee..067d551debf00f7322cb829f84fab0f6d6cd04e9 100644 (file)
@@ -745,7 +745,8 @@ ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data)
   if (IS_DEBUG_OSPF_EVENT)
     zlog_info ("ospf_vl_new(): creating pseudo zebra interface");
 
-  vi = if_create ();
+  snprintf (ifname, INTERFACE_NAMSIZ + 1, "VLINK%d", vlink_count);
+  vi = if_create (ifname, INTERFACE_NAMSIZ);
   co = connected_new ();
   co->ifp = vi;
   listnode_add (vi->connected, co);
@@ -769,10 +770,9 @@ ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data)
   voi->ifp->mtu = OSPF_VL_MTU;
   voi->type = OSPF_IFTYPE_VIRTUALLINK;
 
-  sprintf (ifname, "VLINK%d", vlink_count++);
+  vlink_count++;
   if (IS_DEBUG_OSPF_EVENT)
     zlog_info ("ospf_vl_new(): Created name: %s", ifname);
-  strncpy (vi->name, ifname, IFNAMSIZ);
   if (IS_DEBUG_OSPF_EVENT)
     zlog_info ("ospf_vl_new(): set if->name to %s", vi->name);
 
index 9527315936488071de60b09c56dc77dcf3b568d6..05eec596d817a527b24ca542cbf48efcc09d2e26 100644 (file)
@@ -219,9 +219,8 @@ ifm_read (struct if_msghdr *ifm)
          return -1;
        }
 
-      ifp = if_create ();
+      ifp = if_create (sdl->sdl_data, sdl->sdl_nlen);
 
-      strncpy (ifp->name, sdl->sdl_data, sdl->sdl_nlen);
       ifp->ifindex = ifm->ifm_index;
       ifp->flags = ifm->ifm_flags;
 #if defined(__bsdi__)