* [PATCH mptcp-next v7 01/11] mptcp: pm: more precise error messages
2025-01-06 8:16 [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm Geliang Tang
@ 2025-01-06 8:16 ` Geliang Tang
2025-01-06 9:17 ` Matthieu Baerts
2025-01-06 8:16 ` [PATCH mptcp-next v7 02/11] mptcp: userspace pm set_flags id support Geliang Tang
` (10 subsequent siblings)
11 siblings, 1 reply; 20+ messages in thread
From: Geliang Tang @ 2025-01-06 8:16 UTC (permalink / raw)
To: mptcp; +Cc: Matthieu Baerts (NGI0)
From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
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.
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
net/mptcp/pm_userspace.c | 39 +++++++++++++++++++++++++++++----------
1 file changed, 29 insertions(+), 10 deletions(-)
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index a3d477059b11..40fd2f788196 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -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) {
+ NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr id");
+ err = -EINVAL;
+ goto announce_err;
+ }
+
+ if (!(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
+ NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr flags");
err = -EINVAL;
goto announce_err;
}
@@ -530,8 +536,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) {
+ NL_SET_ERR_MSG_ATTR(info->extack, laddr, "missing local port");
+ err = -EINVAL;
+ goto destroy_err;
+ }
+
+ if (!addr_r.port) {
+ NL_SET_ERR_MSG_ATTR(info->extack, raddr, "missing remote port");
err = -EINVAL;
goto destroy_err;
}
@@ -579,17 +591,24 @@ 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) {
+ NL_SET_ERR_MSG_ATTR(info->extack, attr,
+ "invalid local address family");
+ ret = -EINVAL;
+ goto set_flags_err;
+ }
+
if (attr_rem) {
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");
- ret = -EINVAL;
- goto set_flags_err;
+ if (rem.addr.family == AF_UNSPEC) {
+ NL_SET_ERR_MSG_ATTR(info->extack, attr_rem,
+ "invalid remote address family");
+ ret = -EINVAL;
+ goto set_flags_err;
+ }
}
if (loc.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
--
2.45.2
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH mptcp-next v7 01/11] mptcp: pm: more precise error messages
2025-01-06 8:16 ` [PATCH mptcp-next v7 01/11] mptcp: pm: more precise error messages Geliang Tang
@ 2025-01-06 9:17 ` Matthieu Baerts
0 siblings, 0 replies; 20+ messages in thread
From: Matthieu Baerts @ 2025-01-06 9:17 UTC (permalink / raw)
To: Geliang Tang, mptcp
Hi Geliang,
On 06/01/2025 09:16, Geliang Tang wrote:
> From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
>
> 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.
>
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
If you modify the behaviour of a patch, you can add your 'co-dev' +
'sob' tags.
Also, please add an individual changelog, easier for the reviewers to
spot what has changed.
> ---
> net/mptcp/pm_userspace.c | 39 +++++++++++++++++++++++++++++----------
> 1 file changed, 29 insertions(+), 10 deletions(-)
>
> diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
> index a3d477059b11..40fd2f788196 100644
> --- a/net/mptcp/pm_userspace.c
> +++ b/net/mptcp/pm_userspace.c
(...)
> @@ -579,17 +591,24 @@ 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) {
> + NL_SET_ERR_MSG_ATTR(info->extack, attr,
> + "invalid local address family");
> + ret = -EINVAL;
> + goto set_flags_err;
> + }
> +
> if (attr_rem) {
> 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");
> - ret = -EINVAL;
> - goto set_flags_err;
> + if (rem.addr.family == AF_UNSPEC) {
As I mentioned in a previous version, this is changing the behaviour:
this remote attribute is no longer mandatory. I'm still unsure about
making it optional, because mptcp_pm_nl_mp_prio_send_ack() will pick
only one subflow, not all the ones with the specified local address. It
looks better to keep it mandatory.
At least here, you should not move it under "if (attr_rem)".
(and maybe it makes more sense to have this patch after 07/11 ("mptcp:
pm: use NL_SET_ERR_MSG_ATTR when possible"), but that's a detail, fine here)
> + NL_SET_ERR_MSG_ATTR(info->extack, attr_rem,
> + "invalid remote address family");
> + ret = -EINVAL;
> + goto set_flags_err;
> + }
> }
>
> if (loc.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH mptcp-next v7 02/11] mptcp: userspace pm set_flags id support
2025-01-06 8:16 [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm Geliang Tang
2025-01-06 8:16 ` [PATCH mptcp-next v7 01/11] mptcp: pm: more precise error messages Geliang Tang
@ 2025-01-06 8:16 ` Geliang Tang
2025-01-06 9:31 ` Matthieu Baerts
2025-01-06 8:16 ` [PATCH mptcp-next v7 03/11] mptcp: drop skb parameter of set_flags Geliang Tang
` (9 subsequent siblings)
11 siblings, 1 reply; 20+ messages in thread
From: Geliang Tang @ 2025-01-06 8:16 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
Similar to in-kernel PM, this patch adds address ID support to set_flags()
interface of userspace PM, allowing it to work with either an address or
an address ID.
When an address ID is used, mptcp_userspace_pm_lookup_addr_by_id() helper
is used to look up the address entry in the local address list instead of
using mptcp_userspace_pm_lookup_addr().
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/pm_userspace.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 40fd2f788196..60db72060e6e 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -577,6 +577,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
struct mptcp_pm_addr_entry *entry;
struct mptcp_sock *msk;
+ u8 lookup_by_id = 0;
int ret = -EINVAL;
struct sock *sk;
u8 bkup = 0;
@@ -592,10 +593,13 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
goto set_flags_err;
if (loc.addr.family == AF_UNSPEC) {
- NL_SET_ERR_MSG_ATTR(info->extack, attr,
- "invalid local address family");
- ret = -EINVAL;
- goto set_flags_err;
+ lookup_by_id = 1;
+ if (!loc.addr.id) {
+ NL_SET_ERR_MSG_ATTR(info->extack, attr,
+ "missing address ID");
+ ret = -EOPNOTSUPP;
+ goto set_flags_err;
+ }
}
if (attr_rem) {
@@ -615,17 +619,22 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
bkup = 1;
spin_lock_bh(&msk->pm.lock);
- entry = mptcp_userspace_pm_lookup_addr(msk, &loc.addr);
- if (entry) {
- if (bkup)
- entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
- else
- entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP;
+ entry = lookup_by_id ? mptcp_userspace_pm_lookup_addr_by_id(msk, loc.addr.id) :
+ mptcp_userspace_pm_lookup_addr(msk, &loc.addr);
+ if (!entry) {
+ spin_unlock_bh(&msk->pm.lock);
+ ret = -EINVAL;
+ goto set_flags_err;
}
+
+ if (bkup)
+ entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
+ else
+ entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP;
spin_unlock_bh(&msk->pm.lock);
lock_sock(sk);
- ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem.addr, bkup);
+ ret = mptcp_pm_nl_mp_prio_send_ack(msk, &entry->addr, &rem.addr, bkup);
release_sock(sk);
set_flags_err:
--
2.45.2
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH mptcp-next v7 02/11] mptcp: userspace pm set_flags id support
2025-01-06 8:16 ` [PATCH mptcp-next v7 02/11] mptcp: userspace pm set_flags id support Geliang Tang
@ 2025-01-06 9:31 ` Matthieu Baerts
0 siblings, 0 replies; 20+ messages in thread
From: Matthieu Baerts @ 2025-01-06 9:31 UTC (permalink / raw)
To: Geliang Tang, mptcp; +Cc: Geliang Tang
Hi Geliang,
On 06/01/2025 09:16, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> Similar to in-kernel PM, this patch adds address ID support to set_flags()
> interface of userspace PM, allowing it to work with either an address or
> an address ID.
>
> When an address ID is used, mptcp_userspace_pm_lookup_addr_by_id() helper
> is used to look up the address entry in the local address list instead of
> using mptcp_userspace_pm_lookup_addr().
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
> net/mptcp/pm_userspace.c | 31 ++++++++++++++++++++-----------
> 1 file changed, 20 insertions(+), 11 deletions(-)
>
> diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
> index 40fd2f788196..60db72060e6e 100644
> --- a/net/mptcp/pm_userspace.c
> +++ b/net/mptcp/pm_userspace.c
> @@ -577,6 +577,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
> struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
> struct mptcp_pm_addr_entry *entry;
> struct mptcp_sock *msk;
> + u8 lookup_by_id = 0;
> int ret = -EINVAL;
> struct sock *sk;
> u8 bkup = 0;
> @@ -592,10 +593,13 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
> goto set_flags_err;
>
> if (loc.addr.family == AF_UNSPEC) {
> - NL_SET_ERR_MSG_ATTR(info->extack, attr,
> - "invalid local address family");
> - ret = -EINVAL;
> - goto set_flags_err;
> + lookup_by_id = 1;
> + if (!loc.addr.id) {
> + NL_SET_ERR_MSG_ATTR(info->extack, attr,
> + "missing address ID");
> + ret = -EOPNOTSUPP;
> + goto set_flags_err;
> + }
> }
>
> if (attr_rem) {
> @@ -615,17 +619,22 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
> bkup = 1;
>
> spin_lock_bh(&msk->pm.lock);
> - entry = mptcp_userspace_pm_lookup_addr(msk, &loc.addr);
> - if (entry) {
> - if (bkup)
> - entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
> - else
> - entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP;
> + entry = lookup_by_id ? mptcp_userspace_pm_lookup_addr_by_id(msk, loc.addr.id) :
> + mptcp_userspace_pm_lookup_addr(msk, &loc.addr);
> + if (!entry) {
> + spin_unlock_bh(&msk->pm.lock);
> + ret = -EINVAL;
> + goto set_flags_err;
Mmh, you are changing the behaviour here by making it mandatory to have
an entry, and I don't think you can: if I'm not mistaken, with the
userspace PM, it is possible not to find any entries here, e.g. if a
subflow using this address has not been added or the address has not
been announced (I guess the initial address is not there then).
Also, with the userspace PM, it is possible to have an entry with an
ADDR ID == 0.
Do you think this patch is worth it? Setting by ID for the in-kernel PM
makes sense: unique ID for the netns, easier to type the ID than the
full address. While for the userspace PM, it will be managed by a daemon
that will have to track addresses anyway.
> }
> +
> + if (bkup)
> + entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
> + else
> + entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP;
> spin_unlock_bh(&msk->pm.lock);
>
> lock_sock(sk);
> - ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem.addr, bkup);
> + ret = mptcp_pm_nl_mp_prio_send_ack(msk, &entry->addr, &rem.addr, bkup);
> release_sock(sk);
>
> set_flags_err:
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH mptcp-next v7 03/11] mptcp: drop skb parameter of set_flags
2025-01-06 8:16 [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm Geliang Tang
2025-01-06 8:16 ` [PATCH mptcp-next v7 01/11] mptcp: pm: more precise error messages Geliang Tang
2025-01-06 8:16 ` [PATCH mptcp-next v7 02/11] mptcp: userspace pm set_flags id support Geliang Tang
@ 2025-01-06 8:16 ` Geliang Tang
2025-01-06 8:16 ` [PATCH mptcp-next v7 04/11] mptcp: change rem type " Geliang Tang
` (8 subsequent siblings)
11 siblings, 0 replies; 20+ messages in thread
From: Geliang Tang @ 2025-01-06 8:16 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
The first parameter 'skb' in mptcp_pm_nl_set_flags() is only used to
obtained the network namespace, which can also be obtained through the
second parameters 'info' by using genl_info_net() helper. This patch
drops these useless parameters 'skb' in all three set_flags() interfaces.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/pm.c | 6 +++---
net/mptcp/pm_netlink.c | 6 +++---
net/mptcp/pm_userspace.c | 2 +-
net/mptcp/protocol.h | 6 +++---
4 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 16c336c51940..6cd69ea9a69b 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -449,11 +449,11 @@ int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
return mptcp_pm_nl_dump_addr(msg, cb);
}
-int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
+int mptcp_pm_set_flags(struct genl_info *info)
{
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
- return mptcp_userspace_pm_set_flags(skb, info);
- return mptcp_pm_nl_set_flags(skb, info);
+ return mptcp_userspace_pm_set_flags(info);
+ return mptcp_pm_nl_set_flags(info);
}
void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 98ac73938bd8..e9747bc948b9 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1981,13 +1981,13 @@ static int mptcp_nl_set_flags(struct net *net,
return ret;
}
-int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)
+int mptcp_pm_nl_set_flags(struct genl_info *info)
{
struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, };
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP |
MPTCP_PM_ADDR_FLAG_FULLMESH;
- struct net *net = sock_net(skb->sk);
+ struct net *net = genl_info_net(info);
struct mptcp_pm_addr_entry *entry;
struct pm_nl_pernet *pernet;
u8 lookup_by_id = 0;
@@ -2037,7 +2037,7 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)
int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
{
- return mptcp_pm_set_flags(skb, info);
+ return mptcp_pm_set_flags(info);
}
static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp)
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 60db72060e6e..51fd84c49474 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -569,7 +569,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
return err;
}
-int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info)
+int mptcp_userspace_pm_set_flags(struct genl_info *info)
{
struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
struct mptcp_pm_addr_entry rem = { .addr = { .family = AF_UNSPEC }, };
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 891ffcfd1088..df5619ae8a14 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -1028,9 +1028,9 @@ bool mptcp_lookup_subflow_by_saddr(const struct list_head *list,
const struct mptcp_addr_info *saddr);
bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk,
const struct mptcp_addr_info *addr);
-int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info);
-int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info);
-int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info);
+int mptcp_pm_set_flags(struct genl_info *info);
+int mptcp_pm_nl_set_flags(struct genl_info *info);
+int mptcp_userspace_pm_set_flags(struct genl_info *info);
int mptcp_pm_announce_addr(struct mptcp_sock *msk,
const struct mptcp_addr_info *addr,
bool echo);
--
2.45.2
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH mptcp-next v7 04/11] mptcp: change rem type of set_flags
2025-01-06 8:16 [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm Geliang Tang
` (2 preceding siblings ...)
2025-01-06 8:16 ` [PATCH mptcp-next v7 03/11] mptcp: drop skb parameter of set_flags Geliang Tang
@ 2025-01-06 8:16 ` Geliang Tang
2025-01-06 8:16 ` [PATCH mptcp-next v7 05/11] mptcp: add local & remote parameters for set_flags Geliang Tang
` (7 subsequent siblings)
11 siblings, 0 replies; 20+ messages in thread
From: Geliang Tang @ 2025-01-06 8:16 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
Generally, in the path manager interfaces, the local address is defined as
an mptcp_pm_addr_entry type address, while the remote address is defined as
an mptcp_addr_info type one:
(struct mptcp_pm_addr_entry *local, struct mptcp_addr_info *remote)
But the set_flags() interface uses two mptcp_pm_addr_entry type parameters.
This patch changes the second one to mptcp_addr_info type and use helper
mptcp_pm_parse_addr() to parse it instead of using mptcp_pm_parse_entry().
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/pm_userspace.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 51fd84c49474..2a00227e3f35 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -572,9 +572,9 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
int mptcp_userspace_pm_set_flags(struct genl_info *info)
{
struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
- struct mptcp_pm_addr_entry rem = { .addr = { .family = AF_UNSPEC }, };
struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
+ struct mptcp_addr_info rem = { .family = AF_UNSPEC, };
struct mptcp_pm_addr_entry *entry;
struct mptcp_sock *msk;
u8 lookup_by_id = 0;
@@ -603,11 +603,11 @@ int mptcp_userspace_pm_set_flags(struct genl_info *info)
}
if (attr_rem) {
- ret = mptcp_pm_parse_entry(attr_rem, info, false, &rem);
+ ret = mptcp_pm_parse_addr(attr_rem, info, &rem);
if (ret < 0)
goto set_flags_err;
- if (rem.addr.family == AF_UNSPEC) {
+ if (rem.family == AF_UNSPEC) {
NL_SET_ERR_MSG_ATTR(info->extack, attr_rem,
"invalid remote address family");
ret = -EINVAL;
@@ -634,7 +634,7 @@ int mptcp_userspace_pm_set_flags(struct genl_info *info)
spin_unlock_bh(&msk->pm.lock);
lock_sock(sk);
- ret = mptcp_pm_nl_mp_prio_send_ack(msk, &entry->addr, &rem.addr, bkup);
+ ret = mptcp_pm_nl_mp_prio_send_ack(msk, &entry->addr, &rem, bkup);
release_sock(sk);
set_flags_err:
--
2.45.2
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH mptcp-next v7 05/11] mptcp: add local & remote parameters for set_flags
2025-01-06 8:16 [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm Geliang Tang
` (3 preceding siblings ...)
2025-01-06 8:16 ` [PATCH mptcp-next v7 04/11] mptcp: change rem type " Geliang Tang
@ 2025-01-06 8:16 ` Geliang Tang
2025-01-06 9:39 ` Matthieu Baerts
2025-01-06 8:16 ` [PATCH mptcp-next v7 06/11] mptcp: drop info of userspace_pm_remove_id_zero_address Geliang Tang
` (6 subsequent siblings)
11 siblings, 1 reply; 20+ messages in thread
From: Geliang Tang @ 2025-01-06 8:16 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
This patch updates the interfaces set_flags to reduce repetitive code,
adds two more parameters 'local' and 'remote' for them. These addresses
are parsed in public helper mptcp_pm_nl_set_flags_doit(), then pass them
to mptcp_pm_nl_set_flags() and mptcp_userspace_pm_set_flags().
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/pm.c | 8 +++--
net/mptcp/pm_netlink.c | 70 +++++++++++++++++++++++++++-------------
net/mptcp/pm_userspace.c | 43 +++++-------------------
net/mptcp/protocol.h | 12 +++++--
4 files changed, 69 insertions(+), 64 deletions(-)
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 6cd69ea9a69b..4e851be7a177 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -449,11 +449,13 @@ int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
return mptcp_pm_nl_dump_addr(msg, cb);
}
-int mptcp_pm_set_flags(struct genl_info *info)
+int mptcp_pm_set_flags(struct mptcp_pm_addr_entry *local,
+ struct mptcp_addr_info *remote,
+ struct genl_info *info)
{
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
- return mptcp_userspace_pm_set_flags(info);
- return mptcp_pm_nl_set_flags(info);
+ return mptcp_userspace_pm_set_flags(local, remote, info);
+ return mptcp_pm_nl_set_flags(local, remote, info);
}
void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index e9747bc948b9..7f5a72525bca 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1981,10 +1981,10 @@ static int mptcp_nl_set_flags(struct net *net,
return ret;
}
-int mptcp_pm_nl_set_flags(struct genl_info *info)
+int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *local,
+ struct mptcp_addr_info *remote,
+ struct genl_info *info)
{
- struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, };
- struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP |
MPTCP_PM_ADDR_FLAG_FULLMESH;
struct net *net = genl_info_net(info);
@@ -1992,52 +1992,76 @@ int mptcp_pm_nl_set_flags(struct genl_info *info)
struct pm_nl_pernet *pernet;
u8 lookup_by_id = 0;
u8 bkup = 0;
- int ret;
pernet = pm_nl_get_pernet(net);
- ret = mptcp_pm_parse_entry(attr, info, false, &addr);
- if (ret < 0)
- return ret;
-
- if (addr.addr.family == AF_UNSPEC) {
+ if (local->addr.family == AF_UNSPEC)
lookup_by_id = 1;
- if (!addr.addr.id) {
- GENL_SET_ERR_MSG(info, "missing required inputs");
- return -EOPNOTSUPP;
- }
- }
- if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
+ if (local->flags & MPTCP_PM_ADDR_FLAG_BACKUP)
bkup = 1;
spin_lock_bh(&pernet->lock);
- entry = lookup_by_id ? __lookup_addr_by_id(pernet, addr.addr.id) :
- __lookup_addr(pernet, &addr.addr);
+ entry = lookup_by_id ? __lookup_addr_by_id(pernet, local->addr.id) :
+ __lookup_addr(pernet, &local->addr);
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) &&
+ if ((local->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;
}
- changed = (addr.flags ^ entry->flags) & mask;
- entry->flags = (entry->flags & ~mask) | (addr.flags & mask);
- addr = *entry;
+ changed = (local->flags ^ entry->flags) & mask;
+ entry->flags = (entry->flags & ~mask) | (local->flags & mask);
+ *local = *entry;
spin_unlock_bh(&pernet->lock);
- mptcp_nl_set_flags(net, &addr.addr, bkup, changed);
+ mptcp_nl_set_flags(net, &local->addr, bkup, changed);
return 0;
}
int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
{
- return mptcp_pm_set_flags(info);
+ struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
+ struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
+ struct mptcp_addr_info rem = { .family = AF_UNSPEC, };
+ struct nlattr *attr_loc;
+ int ret;
+
+ if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR))
+ return -EINVAL;
+
+ attr_loc = info->attrs[MPTCP_PM_ATTR_ADDR];
+ ret = mptcp_pm_parse_entry(attr_loc, info, false, &loc);
+ if (ret < 0)
+ return ret;
+
+ if (loc.addr.family == AF_UNSPEC) {
+ if (!loc.addr.id) {
+ NL_SET_ERR_MSG_ATTR(info->extack, attr_loc,
+ "missing address ID");
+ return -EOPNOTSUPP;
+ }
+ }
+
+ if (attr_rem) {
+ ret = mptcp_pm_parse_addr(attr_rem, info, &rem);
+ if (ret < 0)
+ return ret;
+
+ if (rem.family == AF_UNSPEC) {
+ NL_SET_ERR_MSG_ATTR(info->extack, attr_rem,
+ "invalid remote address family");
+ return -EINVAL;
+ }
+ }
+
+ return mptcp_pm_set_flags(&loc, &rem, info);
}
static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp)
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 2a00227e3f35..0f703e06d771 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -569,12 +569,10 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
return err;
}
-int mptcp_userspace_pm_set_flags(struct genl_info *info)
+int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local,
+ struct mptcp_addr_info *remote,
+ struct genl_info *info)
{
- struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
- struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
- struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
- struct mptcp_addr_info rem = { .family = AF_UNSPEC, };
struct mptcp_pm_addr_entry *entry;
struct mptcp_sock *msk;
u8 lookup_by_id = 0;
@@ -588,42 +586,17 @@ int mptcp_userspace_pm_set_flags(struct genl_info *info)
sk = (struct sock *)msk;
- ret = mptcp_pm_parse_entry(attr, info, false, &loc);
- if (ret < 0)
- goto set_flags_err;
-
- if (loc.addr.family == AF_UNSPEC) {
+ if (local->addr.family == AF_UNSPEC)
lookup_by_id = 1;
- if (!loc.addr.id) {
- NL_SET_ERR_MSG_ATTR(info->extack, attr,
- "missing address ID");
- ret = -EOPNOTSUPP;
- goto set_flags_err;
- }
- }
- if (attr_rem) {
- ret = mptcp_pm_parse_addr(attr_rem, info, &rem);
- if (ret < 0)
- goto set_flags_err;
-
- if (rem.family == AF_UNSPEC) {
- NL_SET_ERR_MSG_ATTR(info->extack, attr_rem,
- "invalid remote address family");
- ret = -EINVAL;
- goto set_flags_err;
- }
- }
-
- if (loc.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
+ if (local->flags & MPTCP_PM_ADDR_FLAG_BACKUP)
bkup = 1;
spin_lock_bh(&msk->pm.lock);
- entry = lookup_by_id ? mptcp_userspace_pm_lookup_addr_by_id(msk, loc.addr.id) :
- mptcp_userspace_pm_lookup_addr(msk, &loc.addr);
+ entry = lookup_by_id ? mptcp_userspace_pm_lookup_addr_by_id(msk, local->addr.id) :
+ mptcp_userspace_pm_lookup_addr(msk, &local->addr);
if (!entry) {
spin_unlock_bh(&msk->pm.lock);
- ret = -EINVAL;
goto set_flags_err;
}
@@ -634,7 +607,7 @@ int mptcp_userspace_pm_set_flags(struct genl_info *info)
spin_unlock_bh(&msk->pm.lock);
lock_sock(sk);
- ret = mptcp_pm_nl_mp_prio_send_ack(msk, &entry->addr, &rem, bkup);
+ ret = mptcp_pm_nl_mp_prio_send_ack(msk, &entry->addr, remote, bkup);
release_sock(sk);
set_flags_err:
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index df5619ae8a14..d5a28ffbc1c3 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -1028,9 +1028,15 @@ bool mptcp_lookup_subflow_by_saddr(const struct list_head *list,
const struct mptcp_addr_info *saddr);
bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk,
const struct mptcp_addr_info *addr);
-int mptcp_pm_set_flags(struct genl_info *info);
-int mptcp_pm_nl_set_flags(struct genl_info *info);
-int mptcp_userspace_pm_set_flags(struct genl_info *info);
+int mptcp_pm_set_flags(struct mptcp_pm_addr_entry *local,
+ struct mptcp_addr_info *remote,
+ struct genl_info *info);
+int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *local,
+ struct mptcp_addr_info *remote,
+ struct genl_info *info);
+int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local,
+ struct mptcp_addr_info *remote,
+ struct genl_info *info);
int mptcp_pm_announce_addr(struct mptcp_sock *msk,
const struct mptcp_addr_info *addr,
bool echo);
--
2.45.2
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH mptcp-next v7 05/11] mptcp: add local & remote parameters for set_flags
2025-01-06 8:16 ` [PATCH mptcp-next v7 05/11] mptcp: add local & remote parameters for set_flags Geliang Tang
@ 2025-01-06 9:39 ` Matthieu Baerts
2025-01-06 10:01 ` Matthieu Baerts
0 siblings, 1 reply; 20+ messages in thread
From: Matthieu Baerts @ 2025-01-06 9:39 UTC (permalink / raw)
To: Geliang Tang, mptcp; +Cc: Geliang Tang
Hi Geliang,
On 06/01/2025 09:16, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> This patch updates the interfaces set_flags to reduce repetitive code,
> adds two more parameters 'local' and 'remote' for them. These addresses
> are parsed in public helper mptcp_pm_nl_set_flags_doit(), then pass them
> to mptcp_pm_nl_set_flags() and mptcp_userspace_pm_set_flags().
Because the in-kernel and userspace PM have different requirements:
token and remote addr only for the userspace PM, search by local addr ID
probably only for the in-kernel, etc. it might be clearer to keep them
separated.
At the end, I think only the parsing of the local address can be done
for both (mptcp_pm_parse_entry()). Maybe not worth it to move only this
part? WDYT?
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH mptcp-next v7 05/11] mptcp: add local & remote parameters for set_flags
2025-01-06 9:39 ` Matthieu Baerts
@ 2025-01-06 10:01 ` Matthieu Baerts
0 siblings, 0 replies; 20+ messages in thread
From: Matthieu Baerts @ 2025-01-06 10:01 UTC (permalink / raw)
To: Geliang Tang, mptcp; +Cc: Geliang Tang
Hi Geliang,
On 06/01/2025 10:39, Matthieu Baerts wrote:
> Hi Geliang,
>
> On 06/01/2025 09:16, Geliang Tang wrote:
>> From: Geliang Tang <tanggeliang@kylinos.cn>
>>
>> This patch updates the interfaces set_flags to reduce repetitive code,
>> adds two more parameters 'local' and 'remote' for them. These addresses
>> are parsed in public helper mptcp_pm_nl_set_flags_doit(), then pass them
>> to mptcp_pm_nl_set_flags() and mptcp_userspace_pm_set_flags().
>
> Because the in-kernel and userspace PM have different requirements:
> token and remote addr only for the userspace PM, search by local addr ID
> probably only for the in-kernel, etc. it might be clearer to keep them
> separated.
>
> At the end, I think only the parsing of the local address can be done
> for both (mptcp_pm_parse_entry()). Maybe not worth it to move only this
> part? WDYT?
Just in case you drop this patch, please note that in my v6, I was also
modifying the two set_flags() helpers in different patches:
- The split without changing the behaviour in "mptcp: pm: more precise
error messages"
- Keeping "mptcp: pm: userspace: flags: clearer msg if no remote addr"
- Using NL_SET_ERR_MSG_ATTR() in "mptcp: pm: use NL_SET_ERR_MSG_ATTR
when possible"
- "missing address ID" message in "mptcp: pm: improve error messages"
- Adding GENL_REQ_ATTR_CHECK() in "mptcp: pm: mark missing address
attributes"
Make sure to compare your future v8 with the v6 ;)
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH mptcp-next v7 06/11] mptcp: drop info of userspace_pm_remove_id_zero_address
2025-01-06 8:16 [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm Geliang Tang
` (4 preceding siblings ...)
2025-01-06 8:16 ` [PATCH mptcp-next v7 05/11] mptcp: add local & remote parameters for set_flags Geliang Tang
@ 2025-01-06 8:16 ` Geliang Tang
2025-01-06 9:48 ` Matthieu Baerts
2025-01-06 8:16 ` [PATCH mptcp-next v7 07/11] mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible Geliang Tang
` (5 subsequent siblings)
11 siblings, 1 reply; 20+ messages in thread
From: Geliang Tang @ 2025-01-06 8:16 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
The only use of 'info' parameter of userspace_pm_remove_id_zero_address()
is to set an error message into it.
This patch drops this parameter and sets the error message where this
function is called in mptcp_pm_nl_remove_doit().
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/pm_userspace.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 0f703e06d771..a6580942e628 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -259,8 +259,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
return err;
}
-static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk,
- struct genl_info *info)
+static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk)
{
struct mptcp_rm_list list = { .nr = 0 };
struct mptcp_subflow_context *subflow;
@@ -275,10 +274,8 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk,
break;
}
}
- if (!has_id_0) {
- GENL_SET_ERR_MSG(info, "address with id 0 not found");
+ if (!has_id_0)
goto remove_err;
- }
list.ids[list.nr++] = 0;
@@ -336,7 +333,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
sk = (struct sock *)msk;
if (id_val == 0) {
- err = mptcp_userspace_pm_remove_id_zero_address(msk, info);
+ err = mptcp_userspace_pm_remove_id_zero_address(msk);
goto out;
}
@@ -345,7 +342,6 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
spin_lock_bh(&msk->pm.lock);
match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val);
if (!match) {
- GENL_SET_ERR_MSG(info, "address with specified id not found");
spin_unlock_bh(&msk->pm.lock);
release_sock(sk);
goto out;
@@ -362,6 +358,11 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
err = 0;
out:
+ if (err)
+ GENL_SET_ERR_MSG_FMT(info,
+ "address with id %u not found",
+ id_val);
+
sock_put(sk);
return err;
}
--
2.45.2
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH mptcp-next v7 06/11] mptcp: drop info of userspace_pm_remove_id_zero_address
2025-01-06 8:16 ` [PATCH mptcp-next v7 06/11] mptcp: drop info of userspace_pm_remove_id_zero_address Geliang Tang
@ 2025-01-06 9:48 ` Matthieu Baerts
0 siblings, 0 replies; 20+ messages in thread
From: Matthieu Baerts @ 2025-01-06 9:48 UTC (permalink / raw)
To: Geliang Tang, mptcp; +Cc: Geliang Tang
On 06/01/2025 09:16, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> The only use of 'info' parameter of userspace_pm_remove_id_zero_address()
> is to set an error message into it.
Can you add:
Plus, this helper will only fail when it cannot find any subflows with a
local address ID 0.
(Because if there were different types of errors, you could not drop
'info').
>
> This patch drops this parameter and sets the error message where this
> function is called in mptcp_pm_nl_remove_doit().
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
> net/mptcp/pm_userspace.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
> index 0f703e06d771..a6580942e628 100644
> --- a/net/mptcp/pm_userspace.c
> +++ b/net/mptcp/pm_userspace.c
> @@ -259,8 +259,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
> return err;
> }
>
> -static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk,
> - struct genl_info *info)
> +static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk)
> {
> struct mptcp_rm_list list = { .nr = 0 };
> struct mptcp_subflow_context *subflow;
> @@ -275,10 +274,8 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk,
> break;
> }
> }
> - if (!has_id_0) {
> - GENL_SET_ERR_MSG(info, "address with id 0 not found");
> + if (!has_id_0)
> goto remove_err;
> - }
>
> list.ids[list.nr++] = 0;
>
> @@ -336,7 +333,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
> sk = (struct sock *)msk;
>
> if (id_val == 0) {
> - err = mptcp_userspace_pm_remove_id_zero_address(msk, info);
> + err = mptcp_userspace_pm_remove_id_zero_address(msk);
> goto out;
> }
>
> @@ -345,7 +342,6 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
> spin_lock_bh(&msk->pm.lock);
> match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val);
> if (!match) {
> - GENL_SET_ERR_MSG(info, "address with specified id not found");
> spin_unlock_bh(&msk->pm.lock);
> release_sock(sk);
> goto out;
> @@ -362,6 +358,11 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
>
> err = 0;
> out:
> + if (err)
> + GENL_SET_ERR_MSG_FMT(info,
Can you not use NL_SET_ERR_MSG_ATTR_FMT() here?
> + "address with id %u not found",
> + id_val);
Detail: in fact, I don't think it is needed to specify the ID in the
error message to send to the userspace: the ID has been specified by the
userspace, it knows what it has set. Up to you.
> +
> sock_put(sk);
> return err;
> }
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH mptcp-next v7 07/11] mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible
2025-01-06 8:16 [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm Geliang Tang
` (5 preceding siblings ...)
2025-01-06 8:16 ` [PATCH mptcp-next v7 06/11] mptcp: drop info of userspace_pm_remove_id_zero_address Geliang Tang
@ 2025-01-06 8:16 ` Geliang Tang
2025-01-06 9:04 ` Matthieu Baerts
2025-01-06 8:16 ` [PATCH mptcp-next v7 08/11] mptcp: pm: improve error messages Geliang Tang
` (4 subsequent siblings)
11 siblings, 1 reply; 20+ messages in thread
From: Geliang Tang @ 2025-01-06 8:16 UTC (permalink / raw)
To: mptcp; +Cc: Matthieu Baerts (NGI0)
From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
Instead of only returning a text message with GENL_SET_ERR_MSG(),
NL_SET_ERR_MSG_ATTR() can help the userspace developers by also
reporting which attribute is faulty.
When the error is specific to an attribute, NL_SET_ERR_MSG_ATTR() is now
used. The error messages have not been modified in this commit.
mptcp_userspace_pm_remove_id_zero_address() has been modified to set the
missing attribute.
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
net/mptcp/pm_netlink.c | 16 ++++++++++------
net/mptcp/pm_userspace.c | 13 ++++++++-----
2 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 7f5a72525bca..46a97a3bf319 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1403,18 +1403,21 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info)
return ret;
if (addr.addr.port && !address_use_port(&addr)) {
- GENL_SET_ERR_MSG(info, "flags must have signal and not subflow when using port");
+ NL_SET_ERR_MSG_ATTR(info->extack, attr,
+ "flags must have signal and not subflow when using port");
return -EINVAL;
}
if (addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL &&
addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) {
- GENL_SET_ERR_MSG(info, "flags mustn't have both signal and fullmesh");
+ NL_SET_ERR_MSG_ATTR(info->extack, attr,
+ "flags mustn't have both signal and fullmesh");
return -EINVAL;
}
if (addr.flags & MPTCP_PM_ADDR_FLAG_IMPLICIT) {
- GENL_SET_ERR_MSG(info, "can't create IMPLICIT endpoint");
+ NL_SET_ERR_MSG_ATTR(info->extack, attr,
+ "can't create IMPLICIT endpoint");
return -EINVAL;
}
@@ -1608,7 +1611,7 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info)
spin_lock_bh(&pernet->lock);
entry = __lookup_addr_by_id(pernet, addr.addr.id);
if (!entry) {
- GENL_SET_ERR_MSG(info, "address not found");
+ NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
spin_unlock_bh(&pernet->lock);
return -EINVAL;
}
@@ -1790,7 +1793,7 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
rcu_read_lock();
entry = __lookup_addr_by_id(pernet, addr.addr.id);
if (!entry) {
- GENL_SET_ERR_MSG(info, "address not found");
+ NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
ret = -EINVAL;
goto unlock_fail;
}
@@ -1875,7 +1878,8 @@ static int parse_limit(struct genl_info *info, int id, unsigned int *limit)
*limit = nla_get_u32(attr);
if (*limit > MPTCP_PM_ADDR_MAX) {
- GENL_SET_ERR_MSG(info, "limit greater than maximum");
+ NL_SET_ERR_MSG_ATTR(info->extack, attr,
+ "limit greater than maximum");
return -EINVAL;
}
return 0;
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index a6580942e628..066fd89b1691 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -190,7 +190,8 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in
}
if (!mptcp_pm_is_userspace(msk)) {
- GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected");
+ NL_SET_ERR_MSG_ATTR(info->extack, token,
+ "invalid request; userspace PM not selected");
sock_put((struct sock *)msk);
return NULL;
}
@@ -237,7 +238,8 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
err = mptcp_userspace_pm_append_new_local_addr(msk, &addr_val, false);
if (err < 0) {
- GENL_SET_ERR_MSG(info, "did not match address and id");
+ NL_SET_ERR_MSG_ATTR(info->extack, addr,
+ "did not match address and id");
goto announce_err;
}
@@ -396,7 +398,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
}
if (entry.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
- GENL_SET_ERR_MSG(info, "invalid addr flags");
+ NL_SET_ERR_MSG_ATTR(info->extack, laddr, "invalid addr flags");
err = -EINVAL;
goto create_err;
}
@@ -416,7 +418,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
err = mptcp_userspace_pm_append_new_local_addr(msk, &entry, false);
if (err < 0) {
- GENL_SET_ERR_MSG(info, "did not match address and id");
+ NL_SET_ERR_MSG_ATTR(info->extack, laddr,
+ "did not match address and id");
goto create_err;
}
@@ -704,7 +707,7 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb,
spin_lock_bh(&msk->pm.lock);
entry = mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id);
if (!entry) {
- GENL_SET_ERR_MSG(info, "address not found");
+ NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found");
ret = -EINVAL;
goto unlock_fail;
}
--
2.45.2
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH mptcp-next v7 07/11] mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible
2025-01-06 8:16 ` [PATCH mptcp-next v7 07/11] mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible Geliang Tang
@ 2025-01-06 9:04 ` Matthieu Baerts
0 siblings, 0 replies; 20+ messages in thread
From: Matthieu Baerts @ 2025-01-06 9:04 UTC (permalink / raw)
To: Geliang Tang, mptcp
Hi Geliang,
On 06/01/2025 09:16, Geliang Tang wrote:
> From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
>
> Instead of only returning a text message with GENL_SET_ERR_MSG(),
> NL_SET_ERR_MSG_ATTR() can help the userspace developers by also
> reporting which attribute is faulty.
>
> When the error is specific to an attribute, NL_SET_ERR_MSG_ATTR() is now
> used. The error messages have not been modified in this commit.
>
> mptcp_userspace_pm_remove_id_zero_address() has been modified to set the
> missing attribute.
It is no longer the case. Can you remove these 2 lines please?
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH mptcp-next v7 08/11] mptcp: pm: improve error messages
2025-01-06 8:16 [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm Geliang Tang
` (6 preceding siblings ...)
2025-01-06 8:16 ` [PATCH mptcp-next v7 07/11] mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible Geliang Tang
@ 2025-01-06 8:16 ` Geliang Tang
2025-01-06 9:55 ` Matthieu Baerts
2025-01-06 8:16 ` [PATCH mptcp-next v7 09/11] mptcp: pm: userspace: use GENL_REQ_ATTR_CHECK Geliang Tang
` (3 subsequent siblings)
11 siblings, 1 reply; 20+ messages in thread
From: Geliang Tang @ 2025-01-06 8:16 UTC (permalink / raw)
To: mptcp; +Cc: Matthieu Baerts (NGI0)
From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
Some error messages were:
- too generic: "missing input", "invalid request"
- not precise enough: "limit greater than maximum" but what's the max?
- missing: subflow not found, or connect error.
This can be easily improved by being more precise, or adding new error
messages.
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
net/mptcp/pm_netlink.c | 5 +++--
net/mptcp/pm_userspace.c | 7 ++++++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 46a97a3bf319..528718cb70ec 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1878,8 +1878,9 @@ static int parse_limit(struct genl_info *info, int id, unsigned int *limit)
*limit = nla_get_u32(attr);
if (*limit > MPTCP_PM_ADDR_MAX) {
- NL_SET_ERR_MSG_ATTR(info->extack, attr,
- "limit greater than maximum");
+ NL_SET_ERR_MSG_ATTR_FMT(info->extack, attr,
+ "limit greater than maximum (%u)",
+ MPTCP_PM_ADDR_MAX);
return -EINVAL;
}
return 0;
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 066fd89b1691..341db3bc191b 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -191,7 +191,7 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in
if (!mptcp_pm_is_userspace(msk)) {
NL_SET_ERR_MSG_ATTR(info->extack, token,
- "invalid request; userspace PM not selected");
+ "userspace PM not selected");
sock_put((struct sock *)msk);
return NULL;
}
@@ -430,6 +430,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
lock_sock(sk);
err = __mptcp_subflow_connect(sk, &local, &addr_r);
release_sock(sk);
+ if (err)
+ GENL_SET_ERR_MSG_FMT(info, "connect error: %d", err);
spin_lock_bh(&msk->pm.lock);
if (err)
@@ -555,6 +557,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
lock_sock(sk);
ssk = mptcp_nl_find_ssk(msk, &addr_l.addr, &addr_r);
if (!ssk) {
+ GENL_SET_ERR_MSG(info, "subflow not found");
err = -ESRCH;
goto release_sock;
}
@@ -613,6 +616,8 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local,
lock_sock(sk);
ret = mptcp_pm_nl_mp_prio_send_ack(msk, &entry->addr, remote, bkup);
release_sock(sk);
+ if (ret)
+ GENL_SET_ERR_MSG(info, "mp_prio send ack failed");
set_flags_err:
sock_put(sk);
--
2.45.2
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH mptcp-next v7 08/11] mptcp: pm: improve error messages
2025-01-06 8:16 ` [PATCH mptcp-next v7 08/11] mptcp: pm: improve error messages Geliang Tang
@ 2025-01-06 9:55 ` Matthieu Baerts
0 siblings, 0 replies; 20+ messages in thread
From: Matthieu Baerts @ 2025-01-06 9:55 UTC (permalink / raw)
To: Geliang Tang, mptcp
Hi Geliang,
On 06/01/2025 09:16, Geliang Tang wrote:
> From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
>
> Some error messages were:
>
> - too generic: "missing input", "invalid request"
>
> - not precise enough: "limit greater than maximum" but what's the max?
>
> - missing: subflow not found, or connect error.
>
> This can be easily improved by being more precise, or adding new error
> messages.
(...)
> diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
> index 066fd89b1691..341db3bc191b 100644
> --- a/net/mptcp/pm_userspace.c
> +++ b/net/mptcp/pm_userspace.c
(...)
> @@ -613,6 +616,8 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local,
> lock_sock(sk);
> ret = mptcp_pm_nl_mp_prio_send_ack(msk, &entry->addr, remote, bkup);
> release_sock(sk);
> + if (ret)
> + GENL_SET_ERR_MSG(info, "mp_prio send ack failed");
As mentioned on my comment on the v6, it might be better to have:
/* mptcp_pm_nl_mp_prio_send_ack() only fails in one case */
if (ret < 0)
GENL_SET_ERR_MSG(info, "subflow not found");
>
> set_flags_err:
> sock_put(sk);
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH mptcp-next v7 09/11] mptcp: pm: userspace: use GENL_REQ_ATTR_CHECK
2025-01-06 8:16 [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm Geliang Tang
` (7 preceding siblings ...)
2025-01-06 8:16 ` [PATCH mptcp-next v7 08/11] mptcp: pm: improve error messages Geliang Tang
@ 2025-01-06 8:16 ` Geliang Tang
2025-01-06 8:16 ` [PATCH mptcp-next v7 10/11] mptcp: pm: remove duplicated error messages Geliang Tang
` (2 subsequent siblings)
11 siblings, 0 replies; 20+ messages in thread
From: Geliang Tang @ 2025-01-06 8:16 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang, Jakub Kicinski, Matthieu Baerts
From: Geliang Tang <tanggeliang@kylinos.cn>
A more general way to check if MPTCP_PM_ATTR_* exists in 'info'
is to use GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_*) instead of
directly reading info->attrs[MPTCP_PM_ATTR_*] and then checking
if it's NULL.
So this patch uses GENL_REQ_ATTR_CHECK() for userspace PM in
mptcp_pm_nl_announce_doit(), mptcp_pm_nl_remove_doit(),
mptcp_pm_nl_subflow_create_doit(), mptcp_pm_nl_subflow_destroy_doit()
and mptcp_userspace_pm_get_sock().
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
net/mptcp/pm_userspace.c | 41 +++++++++++++++++++---------------------
1 file changed, 19 insertions(+), 22 deletions(-)
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 341db3bc191b..201595f9ebf9 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -175,14 +175,13 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk,
static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info)
{
- struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
struct mptcp_sock *msk;
+ struct nlattr *token;
- if (!token) {
- GENL_SET_ERR_MSG(info, "missing required token");
+ if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_TOKEN))
return NULL;
- }
+ token = info->attrs[MPTCP_PM_ATTR_TOKEN];
msk = mptcp_token_get_sock(genl_info_net(info), nla_get_u32(token));
if (!msk) {
NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token");
@@ -201,16 +200,14 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in
int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
{
- struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR];
struct mptcp_pm_addr_entry addr_val;
struct mptcp_sock *msk;
+ struct nlattr *addr;
int err = -EINVAL;
struct sock *sk;
- if (!addr) {
- GENL_SET_ERR_MSG(info, "missing required address");
+ if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR))
return err;
- }
msk = mptcp_userspace_pm_get_sock(info);
if (!msk)
@@ -218,6 +215,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
sk = (struct sock *)msk;
+ addr = info->attrs[MPTCP_PM_ATTR_ADDR];
err = mptcp_pm_parse_entry(addr, info, true, &addr_val);
if (err < 0) {
GENL_SET_ERR_MSG(info, "error parsing local address");
@@ -314,18 +312,17 @@ void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk,
int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
{
- struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID];
struct mptcp_pm_addr_entry *match;
struct mptcp_sock *msk;
+ struct nlattr *id;
int err = -EINVAL;
struct sock *sk;
u8 id_val;
- if (!id) {
- GENL_SET_ERR_MSG(info, "missing required ID");
+ if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_LOC_ID))
return err;
- }
+ id = info->attrs[MPTCP_PM_ATTR_LOC_ID];
id_val = nla_get_u8(id);
msk = mptcp_userspace_pm_get_sock(info);
@@ -371,19 +368,17 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
{
- struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
- struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
struct mptcp_pm_addr_entry entry = { 0 };
struct mptcp_addr_info addr_r;
+ struct nlattr *raddr, *laddr;
struct mptcp_pm_local local;
struct mptcp_sock *msk;
int err = -EINVAL;
struct sock *sk;
- if (!laddr || !raddr) {
- GENL_SET_ERR_MSG(info, "missing required address(es)");
+ if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR) ||
+ GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE))
return err;
- }
msk = mptcp_userspace_pm_get_sock(info);
if (!msk)
@@ -391,6 +386,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
sk = (struct sock *)msk;
+ laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
err = mptcp_pm_parse_entry(laddr, info, true, &entry);
if (err < 0) {
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr");
@@ -404,6 +400,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
}
entry.flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW;
+ raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
err = mptcp_pm_parse_addr(raddr, info, &addr_r);
if (err < 0) {
NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr");
@@ -495,18 +492,16 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk,
int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info)
{
- struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
- struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
struct mptcp_pm_addr_entry addr_l;
struct mptcp_addr_info addr_r;
+ struct nlattr *raddr, *laddr;
struct mptcp_sock *msk;
struct sock *sk, *ssk;
int err = -EINVAL;
- if (!laddr || !raddr) {
- GENL_SET_ERR_MSG(info, "missing required address(es)");
+ if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR) ||
+ GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE))
return err;
- }
msk = mptcp_userspace_pm_get_sock(info);
if (!msk)
@@ -514,12 +509,14 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
sk = (struct sock *)msk;
+ laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
err = mptcp_pm_parse_entry(laddr, info, true, &addr_l);
if (err < 0) {
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr");
goto destroy_err;
}
+ raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
err = mptcp_pm_parse_addr(raddr, info, &addr_r);
if (err < 0) {
NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr");
--
2.45.2
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH mptcp-next v7 10/11] mptcp: pm: remove duplicated error messages
2025-01-06 8:16 [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm Geliang Tang
` (8 preceding siblings ...)
2025-01-06 8:16 ` [PATCH mptcp-next v7 09/11] mptcp: pm: userspace: use GENL_REQ_ATTR_CHECK Geliang Tang
@ 2025-01-06 8:16 ` Geliang Tang
2025-01-06 8:16 ` [PATCH mptcp-next v7 11/11] mptcp: pm: mark missing address attributes Geliang Tang
2025-01-06 9:20 ` [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm MPTCP CI
11 siblings, 0 replies; 20+ messages in thread
From: Geliang Tang @ 2025-01-06 8:16 UTC (permalink / raw)
To: mptcp; +Cc: Matthieu Baerts (NGI0)
From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
mptcp_pm_parse_entry() and mptcp_pm_parse_addr() will already set a
error message in case of parsing issue.
Then, no need to override this error message with another less precise
one: "error parsing address".
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
net/mptcp/pm_userspace.c | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 201595f9ebf9..dc9ebfb06d96 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -217,10 +217,8 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
addr = info->attrs[MPTCP_PM_ATTR_ADDR];
err = mptcp_pm_parse_entry(addr, info, true, &addr_val);
- if (err < 0) {
- GENL_SET_ERR_MSG(info, "error parsing local address");
+ if (err < 0)
goto announce_err;
- }
if (addr_val.addr.id == 0) {
NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr id");
@@ -388,10 +386,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
err = mptcp_pm_parse_entry(laddr, info, true, &entry);
- if (err < 0) {
- NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr");
+ if (err < 0)
goto create_err;
- }
if (entry.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "invalid addr flags");
@@ -402,10 +398,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
err = mptcp_pm_parse_addr(raddr, info, &addr_r);
- if (err < 0) {
- NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr");
+ if (err < 0)
goto create_err;
- }
if (!mptcp_pm_addr_families_match(sk, &entry.addr, &addr_r)) {
GENL_SET_ERR_MSG(info, "families mismatch");
@@ -511,17 +505,13 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
err = mptcp_pm_parse_entry(laddr, info, true, &addr_l);
- if (err < 0) {
- NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr");
+ if (err < 0)
goto destroy_err;
- }
raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
err = mptcp_pm_parse_addr(raddr, info, &addr_r);
- if (err < 0) {
- NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr");
+ if (err < 0)
goto destroy_err;
- }
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
if (addr_l.addr.family == AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) {
--
2.45.2
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH mptcp-next v7 11/11] mptcp: pm: mark missing address attributes
2025-01-06 8:16 [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm Geliang Tang
` (9 preceding siblings ...)
2025-01-06 8:16 ` [PATCH mptcp-next v7 10/11] mptcp: pm: remove duplicated error messages Geliang Tang
@ 2025-01-06 8:16 ` Geliang Tang
2025-01-06 9:20 ` [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm MPTCP CI
11 siblings, 0 replies; 20+ messages in thread
From: Geliang Tang @ 2025-01-06 8:16 UTC (permalink / raw)
To: mptcp; +Cc: Matthieu Baerts (NGI0)
From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
mptcp_pm_parse_entry() will check if the given attribute is defined. If
not, it will return a generic error: "missing address info".
It might then not be clear for the userspace developer which attribute
is missing, especially when the command takes multiple addresses.
By using GENL_REQ_ATTR_CHECK(), the userspace will get a hint about
which attribute is missing, making thing clearer. Note that this is what
was already done for most of the other MPTCP NL commands, this patch
simply adds the missing ones.
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
net/mptcp/pm_netlink.c | 18 +++++++++++++++---
net/mptcp/pm_userspace.c | 6 +++++-
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 528718cb70ec..46852c479b43 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1393,11 +1393,15 @@ static bool mptcp_pm_has_addr_attr_id(const struct nlattr *attr,
int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info)
{
- struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
struct mptcp_pm_addr_entry addr, *entry;
+ struct nlattr *attr;
int ret;
+ if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
+ return -EINVAL;
+
+ attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
ret = mptcp_pm_parse_entry(attr, info, true, &addr);
if (ret < 0)
return ret;
@@ -1590,12 +1594,16 @@ static int mptcp_nl_remove_id_zero_address(struct net *net,
int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info)
{
- struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
struct mptcp_pm_addr_entry addr, *entry;
unsigned int addr_max;
+ struct nlattr *attr;
int ret;
+ if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
+ return -EINVAL;
+
+ attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
if (ret < 0)
return ret;
@@ -1767,13 +1775,17 @@ int mptcp_nl_fill_addr(struct sk_buff *skb,
int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
{
- struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
struct mptcp_pm_addr_entry addr, *entry;
struct sk_buff *msg;
+ struct nlattr *attr;
void *reply;
int ret;
+ if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
+ return -EINVAL;
+
+ attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
if (ret < 0)
return ret;
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index dc9ebfb06d96..801b1280a1aa 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -663,20 +663,24 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
int mptcp_userspace_pm_get_addr(struct sk_buff *skb,
struct genl_info *info)
{
- struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
struct mptcp_pm_addr_entry addr, *entry;
struct mptcp_sock *msk;
struct sk_buff *msg;
+ struct nlattr *attr;
int ret = -EINVAL;
struct sock *sk;
void *reply;
+ if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR))
+ return ret;
+
msk = mptcp_userspace_pm_get_sock(info);
if (!msk)
return ret;
sk = (struct sock *)msk;
+ attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR];
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
if (ret < 0)
goto out;
--
2.45.2
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm
2025-01-06 8:16 [PATCH mptcp-next v7 00/11] mptcp: use GENL_REQ_ATTR_CHECK in userspace pm Geliang Tang
` (10 preceding siblings ...)
2025-01-06 8:16 ` [PATCH mptcp-next v7 11/11] mptcp: pm: mark missing address attributes Geliang Tang
@ 2025-01-06 9:20 ` MPTCP CI
11 siblings, 0 replies; 20+ messages in thread
From: MPTCP CI @ 2025-01-06 9:20 UTC (permalink / raw)
To: Matthieu Baerts; +Cc: mptcp
Hi Matthieu,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Unstable: 1 failed test(s): selftest_userspace_pm - Critical: 1 Call Trace(s) ❌
- KVM Validation: debug: Unstable: 2 failed test(s): packetdrill_fastopen selftest_userspace_pm - Critical: 1 Call Trace(s) ❌
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/12629204806
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/1230ba468eda
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=922462
If there are some issues, you can reproduce them using the same environment as
the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normal
For more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a
stable tests suite when executed on a public CI like here, it is possible some
reported issues are not due to your modifications. Still, do not hesitate to
help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
^ permalink raw reply [flat|nested] 20+ messages in thread