+ if (link->ipv4ll && !link->dhcp_lease) {
+ _cleanup_route_free_ Route *route = NULL;
+ struct in_addr addr;
+
+ r = sd_ipv4ll_get_address(link->ipv4ll, &addr);
+ if (r < 0 && r != -ENOENT) {
+ log_warning_link(link, "IPV4LL error: no address: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if (r != -ENOENT) {
+ r = route_new_dynamic(&route);
+ if (r < 0) {
+ log_error_link(link, "Could not allocate route: %s",
+ strerror(-r));
+ return r;
+ }
+
+ route->family = AF_INET;
+ route->scope = RT_SCOPE_LINK;
+ route->metrics = 99;
+
+ r = route_configure(route, link, &route_handler);
+ if (r < 0) {
+ log_warning_link(link,
+ "could not set routes: %s", strerror(-r));
+ link_enter_failed(link);
+ return r;
+ }
+
+ link->route_messages ++;
+ }
+ }
+
+ if (link->dhcp_lease) {
+ _cleanup_route_free_ Route *route = NULL;
+ _cleanup_route_free_ Route *route_gw = NULL;
+ struct in_addr gateway;
+
+ r = sd_dhcp_lease_get_router(link->dhcp_lease, &gateway);
+ if (r < 0) {
+ log_warning_link(link, "DHCP error: no router: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = route_new_dynamic(&route);
+ if (r < 0) {
+ log_error_link(link, "Could not allocate route: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = route_new_dynamic(&route_gw);
+ if (r < 0) {
+ log_error_link(link, "Could not allocate route: %s",
+ strerror(-r));
+ return r;
+ }
+
+ /* The dhcp netmask may mask out the gateway. Add an explicit
+ * route for the gw host so that we can route no matter the
+ * netmask or existing kernel route tables. */
+ route_gw->family = AF_INET;
+ route_gw->dst_addr.in = gateway;
+ route_gw->dst_prefixlen = 32;
+ route_gw->scope = RT_SCOPE_LINK;
+
+ r = route_configure(route_gw, link, &route_handler);
+ if (r < 0) {
+ log_warning_link(link,
+ "could not set host route: %s", strerror(-r));
+ return r;
+ }
+
+ link->route_messages ++;
+
+ route->family = AF_INET;
+ route->in_addr.in = gateway;
+
+ r = route_configure(route, link, &route_handler);