Skip to content

Commit 265eb71

Browse files
maass-hamburgkartben
authored andcommitted
logging: backend: net: use connection mgr
Use connection manager to deactivate and activate net log backend. This removes the warnings about dropped packages completly. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
1 parent e704705 commit 265eb71

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

subsys/logging/backends/Kconfig.net

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ config LOG_BACKEND_NET_AUTOSTART
119119
started by the application later on. Otherwise the logging
120120
thread might block.
121121

122+
config LOG_BACKEND_NET_USE_CONNECTION_MANAGER
123+
bool "Use connection manager for start and stop networking backend"
124+
depends on NET_CONNECTION_MANAGER
125+
depends on LOG_BACKEND_NET_AUTOSTART
126+
default y
127+
help
128+
When enabled the connection manager will be used to start and stop
129+
the networking backend. This is useful when the application
130+
needs to wait for the network connection to be established before
131+
starting the logging backend.
132+
122133
config LOG_BACKEND_NET_USE_DHCPV4_OPTION
123134
bool "Use DHCPv4 Log Server Option to configure syslog server"
124135
depends on NET_DHCPV4

subsys/logging/backends/log_backend_net.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LOG_MODULE_REGISTER(log_backend_net, CONFIG_LOG_DEFAULT_LEVEL);
1414
#include <zephyr/logging/log_backend_net.h>
1515
#include <zephyr/net/hostname.h>
1616
#include <zephyr/net/net_if.h>
17+
#include <zephyr/net/net_mgmt.h>
1718
#include <zephyr/net/socket.h>
1819

1920
/* Set this to 1 if you want to see what is being sent to server */
@@ -364,3 +365,24 @@ const struct log_backend *log_backend_net_get(void)
364365
{
365366
return &log_backend_net;
366367
}
368+
369+
#if defined(CONFIG_LOG_BACKEND_NET_USE_CONNECTION_MANAGER)
370+
static void l4_event_handler(uint32_t mgmt_event, struct net_if *iface, void *info,
371+
size_t info_length, void *user_data)
372+
{
373+
ARG_UNUSED(iface);
374+
ARG_UNUSED(info);
375+
ARG_UNUSED(info_length);
376+
ARG_UNUSED(user_data);
377+
378+
if (mgmt_event == NET_EVENT_L4_CONNECTED) {
379+
log_backend_net_start();
380+
} else if (mgmt_event == NET_EVENT_L4_DISCONNECTED) {
381+
log_backend_deactivate(log_backend_net_get());
382+
}
383+
}
384+
385+
NET_MGMT_REGISTER_EVENT_HANDLER(log_backend_net_event_handler,
386+
NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED,
387+
&l4_event_handler, NULL);
388+
#endif /* CONFIG_LOG_BACKEND_NET_USE_CONNECTION_MANAGER */

subsys/net/lib/config/init.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,8 @@ int net_config_init_app(const struct device *dev, const char *app_info)
553553
/* This is activated late as it requires the network stack to be up
554554
* and running before syslog messages can be sent to network.
555555
*/
556-
if (IS_ENABLED(CONFIG_LOG_BACKEND_NET_AUTOSTART)) {
556+
if (IS_ENABLED(CONFIG_LOG_BACKEND_NET_AUTOSTART) &&
557+
!IS_ENABLED(CONFIG_LOG_BACKEND_NET_USE_CONNECTION_MANAGER)) {
557558
log_backend_net_start();
558559
}
559560

subsys/net/lib/dhcpv4/dhcpv4.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,8 @@ static bool dhcpv4_parse_options(struct net_pkt *pkt,
12061206
log_backend_net_set_ip((struct sockaddr *)&log_server);
12071207

12081208
if (IS_ENABLED(CONFIG_LOG_BACKEND_NET_AUTOSTART) &&
1209-
!IS_ENABLED(CONFIG_NET_CONFIG_SETTINGS)) {
1209+
!IS_ENABLED(CONFIG_NET_CONFIG_SETTINGS) &&
1210+
!IS_ENABLED(CONFIG_LOG_BACKEND_NET_USE_CONNECTION_MANAGER)) {
12101211
log_backend_net_start();
12111212
}
12121213

0 commit comments

Comments
 (0)