Ubuntu: Set MTU for veth in the network files

Configuring veth pair MTU in the systemd-networkd .netdev files
does not set the correct MTU for the peer and there isn't
configuration option in the [Peer] section to do so [1].
This results in an MTU mismatch with peer having the default
(1500) value.

This change moves the MTU configuration from the .netdev file
to the [Link] section of the corresponding veth pair .network files.
Same approach is already recommended in [1] for the tun and
tap devices.

[1] https://www.freedesktop.org/software/systemd/man/systemd.netdev.html

Story: 2009072
Task: 42882
Change-Id: I082e1b807497d17ae40ddf86e1473fbfcdf625e2
This commit is contained in:
Lukasz Zalewski 2021-07-25 14:10:17 +01:00
parent da304da58e
commit 5a0206aef1
3 changed files with 73 additions and 33 deletions

View File

@ -176,13 +176,11 @@ def _veth_netdev(context, veth, inventory_hostname):
"""
interface = veth['name']
peer = veth['peer']
mtu = veth['mtu']
config = [
{
'NetDev': [
{'Name': interface},
{'Kind': 'veth'},
{'MTUBytes': mtu},
],
},
{
@ -425,6 +423,7 @@ def _veth_network(context, veth, inventory_hostname):
"""
interface = veth['name']
bridge = veth['bridge']
mtu = veth['mtu']
config = [
{
'Match': [
@ -435,6 +434,11 @@ def _veth_network(context, veth, inventory_hostname):
'Network': [
{'Bridge': bridge},
]
},
{
'Link': [
{'MTUBytes': mtu},
]
}
]
return _filter_options(config)
@ -448,6 +452,7 @@ def _veth_peer_network(context, veth, inventory_hostname):
:param inventory_hostname: Ansible inventory hostname.
"""
interface = veth['peer']
mtu = veth['mtu']
config = [
{
'Match': [
@ -459,6 +464,11 @@ def _veth_peer_network(context, veth, inventory_hostname):
# NOTE(mgoddard): bring the interface up, even without an IP.
{'ConfigureWithoutCarrier': 'true'},
]
},
{
'Link': [
{'MTUBytes': mtu},
]
}
]
return _filter_options(config)

View File

@ -235,37 +235,6 @@ class TestNetworkdNetDevs(BaseNetworkdTest):
}
self.assertEqual(expected, devs)
def test_veth_with_mtu(self):
self._update_context({"external_net_names": ["net3"],
"net3_mtu": 1400})
devs = networkd.networkd_netdevs(self.context, ["net3"])
expected = {
"50-kayobe-br0": [
{
"NetDev": [
{"Name": "br0"},
{"Kind": "bridge"},
{"MTUBytes": 1400},
]
},
],
"50-kayobe-p-br0-phy": [
{
"NetDev": [
{"Name": "p-br0-phy"},
{"Kind": "veth"},
{"MTUBytes": 1400},
]
},
{
"Peer": [
{"Name": "p-br0-ovs"},
]
},
]
}
self.assertEqual(expected, devs)
def test_veth_no_interface(self):
self._update_context({"external_net_names": ["net3"],
"net3_interface": None})
@ -870,6 +839,61 @@ class TestNetworkdNetworks(BaseNetworkdTest):
}
self.assertEqual(expected, nets)
def test_veth_with_mtu(self):
self._update_context({"external_net_names": ["net3"],
"net3_bridge_ports": [],
"net3_mtu": 1400})
nets = networkd.networkd_networks(self.context, ["net3"])
expected = {
"50-kayobe-br0": [
{
"Match": [
{"Name": "br0"}
]
},
{
"Link": [
{"MTUBytes": 1400},
]
},
],
"50-kayobe-p-br0-phy": [
{
"Match": [
{"Name": "p-br0-phy"}
]
},
{
"Network": [
{"Bridge": "br0"},
]
},
{
"Link": [
{"MTUBytes": 1400},
]
},
],
"50-kayobe-p-br0-ovs": [
{
"Match": [
{"Name": "p-br0-ovs"}
]
},
{
"Network": [
{"ConfigureWithoutCarrier": "true"},
]
},
{
"Link": [
{"MTUBytes": 1400},
]
},
],
}
self.assertEqual(expected, nets)
def test_veth_on_vlan(self):
# Test the case where a VLAN interface is one of the networks that
# needs patching to OVS. The parent interface is a bridge, and the veth

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixes an issue with systemd-networkd MTU mismatch in veth pair on Ubuntu.
See `story 2009072 <https://storyboard.openstack.org/#!/story/2009072>`__
for details.