diff options
-rw-r--r-- | src/network/networkd-manager.c | 2 | ||||
-rw-r--r-- | src/network/networkd-network.c | 14 | ||||
-rw-r--r-- | src/network/networkd-network.h | 8 | ||||
-rw-r--r-- | src/network/test-networkd-conf.c | 3 |
4 files changed, 17 insertions, 10 deletions
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 8c461a89e0..7d55142c41 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -1458,7 +1458,7 @@ void manager_free(Manager *m) { m->duids_requesting_uuid = set_free(m->duids_requesting_uuid); while ((network = m->networks)) - network_free(network); + network_unref(network); hashmap_free(m->networks_by_name); m->netdevs = hashmap_free_with_destructor(m->netdevs, netdev_unref); diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index a85d5ede28..0ac9f7bea3 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -298,7 +298,7 @@ int network_verify(Network *network) { int network_load_one(Manager *manager, const char *filename) { _cleanup_free_ char *fname = NULL, *name = NULL; - _cleanup_(network_freep) Network *network = NULL; + _cleanup_(network_unrefp) Network *network = NULL; _cleanup_fclose_ FILE *file = NULL; const char *dropin_dirname; char *d; @@ -344,6 +344,8 @@ int network_load_one(Manager *manager, const char *filename) { .filename = TAKE_PTR(fname), .name = TAKE_PTR(name), + .n_ref = 1, + .required_for_online = true, .required_operstate_for_online = LINK_OPERSTATE_DEGRADED, .dhcp = ADDRESS_FAMILY_NO, @@ -473,7 +475,7 @@ int network_load(Manager *manager) { assert(manager); while ((network = manager->networks)) - network_free(network); + network_unref(network); r = conf_files_list_strv(&files, ".network", NULL, 0, NETWORK_DIRS); if (r < 0) @@ -488,7 +490,7 @@ int network_load(Manager *manager) { return 0; } -void network_free(Network *network) { +static Network *network_free(Network *network) { IPv6ProxyNDPAddress *ipv6_proxy_ndp_address; RoutingPolicyRule *rule; FdbEntry *fdb_entry; @@ -499,7 +501,7 @@ void network_free(Network *network) { Route *route; if (!network) - return; + return NULL; free(network->filename); @@ -586,9 +588,11 @@ void network_free(Network *network) { set_free_free(network->dnssec_negative_trust_anchors); - free(network); + return mfree(network); } +DEFINE_TRIVIAL_REF_UNREF_FUNC(Network, network, network_free); + int network_get_by_name(Manager *manager, const char *name, Network **ret) { Network *network; diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index 852144da3c..782dd491a8 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -92,6 +92,8 @@ struct Network { char *filename; char *name; + unsigned n_ref; + Set *match_mac; char **match_path; char **match_driver; @@ -278,9 +280,9 @@ struct Network { LIST_FIELDS(Network, networks); }; -void network_free(Network *network); - -DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_free); +Network *network_ref(Network *network); +Network *network_unref(Network *network); +DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_unref); int network_load(Manager *manager); int network_load_one(Manager *manager, const char *filename); diff --git a/src/network/test-networkd-conf.c b/src/network/test-networkd-conf.c index 05fc01d048..dfb41f801b 100644 --- a/src/network/test-networkd-conf.c +++ b/src/network/test-networkd-conf.c @@ -169,9 +169,10 @@ static void test_config_parse_hwaddr(void) { } static void test_config_parse_address_one(const char *rvalue, int family, unsigned n_addresses, const union in_addr_union *u, unsigned char prefixlen) { - _cleanup_(network_freep) Network *network = NULL; + _cleanup_(network_unrefp) Network *network = NULL; assert_se(network = new0(Network, 1)); + network->n_ref = 1; assert_se(network->filename = strdup("hogehoge.network")); assert_se(config_parse_ifnames("network", "filename", 1, "section", 1, "Name", 0, "*", &network->match_name, network) == 0); assert_se(config_parse_address("network", "filename", 1, "section", 1, "Address", 0, rvalue, network, network) == 0); |