Skip to content

Commit 1cee223

Browse files
matttbeintel-lab-lkp
authored andcommitted
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. By splitting some error messages, NL_SET_ERR_MSG_ATTR() can be used instead of GENL_SET_ERR_MSG() in order to give an additional hint to the userspace developers about which attribute is wrong. While at it, in mptcp_userspace_pm_set_flags() move the parsing after the check linked to the local attribute. Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent 33220a7 commit 1cee223

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

net/mptcp/pm_userspace.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,14 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
223223
goto announce_err;
224224
}
225225

226-
if (addr_val.addr.id == 0 || !(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
227-
GENL_SET_ERR_MSG(info, "invalid addr id or flags");
226+
if (addr_val.addr.id == 0) {
227+
NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr id");
228+
err = -EINVAL;
229+
goto announce_err;
230+
}
231+
232+
if (!(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
233+
NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr flags");
228234
err = -EINVAL;
229235
goto announce_err;
230236
}
@@ -531,8 +537,14 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
531537
goto destroy_err;
532538
}
533539

534-
if (!addr_l.addr.port || !addr_r.port) {
535-
GENL_SET_ERR_MSG(info, "missing local or remote port");
540+
if (!addr_l.addr.port) {
541+
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "missing local port");
542+
err = -EINVAL;
543+
goto destroy_err;
544+
}
545+
546+
if (!addr_r.port) {
547+
NL_SET_ERR_MSG_ATTR(info->extack, raddr, "missing remote port");
536548
err = -EINVAL;
537549
goto destroy_err;
538550
}
@@ -580,13 +592,20 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
580592
if (ret < 0)
581593
goto set_flags_err;
582594

595+
if (loc.addr.family == AF_UNSPEC) {
596+
NL_SET_ERR_MSG_ATTR(info->extack, attr,
597+
"invalid local address family");
598+
ret = -EINVAL;
599+
goto set_flags_err;
600+
}
601+
583602
ret = mptcp_pm_parse_entry(attr_rem, info, false, &rem);
584603
if (ret < 0)
585604
goto set_flags_err;
586605

587-
if (loc.addr.family == AF_UNSPEC ||
588-
rem.addr.family == AF_UNSPEC) {
589-
GENL_SET_ERR_MSG(info, "invalid address families");
606+
if (rem.addr.family == AF_UNSPEC) {
607+
NL_SET_ERR_MSG_ATTR(info->extack, attr_rem,
608+
"invalid remote address family");
590609
ret = -EINVAL;
591610
goto set_flags_err;
592611
}

0 commit comments

Comments
 (0)