mptcp: pm: more precise error messages

Some errors reported by the userspace PM were vague: "this or that is
invalid".

It is easier for the userspace to know which part is wrong, instead of
having to guess that.

While at it, in mptcp_userspace_pm_set_flags() move the parsing after
the check linked to the local attribute.

Reviewed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
Matthieu Baerts (NGI0) 2025-02-07 14:59:21 +01:00 committed by Paolo Abeni
parent 58b21309f9
commit 891a87f7a7

View File

@ -223,8 +223,14 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
goto announce_err;
}
if (addr_val.addr.id == 0 || !(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
GENL_SET_ERR_MSG(info, "invalid addr id or flags");
if (addr_val.addr.id == 0) {
GENL_SET_ERR_MSG(info, "invalid addr id");
err = -EINVAL;
goto announce_err;
}
if (!(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
GENL_SET_ERR_MSG(info, "invalid addr flags");
err = -EINVAL;
goto announce_err;
}
@ -531,8 +537,14 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
goto destroy_err;
}
if (!addr_l.addr.port || !addr_r.port) {
GENL_SET_ERR_MSG(info, "missing local or remote port");
if (!addr_l.addr.port) {
GENL_SET_ERR_MSG(info, "missing local port");
err = -EINVAL;
goto destroy_err;
}
if (!addr_r.port) {
GENL_SET_ERR_MSG(info, "missing remote port");
err = -EINVAL;
goto destroy_err;
}
@ -580,13 +592,18 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
if (ret < 0)
goto set_flags_err;
if (loc.addr.family == AF_UNSPEC) {
GENL_SET_ERR_MSG(info, "invalid local address family");
ret = -EINVAL;
goto set_flags_err;
}
ret = mptcp_pm_parse_entry(attr_rem, info, false, &rem);
if (ret < 0)
goto set_flags_err;
if (loc.addr.family == AF_UNSPEC ||
rem.addr.family == AF_UNSPEC) {
GENL_SET_ERR_MSG(info, "invalid address families");
if (rem.addr.family == AF_UNSPEC) {
GENL_SET_ERR_MSG(info, "invalid remote address family");
ret = -EINVAL;
goto set_flags_err;
}