Skip to content

Commit 3125f8b

Browse files
Julian Anastasovgregkh
authored andcommitted
ipv6: fill rt6i_gateway with nexthop address
[ Upstream commit 550bab4 ] Make sure rt6i_gateway contains nexthop information in all routes returned from lookup or when routes are directly attached to skb for generated ICMP packets. The effect of this patch should be a faster version of rt6_nexthop() and the consideration of local addresses as nexthop. Signed-off-by: Julian Anastasov <ja@ssi.bg> Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0c80c90 commit 3125f8b

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎include/net/ip6_route.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,9 @@ static inline int ip6_skb_dst_mtu(struct sk_buff *skb)
196196
skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb));
197197
}
198198

199-
static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt, struct in6_addr *dest)
199+
static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt)
200200
{
201-
if (rt->rt6i_flags & RTF_GATEWAY || !ipv6_addr_any(&rt->rt6i_gateway))
202-
return &rt->rt6i_gateway;
203-
return dest;
201+
return &rt->rt6i_gateway;
204202
}
205203

206204
#endif

‎net/ipv6/ip6_output.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static int ip6_finish_output2(struct sk_buff *skb)
130130
}
131131

132132
rcu_read_lock_bh();
133-
nexthop = rt6_nexthop((struct rt6_info *)dst, &ipv6_hdr(skb)->daddr);
133+
nexthop = rt6_nexthop((struct rt6_info *)dst);
134134
neigh = __ipv6_neigh_lookup_noref(dst->dev, nexthop);
135135
if (unlikely(!neigh))
136136
neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false);
@@ -899,7 +899,7 @@ static int ip6_dst_lookup_tail(struct sock *sk,
899899
*/
900900
rt = (struct rt6_info *) *dst;
901901
rcu_read_lock_bh();
902-
n = __ipv6_neigh_lookup_noref(rt->dst.dev, rt6_nexthop(rt, &fl6->daddr));
902+
n = __ipv6_neigh_lookup_noref(rt->dst.dev, rt6_nexthop(rt));
903903
err = n && !(n->nud_state & NUD_VALID) ? -EINVAL : 0;
904904
rcu_read_unlock_bh();
905905

‎net/ipv6/route.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,6 @@ static struct rt6_info *rt6_alloc_cow(struct rt6_info *ort,
852852
if (ort->rt6i_dst.plen != 128 &&
853853
ipv6_addr_equal(&ort->rt6i_dst.addr, daddr))
854854
rt->rt6i_flags |= RTF_ANYCAST;
855-
rt->rt6i_gateway = *daddr;
856855
}
857856

858857
rt->rt6i_flags |= RTF_CACHE;
@@ -1270,6 +1269,7 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
12701269
rt->dst.flags |= DST_HOST;
12711270
rt->dst.output = ip6_output;
12721271
atomic_set(&rt->dst.__refcnt, 1);
1272+
rt->rt6i_gateway = fl6->daddr;
12731273
rt->rt6i_dst.addr = fl6->daddr;
12741274
rt->rt6i_dst.plen = 128;
12751275
rt->rt6i_idev = idev;
@@ -1824,7 +1824,10 @@ static struct rt6_info *ip6_rt_copy(struct rt6_info *ort,
18241824
in6_dev_hold(rt->rt6i_idev);
18251825
rt->dst.lastuse = jiffies;
18261826

1827-
rt->rt6i_gateway = ort->rt6i_gateway;
1827+
if (ort->rt6i_flags & RTF_GATEWAY)
1828+
rt->rt6i_gateway = ort->rt6i_gateway;
1829+
else
1830+
rt->rt6i_gateway = *dest;
18281831
rt->rt6i_flags = ort->rt6i_flags;
18291832
if ((ort->rt6i_flags & (RTF_DEFAULT | RTF_ADDRCONF)) ==
18301833
(RTF_DEFAULT | RTF_ADDRCONF))
@@ -2111,6 +2114,7 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
21112114
else
21122115
rt->rt6i_flags |= RTF_LOCAL;
21132116

2117+
rt->rt6i_gateway = *addr;
21142118
rt->rt6i_dst.addr = *addr;
21152119
rt->rt6i_dst.plen = 128;
21162120
rt->rt6i_table = fib6_get_table(net, RT6_TABLE_LOCAL);

0 commit comments

Comments
 (0)