]> git.ipfire.org Git - telemetry.git/commitdiff
daemon: Retrieve and cache the nl80211 ID separately
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 30 Mar 2026 14:41:38 +0000 (14:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 30 Mar 2026 14:41:38 +0000 (14:41 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/daemon.c
src/daemon/daemon.h

index 929199789ed94697424d777c9b2e66530ff684d7..71100f72b1e3133620aec28c3b589575107d2e22 100644 (file)
@@ -98,6 +98,12 @@ struct td_daemon {
 # endif /* HAVE_LIBNL3_ROUTE */
        } nl_sockets;
 #endif /* HAVE_LIBNL3 */
+
+#ifdef HAVE_LIBNL3
+# ifdef HAVE_LIBNL3_GENL
+       int nl80211id;
+# endif /* HAVE_LIBNL3_GENL */
+#endif /* HAVE_LIBNL3 */
 };
 
 static int td_daemon_init(sd_event_source* source, void* data) {
@@ -484,32 +490,35 @@ ERROR:
 
 # ifdef HAVE_LIBNL3_GENL
 struct nl_sock* td_daemon_get_nl_80211_socket(td_daemon* self) {
+       // Create socket if not already done
+       if (!self->nl_sockets.nl80211)
+               self->nl_sockets.nl80211 = td_daemon_get_nl_socket(self, NETLINK_GENERIC);
+
+       return self->nl_sockets.nl80211;
+}
+
+int td_daemon_get_nl_80211_id(td_daemon* self) {
        struct nl_sock* sock = NULL;
        int r;
 
-       // Create socket if not already done
-       if (!self->nl_sockets.nl80211) {
-               sock = td_daemon_get_nl_socket(self, NETLINK_GENERIC);
+       if (!self->nl80211id) {
+               // Fetch the nl80211 socket
+               sock = td_daemon_get_nl_80211_socket(self);
+               if (!sock)
+                       return -errno;
 
-               // Resolve 802.11
+               // Retrieve the ID
                r = genl_ctrl_resolve(sock, "nl80211");
                if (r < 0) {
-                       ERROR(self->ctx, "Failed to resolve nl80211: %s\n", nl_geterror(r));
-                       errno = ENOTSUP;
-                       goto ERROR;
+                       ERROR(self->ctx, "Failed to resolve nl80211 family id: %s\n", nl_geterror(r));
+                       return -ENOTSUP;
                }
 
-               // Store the socket
-               self->nl_sockets.nl80211 = sock;
+               // Cache the ID
+               self->nl80211id = r;
        }
 
-       return self->nl_sockets.nl80211;
-
-ERROR:
-       if (sock)
-               nl_socket_free(sock);
-
-       return NULL;
+       return self->nl80211id;
 }
 # endif /* HAVE_LIBNL3_GENL */
 
index 64ab376a8b315ce9ef47264237c65753e6871946..02daba4c6a8481667bd37ba96ac9b8e3fcbc5186 100644 (file)
@@ -61,6 +61,7 @@ int td_daemon_flush_source(
 #ifdef HAVE_LIBNL3
 # 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);
 # endif /* HAVE_LIBNL3_GENL */
 
 # ifdef HAVE_LIBNL3_ROUTE