]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: the maximum MTU size for CAN interface may be changed later
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 22 Nov 2023 20:36:43 +0000 (05:36 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 8 Dec 2023 01:47:42 +0000 (10:47 +0900)
So we should not reduce the requested size to the current maximum
before applying CAN FD mode.

src/network/networkd-setlink.c

index 854699833d0b6b1fdc47ddb5af1f97eabc405b4d..38f90969ec498dffcf9a0c6d337efb25d7594f6b 100644 (file)
@@ -866,7 +866,7 @@ int link_request_to_set_master(Link *link) {
 
 int link_request_to_set_mtu(Link *link, uint32_t mtu) {
         const char *origin;
-        uint32_t min_mtu;
+        uint32_t min_mtu, max_mtu;
         Request *req;
         int r;
 
@@ -894,10 +894,19 @@ int link_request_to_set_mtu(Link *link, uint32_t mtu) {
                 mtu = min_mtu;
         }
 
-        if (mtu > link->max_mtu) {
+        max_mtu = link->max_mtu;
+        if (link->iftype == ARPHRD_CAN)
+                /* The maximum MTU may be changed when FD mode is changed.
+                 * See https://docs.kernel.org/networking/can.html#can-fd-flexible-data-rate-driver-support
+                 *   MTU = 16 (CAN_MTU)   => Classical CAN device
+                 *   MTU = 72 (CANFD_MTU) => CAN FD capable device
+                 * So, even if the current maximum is 16, we should not reduce the requested value now. */
+                max_mtu = MAX(max_mtu, 72u);
+
+        if (mtu > max_mtu) {
                 log_link_warning(link, "Reducing the requested MTU %"PRIu32" to the interface's maximum MTU %"PRIu32".",
-                                 mtu, link->max_mtu);
-                mtu = link->max_mtu;
+                                 mtu, max_mtu);
+                mtu = max_mtu;
         }
 
         if (link->mtu == mtu)