Skip to content

Commit c68681a

Browse files
Albert Huangkuba-moo
authored andcommitted
net/smc: fix smc clc failed issue when netdevice not in init_net
If the netdevice is within a container and communicates externally through network technologies such as VxLAN, we won't be able to find routing information in the init_net namespace. To address this issue, we need to add a struct net parameter to the smc_ib_find_route function. This allow us to locate the routing information within the corresponding net namespace, ensuring the correct completion of the SMC CLC interaction. Fixes: e5c4744 ("net/smc: add SMC-Rv2 connection establishment") Signed-off-by: Albert Huang <huangjie.albert@bytedance.com> Reviewed-by: Dust Li <dust.li@linux.alibaba.com> Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com> Link: https://lore.kernel.org/r/20231011074851.95280-1-huangjie.albert@bytedance.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 419ce13 commit c68681a

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

net/smc/af_smc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,7 @@ static int smc_connect_rdma_v2_prepare(struct smc_sock *smc,
12011201
(struct smc_clc_msg_accept_confirm_v2 *)aclc;
12021202
struct smc_clc_first_contact_ext *fce =
12031203
smc_get_clc_first_contact_ext(clc_v2, false);
1204+
struct net *net = sock_net(&smc->sk);
12041205
int rc;
12051206

12061207
if (!ini->first_contact_peer || aclc->hdr.version == SMC_V1)
@@ -1210,7 +1211,7 @@ static int smc_connect_rdma_v2_prepare(struct smc_sock *smc,
12101211
memcpy(ini->smcrv2.nexthop_mac, &aclc->r0.lcl.mac, ETH_ALEN);
12111212
ini->smcrv2.uses_gateway = false;
12121213
} else {
1213-
if (smc_ib_find_route(smc->clcsock->sk->sk_rcv_saddr,
1214+
if (smc_ib_find_route(net, smc->clcsock->sk->sk_rcv_saddr,
12141215
smc_ib_gid_to_ipv4(aclc->r0.lcl.gid),
12151216
ini->smcrv2.nexthop_mac,
12161217
&ini->smcrv2.uses_gateway))

net/smc/smc_ib.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ bool smc_ib_port_active(struct smc_ib_device *smcibdev, u8 ibport)
193193
return smcibdev->pattr[ibport - 1].state == IB_PORT_ACTIVE;
194194
}
195195

196-
int smc_ib_find_route(__be32 saddr, __be32 daddr,
196+
int smc_ib_find_route(struct net *net, __be32 saddr, __be32 daddr,
197197
u8 nexthop_mac[], u8 *uses_gateway)
198198
{
199199
struct neighbour *neigh = NULL;
@@ -205,7 +205,7 @@ int smc_ib_find_route(__be32 saddr, __be32 daddr,
205205

206206
if (daddr == cpu_to_be32(INADDR_NONE))
207207
goto out;
208-
rt = ip_route_output_flow(&init_net, &fl4, NULL);
208+
rt = ip_route_output_flow(net, &fl4, NULL);
209209
if (IS_ERR(rt))
210210
goto out;
211211
if (rt->rt_uses_gateway && rt->rt_gw_family != AF_INET)
@@ -235,6 +235,7 @@ static int smc_ib_determine_gid_rcu(const struct net_device *ndev,
235235
if (smcrv2 && attr->gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP &&
236236
smc_ib_gid_to_ipv4((u8 *)&attr->gid) != cpu_to_be32(INADDR_NONE)) {
237237
struct in_device *in_dev = __in_dev_get_rcu(ndev);
238+
struct net *net = dev_net(ndev);
238239
const struct in_ifaddr *ifa;
239240
bool subnet_match = false;
240241

@@ -248,7 +249,7 @@ static int smc_ib_determine_gid_rcu(const struct net_device *ndev,
248249
}
249250
if (!subnet_match)
250251
goto out;
251-
if (smcrv2->daddr && smc_ib_find_route(smcrv2->saddr,
252+
if (smcrv2->daddr && smc_ib_find_route(net, smcrv2->saddr,
252253
smcrv2->daddr,
253254
smcrv2->nexthop_mac,
254255
&smcrv2->uses_gateway))

net/smc/smc_ib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void smc_ib_sync_sg_for_device(struct smc_link *lnk,
112112
int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport,
113113
unsigned short vlan_id, u8 gid[], u8 *sgid_index,
114114
struct smc_init_info_smcrv2 *smcrv2);
115-
int smc_ib_find_route(__be32 saddr, __be32 daddr,
115+
int smc_ib_find_route(struct net *net, __be32 saddr, __be32 daddr,
116116
u8 nexthop_mac[], u8 *uses_gateway);
117117
bool smc_ib_is_valid_local_systemid(void);
118118
int smcr_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb);

0 commit comments

Comments
 (0)