ipv6: update Destination Cache entries when gateway turn into host
Subsystems (3)
PATCH 1/1 ipv6: update Destination Cache entries when gateway turn into host
RFC 4861 states in 7.2.5:
The IsRouter flag in the cache entry MUST be set based on the
Router flag in the received advertisement. In those cases where the IsRouter flag changes from TRUE to FALSE as a result of this update, the node MUST remove that router from the Default Router List and update the Destination Cache entries for all destinations using that neighbor as a router as specified in Section 7.3.3. This is needed to detect when a node that is used as a router stops forwarding packets due to being configured as a host.
Currently, when dealing with NA Message which IsRouter flag changes from TRUE to FALSE, the kernel only removes router from the Default Router List, and don't update the Destination Cache entries.
Now in order to update those Destination Cache entries, i introduce function rt6_clean_tohost().
--- include/net/ip6_route.h | 1 + net/ipv6/ndisc.c | 7 ++----- net/ipv6/route.c | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-)
include/net/ip6_route.h +1 -0
@@ -127,6 +127,7 @@ int rt6_dump_route(struct rt6_info *rt, void *p_arg);void rt6_ifdown (struct net *net,struct net_device *dev);void rt6_mtu_change (struct net_device *dev,unsigned int mtu);void rt6_remove_prefsrc (struct inet6_ifaddr *ifp); +void rt6_clean_tohost (struct net *net,struct in6_addr *gateway);/*
net/ipv6/ndisc.c +2 -5
@@ -851,7 +851,7 @@ out:static void ndisc_recv_na (struct sk_buff *skb) {struct nd_msg *msg = (struct nd_msg *)skb_transport_header (skb); -const struct in6_addr *saddr = &ipv6_hdr (skb)->saddr; +struct in6_addr *saddr = &ipv6_hdr (skb)->saddr;const struct in6_addr *daddr = &ipv6_hdr (skb)->daddr;u8 *lladdr =NULL ; u32 ndoptlen = skb_tail_pointer(skb) - (skb_transport_header(skb) +
@@ -944,10 +944,7 @@ static void ndisc_recv_na(struct sk_buff *skb)/* * Change: router to host */ -struct rt6_info *rt; - rt =rt6_get_dflt_router (saddr, dev); -if (rt) -ip6_del_rt (rt); +rt6_clean_tohost (dev_net (dev), saddr); } out:
net/ipv6/route.c +23 -0
@@ -2234,6 +2234,29 @@ void rt6_remove_prefsrc(struct inet6_ifaddr *ifp)fib6_clean_all (net, fib6_remove_prefsrc, &adni); } +/*remove routers and update dst entries when gateway turn into host.*/ +static int fib6_clean_tohost (struct rt6_info *rt,void *arg) +{ +struct in6_addr *gateway = (struct in6_addr *)arg; + +if (((rt->rt6i_flags & (RTF_ADDRCONF |RTF_DEFAULT |RTF_GATEWAY )) + == (RTF_ADDRCONF |RTF_DEFAULT |RTF_GATEWAY )) + &&ipv6_addr_equal (gateway, &rt->rt6i_gateway)) { +return -1 ; + }else if (((rt->rt6i_flags & (RTF_GATEWAY |RTF_CACHE )) + == (RTF_GATEWAY |RTF_CACHE )) + &&ipv6_addr_equal (gateway, &rt->rt6i_gateway)) { + rt->rt6i_flags |=RTF_REJECT ; + rt->dst.error = -ENETUNREACH ; + } +return 0 ; +} + +void rt6_clean_tohost (struct net *net,struct in6_addr *gateway) +{ +fib6_clean_all (net, fib6_clean_tohost, gateway); +} +struct arg_dev_net {struct net_device *dev;struct net *net;
Signature · 1 line
1.8.3.1
Quoted 29 lines · Duan Jiong
RFC 4861 states in 7.2.5:
The IsRouter flag in the cache entry MUST be set based on the
Router flag in the received advertisement. In those cases where the IsRouter flag changes from TRUE to FALSE as a result of this update, the node MUST remove that router from the Default Router List and update the Destination Cache entries for all destinations using that neighbor as a router as specified in Section 7.3.3. This is needed to detect when a node that is used as a router stops forwarding packets due to being configured as a host.Currently, when dealing with NA Message which IsRouter flag changes from TRUE to FALSE, the kernel only removes router from the Default Router List, and don't update the Destination Cache entries.
Now in order to update those Destination Cache entries, i introduce function
rt6_clean_tohost().[...]
net/ipv6/route.c +7
-0+/*remove routers and update dst entries when gateway turn into host.*/ +static int fib6_clean_tohost (struct rt6_info *rt,void *arg) +{ +struct in6_addr *gateway = (struct in6_addr *)arg; + +if (((rt->rt6i_flags & (RTF_ADDRCONF |RTF_DEFAULT |RTF_GATEWAY )) + == (RTF_ADDRCONF | RTF_DEFAULT | RTF_GATEWAY))
net/ipv6/route.c void rt6_remove_prefsrc(struct inet6_ifaddr *ifp) · line 2253
Quoted 10 lines
net/ipv6/route.c +10
-0+ && ipv6_addr_equal(gateway, &rt->rt6i_gateway)) { +return -1 ; + }else if (((rt->rt6i_flags & (RTF_GATEWAY |RTF_CACHE )) + == (RTF_GATEWAY |RTF_CACHE )) + &&ipv6_addr_equal (gateway, &rt->rt6i_gateway)) { + rt->rt6i_flags |=RTF_REJECT ; + rt->dst.error = -ENETUNREACH ; + } +return 0 ; +}
I am not so happy with that but have not tried that.
The Destination Cache you quote from the RFC (if you follow 7.3.3.) actually refers to the neighbouring subsystem, where we would need to generate subsequent errors in case we try to forward a packet through a this particular router.
The reason why I am not that happy is, that the semantics when neighbour nodes are cleared is well
defined but we don't have that semantics when those rt6_nodes get cleared up. E.g. consider a router which just temporarily switches forwarding off and on.
I guess we need to inspect NTF_ROUTER flag in the output path somehow. :/
Greetings,
Hannes
Quoted 43 lines · Hannes Frederic Sowa
Quoted 29 lines · Duan Jiong
RFC 4861 states in 7.2.5:
The IsRouter flag in the cache entry MUST be set based on the
Router flag in the received advertisement. In those cases where the IsRouter flag changes from TRUE to FALSE as a result of this update, the node MUST remove that router from the Default Router List and update the Destination Cache entries for all destinations using that neighbor as a router as specified in Section 7.3.3. This is needed to detect when a node that is used as a router stops forwarding packets due to being configured as a host.Currently, when dealing with NA Message which IsRouter flag changes from TRUE to FALSE, the kernel only removes router from the Default Router List, and don't update the Destination Cache entries.
Now in order to update those Destination Cache entries, i introduce function
rt6_clean_tohost().[...]
net/ipv6/route.c +7
-0+/*remove routers and update dst entries when gateway turn into host.*/ +static int fib6_clean_tohost (struct rt6_info *rt,void *arg) +{ +struct in6_addr *gateway = (struct in6_addr *)arg; + +if (((rt->rt6i_flags & (RTF_ADDRCONF |RTF_DEFAULT |RTF_GATEWAY )) + == (RTF_ADDRCONF | RTF_DEFAULT | RTF_GATEWAY))net/ipv6/route.c void rt6_remove_prefsrc(struct inet6_ifaddr *ifp) · line 2253
Quoted 10 lines
net/ipv6/route.c +10
-0+ && ipv6_addr_equal(gateway, &rt->rt6i_gateway)) { +return -1 ; + }else if (((rt->rt6i_flags & (RTF_GATEWAY |RTF_CACHE )) + == (RTF_GATEWAY |RTF_CACHE )) + &&ipv6_addr_equal (gateway, &rt->rt6i_gateway)) { + rt->rt6i_flags |=RTF_REJECT ; + rt->dst.error = -ENETUNREACH ; + } +return 0 ; +}I am not so happy with that but have not tried that.
Quoted 8 lines
The Destination Cache you quote from the RFC (if you follow 7.3.3.) actually refers to the neighbouring subsystem, where we would need to generate subsequent errors in case we try to forward a packet through a this particular router.
The reason why I am not that happy is, that the semantics when neighbour nodes are cleared is well
defined but we don't have that semantics when thosert6_nodesget cleared up. E.g. consider a router which just temporarily switches forwarding off and on.I guess we need to inspect
NTF_ROUTERflag in the output path somehow. :/
Why we need to inspect NTF_ROUTER flag?
In my opinion, the problem is that we can't use the neighbour node as next hop.
Actually, after a node switches from being a router to being a host, we should perform next-hop determination rather than continue sending traffic to the former router, so we could just delete those Destination Cache entries.
You can refer to the below:
RFC 4861 states in 6.3.5:
Whenever the Lifetime of an entry in the Default Router List expires, that entry is discarded. When removing a router from the Default Router list, the node MUST update the Destination Cache in such a way that all entries using the router perform next-hop determination again rather than continue sending traffic to the (deleted) router.
Thanks,
Duan
Quoted 10 lines
Greetings,
Hannes
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
.
David Miller
maintainerFrom: Duan Jiong <[email protected]>
Date: Fri, 9 May 2014 11:24:36 +0800
Quoted 1 line
+/*remove routers and update dst entries when gateway turn into host.*/
This comment is poorly formatted.
Please put a space after "/*", capitalize "Remove" and place a space before "*/" at the end of the comment.
net/ipv6/route.c void rt6_remove_prefsrc(struct inet6_ifaddr *ifp) · line 2244
Quoted 7 lines
net/ipv6/route.c +7
-0+static int fib6_clean_tohost (struct rt6_info *rt,void *arg) +{ +struct in6_addr *gateway = (struct in6_addr *)arg; + +if (((rt->rt6i_flags & (RTF_ADDRCONF |RTF_DEFAULT |RTF_GATEWAY )) + == (RTF_ADDRCONF |RTF_DEFAULT |RTF_GATEWAY )) + &&ipv6_addr_equal (gateway, &rt->rt6i_gateway)) {
This conditional is poorly formatted:
net/ipv6/route.c void rt6_remove_prefsrc(struct inet6_ifaddr *ifp) · line 2248
Quoted 3 lines
net/ipv6/route.c +3
-0+ }else if (((rt->rt6i_flags & (RTF_GATEWAY |RTF_CACHE )) + == (RTF_GATEWAY |RTF_CACHE )) + &&ipv6_addr_equal (gateway, &rt->rt6i_gateway)) {
As is this one.
Never put operators at the beginning of a continuation line, rather put them at the end of the previous line. This includes "&&", "||", and "=="
Quoted 48 lines · Duan Jiong
Quoted 47 lines · Hannes Frederic Sowa
Quoted 29 lines · Duan Jiong
RFC 4861 states in 7.2.5:
The IsRouter flag in the cache entry MUST be set based on the
Router flag in the received advertisement. In those cases where the IsRouter flag changes from TRUE to FALSE as a result of this update, the node MUST remove that router from the Default Router List and update the Destination Cache entries for all destinations using that neighbor as a router as specified in Section 7.3.3. This is needed to detect when a node that is used as a router stops forwarding packets due to being configured as a host.Currently, when dealing with NA Message which IsRouter flag changes from TRUE to FALSE, the kernel only removes router from the Default Router List, and don't update the Destination Cache entries.
Now in order to update those Destination Cache entries, i introduce function
rt6_clean_tohost().[...]
net/ipv6/route.c +7
-0+/*remove routers and update dst entries when gateway turn into host.*/ +static int fib6_clean_tohost (struct rt6_info *rt,void *arg) +{ +struct in6_addr *gateway = (struct in6_addr *)arg; + +if (((rt->rt6i_flags & (RTF_ADDRCONF |RTF_DEFAULT |RTF_GATEWAY )) + == (RTF_ADDRCONF | RTF_DEFAULT | RTF_GATEWAY))net/ipv6/route.c void rt6_remove_prefsrc(struct inet6_ifaddr *ifp) · line 2253
Quoted 10 lines
net/ipv6/route.c +10
-0+ && ipv6_addr_equal(gateway, &rt->rt6i_gateway)) { +return -1 ; + }else if (((rt->rt6i_flags & (RTF_GATEWAY |RTF_CACHE )) + == (RTF_GATEWAY |RTF_CACHE )) + &&ipv6_addr_equal (gateway, &rt->rt6i_gateway)) { + rt->rt6i_flags |=RTF_REJECT ; + rt->dst.error = -ENETUNREACH ; + } +return 0 ; +}I am not so happy with that but have not tried that.
The Destination Cache you quote from the RFC (if you follow 7.3.3.) actually refers to the neighbouring subsystem, where we would need to generate subsequent errors in case we try to forward a packet through a this particular router.
Quoted 7 lines
Quoted 4 lines
The reason why I am not that happy is, that the semantics when neighbour nodes are cleared is well
defined but we don't have that semantics when thosert6_nodesget cleared up. E.g. consider a router which just temporarily switches forwarding off and on.I guess we need to inspect
NTF_ROUTERflag in the output path somehow. :/Why we need to inspect
NTF_ROUTERflag?
In my opinion, the problem is that we can't use the neighbour node as next hop.
I agree. I don't see a problem with returning -1 from the function but with the case where you originate errors from the routing table by setting rt->dst.error. These entries have a lifetime governed by the gc.
Greetings,
Hannes