network/sysctl: round IPv6 MTU with the current device MTU rather than the maximum MTU

Otherwise, writing IPv6 MTU may fail.

This also makes link_set_ipv6_mtu() take log level about rounding IPv6 MTU,
and downgrade the log level from LOG_WARNING -> LOG_INFO, as we usually
use LOG_WARNING for per-interface critical failure.
This commit is contained in:
Yu Watanabe 2024-04-10 10:07:50 +09:00
parent eb426caae7
commit fb71748e4f
3 changed files with 14 additions and 11 deletions

View file

@ -1881,7 +1881,7 @@ static int link_admin_state_up(Link *link) {
/* We set the ipv6 mtu after the device mtu, but the kernel resets
* ipv6 mtu on NETDEV_UP, so we need to reset it. */
r = link_set_ipv6_mtu(link);
r = link_set_ipv6_mtu(link, LOG_INFO);
if (r < 0)
log_link_warning_errno(link, r, "Cannot set IPv6 MTU, ignoring: %m");
@ -2436,7 +2436,7 @@ static int link_update_mtu(Link *link, sd_netlink_message *message) {
if (IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) {
/* The kernel resets IPv6 MTU after changing device MTU. So, we need to re-set IPv6 MTU again. */
r = link_set_ipv6_mtu(link);
r = link_set_ipv6_mtu(link, LOG_INFO);
if (r < 0)
log_link_warning_errno(link, r, "Failed to set IPv6 MTU, ignoring: %m");
}

View file

@ -250,7 +250,7 @@ static int link_set_ipv6_proxy_ndp(Link *link) {
return sysctl_write_ip_property_boolean(AF_INET6, link->ifname, "proxy_ndp", v);
}
int link_set_ipv6_mtu(Link *link) {
int link_set_ipv6_mtu(Link *link, int log_level) {
uint32_t mtu;
assert(link);
@ -258,14 +258,17 @@ int link_set_ipv6_mtu(Link *link) {
if (!link_is_configured_for_family(link, AF_INET6))
return 0;
if (link->network->ipv6_mtu == 0)
return 0;
assert(link->network);
mtu = link->network->ipv6_mtu;
if (mtu > link->max_mtu) {
log_link_warning(link, "Reducing requested IPv6 MTU %"PRIu32" to the interface's maximum MTU %"PRIu32".",
mtu, link->max_mtu);
mtu = link->max_mtu;
if (mtu == 0)
return 0;
if (mtu > link->mtu) {
log_link_full(link, log_level,
"Reducing requested IPv6 MTU %"PRIu32" to the interface's maximum MTU %"PRIu32".",
mtu, link->mtu);
mtu = link->mtu;
}
return sysctl_write_ip_property_uint32(AF_INET6, link->ifname, "mtu", mtu);
@ -355,7 +358,7 @@ int link_set_sysctl(Link *link) {
if (r < 0)
log_link_warning_errno(link, r, "Cannot set IPv6 proxy NDP, ignoring: %m");
r = link_set_ipv6_mtu(link);
r = link_set_ipv6_mtu(link, LOG_INFO);
if (r < 0)
log_link_warning_errno(link, r, "Cannot set IPv6 MTU, ignoring: %m");

View file

@ -31,7 +31,7 @@ void manager_set_sysctl(Manager *manager);
int link_get_ip_forwarding(Link *link, int family);
int link_set_sysctl(Link *link);
int link_set_ipv6_mtu(Link *link);
int link_set_ipv6_mtu(Link *link, int log_level);
const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i) _const_;
IPv6PrivacyExtensions ipv6_privacy_extensions_from_string(const char *s) _pure_;