HALF ECHO LEARN / REFERENCE COLLECTION

v262.2

src/network/networkd-route.c

76,269 bytesGit mode 100644Download original fileLGPL-2.1-or-later

Git blob: 81cfe84add80ad69bea35e0c0b1fdcc5fc052928

Lines 1001–2000 of 2,102

                                    route_compare_func,
                                    route_process_request,
                                    message_counter,
                                    netlink_handler,
                                    NULL);
        if (r <= 0)
                return r;
 
        route_enter_requesting(tmp);
        if (existing)
                route_enter_requesting(existing);
 
        TAKE_PTR(tmp);
        return 1;
}
 
int link_request_route(
                Link *link,
                const Route *route,
                unsigned *message_counter,
                route_netlink_handler_t netlink_handler) {
 
        int r;
 
        assert(link);
        assert(link->manager);
        assert(route);
        assert(route->source != NETWORK_CONFIG_SOURCE_FOREIGN);
 
        if (route->family == AF_INET || route_is_reject(route) || ordered_set_isempty(route->nexthops))
                return link_request_route_one(link, route, NULL, message_counter, netlink_handler);
 
        RouteNextHop *nh;
        ORDERED_SET_FOREACH(nh, route->nexthops) {
                r = link_request_route_one(link, route, nh, message_counter, netlink_handler);
                if (r < 0)
                        return r;
        }
 
        return 0;
}
 
static int static_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, Route *route) {
        int r;
 
        assert(req);
        assert(link);
        assert(route);
 
        r = route_configure_handler_internal(m, req, route);
        if (r <= 0)
                return r;
 
        if (link->static_route_messages == 0) {
                log_link_debug(link, "Routes set");
                link->static_routes_configured = true;
                link_check_ready(link);
        }
 
        return 1;
}
 
static int link_request_wireguard_routes(Link *link, bool only_ipv4) {
        Route *route;
        int r;
 
        assert(link);
 
        if (!link->netdev || link->netdev->kind != NETDEV_KIND_WIREGUARD)
                return 0;
 
        Wireguard *w = WIREGUARD(link->netdev);
 
        SET_FOREACH(route, w->routes) {
                if (only_ipv4 && route->family != AF_INET)
                        continue;
 
                r = link_request_route(link, route, &link->static_route_messages, static_route_handler);
                if (r < 0)
                        return r;
        }
 
        return 0;
}
 
int link_request_static_routes(Link *link, bool only_ipv4) {
        Route *route;
        int r;
 
        assert(link);
        assert(link->network);
 
        link->static_routes_configured = false;
 
        HASHMAP_FOREACH(route, link->network->routes_by_section) {
                if (route->source != NETWORK_CONFIG_SOURCE_STATIC)
                        continue;
 
                if (only_ipv4 && route->family != AF_INET)
                        continue;
 
                r = link_request_route(link, route, &link->static_route_messages, static_route_handler);
                if (r < 0)
                        return r;
        }
 
        r = link_request_wireguard_routes(link, only_ipv4);
        if (r < 0)
                return r;
 
        if (link->static_route_messages == 0) {
                link->static_routes_configured = true;
                link_check_ready(link);
        } else {
                log_link_debug(link, "Requesting routes");
                link_set_state(link, LINK_STATE_CONFIGURING);
        }
 
        return 0;
}
 
