From d6edaf630588fbc6b54a315f49f252e226c15342 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 2 Feb 2023 01:23:31 +0000 Subject: [PATCH] networkd: Split daemon bus implementation into a separate file Signed-off-by: Michael Tremer --- Makefile.am | 2 ++ src/networkd/bus.c | 29 ++--------------------- src/networkd/daemon-bus.c | 49 +++++++++++++++++++++++++++++++++++++++ src/networkd/daemon-bus.h | 28 ++++++++++++++++++++++ 4 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 src/networkd/daemon-bus.c create mode 100644 src/networkd/daemon-bus.h diff --git a/Makefile.am b/Makefile.am index ae4cb85b..3972d8dc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/networkd/bus.c b/src/networkd/bus.c index cab2ae6a..258aacda 100644 --- a/src/networkd/bus.c +++ b/src/networkd/bus.c @@ -19,39 +19,14 @@ #############################################################################*/ #include -#include #include #include #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 index 00000000..aac9775f --- /dev/null +++ b/src/networkd/daemon-bus.c @@ -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 . # +# # +#############################################################################*/ + +#include + +#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 index 00000000..787e92a1 --- /dev/null +++ b/src/networkd/daemon-bus.h @@ -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 . # +# # +#############################################################################*/ + +#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 */ -- 2.47.3