Skip to content

Commit

Permalink
mptcp: set error messages for set_flags
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang authored and intel-lab-lkp committed Dec 29, 2023
1 parent fedba6f commit ad1910b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion net/mptcp/pm_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1906,8 +1906,10 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)

if (addr.addr.family == AF_UNSPEC) {
lookup_by_id = 1;
if (!addr.addr.id)
if (!addr.addr.id) {
GENL_SET_ERR_MSG(info, "missing required inputs");
return -EOPNOTSUPP;
}
}

if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
Expand All @@ -1917,11 +1919,13 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)
entry = __lookup_addr(pernet, &addr.addr, lookup_by_id);
if (!entry) {
spin_unlock_bh(&pernet->lock);
GENL_SET_ERR_MSG(info, "address not found");
return -EINVAL;
}
if ((addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
spin_unlock_bh(&pernet->lock);
GENL_SET_ERR_MSG(info, "invalid addr flags");
return -EINVAL;
}

Expand Down
9 changes: 7 additions & 2 deletions net/mptcp/pm_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,17 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
token_val = nla_get_u32(token);

msk = mptcp_token_get_sock(net, token_val);
if (!msk)
if (!msk) {
NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token");
return ret;
}

sk = (struct sock *)msk;

if (!mptcp_pm_is_userspace(msk))
if (!mptcp_pm_is_userspace(msk)) {
GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected");
goto set_flags_err;
}

ret = mptcp_pm_parse_entry(attr, info, false, &loc);
if (ret < 0)
Expand All @@ -588,6 +592,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)

if (loc.addr.family == AF_UNSPEC ||
rem.addr.family == AF_UNSPEC) {
GENL_SET_ERR_MSG(info, "address families do not match");
ret = -EINVAL;
goto set_flags_err;
}
Expand Down

0 comments on commit ad1910b

Please sign in to comment.