Skip to content

Commit 1b5a227

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. v2: - update the code related mptcp_userspace_pm_remove_id_zero_address() since a new patch to drop "info" parameter of this patch is added. v3: - not use NL_SET_ERR_MSG_ATTR in mptcp_pm_nl_set_flags(), since 'attr' will be removed in the commit "mptcp: add local & remote parameters for set_flags". Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent 376bee6 commit 1b5a227

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
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: 8 additions & 5 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
}
@@ -233,7 +234,8 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
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

@@ -724,7 +727,7 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb,
724727
spin_lock_bh(&msk->pm.lock);
725728
entry = mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id);
726729
if (!entry) {
727-
GENL_SET_ERR_MSG(info, "address not found");
730+
NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
728731
ret = -EINVAL;
729732
goto unlock_fail;
730733
}

0 commit comments

Comments
 (0)