network: drop list of static routing policy rules
[RoutingPolicyRule] sections are managed by both LIST and Hashmap. Let's drop list.
This commit is contained in:
parent
02e9f4e536
commit
ca183bf8fd
|
@ -30,6 +30,7 @@
|
||||||
#include "networkd-manager-bus.h"
|
#include "networkd-manager-bus.h"
|
||||||
#include "networkd-manager.h"
|
#include "networkd-manager.h"
|
||||||
#include "networkd-network-bus.h"
|
#include "networkd-network-bus.h"
|
||||||
|
#include "networkd-routing-policy-rule.h"
|
||||||
#include "networkd-speed-meter.h"
|
#include "networkd-speed-meter.h"
|
||||||
#include "ordered-set.h"
|
#include "ordered-set.h"
|
||||||
#include "path-lookup.h"
|
#include "path-lookup.h"
|
||||||
|
|
|
@ -15,6 +15,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
|
||||||
#include "networkd-ipv4ll.h"
|
#include "networkd-ipv4ll.h"
|
||||||
#include "networkd-ndisc.h"
|
#include "networkd-ndisc.h"
|
||||||
#include "networkd-network.h"
|
#include "networkd-network.h"
|
||||||
|
#include "networkd-routing-policy-rule.h"
|
||||||
#include "networkd-sriov.h"
|
#include "networkd-sriov.h"
|
||||||
#include "qdisc.h"
|
#include "qdisc.h"
|
||||||
#include "tclass.h"
|
#include "tclass.h"
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "network-internal.h"
|
#include "network-internal.h"
|
||||||
#include "networkd-manager.h"
|
#include "networkd-manager.h"
|
||||||
#include "networkd-network.h"
|
#include "networkd-network.h"
|
||||||
|
#include "networkd-routing-policy-rule.h"
|
||||||
#include "networkd-sriov.h"
|
#include "networkd-sriov.h"
|
||||||
#include "parse-util.h"
|
#include "parse-util.h"
|
||||||
#include "path-lookup.h"
|
#include "path-lookup.h"
|
||||||
|
@ -149,7 +150,7 @@ static int network_resolve_stacked_netdevs(Network *network) {
|
||||||
|
|
||||||
int network_verify(Network *network) {
|
int network_verify(Network *network) {
|
||||||
RoutePrefix *route_prefix, *route_prefix_next;
|
RoutePrefix *route_prefix, *route_prefix_next;
|
||||||
RoutingPolicyRule *rule, *rule_next;
|
RoutingPolicyRule *rule;
|
||||||
Neighbor *neighbor, *neighbor_next;
|
Neighbor *neighbor, *neighbor_next;
|
||||||
AddressLabel *label, *label_next;
|
AddressLabel *label, *label_next;
|
||||||
NextHop *nexthop, *nextnop_next;
|
NextHop *nexthop, *nextnop_next;
|
||||||
|
@ -326,7 +327,7 @@ int network_verify(Network *network) {
|
||||||
if (section_is_invalid(route_prefix->section))
|
if (section_is_invalid(route_prefix->section))
|
||||||
route_prefix_free(route_prefix);
|
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)
|
if (routing_policy_rule_section_verify(rule) < 0)
|
||||||
routing_policy_rule_free(rule);
|
routing_policy_rule_free(rule);
|
||||||
|
|
||||||
|
@ -646,7 +647,6 @@ failure:
|
||||||
static Network *network_free(Network *network) {
|
static Network *network_free(Network *network) {
|
||||||
IPv6ProxyNDPAddress *ipv6_proxy_ndp_address;
|
IPv6ProxyNDPAddress *ipv6_proxy_ndp_address;
|
||||||
RoutePrefix *route_prefix;
|
RoutePrefix *route_prefix;
|
||||||
RoutingPolicyRule *rule;
|
|
||||||
AddressLabel *label;
|
AddressLabel *label;
|
||||||
FdbEntry *fdb_entry;
|
FdbEntry *fdb_entry;
|
||||||
MdbEntry *mdb_entry;
|
MdbEntry *mdb_entry;
|
||||||
|
@ -741,9 +741,6 @@ static Network *network_free(Network *network) {
|
||||||
while ((route_prefix = network->static_route_prefixes))
|
while ((route_prefix = network->static_route_prefixes))
|
||||||
route_prefix_free(route_prefix);
|
route_prefix_free(route_prefix);
|
||||||
|
|
||||||
while ((rule = network->rules))
|
|
||||||
routing_policy_rule_free(rule);
|
|
||||||
|
|
||||||
hashmap_free(network->addresses_by_section);
|
hashmap_free(network->addresses_by_section);
|
||||||
hashmap_free(network->routes_by_section);
|
hashmap_free(network->routes_by_section);
|
||||||
hashmap_free(network->nexthops_by_section);
|
hashmap_free(network->nexthops_by_section);
|
||||||
|
@ -753,7 +750,7 @@ static Network *network_free(Network *network) {
|
||||||
hashmap_free(network->address_labels_by_section);
|
hashmap_free(network->address_labels_by_section);
|
||||||
hashmap_free(network->prefixes_by_section);
|
hashmap_free(network->prefixes_by_section);
|
||||||
hashmap_free(network->route_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->sr_iov_by_section, sr_iov_free);
|
||||||
ordered_hashmap_free_with_destructor(network->tc_by_section, traffic_control_free);
|
ordered_hashmap_free_with_destructor(network->tc_by_section, traffic_control_free);
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include "networkd-nexthop.h"
|
#include "networkd-nexthop.h"
|
||||||
#include "networkd-radv.h"
|
#include "networkd-radv.h"
|
||||||
#include "networkd-route.h"
|
#include "networkd-route.h"
|
||||||
#include "networkd-routing-policy-rule.h"
|
|
||||||
#include "networkd-util.h"
|
#include "networkd-util.h"
|
||||||
#include "ordered-set.h"
|
#include "ordered-set.h"
|
||||||
#include "resolve-util.h"
|
#include "resolve-util.h"
|
||||||
|
@ -295,7 +294,6 @@ struct Network {
|
||||||
LIST_HEAD(AddressLabel, address_labels);
|
LIST_HEAD(AddressLabel, address_labels);
|
||||||
LIST_HEAD(Prefix, static_prefixes);
|
LIST_HEAD(Prefix, static_prefixes);
|
||||||
LIST_HEAD(RoutePrefix, static_route_prefixes);
|
LIST_HEAD(RoutePrefix, static_route_prefixes);
|
||||||
LIST_HEAD(RoutingPolicyRule, rules);
|
|
||||||
|
|
||||||
unsigned n_static_addresses;
|
unsigned n_static_addresses;
|
||||||
unsigned n_static_routes;
|
unsigned n_static_routes;
|
||||||
|
@ -307,7 +305,6 @@ struct Network {
|
||||||
unsigned n_address_labels;
|
unsigned n_address_labels;
|
||||||
unsigned n_static_prefixes;
|
unsigned n_static_prefixes;
|
||||||
unsigned n_static_route_prefixes;
|
unsigned n_static_route_prefixes;
|
||||||
unsigned n_rules;
|
|
||||||
|
|
||||||
Hashmap *addresses_by_section;
|
Hashmap *addresses_by_section;
|
||||||
Hashmap *routes_by_section;
|
Hashmap *routes_by_section;
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
#include "fileio.h"
|
#include "fileio.h"
|
||||||
#include "format-util.h"
|
#include "format-util.h"
|
||||||
#include "ip-protocol-list.h"
|
#include "ip-protocol-list.h"
|
||||||
#include "networkd-routing-policy-rule.h"
|
|
||||||
#include "netlink-util.h"
|
#include "netlink-util.h"
|
||||||
#include "networkd-manager.h"
|
#include "networkd-manager.h"
|
||||||
|
#include "networkd-routing-policy-rule.h"
|
||||||
#include "networkd-util.h"
|
#include "networkd-util.h"
|
||||||
#include "parse-util.h"
|
#include "parse-util.h"
|
||||||
#include "socket-util.h"
|
#include "socket-util.h"
|
||||||
|
@ -44,19 +44,17 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
|
||||||
|
|
||||||
assert(network);
|
assert(network);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
assert(!!filename == (section_line > 0));
|
assert(filename);
|
||||||
|
assert(section_line > 0);
|
||||||
|
|
||||||
if (filename) {
|
r = network_config_section_new(filename, section_line, &n);
|
||||||
r = network_config_section_new(filename, section_line, &n);
|
if (r < 0)
|
||||||
if (r < 0)
|
return r;
|
||||||
return r;
|
|
||||||
|
|
||||||
rule = hashmap_get(network->rules_by_section, n);
|
rule = hashmap_get(network->rules_by_section, n);
|
||||||
if (rule) {
|
if (rule) {
|
||||||
*ret = TAKE_PTR(rule);
|
*ret = TAKE_PTR(rule);
|
||||||
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r = routing_policy_rule_new(&rule);
|
r = routing_policy_rule_new(&rule);
|
||||||
|
@ -64,23 +62,17 @@ static int routing_policy_rule_new_static(Network *network, const char *filename
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
rule->network = network;
|
rule->network = network;
|
||||||
LIST_APPEND(rules, network->rules, rule);
|
rule->section = TAKE_PTR(n);
|
||||||
network->n_rules++;
|
|
||||||
|
|
||||||
if (filename) {
|
r = hashmap_ensure_allocated(&network->rules_by_section, &network_config_hash_ops);
|
||||||
rule->section = TAKE_PTR(n);
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
r = hashmap_ensure_allocated(&network->rules_by_section, &network_config_hash_ops);
|
r = hashmap_put(network->rules_by_section, rule->section, rule);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = hashmap_put(network->rules_by_section, rule->section, rule);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
*ret = TAKE_PTR(rule);
|
*ret = TAKE_PTR(rule);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,12 +81,8 @@ RoutingPolicyRule *routing_policy_rule_free(RoutingPolicyRule *rule) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (rule->network) {
|
if (rule->network) {
|
||||||
LIST_REMOVE(rules, rule->network->rules, rule);
|
assert(rule->section);
|
||||||
assert(rule->network->n_rules > 0);
|
hashmap_remove(rule->network->rules_by_section, rule->section);
|
||||||
rule->network->n_rules--;
|
|
||||||
|
|
||||||
if (rule->section)
|
|
||||||
hashmap_remove(rule->network->rules_by_section, rule->section);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rule->manager) {
|
if (rule->manager) {
|
||||||
|
@ -618,17 +606,18 @@ static int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool manager_links_have_routing_policy_rule(Manager *m, RoutingPolicyRule *rule) {
|
static bool manager_links_have_routing_policy_rule(Manager *m, RoutingPolicyRule *rule) {
|
||||||
RoutingPolicyRule *link_rule;
|
|
||||||
Link *link;
|
Link *link;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(rule);
|
assert(rule);
|
||||||
|
|
||||||
HASHMAP_FOREACH(link, m->links) {
|
HASHMAP_FOREACH(link, m->links) {
|
||||||
|
RoutingPolicyRule *link_rule;
|
||||||
|
|
||||||
if (!link->network)
|
if (!link->network)
|
||||||
continue;
|
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)
|
if (routing_policy_rule_compare_func(link_rule, rule) == 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -678,7 +667,7 @@ int link_set_routing_policy_rules(Link *link) {
|
||||||
|
|
||||||
link->routing_policy_rules_configured = false;
|
link->routing_policy_rules_configured = false;
|
||||||
|
|
||||||
LIST_FOREACH(rules, rule, link->network->rules) {
|
HASHMAP_FOREACH(rule, link->network->rules_by_section) {
|
||||||
RoutingPolicyRule *existing;
|
RoutingPolicyRule *existing;
|
||||||
|
|
||||||
r = routing_policy_rule_get(link->manager, rule, &existing);
|
r = routing_policy_rule_get(link->manager, rule, &existing);
|
||||||
|
|
|
@ -2,25 +2,20 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <linux/fib_rules.h>
|
#include <linux/fib_rules.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "in-addr-util.h"
|
|
||||||
#include "conf-parser.h"
|
#include "conf-parser.h"
|
||||||
|
#include "in-addr-util.h"
|
||||||
typedef struct RoutingPolicyRule RoutingPolicyRule;
|
|
||||||
|
|
||||||
#include "networkd-link.h"
|
|
||||||
#include "networkd-network.h"
|
|
||||||
#include "networkd-util.h"
|
#include "networkd-util.h"
|
||||||
|
#include "set.h"
|
||||||
|
|
||||||
typedef struct Network Network;
|
typedef struct Network Network;
|
||||||
typedef struct Link Link;
|
typedef struct Link Link;
|
||||||
typedef struct NetworkConfigSection NetworkConfigSection;
|
|
||||||
typedef struct Manager Manager;
|
typedef struct Manager Manager;
|
||||||
|
|
||||||
struct RoutingPolicyRule {
|
typedef struct RoutingPolicyRule {
|
||||||
Manager *manager;
|
Manager *manager;
|
||||||
Network *network;
|
Network *network;
|
||||||
Link *link;
|
Link *link;
|
||||||
|
@ -52,9 +47,7 @@ struct RoutingPolicyRule {
|
||||||
struct fib_rule_uid_range uid_range;
|
struct fib_rule_uid_range uid_range;
|
||||||
|
|
||||||
int suppress_prefixlen;
|
int suppress_prefixlen;
|
||||||
|
} RoutingPolicyRule;
|
||||||
LIST_FIELDS(RoutingPolicyRule, rules);
|
|
||||||
};
|
|
||||||
|
|
||||||
int routing_policy_rule_new(RoutingPolicyRule **ret);
|
int routing_policy_rule_new(RoutingPolicyRule **ret);
|
||||||
RoutingPolicyRule *routing_policy_rule_free(RoutingPolicyRule *rule);
|
RoutingPolicyRule *routing_policy_rule_free(RoutingPolicyRule *rule);
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
/***
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||||
SPDX-License-Identifier: LGPL-2.1+
|
|
||||||
***/
|
|
||||||
|
|
||||||
#include "fd-util.h"
|
#include "fd-util.h"
|
||||||
#include "fileio.h"
|
#include "fileio.h"
|
||||||
#include "log.h"
|
#include "networkd-routing-policy-rule.h"
|
||||||
#include "macro.h"
|
|
||||||
#include "network-internal.h"
|
|
||||||
#include "networkd-manager.h"
|
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
#include "tmpfile-util.h"
|
#include "tmpfile-util.h"
|
||||||
|
|
Loading…
Reference in a new issue