]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mptcp: pm: more precise error messages
authorMatthieu Baerts (NGI0) <matttbe@kernel.org>
Fri, 7 Feb 2025 13:59:21 +0000 (14:59 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 11 Feb 2025 11:46:37 +0000 (12:46 +0100)
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>
net/mptcp/pm_userspace.c

index b6cf8ea1161ddc7f0f1662320aebfe720f55e722..cdc83fabb7c2c45bc3d7c954a824c8f27bb85718 100644 (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;
        }