static int process_route_one(
                Manager *manager,
                uint16_t type,
                Route *tmp,
                const struct rta_cacheinfo *cacheinfo) {
 
        Route *route = NULL;
        Link *link = NULL;
        bool is_new = false, update_dhcp4;
        int r;
 
        assert(manager);
        assert(tmp);
        assert(IN_SET(type, RTM_NEWROUTE, RTM_DELROUTE));
 
        (void) route_get(manager, tmp, &route);
        (void) route_get_link(manager, tmp, &link);
 
        update_dhcp4 = link && tmp->family == AF_INET6 && tmp->dst_prefixlen == 0;
 
        switch (type) {
        case RTM_NEWROUTE: {
                Request *req = NULL;
                (void) route_get_request(manager, tmp, &req);
 
                if (!route) {
                        if (!manager->manage_foreign_routes && !(req && req->waiting_reply)) {
                                route_enter_configured(tmp);
                                log_route_debug(tmp, "Ignoring received", manager);
                                return 0;
                        }
 
                        /* If we do not know the route, then save it. */
                        r = route_attach(manager, tmp);
                        if (r < 0) {
                                log_link_warning_errno(link, r, "Failed to remember foreign route, ignoring: %m");
                                return 0;
                        }
 
                        route = route_ref(tmp);
                        is_new = true;
 
                } else {
                        /* Update remembered route with the received notification. */
 
                        /* Here, update weight only when a non-zero weight is received. As the kernel does
                         * not provide the weight of a single-path route. In such case, tmp->nexthop.weight
                         * is zero, hence we should not overwrite the known weight of the route. */
                        if (tmp->nexthop.weight != 0)
                                route->nexthop.weight = tmp->nexthop.weight;
                }
 
                /* Also update information that cannot be obtained through netlink notification. */
                if (req && req->waiting_reply) {
                        r = route_update_by_request(route, req);
                        if (r < 0) {
                                log_link_warning_errno(link, r, "Failed to update route by request: %m");
                                link_enter_failed(link);
                                return 0;
                        }
 
                        /* We configure IPv6 multipath route separately. When the first path is configured,
                         * the kernel does not provide the weight of the path. So, we need to adjust it here.
                         * Hopefully, the weight is assigned correctly. */
                        if (route->nexthop.weight == 0) {
                                Route *rt = ASSERT_PTR(req->userdata);
                                route->nexthop.weight = rt->nexthop.weight;
                        }
                }
 
                route_attach_to_nexthop(route);
 
                route_enter_configured(route);
                log_route_debug(route, is_new ? "Received new" : "Received remembered", manager);
 
                (void) route_setup_timer(route, cacheinfo);
 
                break;
        }
        case RTM_DELROUTE:
                if (route)
                        route_forget(manager, route, "Forgetting removed");
                else
                        log_route_debug(tmp,
                                        manager->manage_foreign_routes ? "Kernel removed unknown" : "Ignoring removed",
                                        manager);
                break;
 
        default:
                assert_not_reached();
        }
 
        if (update_dhcp4) {
                r = dhcp4_update_ipv6_connectivity(link);
                if (r < 0) {
                        log_link_warning_errno(link, r, "Failed to notify IPv6 connectivity to DHCPv4 client: %m");
                        link_enter_failed(link);
                }
        }
 
        return 1;
}
 
