net: conn_mgr: relocate if_get_binding

Relocate conn_mgr_if_get_binding to conn_mgr_private.h so that it
can be used by test suites.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
This commit is contained in:
Georges Oates_Larsen 2023-04-14 16:20:43 -07:00 committed by Carles Cufí
parent 716c19f7ef
commit 41d6a9bcec
3 changed files with 37 additions and 39 deletions

View file

@ -9,28 +9,7 @@ LOG_MODULE_REGISTER(conn_mgr_conn, CONFIG_NET_CONNECTION_MANAGER_LOG_LEVEL);
#include <zephyr/net/net_if.h>
#include <zephyr/net/conn_mgr_connectivity.h>
/**
* @brief Retrieves the conn_mgr binding struct for a provided iface if it exists.
*
* Bindings for connectivity implementations with missing API structs are ignored.
*
* @param iface - bound network interface to obtain the binding struct for.
* @return struct conn_mgr_conn_binding* Pointer to the retrieved binding struct if it exists,
* NULL otherwise.
*/
static inline struct conn_mgr_conn_binding *conn_mgr_if_get_binding(struct net_if *iface)
{
STRUCT_SECTION_FOREACH(conn_mgr_conn_binding, binding) {
if (iface == binding->iface) {
if (binding->impl->api) {
return binding;
}
return NULL;
}
}
return NULL;
}
#include "conn_mgr_private.h"
int conn_mgr_if_connect(struct net_if *iface)
{

View file

@ -7,6 +7,8 @@
#ifndef __CONN_MGR_PRV_H__
#define __CONN_MGR_PRV_H__
#include <zephyr/net/conn_mgr_connectivity.h>
#if defined(CONFIG_NET_IPV6) && defined(CONFIG_NET_IPV4)
#define CONN_MGR_IFACE_MAX MAX(CONFIG_NET_IF_MAX_IPV6_COUNT, \
CONFIG_NET_IF_MAX_IPV4_COUNT)
@ -49,4 +51,26 @@ enum conn_mgr_state {
void conn_mgr_init_events_handler(void);
/**
* @brief Retrieves the conn_mgr binding struct for a provided iface if it exists.
*
* Bindings for connectivity implementations with missing API structs are ignored.
*
* @param iface - bound network interface to obtain the binding struct for.
* @return struct conn_mgr_conn_binding* Pointer to the retrieved binding struct if it exists,
* NULL otherwise.
*/
static inline struct conn_mgr_conn_binding *conn_mgr_if_get_binding(struct net_if *iface)
{
STRUCT_SECTION_FOREACH(conn_mgr_conn_binding, binding) {
if (iface == binding->iface) {
if (binding->impl->api) {
return binding;
}
return NULL;
}
}
return NULL;
}
#endif /* __CONN_MGR_PRV_H__ */

View file

@ -15,26 +15,10 @@
#include <zephyr/ztest.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/conn_mgr_connectivity.h>
#include "conn_mgr_private.h"
#include "test_conn_impl.h"
#include "test_ifaces.h"
/* This is a duplicate of conn_mgr_if_get_binding in net_if.c,
* which is currently not exposed.
*/
static inline struct conn_mgr_conn_binding *conn_mgr_if_get_binding(struct net_if *iface)
{
STRUCT_SECTION_FOREACH(conn_mgr_conn_binding, binding) {
if (iface == binding->iface) {
if (binding->impl->api) {
return binding;
}
return NULL;
}
}
return NULL;
}
static inline struct test_conn_data *conn_mgr_if_get_data(struct net_if *iface)
{
struct conn_mgr_conn_binding *binding = conn_mgr_if_get_binding(iface);
@ -408,6 +392,17 @@ ZTEST(conn_mgr_conn, test_connect_disconnect_double_instant)
zassert_equal(ifa1_data->call_cnt_a, 4, "ifa1->disconnect should have been called once.");
}
/**
* Verify that invalid bound ifaces are treated as though they are not bound at all.
*/
ZTEST(conn_mgr_conn, test_invalid_ignored)
{
zassert_is_null(conn_mgr_if_get_binding(ifnull));
zassert_is_null(conn_mgr_if_get_binding(ifnone));
zassert_false(conn_mgr_if_is_bound(ifnull));
zassert_false(conn_mgr_if_is_bound(ifnone));
}
/* Verify that connecting an iface that isn't up, missing an API,
* or isn't connectivity-bound raises an error.
*/