diff mbox series

[v2,02/11] conf: net: Add wrapper functions for <model> value

Message ID 5dbfb14ad730b118fec14a0b2fbc9421e66d6190.1552492022.git.crobinso@redhat.com
State Accepted
Commit 6bf7c6769925a54bba42faedc119eeebfd248663
Headers show
Series conf: partial net model enum conversion | expand

Commit Message

Cole Robinson March 13, 2019, 3:51 p.m. UTC
To ease converting the net->model value to an enum, add
the wrapper functions:

virDomainNetGetModelString
virDomainNetSetModelString
virDomainNetStreqModelString
virDomainNetStrcaseeqModelString

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
 src/bhyve/bhyve_command.c       |  8 ++++----
 src/bhyve/bhyve_parse_command.c |  2 +-
 src/conf/domain_conf.c          | 36 ++++++++++++++++++++++++++++-----
 src/conf/domain_conf.h          |  7 +++++++
 src/libvirt_private.syms        |  4 ++++
 src/libxl/libxl_conf.c          |  8 ++++----
 src/qemu/qemu_command.c         | 15 +++++++-------
 src/qemu/qemu_domain.c          |  4 ++--
 src/qemu/qemu_domain_address.c  | 13 ++++++------
 src/qemu/qemu_driver.c          | 14 ++++++++++---
 src/qemu/qemu_hotplug.c         |  7 ++++---
 src/qemu/qemu_parse_command.c   |  5 +++--
 src/vbox/vbox_common.c          | 18 ++++++++---------
 src/vmx/vmx.c                   | 31 ++++++++++++++--------------
 src/vz/vz_driver.c              |  4 ++--
 src/vz/vz_sdk.c                 | 14 ++++++-------
 src/xenconfig/xen_common.c      | 21 ++++++++++---------
 src/xenconfig/xen_sxpr.c        | 21 ++++++++++---------
 18 files changed, 140 insertions(+), 92 deletions(-)

-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Comments

Michal Prívozník April 16, 2019, 3:27 p.m. UTC | #1
On 3/13/19 4:51 PM, Cole Robinson wrote:
> To ease converting the net->model value to an enum, add

> the wrapper functions:

> 

> virDomainNetGetModelString

> virDomainNetSetModelString

> virDomainNetStreqModelString

> virDomainNetStrcaseeqModelString

> 

> Signed-off-by: Cole Robinson <crobinso@redhat.com>

> ---

>   src/bhyve/bhyve_command.c       |  8 ++++----

>   src/bhyve/bhyve_parse_command.c |  2 +-

>   src/conf/domain_conf.c          | 36 ++++++++++++++++++++++++++++-----

>   src/conf/domain_conf.h          |  7 +++++++

>   src/libvirt_private.syms        |  4 ++++

>   src/libxl/libxl_conf.c          |  8 ++++----

>   src/qemu/qemu_command.c         | 15 +++++++-------

>   src/qemu/qemu_domain.c          |  4 ++--

>   src/qemu/qemu_domain_address.c  | 13 ++++++------

>   src/qemu/qemu_driver.c          | 14 ++++++++++---

>   src/qemu/qemu_hotplug.c         |  7 ++++---

>   src/qemu/qemu_parse_command.c   |  5 +++--

>   src/vbox/vbox_common.c          | 18 ++++++++---------

>   src/vmx/vmx.c                   | 31 ++++++++++++++--------------

>   src/vz/vz_driver.c              |  4 ++--

>   src/vz/vz_sdk.c                 | 14 ++++++-------

>   src/xenconfig/xen_common.c      | 21 ++++++++++---------

>   src/xenconfig/xen_sxpr.c        | 21 ++++++++++---------

>   18 files changed, 140 insertions(+), 92 deletions(-)


Missed aa-helper:

