#include "link.h"
#include "links.h"
#include "logging.h"
+#include "ports.h"
#include "zone.h"
#include "zones.h"
// Zones
struct nw_zones* zones;
+
+ // Ports
+ struct nw_ports* ports;
+
};
static int __nw_daemon_terminate(sd_event_source* source, const struct signalfd_siginfo* si,
return nw_links_enumerate(daemon->links);
}
+static int nw_daemon_enumerate_ports(struct nw_daemon* daemon) {
+ int r;
+
+ // Create a new ports container
+ r = nw_ports_create(&daemon->ports, daemon);
+ if (r)
+ return r;
+
+ return nw_ports_enumerate(daemon->ports);
+}
+
static int nw_daemon_enumerate(struct nw_daemon* daemon) {
int r;
if (r)
return r;
+ // Ports
+ r = nw_daemon_enumerate_ports(daemon);
+ if (r)
+ return r;
+
return 0;
}
}
static void nw_daemon_cleanup(struct nw_daemon* daemon) {
+ if (daemon->ports)
+ nw_ports_unref(daemon->ports);
if (daemon->zones)
nw_zones_unref(daemon->zones);
if (daemon->links)
--- /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 <stdlib.h>
+#include <string.h>
+#include <sys/queue.h>
+
+#include "logging.h"
+#include "port.h"
+#include "ports.h"
+
+struct nw_ports_entry {
+ struct nw_port* port;
+
+ // Link to the other entries
+ STAILQ_ENTRY(nw_ports_entry) nodes;
+};
+
+struct nw_ports {
+ struct nw_daemon* daemon;
+ int nrefs;
+
+ // Port Entries
+ STAILQ_HEAD(entries, nw_ports_entry) entries;
+
+ // A counter of the port entries
+ unsigned int num;
+};
+
+int nw_ports_create(struct nw_ports** ports, struct nw_daemon* daemon) {
+ struct nw_ports* p = calloc(1, sizeof(*p));
+ if (!p)
+ return 1;
+
+ // Store a reference to the daemon
+ p->daemon = nw_daemon_ref(daemon);
+
+ // Initialize the reference counter
+ p->nrefs = 1;
+
+ // Initialize entries
+ STAILQ_INIT(&p->entries);
+
+ // Reference the pointer
+ *ports = p;
+
+ return 0;
+}
+
+static void nw_ports_free(struct nw_ports* ports) {
+ struct nw_ports_entry* entry = NULL;
+
+ while (!STAILQ_EMPTY(&ports->entries)) {
+ entry = STAILQ_FIRST(&ports->entries);
+
+ // Dereference the port
+ nw_port_unref(entry->port);
+
+ // Remove the entry from the list
+ STAILQ_REMOVE_HEAD(&ports->entries, nodes);
+
+ // Free the entry
+ free(entry);
+ }
+}
+
+struct nw_ports* nw_ports_ref(struct nw_ports* ports) {
+ ports->nrefs++;
+
+ return ports;
+}
+
+struct nw_ports* nw_ports_unref(struct nw_ports* ports) {
+ if (--ports->nrefs > 0)
+ return ports;
+
+ nw_ports_free(ports);
+ return NULL;
+}
+
+int nw_ports_enumerate(struct nw_ports* ports) {
+ return 0; // XXX TODO
+}
--- /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_PORTS_H
+#define NETWORKD_PORTS_H
+
+struct nw_ports;
+
+#include "daemon.h"
+
+int nw_ports_create(struct nw_ports** ports, struct nw_daemon* daemon);
+
+struct nw_ports* nw_ports_ref(struct nw_ports* ports);
+struct nw_ports* nw_ports_unref(struct nw_ports* ports);
+
+int nw_ports_enumerate(struct nw_ports* ports);
+
+#endif /* NETWORKD_ZONES_H */