Skip to content

Commit e6f4979

Browse files
q2venPaolo Abeni
authored andcommitted
ipv6: Check GATEWAY in rtm_to_fib6_multipath_config().
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent fa76c16 commit e6f4979

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

net/ipv6/route.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5031,6 +5031,7 @@ static int rtm_to_fib6_multipath_config(struct fib6_config *cfg,
50315031
}
50325032

50335033
do {
5034+
bool has_gateway = cfg->fc_flags & RTF_GATEWAY;
50345035
int attrlen = rtnh_attrlen(rtnh);
50355036

50365037
if (attrlen > 0) {
@@ -5044,9 +5045,17 @@ static int rtm_to_fib6_multipath_config(struct fib6_config *cfg,
50445045
"Invalid IPv6 address in RTA_GATEWAY");
50455046
return -EINVAL;
50465047
}
5048+
5049+
has_gateway = true;
50475050
}
50485051
}
50495052

5053+
if (newroute && (cfg->fc_nh_id || !has_gateway)) {
5054+
NL_SET_ERR_MSG(extack,
5055+
"Device only routes can not be added for IPv6 using the multipath API.");
5056+
return -EINVAL;
5057+
}
5058+
50505059
rtnh = rtnh_next(rtnh, &remaining);
50515060
} while (rtnh_ok(rtnh, remaining));
50525061

@@ -5388,13 +5397,6 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
53885397
rt = NULL;
53895398
goto cleanup;
53905399
}
5391-
if (!rt6_qualify_for_ecmp(rt)) {
5392-
err = -EINVAL;
5393-
NL_SET_ERR_MSG(extack,
5394-
"Device only routes can not be added for IPv6 using the multipath API.");
5395-
fib6_info_release(rt);
5396-
goto cleanup;
5397-
}
53985400

53995401
rt->fib6_nh->fib_nh_weight = rtnh->rtnh_hops + 1;
54005402

0 commit comments

Comments
 (0)