]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: support configuring mtu size in a virtual network
authorLaine Stump <laine@laine.org>
Mon, 23 Jan 2017 02:23:48 +0000 (21:23 -0500)
committerLaine Stump <laine@laine.org>
Tue, 7 Feb 2017 18:52:06 +0000 (13:52 -0500)
Example:

  <network>
     ...
     <mtu size='9000'/>
     ...

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

docs/formatnetwork.html.in
docs/news.xml
docs/schemas/network.rng
src/conf/network_conf.c
src/conf/network_conf.h
tests/networkxml2xmlin/set-mtu.xml [new file with mode: 0644]
tests/networkxml2xmlout/set-mtu.xml [new file with mode: 0644]
tests/networkxml2xmltest.c

index 8638df96e73869322c78078ffa25ea3a1843b5f9..777c3419b3a260e73958b1730703d2ed952416ca 100644 (file)
@@ -93,6 +93,7 @@
     <pre>
 ...
 &lt;bridge name="virbr0" stp="on" delay="5" macTableManager="libvirt"/&gt;
+&lt;mtu size="9000"/&gt;
 &lt;domain name="example.com" localOnly="no"/&gt;
 &lt;forward mode="nat" dev="eth0"/&gt;
 ...</pre>
           <span class="since">Since 1.2.11, requires kernel 3.17 or
           newer</span>
         </p>
+      </dd>
 
-
+      <dt><code>mtu</code></dt>
+      <dd>
+        The <code>size</code> attribute of the <code>mtu></code>
+        element specifies the Maximum Transmission Unit (MTU) for the
+        network. <span class="since">Since 3.1.0</span>. In the case
+        of a libvirt-managed network (one with forward mode
+        of <code>nat</code>, <code>route</code>, <code>open</code>, or
+        no <code>forward</code> 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).
       </dd>
+
       <dt><code>domain</code></dt>
       <dd>
         The <code>name</code> attribute on the <code>domain</code>
index ef1ed785f97fc8d0db6dd6f7943c042827840cd2..69ed6a75e60ca3b7729fbe2d9f352a823261f3f1 100644 (file)
       </change>
       <change>
         <summary>
-          Introduce MTU to domain &lt;interface/&gt;
+          Introduce MTU to domain &lt;interface/&gt; and &lt;network&gt;
         </summary>
         <description>
-          Allow setting MTU size for some types of domain interface.
+          Allow setting MTU size for some types of domain interface
+          and network.
         </description>
       </change>
     </section>
index 8f0a61b5bc7ce20102a5ddb7e788c7958c53c3f6..1048dabf3e65fb80f30920b18fa6a460c4ccba06 100644 (file)
           </element>
         </optional>
 
+        <!-- <mtu> element -->
+        <optional>
+          <ref name="mtu"/>
+        </optional>
+
         <!-- <mac> element -->
         <optional>
           <element name="mac">
index 86ce311ee1ba1a05f0713b9823a56a722db2abfb..0e20dac074dac97623e7e9c9fdad6d5dda19f136 100644 (file)
@@ -2242,6 +2242,17 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
         def->mac_specified = true;
     }
 
+    tmp = 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 = virXPathNode("./dns", ctxt);
     if (dnsNode != 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 route, 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)
 
     VIR_FREE(stp);
 
+    if (def->mtu &&
+        (def->forward.type != VIR_NETWORK_FORWARD_NONE &&
+         def->forward.type != VIR_NETWORK_FORWARD_NAT &&
+         def->forward.type != VIR_NETWORK_FORWARD_ROUTE &&
+         def->forward.type != 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 = virXPathNode("./metadata[1]", ctxt)) != NULL) {
         def->metadata = xmlCopyNode(metadataNode, 1);
@@ -2964,6 +2990,9 @@ virNetworkDefFormatBuf(virBufferPtr buf,
         virBufferAddLit(buf, "/>\n");
     }
 
+    if (def->mtu)
+        virBufferAsprintf(buf, "<mtu size='%u'/>\n", def->mtu);
+
     if (def->mac_specified) {
         char macaddr[VIR_MAC_STRING_BUFLEN];
         virMacAddrFormat(&def->mac, macaddr);
index b5c9ea24ecd71586f84076ab28d546f34cccee73..9e4ae7161824408d9ec184752bbe5bad783e05ed 100644 (file)
@@ -240,6 +240,7 @@ struct _virNetworkDef {
     int domainLocalOnly; /* enum virTristateBool: yes disables dns forwarding */
     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 config */
     virMacAddr mac; /* mac address of bridge device */
     bool mac_specified;
 
diff --git a/tests/networkxml2xmlin/set-mtu.xml b/tests/networkxml2xmlin/set-mtu.xml
new file mode 100644 (file)
index 0000000..d1ef32a
--- /dev/null
@@ -0,0 +1,12 @@
+<network ipv6='no'>
+  <name>private</name>
+  <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+  <bridge name='virbr2'/>
+  <mtu size='9000'/>
+  <mac address='52:54:00:17:3F:37'/>
+  <ip address="192.168.152.1" netmask="255.255.255.0">
+    <dhcp>
+      <range start="192.168.152.2" end="192.168.152.254"/>
+    </dhcp>
+  </ip>
+</network>
diff --git a/tests/networkxml2xmlout/set-mtu.xml b/tests/networkxml2xmlout/set-mtu.xml
new file mode 100644 (file)
index 0000000..10e8155
--- /dev/null
@@ -0,0 +1,12 @@
+<network>
+  <name>private</name>
+  <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+  <bridge name='virbr2' stp='on' delay='0'/>
+  <mtu size='9000'/>
+  <mac address='52:54:00:17:3f:37'/>
+  <ip address='192.168.152.1' netmask='255.255.255.0'>
+    <dhcp>
+      <range start='192.168.152.2' end='192.168.152.254'/>
+    </dhcp>
+  </ip>
+</network>
index 01cd6f714441b8b3d7f5a5db13776912898373e1..cfaf7181aaa934fcffa55b7c6829a0e47f700b4a 100644 (file)
@@ -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");
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }