src/networkd/daemon.h \
src/networkd/daemon-bus.c \
src/networkd/daemon-bus.h \
+ src/networkd/devmon.c \
+ src/networkd/devmon.h \
src/networkd/logging.h \
src/networkd/main.c \
src/networkd/string.h \
#include <systemd/sd-bus.h>
#include <systemd/sd-daemon.h>
+#include <systemd/sd-device.h>
#include <systemd/sd-event.h>
#include "bus.h"
#include "config.h"
#include "daemon.h"
+#include "devmon.h"
#include "logging.h"
#include "zone.h"
#include "zones.h"
+// Increase the receive buffer to 128 MiB
+#define RCVBUF_SIZE 128 * 1024 * 1024
+
struct nw_daemon {
int nrefs;
// DBus Connection
sd_bus* bus;
+ // udev Connection
+ sd_device_monitor* devmon;
+
// Zones
struct nw_zones* zones;
};
return r;
}
+static int nw_start_device_monitor(struct nw_daemon* daemon) {
+ int r;
+
+ const char* subsystems[] = {
+ "net",
+ "ieee80211",
+ "rfkill",
+ NULL,
+ };
+
+ // Create a new connection to monitor any devices
+ r = sd_device_monitor_new(&daemon->devmon);
+ if (r < 0) {
+ ERROR("Could not inititalize the device monitor: %m\n");
+ return 1;
+ }
+
+ // Increase the receive buffer
+ r = sd_device_monitor_set_receive_buffer_size(daemon->devmon, RCVBUF_SIZE);
+ if (r < 0) {
+ ERROR("Could not increase buffer size for the device monitor: %m\n");
+ return 1;
+ }
+
+ // Filter for events for all relevant subsystems
+ for (const char** subsystem = subsystems; *subsystem; subsystem++) {
+ r = sd_device_monitor_filter_add_match_subsystem_devtype(
+ daemon->devmon, *subsystem, NULL);
+ if (r < 1) {
+ ERROR("Could not add device monitor for the %s subsystem: %m\n", *subsystem);
+ return 1;
+ }
+ }
+
+ // Attach the device monitor to the event loop
+ r = sd_device_monitor_attach_event(daemon->devmon, daemon->loop);
+ if (r < 0) {
+ ERROR("Could not attach the device monitor to the event loop: %m\n");
+ return 1;
+ }
+
+ // Start processing events...
+ r = sd_device_monitor_start(daemon->devmon, nw_devmon_handle_uevent, daemon);
+ if (r < 0) {
+ ERROR("Could not start the device monitor: %m\n");
+ return 1;
+ }
+
+ return 0;
+}
+
static int nw_daemon_setup(struct nw_daemon* daemon) {
int r;
if (r)
return r;
+ // Connect to udev
+ r = nw_start_device_monitor(daemon);
+ if (r)
+ return r;
+
return 0;
}
--- /dev/null
+/*#############################################################################
+# #
+# IPFire.org - A linux based firewall #
+# Copyright (C) 2023 IPFire Network 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 <systemd/sd-device.h>
+
+#include "devmon.h"
+
+int nw_devmon_handle_uevent(sd_device_monitor* monitor, sd_device* device, void* data) {
+ return 0;
+}
--- /dev/null
+/*#############################################################################
+# #
+# IPFire.org - A linux based firewall #
+# Copyright (C) 2023 IPFire Network 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 NETWORKD_DEVMON_H
+#define NETWORKD_DEVMON_H
+
+#include <systemd/sd-device.h>
+
+int nw_devmon_handle_uevent(sd_device_monitor* monitor, sd_device* device, void* data);
+
+#endif /* NETWORKD_DEVMON_H */