MPTCP Linux Development
 help / color / mirror / Atom feed
* [PATCH mptcp-next v3] mptcp: use GENL_REQ_ATTR_CHECK for token
@ 2024-12-16  8:31 Geliang Tang
  2024-12-16  9:29 ` MPTCP CI
  2024-12-16 11:24 ` Matthieu Baerts
  0 siblings, 2 replies; 5+ messages in thread
From: Geliang Tang @ 2024-12-16  8:31 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

A more general way to check if MPTCP_PM_ATTR_TOKEN exists in 'info'
is to use GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_TOKEN) instead of
directly reading info->attrs[MPTCP_PM_ATTR_TOKEN] and then checking
if it's NULL.

So this patch uses GENL_REQ_ATTR_CHECK() for 'token' in 'info' in
mptcp_userspace_pm_get_sock().

'Suggested-by: Jakub Kicinski <kuba@kernel.org>'
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
v3:
 - use GENL_REQ_ATTR_CHECK in mptcp_userspace_pm_get_sock only
 - drop GENL_SET_ERR_MSG as Matt suggested (thanks)

v2:
 - use GENL_REQ_ATTR_CHECK in get_addr(), dump_addr() and set_flags()
   too.
---
 net/mptcp/pm_userspace.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 740a10d669f8..04405fc5a930 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");
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH mptcp-next v3] mptcp: use GENL_REQ_ATTR_CHECK for token
  2024-12-16  8:31 [PATCH mptcp-next v3] mptcp: use GENL_REQ_ATTR_CHECK for token Geliang Tang
@ 2024-12-16  9:29 ` MPTCP CI
  2024-12-16 11:24 ` Matthieu Baerts
  1 sibling, 0 replies; 5+ messages in thread
From: MPTCP CI @ 2024-12-16  9:29 UTC (permalink / raw)
  To: Geliang Tang; +Cc: mptcp

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- 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/12348979008

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/3a1e74facb64
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=918117


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] 5+ messages in thread

* Re: [PATCH mptcp-next v3] mptcp: use GENL_REQ_ATTR_CHECK for token
  2024-12-16  8:31 [PATCH mptcp-next v3] mptcp: use GENL_REQ_ATTR_CHECK for token Geliang Tang
  2024-12-16  9:29 ` MPTCP CI
@ 2024-12-16 11:24 ` Matthieu Baerts
  2024-12-20  9:50   ` Geliang Tang
  1 sibling, 1 reply; 5+ messages in thread
From: Matthieu Baerts @ 2024-12-16 11:24 UTC (permalink / raw)
  To: Geliang Tang, mptcp; +Cc: Geliang Tang

Hi Geliang,

On 16/12/2024 09:31, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> A more general way to check if MPTCP_PM_ATTR_TOKEN exists in 'info'
> is to use GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_TOKEN) instead of
> directly reading info->attrs[MPTCP_PM_ATTR_TOKEN] and then checking
> if it's NULL.
> 
> So this patch uses GENL_REQ_ATTR_CHECK() for 'token' in 'info' in
> mptcp_userspace_pm_get_sock().
> 
> 'Suggested-by: Jakub Kicinski <kuba@kernel.org>'
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
> v3:
>  - use GENL_REQ_ATTR_CHECK in mptcp_userspace_pm_get_sock only
>  - drop GENL_SET_ERR_MSG as Matt suggested (thanks)

Thank you for the v3. While at it, do you want to do a similar change
everywhere we do:

  struct nlattr *X = info->attrs[MPTCP_PM_ATTR_Y]:
  if (!X) {
      GENL_SET_ERR_MSG(info, "missing ...");
      return Z;
  }

e.g. in mptcp_pm_nl_announce_doit() (addr), mptcp_pm_nl_remove_doit()
(id), mptcp_pm_nl_subflow_create_doit() (raddr, laddr),
mptcp_pm_nl_subflow_destroy_doit() (raddr, laddr).
(and maybe mptcp_pm_parse_pm_addr_attr(), but it needs more changes
around to pass the attribute ID, probably best not to change that)

Also, do you know if 'pm_nl_ctl' will continue to indicate a helpful
message if such attribute is missing (that's a message more for
userspace app dev)? Or does it need to be modified to display the
missing argument set by GENL_REQ_ATTR_CHECK()?

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH mptcp-next v3] mptcp: use GENL_REQ_ATTR_CHECK for token
  2024-12-16 11:24 ` Matthieu Baerts