int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, Manager *m) {
        _cleanup_(route_unrefp) Route *tmp = NULL;
        int r;
 
        assert(rtnl);
        assert(message);
        assert(m);
 
        if (sd_netlink_message_is_error(message)) {
                r = sd_netlink_message_get_errno(message);
                if (r < 0)
                        log_message_warning_errno(message, r, "rtnl: failed to receive route message, ignoring");
 
                return 0;
        }
 
        uint16_t type;
        r = sd_netlink_message_get_type(message, &type);
        if (r < 0) {
                log_warning_errno(r, "rtnl: could not get message type, ignoring: %m");
                return 0;
        } else if (!IN_SET(type, RTM_NEWROUTE, RTM_DELROUTE)) {
                log_warning("rtnl: received unexpected message type %u when processing route, ignoring.", type);
                return 0;
        }
 
        r = route_new(&tmp);
        if (r < 0)
                return log_oom();
 
        /* rtmsg header */
        r = sd_rtnl_message_route_get_family(message, &tmp->family);
        if (r < 0) {
                log_warning_errno(r, "rtnl: received route message without family, ignoring: %m");
                return 0;
        } else if (!IN_SET(tmp->family, AF_INET, AF_INET6)) {
                log_debug("rtnl: received route message with invalid family '%i', ignoring.", tmp->family);
                return 0;
        }
 
        r = sd_rtnl_message_route_get_dst_prefixlen(message, &tmp->dst_prefixlen);
        if (r < 0) {
                log_warning_errno(r, "rtnl: received route message with invalid destination prefixlen, ignoring: %m");
                return 0;
        }
 
        r = sd_rtnl_message_route_get_src_prefixlen(message, &tmp->src_prefixlen);
        if (r < 0) {
                log_warning_errno(r, "rtnl: received route message with invalid source prefixlen, ignoring: %m");
                return 0;
        }
 
        r = sd_rtnl_message_route_get_tos(message, &tmp->tos);
        if (r < 0) {
                log_warning_errno(r, "rtnl: received route message with invalid tos, ignoring: %m");
                return 0;
        }
 
        r = sd_rtnl_message_route_get_protocol(message, &tmp->protocol);
        if (r < 0) {
                log_warning_errno(r, "rtnl: received route message without route protocol, ignoring: %m");
                return 0;
        }
 
        r = sd_rtnl_message_route_get_scope(message, &tmp->scope);
        if (r < 0) {
                log_warning_errno(r, "rtnl: received route message with invalid scope, ignoring: %m");
                return 0;
        }
 
        r = sd_rtnl_message_route_get_type(message, &tmp->type);
        if (r < 0) {
                log_warning_errno(r, "rtnl: received route message with invalid type, ignoring: %m");
                return 0;
        }
 
        r = sd_rtnl_message_route_get_flags(message, &tmp->flags);
        if (r < 0) {
                log_warning_errno(r, "rtnl: received route message without route flags, ignoring: %m");
                return 0;
        }
 
        /* attributes */
        r = netlink_message_read_in_addr_union(message, RTA_DST, tmp->family, &tmp->dst);
        if (r < 0 && r != -ENODATA) {
                log_warning_errno(r, "rtnl: received route message without valid destination, ignoring: %m");
                return 0;
        }
 
        r = netlink_message_read_in_addr_union(message, RTA_SRC, tmp->family, &tmp->src);
        if (r < 0 && r != -ENODATA) {
                log_warning_errno(r, "rtnl: received route message without valid source, ignoring: %m");
                return 0;
        }
 
        r = sd_netlink_message_read_u32(message, RTA_PRIORITY, &tmp->priority);
        if (r < 0 && r != -ENODATA) {
                log_warning_errno(r, "rtnl: received route message with invalid priority, ignoring: %m");
                return 0;
        }
 
        r = netlink_message_read_in_addr_union(message, RTA_PREFSRC, tmp->family, &tmp->prefsrc);
        if (r < 0 && r != -ENODATA) {
                log_warning_errno(r, "rtnl: received route message without valid preferred source, ignoring: %m");
                return 0;
        }
 
        r = sd_netlink_message_read_u32(message, RTA_TABLE, &tmp->table);
        if (r == -ENODATA) {
                unsigned char table;
 
                r = sd_rtnl_message_route_get_table(message, &table);
                if (r >= 0)
                        tmp->table = table;
        }
        if (r < 0) {
                log_warning_errno(r, "rtnl: received route message with invalid table, ignoring: %m");
                return 0;
        }
 
        r = sd_netlink_message_read_u8(message, RTA_PREF, &tmp->pref);
        if (r < 0 && r != -ENODATA) {
                log_warning_errno(r, "rtnl: received route message with invalid preference, ignoring: %m");
                return 0;
        }
 
        /* nexthops */
        if (route_nexthops_read_netlink_message(tmp, message) < 0)
                return 0;
 
        /* metrics */
        if (route_metric_read_netlink_message(&tmp->metric, message) < 0)
                return 0;
 
        bool has_cacheinfo;
        struct rta_cacheinfo cacheinfo;
        r = sd_netlink_message_read(message, RTA_CACHEINFO, sizeof(cacheinfo), &cacheinfo);
        if (r < 0 && r != -ENODATA) {
                log_warning_errno(r, "rtnl: failed to read RTA_CACHEINFO attribute, ignoring: %m");
                return 0;
        }
        has_cacheinfo = r >= 0;
 
        if (tmp->family == AF_INET || ordered_set_isempty(tmp->nexthops))
                return process_route_one(m, type, tmp, has_cacheinfo ? &cacheinfo : NULL);
 
        RouteNextHop *nh;
        ORDERED_SET_FOREACH(nh, tmp->nexthops) {
                _cleanup_(route_unrefp) Route *dup = NULL;
 
                r = route_dup(tmp, nh, &dup);
                if (r < 0)
                        return log_oom();
 
                r = process_route_one(m, type, dup, has_cacheinfo ? &cacheinfo : NULL);
                if (r < 0)
                        return r;
        }
 
        return 1;
}
 
void manager_mark_routes(Manager *manager, Link *link, NetworkConfigSource source) {
        Route *route;
 
        assert(manager);
 
        SET_FOREACH(route, manager->routes) {
                if (route->source != source)
                        continue;
 
                if (link) {
                        Link *route_link;
 
                        if (route_get_link(manager, route, &route_link) < 0)
                                continue;
                        if (route_link != link)
                                continue;
                }
 
                route_mark(route);
        }
}
 
static bool route_by_kernel(const Route *route) {
        assert(route);
 
        if (route->protocol == RTPROT_KERNEL)
                return true;
 
        /* The kernels older than a826b04303a40d52439aa141035fca5654ccaccd (v5.11) create the IPv6
         * multicast with RTPROT_BOOT. Do not touch it. */
        if (route->protocol == RTPROT_BOOT &&
            route->family == AF_INET6 &&
            route->dst_prefixlen == 8 &&
            in6_addr_equal(&route->dst.in6, & (struct in6_addr) {{{ 0xff,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 }}}))
                return true;
 
        return false;
}
 
bool route_can_update(Manager *manager, const Route *existing, const Route *requesting) {
        int r;
 
        assert(manager);
        assert(existing);
        assert(requesting);
 
        if (route_compare_func(existing, requesting) != 0) {
                log_route_debug(existing, "Cannot update route, as the existing route is different", manager);
                return false;
        }
 
        switch (existing->family) {
        case AF_INET:
                if (existing->nexthop.weight != requesting->nexthop.weight) {
                        log_debug("Cannot update route: existing weight: %u, requesting weight: %u",
                                  existing->nexthop.weight, requesting->nexthop.weight);
                        return false;
                }
                return true;
 
        case AF_INET6:
                if (existing->protocol != requesting->protocol) {
                        if (DEBUG_LOGGING) {
                                _cleanup_free_ char *ex = NULL, *req = NULL;
 
                                r = route_protocol_to_string_alloc(existing->protocol, &ex);
                                if (r < 0)
                                        return false;
 
                                r = route_protocol_to_string_alloc(requesting->protocol, &req);
                                if (r < 0)
                                        return false;
 
                                log_debug("Cannot update route: existing protocol: %s, requesting protocol: %s", ex, req);
                        }
 
                        return false;
                }
                if (existing->type != requesting->type) {
                        log_debug("Cannot update route: existing type: %s, requesting type: %s",
                                  route_type_to_string(existing->type),
                                  route_type_to_string(requesting->type));
 
                        return false;
                }
                if ((existing->flags & ~RTNH_COMPARE_MASK) != (requesting->flags & ~RTNH_COMPARE_MASK)) {
                        if (DEBUG_LOGGING) {
                                _cleanup_free_ char *ex = NULL, *req = NULL;
 
                                r = route_flags_to_string_alloc(existing->flags, &ex);
                                if (r < 0)
                                        return false;
 
                                r = route_flags_to_string_alloc(requesting->flags, &req);
                                if (r < 0)
                                        return false;
 
                                log_debug("Cannot update route: existing flags: %s, requesting flags: %s", ex, req);
                        }
 
                        return false;
                }
                if (!in6_addr_equal(&existing->prefsrc.in6, &requesting->prefsrc.in6)) {
                        log_debug("Cannot update route: existing preferred source: %s, requesting preferred source: %s",
                                  IN6_ADDR_TO_STRING(&existing->prefsrc.in6),
                                  IN6_ADDR_TO_STRING(&requesting->prefsrc.in6));
                        return false;
                }
                if (existing->pref != requesting->pref) {
                        log_debug("Cannot update route: existing preference: %u, requesting preference: %u",
                                  existing->pref, requesting->pref);
                        return false;
                }
                if (existing->expiration_managed_by_kernel && requesting->lifetime_usec == USEC_INFINITY) {
                        log_route_debug(existing,
                                        "Cannot update route: the expiration is managed by the kernel and requested lifetime is infinite",
                                        manager);
                        return false; /* We cannot disable expiration timer in the kernel. */
                }
                if (!route_metric_can_update(&existing->metric, &requesting->metric, existing->expiration_managed_by_kernel)) {
                        log_route_debug(existing,
                                        "Cannot update route: expiration is managed by the kernel or metrics differ",
                                        manager);
                        return false;
                }
                if (existing->nexthop.weight != requesting->nexthop.weight) {
                        log_debug("Cannot update route: existing weight: %u, requesting weight: %u",
                                  existing->nexthop.weight, requesting->nexthop.weight);
                        return false;
                }
                return true;
 
        default:
                assert_not_reached();
        }
}
 
