summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-address-label.c51
-rw-r--r--src/network/networkd-address-label.h1
-rw-r--r--src/network/networkd-address.c8
-rw-r--r--src/network/networkd-radv.c8
-rw-r--r--src/network/networkd-route.c7
-rw-r--r--src/network/networkd-routing-policy-rule.c36
6 files changed, 53 insertions, 58 deletions
diff --git a/src/network/networkd-address-label.c b/src/network/networkd-address-label.c
index 98e40d3f6a..1392cba538 100644
--- a/src/network/networkd-address-label.c
+++ b/src/network/networkd-address-label.c
@@ -11,18 +11,6 @@
#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;
@@ -50,31 +38,38 @@ static int address_label_new_static(Network *network, const char *filename, unsi
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;
diff --git a/src/network/networkd-address-label.h b/src/network/networkd-address-label.h
index 2e55feabd0..da506b2de4 100644
--- a/src/network/networkd-address-label.h
+++ b/src/network/networkd-address-label.h
@@ -28,7 +28,6 @@ struct AddressLabel {
LIST_FIELDS(AddressLabel, labels);
};
-int address_label_new(AddressLabel **ret);
void address_label_free(AddressLabel *label);
DEFINE_TRIVIAL_CLEANUP_FUNC(AddressLabel*, address_label_free);
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 66e00493d6..d028f7226e 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -67,6 +67,10 @@ int address_new_static(Network *network, const char *filename, unsigned section_
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);
@@ -75,10 +79,6 @@ int address_new_static(Network *network, const char *filename, unsigned section_
return r;
}
- address->network = network;
- LIST_APPEND(addresses, network->static_addresses, address);
- network->n_static_addresses++;
-
*ret = TAKE_PTR(address);
return 0;
diff --git a/src/network/networkd-radv.c b/src/network/networkd-radv.c
index 600fb27d75..d893c1e5d5 100644
--- a/src/network/networkd-radv.c
+++ b/src/network/networkd-radv.c
@@ -153,6 +153,10 @@ int prefix_new_static(Network *network, const char *filename,
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);
@@ -162,10 +166,6 @@ int prefix_new_static(Network *network, const char *filename,
return r;
}
- prefix->network = network;
- LIST_APPEND(prefixes, network->static_prefixes, prefix);
- network->n_static_prefixes++;
-
*ret = TAKE_PTR(prefix);
return 0;
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index 63126b4d13..1e16e4a392 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -95,6 +95,9 @@ int route_new_static(Network *network, const char *filename, unsigned section_li
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);
@@ -104,10 +107,6 @@ int route_new_static(Network *network, const char *filename, unsigned section_li
return r;
}
- route->network = network;
- LIST_PREPEND(routes, network->static_routes, route);
- network->n_static_routes++;
-
*ret = TAKE_PTR(route);
return 0;
diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c
index 739f9e6a5a..4750073d28 100644
--- a/src/network/networkd-routing-policy-rule.c
+++ b/src/network/networkd-routing-policy-rule.c
@@ -40,11 +40,8 @@ void routing_policy_rule_free(RoutingPolicyRule *rule) {
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) {
@@ -52,6 +49,7 @@ void routing_policy_rule_free(RoutingPolicyRule *rule) {
set_remove(rule->manager->rules_foreign, rule);
}
+ network_config_section_free(rule->section);
free(rule->iif);
free(rule->oif);
free(rule);
@@ -390,31 +388,35 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
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;