No functional change.
static int manager_save(Manager *m) {
_cleanup_ordered_set_free_free_ OrderedSet *dns = NULL, *ntp = NULL, *search_domains = NULL, *route_domains = NULL;
- RoutingPolicyRule *rule = NULL;
Link *link;
Iterator i;
_cleanup_free_ char *temp_path = NULL;
print_string_set(f, "DOMAINS=", search_domains);
print_string_set(f, "ROUTE_DOMAINS=", route_domains);
- SET_FOREACH(rule, m->rules, i) {
- _cleanup_free_ char *from_str = NULL, *to_str = NULL;
- bool space = false;
-
- fputs("RULE=", f);
-
- if (!in_addr_is_null(rule->family, &rule->from)) {
- r = in_addr_to_string(rule->family, &rule->from, &from_str);
- if (r < 0)
- goto fail;
-
- fprintf(f, "from=%s/%hhu",
- from_str, rule->from_prefixlen);
- space = true;
- }
-
- if (!in_addr_is_null(rule->family, &rule->to)) {
- r = in_addr_to_string(rule->family, &rule->to, &to_str);
- if (r < 0)
- goto fail;
-
- fprintf(f, "%sto=%s/%hhu",
- space ? " " : "",
- to_str, rule->to_prefixlen);
- space = true;
- }
-
- if (rule->tos != 0) {
- fprintf(f, "%stos=%hhu",
- space ? " " : "",
- rule->tos);
- space = true;
- }
-
- if (rule->fwmark != 0) {
- fprintf(f, "%sfwmark=%"PRIu32"/%"PRIu32,
- space ? " " : "",
- rule->fwmark, rule->fwmask);
- space = true;
- }
-
- fprintf(f, "%stable=%"PRIu32 "\n",
- space ? " " : "",
- rule->table);
- }
+ r = routing_policy_serialize_rules(m->rules, f);
+ if (r < 0)
+ goto fail;
r = fflush_and_check(f);
if (r < 0)
m->duid.type = DUID_TYPE_EN;
- (void) routing_policy_rule_load(m);
+ (void) routing_policy_load_rules(m->state_file, &m->rules_saved);
*ret = m;
m = NULL;
return 0;
}
-static int routing_policy_rule_read_full_file(char *state_file, char **ret) {
+static int routing_policy_rule_read_full_file(const char *state_file, char **ret) {
_cleanup_free_ char *s = NULL;
size_t size;
int r;
return size;
}
-int routing_policy_rule_load(Manager *m) {
+int routing_policy_serialize_rules(Set *rules, FILE *f) {
+ RoutingPolicyRule *rule = NULL;
+ Iterator i;
+ int r;
+
+ assert(f);
+
+ SET_FOREACH(rule, rules, i) {
+ _cleanup_free_ char *from_str = NULL, *to_str = NULL;
+ bool space = false;
+
+ fputs("RULE=", f);
+
+ if (!in_addr_is_null(rule->family, &rule->from)) {
+ r = in_addr_to_string(rule->family, &rule->from, &from_str);
+ if (r < 0)
+ return r;
+
+ fprintf(f, "from=%s/%hhu",
+ from_str, rule->from_prefixlen);
+ space = true;
+ }
+
+ if (!in_addr_is_null(rule->family, &rule->to)) {
+ r = in_addr_to_string(rule->family, &rule->to, &to_str);
+ if (r < 0)
+ return r;
+
+ fprintf(f, "%sto=%s/%hhu",
+ space ? " " : "",
+ to_str, rule->to_prefixlen);
+ space = true;
+ }
+
+ if (rule->tos != 0) {
+ fprintf(f, "%stos=%hhu",
+ space ? " " : "",
+ rule->tos);
+ space = true;
+ }
+
+ if (rule->fwmark != 0) {
+ fprintf(f, "%sfwmark=%"PRIu32"/%"PRIu32,
+ space ? " " : "",
+ rule->fwmark, rule->fwmask);
+ space = true;
+ }
+
+ fprintf(f, "%stable=%"PRIu32 "\n",
+ space ? " " : "",
+ rule->table);
+ }
+
+ return 0;
+}
+
+int routing_policy_load_rules(const char *state_file, Set **rules) {
_cleanup_strv_free_ char **l = NULL;
_cleanup_free_ char *data = NULL;
const char *p;
char **i;
int r;
- assert(m);
+ assert(state_file);
+ assert(rules);
- r = routing_policy_rule_read_full_file(m->state_file, &data);
+ r = routing_policy_rule_read_full_file(state_file, &data);
if (r <= 0)
return r;
if (!l)
return -ENOMEM;
- r = set_ensure_allocated(&m->rules_saved, &routing_policy_rule_hash_ops);
+ r = set_ensure_allocated(rules, &routing_policy_rule_hash_ops);
if (r < 0)
return r;
}
}
- r = set_put(m->rules_saved, rule);
+ r = set_put(*rules, rule);
if (r < 0) {
log_warning_errno(r, "Failed to add RPDB rule to saved DB, ignoring: %s", p);
continue;
int routing_policy_rule_get(Manager *m, int family, const union in_addr_union *from, uint8_t from_prefixlen, const union in_addr_union *to, uint8_t to_prefixlen, uint8_t tos,
uint32_t fwmark, uint32_t table, char *iif, char *oif, RoutingPolicyRule **ret);
int routing_policy_rule_make_local(Manager *m, RoutingPolicyRule *rule);
-int routing_policy_rule_load(Manager *m);
+int routing_policy_serialize_rules(Set *rules, FILE *f);
+int routing_policy_load_rules(const char *state_file, Set **rules);
void routing_policy_rule_purge(Manager *m, Link *link);
int config_parse_routing_policy_rule_tos(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data,void *userdata);