Skip to content

Commit badbe56

Browse files
qsngregkh
authored andcommitted
net: ipv6_stub: use ip6_dst_lookup_flow instead of ip6_dst_lookup
commit 6c8991f upstream. ipv6_stub uses the ip6_dst_lookup function to allow other modules to perform IPv6 lookups. However, this function skips the XFRM layer entirely. All users of ipv6_stub->ip6_dst_lookup use ip_route_output_flow (via the ip_route_output_key and ip_route_output helpers) for their IPv4 lookups, which calls xfrm_lookup_route(). This patch fixes this inconsistent behavior by switching the stub to ip6_dst_lookup_flow, which also calls xfrm_lookup_route(). This requires some changes in all the callers, as these two functions take different arguments and have different return types. Fixes: 5f81bd2 ("ipv6: export a stub for IPv6 symbols used by vxlan") Reported-by: Xiumei Mu <[email protected]> Signed-off-by: Sabrina Dubroca <[email protected]> Signed-off-by: David S. Miller <[email protected]> [bwh: Backported to 4.9: - Drop changes in lwt_bpf.c and mlx5 - Initialise "dst" in drivers/infiniband/core/addr.c:addr_resolve() to avoid introducing a spurious "may be used uninitialised" warning - Adjust filename, context, indentation] Signed-off-by: Ben Hutchings <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 5cc5fa7 commit badbe56

File tree

9 files changed

+36
-29
lines changed

9 files changed

+36
-29
lines changed

