#include "parse-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) {
if (!label)
return;
assert(ret);
assert(!!filename == (section_line > 0));
- r = network_config_section_new(filename, section_line, &n);
- if (r < 0)
- return r;
+ if (filename) {
+ r = network_config_section_new(filename, section_line, &n);
+ if (r < 0)
+ return r;
- label = hashmap_get(network->address_labels_by_section, n);
- if (label) {
- *ret = TAKE_PTR(label);
+ label = hashmap_get(network->address_labels_by_section, n);
+ if (label) {
+ *ret = TAKE_PTR(label);
- return 0;
+ return 0;
+ }
}
- r = address_label_new(&label);
- if (r < 0)
- return r;
-
- label->section = TAKE_PTR(n);
+ label = new(AddressLabel, 1);
+ if (!label)
+ return -ENOMEM;
- r = hashmap_put(network->address_labels_by_section, label->section, label);
- if (r < 0)
- return r;
+ *label = (AddressLabel) {
+ .network = network,
+ };
- label->network = network;
LIST_APPEND(labels, network->address_labels, label);
network->n_address_labels++;
+ if (filename) {
+ label->section = TAKE_PTR(n);
+
+ r = hashmap_put(network->address_labels_by_section, label->section, label);
+ if (r < 0)
+ return r;
+ }
+
*ret = TAKE_PTR(label);
return 0;
LIST_FIELDS(AddressLabel, labels);
};
-int address_label_new(AddressLabel **ret);
void address_label_free(AddressLabel *label);
DEFINE_TRIVIAL_CLEANUP_FUNC(AddressLabel*, address_label_free);
if (r < 0)
return r;
+ address->network = network;
+ LIST_APPEND(addresses, network->static_addresses, address);
+ network->n_static_addresses++;
+
if (filename) {
address->section = TAKE_PTR(n);
return r;
}
- address->network = network;
- LIST_APPEND(addresses, network->static_addresses, address);
- network->n_static_addresses++;
-
*ret = TAKE_PTR(address);
return 0;
if (r < 0)
return r;
+ prefix->network = network;
+ LIST_APPEND(prefixes, network->static_prefixes, prefix);
+ network->n_static_prefixes++;
+
if (filename) {
prefix->section = TAKE_PTR(n);
return r;
}
- prefix->network = network;
- LIST_APPEND(prefixes, network->static_prefixes, prefix);
- network->n_static_prefixes++;
-
*ret = TAKE_PTR(prefix);
return 0;
return r;
route->protocol = RTPROT_STATIC;
+ route->network = network;
+ LIST_PREPEND(routes, network->static_routes, route);
+ network->n_static_routes++;
if (filename) {
route->section = TAKE_PTR(n);
return r;
}
- route->network = network;
- LIST_PREPEND(routes, network->static_routes, route);
- network->n_static_routes++;
-
*ret = TAKE_PTR(route);
return 0;
assert(rule->network->n_rules > 0);
rule->network->n_rules--;
- if (rule->section) {
+ if (rule->section)
hashmap_remove(rule->network->rules_by_section, rule->section);
- network_config_section_free(rule->section);
- }
-
}
if (rule->manager) {
set_remove(rule->manager->rules_foreign, rule);
}
+ network_config_section_free(rule->section);
free(rule->iif);
free(rule->oif);
free(rule);
assert(ret);
assert(!!filename == (section_line > 0));
- r = network_config_section_new(filename, section_line, &n);
- if (r < 0)
- return r;
+ if (filename) {
+ r = network_config_section_new(filename, section_line, &n);
+ if (r < 0)
+ return r;
- rule = hashmap_get(network->rules_by_section, n);
- if (rule) {
- *ret = TAKE_PTR(rule);
+ rule = hashmap_get(network->rules_by_section, n);
+ if (rule) {
+ *ret = TAKE_PTR(rule);
- return 0;
+ return 0;
+ }
}
r = routing_policy_rule_new(&rule);
if (r < 0)
return r;
- rule->section = TAKE_PTR(n);
rule->network = network;
-
- r = hashmap_put(network->rules_by_section, rule->section, rule);
- if (r < 0)
- return r;
-
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);
+ if (r < 0)
+ return r;
+ }
+
*ret = TAKE_PTR(rule);
return 0;