@ 2024-12-20  9:50   ` Geliang Tang
  2024-12-21 10:39     ` Matthieu Baerts
  0 siblings, 1 reply; 5+ messages in thread
From: Geliang Tang @ 2024-12-20  9:50 UTC (permalink / raw)
  To: Matthieu Baerts, mptcp; +Cc: Geliang Tang

Hi Matt,

On Mon, 2024-12-16 at 12:24 +0100, Matthieu Baerts wrote:
> Hi Geliang,
> 
> On 16/12/2024 09:31, Geliang Tang wrote:
> > From: Geliang Tang <tanggeliang@kylinos.cn>
> > 
> > A more general way to check if MPTCP_PM_ATTR_TOKEN exists in 'info'
> > is to use GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_TOKEN) instead of
> > directly reading info->attrs[MPTCP_PM_ATTR_TOKEN] and then checking
> > if it's NULL.
> > 
> > So this patch uses GENL_REQ_ATTR_CHECK() for 'token' in 'info' in
> > mptcp_userspace_pm_get_sock().
> > 
> > 'Suggested-by: Jakub Kicinski <kuba@kernel.org>'
> > Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> > ---
> > v3:
> >  - use GENL_REQ_ATTR_CHECK in mptcp_userspace_pm_get_sock only
> >  - drop GENL_SET_ERR_MSG as Matt suggested (thanks)
> 
> Thank you for the v3. While at it, do you want to do a similar change
> everywhere we do:
> 
>   struct nlattr *X = info->attrs[MPTCP_PM_ATTR_Y]:
>   if (!X) {
>       GENL_SET_ERR_MSG(info, "missing ...");
>       return Z;
>   }
> 
> e.g. in mptcp_pm_nl_announce_doit() (addr), mptcp_pm_nl_remove_doit()
> (id), mptcp_pm_nl_subflow_create_doit() (raddr, laddr),
> mptcp_pm_nl_subflow_destroy_doit() (raddr, laddr).
> (and maybe mptcp_pm_parse_pm_addr_attr(), but it needs more changes
> around to pass the attribute ID, probably best not to change that)

Thanks for this suggestion, I updated this in v4.

> 
> Also, do you know if 'pm_nl_ctl' will continue to indicate a helpful
> message if such attribute is missing (that's a message more for

'pm_nl_ctl' can't display nl error msg, this is a bug in nl_error():

 $ sudo ip mptcp endpoint del id 100
 Error: address not found.
 $ sudo ./pm_nl_ctl del 100
 netlink error -22 (Invalid argument)
 ./pm_nl_ctl: bailing out due to netlink error[s]

Look at this test, nl error msg "address not found" in
mptcp_pm_nl_del_addr_doit() can be displayed in 'ip mptcp', but not in
'pm_nl_ctl'. I'll try to fix it.

> userspace app dev)? Or does it need to be modified to display the
> missing argument set by GENL_REQ_ATTR_CHECK()?

I think no need to modify this, since after GENL_REQ_ATTR_CHECK(), we
will also call NL_SET_ERR_MSG_ATTR/GENL_SET_ERR_MSG to set nl error msg
in the error paths.

Thanks,
-Geliang

> 
> Cheers,
> Matt


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH mptcp-next v3] mptcp: use GENL_REQ_ATTR_CHECK for token
  2024-12-20  9:50   ` Geliang Tang
@ 2024-12-21 10:39     ` Matthieu Baerts
  0 siblings, 0 replies; 5+ messages in thread
