Skip to content

Commit 1039f6b

Browse files
karstengrpiso77
authored andcommitted
net/smc: add netlink support for SMC-Rv2
BugLink: https://bugs.launchpad.net/bugs/1929035 Implement the netlink support for SMC-Rv2 related attributes that are provided to user space. Signed-off-by: Karsten Graul <[email protected]> Signed-off-by: David S. Miller <[email protected]> (cherry picked from commit b0539f5) Signed-off-by: Frank Heimes <[email protected]> Acked-by: Tim Gardner <[email protected]>
1 parent d3bdc25 commit 1039f6b

File tree

2 files changed

+88
-27
lines changed

2 files changed

+88
-27
lines changed

include/uapi/linux/smc.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,28 @@ enum {
8484
SMC_NLA_SYS_IS_ISM_V2, /* u8 */
8585
SMC_NLA_SYS_LOCAL_HOST, /* string */
8686
SMC_NLA_SYS_SEID, /* string */
87+
SMC_NLA_SYS_IS_SMCR_V2, /* u8 */
8788
__SMC_NLA_SYS_MAX,
8889
SMC_NLA_SYS_MAX = __SMC_NLA_SYS_MAX - 1
8990
};
9091

91-
/* SMC_NLA_LGR_V2 nested attributes */
92+
/* SMC_NLA_LGR_D_V2_COMMON and SMC_NLA_LGR_R_V2_COMMON nested attributes */
9293
enum {
9394
SMC_NLA_LGR_V2_VER, /* u8 */
9495
SMC_NLA_LGR_V2_REL, /* u8 */
9596
SMC_NLA_LGR_V2_OS, /* u8 */
9697
SMC_NLA_LGR_V2_NEG_EID, /* string */
9798
SMC_NLA_LGR_V2_PEER_HOST, /* string */
99+
__SMC_NLA_LGR_V2_MAX,
100+
SMC_NLA_LGR_V2_MAX = __SMC_NLA_LGR_V2_MAX - 1
101+
};
102+
103+
/* SMC_NLA_LGR_R_V2 nested attributes */
104+
enum {
105+
SMC_NLA_LGR_R_V2_UNSPEC,
106+
SMC_NLA_LGR_R_V2_DIRECT, /* u8 */
107+
__SMC_NLA_LGR_R_V2_MAX,
108+
SMC_NLA_LGR_R_V2_MAX = __SMC_NLA_LGR_R_V2_MAX - 1
98109
};
99110

100111
/* SMC_GEN_LGR_SMCR attributes */
@@ -106,6 +117,8 @@ enum {
106117
SMC_NLA_LGR_R_PNETID, /* string */
107118
SMC_NLA_LGR_R_VLAN_ID, /* u8 */
108119
SMC_NLA_LGR_R_CONNS_NUM, /* u32 */
120+
SMC_NLA_LGR_R_V2_COMMON, /* nest */
121+
SMC_NLA_LGR_R_V2, /* nest */
109122
__SMC_NLA_LGR_R_MAX,
110123
SMC_NLA_LGR_R_MAX = __SMC_NLA_LGR_R_MAX - 1
111124
};
@@ -138,7 +151,7 @@ enum {
138151
SMC_NLA_LGR_D_PNETID, /* string */
139152
SMC_NLA_LGR_D_CHID, /* u16 */
140153
SMC_NLA_LGR_D_PAD, /* flag */
141-
SMC_NLA_LGR_V2, /* nest */
154+
SMC_NLA_LGR_D_V2_COMMON, /* nest */
142155
__SMC_NLA_LGR_D_MAX,
143156
SMC_NLA_LGR_D_MAX = __SMC_NLA_LGR_D_MAX - 1
144157
};

net/smc/smc_core.c

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ int smc_nl_get_sys_info(struct sk_buff *skb, struct netlink_callback *cb)
246246
goto errattr;
247247
if (nla_put_u8(skb, SMC_NLA_SYS_IS_ISM_V2, smc_ism_is_v2_capable()))
248248
goto errattr;
249+
if (nla_put_u8(skb, SMC_NLA_SYS_IS_SMCR_V2, true))
250+
goto errattr;
249251
smc_clc_get_hostname(&host);
250252
if (host) {
251253
memcpy(hostname, host, SMC_MAX_HOSTNAME_LEN);
@@ -273,12 +275,65 @@ int smc_nl_get_sys_info(struct sk_buff *skb, struct netlink_callback *cb)
273275
return skb->len;
274276
}
275277

