summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-05-07 05:16:32 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-05-12 11:25:55 +0900
commite80509a90454e13ccad8bc7d2be40b1bb177a077 (patch)
tree22c067e732814c5da3c60c3f557e1a3df01ac20a /src
parentc0bd9eb1ed42cb0981f1c5a77c0f045bd326d350 (diff)
downloadsystemd-e80509a90454e13ccad8bc7d2be40b1bb177a077.tar.gz
network: simplify and rename routing_policy_rule_copy()
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-routing-policy-rule.c58
1 files changed, 20 insertions, 38 deletions
diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c
index 18b86fc2d9..6a0e21d9f0 100644
--- a/src/network/networkd-routing-policy-rule.c
+++ b/src/network/networkd-routing-policy-rule.c
@@ -109,45 +109,35 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
return 0;
}
-static int routing_policy_rule_copy(RoutingPolicyRule *dest, const RoutingPolicyRule *src) {
- _cleanup_free_ char *iif = NULL, *oif = NULL;
+static int routing_policy_rule_dup(const RoutingPolicyRule *src, RoutingPolicyRule **ret) {
+ _cleanup_(routing_policy_rule_freep) RoutingPolicyRule *dest = NULL;
- assert(dest);
assert(src);
+ assert(ret);
+
+ dest = newdup(RoutingPolicyRule, src, 1);
+ if (!dest)
+ return -ENOMEM;
+
+ /* Unset all pointers */
+ dest->manager = NULL;
+ dest->network = NULL;
+ dest->section = NULL;
+ dest->iif = dest->oif = NULL;
if (src->iif) {
- iif = strdup(src->iif);
- if (!iif)
+ dest->iif = strdup(src->iif);
+ if (!dest->iif)
return -ENOMEM;
}
if (src->oif) {
- oif = strdup(src->oif);
- if (!oif)
+ dest->oif = strdup(src->oif);
+ if (!dest->oif)
return -ENOMEM;
}
- dest->family = src->family;
- dest->from = src->from;
- dest->from_prefixlen = src->from_prefixlen;
- dest->to = src->to;
- dest->to_prefixlen = src->to_prefixlen;
- dest->invert_rule = src->invert_rule;
- dest->tos = src->tos;
- dest->type = src->type;
- dest->fwmark = src->fwmark;
- dest->fwmask = src->fwmask;
- dest->priority = src->priority;
- dest->table = src->table;
- dest->iif = TAKE_PTR(iif);
- dest->oif = TAKE_PTR(oif);
- dest->ipproto = src->ipproto;
- dest->protocol = src->protocol;
- dest->sport = src->sport;
- dest->dport = src->dport;
- dest->uid_range = src->uid_range;
- dest->suppress_prefixlen = src->suppress_prefixlen;
-
+ *ret = TAKE_PTR(dest);
return 0;
}
@@ -334,11 +324,7 @@ static int routing_policy_rule_add(Manager *m, const RoutingPolicyRule *in, int
assert(IN_SET(family, AF_INET, AF_INET6));
assert(in->family == AF_UNSPEC || in->family == family);
- r = routing_policy_rule_new(&rule);
- if (r < 0)
- return r;
-
- r = routing_policy_rule_copy(rule, in);
+ r = routing_policy_rule_dup(in, &rule);
if (r < 0)
return r;
@@ -641,11 +627,7 @@ static int links_have_routing_policy_rule(const Manager *m, const RoutingPolicyR
/* The case Family=both. */
_cleanup_(routing_policy_rule_freep) RoutingPolicyRule *tmp = NULL;
- r = routing_policy_rule_new(&tmp);
- if (r < 0)
- return r;
-
- r = routing_policy_rule_copy(tmp, link_rule);
+ r = routing_policy_rule_dup(link_rule, &tmp);
if (r < 0)
return r;