Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ip: fix triggering of 'icmp redirect'

__mkroute_input() uses fib_validate_source() to trigger an icmp redirect.
My understanding is that fib_validate_source() is used to know if the src
address and the gateway address are on the same link. For that,
fib_validate_source() returns 1 (same link) or 0 (not the same network).
__mkroute_input() is the only user of these positive values, all other
callers only look if the returned value is negative.

Since the below patch, fib_validate_source() didn't return anymore 1 when
both addresses are on the same network, because the route lookup returns
RT_SCOPE_LINK instead of RT_SCOPE_HOST. But this is, in fact, right.
Let's adapat the test to return 1 again when both addresses are on the same
link.

CC: stable@vger.kernel.org
Fixes: 747c14307214 ("ip: fix dflt addr selection for connected nexthop")
Reported-by: kernel test robot <yujie.liu@intel.com>
Reported-by: Heng Qi <hengqi@linux.alibaba.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://lore.kernel.org/r/20220829100121.3821-1-nicolas.dichtel@6wind.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Nicolas Dichtel and committed by
Jakub Kicinski
eb55dc09 90fabae8

+2 -2
+2 -2
net/ipv4/fib_frontend.c
··· 389 389 dev_match = dev_match || (res.type == RTN_LOCAL && 390 390 dev == net->loopback_dev); 391 391 if (dev_match) { 392 - ret = FIB_RES_NHC(res)->nhc_scope >= RT_SCOPE_HOST; 392 + ret = FIB_RES_NHC(res)->nhc_scope >= RT_SCOPE_LINK; 393 393 return ret; 394 394 } 395 395 if (no_addr) ··· 401 401 ret = 0; 402 402 if (fib_lookup(net, &fl4, &res, FIB_LOOKUP_IGNORE_LINKSTATE) == 0) { 403 403 if (res.type == RTN_UNICAST) 404 - ret = FIB_RES_NHC(res)->nhc_scope >= RT_SCOPE_HOST; 404 + ret = FIB_RES_NHC(res)->nhc_scope >= RT_SCOPE_LINK; 405 405 } 406 406 return ret; 407 407