summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-08-24 22:09:55 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-08-24 23:16:29 +0200
commit78ff6156d18d5a88353854ca4ebe90d141b53282 (patch)
treee295578832528baa8163fa7d8e68859c77344658 /src
parentnetwork/routing-policy-rule: rename n -> rule (diff)
downloadsystemd-78ff6156d18d5a88353854ca4ebe90d141b53282.tar.xz
systemd-78ff6156d18d5a88353854ca4ebe90d141b53282.zip
network/routing-policy-rule: trivial cleanups for conf-parsers
No functional change, just refactoring.
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-routing-policy-rule.c67
1 files changed, 29 insertions, 38 deletions
diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c
index 046fd0f49e..2f9d95ffa5 100644
--- a/src/network/networkd-routing-policy-rule.c
+++ b/src/network/networkd-routing-policy-rule.c
@@ -1563,22 +1563,20 @@ int config_parse_routing_policy_rule_prefix(
int r;
assert(filename);
- assert(section);
- assert(lvalue);
assert(rvalue);
- assert(data);
r = routing_policy_rule_new_static(network, filename, section_line, &rule);
if (r < 0)
return log_oom();
- if (streq(lvalue, "To")) {
+ if (streq_ptr(lvalue, "To")) {
buffer = &rule->to;
prefixlen = &rule->to_prefixlen;
- } else {
+ } else if (streq_ptr(lvalue, "From")) {
buffer = &rule->from;
prefixlen = &rule->from_prefixlen;
- }
+ } else
+ assert_not_reached();
if (rule->family == AF_UNSPEC)
r = in_addr_prefix_from_string_auto(rvalue, &rule->family, buffer, prefixlen);
@@ -1590,7 +1588,7 @@ int config_parse_routing_policy_rule_prefix(
}
TAKE_PTR(rule);
- return 0;
+ return 1;
}
int config_parse_routing_policy_rule_device(
@@ -1647,35 +1645,31 @@ int config_parse_routing_policy_rule_port_range(
_cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL;
Network *network = userdata;
- uint16_t low, high;
+ struct fib_rule_port_range *p;
int r;
assert(filename);
- assert(section);
- assert(lvalue);
assert(rvalue);
- assert(data);
r = routing_policy_rule_new_static(network, filename, section_line, &rule);
if (r < 0)
return log_oom();
- r = parse_ip_port_range(rvalue, &low, &high, /* allow_zero = */ false);
+ if (streq_ptr(lvalue, "SourcePort"))
+ p = &rule->sport;
+ else if (streq_ptr(lvalue, "DestinationPort"))
+ p = &rule->dport;
+ else
+ assert_not_reached();
+
+ r = parse_ip_port_range(rvalue, &p->start, &p->end, /* allow_zero = */ false);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse routing policy rule port range '%s'", rvalue);
return 0;
}
- if (streq(lvalue, "SourcePort")) {
- rule->sport.start = low;
- rule->sport.end = high;
- } else {
- rule->dport.start = low;
- rule->dport.end = high;
- }
-
TAKE_PTR(rule);
- return 0;
+ return 1;
}
int config_parse_routing_policy_rule_ip_protocol(
@@ -1846,36 +1840,33 @@ int config_parse_routing_policy_rule_uid_range(
_cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL;
Network *network = userdata;
- uid_t start, end;
+ struct fib_rule_uid_range *p;
int r;
assert(filename);
- assert(section);
- assert(lvalue);
assert(rvalue);
- assert(data);
r = routing_policy_rule_new_static(network, filename, section_line, &rule);
if (r < 0)
return log_oom();
- r = get_user_creds(&rvalue, &start, NULL, NULL, NULL, 0);
- if (r >= 0)
- end = start;
- else {
- r = parse_uid_range(rvalue, &start, &end);
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r,
- "Invalid uid or uid range '%s', ignoring: %m", rvalue);
- return 0;
- }
+ p = &rule->uid_range;
+
+ if (get_user_creds(&rvalue, &p->start, NULL, NULL, NULL, 0) >= 0) {
+ p->end = p->start;
+ TAKE_PTR(rule);
+ return 1;
}
- rule->uid_range.start = start;
- rule->uid_range.end = end;
+ r = parse_uid_range(rvalue, &p->start, &p->end);
+ if (r < 0) {
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "Invalid uid or uid range '%s', ignoring: %m", rvalue);
+ return 0;
+ }
TAKE_PTR(rule);
- return 0;
+ return 1;
}
int config_parse_routing_policy_rule_suppress_prefixlen(