diff --git i/src/security/virt-aa-helper.c w/src/security/virt-aa-helper.c
index 989dcf1784..158b614757 100644
--- i/src/security/virt-aa-helper.c
+++ w/src/security/virt-aa-helper.c
@@ -1253,7 +1253,7 @@ get_files(vahControl * ctl)
     if (ctl->def->virtType == VIR_DOMAIN_VIRT_KVM) {
         for (i = 0; i < ctl->def->nnets; i++) {
             virDomainNetDefPtr net = ctl->def->nets[i];
-            if (net && net->model) {
+            if (net && virDomainNetGetModelString(net)) {
                 if (net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_QEMU)
                     continue;
                 if (!virDomainNetIsVirtioModel(net))

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox series

Patch

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 10340ee436..d3d790f6b6 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -57,16 +57,16 @@  bhyveBuildNetArgStr(virConnectPtr conn,
     int ret = -1;
     virDomainNetType actualType = virDomainNetGetActualType(net);
 
-    if (net->model == NULL) {
+    if (!virDomainNetGetModelString(net)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("NIC model must be specified"));
         return -1;
     }
 
-    if (STREQ(net->model, "virtio")) {
+    if (virDomainNetStreqModelString(net, "virtio")) {
         if (VIR_STRDUP(nic_model, "virtio-net") < 0)
             return -1;
-    } else if (STREQ(net->model, "e1000")) {
+    } else if (virDomainNetStreqModelString(net, "e1000")) {
         if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_NET_E1000) != 0) {
             if (VIR_STRDUP(nic_model, "e1000") < 0)
                 return -1;
@@ -79,7 +79,7 @@  bhyveBuildNetArgStr(virConnectPtr conn,
     } else {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("NIC model '%s' is not supported"),
-                       net->model);
+                       virDomainNetGetModelString(net));
         return -1;
     }
 
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index bd93070dfb..60eb4c5412 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -511,7 +511,7 @@  bhyveParsePCINet(virDomainDefPtr def,
     if (VIR_STRDUP(net->data.bridge.brname, "virbr0") < 0)
         goto error;
 
-    if (VIR_STRDUP(net->model, model) < 0)
+    if (virDomainNetSetModelString(net, model) < 0)
         goto error;
 
     net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 778c386ee2..d282b4d3ae 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -25282,9 +25282,9 @@  virDomainNetDefFormat(virBufferPtr buf,
             virBufferEscapeString(buf, " actual='%s'", def->ifname_guest_actual);
         virBufferAddLit(buf, "/>\n");
     }
-    if (def->model) {
+    if (virDomainNetGetModelString(def)) {
         virBufferEscapeString(buf, "<model type='%s'/>\n",
-                              def->model);
+                              virDomainNetGetModelString(def));
         if (virDomainNetIsVirtioModel(def)) {
             int rc = 0;
             VIR_AUTOFREE(char *) str = NULL;
@@ -29376,13 +29376,39 @@  virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface)
     return iface->trustGuestRxFilters == VIR_TRISTATE_BOOL_YES;
 }
 
+const char *
+virDomainNetGetModelString(const virDomainNetDef *net)
+{
+    return net->model;
+}
+
+int
+virDomainNetSetModelString(virDomainNetDefPtr net,
+                           const char *model)
+{
+    return VIR_STRDUP(net->model, model);
+}
+
+int
+virDomainNetStreqModelString(const virDomainNetDef *net,
+                             const char *model)
+{
+    return STREQ_NULLABLE(net->model, model);
+}
+
+int
+virDomainNetStrcaseeqModelString(const virDomainNetDef *net,
+                                 const char *model)
+{
+    return net->model && STRCASEEQ(net->model, model);
+}
 
 bool
 virDomainNetIsVirtioModel(const virDomainNetDef *net)
 {
-    return (STREQ_NULLABLE(net->model, "virtio") ||
-            STREQ_NULLABLE(net->model, "virtio-transitional") ||
-            STREQ_NULLABLE(net->model, "virtio-non-transitional"));
+    return (virDomainNetStreqModelString(net, "virtio") ||
+            virDomainNetStreqModelString(net, "virtio-transitional") ||
+            virDomainNetStreqModelString(net, "virtio-non-transitional"));
 }
 
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fe9d4fb81a..39618928f7 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3314,6 +3314,13 @@  virNetDevBandwidthPtr
 virDomainNetGetActualBandwidth(virDomainNetDefPtr iface);
 virNetDevVlanPtr virDomainNetGetActualVlan(virDomainNetDefPtr iface);
 bool virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface);
+const char *virDomainNetGetModelString(const virDomainNetDef *net);
+int virDomainNetSetModelString(virDomainNetDefPtr et,
+                               const char *model);
+int virDomainNetStreqModelString(const virDomainNetDef *net,
+                                 const char *model);
+int virDomainNetStrcaseeqModelString(const virDomainNetDef *net,
+                                     const char *model);
 bool virDomainNetIsVirtioModel(const virDomainNetDef *net);
 int virDomainNetAppendIPAddress(virDomainNetDefPtr def,
                                 const char *address,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 960a97cf1d..a01f158946 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -474,6 +474,7 @@  virDomainNetGetActualTrustGuestRxFilters;
 virDomainNetGetActualType;
 virDomainNetGetActualVirtPortProfile;
 virDomainNetGetActualVlan;
+virDomainNetGetModelString;
 virDomainNetInsert;
 virDomainNetIsVirtioModel;
 virDomainNetNotifyActualDevice;
@@ -482,6 +483,9 @@  virDomainNetRemove;
 virDomainNetRemoveHostdev;
 virDomainNetResolveActualType;
 virDomainNetSetDeviceImpl;
+virDomainNetSetModelString;
+virDomainNetStrcaseeqModelString;
+virDomainNetStreqModelString;
 virDomainNetTypeFromString;
 virDomainNetTypeSharesHostView;
 virDomainNetTypeToString;
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index c769050ff1..9236820bfe 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1266,18 +1266,18 @@  libxlMakeNic(virDomainDefPtr def,
      * xen commit 32e9d0f ("libxl: nic type defaults to vif in hotplug for
      * hvm guest").
      */
-    if (l_nic->model) {
+    if (virDomainNetGetModelString(l_nic)) {
         if ((def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
             def->os.type == VIR_DOMAIN_OSTYPE_XENPVH) &&
-            STRNEQ(l_nic->model, "netfront")) {
+            !virDomainNetStreqModelString(l_nic, "netfront")) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("only model 'netfront' is supported for "
                              "Xen PV(H) domains"));
             return -1;
         }
-        if (VIR_STRDUP(x_nic->model, l_nic->model) < 0)
+        if (VIR_STRDUP(x_nic->model, virDomainNetGetModelString(l_nic)) < 0)
             goto cleanup;
-        if (STREQ(l_nic->model, "netfront"))
+        if (virDomainNetStreqModelString(l_nic, "netfront"))
             x_nic->nictype = LIBXL_NIC_TYPE_VIF;
         else
             x_nic->nictype = LIBXL_NIC_TYPE_VIF_IOEMU;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 5e56447b76..0388ebc5af 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -479,10 +479,10 @@  qemuBuildVirtioDevStr(virBufferPtr buf,
             break;
 
         case VIR_DOMAIN_DEVICE_NET:
-            has_tmodel = STREQ_NULLABLE(device.data.net->model,
-                                        "virtio-transitional");
-            has_ntmodel = STREQ_NULLABLE(device.data.net->model,
-                                         "virtio-non-transitional");
+            has_tmodel = virDomainNetStreqModelString(device.data.net,
+                                                      "virtio-transitional");
+            has_ntmodel = virDomainNetStreqModelString(device.data.net,
+                                                       "virtio-non-transitional");
             break;
 
         case VIR_DOMAIN_DEVICE_HOSTDEV:
@@ -3842,13 +3842,14 @@  qemuBuildLegacyNicStr(virDomainNetDefPtr net)
 {
     char *str;
     char macaddr[VIR_MAC_STRING_BUFLEN];
+    const char *netmodel = virDomainNetGetModelString(net);
 
     ignore_value(virAsprintf(&str,
                              "nic,macaddr=%s,netdev=host%s%s%s%s%s",
                              virMacAddrFormat(&net->mac, macaddr),
                              net->info.alias,
-                             (net->model ? ",model=" : ""),
-                             NULLSTR_EMPTY(net->model),
+                             netmodel ? ",model=" : "",
+                             NULLSTR_EMPTY(netmodel),
                              (net->info.alias ? ",id=" : ""),
                              NULLSTR_EMPTY(net->info.alias)));
     return str;
@@ -3874,7 +3875,7 @@  qemuBuildNicDevStr(virDomainDefPtr def,
 
         usingVirtio = true;
     } else {
-        virBufferAddStr(&buf, net->model);
+        virBufferAddStr(&buf, virDomainNetGetModelString(net));
     }
 
     if (usingVirtio && net->driver.virtio.txmode) {
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 788c19c248..7b001bca52 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6727,8 +6727,8 @@  qemuDomainDeviceNetDefPostParse(virDomainNetDefPtr net,
                                 virQEMUCapsPtr qemuCaps)
 {
     if (net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
-        !net->model) {
-        if (VIR_STRDUP(net->model,
+        !virDomainNetGetModelString(net)) {
+        if (virDomainNetSetModelString(net,
                        qemuDomainDefaultNetModel(def, qemuCaps)) < 0)
             return -1;
     }
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 4740536d82..380c5bffcc 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -230,7 +230,7 @@  qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def)
     for (i = 0; i < def->nnets; i++) {
         virDomainNetDefPtr net = def->nets[i];
 
-        if (STREQ_NULLABLE(net->model, "spapr-vlan"))
+        if (virDomainNetStreqModelString(net, "spapr-vlan"))
             net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO;
 
         if (qemuDomainAssignSpaprVIOAddress(def, &net->info, VIO_ADDR_NET) < 0)
@@ -715,19 +715,18 @@  qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
          * addresses for other hostdev devices.
          */
         if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV ||
-            STREQ_NULLABLE(net->model, "usb-net")) {
+            virDomainNetStreqModelString(net, "usb-net")) {
             return 0;
         }
 
-        if (STREQ_NULLABLE(net->model, "virtio") ||
-            STREQ_NULLABLE(net->model, "virtio-non-transitional"))
+        if (virDomainNetStreqModelString(net, "virtio") ||
+            virDomainNetStreqModelString(net, "virtio-non-transitional"))
             return virtioFlags;
 
-        /* Transitional devices only work in conventional PCI slots */
-        if (STREQ_NULLABLE(net->model, "virtio-transitional"))
+        if (virDomainNetStreqModelString(net, "virtio-transitional"))
             return pciFlags;
 
-        if (STREQ_NULLABLE(net->model, "e1000e"))
+        if (virDomainNetStreqModelString(net, "e1000e"))
             return pcieFlags;
 
         return pciFlags;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e461fb51b0..a3d52a5dc0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7444,20 +7444,28 @@  static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
     for (i = 0; i < vm->def->nnets; i++) {
         virDomainNetDefPtr net = vm->def->nets[i];
         unsigned int bootIndex = net->info.bootIndex;
-        char *model = net->model;
+        char *model;
         virMacAddr mac = net->mac;
         char *script = net->script;
 
-        net->model = NULL;
+        if (virDomainNetGetModelString(net) &&
+            VIR_STRDUP(model, virDomainNetGetModelString(net)) < 0)
+            goto cleanup;
+
         net->script = NULL;
 
         virDomainNetDefClear(net);
 
         net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
         net->info.bootIndex = bootIndex;
-        net->model = model;
         net->mac = mac;
         net->script = script;
+
+        if (model && virDomainNetSetModelString(net, model) < 0) {
+            VIR_FREE(model);
+            goto cleanup;
+        }
+        VIR_FREE(model);
     }
 
     if (!(cmd = qemuProcessCreatePretendCmd(driver, vm, NULL,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f43f80668c..872d8e2a6f 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3692,11 +3692,12 @@  qemuDomainChangeNet(virQEMUDriverPtr driver,
         goto cleanup;
     }
 
-    if (STRNEQ_NULLABLE(olddev->model, newdev->model)) {
+    if (STRNEQ_NULLABLE(virDomainNetGetModelString(olddev),
+                        virDomainNetGetModelString(newdev))) {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
                        _("cannot modify network device model from %s to %s"),
-                       olddev->model ? olddev->model : "(default)",
-                       newdev->model ? newdev->model : "(default)");
+                       NULLSTR(virDomainNetGetModelString(olddev)),
+                       NULLSTR(virDomainNetGetModelString(newdev)));
         goto cleanup;
     }
 
diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c
index 49b34b1c17..fc3f70fcde 100644
--- a/src/qemu/qemu_parse_command.c
+++ b/src/qemu/qemu_parse_command.c
@@ -1109,8 +1109,9 @@  qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt,
                 goto error;
             }
         } else if (STREQ(keywords[i], "model")) {
-            def->model = values[i];
-            values[i] = NULL;
+            if (virDomainNetSetModelString(def, values[i]) < 0)
+                goto error;
+            VIR_FREE(values[i]);
         } else if (STREQ(keywords[i], "vhost")) {
             if ((values[i] == NULL) || STREQ(values[i], "on")) {
                 def->driver.virtio.name = VIR_DOMAIN_NET_BACKEND_TYPE_VHOST;
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index c410514d37..8c28bba8ee 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1309,7 +1309,7 @@  vboxAttachNetwork(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
         macaddrvbox[VIR_MAC_STRING_BUFLEN - 6] = '\0';
 
         VIR_DEBUG("NIC(%zu): Type:   %d", i, def->nets[i]->type);
-        VIR_DEBUG("NIC(%zu): Model:  %s", i, def->nets[i]->model);
+        VIR_DEBUG("NIC(%zu): Model:  %s", i, virDomainNetGetModelString(def->nets[i]));
         VIR_DEBUG("NIC(%zu): Mac:    %s", i, macaddr);
         VIR_DEBUG("NIC(%zu): ifname: %s", i, def->nets[i]->ifname);
         if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
@@ -1338,19 +1338,19 @@  vboxAttachNetwork(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
 
         gVBoxAPI.UINetworkAdapter.SetEnabled(adapter, 1);
 
-        if (def->nets[i]->model) {
-            if (STRCASEEQ(def->nets[i]->model, "Am79C970A")) {
+        if (virDomainNetGetModelString(def->nets[i])) {
+            if (virDomainNetStrcaseeqModelString(def->nets[i], "Am79C970A")) {
                 adapterType = NetworkAdapterType_Am79C970A;
-            } else if (STRCASEEQ(def->nets[i]->model, "Am79C973")) {
+            } else if (virDomainNetStrcaseeqModelString(def->nets[i], "Am79C973")) {
                 adapterType = NetworkAdapterType_Am79C973;
-            } else if (STRCASEEQ(def->nets[i]->model, "82540EM")) {
+            } else if (virDomainNetStrcaseeqModelString(def->nets[i], "82540EM")) {
                 adapterType = NetworkAdapterType_I82540EM;
-            } else if (STRCASEEQ(def->nets[i]->model, "82545EM")) {
+            } else if (virDomainNetStrcaseeqModelString(def->nets[i], "82545EM")) {
                 adapterType = NetworkAdapterType_I82545EM;
-            } else if (STRCASEEQ(def->nets[i]->model, "82543GC")) {
+            } else if (virDomainNetStrcaseeqModelString(def->nets[i], "82543GC")) {
                 adapterType = NetworkAdapterType_I82543GC;
             } else if (gVBoxAPI.APIVersion >= 3000051 &&
-                       STRCASEEQ(def->nets[i]->model, "virtio")) {
+                       virDomainNetStrcaseeqModelString(def->nets[i], "virtio")) {
                 /* Only vbox 3.1 and later support NetworkAdapterType_Virto */
                 adapterType = NetworkAdapterType_Virtio;
             }
@@ -3762,7 +3762,7 @@  vboxDumpNetwork(vboxDriverPtr data, INetworkAdapter *adapter)
             model = "virtio";
         break;
     }
-    if (VIR_STRDUP(net->model, model) < 0)
+    if (virDomainNetSetModelString(net, model) < 0)
         goto error;
 
     gVBoxAPI.UINetworkAdapter.GetMACAddress(adapter, &utf16);
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 8ffd5ff088..7a557847ba 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -2671,10 +2671,8 @@  virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
     /* Setup virDomainNetDef */
     if (connectionType == NULL || STRCASEEQ(connectionType, "bridged")) {
         (*def)->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
-        (*def)->model = virtualDev;
         (*def)->data.bridge.brname = networkName;
 
-        virtualDev = NULL;
         networkName = NULL;
     } else if (STRCASEEQ(connectionType, "hostonly")) {
         /* FIXME */
@@ -2684,16 +2682,12 @@  virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
         goto cleanup;
     } else if (STRCASEEQ(connectionType, "nat")) {
         (*def)->type = VIR_DOMAIN_NET_TYPE_USER;
-        (*def)->model = virtualDev;
 
-        virtualDev = NULL;
     } else if (STRCASEEQ(connectionType, "custom")) {
         (*def)->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
-        (*def)->model = virtualDev;
         (*def)->data.bridge.brname = networkName;
         (*def)->ifname = vnet;
 
-        virtualDev = NULL;
         networkName = NULL;
         vnet = NULL;
     } else {
@@ -2703,6 +2697,10 @@  virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
         goto cleanup;
     }
 
+    if (virDomainNetSetModelString((*def), virtualDev) < 0)
+        goto cleanup;
+    VIR_FREE(virtualDev);
+
     result = 0;
 
  cleanup:
@@ -3740,28 +3738,29 @@  virVMXFormatEthernet(virDomainNetDefPtr def, int controller,
     virBufferAsprintf(buffer, "ethernet%d.present = \"true\"\n", controller);
 
     /* def:model -> vmx:virtualDev, vmx:features */
-    if (def->model != NULL) {
-        if (STRCASENEQ(def->model, "vlance") &&
-            STRCASENEQ(def->model, "vmxnet") &&
-            STRCASENEQ(def->model, "vmxnet2") &&
-            STRCASENEQ(def->model, "vmxnet3") &&
-            STRCASENEQ(def->model, "e1000") &&
-            STRCASENEQ(def->model, "e1000e")) {
+    if (virDomainNetGetModelString(def)) {
+        if (!virDomainNetStrcaseeqModelString(def, "vlance") &&
+            !virDomainNetStrcaseeqModelString(def, "vmxnet") &&
+            !virDomainNetStrcaseeqModelString(def, "vmxnet2") &&
+            !virDomainNetStrcaseeqModelString(def, "vmxnet3") &&
+            !virDomainNetStrcaseeqModelString(def, "e1000") &&
+            !virDomainNetStrcaseeqModelString(def, "e1000e")) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Expecting domain XML entry 'devices/interface/model' "
                              "to be 'vlance' or 'vmxnet' or 'vmxnet2' or 'vmxnet3' "
-                             "or 'e1000' or 'e1000e' but found '%s'"), def->model);
+                             "or 'e1000' or 'e1000e' but found '%s'"),
+                            virDomainNetGetModelString(def));
             return -1;
         }
 
-        if (STRCASEEQ(def->model, "vmxnet2")) {
+        if (virDomainNetStrcaseeqModelString(def, "vmxnet2")) {
             virBufferAsprintf(buffer, "ethernet%d.virtualDev = \"vmxnet\"\n",
                               controller);
             virBufferAsprintf(buffer, "ethernet%d.features = \"15\"\n",
                               controller);
         } else {
             virBufferAsprintf(buffer, "ethernet%d.virtualDev = \"%s\"\n",
-                              controller, def->model);
+                              controller, virDomainNetGetModelString(def));
         }
     }
 
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 066d617524..66d019378f 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -265,9 +265,9 @@  vzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
     if (dev->type == VIR_DOMAIN_DEVICE_NET &&
         (dev->data.net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
          dev->data.net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
-        !dev->data.net->model &&
+        !virDomainNetGetModelString(dev->data.net) &&
         def->os.type == VIR_DOMAIN_OSTYPE_HVM &&
-        VIR_STRDUP(dev->data.net->model, "e1000") < 0)
+        virDomainNetSetModelString(dev->data.net, "e1000") < 0)
         return -1;
 
     return 0;
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index b9fd03c0d2..ed8345a874 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -1104,15 +1104,15 @@  prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt)
 
         switch ((int)type) {
         case PNT_RTL:
-            if (VIR_STRDUP(net->model, "rtl8139") < 0)
+            if (virDomainNetSetModelString(net, "rtl8139") < 0)
                 goto cleanup;
             break;
         case PNT_E1000:
-            if (VIR_STRDUP(net->model, "e1000") < 0)
+            if (virDomainNetSetModelString(net, "e1000") < 0)
                 goto cleanup;
             break;
         case PNT_VIRTIO:
-            if (VIR_STRDUP(net->model, "virtio") < 0)
+            if (virDomainNetSetModelString(net, "virtio") < 0)
                 goto cleanup;
             break;
         default:
@@ -3377,15 +3377,15 @@  static int prlsdkConfigureNet(vzDriverPtr driver ATTRIBUTE_UNUSED,
         goto cleanup;
 
     if (isCt) {
-        if (net->model)
+        if (virDomainNetGetModelString(net))
             VIR_WARN("Setting network adapter for containers is not "
                      "supported by vz driver.");
     } else {
-        if (STREQ(net->model, "rtl8139")) {
+        if (virDomainNetStreqModelString(net, "rtl8139")) {
             pret = PrlVmDevNet_SetAdapterType(sdknet, PNT_RTL);
-        } else if (STREQ(net->model, "e1000")) {
+        } else if (virDomainNetStreqModelString(net, "e1000")) {
             pret = PrlVmDevNet_SetAdapterType(sdknet, PNT_E1000);
-        } else if (STREQ(net->model, "virtio")) {
+        } else if (virDomainNetStreqModelString(net, "virtio")) {
             pret = PrlVmDevNet_SetAdapterType(sdknet, PNT_VIRTIO);
         } else {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 21c56edd58..170378fab5 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -1069,11 +1069,11 @@  xenParseVif(char *entry, const char *vif_typename)
         goto cleanup;
 
     if (model[0] &&
-        VIR_STRDUP(net->model, model) < 0)
+        virDomainNetSetModelString(net, model) < 0)
         goto cleanup;
 
     if (!model[0] && type[0] && STREQ(type, vif_typename) &&
-        VIR_STRDUP(net->model, "netfront") < 0)
+        virDomainNetSetModelString(net, "netfront") < 0)
         goto cleanup;
 
     if (vifname[0] &&
@@ -1422,15 +1422,16 @@  xenFormatNet(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (!hvm) {
-        if (net->model != NULL)
-            virBufferAsprintf(&buf, ",model=%s", net->model);
-    } else {
-        if (net->model != NULL && STREQ(net->model, "netfront")) {
-            virBufferAsprintf(&buf, ",type=%s", vif_typename);
+    if (virDomainNetGetModelString(net)) {
+        if (!hvm) {
+            virBufferAsprintf(&buf, ",model=%s",
+                              virDomainNetGetModelString(net));
         } else {
-            if (net->model != NULL)
-                virBufferAsprintf(&buf, ",model=%s", net->model);
+            if (virDomainNetStreqModelString(net, "netfront"))
+                virBufferAsprintf(&buf, ",type=%s", vif_typename);
+            else
+                virBufferAsprintf(&buf, ",model=%s",
+                                  virDomainNetGetModelString(net));
         }
     }
 
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index eb535cde19..224c874b90 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -642,11 +642,11 @@  xenParseSxprNets(virDomainDefPtr def,
                 }
             }
 
-            if (VIR_STRDUP(net->model, model) < 0)
+            if (virDomainNetSetModelString(net, model) < 0)
                 goto cleanup;
 
             if (!model && type && STREQ(type, "netfront") &&
-                VIR_STRDUP(net->model, "netfront") < 0)
+                virDomainNetSetModelString(net, "netfront") < 0)
                 goto cleanup;
 
             tmp = sexpr_node(node, "device/vif/rate");
@@ -1929,15 +1929,16 @@  xenFormatSxprNet(virConnectPtr conn,
         !STRPREFIX(def->ifname, "vif"))
         virBufferEscapeSexpr(buf, "(vifname '%s')", def->ifname);
 
-    if (!hvm) {
-        if (def->model != NULL)
-            virBufferEscapeSexpr(buf, "(model '%s')", def->model);
-    } else {
-        if (def->model != NULL && STREQ(def->model, "netfront")) {
-            virBufferAddLit(buf, "(type netfront)");
+    if (virDomainNetGetModelString(def)) {
+        if (!hvm) {
+            virBufferEscapeSexpr(buf, "(model '%s')",
+                                 virDomainNetGetModelString(def));
         } else {
-            if (def->model != NULL)
-                virBufferEscapeSexpr(buf, "(model '%s')", def->model);
+            if (virDomainNetStreqModelString(def, "netfront"))
+                virBufferAddLit(buf, "(type netfront)");
+            else
+                virBufferEscapeSexpr(buf, "(model '%s')",
+                                     virDomainNetGetModelString(def));
         }
     }