Skip to content

Commit fa29d1e

Browse files
paravmellanoxrleon
authored andcommitted
RDMA/core: Squash a single user static function
To reduce dependencies in IFF_LOOPBACK in route and neighbour resolution steps, squash the static function to its single caller and simplify the code. Until now, network field was set even when neighbour resolution failed. With this change, dev_addr output fields are valid only when resolution is successful. Signed-off-by: Parav Pandit <parav@nvidia.com> Reviewed-by: Vlad Dumitrescu <vdumitrescu@nvidia.com> Signed-off-by: Edward Srouji <edwards@nvidia.com> Link: https://patch.msgid.link/20250916111103.84069-2-edwards@nvidia.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent 060842f commit fa29d1e

1 file changed

Lines changed: 20 additions & 29 deletions

File tree

drivers/infiniband/core/addr.c

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -465,34 +465,6 @@ static int addr_resolve_neigh(const struct dst_entry *dst,
465465
return ret;
466466
}
467467

468-
static int copy_src_l2_addr(struct rdma_dev_addr *dev_addr,
469-
const struct sockaddr *dst_in,
470-
const struct dst_entry *dst,
471-
const struct net_device *ndev)
472-
{
473-
int ret = 0;
474-
475-
if (dst->dev->flags & IFF_LOOPBACK)
476-
ret = rdma_translate_ip(dst_in, dev_addr);
477-
else
478-
rdma_copy_src_l2_addr(dev_addr, dst->dev);
479-
480-
/*
481-
* If there's a gateway and type of device not ARPHRD_INFINIBAND,
482-
* we're definitely in RoCE v2 (as RoCE v1 isn't routable) set the
483-
* network type accordingly.
484-
*/
485-
if (has_gateway(dst, dst_in->sa_family) &&
486-
ndev->type != ARPHRD_INFINIBAND)
487-
dev_addr->network = dst_in->sa_family == AF_INET ?
488-
RDMA_NETWORK_IPV4 :
489-
RDMA_NETWORK_IPV6;
490-
else
491-
dev_addr->network = RDMA_NETWORK_IB;
492-
493-
return ret;
494-
}
495-
496468
static int rdma_set_src_addr_rcu(struct rdma_dev_addr *dev_addr,
497469
unsigned int *ndev_flags,
498470
const struct sockaddr *dst_in,
@@ -503,6 +475,7 @@ static int rdma_set_src_addr_rcu(struct rdma_dev_addr *dev_addr,
503475
*ndev_flags = ndev->flags;
504476
/* A physical device must be the RDMA device to use */
505477
if (ndev->flags & IFF_LOOPBACK) {
478+
int ret;
506479
/*
507480
* RDMA (IB/RoCE, iWarp) doesn't run on lo interface or
508481
* loopback IP address. So if route is resolved to loopback
@@ -512,9 +485,27 @@ static int rdma_set_src_addr_rcu(struct rdma_dev_addr *dev_addr,
512485
ndev = rdma_find_ndev_for_src_ip_rcu(dev_net(ndev), dst_in);
513486
if (IS_ERR(ndev))
514487
return -ENODEV;
488+
ret = rdma_translate_ip(dst_in, dev_addr);
489+
if (ret)
490+
return ret;
491+
} else {
492+
rdma_copy_src_l2_addr(dev_addr, dst->dev);
515493
}
516494

517-
return copy_src_l2_addr(dev_addr, dst_in, dst, ndev);
495+
/*
496+
* If there's a gateway and type of device not ARPHRD_INFINIBAND,
497+
* we're definitely in RoCE v2 (as RoCE v1 isn't routable) set the
498+
* network type accordingly.
499+
*/
500+
if (has_gateway(dst, dst_in->sa_family) &&
501+
ndev->type != ARPHRD_INFINIBAND)
502+
dev_addr->network = dst_in->sa_family == AF_INET ?
503+
RDMA_NETWORK_IPV4 :
504+
RDMA_NETWORK_IPV6;
505+
else
506+
dev_addr->network = RDMA_NETWORK_IB;
507+
508+
return 0;
518509
}
519510

520511
static int set_addr_netns_by_gid_rcu(struct rdma_dev_addr *addr)

0 commit comments

Comments
 (0)