static int link_unmark_route(Link *link, const Route *route, const RouteNextHop *nh) {
        _cleanup_(route_unrefp) Route *tmp = NULL;
        Route *existing;
        int r;
 
        assert(link);
        assert(route);
 
        r = route_dup(route, nh, &tmp);
        if (r < 0)
                return r;
 
        r = route_adjust_nexthops(tmp, link);
        if (r < 0)
                return r;
 
        if (route_get(link->manager, tmp, &existing) < 0)
                return 0;
 
        if (!route_can_update(link->manager, existing, tmp))
                return 0;
 
        route_unmark(existing);
        return 1;
}
 
int link_drop_routes(Link *link, bool only_static) {
        Route *route;
        Link *other;
        int r = 0;
 
        assert(link);
        assert(link->manager);
 
        /* First, mark all routes. */
        SET_FOREACH(route, link->manager->routes) {
                /* Do not touch routes managed by the kernel. */
                if (route_by_kernel(route))
                        continue;
 
                /* Ignore routes not assigned yet or already removed. */
                if (!route_exists(route))
                        continue;
 
                if (!link_should_mark_config(link, only_static, route->source, route->protocol))
                        continue;
 
                Link *route_link = NULL;
                if (route_get_link(link->manager, route, &route_link) >= 0 && route_link != link) {
                        /* When we also mark foreign routes, do not mark routes assigned to other interfaces.
                         * Otherwise, routes assigned to unmanaged interfaces will be dropped.
                         * Note, route_get_link() does not provide assigned link for routes with an
                         * unreachable type or IPv4 multipath routes. So, the current implementation does not
                         * support managing such routes by other daemon or so, unless ManageForeignRoutes=no. */
                        if (!only_static)
                                continue;
 
                        /* When we mark only static routes, do not mark routes assigned to links that we do
                         * not know the assignment of .network files to the interfaces. Otherwise, if an
                         * interface is in the pending state, even if the .network file to be assigned to the
                         * interface has KeepConfiguration=yes, routes on the interface will be removed.
                         * This is especially important when systemd-networkd is restarted. */
                        if (!IN_SET(route_link->state, LINK_STATE_UNMANAGED, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
                                continue;
                }
 
                route_mark(route);
        }
 
        /* Then, unmark all routes requested by active links. */
        HASHMAP_FOREACH(other, link->manager->links_by_index) {
                if (only_static && other == link)
                        continue;
 
                if (!IN_SET(other->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
                        continue;
 
                HASHMAP_FOREACH(route, other->network->routes_by_section) {
                        if (route->source != NETWORK_CONFIG_SOURCE_STATIC)
                                continue;
 
                        if (route->family == AF_INET || ordered_set_isempty(route->nexthops)) {
                                r = link_unmark_route(other, route, NULL);
                                if (r < 0)
                                        return r;
 
                        } else {
                                RouteNextHop *nh;
                                ORDERED_SET_FOREACH(nh, route->nexthops) {
                                        r = link_unmark_route(other, route, nh);
                                        if (r < 0)
                                                return r;
                                }
                        }
                }
 
                /* Also unmark routes requested in .netdev file. */
                if (other->netdev && other->netdev->kind == NETDEV_KIND_WIREGUARD) {
                        Wireguard *w = WIREGUARD(other->netdev);
 
                        SET_FOREACH(route, w->routes) {
                                r = link_unmark_route(other, route, NULL);
                                if (r < 0)
                                        return r;
                        }
                }
        }
 
        /* Finally, remove all marked routes. */
        SET_FOREACH(route, link->manager->routes) {
                if (!route_is_marked(route))
                        continue;
 
                RET_GATHER(r, route_remove(route, link->manager));
        }
 
        return r;
}
 
void link_forget_routes(Link *link) {
        assert(link);
        assert(link->ifindex > 0);
        assert(!link_is_up(link));
 
        /* When an interface went down, IPv4 non-local routes bound to the interface are silently removed by
         * the kernel, without any notifications. Let's forget them in that case. Otherwise, when the link
         * goes up later, the configuration order of routes may be confused by the nonexistent routes.
         * See issue #35047. */
 
        Route *route;
        SET_FOREACH(route, link->manager->routes) {
                // TODO: handle multipath routes
                if (route->nexthop.ifindex != link->ifindex)
                        continue;
                if (route->family != AF_INET)
                        continue;
                // TODO: check RTN_NAT and RTN_XRESOLVE
                if (!IN_SET(route->type, RTN_UNICAST, RTN_BROADCAST, RTN_ANYCAST, RTN_MULTICAST))
                        continue;
 
                route_forget(link->manager, route, "Forgetting silently removed");
        }
}
 
int network_add_ipv4ll_route(Network *network) {
        _cleanup_(route_unref_or_set_invalidp) Route *route = NULL;
        unsigned section_line;
        int r;
 
        assert(network);
 
        if (!network->ipv4ll_route)
                return 0;
 
        r = hashmap_by_section_find_unused_line(network->routes_by_section, network->filename, &section_line);
        if (r < 0)
                return r;
 
        /* IPv4LLRoute= is in [Network] section. */
        r = route_new_static(network, network->filename, section_line, &route);
        if (r < 0)
                return r;
 
        r = in_addr_from_string(AF_INET, "169.254.0.0", &route->dst);
        if (r < 0)
                return r;
 
        route->family = AF_INET;
        route->dst_prefixlen = 16;
        route->scope = RT_SCOPE_LINK;
        route->scope_set = true;
        route->table_set = true;
        route->priority = IPV4LL_ROUTE_METRIC;
        route->protocol = RTPROT_STATIC;
 
        TAKE_PTR(route);
        return 0;
}
 
int network_add_default_route_on_device(Network *network) {
        _cleanup_(route_unref_or_set_invalidp) Route *route = NULL;
        unsigned section_line;
        int r;
 
        assert(network);
 
        if (!network->default_route_on_device)
                return 0;
 
        r = hashmap_by_section_find_unused_line(network->routes_by_section, network->filename, &section_line);
        if (r < 0)
                return r;
 
        /* DefaultRouteOnDevice= is in [Network] section. */
        r = route_new_static(network, network->filename, section_line, &route);
        if (r < 0)
                return r;
 
        route->family = AF_INET;
        route->scope = RT_SCOPE_LINK;
        route->scope_set = true;
        route->protocol = RTPROT_STATIC;
 
        TAKE_PTR(route);
        return 0;
}
 
static int config_parse_preferred_src(
                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) {
 
        Route *route = ASSERT_PTR(userdata);
        int r;
 
        if (isempty(rvalue)) {
                route->prefsrc_set = false;
                route->prefsrc = IN_ADDR_NULL;
                return 1;
        }
 
        r = parse_boolean(rvalue);
        if (r == 0) {
                /* Accepts only no. That prohibits prefsrc set by DHCP lease. */
                route->prefsrc_set = true;
                route->prefsrc = IN_ADDR_NULL;
                return 1;
        }
 
        if (route->family == AF_UNSPEC)
                r = in_addr_from_string_auto(rvalue, &route->family, &route->prefsrc);
        else
                r = in_addr_from_string(route->family, rvalue, &route->prefsrc);
        if (r < 0)
                return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
 
        route->prefsrc_set = true;
        return 1;
}
 
static int config_parse_route_destination(
                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) {
 
        Route *route = ASSERT_PTR(userdata);
        union in_addr_union *buffer;
        unsigned char *prefixlen;
        int r;
 
        assert(lvalue);
        assert(rvalue);
 
        if (streq(lvalue, "Destination")) {
                buffer = &route->dst;
                prefixlen = &route->dst_prefixlen;
        } else if (streq(lvalue, "Source")) {
                buffer = &route->src;
                prefixlen = &route->src_prefixlen;
        } else
                assert_not_reached();
 
        if (route->family == AF_UNSPEC)
                r = in_addr_prefix_from_string_auto(rvalue, &route->family, buffer, prefixlen);
        else
                r = in_addr_prefix_from_string(rvalue, route->family, buffer, prefixlen);
        if (r < 0)
                return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
 
        (void) in_addr_mask(route->family, buffer, *prefixlen);
        return 1;
}
 
static int config_parse_route_priority(
                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) {
 
        Route *route = ASSERT_PTR(userdata);
        int r;
 
        assert(rvalue);
 
        r = safe_atou32(rvalue, &route->priority);
        if (r < 0)
                return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
 
        route->priority_set = true;
        return 1;
}
 
static int config_parse_route_scope(
                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) {
 
        Route *route = ASSERT_PTR(userdata);
        int r;
 
        assert(rvalue);
 
        r = route_scope_from_string(rvalue);
        if (r < 0)
                return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
 
        route->scope = r;
        route->scope_set = true;
        return 1;
}
 
static int config_parse_route_table(
                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) {
 
        Route *route = ASSERT_PTR(userdata);
        Manager *manager = ASSERT_PTR(ASSERT_PTR(route->network)->manager);
        int r;
 
        assert(rvalue);
 
        r = manager_get_route_table_from_string(manager, rvalue, &route->table);
        if (r < 0)
                return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
 
        route->table_set = true;
        return 1;
}
 
static int config_parse_route_preference(
                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) {
 
        Route *route = ASSERT_PTR(userdata);
 
        assert(rvalue);
 
        if (streq(rvalue, "low"))
                route->pref = SD_NDISC_PREFERENCE_LOW;
        else if (streq(rvalue, "medium"))
                route->pref = SD_NDISC_PREFERENCE_MEDIUM;
        else if (streq(rvalue, "high"))
                route->pref = SD_NDISC_PREFERENCE_HIGH;
        else
                return log_syntax_parse_error(unit, filename, line, 0, lvalue, rvalue);
 
        route->pref_set = true;
        return 1;
}
 
static int config_parse_route_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) {
 
        unsigned char *p = ASSERT_PTR(data);
        int r;
 
        assert(rvalue);
 
        r = route_protocol_from_string(rvalue);
        if (r < 0)
                return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
 
        *p = (unsigned char) r;
        return 1;
}
 
static int config_parse_route_type(
                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) {
 
        unsigned char *p = ASSERT_PTR(data);
        int r;
 
        assert(rvalue);
 
        r = route_type_from_string(rvalue);
        if (r < 0)
                return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
 
        *p = (unsigned char) r;
        return 1;
}
 
int config_parse_route_section(
                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) {
 
        static const ConfigSectionParser table[_ROUTE_CONF_PARSER_MAX] = {
                [ROUTE_DESTINATION]               = { .parser = config_parse_route_destination,      .ltype = 0,                       .offset = 0,                                                   },
                [ROUTE_PREFERRED_SOURCE]          = { .parser = config_parse_preferred_src,          .ltype = 0,                       .offset = 0,                                                   },
                [ROUTE_PRIORITY]                  = { .parser = config_parse_route_priority,         .ltype = 0,                       .offset = 0,                                                   },
                [ROUTE_SCOPE]                     = { .parser = config_parse_route_scope,            .ltype = 0,                       .offset = 0,                                                   },
                [ROUTE_TABLE]                     = { .parser = config_parse_route_table,            .ltype = 0,                       .offset = 0,                                                   },
                [ROUTE_PREFERENCE]                = { .parser = config_parse_route_preference,       .ltype = 0,                       .offset = 0,                                                   },
                [ROUTE_PROTOCOL]                  = { .parser = config_parse_route_protocol,         .ltype = 0,                       .offset = offsetof(Route, protocol),                           },
                [ROUTE_TYPE]                      = { .parser = config_parse_route_type,             .ltype = 0,                       .offset = offsetof(Route, type),                               },
                [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,                                                   },
                [ROUTE_METRIC_INITCWND]           = { .parser = config_parse_route_metric,           .ltype = RTAX_INITCWND,           .offset = 0,                                                   },
                [ROUTE_METRIC_RTO_MIN]            = { .parser = config_parse_route_metric,           .ltype = RTAX_RTO_MIN,            .offset = 0,                                                   },
                [ROUTE_METRIC_INITRWND]           = { .parser = config_parse_route_metric,           .ltype = RTAX_INITRWND,           .offset = 0,                                                   },
                [ROUTE_METRIC_QUICKACK]           = { .parser = config_parse_route_metric,           .ltype = RTAX_QUICKACK,           .offset = 0,                                                   },
                [ROUTE_METRIC_CC_ALGO]            = { .parser = config_parse_string,                 .ltype = 0,                       .offset = offsetof(Route, metric.tcp_congestion_control_algo), },