--- /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 "daemon.h"
+#include "link.h"
+
+struct nw_link {
+ struct nw_daemon* daemon;
+ int nrefs;
+
+ // Interface Index
+ int ifindex;
+};
+
+int nw_link_create(struct nw_link** link, struct nw_daemon* daemon, int ifindex) {
+ // Allocate a new object
+ struct nw_link* 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;
+
+ // Store the ifindex
+ l->ifindex = ifindex;
+
+ *link = l;
+
+ return 0;
+}
+
+static void nw_link_free(struct nw_link* link) {
+ if (link->daemon)
+ nw_daemon_unref(link->daemon);
+}
+
+struct nw_link* nw_link_ref(struct nw_link* link) {
+ link->nrefs++;
+
+ return link;
+}
+
+struct nw_link* nw_link_unref(struct nw_link* link) {
+ if (--link->nrefs > 0)
+ return link;
+
+ nw_link_free(link);
+ return NULL;
+}
--- /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_LINK_H
+#define NETWORKD_LINK_H
+
+struct nw_link;
+
+int nw_link_create(struct nw_link** link, struct nw_daemon* daemon, int ifindex);
+
+struct nw_link* nw_link_ref(struct nw_link* link);
+struct nw_link* nw_link_unref(struct nw_link* link);
+
+#endif /* NETWORKD_LINK_H */