[libvirt] [PATCH] network: set mtu as a DHCP option when specified

Casey Callendrello posted 1 patch 5 years, 4 months ago
Test syntax-check passed
Failed in applying to current master (apply log)
src/network/bridge_driver.c                   |  7 ++++++
.../networkxml2confdata/nat-network-mtu.conf  | 19 +++++++++++++++
tests/networkxml2confdata/nat-network-mtu.xml | 22 +++++++++++++++++
tests/networkxml2conftest.c                   |  1 +
tests/networkxml2xmlin/nat-network-mtu.xml    | 22 +++++++++++++++++
tests/networkxml2xmlout/nat-network-mtu.xml   | 24 +++++++++++++++++++
tests/networkxml2xmltest.c                    |  1 +
7 files changed, 96 insertions(+)
create mode 100644 tests/networkxml2confdata/nat-network-mtu.conf
create mode 100644 tests/networkxml2confdata/nat-network-mtu.xml
create mode 100644 tests/networkxml2xmlin/nat-network-mtu.xml
create mode 100644 tests/networkxml2xmlout/nat-network-mtu.xml
[libvirt] [PATCH] network: set mtu as a DHCP option when specified
Posted by Casey Callendrello 5 years, 4 months ago
This adds an additional directive to the dnsmasq configuration file that
notifies clients via dhcp about the link's MTU. Guests can then choose
adjust their link accordingly.

Signed-off-by: Casey Callendrello <cdc@redhat.com>
---
 src/network/bridge_driver.c                   |  7 ++++++
 .../networkxml2confdata/nat-network-mtu.conf  | 19 +++++++++++++++
 tests/networkxml2confdata/nat-network-mtu.xml | 22 +++++++++++++++++
 tests/networkxml2conftest.c                   |  1 +
 tests/networkxml2xmlin/nat-network-mtu.xml    | 22 +++++++++++++++++
 tests/networkxml2xmlout/nat-network-mtu.xml   | 24 +++++++++++++++++++
 tests/networkxml2xmltest.c                    |  1 +
 7 files changed, 96 insertions(+)
 create mode 100644 tests/networkxml2confdata/nat-network-mtu.conf
 create mode 100644 tests/networkxml2confdata/nat-network-mtu.xml
 create mode 100644 tests/networkxml2xmlin/nat-network-mtu.xml
 create mode 100644 tests/networkxml2xmlout/nat-network-mtu.xml

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 4bbc4f5a6d..81edf72493 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1506,6 +1506,13 @@ networkDnsmasqConfContents(virNetworkObjPtr obj,
                           dctx->addnhostsfile->path);
     }
 
