[RoutingPolicyRule] sections are managed by both LIST and Hashmap.
Let's drop list.
#include "networkd-manager-bus.h"
#include "networkd-manager.h"
#include "networkd-network-bus.h"
+#include "networkd-routing-policy-rule.h"
#include "networkd-speed-meter.h"
#include "ordered-set.h"
#include "path-lookup.h"
#include "networkd-ipv4ll.h"
#include "networkd-ndisc.h"
#include "networkd-network.h"
+#include "networkd-routing-policy-rule.h"
#include "networkd-sriov.h"
#include "qdisc.h"
#include "tclass.h"
#include "network-internal.h"
#include "networkd-manager.h"
#include "networkd-network.h"
+#include "networkd-routing-policy-rule.h"
#include "networkd-sriov.h"
#include "parse-util.h"
#include "path-lookup.h"
int network_verify(Network *network) {
RoutePrefix *route_prefix, *route_prefix_next;
- RoutingPolicyRule *rule, *rule_next;
+ RoutingPolicyRule *rule;
Neighbor *neighbor, *neighbor_next;
AddressLabel *label, *label_next;
NextHop *nexthop, *nextnop_next;
if (section_is_invalid(route_prefix->section))
route_prefix_free(route_prefix);
- LIST_FOREACH_SAFE(rules, rule, rule_next, network->rules)
+ HASHMAP_FOREACH(rule, network->rules_by_section)
if (routing_policy_rule_section_verify(rule) < 0)
routing_policy_rule_free(rule);
static Network *network_free(Network *network) {
IPv6ProxyNDPAddress *ipv6_proxy_ndp_address;
RoutePrefix *route_prefix;
- RoutingPolicyRule *rule;
AddressLabel *label;
FdbEntry *fdb_entry;
MdbEntry *mdb_entry;
while ((route_prefix = network->static_route_prefixes))
route_prefix_free(route_prefix);
- while ((rule = network->rules))
- routing_policy_rule_free(rule);
-
hashmap_free(network->addresses_by_section);
hashmap_free(network->routes_by_section);
hashmap_free(network->nexthops_by_section);
hashmap_free(network->address_labels_by_section);
hashmap_free(network->prefixes_by_section);
hashmap_free(network->route_prefixes_by_section);
- hashmap_free(network->rules_by_section);
+ hashmap_free_with_destructor(network->rules_by_section, routing_policy_rule_free);
ordered_hashmap_free_with_destructor(network->sr_iov_by_section, sr_iov_free);
ordered_hashmap_free_with_destructor(network->tc_by_section, traffic_control_free);
#include "networkd-nexthop.h"
#include "networkd-radv.h"
#include "networkd-route.h"
-#include "networkd-routing-policy-rule.h"
#include "networkd-util.h"
#include "ordered-set.h"
#include "resolve-util.h"
LIST_HEAD(AddressLabel, address_labels);
LIST_HEAD(Prefix, static_prefixes);
LIST_HEAD(RoutePrefix, static_route_prefixes);
- LIST_HEAD(RoutingPolicyRule, rules);
unsigned n_static_addresses;
unsigned n_static_routes;
unsigned n_address_labels;
unsigned n_static_prefixes;
unsigned n_static_route_prefixes;
- unsigned n_rules;
Hashmap *addresses_by_section;
Hashmap *routes_by_section;
#include "fileio.h"
#include "format-util.h"
#include "ip-protocol-list.h"
-#include "networkd-routing-policy-rule.h"
#include "netlink-util.h"
#include "networkd-manager.h"
+#include "networkd-routing-policy-rule.h"
#include "networkd-util.h"
#include "parse-util.h"
#include "socket-util.h"
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;
+ assert(filename);
+ assert(section_line > 0);
- rule = hashmap_get(network->rules_by_section, n);
- if (rule) {
- *ret = TAKE_PTR(rule);
+ r = network_config_section_new(filename, section_line, &n);
+ if (r < 0)
+ return r;
- return 0;
- }
+ rule = hashmap_get(network->rules_by_section, n);
+ if (rule) {
+ *ret = TAKE_PTR(rule);
+ return 0;
}
r = routing_policy_rule_new(&rule);
return r;
rule->network = network;
- LIST_APPEND(rules, network->rules, rule);
- network->n_rules++;
-
- if (filename) {
- rule->section = TAKE_PTR(n);
+ rule->section = TAKE_PTR(n);
- r = hashmap_ensure_allocated(&network->rules_by_section, &network_config_hash_ops);
- if (r < 0)
- return r;
+ r = hashmap_ensure_allocated(&network->rules_by_section, &network_config_hash_ops);
+ if (r < 0)
+ return r;
- r = hashmap_put(network->rules_by_section, rule->section, rule);
- if (r < 0)
- return r;
- }
+ r = hashmap_put(network->rules_by_section, rule->section, rule);
+ if (r < 0)
+ return r;
*ret = TAKE_PTR(rule);
-
return 0;
}
return NULL;
if (rule->network) {
- LIST_REMOVE(rules, rule->network->rules, rule);
- assert(rule->network->n_rules > 0);
- rule->network->n_rules--;
-
- if (rule->section)
- hashmap_remove(rule->network->rules_by_section, rule->section);
+ assert(rule->section);
+ hashmap_remove(rule->network->rules_by_section, rule->section);
}
if (rule->manager) {
}
static bool manager_links_have_routing_policy_rule(Manager *m, RoutingPolicyRule *rule) {
- RoutingPolicyRule *link_rule;
Link *link;
assert(m);
assert(rule);
HASHMAP_FOREACH(link, m->links) {
+ RoutingPolicyRule *link_rule;
+
if (!link->network)
continue;
- LIST_FOREACH(rules, link_rule, link->network->rules)
+ HASHMAP_FOREACH(link_rule, link->network->rules_by_section)
if (routing_policy_rule_compare_func(link_rule, rule) == 0)
return true;
}
link->routing_policy_rules_configured = false;
- LIST_FOREACH(rules, rule, link->network->rules) {
+ HASHMAP_FOREACH(rule, link->network->rules_by_section) {
RoutingPolicyRule *existing;
r = routing_policy_rule_get(link->manager, rule, &existing);
#pragma once
#include <inttypes.h>
-#include <netinet/in.h>
#include <linux/fib_rules.h>
#include <stdbool.h>
+#include <stdio.h>
-#include "in-addr-util.h"
#include "conf-parser.h"
-
-typedef struct RoutingPolicyRule RoutingPolicyRule;
-
-#include "networkd-link.h"
-#include "networkd-network.h"
+#include "in-addr-util.h"
#include "networkd-util.h"
+#include "set.h"
typedef struct Network Network;
typedef struct Link Link;
-typedef struct NetworkConfigSection NetworkConfigSection;
typedef struct Manager Manager;
-struct RoutingPolicyRule {
+typedef struct RoutingPolicyRule {
Manager *manager;
Network *network;
Link *link;
struct fib_rule_uid_range uid_range;
int suppress_prefixlen;
-
- LIST_FIELDS(RoutingPolicyRule, rules);
-};
+} RoutingPolicyRule;
int routing_policy_rule_new(RoutingPolicyRule **ret);
RoutingPolicyRule *routing_policy_rule_free(RoutingPolicyRule *rule);
-/***
- SPDX-License-Identifier: LGPL-2.1+
-***/
+/* SPDX-License-Identifier: LGPL-2.1+ */
#include "fd-util.h"
#include "fileio.h"
-#include "log.h"
-#include "macro.h"
-#include "network-internal.h"
-#include "networkd-manager.h"
+#include "networkd-routing-policy-rule.h"
#include "string-util.h"
#include "tests.h"
#include "tmpfile-util.h"