]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/routing-policy-rule: merge two conf parsers
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 24 Aug 2024 20:31:03 +0000 (05:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 24 Aug 2024 21:17:05 +0000 (06:17 +0900)
Both conf parsers takes an integer. Only difference is the maximum
value. Let's merge them, and pass the maximum value through ltype.

src/network/networkd-network-gperf.gperf
src/network/networkd-routing-policy-rule.c
src/network/networkd-routing-policy-rule.h

index b2794f9efdeb8bb8b5c2bcfc3f9e342f0ab8c383..64601b8a0b57423e41739b139609d80b52eb1b1a 100644 (file)
@@ -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
index 2f9d95ffa57aba5241843c42022d351572f281fb..6d6151de5ba1c811b84b3f3501c812376ab44bf0 100644 (file)
@@ -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(
index 6882afc3e7e196e0003475d9fce444051e6270a2..cefab3cd79f82e53e8c88bd1566bd1a52001f959 100644 (file)
@@ -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);