]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
network: allow '-' in model name
authorEric Blake <eblake@redhat.com>
Thu, 8 Dec 2011 06:41:22 +0000 (17:41 +1100)
committerEric Blake <eblake@redhat.com>
Fri, 9 Dec 2011 20:02:45 +0000 (13:02 -0700)
In QEMU PPC64 we have a network device called "spapr-vlan". We can specify
this using the existing syntax for network devices, however libvirt
currently rejects "spapr-vlan" in virDomainNetDefParseXML() because of
the "-". Fix the code to accept "-".

* src/conf/domain_conf.c (virDomainNetDefParseXML): Allow '-' in
model name, and be more efficient.
* docs/schemas/domaincommon.rng: Limit valid model names to match code.
Based on a patch by Michael Ellerman.

docs/schemas/domaincommon.rng
src/conf/domain_conf.c

index b8fbcf9d661d2cc7a38265e3a65a0dda2a43c18e..27ec1da66dff5c87800901cfe132a2255706ccec 100644 (file)
       </optional>
       <optional>
         <element name="model">
-          <attribute name="type"/>
+          <attribute name="type">
+            <data type="string">
+              <param name='pattern'>[a-zA-Z0-9\-_]+</param>
+            </data>
+          </attribute>
           <empty/>
         </element>
       </optional>
index 75e51a06a2acc24734ebfef00fe5a294fd634133..d68ab10d0d651b53cbcc6f6226f4e5530c65861f 100644 (file)
@@ -3385,6 +3385,9 @@ error:
     return ret;
 }
 
+#define NET_MODEL_CHARS \
+    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ091234567890_-"
+
 /* Parse the XML definition for a network interface
  * @param node XML nodeset to parse for net definition
  * @return 0 on success, -1 on failure
@@ -3699,16 +3702,13 @@ virDomainNetDefParseXML(virCapsPtr caps,
      * reasonable, not that it is a supported NIC type.  FWIW kvm
      * supports these types as of April 2008:
      * i82551 i82557b i82559er ne2k_pci pcnet rtl8139 e1000 virtio
+     * QEMU PPC64 supports spapr-vlan
      */
     if (model != NULL) {
-        int i;
-        for (i = 0 ; i < strlen(model) ; i++) {
-            int char_ok = c_isalnum(model[i]) || model[i] == '_';
-            if (!char_ok) {
-                virDomainReportError(VIR_ERR_INVALID_ARG, "%s",
-                                     _("Model name contains invalid characters"));
-                goto error;
-            }
+        if (strspn(model, NET_MODEL_CHARS) < strlen(model)) {
+            virDomainReportError(VIR_ERR_INVALID_ARG, "%s",
+                                 _("Model name contains invalid characters"));
+            goto error;
         }
         def->model = model;
         model = NULL;