From: Yu Watanabe Date: Sat, 4 May 2019 05:52:38 +0000 (+0200) Subject: network: introduce reference counter for Network object X-Git-Tag: v243~593^2~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=35ac3b76641926f60c7f0602fc24eaeae24e4fc8;p=platform%2Fupstream%2Fsystemd.git network: introduce reference counter for Network object --- diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 8c461a8..7d55142 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 a85d5ed..0ac9f7b 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 852144d..782dd49 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 05fc01d..dfb41f8 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);