src/daemon/main.c \
src/daemon/metrics.c \
src/daemon/metrics.h \
+ src/daemon/netlink.c \
+ src/daemon/netlink.h \
src/daemon/parse.c \
src/daemon/parse.h \
src/daemon/priv.c \
#include "graphs.h"
#include "graph-bus.h"
#include "metrics.h"
+#include "netlink.h"
#include "queue.h"
#include "sensors.h"
#include "source.h"
// udev
struct udev* udev;
+ // Netlink
+ td_netlink* netlink;
+
// Netlink Sockets
#ifdef HAVE_LIBNL3
struct {
return 0;
}
+static int td_daemon_setup_netlink(td_daemon* self) {
+ int r;
+
+ // Create netlink
+ r = td_netlink_create(&self->netlink, self->ctx);
+ if (r < 0) {
+ ERROR(self->ctx, "Failed to setup netlink: %s\n", strerror(-r));
+ return r;
+ }
+
+ return 0;
+}
+
static void td_daemon_free(td_daemon* self) {
// Free Netlink Sockets
#ifdef HAVE_LIBNL3
sd_event_source_unref(self->events.init);
if (self->events.exit)
sd_event_source_unref(self->events.exit);
+ if (self->netlink)
+ td_netlink_unref(self->netlink);
if (self->sources)
td_sources_unref(self->sources);
if (self->graphs)
if (r < 0)
goto ERROR;
+ // Connect to netlink
+ r = td_daemon_setup_netlink(self);
+ if (r < 0)
+ goto ERROR;
+
// Return the pointer
*daemon = self;
return 0;
return td_queue_flush_source(self->queue, source, object);
}
+td_netlink* td_daemon_get_netlink(td_daemon* self) {
+ return td_netlink_ref(self->netlink);
+}
+
#ifdef HAVE_LIBNL3
static struct nl_sock* td_daemon_get_nl_socket(td_daemon* self, int protocol) {
struct nl_sock* sock = NULL;
#include "ctx.h"
#include "graphs.h"
#include "metrics.h"
+#include "netlink.h"
#include "source.h"
#include "sources.h"
td_daemon* self, td_source* source, const char* object);
#ifdef HAVE_LIBNL3
+td_netlink* td_daemon_get_netlink(td_daemon* self);
+
# ifdef HAVE_LIBNL3_GENL
struct nl_sock* td_daemon_get_nl_80211_socket(td_daemon* self);
int td_daemon_get_nl_80211_id(td_daemon* self);
--- /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/>. #
+# #
+#############################################################################*/
+
+#ifdef HAVE_LIBNL3
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include "ctx.h"
+#include "netlink.h"
+
+struct td_netlink {
+ td_ctx* ctx;
+ int nrefs;
+};
+
+static void td_netlink_free(td_netlink* self) {
+ if (self->ctx)
+ td_ctx_unref(self->ctx);
+ free(self);
+}
+
+int td_netlink_create(td_netlink** netlink, td_ctx* ctx) {
+ td_netlink* self = NULL;
+
+ // Allocate some memory
+ self = calloc(1, sizeof(*self));
+ if (!self)
+ return -errno;
+
+ // Initialize the reference counter
+ self->nrefs = 1;
+
+ // Store a reference to the context
+ self->ctx = td_ctx_ref(ctx);
+
+ // Return the pointer
+ *netlink = self;
+
+ return 0;
+}
+
+td_netlink* td_netlink_ref(td_netlink* self) {
+ ++self->nrefs;
+ return self;
+}
+
+td_netlink* td_netlink_unref(td_netlink* self) {
+ if (--self->nrefs > 0)
+ return self;
+
+ td_netlink_free(self);
+ return NULL;
+}
+
+#endif /* HAVE_LIBNL3 */
--- /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_NETLINK_H
+#define TELEMETRY_NETLINK_H
+
+#ifdef HAVE_LIBNL3
+
+#include "ctx.h"
+
+typedef struct td_netlink td_netlink;
+
+int td_netlink_create(td_netlink** netlink, td_ctx* ctx);
+
+td_netlink* td_netlink_ref(td_netlink* self);
+td_netlink* td_netlink_unref(td_netlink* self);
+
+#endif /* HAVE_LIBNL3 */
+
+#endif /* TELEMETRY_NETLINK_H */