src/daemon/metrics.h \
src/daemon/netlink.c \
src/daemon/netlink.h \
+ src/daemon/openvpn.c \
+ src/daemon/openvpn.h \
src/daemon/parse.c \
src/daemon/parse.h \
src/daemon/priv.c \
--- /dev/null
+/*#############################################################################
+# #
+# telemetryd - The IPFire Telemetry Collection Service #
+# Copyright (C) 2026 IPFire Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <errno.h>
+#include <string.h>
+
+#include "openvpn.h"
+
+int __openvpn_escape_name(char* buffer, const size_t length, const char* name) {
+ const size_t l = strlen(name);
+
+ // Check if the output buffer is long enough
+ if (l >= length)
+ return -ENOBUFS;
+
+ const char* src = name;
+ char* dst = buffer;
+
+ while (*src) {
+ switch (*src) {
+ case ' ':
+ *dst++ = '-';
+ src++;
+ break;
+
+ default:
+ *dst++ = *src++;
+ break;
+ }
+ }
+
+ // Terminate the output buffer
+ *dst = '\0';
+
+ return 0;
+}
--- /dev/null
+/*#############################################################################
+# #
+# telemetryd - The IPFire Telemetry Collection Service #
+# Copyright (C) 2026 IPFire Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#ifndef TELEMETRY_OPENVPN_H
+#define TELEMETRY_OPENVPN_H
+
+#include <stddef.h>
+
+#define OPENVPN_NAME_MAX 128
+
+#define openvpn_escape_name(buffer, name) \
+ __openvpn_escape_name(buffer, sizeof(buffer), name)
+
+int __openvpn_escape_name(char* buffer, const size_t length, const char* name);
+
+#endif /* TELEMETRY_OPENVPN_H */
#ifdef BUILD_SOURCE_OPENVPN
#include "../ctx.h"
+#include "../openvpn.h"
#include "../source.h"
#include "../string.h"
#include "openvpn.h"
size_t tx_bytes;
} openvpn_client;
-static void openvpn_escape_name(char* name) {
- for (char* p = name; *p; p++) {
- switch (*p) {
- case ' ':
- *p = '-';
- break;
-
- default:
- break;
- }
- }
-}
-
// This function ensures that we can parse the comma-separated as well as the
// tab-separated status format.
static int detect_delimiter(td_ctx* ctx, char* line, openvpn_fields* fields) {
char* line, size_t length, void* data) {
openvpn_fields* fields = data;
openvpn_client client = {};
+ char name[OPENVPN_NAME_MAX];
int r;
// Detect the delimiter
return 0;
// Escape the name
- openvpn_escape_name(client.common_name);
+ r = openvpn_escape_name(name, client.common_name);
+ if (r < 0)
+ return r;
// Submit the client
- return td_source_submit_values(fields->source,
- client.common_name, VALUES(
- VALUE_UINT64("rx_bytes", &client.rx_bytes),
- VALUE_UINT64("tx_bytes", &client.tx_bytes)
- )
- );
+ return td_source_submit_values(fields->source, name, VALUES(
+ VALUE_UINT64("rx_bytes", &client.rx_bytes),
+ VALUE_UINT64("tx_bytes", &client.tx_bytes)
+ ));
}
return 0;