Skip to content

Commit a4d68b1

Browse files
Geliang Tangkuba-moo
authored andcommitted
mptcp: set error messages for set_flags
In addition to returning the error value, this patch also sets an error messages with GENL_SET_ERR_MSG or NL_SET_ERR_MSG_ATTR both for pm_netlink.c and pm_userspace.c. It will help the userspace to identify the issue. Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Link: https://lore.kernel.org/r/20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-3-c436ba5e569b@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 6a42477 commit a4d68b1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

net/mptcp/pm_netlink.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1908,8 +1908,10 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)
19081908

19091909
if (addr.addr.family == AF_UNSPEC) {
19101910
lookup_by_id = 1;
1911-
if (!addr.addr.id)
1911+
if (!addr.addr.id) {
1912+
GENL_SET_ERR_MSG(info, "missing required inputs");
19121913
return -EOPNOTSUPP;
1914+
}
19131915
}
19141916

19151917
if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
@@ -1919,11 +1921,13 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)
19191921
entry = __lookup_addr(pernet, &addr.addr, lookup_by_id);
19201922
if (!entry) {
19211923
spin_unlock_bh(&pernet->lock);
1924+
GENL_SET_ERR_MSG(info, "address not found");
19221925
return -EINVAL;
19231926
}
19241927
if ((addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
19251928
(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
19261929
spin_unlock_bh(&pernet->lock);
1930+
GENL_SET_ERR_MSG(info, "invalid addr flags");
19271931
return -EINVAL;
19281932
}
19291933

net/mptcp/pm_userspace.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,13 +563,17 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
563563
token_val = nla_get_u32(token);
564564

565565
msk = mptcp_token_get_sock(net, token_val);
566-
if (!msk)
566+
if (!msk) {
567+
NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token");
567568
return ret;
569+
}
568570

569571
sk = (struct sock *)msk;
570572

571-
if (!mptcp_pm_is_userspace(msk))
573+
if (!mptcp_pm_is_userspace(msk)) {
574+
GENL_SET_ERR_MSG(info, "userspace PM not selected");
572575
goto set_flags_err;
576+
}
573577

574578
ret = mptcp_pm_parse_entry(attr, info, false, &loc);
575579
if (ret < 0)
@@ -583,6 +587,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
583587

584588
if (loc.addr.family == AF_UNSPEC ||
585589
rem.addr.family == AF_UNSPEC) {
590+
GENL_SET_ERR_MSG(info, "invalid address families");
586591
ret = -EINVAL;
587592
goto set_flags_err;
588593
}

0 commit comments

Comments
 (0)