Merge pull request #12574 from yuwata/network-mtu-issue-12552
network: do not always bump MTU with additional 4bytes
This commit is contained in:
@@ -261,7 +261,7 @@ static int dhcp_lease_lost(Link *link) {
|
||||
|
||||
r = sd_dhcp_lease_get_mtu(link->dhcp_lease, &mtu);
|
||||
if (r >= 0 && link->original_mtu != mtu) {
|
||||
r = link_set_mtu(link, link->original_mtu, true);
|
||||
r = link_set_mtu(link, link->original_mtu);
|
||||
if (r < 0) {
|
||||
log_link_warning(link,
|
||||
"DHCP error: could not reset MTU");
|
||||
@@ -454,7 +454,7 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) {
|
||||
|
||||
r = sd_dhcp_lease_get_mtu(lease, &mtu);
|
||||
if (r >= 0) {
|
||||
r = link_set_mtu(link, mtu, true);
|
||||
r = link_set_mtu(link, mtu);
|
||||
if (r < 0)
|
||||
log_link_error_errno(link, r, "Failed to set MTU to %" PRIu16 ": %m", mtu);
|
||||
}
|
||||
|
||||
@@ -1384,7 +1384,7 @@ static int set_mtu_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int link_set_mtu(Link *link, uint32_t mtu, bool force) {
|
||||
int link_set_mtu(Link *link, uint32_t mtu) {
|
||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
|
||||
int r;
|
||||
|
||||
@@ -1395,7 +1395,7 @@ int link_set_mtu(Link *link, uint32_t mtu, bool force) {
|
||||
if (mtu == 0 || link->setting_mtu)
|
||||
return 0;
|
||||
|
||||
if (force ? link->mtu == mtu : link->mtu >= mtu)
|
||||
if (link->mtu == mtu)
|
||||
return 0;
|
||||
|
||||
log_link_debug(link, "Setting MTU: %" PRIu32, mtu);
|
||||
@@ -1433,6 +1433,48 @@ int link_set_mtu(Link *link, uint32_t mtu, bool force) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool link_reduces_vlan_mtu(Link *link) {
|
||||
/* See netif_reduces_vlan_mtu() in kernel. */
|
||||
return streq_ptr(link->kind, "macsec");
|
||||
}
|
||||
|
||||
static uint32_t link_get_requested_mtu_by_stacked_netdevs(Link *link) {
|
||||
uint32_t mtu = 0;
|
||||
NetDev *dev;
|
||||
Iterator i;
|
||||
|
||||
HASHMAP_FOREACH(dev, link->network->stacked_netdevs, i)
|
||||
if (dev->kind == NETDEV_KIND_VLAN && dev->mtu > 0)
|
||||
/* See vlan_dev_change_mtu() in kernel. */
|
||||
mtu = MAX(mtu, link_reduces_vlan_mtu(link) ? dev->mtu + 4 : dev->mtu);
|
||||
|
||||
else if (dev->kind == NETDEV_KIND_MACVLAN && dev->mtu > mtu)
|
||||
/* See macvlan_change_mtu() in kernel. */
|
||||
mtu = dev->mtu;
|
||||
|
||||
return mtu;
|
||||
}
|
||||
|
||||
static int link_configure_mtu(Link *link) {
|
||||
uint32_t mtu;
|
||||
|
||||
assert(link);
|
||||
assert(link->network);
|
||||
|
||||
if (link->network->mtu > 0)
|
||||
return link_set_mtu(link, link->network->mtu);
|
||||
|
||||
mtu = link_get_requested_mtu_by_stacked_netdevs(link);
|
||||
if (link->mtu >= mtu)
|
||||
return 0;
|
||||
|
||||
log_link_notice(link, "Bumping MTU bytes from %"PRIu32" to %"PRIu32" because of stacked device. "
|
||||
"If it is not desired, then please explicitly specify MTUBytes= setting.",
|
||||
link->mtu, mtu);
|
||||
|
||||
return link_set_mtu(link, mtu);
|
||||
}
|
||||
|
||||
static int set_flags_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
int r;
|
||||
|
||||
@@ -2635,7 +2677,7 @@ static int link_configure(Link *link) {
|
||||
return r;
|
||||
}
|
||||
|
||||
r = link_set_mtu(link, link->network->mtu, link->network->mtu_is_set);
|
||||
r = link_configure_mtu(link);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ bool link_has_carrier(Link *link);
|
||||
|
||||
int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
|
||||
|
||||
int link_set_mtu(Link *link, uint32_t mtu, bool force);
|
||||
int link_set_mtu(Link *link, uint32_t mtu);
|
||||
|
||||
int ipv4ll_configure(Link *link);
|
||||
bool link_ipv4ll_enabled(Link *link);
|
||||
|
||||
@@ -143,24 +143,6 @@ static int network_resolve_stacked_netdevs(Network *network) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t network_get_stacked_netdevs_mtu(Network *network) {
|
||||
uint32_t mtu = 0;
|
||||
NetDev *dev;
|
||||
Iterator i;
|
||||
|
||||
HASHMAP_FOREACH(dev, network->stacked_netdevs, i)
|
||||
if (dev->kind == NETDEV_KIND_VLAN && dev->mtu > 0)
|
||||
/* See vlan_dev_change_mtu() in kernel.
|
||||
* Note that the additional 4bytes may not be necessary for all devices. */
|
||||
mtu = MAX(mtu, dev->mtu + 4);
|
||||
|
||||
else if (dev->kind == NETDEV_KIND_MACVLAN && dev->mtu > mtu)
|
||||
/* See macvlan_change_mtu() in kernel. */
|
||||
mtu = dev->mtu;
|
||||
|
||||
return mtu;
|
||||
}
|
||||
|
||||
int network_verify(Network *network) {
|
||||
Address *address, *address_next;
|
||||
Route *route, *route_next;
|
||||
@@ -169,7 +151,6 @@ int network_verify(Network *network) {
|
||||
AddressLabel *label, *label_next;
|
||||
Prefix *prefix, *prefix_next;
|
||||
RoutingPolicyRule *rule, *rule_next;
|
||||
uint32_t mtu;
|
||||
|
||||
assert(network);
|
||||
assert(network->filename);
|
||||
@@ -252,16 +233,7 @@ int network_verify(Network *network) {
|
||||
if (network->ip_masquerade)
|
||||
network->ip_forward |= ADDRESS_FAMILY_IPV4;
|
||||
|
||||
network->mtu_is_set = network->mtu > 0;
|
||||
mtu = network_get_stacked_netdevs_mtu(network);
|
||||
if (network->mtu < mtu) {
|
||||
if (network->mtu_is_set)
|
||||
log_notice("%s: Bumping MTUBytes= from %"PRIu32" to %"PRIu32" because of stacked device",
|
||||
network->filename, network->mtu, mtu);
|
||||
network->mtu = mtu;
|
||||
}
|
||||
|
||||
if (network->mtu_is_set && network->dhcp_use_mtu) {
|
||||
if (network->mtu > 0 && network->dhcp_use_mtu) {
|
||||
log_warning("%s: MTUBytes= in [Link] section and UseMTU= in [DHCP] section are set. "
|
||||
"Disabling UseMTU=.", network->filename);
|
||||
network->dhcp_use_mtu = false;
|
||||
|
||||
@@ -220,7 +220,6 @@ struct Network {
|
||||
|
||||
struct ether_addr *mac;
|
||||
uint32_t mtu;
|
||||
bool mtu_is_set; /* Indicate MTUBytes= is specified. */
|
||||
int arp;
|
||||
int multicast;
|
||||
int allmulticast;
|
||||
|
||||
@@ -479,7 +479,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
|
||||
|
||||
output = subprocess.check_output(['ip', '-d', 'link', 'show', 'test1']).rstrip().decode('utf-8')
|
||||
print(output)
|
||||
self.assertRegex(output, ' mtu 2004 ')
|
||||
self.assertRegex(output, ' mtu 2000 ')
|
||||
|
||||
output = subprocess.check_output(['ip', '-d', 'link', 'show', 'vlan99']).rstrip().decode('utf-8')
|
||||
print(output)
|
||||
|
||||
Reference in New Issue
Block a user