--- /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 <net/if.h>
+#include <stdlib.h>
+
+#include "config.h"
+#include "string.h"
+#include "port.h"
+
+struct nw_port {
+ int nrefs;
+
+ char name[IF_NAMESIZE];
+
+ // Configuration
+ struct nw_config *config;
+};
+
+static void nw_port_free(struct nw_port* port) {
+ if (port->config)
+ nw_config_unref(port->config);
+
+ free(port);
+}
+
+int nw_port_create(struct nw_port** port, const char* name) {
+ int r;
+
+ // Allocate a new object
+ struct nw_port* p = calloc(1, sizeof(*p));
+ if (!p)
+ return 1;
+
+ // Initialize reference counter
+ p->nrefs = 1;
+
+ // Store the name
+ r = nw_string_set(p->name, name);
+ if (r)
+ goto ERROR;
+
+ *port = p;
+ return 0;
+
+ERROR:
+ nw_port_free(p);
+ return r;
+}
+
+struct nw_port* nw_port_ref(struct nw_port* port) {
+ port->nrefs++;
+
+ return port;
+}
+
+struct nw_port* nw_port_unref(struct nw_port* port) {
+ if (--port->nrefs > 0)
+ return port;
+
+ nw_port_free(port);
+ return NULL;
+}
+
+const char* nw_port_name(struct nw_port* port) {
+ return port->name;
+}
--- /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_PORT_H
+#define NETWORKD_PORT_H
+
+struct nw_port;
+
+int nw_port_create(struct nw_port** port, const char* name);
+
+struct nw_port* nw_port_ref(struct nw_port* port);
+struct nw_port* nw_port_unref(struct nw_port* port);
+
+const char* nw_port_name(struct nw_port* port);
+
+#endif /* NETWORKD_PORT_H */