Skip to content

Commit b34975f

Browse files
matttbeintel-lab-lkp
authored andcommitted
mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible
Instead of only returning a text message with GENL_SET_ERR_MSG(), NL_SET_ERR_MSG_ATTR() can help the userspace developers by also reporting which attribute is faulty. When the error is specific to an attribute, NL_SET_ERR_MSG_ATTR() is now used. The error messages have not been modified in this commit. Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent c250de5 commit b34975f

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

net/mptcp/pm_netlink.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,18 +1407,21 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info)
14071407
return ret;
14081408

14091409
if (addr.addr.port && !address_use_port(&addr)) {
1410-
GENL_SET_ERR_MSG(info, "flags must have signal and not subflow when using port");
1410+
NL_SET_ERR_MSG_ATTR(info->extack, attr,
1411+
"flags must have signal and not subflow when using port");
14111412
return -EINVAL;
14121413
}
14131414

14141415
if (addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL &&
14151416
addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) {
1416-
GENL_SET_ERR_MSG(info, "flags mustn't have both signal and fullmesh");
1417+
NL_SET_ERR_MSG_ATTR(info->extack, attr,
1418+
"flags mustn't have both signal and fullmesh");
14171419
return -EINVAL;
14181420
}
14191421

14201422
if (addr.flags & MPTCP_PM_ADDR_FLAG_IMPLICIT) {
1421-
GENL_SET_ERR_MSG(info, "can't create IMPLICIT endpoint");
1423+
NL_SET_ERR_MSG_ATTR(info->extack, attr,
1424+
"can't create IMPLICIT endpoint");
14221425
return -EINVAL;
14231426
}
14241427

@@ -1616,7 +1619,7 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info)
16161619
spin_lock_bh(&pernet->lock);
16171620
entry = __lookup_addr_by_id(pernet, addr.addr.id);
16181621
if (!entry) {
1619-
GENL_SET_ERR_MSG(info, "address not found");
1622+
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
16201623
spin_unlock_bh(&pernet->lock);
16211624
return -EINVAL;
16221625
}
@@ -1802,7 +1805,7 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
18021805
rcu_read_lock();
18031806
entry = __lookup_addr_by_id(pernet, addr.addr.id);
18041807
if (!entry) {
1805-
GENL_SET_ERR_MSG(info, "address not found");
1808+
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
18061809
ret = -EINVAL;
18071810
goto unlock_fail;
18081811
}

net/mptcp/pm_userspace.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in
189189
}
190190

191191
if (!mptcp_pm_is_userspace(msk)) {
192-
GENL_SET_ERR_MSG(info, "userspace PM not selected");
192+
NL_SET_ERR_MSG_ATTR(info->extack, token,
193+
"userspace PM not selected");
193194
sock_put((struct sock *)msk);
194195
return NULL;
195196
}
@@ -220,20 +221,21 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
220221
goto announce_err;
221222

222223
if (addr_val.addr.id == 0) {
223-
GENL_SET_ERR_MSG(info, "invalid addr id");
224+
NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr id");
224225
err = -EINVAL;
225226
goto announce_err;
226227
}
227228

228229
if (!(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
229-
GENL_SET_ERR_MSG(info, "invalid addr flags");
230+
NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr flags");
230231
err = -EINVAL;
231232
goto announce_err;
232233
}
233234

234235
err = mptcp_userspace_pm_append_new_local_addr(msk, &addr_val, false);
235236
if (err < 0) {
236-
GENL_SET_ERR_MSG(info, "did not match address and id");
237+
NL_SET_ERR_MSG_ATTR(info->extack, addr,
238+
"did not match address and id");
237239
goto announce_err;
238240
}
239241

@@ -388,7 +390,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
388390
goto create_err;
389391

390392
if (entry.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
391-
GENL_SET_ERR_MSG(info, "invalid addr flags");
393+
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "invalid addr flags");
392394
err = -EINVAL;
393395
goto create_err;
394396
}
@@ -407,7 +409,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
407409

408410
err = mptcp_userspace_pm_append_new_local_addr(msk, &entry, false);
409411
if (err < 0) {
410-
GENL_SET_ERR_MSG(info, "did not match address and id");
412+
NL_SET_ERR_MSG_ATTR(info->extack, laddr,
413+
"did not match address and id");
411414
goto create_err;
412415
}
413416

@@ -528,13 +531,13 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
528531
}
529532

530533
if (!addr_l.addr.port) {
531-
GENL_SET_ERR_MSG(info, "missing local port");
534+
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "missing local port");
532535
err = -EINVAL;
533536
goto destroy_err;
534537
}
535538

536539
if (!addr_r.port) {
537-
GENL_SET_ERR_MSG(info, "missing remote port");
540+
NL_SET_ERR_MSG_ATTR(info->extack, raddr, "missing remote port");
538541
err = -EINVAL;
539542
goto destroy_err;
540543
}
@@ -599,7 +602,8 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
599602
goto set_flags_err;
600603

601604
if (rem.addr.family == AF_UNSPEC) {
602-
GENL_SET_ERR_MSG(info, "invalid remote address family");
605+
NL_SET_ERR_MSG_ATTR(info->extack, attr_rem,
606+
"invalid remote address family");
603607
ret = -EINVAL;
604608
goto set_flags_err;
605609
}
@@ -722,7 +726,7 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb,
722726
spin_lock_bh(&msk->pm.lock);
723727
entry = mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id);
724728
if (!entry) {
725-
GENL_SET_ERR_MSG(info, "address not found");
729+
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
726730
ret = -EINVAL;
727731
goto unlock_fail;
728732
}

0 commit comments

Comments
 (0)