summaryrefslogtreecommitdiffstats
path: root/src/network/networkd-routing-policy-rule.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/networkd-routing-policy-rule.c')
-rw-r--r--src/network/networkd-routing-policy-rule.c89
1 files changed, 28 insertions, 61 deletions
diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c
index c03493b7e0..ec050e3a2d 100644
--- a/src/network/networkd-routing-policy-rule.c
+++ b/src/network/networkd-routing-policy-rule.c
@@ -215,12 +215,12 @@ static void routing_policy_rule_hash_func(const RoutingPolicyRule *rule, struct
siphash24_compress_typesafe(rule->dport, state);
/* See fib4_rule_compare() in net/ipv4/fib_rules.c, and fib6_rule_compare() in net/ipv6/fib6_rules.c. */
- siphash24_compress_typesafe(rule->from_prefixlen, state);
- siphash24_compress_typesafe(rule->to_prefixlen, state);
+ siphash24_compress_typesafe(rule->from.prefixlen, state);
+ siphash24_compress_typesafe(rule->to.prefixlen, state);
siphash24_compress_typesafe(rule->tos, state);
siphash24_compress_typesafe(rule->realms, state);
- in_addr_hash_func(&rule->from, rule->family, state);
- in_addr_hash_func(&rule->to, rule->family, state);
+ in_addr_hash_func(&rule->from.address, rule->family, state);
+ in_addr_hash_func(&rule->to.address, rule->family, state);
}
static int routing_policy_rule_compare_func_full(const RoutingPolicyRule *a, const RoutingPolicyRule *b, bool all) {
@@ -301,11 +301,11 @@ static int routing_policy_rule_compare_func_full(const RoutingPolicyRule *a, con
if (r != 0)
return r;
- r = CMP(a->from_prefixlen, b->from_prefixlen);
+ r = CMP(a->from.prefixlen, b->from.prefixlen);
if (r != 0)
return r;
- r = CMP(a->to_prefixlen, b->to_prefixlen);
+ r = CMP(a->to.prefixlen, b->to.prefixlen);
if (r != 0)
return r;
@@ -318,11 +318,11 @@ static int routing_policy_rule_compare_func_full(const RoutingPolicyRule *a, con
return r;
if (all) {
- r = memcmp(&a->from, &b->from, FAMILY_ADDRESS_SIZE(a->family));
+ r = memcmp(&a->from.address, &b->from.address, FAMILY_ADDRESS_SIZE(a->family));
if (r != 0)
return r;
- r = memcmp(&a->to, &b->to, FAMILY_ADDRESS_SIZE(a->family));
+ r = memcmp(&a->to.address, &b->to.address, FAMILY_ADDRESS_SIZE(a->family));
if (r != 0)
return r;
}
@@ -544,8 +544,8 @@ static void log_routing_policy_rule_debug(const RoutingPolicyRule *rule, const c
"%s %s routing policy rule (%s): priority: %"PRIu32", %s -> %s, iif: %s, oif: %s, table: %s",
str, strna(network_config_source_to_string(rule->source)), strna(state),
rule->priority,
- IN_ADDR_PREFIX_TO_STRING(rule->family, &rule->from, rule->from_prefixlen),
- IN_ADDR_PREFIX_TO_STRING(rule->family, &rule->to, rule->to_prefixlen),
+ IN_ADDR_PREFIX_TO_STRING(rule->family, &rule->from.address, rule->from.prefixlen),
+ IN_ADDR_PREFIX_TO_STRING(rule->family, &rule->to.address, rule->to.prefixlen),
strna(rule->iif), strna(rule->oif), strna(table));
}
@@ -555,22 +555,22 @@ static int routing_policy_rule_set_netlink_message(const RoutingPolicyRule *rule
assert(rule);
assert(m);
- if (rule->from_prefixlen > 0) {
- r = netlink_message_append_in_addr_union(m, FRA_SRC, rule->family, &rule->from);
+ if (rule->from.prefixlen > 0) {
+ r = netlink_message_append_in_addr_union(m, FRA_SRC, rule->family, &rule->from.address);
if (r < 0)
return r;
- r = sd_rtnl_message_routing_policy_rule_set_src_prefixlen(m, rule->from_prefixlen);
+ r = sd_rtnl_message_routing_policy_rule_set_src_prefixlen(m, rule->from.prefixlen);
if (r < 0)
return r;
}
- if (rule->to_prefixlen > 0) {
- r = netlink_message_append_in_addr_union(m, FRA_DST, rule->family, &rule->to);
+ if (rule->to.prefixlen > 0) {
+ r = netlink_message_append_in_addr_union(m, FRA_DST, rule->family, &rule->to.address);
if (r < 0)
return r;
- r = sd_rtnl_message_routing_policy_rule_set_dst_prefixlen(m, rule->to_prefixlen);
+ r = sd_rtnl_message_routing_policy_rule_set_dst_prefixlen(m, rule->to.prefixlen);
if (r < 0)
return r;
}
@@ -1100,24 +1100,24 @@ int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, Man
return 0;
}
- r = netlink_message_read_in_addr_union(message, FRA_SRC, tmp->family, &tmp->from);
+ r = netlink_message_read_in_addr_union(message, FRA_SRC, tmp->family, &tmp->from.address);
if (r < 0 && r != -ENODATA) {
log_warning_errno(r, "rtnl: could not get FRA_SRC attribute, ignoring: %m");
return 0;
} else if (r >= 0) {
- r = sd_rtnl_message_routing_policy_rule_get_src_prefixlen(message, &tmp->from_prefixlen);
+ r = sd_rtnl_message_routing_policy_rule_get_src_prefixlen(message, &tmp->from.prefixlen);
if (r < 0) {
log_warning_errno(r, "rtnl: received rule message without valid source prefix length, ignoring: %m");
return 0;
}
}
- r = netlink_message_read_in_addr_union(message, FRA_DST, tmp->family, &tmp->to);
+ r = netlink_message_read_in_addr_union(message, FRA_DST, tmp->family, &tmp->to.address);
if (r < 0 && r != -ENODATA) {
log_warning_errno(r, "rtnl: could not get FRA_DST attribute, ignoring: %m");
return 0;
} else if (r >= 0) {
- r = sd_rtnl_message_routing_policy_rule_get_dst_prefixlen(message, &tmp->to_prefixlen);
+ r = sd_rtnl_message_routing_policy_rule_get_dst_prefixlen(message, &tmp->to.prefixlen);
if (r < 0) {
log_warning_errno(r, "rtnl: received rule message without valid destination prefix length, ignoring: %m");
return 0;
@@ -1469,46 +1469,6 @@ static int config_parse_routing_policy_rule_fwmark(
return 1;
}
-static int config_parse_routing_policy_rule_prefix(
- 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) {
-
- RoutingPolicyRule *rule = ASSERT_PTR(userdata);
- union in_addr_union *buffer;
- uint8_t *prefixlen;
- int r;
-
- assert(rvalue);
-
- if (streq_ptr(lvalue, "To")) {
- buffer = &rule->to;
- prefixlen = &rule->to_prefixlen;
- } else if (streq_ptr(lvalue, "From")) {
- buffer = &rule->from;
- prefixlen = &rule->from_prefixlen;
- } else
- assert_not_reached();
-
- if (rule->family == AF_UNSPEC)
- r = in_addr_prefix_from_string_auto(rvalue, &rule->family, buffer, prefixlen);
- else
- r = in_addr_prefix_from_string(rvalue, rule->family, buffer, prefixlen);
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r, "RPDB rule prefix is invalid, ignoring assignment: %s", rvalue);
- return 0;
- }
-
- return 1;
-}
-
static int config_parse_routing_policy_rule_port_range(
const char *unit,
const char *filename,
@@ -1662,7 +1622,8 @@ int config_parse_routing_policy_rule(
[ROUTING_POLICY_RULE_L3MDEV] = { .parser = config_parse_bool, .ltype = 0, .offset = offsetof(RoutingPolicyRule, l3mdev), },
[ROUTING_POLICY_RULE_SPORT] = { .parser = config_parse_routing_policy_rule_port_range, .ltype = 0, .offset = offsetof(RoutingPolicyRule, sport), },
[ROUTING_POLICY_RULE_DPORT] = { .parser = config_parse_routing_policy_rule_port_range, .ltype = 0, .offset = offsetof(RoutingPolicyRule, dport), },
- [ROUTING_POLICY_RULE_PREFIX] = { .parser = config_parse_routing_policy_rule_prefix, .ltype = 0, .offset = 0, },
+ [ROUTING_POLICY_RULE_FROM] = { .parser = config_parse_in_addr_prefix, .ltype = 0, .offset = offsetof(RoutingPolicyRule, from), },
+ [ROUTING_POLICY_RULE_TO] = { .parser = config_parse_in_addr_prefix, .ltype = 0, .offset = offsetof(RoutingPolicyRule, to), },
[ROUTING_POLICY_RULE_PRIORITY] = { .parser = config_parse_routing_policy_rule_priority, .ltype = 0, .offset = 0, },
[ROUTING_POLICY_RULE_SUPPRESS_IFGROUP] = { .parser = config_parse_routing_policy_rule_suppress, .ltype = INT32_MAX, .offset = offsetof(RoutingPolicyRule, suppress_ifgroup), },
[ROUTING_POLICY_RULE_SUPPRESS_PREFIXLEN] = { .parser = config_parse_routing_policy_rule_suppress, .ltype = 128, .offset = offsetof(RoutingPolicyRule, suppress_prefixlen), },
@@ -1707,6 +1668,12 @@ static int routing_policy_rule_section_verify(RoutingPolicyRule *rule) {
if (section_is_invalid(rule->section))
return -EINVAL;
+ rule->family = rule->from.family;
+ if (rule->family == AF_UNSPEC)
+ rule->family = rule->to.family;
+ else if (rule->to.family != AF_UNSPEC && rule->to.family != rule->family)
+ return log_rule_section(rule, "From= and To= settings for routing policy rule contradict each other.");
+
if ((rule->family == AF_INET && FLAGS_SET(rule->address_family, ADDRESS_FAMILY_IPV6)) ||
(rule->family == AF_INET6 && FLAGS_SET(rule->address_family, ADDRESS_FAMILY_IPV4)))
return log_rule_section(rule, "Address family specified by Family= conflicts with To= and/or From=.");