]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: add MTU arg to virNetDevTapCreateInBridgePort()
authorLaine Stump <laine@laine.org>
Mon, 23 Jan 2017 01:41:03 +0000 (20:41 -0500)
committerLaine Stump <laine@laine.org>
Tue, 7 Feb 2017 18:45:08 +0000 (13:45 -0500)
virNetDevTapCreateInBridgePort() has always set the new tap device to
the current MTU of the bridge it's being attached to. There is one
case where we will want to set the new tap device to a different
(usually larger) MTU - if that's done with the very first device added
to the bridge, the bridge's MTU will be set to the device's MTU. This
patch allows for that possibility by adding "int mtu" to the arg list
for virNetDevTapCreateInBridgePort(), but all callers are sending -1,
so it doesn't yet have any effect.

Since the requested MTU isn't necessarily what is used in the end (for
example, if there is no MTU requested, the tap device will be set to
the current MTU of the bridge), and the hypervisor may want to know
the actual MTU used, we also return the actual MTU to the caller (if
actualMTU is non-NULL).

src/bhyve/bhyve_command.c
src/network/bridge_driver.c
src/qemu/qemu_interface.c
src/uml/uml_conf.c
src/util/virnetdevtap.c
src/util/virnetdevtap.h
tests/bhyvexml2argvmock.c

index a50bd106604f7fe9957c6f56b3d558c16c0d9817..192a9220c13c0ab2347c203cfe3d0fdbd1dc003b 100644 (file)
@@ -78,6 +78,7 @@ bhyveBuildNetArgStr(const virDomainDef *def,
                                            def->uuid, NULL, NULL, 0,
                                            virDomainNetGetActualVirtPortProfile(net),
                                            virDomainNetGetActualVlan(net),
+                                           0, NULL,
                                            VIR_NETDEV_TAP_CREATE_IFUP | VIR_NETDEV_TAP_CREATE_PERSIST) < 0) {
             goto cleanup;
         }
