Skip to content

Commit 307edde

Browse files
paravmellanoxjgunthorpe
authored andcommitted
RDMA/core: Refer to network type instead of device type
Set and refer to rdma_dev_addr network type instead of dst->ndev to reduce dependency on accessing dst netdevice. Signed-off-by: Parav Pandit <parav@mellanox.com> Reviewed-by: Daniel Jurgens <danielj@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 783793b commit 307edde

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

drivers/infiniband/core/addr.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ static int fetch_ha(const struct dst_entry *dst, struct rdma_dev_addr *dev_addr,
368368
(const void *)&dst_in6->sin6_addr;
369369
sa_family_t family = dst_in->sa_family;
370370

371-
/* Gateway + ARPHRD_INFINIBAND -> IB router */
372-
if (has_gateway(dst, family) && dst->dev->type == ARPHRD_INFINIBAND)
371+
/* If we have a gateway in IB mode then it must be an IB network */
372+
if (has_gateway(dst, family) && dev_addr->network == RDMA_NETWORK_IB)
373373
return ib_nl_fetch_ha(dev_addr, daddr, seq, family);
374374
else
375375
return dst_fetch_ha(dst, dev_addr, daddr);
@@ -401,13 +401,6 @@ static int addr4_resolve(struct sockaddr *src_sock,
401401

402402
src_in->sin_addr.s_addr = fl4.saddr;
403403

404-
/* If there's a gateway and type of device not ARPHRD_INFINIBAND, we're
405-
* definitely in RoCE v2 (as RoCE v1 isn't routable) set the network
406-
* type accordingly.
407-
*/
408-
if (rt->rt_uses_gateway && rt->dst.dev->type != ARPHRD_INFINIBAND)
409-
addr->network = RDMA_NETWORK_IPV4;
410-
411404
addr->hoplimit = ip4_dst_hoplimit(&rt->dst);
412405

413406
*prt = rt;
@@ -425,7 +418,6 @@ static int addr6_resolve(struct sockaddr *src_sock,
425418
(const struct sockaddr_in6 *)dst_sock;
426419
struct flowi6 fl6;
427420
struct dst_entry *dst;
428-
struct rt6_info *rt;
429421
int ret;
430422

431423
memset(&fl6, 0, sizeof fl6);
@@ -437,18 +429,9 @@ static int addr6_resolve(struct sockaddr *src_sock,
437429
if (ret < 0)
438430
return ret;
439431

440-
rt = (struct rt6_info *)dst;
441432
if (ipv6_addr_any(&src_in->sin6_addr))
442433
src_in->sin6_addr = fl6.saddr;
443434

444-
/* If there's a gateway and type of device not ARPHRD_INFINIBAND, we're
445-
* definitely in RoCE v2 (as RoCE v1 isn't routable) set the network
446-
* type accordingly.
447-
*/
448-
if (rt->rt6i_flags & RTF_GATEWAY &&
449-
ip6_dst_idev(dst)->dev->type != ARPHRD_INFINIBAND)
450-
addr->network = RDMA_NETWORK_IPV6;
451-
452435
addr->hoplimit = ip6_dst_hoplimit(dst);
453436

454437
*pdst = dst;
@@ -491,6 +474,20 @@ static int rdma_set_src_addr(const struct dst_entry *dst,
491474
ret = rdma_translate_ip(dst_in, dev_addr);
492475
else
493476
rdma_copy_src_l2_addr(dev_addr, dst->dev);
477+
478+
/*
479+
* If there's a gateway and type of device not ARPHRD_INFINIBAND,
480+
* we're definitely in RoCE v2 (as RoCE v1 isn't routable) set the
481+
* network type accordingly.
482+
*/
483+
if (has_gateway(dst, dst_in->sa_family) &&
484+
dst->dev->type != ARPHRD_INFINIBAND)
485+
dev_addr->network = dst_in->sa_family == AF_INET ?
486+
RDMA_NETWORK_IPV4 :
487+
RDMA_NETWORK_IPV6;
488+
else
489+
dev_addr->network = RDMA_NETWORK_IB;
490+
494491
return ret;
495492
}
496493

0 commit comments

Comments
 (0)