net: dhcpv4: set log backend net ip via option
Adds the option to set the log_backend_net ip via dhcpv4 option 7. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This commit is contained in:
parent
2b23d1f3f1
commit
0d776d39bb
@ -49,6 +49,13 @@ config LOG_BACKEND_NET_AUTOSTART
|
||||
started by the application later on. Otherwise the logging
|
||||
thread might block.
|
||||
|
||||
config LOG_BACKEND_NET_USE_DHCPV4_OPTION
|
||||
bool "Use DHCPv4 Log Server Option to configure syslog server"
|
||||
depends on NET_DHCPV4
|
||||
help
|
||||
When enabled the syslog server IP address is read from the DHCPv4
|
||||
Log Server Option (7).
|
||||
|
||||
backend = NET
|
||||
backend-str = net
|
||||
source "subsys/logging/Kconfig.template.log_format_config"
|
||||
|
||||
@ -28,6 +28,10 @@ LOG_MODULE_REGISTER(net_dhcpv4, CONFIG_NET_DHCPV4_LOG_LEVEL);
|
||||
#include <zephyr/net/dhcpv4.h>
|
||||
#include <zephyr/net/dns_resolve.h>
|
||||
|
||||
#include <zephyr/logging/log_backend.h>
|
||||
#include <zephyr/logging/log_backend_net.h>
|
||||
#include <zephyr/logging/log_ctrl.h>
|
||||
|
||||
#include "dhcpv4_internal.h"
|
||||
#include "ipv4.h"
|
||||
#include "net_stats.h"
|
||||
@ -56,6 +60,9 @@ static sys_slist_t option_vendor_callbacks = SYS_SLIST_STATIC_INIT(&option_vendo
|
||||
static const uint8_t min_req_options[] = {
|
||||
DHCPV4_OPTIONS_SUBNET_MASK,
|
||||
DHCPV4_OPTIONS_ROUTER,
|
||||
#ifdef CONFIG_LOG_BACKEND_NET_USE_DHCPV4_OPTION
|
||||
DHCPV4_OPTIONS_LOG_SERVER,
|
||||
#endif
|
||||
#ifdef CONFIG_NET_DHCPV4_OPTION_NTP_SERVER
|
||||
DHCPV4_OPTIONS_NTP_SERVER,
|
||||
#endif
|
||||
@ -969,6 +976,39 @@ static bool dhcpv4_parse_options(struct net_pkt *pkt,
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if defined(CONFIG_LOG_BACKEND_NET_USE_DHCPV4_OPTION)
|
||||
case DHCPV4_OPTIONS_LOG_SERVER: {
|
||||
struct sockaddr_in log_server = { 0 };
|
||||
|
||||
/* Log server option may present 1 or more
|
||||
* addresses. Each 4 bytes in length. Log
|
||||
* servers should be listed in order
|
||||
* of preference. Hence we choose the first
|
||||
* and skip the rest.
|
||||
*/
|
||||
if (length % 4 != 0U) {
|
||||
NET_ERR("options_log_server, bad length");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (net_pkt_read(pkt, log_server.sin_addr.s4_addr, 4) < 0 ||
|
||||
net_pkt_skip(pkt, length - 4U) < 0) {
|
||||
NET_ERR("options_log_server, short packet");
|
||||
return false;
|
||||
}
|
||||
|
||||
log_server.sin_family = AF_INET;
|
||||
log_backend_net_set_ip((struct sockaddr *)&log_server);
|
||||
|
||||
#ifdef CONFIG_LOG_BACKEND_NET_AUTOSTART
|
||||
log_backend_net_start();
|
||||
#endif
|
||||
|
||||
NET_DBG("options_log_server: %s", net_sprint_ipv4_addr(&log_server));
|
||||
|
||||
break;
|
||||
}
|
||||
#endif /* CONFIG_LOG_BACKEND_NET_USE_DHCPV4_OPTION */
|
||||
#if defined(CONFIG_NET_DHCPV4_OPTION_NTP_SERVER)
|
||||
case DHCPV4_OPTIONS_NTP_SERVER: {
|
||||
|
||||
|
||||
@ -54,6 +54,7 @@ struct dhcp_msg {
|
||||
#define DHCPV4_OPTIONS_SUBNET_MASK 1
|
||||
#define DHCPV4_OPTIONS_ROUTER 3
|
||||
#define DHCPV4_OPTIONS_DNS_SERVER 6
|
||||
#define DHCPV4_OPTIONS_LOG_SERVER 7
|
||||
#define DHCPV4_OPTIONS_HOST_NAME 12
|
||||
#define DHCPV4_OPTIONS_NTP_SERVER 42
|
||||
#define DHCPV4_OPTIONS_VENDOR_SPECIFIC 43
|
||||
|
||||
Loading…
Reference in New Issue
Block a user