From: Matthieu Baerts @ 2024-12-21 10:39 UTC (permalink / raw)
  To: Geliang Tang, mptcp; +Cc: Geliang Tang

Hi Geliang,

On 20/12/2024 10:50, Geliang Tang wrote:
> Hi Matt,
> 
> On Mon, 2024-12-16 at 12:24 +0100, Matthieu Baerts wrote:
>> Hi Geliang,
>>
>> On 16/12/2024 09:31, Geliang Tang wrote:
>>> From: Geliang Tang <tanggeliang@kylinos.cn>
>>>
>>> A more general way to check if MPTCP_PM_ATTR_TOKEN exists in 'info'
>>> is to use GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_TOKEN) instead of
>>> directly reading info->attrs[MPTCP_PM_ATTR_TOKEN] and then checking
>>> if it's NULL.
>>>
>>> So this patch uses GENL_REQ_ATTR_CHECK() for 'token' in 'info' in
>>> mptcp_userspace_pm_get_sock().
>>>
>>> 'Suggested-by: Jakub Kicinski <kuba@kernel.org>'
>>> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
>>> ---
>>> v3:
>>>  - use GENL_REQ_ATTR_CHECK in mptcp_userspace_pm_get_sock only
>>>  - drop GENL_SET_ERR_MSG as Matt suggested (thanks)
>>
>> Thank you for the v3. While at it, do you want to do a similar change
>> everywhere we do:
>>
>>   struct nlattr *X = info->attrs[MPTCP_PM_ATTR_Y]:
>>   if (!X) {
>>       GENL_SET_ERR_MSG(info, "missing ...");
>>       return Z;
>>   }
>>
>> e.g. in mptcp_pm_nl_announce_doit() (addr), mptcp_pm_nl_remove_doit()
>> (id), mptcp_pm_nl_subflow_create_doit() (raddr, laddr),
>> mptcp_pm_nl_subflow_destroy_doit() (raddr, laddr).
>> (and maybe mptcp_pm_parse_pm_addr_attr(), but it needs more changes
>> around to pass the attribute ID, probably best not to change that)
> 
> Thanks for this suggestion, I updated this in v4.

Thank you!

>> Also, do you know if 'pm_nl_ctl' will continue to indicate a helpful
>> message if such attribute is missing (that's a message more for
> 
> 'pm_nl_ctl' can't display nl error msg, this is a bug in nl_error():
> 
>  $ sudo ip mptcp endpoint del id 100
>  Error: address not found.
>  $ sudo ./pm_nl_ctl del 100
>  netlink error -22 (Invalid argument)
>  ./pm_nl_ctl: bailing out due to netlink error[s]
> 
> Look at this test, nl error msg "address not found" in
> mptcp_pm_nl_del_addr_doit() can be displayed in 'ip mptcp', but not in
> 'pm_nl_ctl'. I'll try to fix it.

It might help developers if pm_nl_ctl could also print errors generated
by GENL_REQ_ATTR_CHECK(), not only the ones generated with
GENL_SET_ERR_MSG().

>> userspace app dev)? Or does it need to be modified to display the
>> missing argument set by GENL_REQ_ATTR_CHECK()?
> 
> I think no need to modify this, since after GENL_REQ_ATTR_CHECK(), we
> will also call NL_SET_ERR_MSG_ATTR/GENL_SET_ERR_MSG to set nl error msg
> in the error paths.

If GENL_REQ_ATTR_CHECK() is used, it should no longer needed to use
NL_SET_ERR_MSG_ATTR/GENL_SET_ERR_MSG. I guess the userspace should be
able to find the arguments that are missing, no?

This can be done in another series of course.

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-12-21 10:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-16  8:31 [PATCH mptcp-next v3] mptcp: use GENL_REQ_ATTR_CHECK for token Geliang Tang
2024-12-16  9:29 ` MPTCP CI
2024-12-16 11:24 ` Matthieu Baerts
2024-12-20  9:50   ` Geliang Tang
2024-12-21 10:39     ` Matthieu Baerts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox