Skip to content

Inconsistent net_context APIs #90639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ag00se opened this issue May 27, 2025 · 4 comments · Fixed by #90645
Closed

Inconsistent net_context APIs #90639

ag00se opened this issue May 27, 2025 · 4 comments · Fixed by #90645
Assignees
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@ag00se
Copy link

ag00se commented May 27, 2025

Zephyr version: v4.1.0-4041-g6ee55e42117a

I found the following behaviour during my implementation of a TCP server using net_context_* APIs:

After socket creation, bind and listen I called net_context_accept providing this as user_data parameter:
net_context_accept(_tcpContext, Communicator::tcpAcceptCallback, K_NO_WAIT, this)

The documentation of this function in net_context.h states:
"param user_data Caller-supplied user data."

I expected that this parameter is provided as argument to the registered callback.
Because of problems obtaining the correct data in the parameter I found during debbuging that the callback is executetd
like this (net/ip/tcp.c:3016):

accept_cb(conn->context, &conn->context->remote,
      net_context_get_family(context) == AF_INET6 ?
      sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in),
      0, context);

Instead of the registered user_data, the context itself is provided as argument.
I can obtain the correct user_data from the context (context->user_data) but the naming of the parameter and
the behaviour of the stack is not as expected. Furthermore, I don't know if this implementation is a subject to change?

Is this intentional? It seems that either the parameter name user_data is wrong or the tcp subsystem provides the wrong argument.
Other callbacks provide the correct user_data (e.g. `net/ip/tcp.c:35551):

conn->connect_cb(conn->context, 0, conn->context->user_data);

I also posted this in the community discord, but maybe this is the correct place?
Thanks for any feedback and regards

@ag00se ag00se added the bug The issue is a bug, or the PR is fixing a bug label May 27, 2025
Copy link

Hi @ag00se! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

@rlubos
Copy link
Collaborator

rlubos commented May 27, 2025

This looks wrong, it works fine with the socket implementation, as the socket layer provides the parent context as user_data for net_context_accept(), but it shouldn't be hardcoded like this in the TCP implementation. I'll send a fix.

@rlubos
Copy link
Collaborator

rlubos commented May 27, 2025

It was a pretty straightforward fix: #90645, hopefully CI doesn't blow up, but from testing locally it shouldn't be the case.

@ag00se
Copy link
Author

ag00se commented May 27, 2025

Thanks for the fast response and bugfix.

@dkalowsk dkalowsk added the priority: low Low impact/importance bug label May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants