From nobody Tue Feb 10 08:26:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1486143531621382.3707285451252; Fri, 3 Feb 2017 09:38:51 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v13HZY3k001192; Fri, 3 Feb 2017 12:35:35 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v13HZXvR004551 for ; Fri, 3 Feb 2017 12:35:33 -0500 Received: from vhost2.laine.org (ovpn-116-95.phx2.redhat.com [10.3.116.95]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v13HZVkh008983; Fri, 3 Feb 2017 12:35:33 -0500 From: Laine Stump To: libvir-list@redhat.com Date: Fri, 3 Feb 2017 12:35:24 -0500 Message-Id: <20170203173526.2494-3-laine@laine.org> In-Reply-To: <20170203173526.2494-1-laine@laine.org> References: <20170203173526.2494-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-loop: libvir-list@redhat.com Cc: Michal Privoznik Subject: [libvirt] [PATCH v2 2/4] conf: support configuring mtu size in a virtual network X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Example: ... ... If mtu is unset, it's assumed that we want the default for whatever is the underlying transport (usually this is 1500). This setting isn't yet wired in, so it will have no effect. This partially resolves: https://bugzilla.redhat.com/1224348 --- Change from V1: * switch from to for consistency and to allow for potentially setting an MTU on a network that doesn't have a element. * use Michal's mtu element definition from networkcommon.rng rather than rolling my own. docs/formatnetwork.html.in | 19 ++++++++++++++++++- docs/news.xml | 5 +++-- docs/schemas/network.rng | 5 +++++ src/conf/network_conf.c | 31 ++++++++++++++++++++++++++++++- src/conf/network_conf.h | 1 + tests/networkxml2xmlin/set-mtu.xml | 12 ++++++++++++ tests/networkxml2xmlout/set-mtu.xml | 12 ++++++++++++ tests/networkxml2xmltest.c | 1 + 8 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 tests/networkxml2xmlin/set-mtu.xml create mode 100644 tests/networkxml2xmlout/set-mtu.xml diff --git a/docs/formatnetwork.html.in b/docs/formatnetwork.html.in index 8638df9..777c341 100644 --- a/docs/formatnetwork.html.in +++ b/docs/formatnetwork.html.in @@ -93,6 +93,7 @@
 ...
 <bridge name=3D"virbr0" stp=3D"on" delay=3D"5" macTableManager=3D"libvi=
rt"/>
+<mtu size=3D"9000"/>
 <domain name=3D"example.com" localOnly=3D"no"/>
 <forward mode=3D"nat" dev=3D"eth0"/>
 ...
@@ -151,9 +152,25 @@ Since 1.2.11, requires kernel 3.17 or newer

+ =20 - +
mtu
+
+ The size attribute of the mtu> + element specifies the Maximum Transmission Unit (MTU) for the + network. Since 3.1.0. In the case + of a libvirt-managed network (one with forward mode + of nat, route, open, or + no forward element (i.e. an isolated network), + this will be the MTU assigned to the bridge device when + libvirt creates it, and thereafter also assigned to all tap + devices created to connect guest interfaces. Network types not + specifically mentioned here don't support having an MTU set in + the libvirt network config. If mtu size is unspecified, the + default setting for the type of device being used is assumed + (usually 1500).
+
domain
The name attribute on the domain diff --git a/docs/news.xml b/docs/news.xml index f408293..8f0d3d6 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -36,10 +36,11 @@ - Introduce MTU to domain <interface/> + Introduce MTU to domain <interface/> and <network> - Allow setting MTU size for some types of domain interface. + Allow setting MTU size for some types of domain interface + and network. diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng index 8f0a61b..1048dab 100644 --- a/docs/schemas/network.rng +++ b/docs/schemas/network.rng @@ -79,6 +79,11 @@ =20 + + + + + diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 86ce311..0e20dac 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2242,6 +2242,17 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) def->mac_specified =3D true; } =20 + tmp =3D virXPathString("string(./mtu/@size)", ctxt); + if (tmp) { + if (virStrToLong_ui(tmp, NULL, 10, &def->mtu) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid mtu size '%s' in network '%s'"), + tmp, def->name); + goto error; + } + } + VIR_FREE(tmp); + dnsNode =3D virXPathNode("./dns", ctxt); if (dnsNode !=3D NULL && virNetworkDNSDefParseXML(def->name, dnsNode, ctxt, &def->dns) < 0)= { @@ -2435,7 +2446,9 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) case VIR_NETWORK_FORWARD_BRIDGE: if (def->delay || stp) { virReportError(VIR_ERR_XML_ERROR, - _("bridge delay/stp options only allowed in rou= te, nat, and isolated mode, not in %s (network '%s')"), + _("bridge delay/stp options only allowed in " + "route, nat, and isolated mode, not in %s " + "(network '%s')"), virNetworkForwardTypeToString(def->forward.type= ), def->name); goto error; @@ -2454,6 +2467,19 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) =20 VIR_FREE(stp); =20 + if (def->mtu && + (def->forward.type !=3D VIR_NETWORK_FORWARD_NONE && + def->forward.type !=3D VIR_NETWORK_FORWARD_NAT && + def->forward.type !=3D VIR_NETWORK_FORWARD_ROUTE && + def->forward.type !=3D VIR_NETWORK_FORWARD_OPEN)) { + virReportError(VIR_ERR_XML_ERROR, + _("mtu size only allowed in open, route, nat, " + "and isolated mode, not in %s (network '%s')"), + virNetworkForwardTypeToString(def->forward.type), + def->name); + goto error; + } + /* Extract custom metadata */ if ((metadataNode =3D virXPathNode("./metadata[1]", ctxt)) !=3D NULL) { def->metadata =3D xmlCopyNode(metadataNode, 1); @@ -2964,6 +2990,9 @@ virNetworkDefFormatBuf(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } =20 + if (def->mtu) + virBufferAsprintf(buf, "\n", def->mtu); + if (def->mac_specified) { char macaddr[VIR_MAC_STRING_BUFLEN]; virMacAddrFormat(&def->mac, macaddr); diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index b5c9ea2..9e4ae71 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -240,6 +240,7 @@ struct _virNetworkDef { int domainLocalOnly; /* enum virTristateBool: yes disables dns forward= ing */ unsigned long delay; /* Bridge forward delay (ms) */ bool stp; /* Spanning tree protocol */ + unsigned int mtu; /* MTU for bridge, 0 means "default" i.e. unset in c= onfig */ virMacAddr mac; /* mac address of bridge device */ bool mac_specified; =20 diff --git a/tests/networkxml2xmlin/set-mtu.xml b/tests/networkxml2xmlin/se= t-mtu.xml new file mode 100644 index 0000000..d1ef32a --- /dev/null +++ b/tests/networkxml2xmlin/set-mtu.xml @@ -0,0 +1,12 @@ + + private + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + + + + + + + + diff --git a/tests/networkxml2xmlout/set-mtu.xml b/tests/networkxml2xmlout/= set-mtu.xml new file mode 100644 index 0000000..10e8155 --- /dev/null +++ b/tests/networkxml2xmlout/set-mtu.xml @@ -0,0 +1,12 @@ + + private + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + + + + + + + + diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index 01cd6f7..cfaf718 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -158,6 +158,7 @@ mymain(void) DO_TEST_PARSE_ERROR("hostdev-duplicate"); DO_TEST_PARSE_ERROR("passthrough-duplicate"); DO_TEST("metadata"); + DO_TEST("set-mtu"); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list