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.
---
src/bhyve/bhyve_command.c | 2 +-
src/network/bridge_driver.c | 2 +-
src/qemu/qemu_interface.c | 2 +-
src/uml/uml_conf.c | 2 +-
src/util/virnetdevtap.c | 20 +++++++++++++++-----
src/util/virnetdevtap.h | 1 +
tests/bhyvexml2argvmock.c | 1 +
7 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 8a29977..0e5d5db 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -77,7 +77,7 @@ bhyveBuildNetArgStr(const virDomainDef *def,
if (virNetDevTapCreateInBridgePort(brname, &net->ifname,
&net->mac,
def->uuid, NULL, NULL, 0,
virDomainNetGetActualVirtPortProfile(net),
- virDomainNetGetActualVlan(net),
+ virDomainNetGetActualVlan(net), -1,
VIR_NETDEV_TAP_CREATE_IFUP |
VIR_NETDEV_TAP_CREATE_PERSIST) < 0) {
goto cleanup;
}
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 7d340ef..7a7bdaf 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2300,7 +2300,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
/* Keep tun fd open and interface up to allow for IPv6 DAD to happen */
if (virNetDevTapCreateInBridgePort(network->def->bridge,
&macTapIfName,
&network->def->mac,
- NULL, NULL, &tapfd, 1, NULL, NULL,
+ NULL, NULL, &tapfd, 1, NULL, NULL, -1,
VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE |
VIR_NETDEV_TAP_CREATE_IFUP |
VIR_NETDEV_TAP_CREATE_PERSIST) < 0) {
diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
index 455c2d0..2313de4 100644
--- a/src/qemu/qemu_interface.c
+++ b/src/qemu/qemu_interface.c
@@ -543,7 +543,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
if (virNetDevTapCreateInBridgePort(brname, &net->ifname,
&net->mac,
def->uuid, tunpath, tapfd, *tapfdSize,
virDomainNetGetActualVirtPortProfile(net),
- virDomainNetGetActualVlan(net),
+ virDomainNetGetActualVlan(net), -1,
tap_create_flags) < 0) {
virDomainAuditNetDevice(def, net, tunpath, false);
goto cleanup;
diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c
index 6754d3c..e98973e 100644
--- a/src/uml/uml_conf.c
+++ b/src/uml/uml_conf.c
@@ -125,7 +125,7 @@ umlConnectTapDevice(virDomainDefPtr vm,
if (virNetDevTapCreateInBridgePort(bridge, &net->ifname, &net->mac,
vm->uuid, net->backend.tap, &tapfd, 1,
virDomainNetGetActualVirtPortProfile(net),
- virDomainNetGetActualVlan(net),
+ virDomainNetGetActualVlan(net), -1,
VIR_NETDEV_TAP_CREATE_IFUP |
VIR_NETDEV_TAP_CREATE_PERSIST) < 0) {
if (template_ifname)
diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
index 85c0045..2827cde 100644
--- a/src/util/virnetdevtap.c
+++ b/src/util/virnetdevtap.c
@@ -543,6 +543,7 @@ int virNetDevTapCreateInBridgePort(const char *brname,
size_t tapfdSize,
virNetDevVPortProfilePtr virtPortProfile,
virNetDevVlanPtr virtVlan,
+ int mtu,
unsigned int flags)
{
virMacAddr tapmac;
@@ -578,12 +579,21 @@ 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
+ * bridgeg). If MTU isn't specified for the new device, 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 (virtPortProfile) {
if (virtPortProfile->virtPortType == VIR_NETDEV_VPORT_PROFILE_MIDONET) {
diff --git a/src/util/virnetdevtap.h b/src/util/virnetdevtap.h
index 259e7c9..8fe7fa1 100644
--- a/src/util/virnetdevtap.h
+++ b/src/util/virnetdevtap.h
@@ -71,6 +71,7 @@ int virNetDevTapCreateInBridgePort(const char *brname,
size_t tapfdSize,
virNetDevVPortProfilePtr virtPortProfile,
virNetDevVlanPtr virtVlan,
+ int mtu,
unsigned int flags)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
ATTRIBUTE_RETURN_CHECK;
diff --git a/tests/bhyvexml2argvmock.c b/tests/bhyvexml2argvmock.c
index a851632..a1080c0 100644
--- a/tests/bhyvexml2argvmock.c
+++ b/tests/bhyvexml2argvmock.c
@@ -28,6 +28,7 @@ int virNetDevTapCreateInBridgePort(const char *brname ATTRIBUTE_UNUSED,
size_t tapfdSize ATTRIBUTE_UNUSED,
virNetDevVPortProfilePtr virtPortProfile
ATTRIBUTE_UNUSED,
virNetDevVlanPtr virtVlan ATTRIBUTE_UNUSED,
+ int mtu ATTRIBUTE_UNUSED,
unsigned int fakeflags ATTRIBUTE_UNUSED)
{
VIR_FREE(*ifname);
--
2.9.3