network: fixes related to NetworkConfigSection
- Do not allocate NetworkConfigSection when filename == NULL - set .network element before calling hashmap_put() - Always free NetworkConfigSection in each object.
This commit is contained in:
parent
17f9c355d5
commit
0f7f27694e
|
@ -11,18 +11,6 @@
|
||||||
#include "parse-util.h"
|
#include "parse-util.h"
|
||||||
#include "socket-util.h"
|
#include "socket-util.h"
|
||||||
|
|
||||||
int address_label_new(AddressLabel **ret) {
|
|
||||||
_cleanup_(address_label_freep) AddressLabel *addrlabel = NULL;
|
|
||||||
|
|
||||||
addrlabel = new0(AddressLabel, 1);
|
|
||||||
if (!addrlabel)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
*ret = TAKE_PTR(addrlabel);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void address_label_free(AddressLabel *label) {
|
void address_label_free(AddressLabel *label) {
|
||||||
if (!label)
|
if (!label)
|
||||||
return;
|
return;
|
||||||
|
@ -50,6 +38,7 @@ static int address_label_new_static(Network *network, const char *filename, unsi
|
||||||
assert(ret);
|
assert(ret);
|
||||||
assert(!!filename == (section_line > 0));
|
assert(!!filename == (section_line > 0));
|
||||||
|
|
||||||
|
if (filename) {
|
||||||
r = network_config_section_new(filename, section_line, &n);
|
r = network_config_section_new(filename, section_line, &n);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
@ -60,20 +49,26 @@ static int address_label_new_static(Network *network, const char *filename, unsi
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
r = address_label_new(&label);
|
label = new(AddressLabel, 1);
|
||||||
if (r < 0)
|
if (!label)
|
||||||
return r;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
*label = (AddressLabel) {
|
||||||
|
.network = network,
|
||||||
|
};
|
||||||
|
|
||||||
|
LIST_APPEND(labels, network->address_labels, label);
|
||||||
|
network->n_address_labels++;
|
||||||
|
|
||||||
|
if (filename) {
|
||||||
label->section = TAKE_PTR(n);
|
label->section = TAKE_PTR(n);
|
||||||
|
|
||||||
r = hashmap_put(network->address_labels_by_section, label->section, label);
|
r = hashmap_put(network->address_labels_by_section, label->section, label);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
}
|
||||||
label->network = network;
|
|
||||||
LIST_APPEND(labels, network->address_labels, label);
|
|
||||||
network->n_address_labels++;
|
|
||||||
|
|
||||||
*ret = TAKE_PTR(label);
|
*ret = TAKE_PTR(label);
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ struct AddressLabel {
|
||||||
LIST_FIELDS(AddressLabel, labels);
|
LIST_FIELDS(AddressLabel, labels);
|
||||||
};
|
};
|
||||||
|
|
||||||
int address_label_new(AddressLabel **ret);
|
|
||||||
void address_label_free(AddressLabel *label);
|
void address_label_free(AddressLabel *label);
|
||||||
|
|
||||||
DEFINE_TRIVIAL_CLEANUP_FUNC(AddressLabel*, address_label_free);
|
DEFINE_TRIVIAL_CLEANUP_FUNC(AddressLabel*, address_label_free);
|
||||||
|
|
|
@ -67,6 +67,10 @@ int address_new_static(Network *network, const char *filename, unsigned section_
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
address->network = network;
|
||||||
|
LIST_APPEND(addresses, network->static_addresses, address);
|
||||||
|
network->n_static_addresses++;
|
||||||
|
|
||||||
if (filename) {
|
if (filename) {
|
||||||
address->section = TAKE_PTR(n);
|
address->section = TAKE_PTR(n);
|
||||||
|
|
||||||
|
@ -75,10 +79,6 @@ int address_new_static(Network *network, const char *filename, unsigned section_
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
address->network = network;
|
|
||||||
LIST_APPEND(addresses, network->static_addresses, address);
|
|
||||||
network->n_static_addresses++;
|
|
||||||
|
|
||||||
*ret = TAKE_PTR(address);
|
*ret = TAKE_PTR(address);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -153,6 +153,10 @@ int prefix_new_static(Network *network, const char *filename,
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
prefix->network = network;
|
||||||
|
LIST_APPEND(prefixes, network->static_prefixes, prefix);
|
||||||
|
network->n_static_prefixes++;
|
||||||
|
|
||||||
if (filename) {
|
if (filename) {
|
||||||
prefix->section = TAKE_PTR(n);
|
prefix->section = TAKE_PTR(n);
|
||||||
|
|
||||||
|
@ -162,10 +166,6 @@ int prefix_new_static(Network *network, const char *filename,
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix->network = network;
|
|
||||||
LIST_APPEND(prefixes, network->static_prefixes, prefix);
|
|
||||||
network->n_static_prefixes++;
|
|
||||||
|
|
||||||
*ret = TAKE_PTR(prefix);
|
*ret = TAKE_PTR(prefix);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -95,6 +95,9 @@ int route_new_static(Network *network, const char *filename, unsigned section_li
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
route->protocol = RTPROT_STATIC;
|
route->protocol = RTPROT_STATIC;
|
||||||
|
route->network = network;
|
||||||
|
LIST_PREPEND(routes, network->static_routes, route);
|
||||||
|
network->n_static_routes++;
|
||||||
|
|
||||||
if (filename) {
|
if (filename) {
|
||||||
route->section = TAKE_PTR(n);
|
route->section = TAKE_PTR(n);
|
||||||
|
@ -104,10 +107,6 @@ int route_new_static(Network *network, const char *filename, unsigned section_li
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
route->network = network;
|
|
||||||
LIST_PREPEND(routes, network->static_routes, route);
|
|
||||||
network->n_static_routes++;
|
|
||||||
|
|
||||||
*ret = TAKE_PTR(route);
|
*ret = TAKE_PTR(route);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -40,11 +40,8 @@ void routing_policy_rule_free(RoutingPolicyRule *rule) {
|
||||||
assert(rule->network->n_rules > 0);
|
assert(rule->network->n_rules > 0);
|
||||||
rule->network->n_rules--;
|
rule->network->n_rules--;
|
||||||
|
|
||||||
if (rule->section) {
|
if (rule->section)
|
||||||
hashmap_remove(rule->network->rules_by_section, rule->section);
|
hashmap_remove(rule->network->rules_by_section, rule->section);
|
||||||
network_config_section_free(rule->section);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rule->manager) {
|
if (rule->manager) {
|
||||||
|
@ -52,6 +49,7 @@ void routing_policy_rule_free(RoutingPolicyRule *rule) {
|
||||||
set_remove(rule->manager->rules_foreign, rule);
|
set_remove(rule->manager->rules_foreign, rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
network_config_section_free(rule->section);
|
||||||
free(rule->iif);
|
free(rule->iif);
|
||||||
free(rule->oif);
|
free(rule->oif);
|
||||||
free(rule);
|
free(rule);
|
||||||
|
@ -390,6 +388,7 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
|
||||||
assert(ret);
|
assert(ret);
|
||||||
assert(!!filename == (section_line > 0));
|
assert(!!filename == (section_line > 0));
|
||||||
|
|
||||||
|
if (filename) {
|
||||||
r = network_config_section_new(filename, section_line, &n);
|
r = network_config_section_new(filename, section_line, &n);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
@ -400,20 +399,23 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
r = routing_policy_rule_new(&rule);
|
r = routing_policy_rule_new(&rule);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
rule->section = TAKE_PTR(n);
|
|
||||||
rule->network = network;
|
rule->network = network;
|
||||||
|
LIST_APPEND(rules, network->rules, rule);
|
||||||
|
network->n_rules++;
|
||||||
|
|
||||||
|
if (filename) {
|
||||||
|
rule->section = TAKE_PTR(n);
|
||||||
|
|
||||||
r = hashmap_put(network->rules_by_section, rule->section, rule);
|
r = hashmap_put(network->rules_by_section, rule->section, rule);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
}
|
||||||
LIST_APPEND(rules, network->rules, rule);
|
|
||||||
network->n_rules++;
|
|
||||||
|
|
||||||
*ret = TAKE_PTR(rule);
|
*ret = TAKE_PTR(rule);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue