2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>

	* if.h: (if_lookup_by_name_len, if_get_by_name_len) New functions.
	* if.c: (if_lookup_by_name_len, if_get_by_name_len) New functions.
	  (if_get_by_name) Tighten up code.
	  (interface) Use new function if_get_by_name_len.
	* zclient.c: (zebra_interface_add_read) Use new if_get_by_name_len
	  function.
	  (zebra_interface_state_read) Use new if_lookup_by_name_len function.
	* kernel_socket.c: (ifm_read) Use new if_lookup_by_name_len function
	  to save a memcpy.
	* if_ioctl_solaris.c: (interface_list_ioctl) Fix subtle bug with new
	  if_get_by_name_len function.
	* ospf_interface.c: (ospf_vl_new) Use strnlen to fix call to if_create.
diff --git a/lib/if.c b/lib/if.c
index e35e3ed..212b236 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -219,12 +219,33 @@
   for (node = listhead (iflist); node; nextnode (node))
     {
       ifp = getdata (node);
+      /* Change this to strcmp once improper uses of this function
+         have been replaced with calls to if_lookup_by_name_len. */
       if (strncmp (name, ifp->name, sizeof ifp->name) == 0)
 	return ifp;
     }
   return NULL;
 }
 
+struct interface *
+if_lookup_by_name_len(const char *name, size_t namelen)
+{
+  struct listnode *node;
+
+  if (namelen > INTERFACE_NAMSIZ)
+    return NULL;
+
+  for (node = listhead (iflist); node; nextnode (node))
+    {
+      struct interface *ifp;
+
+      ifp = getdata (node);
+      if (!memcmp(name, ifp->name, namelen) && (ifp->name[namelen] == '\0'))
+	return ifp;
+    }
+  return NULL;
+}
+
 /* Lookup interface by IPv4 address. */
 struct interface *
 if_lookup_exact_address (struct in_addr src)
@@ -314,10 +335,19 @@
 {
   struct interface *ifp;
 
-  ifp = if_lookup_by_name (name);
-  if (ifp == NULL)
-    ifp = if_create (name, INTERFACE_NAMSIZ);
-  return ifp;
+  /* Replace 2nd arg to if_create with strlen(name) once improper uses of
+     this function have been replaced with calls to if_get_by_name_len. */
+  return ((ifp = if_lookup_by_name(name)) != NULL) ? ifp :
+	 if_create(name, INTERFACE_NAMSIZ);
+}
+
+struct interface *
+if_get_by_name_len(const char *name, size_t namelen)
+{
+  struct interface *ifp;
+
+  return ((ifp = if_lookup_by_name_len(name, namelen)) != NULL) ? ifp :
+	 if_create(name, namelen);
 }
 
 /* Does interface up ? */
@@ -504,10 +534,8 @@
       return CMD_WARNING;
     }
 
-  ifp = if_lookup_by_name (argv[0]);
+  ifp = if_get_by_name_len(argv[0], sl);
 
-  if (ifp == NULL)
-    ifp = if_create (argv[0], sl);
   vty->index = ifp;
   vty->node = INTERFACE_NODE;