Skip to content

Conversation

JordanYates
Copy link
Contributor

Add the option for users to specify idle timeouts on an interface, which results in a disconnect event if N seconds pass without any activity on the interface.

Proper operation of this feature requires two changes to existing bindings:

  • Implement the used callback to receive usage notifications (to refresh the idle timeout)
  • Add conn_mgr_if_used calls to the underlying networking driver

Existing bindings do not break with this addition, but the idle timeout won't work without updates.
Adding the new conn_mgr_if_used function call appeared to be the best way to notify the connection manager of interface activity, rather than trying to patch into the net_stats module.

The second requirement has been done for the native socket abstraction and NET_NATIVE (which include nRF7x).
The implementation has been tested on an OOT WiFi connectivity manager implementation.
The following are example logs with a 10 second idle timeout, with no activity occuring and persistence enabled.

[00:16:12.793,544] <inf> wifi_mgmt: Connection successful
[00:16:12.806,332] <wrn> net_dhcpv4: DHCP server provided more DNS servers than can be saved
[00:16:12.826,107] <wrn> net_dhcpv4: DHCP server provided more DNS servers than can be saved
[00:16:12.826,149] <inf> net_dhcpv4: Received: 192.168.20.76
[00:16:12.826,282] <inf> epacket_udp: Network connected
[00:16:12.826,519] <inf> epacket_udp: Waiting for UDP packets on port 6200
[00:16:22.837,169] <inf> wifi_mgmt: Connection lost (0), retrying
[00:16:22.848,053] <inf> epacket_udp: Network disconnected
[00:16:22.848,083] <err> epacket_udp: Socket closed
[00:16:23.838,008] <inf> wifi_mgmt: Initiating connection to '********'

Implements #90198

@JordanYates JordanYates changed the title net: conn_mgr_connectivity: idle/inactivty timeout net: conn_mgr_connectivity: idle/inactivity timeout Jun 17, 2025
@JordanYates JordanYates force-pushed the 250617_conn_mgr_idle branch 2 times, most recently from 997159c to 476b8f7 Compare June 17, 2025 03:27
Copy link

@JordanYates JordanYates linked an issue Jun 17, 2025 that may be closed by this pull request
JordanYates added a commit to Embeint/infuse-sdk that referenced this pull request Jun 17, 2025
Update zephyr fork with Connectivity Manager idle timeout support.
Upstream PR:
  zephyrproject-rtos/zephyr#91733

Signed-off-by: Jordan Yates <[email protected]>
JordanYates added a commit to Embeint/infuse-sdk that referenced this pull request Jun 17, 2025
Update zephyr fork with Connectivity Manager idle timeout support.
Upstream PR:
  zephyrproject-rtos/zephyr#91733

Signed-off-by: Jordan Yates <[email protected]>
Copy link
Contributor

@rlubos rlubos left a comment

Choose a reason for hiding this comment

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

Everything is super neat, although I have one concern about the inactivity timer placement.

}
}

static void nsos_idle_fn(struct k_work *work)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, so from the issue description and the new documentation I had an impression that this idle timeout handling would be a generic implementation in the conn_mgr, and not handled individually by each binding implementation?

So that when the timer for particular binding expires, the conn_mgr would call conn_mgr_if_disconnect() on the interface. This way the feature would practically become avaialble for each binding implementation for free? That would also put the need of having used() API in struct conn_mgr_conn_api at question.

Or do you forsee there may be some differences between implementations and it is actually beneficial to have the incactivity timer to be implemented by each binding individually?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So that was the original plan, but it ran up against some pretty immediate roadblocks due to the design of the Connectivity Manager. Because it delegates all management of connections to the bindings, it has no knowledge of when a connection actually succeeds or disconnects. Since those are the two events needed to implement the idle timeout (to start and terminate it), it poses a problem.

So it's either add new callbacks from bindings back to the connectivity manager so that it can handle the idle timeouts, or just handle the timeout in the binding directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because it delegates all management of connections to the bindings, it has no knowledge of when a connection actually succeeds or disconnects. Since those are the two events needed to implement the idle timeout (to start and terminate it), it poses a problem.

What about generic NET_EVENT_IF_UP/NET_EVENT_IF_DOWN events? The interface should only go operational UP after it's connected, and when it loses connectivity it goes down. Couldn't we use those for a common implementation of the idle timeout feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

Add a helper macro to declare a network interface, enabling the use of
`NET_IF_GET` in the driver before the call to `NET_DEVICE_OFFLOAD_INIT`
or `NET_DEVICE_INIT`.

Signed-off-by: Jordan Yates <[email protected]>
@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label Oct 15, 2025
@zephyrbot zephyrbot requested a review from nashif October 15, 2025 04:19
@JordanYates
Copy link
Contributor Author

Updated implementation from @rlubos suggestions, moving the core functionality inside the connection manager. Connectivity bindings no longer need any updates, interfaces just need to call conn_mgr_iface_used whenever an operation occurs.

@JordanYates JordanYates force-pushed the 250617_conn_mgr_idle branch 3 times, most recently from 6f18ea4 to 3820224 Compare October 15, 2025 05:56
Copy link
Member

@jukkar jukkar left a comment

Choose a reason for hiding this comment

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

LGTM, couple of minor nits about pointer checks.

Replace all `!binding` checks with `binding == NULL` for MISRA
compliance.

Signed-off-by: Jordan Yates <[email protected]>
Add an interface idle timeout parameter to the connectivity
binding structure. This will be used to track idle timeouts for
interfaces.

Signed-off-by: Jordan Yates <[email protected]>
@JordanYates
Copy link
Contributor Author

LGTM, couple of minor nits about pointer checks.

Added an initial commit to switch all the existing usage of !binding in the file, then changed my commit

Copy link
Contributor

@pdgendt pdgendt left a comment

Choose a reason for hiding this comment

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

Might need some release note bits. Looks good!

Add tests for the idle timeout parameter.

Signed-off-by: Jordan Yates <[email protected]>
Implement idle timeouts, primarily in the common connectivity library,
with individual interfaces notifying the library when the interface has
been used.

Signed-off-by: Jordan Yates <[email protected]>
Add interface usage notifications to the `NET_NATIVE` code paths.

Signed-off-by: Jordan Yates <[email protected]>
Add interface usage notifications to the native socket offload code
paths.

Signed-off-by: Jordan Yates <[email protected]>
Test the behaviour of the idle timeout on native sockets. Only tests
a subset of the "active" paths to not require any external services.

Signed-off-by: Jordan Yates <[email protected]>
Add documentation for the new idle timeout feature of the connection
manager.

Signed-off-by: Jordan Yates <[email protected]>
Copy link

Copy link
Contributor

@rlubos rlubos left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@jhedberg jhedberg merged commit 7c82c06 into zephyrproject-rtos:main Oct 15, 2025
27 checks passed
@JordanYates JordanYates deleted the 250617_conn_mgr_idle branch October 15, 2025 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Networking area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connection Manager: Interface keep alive

6 participants