drivers/infiniband/core/addr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,16 +453,15 @@ static int addr6_resolve(struct sockaddr_in6 *src_in,
453453
struct flowi6 fl6;
454454
struct dst_entry *dst;
455455
struct rt6_info *rt;
456-
int ret;
457456

458457
memset(&fl6, 0, sizeof fl6);
459458
fl6.daddr = dst_in->sin6_addr;
460459
fl6.saddr = src_in->sin6_addr;
461460
fl6.flowi6_oif = addr->bound_dev_if;
462461

463-
ret = ipv6_stub->ipv6_dst_lookup(addr->net, NULL, &dst, &fl6);
464-
if (ret < 0)
465-
return ret;
462+
dst = ipv6_stub->ipv6_dst_lookup_flow(addr->net, NULL, &fl6, NULL);
463+
if (IS_ERR(dst))
464+
return PTR_ERR(dst);
466465

467466
rt = (struct rt6_info *)dst;
468467
if (ipv6_addr_any(&src_in->sin6_addr)) {
@@ -552,6 +551,7 @@ static int addr_resolve(struct sockaddr *src_in,
552551
const struct sockaddr_in6 *dst_in6 =
553552
(const struct sockaddr_in6 *)dst_in;
554553

554+
dst = NULL;
555555
ret = addr6_resolve((struct sockaddr_in6 *)src_in,
556556
dst_in6, addr,
557557
&dst);

drivers/infiniband/sw/rxe/rxe_net.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,12 @@ static struct dst_entry *rxe_find_route6(struct net_device *ndev,
182182
memcpy(&fl6.daddr, daddr, sizeof(*daddr));
183183
fl6.flowi6_proto = IPPROTO_UDP;
184184

185-
if (unlikely(ipv6_stub->ipv6_dst_lookup(sock_net(recv_sockets.sk6->sk),
186-
recv_sockets.sk6->sk, &ndst, &fl6))) {
185+
ndst = ipv6_stub->ipv6_dst_lookup_flow(sock_net(recv_sockets.sk6->sk),
186+
recv_sockets.sk6->sk, &fl6,
187+
NULL);
188+
if (unlikely(IS_ERR(ndst))) {
187189
pr_err_ratelimited("no route to %pI6\n", daddr);
188-
goto put;
190+
return NULL;
189191
}
190192

191193
if (unlikely(ndst->error)) {

drivers/net/geneve.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,9 @@ static struct dst_entry *geneve_get_v6_dst(struct sk_buff *skb,
835835
return dst;
836836
}
837837

838-
if (ipv6_stub->ipv6_dst_lookup(geneve->net, gs6->sock->sk, &dst, fl6)) {
838+
dst = ipv6_stub->ipv6_dst_lookup_flow(geneve->net, gs6->sock->sk, fl6,
839+
NULL);
840+
if (IS_ERR(dst)) {
839841
netdev_dbg(dev, "no route to %pI6\n", &fl6->daddr);
840842
return ERR_PTR(-ENETUNREACH);
841843
}

drivers/net/vxlan.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,6 @@ static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan,
18811881
bool use_cache = ip_tunnel_dst_cache_usable(skb, info);
18821882
struct dst_entry *ndst;
18831883
struct flowi6 fl6;
1884-
int err;
18851884

18861885
if (!sock6)
18871886
return ERR_PTR(-EIO);
@@ -1902,11 +1901,10 @@ static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan,
19021901
fl6.flowi6_mark = skb->mark;
19031902
fl6.flowi6_proto = IPPROTO_UDP;
19041903

1905-
err = ipv6_stub->ipv6_dst_lookup(vxlan->net,
1906-
sock6->sock->sk,
1907-
&ndst, &fl6);
1908-
if (err < 0)
1909-
return ERR_PTR(err);
1904+
ndst = ipv6_stub->ipv6_dst_lookup_flow(vxlan->net, sock6->sock->sk,
1905+
&fl6, NULL);
1906+
if (unlikely(IS_ERR(ndst)))
1907+
return ERR_PTR(-ENETUNREACH);
19101908

19111909
*saddr = fl6.saddr;
19121910
if (use_cache)

include/net/addrconf.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ struct ipv6_stub {
206206
const struct in6_addr *addr);
207207
int (*ipv6_sock_mc_drop)(struct sock *sk, int ifindex,
208208
const struct in6_addr *addr);
209-
int (*ipv6_dst_lookup)(struct net *net, struct sock *sk,
210-
struct dst_entry **dst, struct flowi6 *fl6);
209+
struct dst_entry *(*ipv6_dst_lookup_flow)(struct net *net,
210+
const struct sock *sk,
211+
struct flowi6 *fl6,
212+
const struct in6_addr *final_dst);
211213
void (*udpv6_encap_enable)(void);
212214
void (*ndisc_send_na)(struct net_device *dev, const struct in6_addr *daddr,
213215
const struct in6_addr *solicited_addr,

net/ipv6/addrconf_core.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,16 @@ int inet6addr_notifier_call_chain(unsigned long val, void *v)
107107
}
108108
EXPORT_SYMBOL(inet6addr_notifier_call_chain);
109109

110-
static int eafnosupport_ipv6_dst_lookup(struct net *net, struct sock *u1,
111-
struct dst_entry **u2,
112-
struct flowi6 *u3)
110+
static struct dst_entry *eafnosupport_ipv6_dst_lookup_flow(struct net *net,
111+
const struct sock *sk,
112+
struct flowi6 *fl6,
113+
const struct in6_addr *final_dst)
113114
{
114-
return -EAFNOSUPPORT;
115+
return ERR_PTR(-EAFNOSUPPORT);
115116
}
116117

117118
const struct ipv6_stub *ipv6_stub __read_mostly = &(struct ipv6_stub) {
118-
.ipv6_dst_lookup = eafnosupport_ipv6_dst_lookup,
119+
.ipv6_dst_lookup_flow = eafnosupport_ipv6_dst_lookup_flow,
119120
};
120121
EXPORT_SYMBOL_GPL(ipv6_stub);
121122

net/ipv6/af_inet6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ static struct pernet_operations inet6_net_ops = {
860860
static const struct ipv6_stub ipv6_stub_impl = {
861861
.ipv6_sock_mc_join = ipv6_sock_mc_join,
862862
.ipv6_sock_mc_drop = ipv6_sock_mc_drop,
863-
.ipv6_dst_lookup = ip6_dst_lookup,
863+
.ipv6_dst_lookup_flow = ip6_dst_lookup_flow,
864864
.udpv6_encap_enable = udpv6_encap_enable,
865865
.ndisc_send_na = ndisc_send_na,
866866
.nd_tbl = &nd_tbl,

net/mpls/af_mpls.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,16 +497,15 @@ static struct net_device *inet6_fib_lookup_dev(struct net *net,
497497
struct net_device *dev;
498498
struct dst_entry *dst;
499499
struct flowi6 fl6;
500-
int err;
501500

502501
if (!ipv6_stub)
503502
return ERR_PTR(-EAFNOSUPPORT);
504503

505504
memset(&fl6, 0, sizeof(fl6));
506505
memcpy(&fl6.daddr, addr, sizeof(struct in6_addr));
507-
err = ipv6_stub->ipv6_dst_lookup(net, NULL, &dst, &fl6);
508-
if (err)
509-
return ERR_PTR(err);
506+
dst = ipv6_stub->ipv6_dst_lookup_flow(net, NULL, &fl6, NULL);
507+
if (IS_ERR(dst))
508+
return ERR_CAST(dst);
510509

511510
dev = dst->dev;
512511
dev_hold(dev);

net/tipc/udp_media.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@ static int tipc_udp_xmit(struct net *net, struct sk_buff *skb,
187187
.saddr = src->ipv6,
188188
.flowi6_proto = IPPROTO_UDP
189189
};
190-
err = ipv6_stub->ipv6_dst_lookup(net, ub->ubsock->sk, &ndst,
191-
&fl6);
192-
if (err)
190+
ndst = ipv6_stub->ipv6_dst_lookup_flow(net,
191+
ub->ubsock->sk,
192+
&fl6, NULL);
193+
if (IS_ERR(ndst)) {
194+
err = PTR_ERR(ndst);
193195
goto tx_error;
196+
}
194197
ttl = ip6_dst_hoplimit(ndst);
195198
err = udp_tunnel6_xmit_skb(ndst, ub->ubsock->sk, skb, NULL,
196199
&src->ipv6, &dst->ipv6, 0, ttl, 0,

0 commit comments

Comments
 (0)