[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH v3] dots should be valid characters in interface names



On 05/19/2010 11:54 PM, Charles Duffy wrote:
A revised patch is attached. This lifts its logic from its kernel
counterpart, and is updated only to permit forward slashes (which, while
disallowed for interface names with the kernel, are required for
*device* names -- for which the ESX driver happens to overload this
field. Ugh).

Failed to run "make syntax-check" on the last rev. Oops.
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 20c9c51..af9684d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include "c-ctype.h"
 #include <fcntl.h>
 #include <dirent.h>
 #include <sys/time.h>
@@ -1802,8 +1803,29 @@ cleanup:
 
 
 static bool
-isValidIfname(const char *ifname) {
-    return ifname[strspn(ifname, VALID_IFNAME_CHARS)] == 0;
+isValidIfname(const char *ifname)
+{
+    if (*ifname == 0)
+        return false;
+    if (strlen(ifname) >= IFNAME_MAX_LENGTH)
+        return false;
+    if (STREQ(ifname, ".") || STREQ(ifname, ".."))
+        return false;
+    while (*ifname) {
+        /* in the kernel, forward slashes aren't allowed; however, the vmxnet
+         * driver depends on them, so we're slightly more permissive and
+         * disallow only spaces -- however, this will break for drivers other
+         * than VMware.
+         *
+         * Enforcing IFNAME_MAX_LENGTH is probably not appropriate for VMware
+         * either. Perhaps it should be using a different attribute name?
+         */
+        if (c_isspace(*ifname)) {
+            return false;
+        }
+        ifname++;
+    }
+    return true;
 }
 
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fadc8bd..b68818e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -298,8 +298,8 @@ struct _virDomainNetDef {
     virNWFilterHashTablePtr filterparams;
 };
 
-# define VALID_IFNAME_CHARS \
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_/"
+/* corresponds with kernel constant IFNAMSIZ from <linux/if.h> */
+# define IFNAME_MAX_LENGTH 16
 
 enum virDomainChrTargetType {
     VIR_DOMAIN_CHR_TARGET_TYPE_NULL = 0,

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]