From e0978eb8cf7456f1e4e40078c83fadd80f533d0f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 25 Aug 2024 05:03:26 +0900 Subject: [PATCH 1/9] network/routing-policy-rule: rename n -> rule --- src/network/networkd-routing-policy-rule.c | 168 ++++++++++----------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index dd24bf0f416..046fd0f49e2 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -1361,7 +1361,7 @@ int config_parse_routing_policy_rule_tos( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; int r; @@ -1371,17 +1371,17 @@ int config_parse_routing_policy_rule_tos( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); - r = safe_atou8(rvalue, &n->tos); + r = safe_atou8(rvalue, &rule->tos); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse RPDB rule TOS, ignoring: %s", rvalue); return 0; } - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1397,7 +1397,7 @@ int config_parse_routing_policy_rule_priority( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; int r; @@ -1407,25 +1407,25 @@ int config_parse_routing_policy_rule_priority( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); if (isempty(rvalue)) { - n->priority = 0; - n->priority_set = false; - TAKE_PTR(n); + rule->priority = 0; + rule->priority_set = false; + TAKE_PTR(rule); return 0; } - r = safe_atou32(rvalue, &n->priority); + r = safe_atou32(rvalue, &rule->priority); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse RPDB rule priority, ignoring: %s", rvalue); return 0; } - n->priority_set = true; + rule->priority_set = true; - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1441,7 +1441,7 @@ int config_parse_routing_policy_rule_goto( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = ASSERT_PTR(userdata); uint32_t priority; int r; @@ -1450,7 +1450,7 @@ int config_parse_routing_policy_rule_goto( assert(lvalue); assert(rvalue); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); @@ -1464,10 +1464,10 @@ int config_parse_routing_policy_rule_goto( return 0; } - n->type = FR_ACT_GOTO; - n->priority_goto = priority; + rule->type = FR_ACT_GOTO; + rule->priority_goto = priority; - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1483,7 +1483,7 @@ int config_parse_routing_policy_rule_table( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; int r; @@ -1493,18 +1493,18 @@ int config_parse_routing_policy_rule_table( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); - r = manager_get_route_table_from_string(network->manager, rvalue, &n->table); + r = manager_get_route_table_from_string(network->manager, rvalue, &rule->table); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Could not parse RPDB rule route table \"%s\", ignoring assignment: %m", rvalue); return 0; } - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1520,7 +1520,7 @@ int config_parse_routing_policy_rule_fwmark_mask( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; int r; @@ -1530,17 +1530,17 @@ int config_parse_routing_policy_rule_fwmark_mask( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); - r = parse_fwmark_fwmask(rvalue, &n->fwmark, &n->fwmask); + r = parse_fwmark_fwmask(rvalue, &rule->fwmark, &rule->fwmask); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse RPDB rule firewall mark or mask, ignoring: %s", rvalue); return 0; } - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1556,7 +1556,7 @@ int config_parse_routing_policy_rule_prefix( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; union in_addr_union *buffer; uint8_t *prefixlen; @@ -1568,28 +1568,28 @@ int config_parse_routing_policy_rule_prefix( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); if (streq(lvalue, "To")) { - buffer = &n->to; - prefixlen = &n->to_prefixlen; + buffer = &rule->to; + prefixlen = &rule->to_prefixlen; } else { - buffer = &n->from; - prefixlen = &n->from_prefixlen; + buffer = &rule->from; + prefixlen = &rule->from_prefixlen; } - if (n->family == AF_UNSPEC) - r = in_addr_prefix_from_string_auto(rvalue, &n->family, buffer, prefixlen); + 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, n->family, buffer, prefixlen); + 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; } - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1605,7 +1605,7 @@ int config_parse_routing_policy_rule_device( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; int r; @@ -1615,7 +1615,7 @@ int config_parse_routing_policy_rule_device( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); @@ -1625,11 +1625,11 @@ int config_parse_routing_policy_rule_device( return 0; } - r = free_and_strdup(streq(lvalue, "IncomingInterface") ? &n->iif : &n->oif, rvalue); + r = free_and_strdup(streq(lvalue, "IncomingInterface") ? &rule->iif : &rule->oif, rvalue); if (r < 0) return log_oom(); - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1645,7 +1645,7 @@ int config_parse_routing_policy_rule_port_range( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; uint16_t low, high; int r; @@ -1656,7 +1656,7 @@ int config_parse_routing_policy_rule_port_range( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); @@ -1667,14 +1667,14 @@ int config_parse_routing_policy_rule_port_range( } if (streq(lvalue, "SourcePort")) { - n->sport.start = low; - n->sport.end = high; + rule->sport.start = low; + rule->sport.end = high; } else { - n->dport.start = low; - n->dport.end = high; + rule->dport.start = low; + rule->dport.end = high; } - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1690,7 +1690,7 @@ int config_parse_routing_policy_rule_ip_protocol( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; int r; @@ -1700,7 +1700,7 @@ int config_parse_routing_policy_rule_ip_protocol( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); @@ -1710,9 +1710,9 @@ int config_parse_routing_policy_rule_ip_protocol( return 0; } - n->ipproto = r; + rule->ipproto = r; - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1728,7 +1728,7 @@ int config_parse_routing_policy_rule_invert( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; int r; @@ -1738,7 +1738,7 @@ int config_parse_routing_policy_rule_invert( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); @@ -1748,9 +1748,9 @@ int config_parse_routing_policy_rule_invert( return 0; } - SET_FLAG(n->flags, FIB_RULE_INVERT, r); + SET_FLAG(rule->flags, FIB_RULE_INVERT, r); - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1766,7 +1766,7 @@ int config_parse_routing_policy_rule_l3mdev( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; int r; @@ -1776,7 +1776,7 @@ int config_parse_routing_policy_rule_l3mdev( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); @@ -1786,9 +1786,9 @@ int config_parse_routing_policy_rule_l3mdev( return 0; } - n->l3mdev = r; + rule->l3mdev = r; - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1804,7 +1804,7 @@ int config_parse_routing_policy_rule_family( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; AddressFamily a; int r; @@ -1815,7 +1815,7 @@ int config_parse_routing_policy_rule_family( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); @@ -1826,9 +1826,9 @@ int config_parse_routing_policy_rule_family( return 0; } - n->address_family = a; + rule->address_family = a; - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1844,7 +1844,7 @@ int config_parse_routing_policy_rule_uid_range( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; uid_t start, end; int r; @@ -1855,7 +1855,7 @@ int config_parse_routing_policy_rule_uid_range( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); @@ -1871,10 +1871,10 @@ int config_parse_routing_policy_rule_uid_range( } } - n->uid_range.start = start; - n->uid_range.end = end; + rule->uid_range.start = start; + rule->uid_range.end = end; - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1890,7 +1890,7 @@ int config_parse_routing_policy_rule_suppress_prefixlen( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; int r; @@ -1900,11 +1900,11 @@ int config_parse_routing_policy_rule_suppress_prefixlen( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); - r = parse_ip_prefix_length(rvalue, &n->suppress_prefixlen); + 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; @@ -1914,7 +1914,7 @@ int config_parse_routing_policy_rule_suppress_prefixlen( return 0; } - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } @@ -1930,7 +1930,7 @@ int config_parse_routing_policy_rule_suppress_ifgroup( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; int32_t suppress_ifgroup; int r; @@ -1941,12 +1941,12 @@ int config_parse_routing_policy_rule_suppress_ifgroup( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); if (isempty(rvalue)) { - n->suppress_ifgroup = -1; + rule->suppress_ifgroup = -1; return 0; } @@ -1961,8 +1961,8 @@ int config_parse_routing_policy_rule_suppress_ifgroup( "Value of SuppressInterfaceGroup= must be in the range 0…2147483647, ignoring assignment: %s", rvalue); return 0; } - n->suppress_ifgroup = suppress_ifgroup; - TAKE_PTR(n); + rule->suppress_ifgroup = suppress_ifgroup; + TAKE_PTR(rule); return 0; } @@ -1978,9 +1978,9 @@ int config_parse_routing_policy_rule_type( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *n = NULL; + _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; - int r, t; + int r; assert(filename); assert(section); @@ -1988,20 +1988,20 @@ int config_parse_routing_policy_rule_type( assert(rvalue); assert(data); - r = routing_policy_rule_new_static(network, filename, section_line, &n); + r = routing_policy_rule_new_static(network, filename, section_line, &rule); if (r < 0) return log_oom(); - t = fr_act_type_from_string(rvalue); - if (t < 0) { - log_syntax(unit, LOG_WARNING, filename, line, t, + r = fr_act_type_from_string(rvalue); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, "Could not parse FIB rule type \"%s\", ignoring assignment: %m", rvalue); return 0; } - n->type = (uint8_t) t; + rule->type = (uint8_t) r; - TAKE_PTR(n); + TAKE_PTR(rule); return 0; } From 78ff6156d18d5a88353854ca4ebe90d141b53282 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 25 Aug 2024 05:09:55 +0900 Subject: [PATCH 2/9] network/routing-policy-rule: trivial cleanups for conf-parsers No functional change, just refactoring. --- src/network/networkd-routing-policy-rule.c | 67 ++++++++++------------ 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index 046fd0f49e2..2f9d95ffa57 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -1563,22 +1563,20 @@ int config_parse_routing_policy_rule_prefix( 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, "To")) { + if (streq_ptr(lvalue, "To")) { buffer = &rule->to; prefixlen = &rule->to_prefixlen; - } else { + } 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); @@ -1590,7 +1588,7 @@ int config_parse_routing_policy_rule_prefix( } TAKE_PTR(rule); - return 0; + return 1; } int config_parse_routing_policy_rule_device( @@ -1647,35 +1645,31 @@ int config_parse_routing_policy_rule_port_range( _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; - uint16_t low, high; + struct fib_rule_port_range *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_port_range(rvalue, &low, &high, /* allow_zero = */ false); + if (streq_ptr(lvalue, "SourcePort")) + p = &rule->sport; + else if (streq_ptr(lvalue, "DestinationPort")) + p = &rule->dport; + else + assert_not_reached(); + + r = parse_ip_port_range(rvalue, &p->start, &p->end, /* allow_zero = */ false); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse routing policy rule port range '%s'", rvalue); return 0; } - if (streq(lvalue, "SourcePort")) { - rule->sport.start = low; - rule->sport.end = high; - } else { - rule->dport.start = low; - rule->dport.end = high; - } - TAKE_PTR(rule); - return 0; + return 1; } int config_parse_routing_policy_rule_ip_protocol( @@ -1846,36 +1840,33 @@ int config_parse_routing_policy_rule_uid_range( _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; Network *network = userdata; - uid_t start, end; + struct fib_rule_uid_range *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 = get_user_creds(&rvalue, &start, NULL, NULL, NULL, 0); - if (r >= 0) - end = start; - else { - r = parse_uid_range(rvalue, &start, &end); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Invalid uid or uid range '%s', ignoring: %m", rvalue); - return 0; - } + p = &rule->uid_range; + + if (get_user_creds(&rvalue, &p->start, NULL, NULL, NULL, 0) >= 0) { + p->end = p->start; + TAKE_PTR(rule); + return 1; } - rule->uid_range.start = start; - rule->uid_range.end = end; + r = parse_uid_range(rvalue, &p->start, &p->end); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Invalid uid or uid range '%s', ignoring: %m", rvalue); + return 0; + } TAKE_PTR(rule); - return 0; + return 1; } int config_parse_routing_policy_rule_suppress_prefixlen( From 74601abcdd2a77882f6d627b08e45f5b534007e0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 25 Aug 2024 05:31:03 +0900 Subject: [PATCH 3/9] 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. --- src/network/networkd-network-gperf.gperf | 4 +- src/network/networkd-routing-policy-rule.c | 82 +++++++--------------- src/network/networkd-routing-policy-rule.h | 3 +- 3 files changed, 27 insertions(+), 62 deletions(-) diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index b2794f9efde..64601b8a0b5 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 2f9d95ffa57..6d6151de5ba 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; + *p = -1; + TAKE_PTR(rule); + return 1; + } + + r = safe_atoi32(rvalue, &val); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to parse %s=%s, ignoring assignment: %m", lvalue, rvalue); + return 0; + } + if (val < 0 || val > ltype) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Invalid value specified to %s=, ignoring assignment: %s", lvalue, rvalue); return 0; } - r = safe_atoi32(rvalue, &suppress_ifgroup); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse SuppressInterfaceGroup=, ignoring assignment: %s", rvalue); - return 0; - } - if (suppress_ifgroup < 0) { - log_syntax(unit, LOG_WARNING, filename, line, 0, - "Value of SuppressInterfaceGroup= must be in the range 0…2147483647, ignoring assignment: %s", 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 6882afc3e7e..cefab3cd79f 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); From 83c187f585e3b161cc538929380ad3b832bf65bc Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 25 Aug 2024 05:32:00 +0900 Subject: [PATCH 4/9] parse-util: drop unused parse_ip_prefix_length() --- src/basic/parse-util.c | 16 ---------------- src/basic/parse-util.h | 2 -- 2 files changed, 18 deletions(-) diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index 5ace2b9b11c..7700c4edef8 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -714,22 +714,6 @@ int parse_ip_port_range(const char *s, uint16_t *low, uint16_t *high, bool allow return 0; } -int parse_ip_prefix_length(const char *s, int32_t *ret) { - unsigned l; - int r; - - r = safe_atou(s, &l); - if (r < 0) - return r; - - if (l > 128) - return -ERANGE; - - *ret = (int32_t) l; - - return 0; -} - int parse_oom_score_adjust(const char *s, int *ret) { int r, v; diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h index e4ae48366c2..a47c8c7935b 100644 --- a/src/basic/parse-util.h +++ b/src/basic/parse-util.h @@ -141,8 +141,6 @@ int parse_nice(const char *p, int *ret); int parse_ip_port(const char *s, uint16_t *ret); int parse_ip_port_range(const char *s, uint16_t *low, uint16_t *high, bool allow_zero); -int parse_ip_prefix_length(const char *s, int32_t *ret); - int parse_oom_score_adjust(const char *s, int *ret); /* Implement floating point using fixed integers, to improve performance when From f4810fe2371ec3d230a788de233d85ca3a312782 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 25 Aug 2024 04:53:10 +0900 Subject: [PATCH 5/9] conf-parser: return 1 on success Typically, conf parsers will ignore most errors during parsing strings and return 0. Let's return 1 on success. Otherwise it is hard to reused these function in another conf parser. --- src/shared/conf-parser.c | 6 +++--- src/shared/conf-parser.h | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 5a5a3c76133..d33ee8a9b0f 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -1005,7 +1005,7 @@ int config_parse_bool( } *b = k; - return 0; + return 1; /* set */ } int config_parse_id128( @@ -1453,7 +1453,7 @@ int config_parse_ifname( if (isempty(rvalue)) { *s = mfree(*s); - return 0; + return 1; } if (!ifname_valid(rvalue)) { @@ -1465,7 +1465,7 @@ int config_parse_ifname( if (r < 0) return log_oom(); - return 0; + return 1; } int config_parse_ifnames( diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index b73039cc5c8..94f81a3bd63 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -320,7 +320,7 @@ typedef enum ConfigParseStringFlags { } \ \ *i = r; \ - return 0; \ + return 1; \ } #define DEFINE_CONFIG_PARSE_PTR(function, parser, type, msg) \ @@ -337,7 +337,7 @@ typedef enum ConfigParseStringFlags { log_syntax(unit, LOG_WARNING, filename, line, r, \ msg ", ignoring: %s", rvalue); \ \ - return 0; \ + return 1; \ } #define DEFINE_CONFIG_PARSE_ENUM_FULL(function, from_string, type, msg) \ @@ -357,7 +357,7 @@ typedef enum ConfigParseStringFlags { } \ \ *i = x; \ - return 0; \ + return 1; \ } #define DEFINE_CONFIG_PARSE_ENUM(function, name, type, msg) \ @@ -374,7 +374,7 @@ typedef enum ConfigParseStringFlags { \ if (isempty(rvalue)) { \ *i = default_value; \ - return 0; \ + return 1; \ } \ \ x = name##_from_string(rvalue); \ @@ -385,7 +385,7 @@ typedef enum ConfigParseStringFlags { } \ \ *i = x; \ - return 0; \ + return 1; \ } #define DEFINE_CONFIG_PARSE_ENUMV(function, name, type, invalid, msg) \ @@ -448,7 +448,8 @@ typedef enum ConfigParseStringFlags { *(xs + i) = invalid; \ } \ \ - return free_and_replace(*enums, xs); \ + free_and_replace(*enums, xs); \ + return 1; \ } int config_parse_unsigned_bounded( From 6db311fdc82f25bfdedd2b5f97a185f05ee10d09 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 25 Aug 2024 04:56:43 +0900 Subject: [PATCH 6/9] conf-parser: introduce config_parse_uint32_flag() This is not used currently, but will be used later. --- src/shared/conf-parser.c | 29 +++++++++++++++++++++++++++++ src/shared/conf-parser.h | 1 + 2 files changed, 30 insertions(+) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index d33ee8a9b0f..ac0df88b4d5 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -1008,6 +1008,35 @@ int config_parse_bool( return 1; /* set */ } +int config_parse_uint32_flag( + 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) { + + uint32_t *flags = ASSERT_PTR(data); + int r; + + assert(ltype != 0); + + r = isempty(rvalue) ? 0 : parse_boolean(rvalue); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to parse %s=%s. Ignoring assignment: %m", + lvalue, rvalue); + return 0; + } + + SET_FLAG(*flags, ltype, r); + return 1; +} + int config_parse_id128( const char *unit, const char *filename, diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 94f81a3bd63..ad40c6224c5 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -254,6 +254,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_si_uint64); CONFIG_PARSER_PROTOTYPE(config_parse_iec_uint64); CONFIG_PARSER_PROTOTYPE(config_parse_iec_uint64_infinity); CONFIG_PARSER_PROTOTYPE(config_parse_bool); +CONFIG_PARSER_PROTOTYPE(config_parse_uint32_flag); CONFIG_PARSER_PROTOTYPE(config_parse_id128); CONFIG_PARSER_PROTOTYPE(config_parse_tristate); CONFIG_PARSER_PROTOTYPE(config_parse_string); From f7a1e57e1f864c2aa6d77838d3ce3ea6d89be3c6 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 25 Aug 2024 04:58:14 +0900 Subject: [PATCH 7/9] conf-parser: move config_parse_ip_protocol() from network/netdev/fou-tunnel.c The function is generic enough. Currently it is used at only one place. But it will be used at another place. --- src/network/netdev/fou-tunnel.c | 41 --------------------------- src/network/netdev/fou-tunnel.h | 1 - src/network/netdev/netdev-gperf.gperf | 2 +- src/shared/conf-parser.c | 37 ++++++++++++++++++++++++ src/shared/conf-parser.h | 1 + 5 files changed, 39 insertions(+), 43 deletions(-) diff --git a/src/network/netdev/fou-tunnel.c b/src/network/netdev/fou-tunnel.c index bddee5e98cd..969a4e6de64 100644 --- a/src/network/netdev/fou-tunnel.c +++ b/src/network/netdev/fou-tunnel.c @@ -142,47 +142,6 @@ static int netdev_fou_tunnel_create(NetDev *netdev) { return 0; } -int config_parse_ip_protocol( - 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) { - - assert(filename); - assert(section); - assert(lvalue); - assert(rvalue); - - uint8_t *proto = ASSERT_PTR(data); - int r; - - r = parse_ip_protocol_full(rvalue, /* relaxed= */ true); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse '%s=%s', ignoring: %m", - lvalue, rvalue); - return 0; - } - - if (r > UINT8_MAX) { - /* linux/fou.h defines the netlink field as one byte, so we need to reject - * protocols numbers that don't fit in one byte. */ - log_syntax(unit, LOG_WARNING, filename, line, r, - "Invalid '%s=%s', allowed range is 0..255, ignoring.", - lvalue, rvalue); - return 0; - } - - *proto = r; - return 0; -} - int config_parse_fou_tunnel_address( const char *unit, const char *filename, diff --git a/src/network/netdev/fou-tunnel.h b/src/network/netdev/fou-tunnel.h index 72cb315e5fc..1dd2e3b927d 100644 --- a/src/network/netdev/fou-tunnel.h +++ b/src/network/netdev/fou-tunnel.h @@ -38,5 +38,4 @@ const char* fou_encap_type_to_string(FooOverUDPEncapType d) _const_; FooOverUDPEncapType fou_encap_type_from_string(const char *d) _pure_; CONFIG_PARSER_PROTOTYPE(config_parse_fou_encap_type); -CONFIG_PARSER_PROTOTYPE(config_parse_ip_protocol); CONFIG_PARSER_PROTOTYPE(config_parse_fou_tunnel_address); diff --git a/src/network/netdev/netdev-gperf.gperf b/src/network/netdev/netdev-gperf.gperf index 03a4791ee48..be010665c5d 100644 --- a/src/network/netdev/netdev-gperf.gperf +++ b/src/network/netdev/netdev-gperf.gperf @@ -99,7 +99,7 @@ Tunnel.ERSPANHardwareId, config_parse_erspan_hwid, Tunnel.SerializeTunneledPackets, config_parse_tristate, 0, offsetof(Tunnel, gre_erspan_sequence) Tunnel.ISATAP, config_parse_tristate, 0, offsetof(Tunnel, isatap) Tunnel.External, config_parse_bool, 0, offsetof(Tunnel, external) -FooOverUDP.Protocol, config_parse_ip_protocol, 0, offsetof(FouTunnel, fou_protocol) +FooOverUDP.Protocol, config_parse_ip_protocol, /* relax = */ true, offsetof(FouTunnel, fou_protocol) FooOverUDP.Encapsulation, config_parse_fou_encap_type, 0, offsetof(FouTunnel, fou_encap_type) FooOverUDP.Port, config_parse_ip_port, 0, offsetof(FouTunnel, port) FooOverUDP.PeerPort, config_parse_ip_port, 0, offsetof(FouTunnel, peer_port) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index ac0df88b4d5..c4633fc52f1 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -24,6 +24,7 @@ #include "hostname-util.h" #include "id128-util.h" #include "in-addr-util.h" +#include "ip-protocol-list.h" #include "log.h" #include "macro.h" #include "missing_network.h" @@ -2082,3 +2083,39 @@ int config_parse_timezone( return free_and_strdup_warn(tz, rvalue); } + +int config_parse_ip_protocol( + 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) { + + uint8_t *proto = ASSERT_PTR(data); + int r; + + r = isempty(rvalue) ? 0 : parse_ip_protocol_full(rvalue, /* relaxed= */ ltype); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to parse '%s=%s', ignoring: %m", + lvalue, rvalue); + return 0; + } + + if (r > UINT8_MAX) { + /* linux/fib_rules.h and linux/fou.h define the netlink field as one byte, so we need to + * reject protocols numbers that don't fit in one byte. */ + log_syntax(unit, LOG_WARNING, filename, line, r, + "Invalid '%s=%s', allowed range is 0..255, ignoring.", + lvalue, rvalue); + return 0; + } + + *proto = r; + return 1; /* done. */ +} diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index ad40c6224c5..937bdc73ed6 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -290,6 +290,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_pid); CONFIG_PARSER_PROTOTYPE(config_parse_sec_fix_0); CONFIG_PARSER_PROTOTYPE(config_parse_timezone); CONFIG_PARSER_PROTOTYPE(config_parse_calendar); +CONFIG_PARSER_PROTOTYPE(config_parse_ip_protocol); typedef enum Disabled { DISABLED_CONFIGURATION, From 7f66a94ecfe5e7828ab193134f75d7d93f257f71 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 25 Aug 2024 05:50:27 +0900 Subject: [PATCH 8/9] network/routing-policy-rule: introduce a generic conf-parser for [RoutingPolicyRule] sectin This introduce config_parse_routing_policy_rule(), which wraps existing conf parsers. With this, we can drop many custom conf parsers for [RoutingPolicyRule], and can reuse generic conf parsers in conf-parser.[ch]. --- src/network/networkd-network-gperf.gperf | 14 +- src/network/networkd-routing-policy-rule.c | 290 +++++---------------- src/network/networkd-routing-policy-rule.h | 19 +- 3 files changed, 80 insertions(+), 243 deletions(-) diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 64601b8a0b5..23a9242fbb4 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -176,21 +176,21 @@ IPv6AddressLabel.Label, config_parse_address_label, Neighbor.Address, config_parse_neighbor_address, 0, 0 Neighbor.LinkLayerAddress, config_parse_neighbor_lladdr, 0, 0 Neighbor.MACAddress, config_parse_neighbor_lladdr, 0, 0 /* deprecated */ -RoutingPolicyRule.TypeOfService, config_parse_routing_policy_rule_tos, 0, 0 +RoutingPolicyRule.TypeOfService, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_TOS, 0 RoutingPolicyRule.Priority, config_parse_routing_policy_rule_priority, 0, 0 RoutingPolicyRule.GoTo, config_parse_routing_policy_rule_goto, 0, 0 RoutingPolicyRule.Table, config_parse_routing_policy_rule_table, 0, 0 RoutingPolicyRule.FirewallMark, config_parse_routing_policy_rule_fwmark_mask, 0, 0 RoutingPolicyRule.From, config_parse_routing_policy_rule_prefix, 0, 0 RoutingPolicyRule.To, config_parse_routing_policy_rule_prefix, 0, 0 -RoutingPolicyRule.IncomingInterface, config_parse_routing_policy_rule_device, 0, 0 -RoutingPolicyRule.OutgoingInterface, config_parse_routing_policy_rule_device, 0, 0 -RoutingPolicyRule.IPProtocol, config_parse_routing_policy_rule_ip_protocol, 0, 0 +RoutingPolicyRule.IncomingInterface, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_IIF, 0 +RoutingPolicyRule.OutgoingInterface, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_OIF, 0 +RoutingPolicyRule.IPProtocol, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_IP_PROTOCOL, 0 RoutingPolicyRule.SourcePort, config_parse_routing_policy_rule_port_range, 0, 0 RoutingPolicyRule.DestinationPort, config_parse_routing_policy_rule_port_range, 0, 0 -RoutingPolicyRule.InvertRule, config_parse_routing_policy_rule_invert, 0, 0 -RoutingPolicyRule.L3MasterDevice, config_parse_routing_policy_rule_l3mdev, 0, 0 -RoutingPolicyRule.Family, config_parse_routing_policy_rule_family, 0, 0 +RoutingPolicyRule.InvertRule, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_INVERT, 0 +RoutingPolicyRule.L3MasterDevice, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_L3MDEV, 0 +RoutingPolicyRule.Family, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_FAMILY, 0 RoutingPolicyRule.User, config_parse_routing_policy_rule_uid_range, 0, 0 RoutingPolicyRule.SuppressInterfaceGroup, config_parse_routing_policy_rule_suppress, INT32_MAX, 0 RoutingPolicyRule.SuppressPrefixLength, config_parse_routing_policy_rule_suppress, 128, 0 diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index 6d6151de5ba..5f0bcd852dc 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -1349,42 +1349,6 @@ static int parse_fwmark_fwmask(const char *s, uint32_t *ret_fwmark, uint32_t *re return 0; } -int config_parse_routing_policy_rule_tos( - 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; - 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 = safe_atou8(rvalue, &rule->tos); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse RPDB rule TOS, ignoring: %s", rvalue); - return 0; - } - - TAKE_PTR(rule); - return 0; -} - int config_parse_routing_policy_rule_priority( const char *unit, const char *filename, @@ -1591,46 +1555,6 @@ int config_parse_routing_policy_rule_prefix( return 1; } -int config_parse_routing_policy_rule_device( - 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; - 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 (!ifname_valid(rvalue)) { - log_syntax(unit, LOG_WARNING, filename, line, 0, - "Invalid interface name '%s' in %s=, ignoring assignment.", rvalue, lvalue); - return 0; - } - - r = free_and_strdup(streq(lvalue, "IncomingInterface") ? &rule->iif : &rule->oif, rvalue); - if (r < 0) - return log_oom(); - - TAKE_PTR(rule); - return 0; -} - int config_parse_routing_policy_rule_port_range( const char *unit, const char *filename, @@ -1672,160 +1596,6 @@ int config_parse_routing_policy_rule_port_range( return 1; } -int config_parse_routing_policy_rule_ip_protocol( - 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; - 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_protocol(rvalue); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse IP protocol '%s' for routing policy rule, ignoring: %m", rvalue); - return 0; - } - - rule->ipproto = r; - - TAKE_PTR(rule); - return 0; -} - -int config_parse_routing_policy_rule_invert( - 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; - 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_boolean(rvalue); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse RPDB rule invert, ignoring: %s", rvalue); - return 0; - } - - SET_FLAG(rule->flags, FIB_RULE_INVERT, r); - - TAKE_PTR(rule); - return 0; -} - -int config_parse_routing_policy_rule_l3mdev( - 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; - 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_boolean(rvalue); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse RPDB rule l3mdev, ignoring: %s", rvalue); - return 0; - } - - rule->l3mdev = r; - - TAKE_PTR(rule); - return 0; -} - -int config_parse_routing_policy_rule_family( - 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; - AddressFamily a; - 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(); - - a = routing_policy_rule_address_family_from_string(rvalue); - if (a < 0) { - log_syntax(unit, LOG_WARNING, filename, line, a, - "Invalid address family '%s', ignoring.", rvalue); - return 0; - } - - rule->address_family = a; - - TAKE_PTR(rule); - return 0; -} - int config_parse_routing_policy_rule_uid_range( const char *unit, const char *filename, @@ -1962,6 +1732,66 @@ int config_parse_routing_policy_rule_type( return 0; } +static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT( + config_parse_routing_policy_rule_family, + routing_policy_rule_address_family, + AddressFamily, + ADDRESS_FAMILY_NO, + "Invalid family"); + +typedef struct RoutingPolicyRuleConfParser { + ConfigParserCallback parser; + int ltype; + size_t offset; +} RoutingPolicyRuleConfParser; + +static RoutingPolicyRuleConfParser routing_policy_rule_conf_parser_table[_ROUTING_POLICY_RULE_CONF_PARSER_MAX] = { + [ROUTING_POLICY_RULE_IIF] = { .parser = config_parse_ifname, .ltype = 0, .offset = offsetof(RoutingPolicyRule, iif), }, + [ROUTING_POLICY_RULE_OIF] = { .parser = config_parse_ifname, .ltype = 0, .offset = offsetof(RoutingPolicyRule, oif), }, + [ROUTING_POLICY_RULE_FAMILY] = { .parser = config_parse_routing_policy_rule_family, .ltype = 0, .offset = offsetof(RoutingPolicyRule, address_family), }, + [ROUTING_POLICY_RULE_INVERT] = { .parser = config_parse_uint32_flag, .ltype = FIB_RULE_INVERT, .offset = offsetof(RoutingPolicyRule, flags), }, + [ROUTING_POLICY_RULE_IP_PROTOCOL] = { .parser = config_parse_ip_protocol, .ltype = 0, .offset = offsetof(RoutingPolicyRule, ipproto), }, + [ROUTING_POLICY_RULE_L3MDEV] = { .parser = config_parse_bool, .ltype = 0, .offset = offsetof(RoutingPolicyRule, l3mdev), }, + [ROUTING_POLICY_RULE_TOS] = { .parser = config_parse_uint8, .ltype = 0, .offset = offsetof(RoutingPolicyRule, tos), }, +}; + +int config_parse_routing_policy_rule( + 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 = ASSERT_PTR(userdata); + int r; + + assert(filename); + assert(ltype >= 0); + assert(ltype < _ROUTING_POLICY_RULE_CONF_PARSER_MAX); + + r = routing_policy_rule_new_static(network, filename, section_line, &rule); + if (r < 0) + return log_oom(); + + RoutingPolicyRuleConfParser *e = routing_policy_rule_conf_parser_table + ltype; + assert(e->parser); + assert(e->offset < sizeof(RoutingPolicyRule)); + + r = e->parser(unit, filename, line, section, section_line, lvalue, e->ltype, rvalue, + (uint8_t*) rule + e->offset, rule); + if (r <= 0) /* 0 means non-critical error, but the section will be ignored. */ + return r; + + TAKE_PTR(rule); + return 0; +} + #define log_rule_section(rule, fmt, ...) \ ({ \ const RoutingPolicyRule *_rule = (rule); \ diff --git a/src/network/networkd-routing-policy-rule.h b/src/network/networkd-routing-policy-rule.h index cefab3cd79f..71038b16ecc 100644 --- a/src/network/networkd-routing-policy-rule.h +++ b/src/network/networkd-routing-policy-rule.h @@ -77,18 +77,25 @@ void link_foreignize_routing_policy_rules(Link *link); DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(RoutingPolicyRule, routing_policy_rule); -CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_device); -CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_family); +typedef enum RoutingPolicyRuleConfParserType { + ROUTING_POLICY_RULE_IIF, + ROUTING_POLICY_RULE_OIF, + ROUTING_POLICY_RULE_FAMILY, + ROUTING_POLICY_RULE_INVERT, + ROUTING_POLICY_RULE_IP_PROTOCOL, + ROUTING_POLICY_RULE_L3MDEV, + ROUTING_POLICY_RULE_TOS, + _ROUTING_POLICY_RULE_CONF_PARSER_MAX, + _ROUTING_POLICY_RULE_CONF_PARSER_INVALID = -EINVAL, +} RoutingPolicyRuleConfParserType; + +CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule); CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_fwmark_mask); CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_goto); -CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_invert); -CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_ip_protocol); -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); 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); CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_uid_range); From 605377e7b3500f955def2ecc5b95866873464841 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 25 Aug 2024 05:53:41 +0900 Subject: [PATCH 9/9] network/routing-policy-rule: use config_parse_routing_policy_rule() more Then, we can drop allocation of RoutingPolicyRule object in each conf parsers. No functional change, just refactoring. --- src/network/networkd-network-gperf.gperf | 24 +-- src/network/networkd-routing-policy-rule.c | 168 +++++---------------- src/network/networkd-routing-policy-rule.h | 20 +-- 3 files changed, 63 insertions(+), 149 deletions(-) diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 23a9242fbb4..0957eeef6ed 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -177,24 +177,24 @@ Neighbor.Address, config_parse_neighbor_address, Neighbor.LinkLayerAddress, config_parse_neighbor_lladdr, 0, 0 Neighbor.MACAddress, config_parse_neighbor_lladdr, 0, 0 /* deprecated */ RoutingPolicyRule.TypeOfService, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_TOS, 0 -RoutingPolicyRule.Priority, config_parse_routing_policy_rule_priority, 0, 0 -RoutingPolicyRule.GoTo, config_parse_routing_policy_rule_goto, 0, 0 -RoutingPolicyRule.Table, config_parse_routing_policy_rule_table, 0, 0 -RoutingPolicyRule.FirewallMark, config_parse_routing_policy_rule_fwmark_mask, 0, 0 -RoutingPolicyRule.From, config_parse_routing_policy_rule_prefix, 0, 0 -RoutingPolicyRule.To, config_parse_routing_policy_rule_prefix, 0, 0 +RoutingPolicyRule.Priority, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_PRIORITY, 0 +RoutingPolicyRule.GoTo, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_GOTO, 0 +RoutingPolicyRule.Table, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_TABLE, 0 +RoutingPolicyRule.FirewallMark, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_FWMARK, 0 +RoutingPolicyRule.From, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_PREFIX, 0 +RoutingPolicyRule.To, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_PREFIX, 0 RoutingPolicyRule.IncomingInterface, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_IIF, 0 RoutingPolicyRule.OutgoingInterface, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_OIF, 0 RoutingPolicyRule.IPProtocol, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_IP_PROTOCOL, 0 -RoutingPolicyRule.SourcePort, config_parse_routing_policy_rule_port_range, 0, 0 -RoutingPolicyRule.DestinationPort, config_parse_routing_policy_rule_port_range, 0, 0 +RoutingPolicyRule.SourcePort, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_SPORT, 0 +RoutingPolicyRule.DestinationPort, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_DPORT, 0 RoutingPolicyRule.InvertRule, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_INVERT, 0 RoutingPolicyRule.L3MasterDevice, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_L3MDEV, 0 RoutingPolicyRule.Family, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_FAMILY, 0 -RoutingPolicyRule.User, config_parse_routing_policy_rule_uid_range, 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 +RoutingPolicyRule.User, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_UID_RANGE, 0 +RoutingPolicyRule.SuppressInterfaceGroup, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_SUPPRESS_IFGROUP, 0 +RoutingPolicyRule.SuppressPrefixLength, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_SUPPRESS_PREFIXLEN, 0 +RoutingPolicyRule.Type, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_TYPE, 0 Route.Gateway, config_parse_gateway, 0, 0 Route.Destination, config_parse_destination, 0, 0 Route.Source, config_parse_destination, 0, 0 diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index 5f0bcd852dc..75b4224c8ad 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -1349,7 +1349,7 @@ static int parse_fwmark_fwmask(const char *s, uint32_t *ret_fwmark, uint32_t *re return 0; } -int config_parse_routing_policy_rule_priority( +static int config_parse_routing_policy_rule_priority( const char *unit, const char *filename, unsigned line, @@ -1361,25 +1361,13 @@ int config_parse_routing_policy_rule_priority( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; - Network *network = userdata; + RoutingPolicyRule *rule = ASSERT_PTR(userdata); 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 (isempty(rvalue)) { rule->priority = 0; rule->priority_set = false; - TAKE_PTR(rule); - return 0; + return 1; } r = safe_atou32(rvalue, &rule->priority); @@ -1387,13 +1375,12 @@ int config_parse_routing_policy_rule_priority( log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse RPDB rule priority, ignoring: %s", rvalue); return 0; } - rule->priority_set = true; - TAKE_PTR(rule); - return 0; + rule->priority_set = true; + return 1; } -int config_parse_routing_policy_rule_goto( +static int config_parse_routing_policy_rule_goto( const char *unit, const char *filename, unsigned line, @@ -1405,19 +1392,13 @@ int config_parse_routing_policy_rule_goto( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; - Network *network = ASSERT_PTR(userdata); + RoutingPolicyRule *rule = ASSERT_PTR(userdata); uint32_t priority; int r; - assert(filename); assert(lvalue); assert(rvalue); - r = routing_policy_rule_new_static(network, filename, section_line, &rule); - if (r < 0) - return log_oom(); - r = safe_atou32(rvalue, &priority); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s=%s, ignoring assignment: %m", lvalue, rvalue); @@ -1430,12 +1411,10 @@ int config_parse_routing_policy_rule_goto( rule->type = FR_ACT_GOTO; rule->priority_goto = priority; - - TAKE_PTR(rule); - return 0; + return 1; } -int config_parse_routing_policy_rule_table( +static int config_parse_routing_policy_rule_table( const char *unit, const char *filename, unsigned line, @@ -1447,32 +1426,24 @@ int config_parse_routing_policy_rule_table( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; - Network *network = userdata; + RoutingPolicyRule *rule = ASSERT_PTR(userdata); + Manager *manager = ASSERT_PTR(ASSERT_PTR(rule->network)->manager); + uint32_t *table = ASSERT_PTR(data); 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 = manager_get_route_table_from_string(network->manager, rvalue, &rule->table); + r = manager_get_route_table_from_string(manager, rvalue, table); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Could not parse RPDB rule route table \"%s\", ignoring assignment: %m", rvalue); return 0; } - TAKE_PTR(rule); - return 0; + return 1; } -int config_parse_routing_policy_rule_fwmark_mask( +static int config_parse_routing_policy_rule_fwmark( const char *unit, const char *filename, unsigned line, @@ -1484,19 +1455,10 @@ int config_parse_routing_policy_rule_fwmark_mask( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; - Network *network = userdata; + RoutingPolicyRule *rule = ASSERT_PTR(userdata); 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_fwmark_fwmask(rvalue, &rule->fwmark, &rule->fwmask); if (r < 0) { @@ -1504,11 +1466,10 @@ int config_parse_routing_policy_rule_fwmark_mask( return 0; } - TAKE_PTR(rule); - return 0; + return 1; } -int config_parse_routing_policy_rule_prefix( +static int config_parse_routing_policy_rule_prefix( const char *unit, const char *filename, unsigned line, @@ -1520,19 +1481,13 @@ int config_parse_routing_policy_rule_prefix( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; - Network *network = userdata; + RoutingPolicyRule *rule = ASSERT_PTR(userdata); union in_addr_union *buffer; uint8_t *prefixlen; int r; - assert(filename); assert(rvalue); - r = routing_policy_rule_new_static(network, filename, section_line, &rule); - if (r < 0) - return log_oom(); - if (streq_ptr(lvalue, "To")) { buffer = &rule->to; prefixlen = &rule->to_prefixlen; @@ -1551,11 +1506,10 @@ int config_parse_routing_policy_rule_prefix( return 0; } - TAKE_PTR(rule); return 1; } -int config_parse_routing_policy_rule_port_range( +static int config_parse_routing_policy_rule_port_range( const char *unit, const char *filename, unsigned line, @@ -1567,36 +1521,21 @@ int config_parse_routing_policy_rule_port_range( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; - Network *network = userdata; - struct fib_rule_port_range *p; + struct fib_rule_port_range *p = ASSERT_PTR(data); int r; - assert(filename); assert(rvalue); - r = routing_policy_rule_new_static(network, filename, section_line, &rule); - if (r < 0) - return log_oom(); - - if (streq_ptr(lvalue, "SourcePort")) - p = &rule->sport; - else if (streq_ptr(lvalue, "DestinationPort")) - p = &rule->dport; - else - assert_not_reached(); - r = parse_ip_port_range(rvalue, &p->start, &p->end, /* allow_zero = */ false); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse routing policy rule port range '%s'", rvalue); return 0; } - TAKE_PTR(rule); return 1; } -int config_parse_routing_policy_rule_uid_range( +static int config_parse_routing_policy_rule_uid_range( const char *unit, const char *filename, unsigned line, @@ -1608,23 +1547,13 @@ int config_parse_routing_policy_rule_uid_range( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; - Network *network = userdata; - struct fib_rule_uid_range *p; + struct fib_rule_uid_range *p = ASSERT_PTR(data); int r; - assert(filename); assert(rvalue); - r = routing_policy_rule_new_static(network, filename, section_line, &rule); - if (r < 0) - return log_oom(); - - p = &rule->uid_range; - if (get_user_creds(&rvalue, &p->start, NULL, NULL, NULL, 0) >= 0) { p->end = p->start; - TAKE_PTR(rule); return 1; } @@ -1635,11 +1564,10 @@ int config_parse_routing_policy_rule_uid_range( return 0; } - TAKE_PTR(rule); return 1; } -int config_parse_routing_policy_rule_suppress( +static int config_parse_routing_policy_rule_suppress( const char *unit, const char *filename, unsigned line, @@ -1651,28 +1579,13 @@ int config_parse_routing_policy_rule_suppress( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; - Network *network = userdata; - int32_t val, *p; + int32_t val, *p = ASSERT_PTR(data); int r; - assert(filename); assert(lvalue); - 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)) { *p = -1; - TAKE_PTR(rule); return 1; } @@ -1689,11 +1602,10 @@ int config_parse_routing_policy_rule_suppress( } *p = val; - TAKE_PTR(rule); return 1; } -int config_parse_routing_policy_rule_type( +static int config_parse_routing_policy_rule_type( const char *unit, const char *filename, unsigned line, @@ -1705,19 +1617,10 @@ int config_parse_routing_policy_rule_type( void *data, void *userdata) { - _cleanup_(routing_policy_rule_unref_or_set_invalidp) RoutingPolicyRule *rule = NULL; - Network *network = userdata; + uint8_t *p = ASSERT_PTR(data); 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 = fr_act_type_from_string(rvalue); if (r < 0) { @@ -1726,10 +1629,8 @@ int config_parse_routing_policy_rule_type( return 0; } - rule->type = (uint8_t) r; - - TAKE_PTR(rule); - return 0; + *p = (uint8_t) r; + return 1; } static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT( @@ -1749,10 +1650,21 @@ static RoutingPolicyRuleConfParser routing_policy_rule_conf_parser_table[_ROUTIN [ROUTING_POLICY_RULE_IIF] = { .parser = config_parse_ifname, .ltype = 0, .offset = offsetof(RoutingPolicyRule, iif), }, [ROUTING_POLICY_RULE_OIF] = { .parser = config_parse_ifname, .ltype = 0, .offset = offsetof(RoutingPolicyRule, oif), }, [ROUTING_POLICY_RULE_FAMILY] = { .parser = config_parse_routing_policy_rule_family, .ltype = 0, .offset = offsetof(RoutingPolicyRule, address_family), }, + [ROUTING_POLICY_RULE_FWMARK] = { .parser = config_parse_routing_policy_rule_fwmark, .ltype = 0, .offset = 0, }, + [ROUTING_POLICY_RULE_GOTO] = { .parser = config_parse_routing_policy_rule_goto, .ltype = 0, .offset = 0, }, [ROUTING_POLICY_RULE_INVERT] = { .parser = config_parse_uint32_flag, .ltype = FIB_RULE_INVERT, .offset = offsetof(RoutingPolicyRule, flags), }, [ROUTING_POLICY_RULE_IP_PROTOCOL] = { .parser = config_parse_ip_protocol, .ltype = 0, .offset = offsetof(RoutingPolicyRule, ipproto), }, [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_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), }, + [ROUTING_POLICY_RULE_TABLE] = { .parser = config_parse_routing_policy_rule_table, .ltype = 0, .offset = offsetof(RoutingPolicyRule, table), }, [ROUTING_POLICY_RULE_TOS] = { .parser = config_parse_uint8, .ltype = 0, .offset = offsetof(RoutingPolicyRule, tos), }, + [ROUTING_POLICY_RULE_TYPE] = { .parser = config_parse_routing_policy_rule_type, .ltype = 0, .offset = offsetof(RoutingPolicyRule, type), }, + [ROUTING_POLICY_RULE_UID_RANGE] = { .parser = config_parse_routing_policy_rule_uid_range, .ltype = 0, .offset = offsetof(RoutingPolicyRule, uid_range), }, }; int config_parse_routing_policy_rule( diff --git a/src/network/networkd-routing-policy-rule.h b/src/network/networkd-routing-policy-rule.h index 71038b16ecc..b57a16ee7c5 100644 --- a/src/network/networkd-routing-policy-rule.h +++ b/src/network/networkd-routing-policy-rule.h @@ -81,21 +81,23 @@ typedef enum RoutingPolicyRuleConfParserType { ROUTING_POLICY_RULE_IIF, ROUTING_POLICY_RULE_OIF, ROUTING_POLICY_RULE_FAMILY, + ROUTING_POLICY_RULE_FWMARK, + ROUTING_POLICY_RULE_GOTO, ROUTING_POLICY_RULE_INVERT, ROUTING_POLICY_RULE_IP_PROTOCOL, ROUTING_POLICY_RULE_L3MDEV, + ROUTING_POLICY_RULE_SPORT, + ROUTING_POLICY_RULE_DPORT, + ROUTING_POLICY_RULE_PREFIX, + ROUTING_POLICY_RULE_PRIORITY, + ROUTING_POLICY_RULE_SUPPRESS_IFGROUP, + ROUTING_POLICY_RULE_SUPPRESS_PREFIXLEN, + ROUTING_POLICY_RULE_TABLE, ROUTING_POLICY_RULE_TOS, + ROUTING_POLICY_RULE_TYPE, + ROUTING_POLICY_RULE_UID_RANGE, _ROUTING_POLICY_RULE_CONF_PARSER_MAX, _ROUTING_POLICY_RULE_CONF_PARSER_INVALID = -EINVAL, } RoutingPolicyRuleConfParserType; CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule); -CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_fwmark_mask); -CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_goto); -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); -CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_table); -CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_type); -CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_uid_range);