Skip to content

Commit e8dfd42

Browse files
edumazetdavem330
authored andcommitted
ipv6: introduce dst_rt6_info() helper
Instead of (struct rt6_info *)dst casts, we can use : #define dst_rt6_info(_ptr) \ container_of_const(_ptr, struct rt6_info, dst) Some places needed missing const qualifiers : ip6_confirm_neigh(), ipv6_anycast_destination(), ipv6_unicast_destination(), has_gateway() v2: added missing parts (David Ahern) Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fac87d3 commit e8dfd42

File tree

30 files changed

+77
-86
lines changed

30 files changed

+77
-86
lines changed

drivers/infiniband/core/addr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,15 @@ static int dst_fetch_ha(const struct dst_entry *dst,
348348

349349
static bool has_gateway(const struct dst_entry *dst, sa_family_t family)
350350
{
351-
struct rtable *rt;
352-
struct rt6_info *rt6;
351+
const struct rtable *rt;
352+
const struct rt6_info *rt6;
353353

354354
if (family == AF_INET) {
355355
rt = container_of(dst, struct rtable, dst);
356356
return rt->rt_uses_gateway;
357357
}
358358

359-
rt6 = container_of(dst, struct rt6_info, dst);
359+
rt6 = dst_rt6_info(dst);
360360
return rt6->rt6i_flags & RTF_GATEWAY;
361361
}
362362

drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ mlxsw_sp_span_gretap6_route(const struct net_device *to_dev,
540540
if (!dst || dst->error)
541541
goto out;
542542

543-
rt6 = container_of(dst, struct rt6_info, dst);
543+
rt6 = dst_rt6_info(dst);
544544

545545
dev = dst->dev;
546546
*saddrp = fl6.saddr;

drivers/net/vrf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ static int vrf_finish_output6(struct net *net, struct sock *sk,
653653
skb->dev = dev;
654654

655655
rcu_read_lock();
656-
nexthop = rt6_nexthop((struct rt6_info *)dst, &ipv6_hdr(skb)->daddr);
656+
nexthop = rt6_nexthop(dst_rt6_info(dst), &ipv6_hdr(skb)->daddr);
657657
neigh = __ipv6_neigh_lookup_noref(dst->dev, nexthop);
658658
if (unlikely(!neigh))
659659
neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false);

drivers/net/vxlan/vxlan_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2513,7 +2513,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
25132513
}
25142514

25152515
if (!info) {
2516-
u32 rt6i_flags = ((struct rt6_info *)ndst)->rt6i_flags;
2516+
u32 rt6i_flags = dst_rt6_info(ndst)->rt6i_flags;
25172517

25182518
err = encap_bypass_if_local(skb, dev, vxlan, AF_INET6,
25192519
dst_port, ifindex, vni,

drivers/s390/net/qeth_core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ static inline struct dst_entry *qeth_dst_check_rcu(struct sk_buff *skb,
956956
struct dst_entry *dst = skb_dst(skb);
957957
struct rt6_info *rt;
958958

959-
rt = (struct rt6_info *) dst;
959+
rt = dst_rt6_info(dst);
960960
if (dst) {
961961
if (proto == htons(ETH_P_IPV6))
962962
dst = dst_check(dst, rt6_get_cookie(rt));
@@ -978,7 +978,7 @@ static inline __be32 qeth_next_hop_v4_rcu(struct sk_buff *skb,
978978
static inline struct in6_addr *qeth_next_hop_v6_rcu(struct sk_buff *skb,
979979
struct dst_entry *dst)
980980
{
981-
struct rt6_info *rt = (struct rt6_info *) dst;
981+
struct rt6_info *rt = dst_rt6_info(dst);
982982

983983
if (rt && !ipv6_addr_any(&rt->rt6i_gateway))
984984
return &rt->rt6i_gateway;

include/net/ip6_fib.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,11 @@ struct fib6_result {
234234
for (rt = (w)->leaf; rt; \
235235
rt = rcu_dereference_protected(rt->fib6_next, 1))
236236

237-
static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
237+
#define dst_rt6_info(_ptr) container_of_const(_ptr, struct rt6_info, dst)
238+
239+
static inline struct inet6_dev *ip6_dst_idev(const struct dst_entry *dst)
238240
{
239-
return ((struct rt6_info *)dst)->rt6i_idev;
241+
return dst_rt6_info(dst)->rt6i_idev;
240242
}
241243

242244
static inline bool fib6_requires_src(const struct fib6_info *rt)

include/net/ip6_route.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,11 @@ void rt6_uncached_list_del(struct rt6_info *rt);
210210
static inline const struct rt6_info *skb_rt6_info(const struct sk_buff *skb)
211211
{
212212
const struct dst_entry *dst = skb_dst(skb);
213-
const struct rt6_info *rt6 = NULL;
214213

215214
if (dst)
216-
rt6 = container_of(dst, struct rt6_info, dst);
215+
return dst_rt6_info(dst);
217216

218-
return rt6;
217+
return NULL;
219218
}
220219

221220
/*
@@ -227,7 +226,7 @@ static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
227226
{
228227
struct ipv6_pinfo *np = inet6_sk(sk);
229228

230-
np->dst_cookie = rt6_get_cookie((struct rt6_info *)dst);
229+
np->dst_cookie = rt6_get_cookie(dst_rt6_info(dst));
231230
sk_setup_caps(sk, dst);
232231
np->daddr_cache = daddr;
233232
#ifdef CONFIG_IPV6_SUBTREES
@@ -240,15 +239,15 @@ void ip6_sk_dst_store_flow(struct sock *sk, struct dst_entry *dst,
240239

241240
static inline bool ipv6_unicast_destination(const struct sk_buff *skb)
242241
{
243-
struct rt6_info *rt = (struct rt6_info *) skb_dst(skb);
242+
const struct rt6_info *rt = dst_rt6_info(skb_dst(skb));
244243

245244
return rt->rt6i_flags & RTF_LOCAL;
246245
}
247246

248247
static inline bool ipv6_anycast_destination(const struct dst_entry *dst,
249248
const struct in6_addr *daddr)
250249
{
251-
struct rt6_info *rt = (struct rt6_info *)dst;
250+
const struct rt6_info *rt = dst_rt6_info(dst);
252251

253252
return rt->rt6i_flags & RTF_ANYCAST ||
254253
(rt->rt6i_dst.plen < 127 &&

net/bluetooth/6lowpan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_btle_dev *dev,
133133
struct in6_addr *daddr,
134134
struct sk_buff *skb)
135135
{
136-
struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
136+
struct rt6_info *rt = dst_rt6_info(skb_dst(skb));
137137
int count = atomic_read(&dev->peer_count);
138138
const struct in6_addr *nexthop;
139139
struct lowpan_peer *peer;

net/core/dst_cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void dst_cache_set_ip6(struct dst_cache *dst_cache, struct dst_entry *dst,
112112

113113
idst = this_cpu_ptr(dst_cache->cache);
114114
dst_cache_per_cpu_dst_set(this_cpu_ptr(dst_cache->cache), dst,
115-
rt6_get_cookie((struct rt6_info *)dst));
115+
rt6_get_cookie(dst_rt6_info(dst)));
116116
idst->in6_saddr = *saddr;
117117
}
118118
EXPORT_SYMBOL_GPL(dst_cache_set_ip6);

net/core/filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ static int bpf_out_neigh_v6(struct net *net, struct sk_buff *skb,
22152215
rcu_read_lock();
22162216
if (!nh) {
22172217
dst = skb_dst(skb);
2218-
nexthop = rt6_nexthop(container_of(dst, struct rt6_info, dst),
2218+
nexthop = rt6_nexthop(dst_rt6_info(dst),
22192219
&ipv6_hdr(skb)->daddr);
22202220
} else {
22212221
nexthop = &nh->ipv6_nh;

net/ipv4/ip_tunnel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ static int tnl_update_pmtu(struct net_device *dev, struct sk_buff *skb,
543543
struct rt6_info *rt6;
544544
__be32 daddr;
545545

546-
rt6 = skb_valid_dst(skb) ? (struct rt6_info *)skb_dst(skb) :
546+
rt6 = skb_valid_dst(skb) ? dst_rt6_info(skb_dst(skb)) :
547547
NULL;
548548
daddr = md ? dst : tunnel->parms.iph.daddr;
549549

net/ipv6/icmp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static bool icmpv6_xrlim_allow(struct sock *sk, u8 type,
212212
} else if (dst->dev && (dst->dev->flags&IFF_LOOPBACK)) {
213213
res = true;
214214
} else {
215-
struct rt6_info *rt = (struct rt6_info *)dst;
215+
struct rt6_info *rt = dst_rt6_info(dst);
216216
int tmo = net->ipv6.sysctl.icmpv6_time;
217217
struct inet_peer *peer;
218218

@@ -241,7 +241,7 @@ static bool icmpv6_rt_has_prefsrc(struct sock *sk, u8 type,
241241

242242
dst = ip6_route_output(net, sk, fl6);
243243
if (!dst->error) {
244-
struct rt6_info *rt = (struct rt6_info *)dst;
244+
struct rt6_info *rt = dst_rt6_info(dst);
245245
struct in6_addr prefsrc;
246246

247247
rt6_get_prefsrc(rt, &prefsrc);
@@ -616,7 +616,7 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
616616
if (ip6_append_data(sk, icmpv6_getfrag, &msg,
617617
len + sizeof(struct icmp6hdr),
618618
sizeof(struct icmp6hdr),
619-
&ipc6, &fl6, (struct rt6_info *)dst,
619+
&ipc6, &fl6, dst_rt6_info(dst),
620620
MSG_DONTWAIT)) {
621621
ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTERRORS);
622622
ip6_flush_pending_frames(sk);
@@ -803,7 +803,7 @@ static enum skb_drop_reason icmpv6_echo_reply(struct sk_buff *skb)
803803
if (ip6_append_data(sk, icmpv6_getfrag, &msg,
804804
skb->len + sizeof(struct icmp6hdr),
805805
sizeof(struct icmp6hdr), &ipc6, &fl6,
806-
(struct rt6_info *)dst, MSG_DONTWAIT)) {
806+
dst_rt6_info(dst), MSG_DONTWAIT)) {
807807
__ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTERRORS);
808808
ip6_flush_pending_frames(sk);
809809
} else {

net/ipv6/ila/ila_lwt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static inline struct ila_params *ila_params_lwtunnel(
3838
static int ila_output(struct net *net, struct sock *sk, struct sk_buff *skb)
3939
{
4040
struct dst_entry *orig_dst = skb_dst(skb);
41-
struct rt6_info *rt = (struct rt6_info *)orig_dst;
41+
struct rt6_info *rt = dst_rt6_info(orig_dst);
4242
struct ila_lwt *ilwt = ila_lwt_lwtunnel(orig_dst->lwtstate);
4343
struct dst_entry *dst;
4444
int err = -EINVAL;
@@ -70,7 +70,7 @@ static int ila_output(struct net *net, struct sock *sk, struct sk_buff *skb)
7070
memset(&fl6, 0, sizeof(fl6));
7171
fl6.flowi6_oif = orig_dst->dev->ifindex;
7272
fl6.flowi6_iif = LOOPBACK_IFINDEX;
73-
fl6.daddr = *rt6_nexthop((struct rt6_info *)orig_dst,
73+
fl6.daddr = *rt6_nexthop(dst_rt6_info(orig_dst),
7474
&ip6h->daddr);
7575

7676
dst = ip6_route_output(net, NULL, &fl6);

net/ipv6/ip6_output.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *
120120
IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUT, skb->len);
121121

122122
rcu_read_lock();
123-
nexthop = rt6_nexthop((struct rt6_info *)dst, daddr);
123+
nexthop = rt6_nexthop(dst_rt6_info(dst), daddr);
124124
neigh = __ipv6_neigh_lookup_noref(dev, nexthop);
125125

126126
if (unlikely(IS_ERR_OR_NULL(neigh))) {
@@ -599,7 +599,7 @@ int ip6_forward(struct sk_buff *skb)
599599
* send a redirect.
600600
*/
601601

602-
rt = (struct rt6_info *) dst;
602+
rt = dst_rt6_info(dst);
603603
if (rt->rt6i_flags & RTF_GATEWAY)
604604
target = &rt->rt6i_gateway;
605605
else
@@ -856,7 +856,7 @@ int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
856856
int (*output)(struct net *, struct sock *, struct sk_buff *))
857857
{
858858
struct sk_buff *frag;
859-
struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
859+
struct rt6_info *rt = dst_rt6_info(skb_dst(skb));
860860
struct ipv6_pinfo *np = skb->sk && !dev_recursion_level() ?
861861
inet6_sk(skb->sk) : NULL;
862862
bool mono_delivery_time = skb->mono_delivery_time;
@@ -1063,7 +1063,7 @@ static struct dst_entry *ip6_sk_dst_check(struct sock *sk,
10631063
return NULL;
10641064
}
10651065

1066-
rt = (struct rt6_info *)dst;
1066+
rt = dst_rt6_info(dst);
10671067
/* Yes, checking route validity in not connected
10681068
* case is not very simple. Take into account,
10691069
* that we do not support routing by source, TOS,
@@ -1118,7 +1118,7 @@ static int ip6_dst_lookup_tail(struct net *net, const struct sock *sk,
11181118
struct rt6_info *rt;
11191119

11201120
*dst = ip6_route_output(net, sk, fl6);
1121-
rt = (*dst)->error ? NULL : (struct rt6_info *)*dst;
1121+
rt = (*dst)->error ? NULL : dst_rt6_info(*dst);
11221122

11231123
rcu_read_lock();
11241124
from = rt ? rcu_dereference(rt->from) : NULL;
@@ -1159,7 +1159,7 @@ static int ip6_dst_lookup_tail(struct net *net, const struct sock *sk,
11591159
* dst entry and replace it instead with the
11601160
* dst entry of the nexthop router
11611161
*/
1162-
rt = (struct rt6_info *) *dst;
1162+
rt = dst_rt6_info(*dst);
11631163
rcu_read_lock();
11641164
n = __ipv6_neigh_lookup_noref(rt->dst.dev,
11651165
rt6_nexthop(rt, &fl6->daddr));
@@ -1423,7 +1423,7 @@ static int __ip6_append_data(struct sock *sk,
14231423
int offset = 0;
14241424
bool zc = false;
14251425
u32 tskey = 0;
1426-
struct rt6_info *rt = (struct rt6_info *)cork->dst;
1426+
struct rt6_info *rt = dst_rt6_info(cork->dst);
14271427
bool paged, hold_tskey, extra_uref = false;
14281428
struct ipv6_txoptions *opt = v6_cork->opt;
14291429
int csummode = CHECKSUM_NONE;
@@ -1877,7 +1877,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk,
18771877
struct net *net = sock_net(sk);
18781878
struct ipv6hdr *hdr;
18791879
struct ipv6_txoptions *opt = v6_cork->opt;
1880-
struct rt6_info *rt = (struct rt6_info *)cork->base.dst;
1880+
struct rt6_info *rt = dst_rt6_info(cork->base.dst);
18811881
struct flowi6 *fl6 = &cork->fl.u.ip6;
18821882
unsigned char proto = fl6->flowi6_proto;
18831883

@@ -1949,7 +1949,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk,
19491949
int ip6_send_skb(struct sk_buff *skb)
19501950
{
19511951
struct net *net = sock_net(skb->sk);
1952-
struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
1952+
struct rt6_info *rt = dst_rt6_info(skb_dst(skb));
19531953
int err;
19541954

19551955
err = ip6_local_out(net, skb->sk, skb);

net/ipv6/ip6mr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ int ip6mr_get_route(struct net *net, struct sk_buff *skb, struct rtmsg *rtm,
22732273
int err;
22742274
struct mr_table *mrt;
22752275
struct mfc6_cache *cache;
2276-
struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
2276+
struct rt6_info *rt = dst_rt6_info(skb_dst(skb));
22772277

22782278
mrt = ip6mr_get_table(net, RT6_TABLE_DFLT);
22792279
if (!mrt)

net/ipv6/ndisc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target)
17221722
if (IS_ERR(dst))
17231723
return;
17241724

1725-
rt = (struct rt6_info *) dst;
1725+
rt = dst_rt6_info(dst);
17261726

17271727
if (rt->rt6i_flags & RTF_GATEWAY) {
17281728
ND_PRINTK(2, warn,

net/ipv6/ping.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
154154
dst = ip6_sk_dst_lookup_flow(sk, &fl6, daddr, false);
155155
if (IS_ERR(dst))
156156
return PTR_ERR(dst);
157-
rt = (struct rt6_info *) dst;
157+
rt = dst_rt6_info(dst);
158158

159159
if (!fl6.flowi6_oif && ipv6_addr_is_multicast(&fl6.daddr))
160160
fl6.flowi6_oif = READ_ONCE(np->mcast_oif);

net/ipv6/raw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,
598598
struct ipv6hdr *iph;
599599
struct sk_buff *skb;
600600
int err;
601-
struct rt6_info *rt = (struct rt6_info *)*dstp;
601+
struct rt6_info *rt = dst_rt6_info(*dstp);
602602
int hlen = LL_RESERVED_SPACE(rt->dst.dev);
603603
int tlen = rt->dst.dev->needed_tailroom;
604604

@@ -917,7 +917,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
917917
ipc6.opt = opt;
918918
lock_sock(sk);
919919
err = ip6_append_data(sk, raw6_getfrag, &rfv,
920-
len, 0, &ipc6, &fl6, (struct rt6_info *)dst,
920+
len, 0, &ipc6, &fl6, dst_rt6_info(dst),
921921
msg->msg_flags);
922922

923923
if (err)

0 commit comments

Comments
 (0)