return 0;
}
-static int routing_policy_rule_read_full_file(const char *state_file, char **ret) {
+static int routing_policy_rule_read_full_file(const char *state_file, char ***ret) {
+ _cleanup_strv_free_ char **lines = NULL;
_cleanup_free_ char *s = NULL;
- size_t size;
int r;
assert(state_file);
- r = read_full_file(state_file, &s, &size);
- if (r == -ENOENT)
- return -ENODATA;
+ r = read_full_file(state_file, &s, NULL);
+ if (r == -ENOENT) {
+ *ret = NULL;
+ return 0;
+ }
if (r < 0)
return r;
- if (size <= 0)
- return -ENODATA;
- *ret = TAKE_PTR(s);
+ lines = strv_split_newlines(s);
+ if (!lines)
+ return -ENOMEM;
- return size;
+ *ret = TAKE_PTR(lines);
+ return 0;
}
int routing_policy_load_rules(const char *state_file, Set **rules) {
- _cleanup_strv_free_ char **l = NULL;
- _cleanup_free_ char *data = NULL;
- uint16_t low = 0, high = 0;
- const char *p;
+ _cleanup_strv_free_ char **data = NULL;
char **i;
int r;
assert(rules);
r = routing_policy_rule_read_full_file(state_file, &data);
- if (r <= 0)
- return r;
-
- l = strv_split_newlines(data);
- if (!l)
- return -ENOMEM;
+ if (r < 0)
+ return log_warning_errno(r, "Failed to read %s, ignoring: %m", state_file);
- STRV_FOREACH(i, l) {
+ STRV_FOREACH(i, data) {
_cleanup_(routing_policy_rule_freep) RoutingPolicyRule *rule = NULL;
+ const char *p;
p = startswith(*i, "RULE=");
if (!p)
r = routing_policy_rule_new(&rule);
if (r < 0)
- return r;
+ return log_oom();
for (;;) {
_cleanup_free_ char *a = NULL;
r = extract_first_word(&p, &a, NULL, 0);
if (r < 0)
- return r;
+ return log_oom();
if (r == 0)
break;
continue;
}
} else if (streq(a, "sourceport")) {
+ uint16_t low, high;
+
r = parse_ip_port_range(b, &low, &high);
if (r < 0) {
log_warning_errno(r, "Invalid routing policy rule source port range, ignoring assignment: '%s'", b);
rule->sport.start = low;
rule->sport.end = high;
} else if (streq(a, "destinationport")) {
+ uint16_t low, high;
+
r = parse_ip_port_range(b, &low, &high);
if (r < 0) {
log_warning_errno(r, "Invalid routing policy rule destination port range, ignoring assignment: '%s'", b);
r = set_ensure_put(rules, &routing_policy_rule_hash_ops, rule);
if (r < 0) {
- log_warning_errno(r, "Failed to add RPDB rule to saved DB, ignoring: %s", p);
+ log_warning_errno(r, "Failed to add RPDB rule to saved DB, ignoring: %s", *i);
continue;
}
if (r > 0)