]> git.ipfire.org Git - network.git/commitdiff
networkd: Split daemon bus implementation into a separate file
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Feb 2023 01:23:31 +0000 (01:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Feb 2023 01:23:31 +0000 (01:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/networkd/bus.c
src/networkd/daemon-bus.c [new file with mode: 0644]
src/networkd/daemon-bus.h [new file with mode: 0644]

index ae4cb85ba8f48f068f20f8a0ff87a9830d6d7007..3972d8dca9f38939af4a8ca6e682ef8333169262 100644 (file)
@@ -314,6 +314,8 @@ dist_networkd_SOURCES = \
        src/networkd/config.h \
        src/networkd/daemon.c \
        src/networkd/daemon.h \
+       src/networkd/daemon-bus.c \
+       src/networkd/daemon-bus.h \
        src/networkd/logging.h \
        src/networkd/main.c \
        src/networkd/string.h \
index cab2ae6a34a796badb8bfc76e1142ca2ec909c77..258aacdaedfb39a76daf5100f82645f5113b002c 100644 (file)
 #############################################################################*/
 
 #include <stdlib.h>
-#include <string.h>
 
 #include <systemd/sd-bus.h>
 #include <systemd/sd-event.h>
 
 #include "bus.h"
 #include "daemon.h"
+#include "daemon-bus.h"
 #include "logging.h"
-#include "zone-bus.h"
-
-static int nw_bus_daemon_reload(sd_bus_message* m, void* data, sd_bus_error* error) {
-       struct nw_daemon* daemon = (struct nw_daemon*)data;
-
-       // Reload the daemon
-       nw_daemon_reload(daemon);
-
-       // Respond with an empty message
-       return sd_bus_reply_method_return(m, NULL);
-}
-
-static const sd_bus_vtable daemon_vtable[] = {
-        SD_BUS_VTABLE_START(0),
-        SD_BUS_METHOD("Reload", SD_BUS_NO_ARGS, SD_BUS_NO_RESULT,
-                       nw_bus_daemon_reload, SD_BUS_VTABLE_UNPRIVILEGED),
-        SD_BUS_VTABLE_END,
-};
-
-const struct nw_bus_implementation daemon_implementation = {
-       .path = "/org/ipfire/network1",
-       .interface = "org.ipfire.network1",
-       .vtables = BUS_VTABLES(daemon_vtable),
-       .children = BUS_IMPLEMENTATIONS(&zone_bus_impl),
-};
 
 static int nw_bus_on_connect(sd_bus_message* m, void* data, sd_bus_error* error) {
        struct nw_daemon* daemon = (struct nw_daemon*)data;
@@ -126,7 +101,7 @@ int nw_bus_connect(sd_bus* bus, sd_event* loop, struct nw_daemon* daemon) {
        }
 
        // Register the implementation
-       r = nw_bus_register_implementation(bus, &daemon_implementation, daemon);
+       r = nw_bus_register_implementation(bus, &daemon_bus_impl, daemon);
        if (r)
                return r;
 
diff --git a/src/networkd/daemon-bus.c b/src/networkd/daemon-bus.c
new file mode 100644 (file)
index 0000000..aac9775
--- /dev/null
@@ -0,0 +1,49 @@
+/*#############################################################################
+#                                                                             #
+# 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-bus.h>
+
+#include "bus.h"
+#include "daemon.h"
+#include "zone-bus.h"
+
+static int nw_daemon_bus_reload(sd_bus_message* m, void* data, sd_bus_error* error) {
+       struct nw_daemon* daemon = (struct nw_daemon*)data;
+
+       // Reload the daemon
+       nw_daemon_reload(daemon);
+
+       // Respond with an empty message
+       return sd_bus_reply_method_return(m, NULL);
+}
+
+static const sd_bus_vtable daemon_vtable[] = {
+       SD_BUS_VTABLE_START(0),
+       SD_BUS_METHOD("Reload", SD_BUS_NO_ARGS, SD_BUS_NO_RESULT,
+               nw_daemon_bus_reload, SD_BUS_VTABLE_UNPRIVILEGED),
+       SD_BUS_VTABLE_END,
+};
+
+const struct nw_bus_implementation daemon_bus_impl = {
+       .path = "/org/ipfire/network1",
+       .interface = "org.ipfire.network1",
+       .vtables = BUS_VTABLES(daemon_vtable),
+       .children = BUS_IMPLEMENTATIONS(&zone_bus_impl),
+};
diff --git a/src/networkd/daemon-bus.h b/src/networkd/daemon-bus.h
new file mode 100644 (file)
index 0000000..787e92a
--- /dev/null
@@ -0,0 +1,28 @@
+/*#############################################################################
+#                                                                             #
+# 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_DAEMON_BUS_H
+#define NETWORKD_DAEMON_BUS_H
+
+#include "bus.h"
+
+extern const struct nw_bus_implementation daemon_bus_impl;
+
+#endif /* NETWORKD_DAEMON_BUS_H */