278+
/* Fill SMC_NLA_LGR_D_V2_COMMON/SMC_NLA_LGR_R_V2_COMMON nested attributes */
279+
static int smc_nl_fill_lgr_v2_common(struct smc_link_group *lgr,
280+
struct sk_buff *skb,
281+
struct netlink_callback *cb,
282+
struct nlattr *v2_attrs)
283+
{
284+
char smc_host[SMC_MAX_HOSTNAME_LEN + 1];
285+
char smc_eid[SMC_MAX_EID_LEN + 1];
286+
287+
if (nla_put_u8(skb, SMC_NLA_LGR_V2_VER, lgr->smc_version))
288+
goto errv2attr;
289+
if (nla_put_u8(skb, SMC_NLA_LGR_V2_REL, lgr->peer_smc_release))
290+
goto errv2attr;
291+
if (nla_put_u8(skb, SMC_NLA_LGR_V2_OS, lgr->peer_os))
292+
goto errv2attr;
293+
memcpy(smc_host, lgr->peer_hostname, SMC_MAX_HOSTNAME_LEN);
294+
smc_host[SMC_MAX_HOSTNAME_LEN] = 0;
295+
if (nla_put_string(skb, SMC_NLA_LGR_V2_PEER_HOST, smc_host))
296+
goto errv2attr;
297+
memcpy(smc_eid, lgr->negotiated_eid, SMC_MAX_EID_LEN);
298+
smc_eid[SMC_MAX_EID_LEN] = 0;
299+
if (nla_put_string(skb, SMC_NLA_LGR_V2_NEG_EID, smc_eid))
300+
goto errv2attr;
301+
302+
nla_nest_end(skb, v2_attrs);
303+
return 0;
304+
305+
errv2attr:
306+
nla_nest_cancel(skb, v2_attrs);
307+
return -EMSGSIZE;
308+
}
309+
310+
static int smc_nl_fill_smcr_lgr_v2(struct smc_link_group *lgr,
311+
struct sk_buff *skb,
312+
struct netlink_callback *cb)
313+
{
314+
struct nlattr *v2_attrs;
315+
316+
v2_attrs = nla_nest_start(skb, SMC_NLA_LGR_R_V2);
317+
if (!v2_attrs)
318+
goto errattr;
319+
if (nla_put_u8(skb, SMC_NLA_LGR_R_V2_DIRECT, !lgr->uses_gateway))
320+
goto errv2attr;
321+
322+
nla_nest_end(skb, v2_attrs);
323+
return 0;
324+
325+
errv2attr:
326+
nla_nest_cancel(skb, v2_attrs);
327+
errattr:
328+
return -EMSGSIZE;
329+
}
330+
276331
static int smc_nl_fill_lgr(struct smc_link_group *lgr,
277332
struct sk_buff *skb,
278333
struct netlink_callback *cb)
279334
{
280335
char smc_target[SMC_MAX_PNETID_LEN + 1];
281-
struct nlattr *attrs;
336+
struct nlattr *attrs, *v2_attrs;
282337

283338
attrs = nla_nest_start(skb, SMC_GEN_LGR_SMCR);
284339
if (!attrs)
@@ -298,6 +353,15 @@ static int smc_nl_fill_lgr(struct smc_link_group *lgr,
298353
smc_target[SMC_MAX_PNETID_LEN] = 0;
299354
if (nla_put_string(skb, SMC_NLA_LGR_R_PNETID, smc_target))
300355
goto errattr;
356+
if (lgr->smc_version > SMC_V1) {
357+
v2_attrs = nla_nest_start(skb, SMC_NLA_LGR_R_V2_COMMON);
358+
if (!v2_attrs)
359+
goto errattr;
360+
if (smc_nl_fill_lgr_v2_common(lgr, skb, cb, v2_attrs))
361+
goto errattr;
362+
if (smc_nl_fill_smcr_lgr_v2(lgr, skb, cb))
363+
goto errattr;
364+
}
301365

302366
nla_nest_end(skb, attrs);
303367
return 0;
@@ -430,10 +494,7 @@ static int smc_nl_fill_smcd_lgr(struct smc_link_group *lgr,
430494
struct sk_buff *skb,
431495
struct netlink_callback *cb)
432496
{
433-
char smc_host[SMC_MAX_HOSTNAME_LEN + 1];
434497
char smc_pnet[SMC_MAX_PNETID_LEN + 1];
435-
char smc_eid[SMC_MAX_EID_LEN + 1];
436-
struct nlattr *v2_attrs;
437498
struct nlattr *attrs;
438499
void *nlh;
439500

@@ -465,32 +526,19 @@ static int smc_nl_fill_smcd_lgr(struct smc_link_group *lgr,
465526
smc_pnet[SMC_MAX_PNETID_LEN] = 0;
466527
if (nla_put_string(skb, SMC_NLA_LGR_D_PNETID, smc_pnet))
467528
goto errattr;
529+
if (lgr->smc_version > SMC_V1) {
530+
struct nlattr *v2_attrs;
468531

469-
v2_attrs = nla_nest_start(skb, SMC_NLA_LGR_V2);
470-
if (!v2_attrs)
471-
goto errattr;
472-
if (nla_put_u8(skb, SMC_NLA_LGR_V2_VER, lgr->smc_version))
473-
goto errv2attr;
474-
if (nla_put_u8(skb, SMC_NLA_LGR_V2_REL, lgr->peer_smc_release))
475-
goto errv2attr;
476-
if (nla_put_u8(skb, SMC_NLA_LGR_V2_OS, lgr->peer_os))
477-
goto errv2attr;
478-
memcpy(smc_host, lgr->peer_hostname, SMC_MAX_HOSTNAME_LEN);
479-
smc_host[SMC_MAX_HOSTNAME_LEN] = 0;
480-
if (nla_put_string(skb, SMC_NLA_LGR_V2_PEER_HOST, smc_host))
481-
goto errv2attr;
482-
memcpy(smc_eid, lgr->negotiated_eid, SMC_MAX_EID_LEN);
483-
smc_eid[SMC_MAX_EID_LEN] = 0;
484-
if (nla_put_string(skb, SMC_NLA_LGR_V2_NEG_EID, smc_eid))
485-
goto errv2attr;
486-
487-
nla_nest_end(skb, v2_attrs);
532+
v2_attrs = nla_nest_start(skb, SMC_NLA_LGR_D_V2_COMMON);
533+
if (!v2_attrs)
534+
goto errattr;
535+
if (smc_nl_fill_lgr_v2_common(lgr, skb, cb, v2_attrs))
536+
goto errattr;
537+
}
488538
nla_nest_end(skb, attrs);
489539
genlmsg_end(skb, nlh);
490540
return 0;
491541

492-
errv2attr:
493-
nla_nest_cancel(skb, v2_attrs);
494542
errattr:
495543
nla_nest_cancel(skb, attrs);
496544
errout:

0 commit comments

Comments
 (0)