+static int link_set_dhcp_routes(Link *link) {
+ struct sd_dhcp_route *static_routes;
+ int r, n, i;
+
+ assert(link);
+
+ n = sd_dhcp_lease_get_routes(link->dhcp_lease, &static_routes);
+ if (n < 0) {
+ if (n != -ENOENT)
+ log_warning_link(link, "DHCP error: could not get routes: %s", strerror(-n));
+ return n;
+ }
+
+ for (i = 0; i < n; i++) {
+ _cleanup_route_free_ Route *route = NULL;
+
+ 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->in_addr.in = static_routes[i].gw_addr;
+ route->dst_addr.in = static_routes[i].dst_addr;
+ route->dst_prefixlen = static_routes[i].dst_prefixlen;
+ route->metrics = DHCP_ROUTE_METRIC;
+
+ r = route_configure(route, link, &route_handler);
+ if (r < 0) {
+ log_warning_link(link,
+ "could not set host route: %s", strerror(-r));
+ return r;
+ }
+
+ link->route_messages ++;
+ }
+
+ return 0;
+}
+