Skip to content

Commit 2647a9b

Browse files
iamkafaidavem330
authored andcommitted
ipv6: Remove external dependency on rt6i_gateway and RTF_ANYCAST
When creating a RTF_CACHE route, RTF_ANYCAST is set based on rt6i_dst. Also, rt6i_gateway is always set to the nexthop while the nexthop could be a gateway or the rt6i_dst.addr. After removing the rt6i_dst and rt6i_src dependency in the last patch, we also need to stop the caller from depending on rt6i_gateway and RTF_ANYCAST. Signed-off-by: Martin KaFai Lau <[email protected]> Cc: Hannes Frederic Sowa <[email protected]> Cc: Steffen Klassert <[email protected]> Cc: Julian Anastasov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fd0273d commit 2647a9b

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

include/net/ip6_route.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,14 @@ static inline bool ipv6_unicast_destination(const struct sk_buff *skb)
163163
return rt->rt6i_flags & RTF_LOCAL;
164164
}
165165

166-
static inline bool ipv6_anycast_destination(const struct sk_buff *skb)
166+
static inline bool ipv6_anycast_destination(const struct dst_entry *dst,
167+
const struct in6_addr *daddr)
167168
{
168-
struct rt6_info *rt = (struct rt6_info *) skb_dst(skb);
169+
struct rt6_info *rt = (struct rt6_info *)dst;
169170

170-
return rt->rt6i_flags & RTF_ANYCAST;
171+
return rt->rt6i_flags & RTF_ANYCAST ||
172+
(rt->rt6i_dst.plen != 128 &&
173+
ipv6_addr_equal(&rt->rt6i_dst.addr, daddr));
171174
}
172175

173176
int ip6_fragment(struct sock *sk, struct sk_buff *skb,
@@ -194,9 +197,15 @@ static inline bool ip6_sk_ignore_df(const struct sock *sk)
194197
inet6_sk(sk)->pmtudisc == IPV6_PMTUDISC_OMIT;
195198
}
196199

197-
static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt)
200+
static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt,
201+
struct in6_addr *daddr)
198202
{
199-
return &rt->rt6i_gateway;
203+
if (rt->rt6i_flags & RTF_GATEWAY)
204+
return &rt->rt6i_gateway;
205+
else if (rt->rt6i_flags & RTF_CACHE)
206+
return &rt->rt6i_dst.addr;
207+
else
208+
return daddr;
200209
}
201210

202211
#endif

net/bluetooth/6lowpan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_dev *dev,
192192
if (ipv6_addr_any(nexthop))
193193
return NULL;
194194
} else {
195-
nexthop = rt6_nexthop(rt);
195+
nexthop = rt6_nexthop(rt, daddr);
196196

197197
/* We need to remember the address because it is needed
198198
* by bt_xmit() when sending the packet. In bt_xmit(), the

net/ipv6/icmp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static struct dst_entry *icmpv6_route_lookup(struct net *net,
337337
* We won't send icmp if the destination is known
338338
* anycast.
339339
*/
340-
if (((struct rt6_info *)dst)->rt6i_flags & RTF_ANYCAST) {
340+
if (ipv6_anycast_destination(dst, &fl6->daddr)) {
341341
net_dbg_ratelimited("icmp6_send: acast source\n");
342342
dst_release(dst);
343343
return ERR_PTR(-EINVAL);
@@ -564,7 +564,7 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
564564

565565
if (!ipv6_unicast_destination(skb) &&
566566
!(net->ipv6.sysctl.anycast_src_echo_reply &&
567-
ipv6_anycast_destination(skb)))
567+
ipv6_anycast_destination(skb_dst(skb), saddr)))
568568
saddr = NULL;
569569

570570
memcpy(&tmp_hdr, icmph, sizeof(tmp_hdr));

net/ipv6/ip6_output.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static int ip6_finish_output2(struct sock *sk, struct sk_buff *skb)
105105
}
106106

107107
rcu_read_lock_bh();
108-
nexthop = rt6_nexthop((struct rt6_info *)dst);
108+
nexthop = rt6_nexthop((struct rt6_info *)dst, &ipv6_hdr(skb)->daddr);
109109
neigh = __ipv6_neigh_lookup_noref(dst->dev, nexthop);
110110
if (unlikely(!neigh))
111111
neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false);
@@ -934,7 +934,8 @@ static int ip6_dst_lookup_tail(struct sock *sk,
934934
*/
935935
rt = (struct rt6_info *) *dst;
936936
rcu_read_lock_bh();
937-
n = __ipv6_neigh_lookup_noref(rt->dst.dev, rt6_nexthop(rt));
937+
n = __ipv6_neigh_lookup_noref(rt->dst.dev,
938+
rt6_nexthop(rt, &fl6->daddr));
938939
err = n && !(n->nud_state & NUD_VALID) ? -EINVAL : 0;
939940
rcu_read_unlock_bh();
940941

net/ipv6/route.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,11 +1945,7 @@ static struct rt6_info *ip6_rt_copy(struct rt6_info *ort,
19451945
if (rt->rt6i_idev)
19461946
in6_dev_hold(rt->rt6i_idev);
19471947
rt->dst.lastuse = jiffies;
1948-
1949-
if (ort->rt6i_flags & RTF_GATEWAY)
1950-
rt->rt6i_gateway = ort->rt6i_gateway;
1951-
else
1952-
rt->rt6i_gateway = *dest;
1948+
rt->rt6i_gateway = ort->rt6i_gateway;
19531949
rt->rt6i_flags = ort->rt6i_flags;
19541950
rt6_set_from(rt, ort);
19551951
rt->rt6i_metric = 0;

net/netfilter/nf_conntrack_h323_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ static int callforward_do_filter(struct net *net,
779779
flowi6_to_flowi(&fl1), false)) {
780780
if (!afinfo->route(net, (struct dst_entry **)&rt2,
781781
flowi6_to_flowi(&fl2), false)) {
782-
if (ipv6_addr_equal(rt6_nexthop(rt1),
783-
rt6_nexthop(rt2)) &&
782+
if (ipv6_addr_equal(rt6_nexthop(rt1, &fl1.daddr),
783+
rt6_nexthop(rt2, &fl2.daddr)) &&
784784
rt1->dst.dev == rt2->dst.dev)
785785
ret = 1;
786786
dst_release(&rt2->dst);

net/netfilter/xt_addrtype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static u32 match_lookup_rt6(struct net *net, const struct net_device *dev,
7373

7474
if (dev == NULL && rt->rt6i_flags & RTF_LOCAL)
7575
ret |= XT_ADDRTYPE_LOCAL;
76-
if (rt->rt6i_flags & RTF_ANYCAST)
76+
if (ipv6_anycast_destination((struct dst_entry *)rt, addr))
7777
ret |= XT_ADDRTYPE_ANYCAST;
7878

7979
dst_release(&rt->dst);

0 commit comments

Comments
 (0)