]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ipv6: Check GATEWAY in rtm_to_fib6_multipath_config().
authorKuniyuki Iwashima <kuniyu@amazon.com>
Fri, 18 Apr 2025 00:03:45 +0000 (17:03 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 24 Apr 2025 07:29:56 +0000 (09:29 +0200)
In ip6_route_multipath_add(), we call rt6_qualify_for_ecmp() for each
entry.  If it returns false, the request fails.

rt6_qualify_for_ecmp() returns false if either of the conditions below
is true:

  1. f6i->fib6_flags has RTF_ADDRCONF
  2. f6i->nh is not NULL
  3. f6i->fib6_nh->fib_nh_gw_family is AF_UNSPEC

1 is unnecessary because rtm_to_fib6_config() never sets RTF_ADDRCONF
to cfg->fc_flags.

2. is equivalent with cfg->fc_nh_id.

3. can be replaced by checking RTF_GATEWAY in the base and each multipath
entry because AF_INET6 is set to f6i->fib6_nh->fib_nh_gw_family only when
cfg.fc_is_fdb is true or RTF_GATEWAY is set, but the former is always
false.

These checks do not require RCU and can be done earlier.

Let's perform the equivalent checks in rtm_to_fib6_multipath_config().

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250418000443.43734-5-kuniyu@amazon.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/ipv6/route.c

index aa92e02a47f498f4d3aaa4359468c45c0bbf3b52..88d2f85ed69dcb411e3f7dca95f986a31d7f5827 100644 (file)
@@ -5031,6 +5031,7 @@ static int rtm_to_fib6_multipath_config(struct fib6_config *cfg,
        }
 
        do {
+               bool has_gateway = cfg->fc_flags & RTF_GATEWAY;
                int attrlen = rtnh_attrlen(rtnh);
 
                if (attrlen > 0) {
@@ -5044,9 +5045,17 @@ static int rtm_to_fib6_multipath_config(struct fib6_config *cfg,
                                                       "Invalid IPv6 address in RTA_GATEWAY");
                                        return -EINVAL;
                                }
+
+                               has_gateway = true;
                        }
                }
 
+               if (newroute && (cfg->fc_nh_id || !has_gateway)) {
+                       NL_SET_ERR_MSG(extack,
+                                      "Device only routes can not be added for IPv6 using the multipath API.");
+                       return -EINVAL;
+               }
+
                rtnh = rtnh_next(rtnh, &remaining);
        } while (rtnh_ok(rtnh, remaining));
 
@@ -5388,13 +5397,6 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
                        rt = NULL;
                        goto cleanup;
                }
-               if (!rt6_qualify_for_ecmp(rt)) {
-                       err = -EINVAL;
-                       NL_SET_ERR_MSG(extack,
-                                      "Device only routes can not be added for IPv6 using the multipath API.");
-                       fib6_info_release(rt);
-                       goto cleanup;
-               }
 
                rt->fib6_nh->fib_nh_weight = rtnh->rtnh_hops + 1;