Skip to content

Commit 5c0521c

Browse files
JordanYatesnashif
authored andcommitted
conn_mgr: make internal state static
Make the interface interface state array static, ensuring that the array is zeroed at boot. This enables interfaces which initialise earlier than the CONN_MGR module to set flags in their init functions. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent ab9c531 commit 5c0521c

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

subsys/net/conn_mgr/conn_mgr_monitor.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static struct k_thread conn_mgr_mon_thread;
3232
* conn_mgr_mon_get_if_by_index and conn_mgr_get_index_for_if are used to go back and forth between
3333
* iface_states indices and Zephyr iface pointers.
3434
*/
35-
uint16_t iface_states[CONN_MGR_IFACE_MAX];
35+
static uint16_t iface_states[CONN_MGR_IFACE_MAX];
3636

3737
/* Tracks the most recent total quantity of L4-ready ifaces (any, IPv4, IPv6) */
3838
static uint16_t last_ready_count;
@@ -50,6 +50,11 @@ K_SEM_DEFINE(conn_mgr_mon_updated, 1, 1);
5050
/* Used to protect conn_mgr_monitor state */
5151
K_MUTEX_DEFINE(conn_mgr_mon_lock);
5252

53+
uint16_t *conn_mgr_if_state_internal(void)
54+
{
55+
return iface_states;
56+
}
57+
5358
/**
5459
* @brief Retrieves pointer to an iface by the index that corresponds to it in iface_states
5560
*
@@ -400,12 +405,6 @@ void conn_mgr_watch_l2(const struct net_l2 *l2)
400405

401406
static int conn_mgr_mon_init(void)
402407
{
403-
int i;
404-
405-
for (i = 0; i < ARRAY_SIZE(iface_states); i++) {
406-
iface_states[i] = 0;
407-
}
408-
409408
k_thread_create(&conn_mgr_mon_thread, conn_mgr_mon_stack,
410409
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE,
411410
conn_mgr_mon_thread_fn,

subsys/net/conn_mgr/conn_mgr_private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ void conn_mgr_init_events_handler(void);
6363
/* Cause conn_mgr_connectivity to Initialize all connectivity implementation bindings */
6464
void conn_mgr_conn_init(void);
6565

66+
/* Retrieve the raw pointer to the state array of size CONN_MGR_IFACE_MAX */
67+
uint16_t *conn_mgr_if_state_internal(void);
68+
6669
/* Internal helper function to allow the shell net cm command to safely read conn_mgr state. */
6770
uint16_t conn_mgr_if_state(struct net_if *iface);
6871

subsys/net/conn_mgr/events_handler.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ LOG_MODULE_DECLARE(conn_mgr, CONFIG_NET_CONNECTION_MANAGER_LOG_LEVEL);
1212
#include <zephyr/net/net_mgmt.h>
1313
#include "conn_mgr_private.h"
1414

15-
extern uint16_t iface_states[CONN_MGR_IFACE_MAX];
16-
1715
static struct net_mgmt_event_callback iface_events_cb;
1816
static struct net_mgmt_event_callback ipv6_events_cb;
1917
static struct net_mgmt_event_callback ipv4_events_cb;
@@ -22,6 +20,7 @@ static void conn_mgr_iface_events_handler(struct net_mgmt_event_callback *cb,
2220
uint64_t mgmt_event,
2321
struct net_if *iface)
2422
{
23+
uint16_t *iface_states = conn_mgr_if_state_internal();
2524
int idx;
2625

2726
NET_DBG("%s event 0x%" PRIx64 " received on iface %d (%p)", "Iface", mgmt_event,
@@ -58,6 +57,7 @@ static void conn_mgr_ipv6_events_handler(struct net_mgmt_event_callback *cb,
5857
uint64_t mgmt_event,
5958
struct net_if *iface)
6059
{
60+
uint16_t *iface_states = conn_mgr_if_state_internal();
6161
int idx;
6262

6363
NET_DBG("%s event 0x%" PRIx64 " received on iface %d (%p)", "IPv6", mgmt_event,
@@ -115,6 +115,7 @@ static void conn_mgr_ipv4_events_handler(struct net_mgmt_event_callback *cb,
115115
uint64_t mgmt_event,
116116
struct net_if *iface)
117117
{
118+
uint16_t *iface_states = conn_mgr_if_state_internal();
118119
int idx;
119120

120121
NET_DBG("%s event 0x%" PRIx64 " received on iface %d (%p)", "IPv4", mgmt_event,

0 commit comments

Comments
 (0)