]> git.ipfire.org Git - people/ms/network.git/blame - src/networkd/zone.c
networkd: Store the path with the configuration object
[people/ms/network.git] / src / networkd / zone.c
CommitLineData
e4eebc6e
MT
1/*#############################################################################
2# #
3# IPFire.org - A linux based firewall #
4# Copyright (C) 2023 IPFire Network Development Team #
5# #
6# This program is free software: you can redistribute it and/or modify #
7# it under the terms of the GNU General Public License as published by #
8# the Free Software Foundation, either version 3 of the License, or #
9# (at your option) any later version. #
10# #
11# This program is distributed in the hope that it will be useful, #
12# but WITHOUT ANY WARRANTY; without even the implied warranty of #
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14# GNU General Public License for more details. #
15# #
16# You should have received a copy of the GNU General Public License #
17# along with this program. If not, see <http://www.gnu.org/licenses/>. #
18# #
19#############################################################################*/
20
21#include <stdlib.h>
22
23#include "config.h"
24#include "string.h"
25#include "zone.h"
26
27struct nw_zone {
28 int nrefs;
29
30 char name[NETWORK_ZONE_NAME_MAX_LENGTH];
31
32 // Configuration
33 struct nw_config *config;
34};
35
36static void nw_zone_free(struct nw_zone* zone) {
37 if (zone->config)
38 nw_config_unref(zone->config);
39
40 free(zone);
41}
42
43int nw_zone_create(struct nw_zone** zone, const char* name) {
44 int r;
45
46 // Allocate a new object
47 struct nw_zone* z = calloc(1, sizeof(*z));
48 if (!z)
49 return 1;
50
51 // Initialize reference counter
52 z->nrefs = 1;
53
54 // Store the name
55 r = nw_string_set(z->name, name);
56 if (r)
57 goto ERROR;
58
59 *zone = z;
60 return 0;
61
62ERROR:
63 nw_zone_free(z);
64 return r;
65}
66
67struct nw_zone* nw_zone_ref(struct nw_zone* zone) {
68 zone->nrefs++;
69
70 return zone;
71}
72
73struct nw_zone* nw_zone_unref(struct nw_zone* zone) {
74 if (--zone->nrefs > 0)
75 return zone;
76
77 nw_zone_free(zone);
78 return NULL;
79}
80
81const char* nw_zone_name(struct nw_zone* zone) {
82 return zone->name;
83}