Bug 256309 - net/cloud-init: fix set mtu, bump port version 21.2
Summary: net/cloud-init: fix set mtu, bump port version 21.2
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Li-Wen Hsu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-31 19:40 UTC by Andrey Fesenko
Modified: 2021-07-05 05:30 UTC (History)
2 users (show)

See Also:


Attachments
add mtu set, bump port version 21.2 (5.02 KB, patch)
2021-07-05 04:42 UTC, Andrey Fesenko
andrey: maintainer-approval+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Fesenko 2021-05-31 19:40:17 UTC
Upstream have patch https://github.com/canonical/cloud-init/pull/894/files

but, this add set mtu only "subnets:" section, docs and may by some dadasource (SmartOS) support only set mtu in "config:" section, linux's have any with subnets priority

`netplan.py[WARNING]: Network config: ignoring enp0s5 device-level mtu:1500 because ipv4 subnet-level mtu:1501 provided.`

proof of concept get data in config section, but linux have logic https://github.com/canonical/cloud-init/blob/master/cloudinit/net/netplan.py#L116 (line 134)

https://github.com/canonical/cloud-init/blob/master/cloudinit/net/eni.py#L107

```
--- /usr/local/lib/python3.8/site-packages/cloudinit/net/bsd.py.orig    2021-01-15 17:33:05.000000000 +0000
+++ /usr/local/lib/python3.8/site-packages/cloudinit/net/bsd.py 2021-05-31 19:30:55.808268000 +0000
@@ -37,7 +37,9 @@ class BSDRenderer(renderer.Renderer):
         ifname_by_mac = net.get_interfaces_by_mac()
         for interface in settings.iter_interfaces():
             device_name = interface.get("name")
+            device_mtu = interface.get("mtu")
             device_mac = interface.get("mac_address")
+            LOG.info('Debug interface mtu %s', device_mtu)
             if device_name and re.match(r'^lo\d+$', device_name):
                 continue
             if device_mac not in ifname_by_mac:
@@ -64,18 +66,21 @@ class BSDRenderer(renderer.Renderer):
 
             for subnet in interface.get("subnets", []):
                 if subnet.get('type') == 'static':
+                    LOG.debug('Debug mtu %s', subnet.get('mtu'))
+                    LOG.debug('Debug address %s', subnet.get('address'))
                     if not subnet.get('netmask'):
                         LOG.debug(
                             'Skipping IP %s, because there is no netmask',
                             subnet.get('address')
                         )
                         continue
-                    LOG.debug('Configuring dev %s with %s / %s', device_name,
-                              subnet.get('address'), subnet.get('netmask'))
+                    LOG.debug('Configuring dev %s with %s / %s mtu %s, device mtu %s', device_name,
+                              subnet.get('address'), subnet.get('netmask'), subnet.get('mtu'), device_mtu)
 
                     self.interface_configurations[device_name] = {
                         'address': subnet.get('address'),
                         'netmask': subnet.get('netmask'),
+                        'mtu': device_mtu,
                     }
 
     def _route_entries(self, settings, target=None):
--- /usr/local/lib/python3.8/site-packages/cloudinit/net/freebsd.py.orig        2021-01-15 17:33:05.000000000 +0000
+++ /usr/local/lib/python3.8/site-packages/cloudinit/net/freebsd.py     2021-05-31 19:31:29.486255000 +0000
@@ -19,12 +19,13 @@ class Renderer(cloudinit.net.bsd.BSDRenderer):
 
     def write_config(self):
         for device_name, v in self.interface_configurations.items():
+            net_config = 'DHCP'
             if isinstance(v, dict):
-                self.set_rc_config_value(
-                    'ifconfig_' + device_name,
-                    v.get('address') + ' netmask ' + v.get('netmask'))
-            else:
-                self.set_rc_config_value('ifconfig_' + device_name, 'DHCP')
+                net_config = v.get('address') + ' netmask ' + v.get('netmask')
+                mtu = v.get('mtu')
+                if mtu:
+                   net_config += (' mtu %d' % mtu)
+            self.set_rc_config_value('ifconfig_' + device_name, net_config)
 
     def start_services(self, run=False):
         if not run:
```

DataSourceSmartOS declare only physical section contain mtu
https://github.com/canonical/cloud-init/blob/master/cloudinit/sources/DataSourceSmartOS.py#L815
Comment 1 Li-Wen Hsu freebsd_committer freebsd_triage 2021-06-01 03:21:27 UTC
Is it possible for you to upload the patch as an attachment? Also, it's preferred to use `git format-patch` to include your author line, not required strictly but it's handy for a committer to process it. Thanks!
Comment 2 Gonéri Le Bouder 2021-06-27 00:04:29 UTC
Andrey, I've just pushed this. Feedback are welcome:

https://github.com/canonical/cloud-init/pull/930
Comment 3 Andrey Fesenko 2021-07-05 04:42:44 UTC
Created attachment 226228 [details]
add mtu set, bump port version 21.2

Bump port version 21.2

Add patch for set MTU, FreeBSD specific part
https://github.com/canonical/cloud-init/commit/6fe1983777663a1a1136fd73dc50244f2d030be8#diff-25825a25ab56718be03c5147293f56d6c93822fb59b5840034f841b7a977bddc

https://github.com/canonical/cloud-init/commit/db51b656ee997382c3c4792271fa08398f43e105

testport: OK (poudriere: 122amd64, 13amd64 tested)
Comment 4 commit-hook freebsd_committer freebsd_triage 2021-07-05 05:25:25 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=9620aca55054d7f4e7fc85cd2f0e01ea984c237a

commit 9620aca55054d7f4e7fc85cd2f0e01ea984c237a
Author:     Andrey Fesenko <andrey@bsdnir.info>
AuthorDate: 2021-07-05 05:23:02 +0000
Commit:     Li-Wen Hsu <lwhsu@FreeBSD.org>
CommitDate: 2021-07-05 05:24:22 +0000

    net/cloud-init: Update to 21.2 and add patch for setting MTU

    PR:             256309

 net/cloud-init/Makefile                            |  3 +-
 net/cloud-init/distinfo                            |  6 +--
 .../files/patch-cloudinit_net_bsd.py (new)         | 60 ++++++++++++++++++++++
 .../files/patch-cloudinit_net_freebsd.py (new)     | 21 ++++++++
 4 files changed, 85 insertions(+), 5 deletions(-)