src/networkd/daemon.h \
src/networkd/logging.h \
src/networkd/main.c \
- src/networkd/string.h
+ src/networkd/string.h \
+ src/networkd/zone.c \
+ src/networkd/zone.h
networkd_CPPFLAGS = \
$(AM_CPPFLAGS) \
#ifndef NETWORKD_CONFIG_H
#define NETWORKD_CONFIG_H
+#include <stdio.h>
+
#define NETWORK_CONFIG_KEY_MAX_LENGTH 128
#define NETWORK_CONFIG_VALUE_MAX_LENGTH 2048
#ifndef NETWORKD_STRING_H
#define NETWORKD_STRING_H
+#include <errno.h>
#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
static inline int __nw_string_vformat(char* s, const size_t length,
const char* format, va_list args) {
--- /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 "config.h"
+#include "string.h"
+#include "zone.h"
+
+struct nw_zone {
+ int nrefs;
+
+ char name[NETWORK_ZONE_NAME_MAX_LENGTH];
+
+ // Configuration
+ struct nw_config *config;
+};
+
+static void nw_zone_free(struct nw_zone* zone) {
+ if (zone->config)
+ nw_config_unref(zone->config);
+
+ free(zone);
+}
+
+int nw_zone_create(struct nw_zone** zone, const char* name) {
+ int r;
+
+ // Allocate a new object
+ struct nw_zone* z = calloc(1, sizeof(*z));
+ if (!z)
+ return 1;
+
+ // Initialize reference counter
+ z->nrefs = 1;
+
+ // Store the name
+ r = nw_string_set(z->name, name);
+ if (r)
+ goto ERROR;
+
+ *zone = z;
+ return 0;
+
+ERROR:
+ nw_zone_free(z);
+ return r;
+}
+
+struct nw_zone* nw_zone_ref(struct nw_zone* zone) {
+ zone->nrefs++;
+
+ return zone;
+}
+
+struct nw_zone* nw_zone_unref(struct nw_zone* zone) {
+ if (--zone->nrefs > 0)
+ return zone;
+
+ nw_zone_free(zone);
+ return NULL;
+}
+
+const char* nw_zone_name(struct nw_zone* zone) {
+ return zone->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_ZONE_H
+#define NETWORKD_ZONE_H
+
+#define NETWORK_ZONE_NAME_MAX_LENGTH 16
+
+struct nw_zone;
+
+int nw_zone_create(struct nw_zone** zone, const char* name);
+
+struct nw_zone* nw_zone_ref(struct nw_zone* zone);
+struct nw_zone* nw_zone_unref(struct nw_zone* zone);
+
+const char* nw_zone_name(struct nw_zone* zone);
+
+#endif /* NETWORKD_ZONE_H */