index 7d340eff024b18e068a22129772bd56bd001f6bc..f88c261ed84d6dab1416d044360b201bda2781ff 100644 (file)
@@ -2301,6 +2301,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
         if (virNetDevTapCreateInBridgePort(network->def->bridge,
                                            &macTapIfName, &network->def->mac,
                                            NULL, NULL, &tapfd, 1, NULL, NULL,
+                                           0, NULL,
                                            VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE |
                                            VIR_NETDEV_TAP_CREATE_IFUP |
                                            VIR_NETDEV_TAP_CREATE_PERSIST) < 0) {
index 455c2d05322f0dac0656455bb885e3b78392b592..ce448d24330279a2c9fd85a6f715cf665e6f595c 100644 (file)
@@ -544,6 +544,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
                                            def->uuid, tunpath, tapfd, *tapfdSize,
                                            virDomainNetGetActualVirtPortProfile(net),
                                            virDomainNetGetActualVlan(net),
+                                           0, NULL,
                                            tap_create_flags) < 0) {
             virDomainAuditNetDevice(def, net, tunpath, false);
             goto cleanup;
index 6754d3c71ed6a8c31951437bcef5010e5f639fda..4663c7dee83aded318c27492a88cd29890cc2d66 100644 (file)
@@ -126,6 +126,7 @@ umlConnectTapDevice(virDomainDefPtr vm,
                                        vm->uuid, net->backend.tap, &tapfd, 1,
                                        virDomainNetGetActualVirtPortProfile(net),
                                        virDomainNetGetActualVlan(net),
+                                       0, NULL,
                                        VIR_NETDEV_TAP_CREATE_IFUP |
                                        VIR_NETDEV_TAP_CREATE_PERSIST) < 0) {
         if (template_ifname)
index 85c0045ea87b34e245a535377b86760b6eaa3d6e..41e68f4a69c493638ee0f970a457b6d18ff7a463 100644 (file)
@@ -513,6 +513,8 @@ int virNetDevTapDelete(const char *ifname ATTRIBUTE_UNUSED,
  * @tapfd: array of file descriptor return value for the new tap device
  * @tapfdSize: number of file descriptors in @tapfd
  * @virtPortProfile: bridge/port specific configuration
+ * @mtu: requested MTU for port (or 0 for "default")
+ * @actualMTU: MTU actually set for port (after accounting for bridge's MTU)
  * @flags: OR of virNetDevTapCreateFlags:
 
  *   VIR_NETDEV_TAP_CREATE_IFUP
@@ -543,6 +545,8 @@ int virNetDevTapCreateInBridgePort(const char *brname,
                                    size_t tapfdSize,
                                    virNetDevVPortProfilePtr virtPortProfile,
                                    virNetDevVlanPtr virtVlan,
+                                   unsigned int mtu,
+                                   unsigned int *actualMTU,
                                    unsigned int flags)
 {
     virMacAddr tapmac;
@@ -578,12 +582,30 @@ int virNetDevTapCreateInBridgePort(const char *brname,
     if (virNetDevSetMAC(*ifname, &tapmac) < 0)
         goto error;
 
-    /* We need to set the interface MTU before adding it
-     * to the bridge, because the bridge will have its
-     * MTU adjusted automatically when we add the new interface.
+    /* If an MTU is specified for the new device, set it before
+     * attaching the device to the bridge, as it may affect the MTU of
+     * the bridge (in particular if it is the first device attached to
+     * the bridge, or if it is smaller than the current MTU of the
+     * bridge). If MTU isn't specified for the new device (i.e. 0),
+     * we need to set the interface MTU to the current MTU of the
+     * bridge (to avoid inadvertantly changing the bridge's MTU).
      */
-    if (virNetDevSetMTUFromDevice(*ifname, brname) < 0)
-        goto error;
+    if (mtu > 0) {
+        if (virNetDevSetMTU(*ifname, mtu) < 0)
+            goto error;
+    } else {
+        if (virNetDevSetMTUFromDevice(*ifname, brname) < 0)
+            goto error;
+    }
+    if (actualMTU) {
+        int retMTU = virNetDevGetMTU(*ifname);
+
+        if (retMTU < 0)
+            goto error;
+
+        *actualMTU = retMTU;
+    }
+
 
     if (virtPortProfile) {
         if (virtPortProfile->virtPortType == VIR_NETDEV_VPORT_PROFILE_MIDONET) {
index 259e7c9c2024890ff7468105fa1e28169d7e9921..6441df49150045c4da9ba924bb369f8f7c91ca9b 100644 (file)
@@ -71,6 +71,8 @@ int virNetDevTapCreateInBridgePort(const char *brname,
                                    size_t tapfdSize,
                                    virNetDevVPortProfilePtr virtPortProfile,
                                    virNetDevVlanPtr virtVlan,
+                                   unsigned int mtu,
+                                   unsigned int *actualMTU,
                                    unsigned int flags)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
     ATTRIBUTE_RETURN_CHECK;
index a8516327c2a84770c49750852b50b3a323f227cc..fd714694f0bde305addb881862d259ff8ce7be6b 100644 (file)
@@ -28,6 +28,8 @@ int virNetDevTapCreateInBridgePort(const char *brname ATTRIBUTE_UNUSED,
                                    size_t tapfdSize ATTRIBUTE_UNUSED,
                                    virNetDevVPortProfilePtr virtPortProfile ATTRIBUTE_UNUSED,
                                    virNetDevVlanPtr virtVlan ATTRIBUTE_UNUSED,
+                                   unsigned int mtu ATTRIBUTE_UNUSED,
+                                   unsigned int *actualMTU ATTRIBUTE_UNUSED,
                                    unsigned int fakeflags ATTRIBUTE_UNUSED)
 {
     VIR_FREE(*ifname);