From: Xin Long <lucien.xin@gmail.com> Date: 2017-07-30 12:51:47
After commit c2ed1880fd61 ("net: ipv6: check route protocol when
deleting routes"), ipv6 route checks rt protocol when trying to
remove a rt entry.
It introduced a side effect when flushing caches with iproute, in
which all route caches get dumped from kernel then removed one by
one by sending RTM_DELROUTE requests to kernel for each cache.
The thing is iproute sends the request with the cache whose proto
is set with RTPROT_REDIRECT by rt6_fill_node() when kernel dumps
it. But in kernel the rt_cache protocol is still 0, which causes
the cache not to be found and removed.
As rt6_fill_node always sets rtm proto with RTPROT_REDIRECT when
rt cache info goes to rtmsg, the reverse process is needed when
users remove a route cache and rtmsg goes to cfg.
This patch is to fix it by keeping cfg proto as 0 when rtm proto
is REDIRECT. It's a safe fix as rtm proto is set with REDIRECT
only if rt flag has RTF_DYNAMIC which is set when creating a rt
cache in rt6_do_redirect where the cache's proto is always 0.
Note that this issue can also be avoided in iproute by changing
rtm proto back to 0 before sending DELROUTE requests for cache.
But in kernel part, the fix is still necessary as kernel should
do the reverse conversion when rtm goes to cfg.
Fixes: c2ed1880fd61 ("net: ipv6: check route protocol when deleting routes")
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/ipv6/route.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
Did you look at removing this hunk from rt6_fill_node:
if (rt->rt6i_flags & RTF_DYNAMIC)
rtm->rtm_protocol = RTPROT_REDIRECT;
else if (rt->rt6i_flags & RTF_ADDRCONF) {
if (rt->rt6i_flags & (RTF_DEFAULT | RTF_ROUTEINFO))
rtm->rtm_protocol = RTPROT_RA;
else
rtm->rtm_protocol = RTPROT_KERNEL;
}
And have rtm_protocol set properly on the route when it is installed?
Did you look at removing this hunk from rt6_fill_node:
if (rt->rt6i_flags & RTF_DYNAMIC)
rtm->rtm_protocol = RTPROT_REDIRECT;
else if (rt->rt6i_flags & RTF_ADDRCONF) {
if (rt->rt6i_flags & (RTF_DEFAULT | RTF_ROUTEINFO))
rtm->rtm_protocol = RTPROT_RA;
else
rtm->rtm_protocol = RTPROT_KERNEL;
}
The issue seems to affect "ip -6 route flush all" as well, not only cache
since 'else if {}' also causes rtm proto being different from rt6 proto.
And have rtm_protocol set properly on the route when it is installed?
The codes not keeping rtm proto consistent with rt6 proto day 1,
any idea on why it didn't use rt6 proto in kernel properly?
Thanks.
From: David Ahern <hidden> Date: 2017-08-01 00:12:46
On 7/30/17 9:31 PM, Xin Long wrote:
quoted
Did you look at removing this hunk from rt6_fill_node:
if (rt->rt6i_flags & RTF_DYNAMIC)
rtm->rtm_protocol = RTPROT_REDIRECT;
else if (rt->rt6i_flags & RTF_ADDRCONF) {
if (rt->rt6i_flags & (RTF_DEFAULT | RTF_ROUTEINFO))
rtm->rtm_protocol = RTPROT_RA;
else
rtm->rtm_protocol = RTPROT_KERNEL;
}
The issue seems to affect "ip -6 route flush all" as well, not only cache
since 'else if {}' also causes rtm proto being different from rt6 proto.
quoted
And have rtm_protocol set properly on the route when it is installed?
The codes not keeping rtm proto consistent with rt6 proto day 1,
any idea on why it didn't use rt6 proto in kernel properly?
no, AFAIK it was just an oversight when the original code was written. I
do not know of any reason that would prevent properly setting the
rt6i_protocol in the route when it is allocated.
Something like this (not compiled, much less tested):
From: Xin Long <lucien.xin@gmail.com> Date: 2017-08-01 01:40:06
On Tue, Aug 1, 2017 at 12:12 PM, David Ahern [off-list ref] wrote:
On 7/30/17 9:31 PM, Xin Long wrote:
quoted
quoted
Did you look at removing this hunk from rt6_fill_node:
if (rt->rt6i_flags & RTF_DYNAMIC)
rtm->rtm_protocol = RTPROT_REDIRECT;
else if (rt->rt6i_flags & RTF_ADDRCONF) {
if (rt->rt6i_flags & (RTF_DEFAULT | RTF_ROUTEINFO))
rtm->rtm_protocol = RTPROT_RA;
else
rtm->rtm_protocol = RTPROT_KERNEL;
}
The issue seems to affect "ip -6 route flush all" as well, not only cache
since 'else if {}' also causes rtm proto being different from rt6 proto.
quoted
And have rtm_protocol set properly on the route when it is installed?
The codes not keeping rtm proto consistent with rt6 proto day 1,
any idea on why it didn't use rt6 proto in kernel properly?
no, AFAIK it was just an oversight when the original code was written. I
do not know of any reason that would prevent properly setting the
rt6i_protocol in the route when it is allocated.
That's what I was worried about, it might break something,
but double checked, should be fine.
Something like this (not compiled, much less tested):
To respect the old code more, setting RTPROT_RA only when
it's with the flag (ADDRCONF | DEFAULT | ROUTEINFO),
shouldn't it be:
[...]
*rt6_add_route_info(struct net *net,
cfg.fc_gateway = *gwaddr;
/* We should treat it as a default route if prefix length is 0. */
- if (!prefixlen)
+ if (!prefixlen) {
+ cfg.fc_protocol = RTPROT_RA;
cfg.fc_flags |= RTF_DEFAULT;
+ }
ip6_route_add(&cfg, NULL);
struct in6_addr *gwaddr,
.fc_nlinfo.portid = 0,
.fc_nlinfo.nlh = NULL,
.fc_nlinfo.nl_net = dev_net(dev),
+ .fc_protocol = RTPROT_KERNEL,
};
[...]
or you changed it intentionally ?
I will do some testing before posting v2.
thanks for your suggestion. :-)
From: David Ahern <hidden> Date: 2017-08-01 02:01:34
On 7/31/17 7:40 PM, Xin Long wrote:
To respect the old code more, setting RTPROT_RA only when
it's with the flag (ADDRCONF | DEFAULT | ROUTEINFO),
shouldn't it be:
Look at rtm_fill_info:
if (rt->rt6i_flags & (RTF_DEFAULT | RTF_ROUTEINFO))
rtm->rtm_protocol = RTPROT_RA;
If either flag is set the protocol should be RTPROT_RA and looking at
both places that seems correct to me.
From: Xin Long <lucien.xin@gmail.com> Date: 2017-08-01 02:50:51
On Tue, Aug 1, 2017 at 2:01 PM, David Ahern [off-list ref] wrote:
On 7/31/17 7:40 PM, Xin Long wrote:
quoted
To respect the old code more, setting RTPROT_RA only when
it's with the flag (ADDRCONF | DEFAULT | ROUTEINFO),
shouldn't it be:
Look at rtm_fill_info:
if (rt->rt6i_flags & (RTF_DEFAULT | RTF_ROUTEINFO))
rtm->rtm_protocol = RTPROT_RA;
If either flag is set the protocol should be RTPROT_RA and looking at
both places that seems correct to me.