From 0aabccc87dd054ee21dc0372648200808f69c5c2 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 2 Aug 2019 05:07:40 +0900 Subject: [PATCH] network: refuse the case To= and From= are in different address family --- src/network/networkd-network.c | 2 +- src/network/networkd-routing-policy-rule.c | 16 ++++++++++++++-- src/network/networkd-routing-policy-rule.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 9d3c383378e..191e766a925 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -281,7 +281,7 @@ int network_verify(Network *network) { prefix_free(prefix); LIST_FOREACH_SAFE(rules, rule, rule_next, network->rules) - if (section_is_invalid(rule->section)) + if (routing_policy_rule_section_verify(rule) < 0) routing_policy_rule_free(rule); return 0; diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index 1864a5a376d..857b01468fa 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -23,7 +23,6 @@ int routing_policy_rule_new(RoutingPolicyRule **ret) { return -ENOMEM; *rule = (RoutingPolicyRule) { - .family = AF_INET, .table = RT_TABLE_MAIN, }; @@ -555,6 +554,16 @@ int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link, link_netl return 1; } +int routing_policy_rule_section_verify(RoutingPolicyRule *rule) { + if (section_is_invalid(rule->section)) + return -EINVAL; + + if (rule->family == AF_UNSPEC) + rule->family = AF_INET; + + return 0; +} + static int parse_fwmark_fwmask(const char *s, uint32_t *fwmark, uint32_t *fwmask) { _cleanup_free_ char *f = NULL; char *p; @@ -767,7 +776,10 @@ int config_parse_routing_policy_rule_prefix( prefixlen = &n->from_prefixlen; } - r = in_addr_prefix_from_string_auto(rvalue, &n->family, buffer, prefixlen); + if (n->family == AF_UNSPEC) + r = in_addr_prefix_from_string_auto(rvalue, &n->family, buffer, prefixlen); + else + r = in_addr_prefix_from_string(rvalue, n->family, buffer, prefixlen); if (r < 0) { log_syntax(unit, LOG_ERR, filename, line, r, "RPDB rule prefix is invalid, ignoring assignment: %s", rvalue); return 0; diff --git a/src/network/networkd-routing-policy-rule.h b/src/network/networkd-routing-policy-rule.h index 512af3dfdd4..8ddb85307c4 100644 --- a/src/network/networkd-routing-policy-rule.h +++ b/src/network/networkd-routing-policy-rule.h @@ -56,6 +56,7 @@ int routing_policy_rule_new(RoutingPolicyRule **ret); void routing_policy_rule_free(RoutingPolicyRule *rule); DEFINE_NETWORK_SECTION_FUNCTIONS(RoutingPolicyRule, routing_policy_rule_free); +int routing_policy_rule_section_verify(RoutingPolicyRule *rule); int routing_policy_rule_configure(RoutingPolicyRule *address, Link *link, link_netlink_message_handler_t callback); int routing_policy_rule_remove(RoutingPolicyRule *routing_policy_rule, Link *link, link_netlink_message_handler_t callback);