diff options
Diffstat (limited to '')
-rw-r--r-- | src/network/networkd-network-gperf.gperf | 12 | ||||
-rw-r--r-- | src/network/networkd-route-nexthop.c | 140 | ||||
-rw-r--r-- | src/network/networkd-route-nexthop.h | 1 | ||||
-rw-r--r-- | src/network/networkd-route.c | 13 | ||||
-rw-r--r-- | src/network/networkd-route.h | 5 |
5 files changed, 43 insertions, 128 deletions
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index a25370d85c..c7218b6d92 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -118,7 +118,7 @@ Network.DefaultRouteOnDevice, config_parse_bool, Network.LLDP, config_parse_lldp_mode, 0, offsetof(Network, lldp_mode) Network.EmitLLDP, config_parse_lldp_multicast_mode, 0, offsetof(Network, lldp_multicast_mode) Network.Address, config_parse_address_section, ADDRESS_ADDRESS, 0 -Network.Gateway, config_parse_gateway, 0, 0 +Network.Gateway, config_parse_route_section, ROUTE_GATEWAY_NETWORK, 0 Network.Domains, config_parse_domains, 0, 0 Network.UseDomains, config_parse_use_domains, 0, offsetof(Network, use_domains) Network.DNS, config_parse_dns, 0, 0 @@ -195,20 +195,20 @@ RoutingPolicyRule.User, config_parse_routing_policy_rule, 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_ACTION, 0 -Route.Gateway, config_parse_gateway, 0, 0 +Route.Gateway, config_parse_route_section, ROUTE_GATEWAY, 0 Route.Destination, config_parse_destination, 0, 0 Route.Source, config_parse_destination, 0, 0 Route.Metric, config_parse_route_priority, 0, 0 Route.Scope, config_parse_route_scope, 0, 0 Route.PreferredSource, config_parse_preferred_src, 0, 0 Route.Table, config_parse_route_table, 0, 0 -Route.GatewayOnLink, config_parse_route_gateway_onlink, 0, 0 -Route.GatewayOnlink, config_parse_route_gateway_onlink, 0, 0 +Route.GatewayOnLink, config_parse_route_section, ROUTE_GATEWAY_ONLINK, 0 +Route.GatewayOnlink, config_parse_route_section, ROUTE_GATEWAY_ONLINK, 0 Route.IPv6Preference, config_parse_ipv6_route_preference, 0, 0 Route.Protocol, config_parse_route_protocol, 0, 0 Route.Type, config_parse_route_type, 0, 0 -Route.MultiPathRoute, config_parse_multipath_route, 0, 0 -Route.NextHop, config_parse_route_nexthop, 0, 0 +Route.MultiPathRoute, config_parse_route_section, ROUTE_MULTIPATH, 0 +Route.NextHop, config_parse_route_section, ROUTE_NEXTHOP, 0 Route.MTUBytes, config_parse_route_section, ROUTE_METRIC_MTU, 0 Route.TCPAdvertisedMaximumSegmentSize, config_parse_route_section, ROUTE_METRIC_ADVMSS, 0 Route.HopLimit, config_parse_route_section, ROUTE_METRIC_HOPLIMIT, 0 diff --git a/src/network/networkd-route-nexthop.c b/src/network/networkd-route-nexthop.c index c0c77c02f5..f6f6b4a804 100644 --- a/src/network/networkd-route-nexthop.c +++ b/src/network/networkd-route-nexthop.c @@ -937,121 +937,52 @@ int config_parse_gateway( const char *section, unsigned section_line, const char *lvalue, - int ltype, + int ltype, /* 0 : only address is accepted, 1 : also supports an empty string, _dhcp, and friends. */ const char *rvalue, void *data, void *userdata) { - Network *network = userdata; - _cleanup_(route_unref_or_set_invalidp) Route *route = NULL; + Route *route = ASSERT_PTR(userdata); int r; - assert(filename); - assert(section); - assert(lvalue); - assert(rvalue); - assert(data); - - if (streq(section, "Network")) { - /* we are not in an Route section, so use line number instead */ - r = route_new_static(network, filename, line, &route); - if (r == -ENOMEM) - return log_oom(); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to allocate route, ignoring assignment: %m"); - return 0; - } - } else { - r = route_new_static(network, filename, section_line, &route); - if (r == -ENOMEM) - return log_oom(); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to allocate route, ignoring assignment: %m"); - return 0; - } - + if (ltype) { if (isempty(rvalue)) { route->gateway_from_dhcp_or_ra = false; route->nexthop.family = AF_UNSPEC; route->nexthop.gw = IN_ADDR_NULL; - TAKE_PTR(route); - return 0; + return 1; } if (streq(rvalue, "_dhcp")) { route->gateway_from_dhcp_or_ra = true; route->nexthop.family = AF_UNSPEC; route->nexthop.gw = IN_ADDR_NULL; - TAKE_PTR(route); - return 0; + return 1; } if (streq(rvalue, "_dhcp4")) { route->gateway_from_dhcp_or_ra = true; route->nexthop.family = AF_INET; route->nexthop.gw = IN_ADDR_NULL; - TAKE_PTR(route); - return 0; + return 1; } if (streq(rvalue, "_ipv6ra")) { route->gateway_from_dhcp_or_ra = true; route->nexthop.family = AF_INET6; route->nexthop.gw = IN_ADDR_NULL; - TAKE_PTR(route); - return 0; + return 1; } } + assert(rvalue); + r = in_addr_from_string_auto(rvalue, &route->nexthop.family, &route->nexthop.gw); if (r < 0) return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); route->gateway_from_dhcp_or_ra = false; - TAKE_PTR(route); - return 0; -} - -int config_parse_route_gateway_onlink( - 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) { - - Network *network = userdata; - _cleanup_(route_unref_or_set_invalidp) Route *route = NULL; - int r; - - assert(filename); - assert(section); - assert(lvalue); - assert(rvalue); - assert(data); - - r = route_new_static(network, filename, section_line, &route); - if (r == -ENOMEM) - return log_oom(); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to allocate route, ignoring assignment: %m"); - return 0; - } - - r = config_parse_tristate(unit, filename, line, section, section_line, lvalue, ltype, rvalue, - &route->gateway_onlink, network); - if (r <= 0) - return r; - - TAKE_PTR(route); - return 0; + return 1; } int config_parse_route_nexthop( @@ -1066,30 +997,12 @@ int config_parse_route_nexthop( void *data, void *userdata) { - Network *network = userdata; - _cleanup_(route_unref_or_set_invalidp) Route *route = NULL; - uint32_t id; + uint32_t id, *p = ASSERT_PTR(data); int r; - assert(filename); - assert(section); - assert(lvalue); - assert(rvalue); - assert(data); - - r = route_new_static(network, filename, section_line, &route); - if (r == -ENOMEM) - return log_oom(); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to allocate route, ignoring assignment: %m"); - return 0; - } - if (isempty(rvalue)) { - route->nexthop_id = 0; - TAKE_PTR(route); - return 0; + *p = 0; + return 1; } r = safe_atou32(rvalue, &id); @@ -1100,9 +1013,8 @@ int config_parse_route_nexthop( return 0; } - route->nexthop_id = id; - TAKE_PTR(route); - return 0; + *p = id; + return 1; } int config_parse_multipath_route( @@ -1118,9 +1030,8 @@ int config_parse_multipath_route( void *userdata) { _cleanup_(route_nexthop_freep) RouteNextHop *nh = NULL; - _cleanup_(route_unref_or_set_invalidp) Route *route = NULL; _cleanup_free_ char *word = NULL; - Network *network = userdata; + OrderedSet **nexthops = ASSERT_PTR(data); const char *p; char *dev; int r; @@ -1131,19 +1042,9 @@ int config_parse_multipath_route( assert(rvalue); assert(data); - r = route_new_static(network, filename, section_line, &route); - if (r == -ENOMEM) - return log_oom(); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to allocate route, ignoring assignment: %m"); - return 0; - } - if (isempty(rvalue)) { - route->nexthops = ordered_set_free(route->nexthops); - TAKE_PTR(route); - return 0; + *nexthops = ordered_set_free(*nexthops); + return 1; } nh = new0(RouteNextHop, 1); @@ -1201,7 +1102,7 @@ int config_parse_multipath_route( nh->weight--; } - r = ordered_set_ensure_put(&route->nexthops, &route_nexthop_hash_ops, nh); + r = ordered_set_ensure_put(nexthops, &route_nexthop_hash_ops, nh); if (r == -ENOMEM) return log_oom(); if (r < 0) { @@ -1211,6 +1112,5 @@ int config_parse_multipath_route( } TAKE_PTR(nh); - TAKE_PTR(route); - return 0; + return 1; } diff --git a/src/network/networkd-route-nexthop.h b/src/network/networkd-route-nexthop.h index f9a147839d..f3f1d7e7a0 100644 --- a/src/network/networkd-route-nexthop.h +++ b/src/network/networkd-route-nexthop.h @@ -52,6 +52,5 @@ int route_nexthops_read_netlink_message(Route *route, sd_netlink_message *messag int route_section_verify_nexthops(Route *route); CONFIG_PARSER_PROTOTYPE(config_parse_gateway); -CONFIG_PARSER_PROTOTYPE(config_parse_route_gateway_onlink); CONFIG_PARSER_PROTOTYPE(config_parse_route_nexthop); CONFIG_PARSER_PROTOTYPE(config_parse_multipath_route); diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 2962768391..bb6c6471f2 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -1990,6 +1990,11 @@ int config_parse_route_section( void *userdata) { static const ConfigSectionParser table[_ROUTE_CONF_PARSER_MAX] = { + [ROUTE_GATEWAY_NETWORK] = { .parser = config_parse_gateway, .ltype = 0, .offset = 0, }, + [ROUTE_GATEWAY] = { .parser = config_parse_gateway, .ltype = 1, .offset = 0, }, + [ROUTE_GATEWAY_ONLINK] = { .parser = config_parse_tristate, .ltype = 0, .offset = offsetof(Route, gateway_onlink), }, + [ROUTE_MULTIPATH] = { .parser = config_parse_multipath_route, .ltype = 0, .offset = offsetof(Route, nexthops), }, + [ROUTE_NEXTHOP] = { .parser = config_parse_route_nexthop, .ltype = 0, .offset = offsetof(Route, nexthop_id), }, [ROUTE_METRIC_MTU] = { .parser = config_parse_route_metric, .ltype = RTAX_MTU, .offset = 0, }, [ROUTE_METRIC_ADVMSS] = { .parser = config_parse_route_metric, .ltype = RTAX_ADVMSS, .offset = 0, }, [ROUTE_METRIC_HOPLIMIT] = { .parser = config_parse_route_metric, .ltype = RTAX_HOPLIMIT, .offset = 0, }, @@ -2007,7 +2012,13 @@ int config_parse_route_section( assert(filename); - r = route_new_static(network, filename, section_line, &route); + if (streq(section, "Network")) { + assert(streq_ptr(lvalue, "Gateway")); + + /* we are not in an Route section, so use line number instead */ + r = route_new_static(network, filename, line, &route); + } else + r = route_new_static(network, filename, section_line, &route); if (r == -ENOMEM) return log_oom(); if (r < 0) { diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h index a4638db01f..543ac64814 100644 --- a/src/network/networkd-route.h +++ b/src/network/networkd-route.h @@ -127,6 +127,11 @@ DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(Route, route); void manager_mark_routes(Manager *manager, Link *link, NetworkConfigSource source); typedef enum RouteConfParserType { + ROUTE_GATEWAY_NETWORK, + ROUTE_GATEWAY, + ROUTE_GATEWAY_ONLINK, + ROUTE_MULTIPATH, + ROUTE_NEXTHOP, ROUTE_METRIC_MTU, ROUTE_METRIC_ADVMSS, ROUTE_METRIC_HOPLIMIT, |