]> git.ipfire.org Git - people/ms/network.git/commitdiff
networkd: Add scaffolding for config objects
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 30 Jan 2023 02:16:06 +0000 (02:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 30 Jan 2023 02:16:06 +0000 (02:16 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/networkd/config.c [new file with mode: 0644]
src/networkd/config.h [new file with mode: 0644]

index 60a1bcde84565e70ce92d53b9f82fa0959db8be2..50a6034a0b6dec769a3417a0a49ad7f74758422b 100644 (file)
@@ -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 (file)
index 0000000..d18fb12
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <stdlib.h>
+
+#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 (file)
index 0000000..a8aed7f
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#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 */