Skip to content

Commit e3a7bb3

Browse files
JordanYatesjhedberg
authored andcommitted
net: conn_mgr_connectivity: idle timeout parameter
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]>
1 parent 65b616f commit e3a7bb3

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

include/zephyr/net/conn_mgr_connectivity.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern "C" {
4444
enum {
4545
NET_EVENT_CONN_CMD_IF_TIMEOUT_VAL,
4646
NET_EVENT_CONN_CMD_IF_FATAL_ERROR_VAL,
47+
NET_EVENT_CONN_CMD_IF_IDLE_TIMEOUT_VAL,
4748

4849
NET_EVENT_CONN_CMD_MAX
4950
};
@@ -54,6 +55,7 @@ BUILD_ASSERT(NET_EVENT_CONN_CMD_MAX <= NET_MGMT_MAX_COMMANDS,
5455
enum net_event_conn_cmd {
5556
NET_MGMT_CMD(NET_EVENT_CONN_CMD_IF_TIMEOUT),
5657
NET_MGMT_CMD(NET_EVENT_CONN_CMD_IF_FATAL_ERROR),
58+
NET_MGMT_CMD(NET_EVENT_CONN_CMD_IF_IDLE_TIMEOUT),
5759
};
5860

5961
/** @endcond */
@@ -70,6 +72,12 @@ enum net_event_conn_cmd {
7072
#define NET_EVENT_CONN_IF_FATAL_ERROR \
7173
(NET_MGMT_CONN_IF_EVENT | NET_EVENT_CONN_CMD_IF_FATAL_ERROR)
7274

75+
/**
76+
* @brief net_mgmt event raised when an interface times out due to inactivity
77+
*/
78+
#define NET_EVENT_CONN_IF_IDLE_TIMEOUT \
79+
(NET_MGMT_CONN_IF_EVENT | NET_EVENT_CONN_CMD_IF_IDLE_TIMEOUT)
80+
7381

7482
/**
7583
* @brief Per-iface connectivity flags
@@ -264,6 +272,32 @@ int conn_mgr_if_get_timeout(struct net_if *iface);
264272
*/
265273
int conn_mgr_if_set_timeout(struct net_if *iface, int timeout);
266274

275+
/**
276+
* @brief Get the idle timeout for an iface
277+
*
278+
* If the provided iface is bound to a connectivity implementation, retrieves the idle timeout
279+
* setting in seconds for it.
280+
*
281+
* @param iface - Pointer to the iface to check.
282+
* @return int - The connectivity timeout value (in seconds) if it could be retrieved, otherwise
283+
* CONN_MGR_IF_NO_TIMEOUT.
284+
*/
285+
int conn_mgr_if_get_idle_timeout(struct net_if *iface);
286+
287+
/**
288+
* @brief Set the idle timeout for an iface.
289+
*
290+
* If the provided iface is bound to a connectivity implementation, sets the idle timeout setting
291+
* in seconds for it.
292+
*
293+
* @param iface - Pointer to the network interface to modify.
294+
* @param timeout - The timeout value to set (in seconds).
295+
* Pass @ref CONN_MGR_IF_NO_TIMEOUT to disable the timeout.
296+
* @retval 0 on success.
297+
* @retval -ENOTSUP if the provided iface is not bound to a connectivity implementation.
298+
*/
299+
int conn_mgr_if_set_idle_timeout(struct net_if *iface, int timeout);
300+
267301
/**
268302
* @}
269303
*/

include/zephyr/net/conn_mgr_connectivity_impl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ struct conn_mgr_conn_binding {
193193
*/
194194
int timeout;
195195

196+
/**
197+
* Usage timeout (seconds)
198+
*
199+
* Indicates to the connectivity implementation how long the interface can be idle
200+
* for before automatically taking the interface down.
201+
*
202+
* Set to @ref CONN_MGR_IF_NO_TIMEOUT to indicate that no idle timeout should be used.
203+
*/
204+
int idle_timeout;
205+
196206
/** @} */
197207

198208
/** @cond INTERNAL_HIDDEN */

subsys/net/conn_mgr/conn_mgr_connectivity.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int conn_mgr_if_get_timeout(struct net_if *iface)
197197
int value;
198198

199199
if (binding == NULL) {
200-
return false;
200+
return CONN_MGR_IF_NO_TIMEOUT;
201201
}
202202

203203
conn_mgr_binding_lock(binding);
@@ -226,6 +226,41 @@ int conn_mgr_if_set_timeout(struct net_if *iface, int timeout)
226226
return 0;
227227
}
228228

229+
int conn_mgr_if_get_idle_timeout(struct net_if *iface)
230+
{
231+
struct conn_mgr_conn_binding *binding = conn_mgr_if_get_binding(iface);
232+
int value;
233+
234+
if (binding == NULL) {
235+
return CONN_MGR_IF_NO_TIMEOUT;
236+
}
237+
238+
conn_mgr_binding_lock(binding);
239+
240+
value = binding->idle_timeout;
241+
242+
conn_mgr_binding_unlock(binding);
243+
244+
return value;
245+
}
246+
247+
int conn_mgr_if_set_idle_timeout(struct net_if *iface, int timeout)
248+
{
249+
struct conn_mgr_conn_binding *binding = conn_mgr_if_get_binding(iface);
250+
251+
if (binding == NULL) {
252+
return -ENOTSUP;
253+
}
254+
255+
conn_mgr_binding_lock(binding);
256+
257+
binding->idle_timeout = timeout;
258+
259+
conn_mgr_binding_unlock(binding);
260+
261+
return 0;
262+
}
263+
229264
/* Automated behavior handling */
230265

231266
/**
@@ -375,6 +410,7 @@ void conn_mgr_conn_init(void)
375410
/* Set initial default values for binding state */
376411

377412
binding->timeout = CONN_MGR_IF_NO_TIMEOUT;
413+
binding->idle_timeout = CONN_MGR_IF_NO_TIMEOUT;
378414

379415
/* Call binding initializer */
380416

0 commit comments

Comments
 (0)