+    /* Configure DHCP to tell clients about the MTU.
+     */
+    if (def->mtu > 0) {
+        virBufferAsprintf(&configbuf, "dhcp-option=option:mtu,%d\n",
+                          def->mtu);
+    }
+
     /* Are we doing RA instead of radvd? */
     if (DNSMASQ_RA_SUPPORT(caps)) {
         if (ipv6def) {
diff --git a/tests/networkxml2confdata/nat-network-mtu.conf b/tests/networkxml2confdata/nat-network-mtu.conf
new file mode 100644
index 0000000000..91b574b964
--- /dev/null
+++ b/tests/networkxml2confdata/nat-network-mtu.conf
@@ -0,0 +1,19 @@
+##WARNING:  THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
+##OVERWRITTEN AND LOST.  Changes to this configuration should be made using:
+##    virsh net-edit default
+## or other application using the libvirt API.
+##
+## dnsmasq conf file created by libvirt
+strict-order
+except-interface=lo
+bind-dynamic
+interface=virbr0
+dhcp-range=192.168.122.2,192.168.122.254
+dhcp-no-override
+dhcp-authoritative
+dhcp-lease-max=253
+dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
+addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
+dhcp-option=option:mtu,7000
+dhcp-range=2001:db8:ac10:fe01::1,ra-only
+dhcp-range=2001:db8:ac10:fd01::1,ra-only
diff --git a/tests/networkxml2confdata/nat-network-mtu.xml b/tests/networkxml2confdata/nat-network-mtu.xml
new file mode 100644
index 0000000000..87b214e95c
--- /dev/null
+++ b/tests/networkxml2confdata/nat-network-mtu.xml
@@ -0,0 +1,22 @@
+<network>
+  <name>default</name>
+  <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+  <forward dev='eth1' mode='nat'/>
+  <bridge name='virbr0' stp='on' delay='0'/>
+  <mtu size='7000'/>
+  <ip address='192.168.122.1' netmask='255.255.255.0'>
+    <dhcp>
+      <range start='192.168.122.2' end='192.168.122.254'/>
+      <host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10'/>
+      <host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11'/>
+    </dhcp>
+  </ip>
+  <ip family='ipv4' address='192.168.123.1' netmask='255.255.255.0'>
+  </ip>
+  <ip family='ipv6' address='2001:db8:ac10:fe01::1' prefix='64'>
+  </ip>
+  <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'>
+  </ip>
+  <ip family='ipv4' address='10.24.10.1'>
+  </ip>
+</network>
diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c
index 367e30b994..f3b4dafc1b 100644
--- a/tests/networkxml2conftest.c
+++ b/tests/networkxml2conftest.c
@@ -137,6 +137,7 @@ mymain(void)
     DO_TEST("nat-network-dns-forwarders", full);
     DO_TEST("nat-network-dns-forwarder-no-resolv", full);
     DO_TEST("nat-network-dns-local-domain", full);
+    DO_TEST("nat-network-mtu", dhcpv6);
     DO_TEST("dhcp6-network", dhcpv6);
     DO_TEST("dhcp6-nat-network", dhcpv6);
     DO_TEST("dhcp6host-routed-network", dhcpv6);
diff --git a/tests/networkxml2xmlin/nat-network-mtu.xml b/tests/networkxml2xmlin/nat-network-mtu.xml
new file mode 100644
index 0000000000..07d0d9f22d
--- /dev/null
+++ b/tests/networkxml2xmlin/nat-network-mtu.xml
@@ -0,0 +1,22 @@
+<network>
+  <name>default</name>
+  <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+  <bridge name="virbr0"/>
+  <mtu size='7000'/>
+  <forward mode="nat" dev="eth1"/>
+  <ip address="192.168.122.1" netmask="255.255.255.0">
+    <dhcp>
+      <range start="192.168.122.2" end="192.168.122.254"/>
+      <host mac="00:16:3e:77:e2:ed" name="a.example.com" ip="192.168.122.10"/>
+      <host mac="00:16:3e:3e:a9:1a" name="b.example.com" ip="192.168.122.11"/>
+    </dhcp>
+  </ip>
+  <ip family="ipv4" address="192.168.123.1" netmask="255.255.255.0">
+  </ip>
+  <ip family="ipv6" address="2001:db8:ac10:fe01::1" prefix="64">
+  </ip>
+  <ip family="ipv6" address="2001:db8:ac10:fd01::1" prefix="64">
+  </ip>
+  <ip family="ipv4" address="10.24.10.1">
+  </ip>
+</network>
diff --git a/tests/networkxml2xmlout/nat-network-mtu.xml b/tests/networkxml2xmlout/nat-network-mtu.xml
new file mode 100644
index 0000000000..715bc1b505
--- /dev/null
+++ b/tests/networkxml2xmlout/nat-network-mtu.xml
@@ -0,0 +1,24 @@
+<network>
+  <name>default</name>
+  <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+  <forward dev='eth1' mode='nat'>
+    <interface dev='eth1'/>
+  </forward>
+  <bridge name='virbr0' stp='on' delay='0'/>
+  <mtu size='7000'/>
+  <ip address='192.168.122.1' netmask='255.255.255.0'>
+    <dhcp>
+      <range start='192.168.122.2' end='192.168.122.254'/>
+      <host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10'/>
+      <host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11'/>
+    </dhcp>
+  </ip>
+  <ip family='ipv4' address='192.168.123.1' netmask='255.255.255.0'>
+  </ip>
+  <ip family='ipv6' address='2001:db8:ac10:fe01::1' prefix='64'>
+  </ip>
+  <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'>
+  </ip>
+  <ip family='ipv4' address='10.24.10.1'>
+  </ip>
+</network>
diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c
index 4e4c7d20a6..b19a365ff4 100644
--- a/tests/networkxml2xmltest.c
+++ b/tests/networkxml2xmltest.c
@@ -141,6 +141,7 @@ mymain(void)
     DO_TEST("nat-network-dns-forwarder-no-resolv");
     DO_TEST("nat-network-forward-nat-address");
     DO_TEST("nat-network-forward-nat-no-address");
+    DO_TEST("nat-network-mtu");
     DO_TEST("8021Qbh-net");
     DO_TEST("direct-net");
     DO_TEST("host-bridge-net");
-- 
2.17.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] network: set mtu as a DHCP option when specified
Posted by Ján Tomko 5 years, 2 months ago
On Tue, Dec 11, 2018 at 05:05:43PM +0100, Casey Callendrello wrote:
>This adds an additional directive to the dnsmasq configuration file that
>notifies clients via dhcp about the link's MTU. Guests can then choose
>adjust their link accordingly.
>
>Signed-off-by: Casey Callendrello <cdc@redhat.com>
>---
> src/network/bridge_driver.c                   |  7 ++++++
> .../networkxml2confdata/nat-network-mtu.conf  | 19 +++++++++++++++
> tests/networkxml2confdata/nat-network-mtu.xml | 22 +++++++++++++++++
> tests/networkxml2conftest.c                   |  1 +
> tests/networkxml2xmlin/nat-network-mtu.xml    | 22 +++++++++++++++++
> tests/networkxml2xmlout/nat-network-mtu.xml   | 24 +++++++++++++++++++
> tests/networkxml2xmltest.c                    |  1 +
> 7 files changed, 96 insertions(+)
> create mode 100644 tests/networkxml2confdata/nat-network-mtu.conf
> create mode 100644 tests/networkxml2confdata/nat-network-mtu.xml
> create mode 100644 tests/networkxml2xmlin/nat-network-mtu.xml
> create mode 100644 tests/networkxml2xmlout/nat-network-mtu.xml
>
>diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
>index 4bbc4f5a6d..81edf72493 100644
>--- a/src/network/bridge_driver.c
>+++ b/src/network/bridge_driver.c
>@@ -1506,6 +1506,13 @@ networkDnsmasqConfContents(virNetworkObjPtr obj,
>                           dctx->addnhostsfile->path);
>     }
>
>+    /* Configure DHCP to tell clients about the MTU.
>+     */

This comment can fit on one line,

>+    if (def->mtu > 0) {
>+        virBufferAsprintf(&configbuf, "dhcp-option=option:mtu,%d\n",
>+                          def->mtu);

and so can this command.

>+    }
>+
>     /* Are we doing RA instead of radvd? */
>     if (DNSMASQ_RA_SUPPORT(caps)) {
>         if (ipv6def) {

With that adjusted:
Reviewed-by: Ján Tomko <jtomko@redhat.com>

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