return r;
}
if (r >= 0) {
+ struct in_addr address;
_cleanup_route_free_ Route *route = NULL;
_cleanup_route_free_ Route *route_gw = NULL;
+ r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
+ if (r < 0) {
+ log_warning_link(link,
+ "DHCP error: could not get address: %s",
+ strerror(-r));
+ return r;
+ }
+
r = route_new_dynamic(&route, RTPROT_DHCP);
if (r < 0) {
log_error_link(link,
route_gw->family = AF_INET;
route_gw->dst_addr.in = gateway;
route_gw->dst_prefixlen = 32;
+ route_gw->prefsrc_addr.in = address;
route_gw->scope = RT_SCOPE_LINK;
- route_gw->metrics = DHCP_ROUTE_METRIC;
+ route_gw->metrics = link->network->dhcp_route_metric;
r = route_configure(route_gw, link, &dhcp4_route_handler);
if (r < 0) {
route->family = AF_INET;
route->in_addr.in = gateway;
- route->metrics = DHCP_ROUTE_METRIC;
+ route->prefsrc_addr.in = address;
+ route->metrics = link->network->dhcp_route_metric;
r = route_configure(route, link, &dhcp4_route_handler);
if (r < 0) {
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;
+ route->metrics = link->network->dhcp_route_metric;
r = route_configure(route, link, &dhcp4_route_handler);
if (r < 0) {
struct in_addr addr;
struct in_addr netmask;
struct in_addr gateway;
- unsigned prefixlen;
+ unsigned prefixlen = 0;
int r;
assert(link);
}
}
- sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
- sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
- prefixlen = in_addr_netmask_to_prefixlen(&netmask);
+ r = sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
+ if (r >= 0) {
+ r = sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
+ if (r >= 0)
+ prefixlen = in_addr_netmask_to_prefixlen(&netmask);
- address->family = AF_INET;
- address->in_addr.in = addr;
- address->prefixlen = prefixlen;
+ address->family = AF_INET;
+ address->in_addr.in = addr;
+ address->prefixlen = prefixlen;
- address_drop(address, link, &link_address_drop_handler);
+ address_drop(address, link, &link_address_drop_handler);
+ }
}
if (link->network->dhcp_mtu) {