From: Michael Tremer Date: Mon, 30 Jan 2023 02:16:06 +0000 (+0000) Subject: networkd: Add scaffolding for config objects X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b666d6221c5797f78fa4942561c931609d8f656;p=network.git networkd: Add scaffolding for config objects Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 60a1bcde..50a6034a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -306,6 +306,8 @@ sbin_PROGRAMS += \ dist_networkd_SOURCES = \ src/networkd/bus.c \ src/networkd/bus.h \ + src/networkd/config.c \ + src/networkd/config.h \ src/networkd/daemon.c \ src/networkd/daemon.h \ src/networkd/logging.h \ diff --git a/src/networkd/config.c b/src/networkd/config.c new file mode 100644 index 00000000..d18fb12b --- /dev/null +++ b/src/networkd/config.c @@ -0,0 +1,58 @@ +/*############################################################################# +# # +# 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 "config.h" + +struct nw_config { + int nrefs; +}; + +static void nw_config_free(struct nw_config* config) { + free(config); +} + +int nw_config_create(struct nw_config** config) { + struct nw_config* c = calloc(1, sizeof(*c)); + if (!c) + return 1; + + // Initialize reference counter + c->nrefs = 1; + + *config = c; + + return 0; +} + +struct nw_config* nw_config_ref(struct nw_config* config) { + config->nrefs++; + + return config; +} + +struct nw_config* nw_config_unref(struct nw_config* config) { + if (--config->nrefs > 0) + return config; + + nw_config_free(config); + return NULL; +} diff --git a/src/networkd/config.h b/src/networkd/config.h new file mode 100644 index 00000000..a8aed7f0 --- /dev/null +++ b/src/networkd/config.h @@ -0,0 +1,31 @@ +/*############################################################################# +# # +# 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_CONFIG_H +#define NETWORKD_CONFIG_H + +struct nw_config; + +int nw_config_create(struct nw_config** config); + +struct nw_config* nw_config_ref(struct nw_config* config); +struct nw_config* nw_config_unref(struct nw_config* config); + +#endif /* NETWORKD_CONFIG_H */