network/sysctl: round IPv6 MTU with the current device MTU rather than the maximum MTU
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 10 Apr 2024 01:07:50 +0000 (10:07 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 10 Apr 2024 03:15:33 +0000 (12:15 +0900)
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.

src/network/networkd-link.c
src/network/networkd-sysctl.c
src/network/networkd-sysctl.h

index a69402ee9fd3d2fd9889c8b3c04a28717a6064b8..61e0e16818e5e3c042529bfddd29b1212446465b 100644 (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");
         }
index f9db1f7f4af16c4c3085231d9f7aa234ebe33708..66ee2afeed2e97675b6fe96afb95a141b28966e9 100644 (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");
 
index a47dda015defbb86579f2a04e89b63dea05dfbcd..d7a9b1f3201587e4209fb9fe15e445adcca5b691 100644 (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_;