Commit 04e0f78f authored by David Ahern's avatar David Ahern Committed by Greg Kroah-Hartman

net: ipv6: Compare lwstate in detecting duplicate nexthops


[ Upstream commit f06b7549 ]

Lennert reported a failure to add different mpls encaps in a multipath
route:

  $ ip -6 route add 1234::/16 \
        nexthop encap mpls 10 via fe80::1 dev ens3 \
        nexthop encap mpls 20 via fe80::1 dev ens3
  RTNETLINK answers: File exists

The problem is that the duplicate nexthop detection does not compare
lwtunnel configuration. Add it.

Fixes: 19e42e45 ("ipv6: support for fib route lwtunnel encap attributes")
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Reported-by: default avatarJoão Taveira Araújo <joao.taveira@gmail.com>
Reported-by: default avatarLennert Buytenhek <buytenh@wantstofly.org>
Acked-by: default avatarRoopa Prabhu <roopa@cumulusnetworks.com>
Tested-by: default avatarLennert Buytenhek <buytenh@wantstofly.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5269faa4
...@@ -22,6 +22,7 @@ struct route_info { ...@@ -22,6 +22,7 @@ struct route_info {
#include <net/flow.h> #include <net/flow.h>
#include <net/ip6_fib.h> #include <net/ip6_fib.h>
#include <net/sock.h> #include <net/sock.h>
#include <net/lwtunnel.h>
#include <linux/ip.h> #include <linux/ip.h>
#include <linux/ipv6.h> #include <linux/ipv6.h>
#include <linux/route.h> #include <linux/route.h>
...@@ -233,4 +234,11 @@ static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt, ...@@ -233,4 +234,11 @@ static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt,
return daddr; return daddr;
} }
static inline bool rt6_duplicate_nexthop(struct rt6_info *a, struct rt6_info *b)
{
return a->dst.dev == b->dst.dev &&
a->rt6i_idev == b->rt6i_idev &&
ipv6_addr_equal(&a->rt6i_gateway, &b->rt6i_gateway) &&
!lwtunnel_cmp_encap(a->dst.lwtstate, b->dst.lwtstate);
}
#endif #endif
...@@ -784,10 +784,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt, ...@@ -784,10 +784,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
goto next_iter; goto next_iter;
} }
if (iter->dst.dev == rt->dst.dev && if (rt6_duplicate_nexthop(iter, rt)) {
iter->rt6i_idev == rt->rt6i_idev &&
ipv6_addr_equal(&iter->rt6i_gateway,
&rt->rt6i_gateway)) {
if (rt->rt6i_nsiblings) if (rt->rt6i_nsiblings)
rt->rt6i_nsiblings = 0; rt->rt6i_nsiblings = 0;
if (!(iter->rt6i_flags & RTF_EXPIRES)) if (!(iter->rt6i_flags & RTF_EXPIRES))
......
...@@ -3047,17 +3047,11 @@ static int ip6_route_info_append(struct list_head *rt6_nh_list, ...@@ -3047,17 +3047,11 @@ static int ip6_route_info_append(struct list_head *rt6_nh_list,
struct rt6_info *rt, struct fib6_config *r_cfg) struct rt6_info *rt, struct fib6_config *r_cfg)
{ {
struct rt6_nh *nh; struct rt6_nh *nh;
struct rt6_info *rtnh;
int err = -EEXIST; int err = -EEXIST;
list_for_each_entry(nh, rt6_nh_list, next) { list_for_each_entry(nh, rt6_nh_list, next) {
/* check if rt6_info already exists */ /* check if rt6_info already exists */
rtnh = nh->rt6_info; if (rt6_duplicate_nexthop(nh->rt6_info, rt))
if (rtnh->dst.dev == rt->dst.dev &&
rtnh->rt6i_idev == rt->rt6i_idev &&
ipv6_addr_equal(&rtnh->rt6i_gateway,
&rt->rt6i_gateway))
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment