Skip to content

Conversation

@jukkar
Copy link
Member

@jukkar jukkar commented Nov 10, 2025

Rename network symbols i.e., add net_, NET_ or ZSOCK_ prefixes to those network symbols that can be found in POSIX or libc. This way we can avoid circular dependency issues.

Fixes #97050

@jukkar jukkar added the In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on label Nov 10, 2025
@jukkar
Copy link
Member Author

jukkar commented Nov 10, 2025

Initial work on namespacing the network APIs, this is WIP. Creating a draft in order to get some faster CI runs than what I can do locally.
fyi: @aescolar / @rlubos / @cfriedt / @carlescufi

@jukkar
Copy link
Member Author

jukkar commented Nov 10, 2025

Instructions for the reviewers. The main changes are in

  • include/zephyr/net/net_ip.h
  • include/zephyr/net/socket.h

The majority of the other changes are just to there to support the API naming changes.
The compatibility commit introduces a header file include/zephyr/net/net_compat.h that reverts the API changes so that we can do things in stages. This is controlled by a Kconfig option CONFIG_NET_NAMESPACE_COMPAT_MODE.

Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work so far. I just left a couple of comments for non-sockaddr things. Although I'm sure you are already aware and planning for those too.

static int send_temperature(struct coap_resource *resource,
const struct sockaddr *addr, socklen_t addr_len,
const struct net_sockaddr *addr, socklen_t addr_len,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

socklen_t should probably also be changed to uint32_t within the network subsystem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not go that route, but just changed socklen_t to net_socklen_t. Not sure if we should do that uint32_t change as now it is easy to map the socklen variable between the network and Posix apis (because the naming is similar).
What other reviewers think about this, I am open to replace net_socklen_t if there are good arguments for it.

addr.hci_channel = HCI_CHANNEL_USER;

if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
if (bind(fd, (struct net_sockaddr *)&addr, sizeof(addr)) < 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calls to bind() should also be replaced with zsock_bind() (unless being used via POSIX through a sample).

Similarly, connect(), close(), should be switched to zsock_connect(), zsock_close(), etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That file is for native_sim driver so I think I need to remove all the changes I did there.

}

if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
if (connect(fd, (struct net_sockaddr *)&addr, sizeof(addr)) < 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use zsock_connect()

{
struct net_eth_hdr *eth_hdr = (struct net_eth_hdr *)rx_buf;

switch (ntohs(eth_hdr->type)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should have a non-POSIX version of ntohs() and others too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will change these. I started to change the source all over the code base but there was just so much of it, so I decided to concentrate my efforts first to subsys/net, tests/net and include/zephyr/net directories. Some of the drivers contain already changes and I will continue this work.

Copy link
Member

@aescolar aescolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jukkar , overall it is looking good to me :)

@jukkar jukkar force-pushed the devel/97050/net-namespacing branch 9 times, most recently from 4a5aa36 to 1f46999 Compare November 13, 2025 11:51
@jukkar jukkar removed the In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on label Nov 13, 2025
@jukkar jukkar marked this pull request as ready for review November 13, 2025 12:32
Rename network symbols in modem drivers to use the renamed
network APIs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Rename network symbols in usb drivers to use the renamed network APIs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Rename network symbols in wifi drivers to use the renamed
network APIs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Removing Posix header inclusion as networking APIs and code should
be self contained now.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Do not include Posix header files inside network stack as we should
not depend on Posix symbols in net stack.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Use namespaced network symbols in order to avoid circular dependency
between Posix and network subsystems.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
We need certain network related Posix header files so that the
network sample compiles ok. Previously the Posix symbols were
introduced by network stack automatically even if user had not
enabled Posix, but that is no longer the case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
We need certain network related Posix header files so that the
network tests using Posix symbols compiles ok.
Previously the Posix symbols were introduced by network stack
automatically, but that is no longer the case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Mark the err variable as possibly unsed depending on the enabled
config options.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Compliance checker complains

   TYPO_SPELLING: 'in in' may be misspelled - perhaps 'is in'?

for code like this

   static struct net_sockaddr_in in_addr_my = {

so change the variable to ipv4_addr_my. Similar change is
done for IPv6 variables for consistency.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The network backend needs nothing from Posix so remove the
dependency.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Make sure we test coap client/server, MQTT SN, telnet and
logging network backend when testing all network options.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
@jukkar jukkar force-pushed the devel/97050/net-namespacing branch from cb7bee8 to eea9c41 Compare November 17, 2025 15:58
@jukkar
Copy link
Member Author

jukkar commented Nov 17, 2025

  • compliance check fix

@sonarqubecloud
Copy link

@jukkar
Copy link
Member Author

jukkar commented Nov 17, 2025

If CI fails or something requires me to send a new version, I will also add a commit adding a note to migration guide. Otherwise I will send the migration guide changes in a separate PR immediately after this is merged.

@jukkar jukkar changed the title net: Namespace network symbols to avoid conflicts with Posix/libc net: Namespace network symbols to avoid conflicts with POSIX or libc Nov 17, 2025
@nashif nashif merged commit 1380739 into zephyrproject-rtos:main Nov 17, 2025
33 checks passed
@jukkar jukkar deleted the devel/97050/net-namespacing branch November 18, 2025 07:28
Cristib05 added a commit to nxp-upstream/zephyr that referenced this pull request Nov 18, 2025
This commit aims to refactor the application code after network
namespace symbols have been changed zephyrproject-rtos#99169

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
Cristib05 added a commit to nxp-upstream/zephyr that referenced this pull request Nov 18, 2025
In this commit, `net_socket_service_register` is called when a platform
module that has sockets is deinitialized, and it's socket/sockets are
closed.
This commit also handles a case when a module tries to join a multicast
group and a subscription, from another module, is already present.

Also, covered network namespace changes done in zephyrproject-rtos#99169

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
Cristib05 added a commit to nxp-upstream/zephyr that referenced this pull request Nov 20, 2025
In this commit, `net_socket_service_register` is called when a platform
module that has sockets is deinitialized, and it's socket/sockets are
closed.
This commit also handles a case when a module tries to join a multicast
group and a subscription, from another module, is already present.

Also, covered network namespace changes done in zephyrproject-rtos#99169

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
nashif pushed a commit that referenced this pull request Nov 21, 2025
In this commit, `net_socket_service_register` is called when a platform
module that has sockets is deinitialized, and it's socket/sockets are
closed.
This commit also handles a case when a module tries to join a multicast
group and a subscription, from another module, is already present.

Also, covered network namespace changes done in #99169

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Networking subsystem should not (re)define C library types, macros or functions

6 participants