int route_new_static(Network *network, const char *filename, unsigned section_line, Route **ret) { _cleanup_network_config_section_free_ NetworkConfigSection *n = NULL; _cleanup_route_free_ Route *route = NULL; int r; assert(network); assert(ret); assert(!!filename == (section_line > 0)); if (filename) { r = network_config_section_new(filename, section_line, &n); if (r < 0) return r; route = hashmap_get(network->routes_by_section, n); if (route) { *ret = route; route = NULL; return 0; } } if (network->n_static_routes >= routes_max()) return -E2BIG; r = route_new(&route); if (r < 0) return r; route->protocol = RTPROT_STATIC; if (filename) { route->section = n; n = NULL; r = hashmap_put(network->routes_by_section, route->section, route); if (r < 0) return r; } route->network = network; LIST_PREPEND(routes, network->static_routes, route); network->n_static_routes++; *ret = route; route = NULL; return 0; }
static int prefix_new_static(Network *network, const char *filename, unsigned section_line, Prefix **ret) { _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL; _cleanup_(prefix_freep) Prefix *prefix = NULL; int r; assert(network); assert(ret); assert(!!filename == (section_line > 0)); if (filename) { r = network_config_section_new(filename, section_line, &n); if (r < 0) return r; if (section_line) { prefix = hashmap_get(network->prefixes_by_section, n); if (prefix) { *ret = TAKE_PTR(prefix); return 0; } } } r = prefix_new(&prefix); 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); r = hashmap_ensure_allocated(&network->prefixes_by_section, &network_config_hash_ops); if (r < 0) return r; r = hashmap_put(network->prefixes_by_section, prefix->section, prefix); if (r < 0) return r; } *ret = TAKE_PTR(prefix); return 0; }
int prefix_new_static(Network *network, const char *filename, unsigned section_line, Prefix **ret) { _cleanup_network_config_section_free_ NetworkConfigSection *n = NULL; _cleanup_prefix_free_ Prefix *prefix = NULL; int r; assert(network); assert(ret); assert(!!filename == (section_line > 0)); if (filename) { r = network_config_section_new(filename, section_line, &n); if (r < 0) return r; if (section_line) { prefix = hashmap_get(network->prefixes_by_section, n); if (prefix) { *ret = prefix; prefix = NULL; return 0; } } } r = prefix_new(&prefix); if (r < 0) return r; if (filename) { prefix->section = n; n = NULL; r = hashmap_put(network->prefixes_by_section, prefix->section, prefix); if (r < 0) return r; } prefix->network = network; LIST_APPEND(prefixes, network->static_prefixes, prefix); network->n_static_prefixes++; *ret = prefix; prefix = NULL; return 0; }
static int address_label_new_static(Network *network, const char *filename, unsigned section_line, AddressLabel **ret) { _cleanup_network_config_section_free_ NetworkConfigSection *n = NULL; _cleanup_address_label_free_ AddressLabel *label = NULL; int r; assert(network); assert(ret); assert(!!filename == (section_line > 0)); 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 = label; label = NULL; return 0; } r = address_label_new(&label); if (r < 0) return r; label->section = n; n = NULL; r = hashmap_put(network->address_labels_by_section, label->section, label); if (r < 0) return r; label->network = network; LIST_APPEND(labels, network->address_labels, label); network->n_address_labels++; *ret = label; label = NULL; return 0; }
static int routing_policy_rule_new_static(Network *network, const char *filename, unsigned section_line, RoutingPolicyRule **ret) { _cleanup_routing_policy_rule_free_ RoutingPolicyRule *rule = NULL; _cleanup_network_config_section_free_ NetworkConfigSection *n = NULL; int r; assert(network); assert(ret); assert(!!filename == (section_line > 0)); 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); return 0; } r = routing_policy_rule_new(&rule); if (r < 0) return r; rule->section = n; rule->network = network; n = NULL; r = hashmap_put(network->rules_by_section, rule->section, rule); if (r < 0) return r; LIST_APPEND(rules, network->rules, rule); network->n_rules++; *ret = TAKE_PTR(rule); return 0; }