src/networkd/devmon.h \
src/networkd/link.c \
src/networkd/link.h \
+ src/networkd/links.c \
+ src/networkd/links.h \
src/networkd/logging.h \
src/networkd/main.c \
src/networkd/string.h \
#include "config.h"
#include "daemon.h"
#include "devmon.h"
+#include "links.h"
#include "logging.h"
#include "zone.h"
#include "zones.h"
// udev Connection
sd_device_monitor* devmon;
+ // Links
+ struct nw_links* links;
+
// Zones
struct nw_zones* zones;
};
return 0;
}
+static int nw_daemon_enumerate_links(struct nw_daemon* daemon) {
+ int r;
+
+ // Create a new links container
+ r = nw_links_create(&daemon->links, daemon);
+ if (r)
+ return r;
+
+ return nw_links_enumerate(daemon->links);
+}
+
+static int nw_daemon_enumerate(struct nw_daemon* daemon) {
+ int r;
+
+ // Links
+ r = nw_daemon_enumerate_links(daemon);
+ if (r)
+ return r;
+
+ return 0;
+}
+
static int nw_daemon_setup(struct nw_daemon* daemon) {
int r;
if (r)
return r;
+ // Enumerate everything we need to know
+ r = nw_daemon_enumerate(daemon);
+ if (r)
+ return r;
+
return 0;
}
return r;
}
-static void nw_daemon_free(struct nw_daemon* daemon) {
+static void nw_daemon_cleanup(struct nw_daemon* daemon) {
if (daemon->zones)
nw_zones_unref(daemon->zones);
+ if (daemon->links)
+ nw_links_unref(daemon->links);
if (daemon->config)
nw_config_unref(daemon->config);
+}
+
+static void nw_daemon_free(struct nw_daemon* daemon) {
+ // Cleanup common objects
+ nw_daemon_cleanup(daemon);
+
if (daemon->bus)
sd_bus_unref(daemon->bus);
if (daemon->loop)
goto ERROR;
}
-
// Let systemd know that we are shutting down
sd_notify(0, "STOPPING=1\n" "STATUS=Shutting down...");
+ // Cleanup everything
+ nw_daemon_cleanup(daemon);
+
return 0;
ERROR:
sd_notifyf(0, "ERRNO=%i", -r);
+ // Cleanup everything
+ nw_daemon_cleanup(daemon);
+
return 1;
}
#ifndef NETWORKD_LINK_H
#define NETWORKD_LINK_H
+#include "daemon.h"
+
struct nw_link;
int nw_link_create(struct nw_link** link, struct nw_daemon* daemon, int ifindex);
--- /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 <stddef.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+
+#include "daemon.h"
+#include "link.h"
+#include "links.h"
+
+struct nw_links_entry {
+ struct nw_link* link;
+
+ // Link to the other entries
+ STAILQ_ENTRY(nw_links_entry) nodes;
+};
+
+struct nw_links {
+ struct nw_daemon* daemon;
+ int nrefs;
+
+ // Link Entries
+ STAILQ_HEAD(entries, nw_links_entry) entries;
+
+ // A counter of the link entries
+ unsigned int num;
+};
+
+int nw_links_create(struct nw_links** links, struct nw_daemon* daemon) {
+ struct nw_links* l = calloc(1, sizeof(*l));
+ if (!l)
+ return 1;
+
+ // Store a reference to the daemon
+ l->daemon = nw_daemon_ref(daemon);
+
+ // Initialize the reference counter
+ l->nrefs = 1;
+
+ // Initialize entries
+ STAILQ_INIT(&l->entries);
+
+ // Reference the pointer
+ *links = l;
+
+ return 0;
+}
+
+static void nw_links_free(struct nw_links* links) {
+ struct nw_links_entry* entry = NULL;
+
+ while (!STAILQ_EMPTY(&links->entries)) {
+ entry = STAILQ_FIRST(&links->entries);
+
+ // Dereference the zone
+ nw_link_unref(entry->link);
+
+ // Remove the entry from the list
+ STAILQ_REMOVE_HEAD(&links->entries, nodes);
+
+ // Free the entry
+ free(entry);
+ }
+
+ if (links->daemon)
+ nw_daemon_unref(links->daemon);
+}
+
+struct nw_links* nw_links_ref(struct nw_links* links) {
+ links->nrefs++;
+
+ return links;
+}
+
+struct nw_links* nw_links_unref(struct nw_links* links) {
+ if (--links->nrefs > 0)
+ return links;
+
+ nw_links_free(links);
+ return NULL;
+}
+
+int nw_links_enumerate(struct nw_links* links) {
+ // TODO
+
+ 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_LINKS_H
+#define NETWORKD_LINKS_H
+
+#include "daemon.h"
+
+struct nw_links;
+
+int nw_links_create(struct nw_links** links, struct nw_daemon* daemon);
+
+struct nw_links* nw_links_ref(struct nw_links* links);
+struct nw_links* nw_links_unref(struct nw_links* links);
+
+int nw_links_enumerate(struct nw_links* links);
+
+#endif /* NETWORKD_LINKS_H */