diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-08-24 22:31:03 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-08-24 23:17:05 +0200 |
commit | 74601abcdd2a77882f6d627b08e45f5b534007e0 (patch) | |
tree | 3880ca1d4b129daab3c71f4ed48dee3a89b400e2 /src | |
parent | network/routing-policy-rule: trivial cleanups for conf-parsers (diff) | |
download | systemd-74601abcdd2a77882f6d627b08e45f5b534007e0.tar.xz systemd-74601abcdd2a77882f6d627b08e45f5b534007e0.zip |
network/routing-policy-rule: merge two conf parsers
Both conf parsers takes an integer. Only difference is the maximum
value. Let's merge them, and pass the maximum value through ltype.
Diffstat (limited to 'src')
-rw-r--r-- | src/network/networkd-network-gperf.gperf | 4 | ||||
-rw-r--r-- | src/network/networkd-routing-policy-rule.c | 70 | ||||
-rw-r--r-- | src/network/networkd-routing-policy-rule.h | 3 |
3 files changed, 21 insertions, 56 deletions
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index b2794f9efd..64601b8a0b 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -192,8 +192,8 @@ RoutingPolicyRule.InvertRule, config_parse_routing_policy_rule_in RoutingPolicyRule.L3MasterDevice, config_parse_routing_policy_rule_l3mdev, 0, 0 RoutingPolicyRule.Family, config_parse_routing_policy_rule_family, 0, 0 RoutingPolicyRule.User, config_parse_routing_policy_rule_uid_range, 0, 0 -RoutingPolicyRule.SuppressInterfaceGroup, config_parse_routing_policy_rule_suppress_ifgroup, 0, 0 -RoutingPolicyRule.SuppressPrefixLength, config_parse_routing_policy_rule_suppress_prefixlen, 0, 0 +RoutingPolicyRule.SuppressInterfaceGroup, config_parse_routing_policy_rule_suppress, INT32_MAX, 0 +RoutingPolicyRule.SuppressPrefixLength, config_parse_routing_policy_rule_suppress, 128, 0 RoutingPolicyRule.Type, config_parse_routing_policy_rule_type, 0, 0 Route.Gateway, config_parse_gateway, 0, 0 Route.Destination, config_parse_destination, 0, 0 diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index 2f9d95ffa5..6d6151de5b 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -1869,7 +1869,7 @@ int config_parse_routing_policy_rule_uid_range( return 1; } -int config_parse_routing_policy_rule_suppress_prefixlen( +int config_parse_routing_policy_rule_suppress( const char *unit, const char *filename, unsigned line, @@ -1883,78 +1883,44 @@ int config_parse_routing_policy_rule_suppress_prefixlen( _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; + int32_t val, *p; int r; assert(filename); - assert(section); assert(lvalue); - assert(rvalue); - assert(data); r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); - r = parse_ip_prefix_length(rvalue, &rule->suppress_prefixlen); - if (r == -ERANGE) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Prefix length outside of valid range 0-128, ignoring: %s", rvalue); - return 0; - } - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse RPDB rule suppress_prefixlen, ignoring: %s", rvalue); - return 0; - } - - TAKE_PTR(rule); - return 0; -} - -int config_parse_routing_policy_rule_suppress_ifgroup( - 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) { - - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; - Network *network = userdata; - int32_t suppress_ifgroup; - int r; - - assert(filename); - assert(section); - assert(lvalue); - assert(rvalue); - assert(data); - - r = routing_policy_rule_new_static(network, filename, section_line, &rule); - if (r < 0) - return log_oom(); + if (streq(lvalue, "SuppressPrefixLength")) + p = &rule->suppress_prefixlen; + else if (streq(lvalue, "SuppressInterfaceGroup")) + p = &rule->suppress_ifgroup; + else + assert_not_reached(); if (isempty(rvalue)) { - rule->suppress_ifgroup = -1; - return 0; + *p = -1; + TAKE_PTR(rule); + return 1; } - r = safe_atoi32(rvalue, &suppress_ifgroup); + r = safe_atoi32(rvalue, &val); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse SuppressInterfaceGroup=, ignoring assignment: %s", rvalue); + "Failed to parse %s=%s, ignoring assignment: %m", lvalue, rvalue); return 0; } - if (suppress_ifgroup < 0) { + if (val < 0 || val > ltype) { log_syntax(unit, LOG_WARNING, filename, line, 0, - "Value of SuppressInterfaceGroup= must be in the range 0…2147483647, ignoring assignment: %s", rvalue); + "Invalid value specified to %s=, ignoring assignment: %s", lvalue, rvalue); return 0; } - rule->suppress_ifgroup = suppress_ifgroup; + + *p = val; TAKE_PTR(rule); - return 0; + return 1; } int config_parse_routing_policy_rule_type( diff --git a/src/network/networkd-routing-policy-rule.h b/src/network/networkd-routing-policy-rule.h index 6882afc3e7..cefab3cd79 100644 --- a/src/network/networkd-routing-policy-rule.h +++ b/src/network/networkd-routing-policy-rule.h @@ -87,8 +87,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_l3mdev); CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_port_range); CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_prefix); CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_priority); -CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_suppress_ifgroup); -CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_suppress_prefixlen); +CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_suppress); CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_table); CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_tos); CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_type); |