summaryrefslogtreecommitdiff
path: root/fw/app
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2025-04-15 18:33:31 +0200
committerxengineering <me@xengineering.eu>2025-04-15 18:33:31 +0200
commit409348732bb4cd6ec0c06c4b38f26f528313ffdf (patch)
treea0a728f2e77ba5721caada8bf2e055fdb55be4dd /fw/app
parent0bff2eea39c11b5ad2e762325abeb1457ae0fd7e (diff)
downloadiot-contact-409348732bb4cd6ec0c06c4b38f26f528313ffdf.tar
iot-contact-409348732bb4cd6ec0c06c4b38f26f528313ffdf.tar.zst
iot-contact-409348732bb4cd6ec0c06c4b38f26f528313ffdf.zip
fw: app: syslog: Put only IP into syslog/target/ip
The old format contained `[<ip>]:<port>`. Nevertheless the format should be as strict as possible. Thus only the IP is used in the setting.
Diffstat (limited to 'fw/app')
-rw-r--r--fw/app/src/syslog.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/fw/app/src/syslog.c b/fw/app/src/syslog.c
index 8fe2412..c3b5815 100644
--- a/fw/app/src/syslog.c
+++ b/fw/app/src/syslog.c
@@ -6,6 +6,7 @@
#include <errno.h>
#include <stdbool.h>
+#include <stdio.h>
#include <string.h>
#include <zephyr/init.h>
@@ -27,7 +28,8 @@ LOG_MODULE_REGISTER(syslog);
#define NETWORK_BUG_DELAY K_MSEC(4000)
#define L4_EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)
-#define IPV6_STRLEN_MAX 40 // including '\0'
+#define IPV6_STRLEN_MAX 39 // excluding '\0'
+#define SYSLOG_TARGET_PORT 514
struct net_mgmt_event_callback l4_cb;
static K_SEM_DEFINE(network_connected, 0, 1);
@@ -104,10 +106,10 @@ int syslog_handle_set(const char *name, size_t len, settings_read_cb read_cb,
memset(target_ip, '\0', sizeof(target_ip));
ssize_t ret = read_cb(cb_arg, target_ip, MIN(sizeof(target_ip) - 1, len));
if (ret < 0) {
- LOG_ERR("Failed to set target (%d)", ret);
+ LOG_ERR("Failed to set target IP (%d)", ret);
return (int)ret;
}
- LOG_INF("Set target to '%s'", target_ip);
+ LOG_INF("Set target IP to '%s'", target_ip);
return 0;
}
@@ -116,10 +118,20 @@ int syslog_handle_set(const char *name, size_t len, settings_read_cb read_cb,
int syslog_handle_commit(void)
{
- if (log_backend_net_set_addr(target_ip) == false) {
- LOG_ERR("Could not commit target to '%s'", target_ip);
+ char target[IPV6_STRLEN_MAX + 9]; // 9 for brackets, colon, port and \0
+
+ int ret = snprintf(target, sizeof(target), "[%s]:%d", target_ip,
+ SYSLOG_TARGET_PORT);
+ if (ret < 0) {
+ LOG_ERR("Failed to format target based on ip and port (%d)", ret);
+ return ret;
+ }
+
+ if (log_backend_net_set_addr(target) == false) {
+ LOG_ERR("Could not commit settings");
+ return -EINVAL;
}
- LOG_INF("Committed new target: '%s'", target_ip);
+ LOG_INF("Committed settings");
return 0;
}