r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -EEXIST) {
- log_error_link(link, "could not set DHCPv4 route: %s",
+ log_link_error(link, "could not set DHCPv4 route: %s",
strerror(-r));
link_enter_failed(link);
}
r = sd_dhcp_lease_get_router(link->dhcp_lease, &gateway);
if (r < 0 && r != -ENOENT) {
- log_warning_link(link,
+ log_link_warning(link,
"DHCP error: could not get gateway: %s",
strerror(-r));
return r;
r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
if (r < 0) {
- log_warning_link(link,
+ log_link_warning(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,
+ log_link_error(link,
"Could not allocate route: %s",
strerror(-r));
return r;
r = route_new_dynamic(&route_gw, RTPROT_DHCP);
if (r < 0) {
- log_error_link(link,
+ log_link_error(link,
"Could not allocate route: %s",
strerror(-r));
return r;
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) {
- log_warning_link(link,
+ log_link_warning(link,
"could not set host route: %s",
strerror(-r));
return r;
route->family = AF_INET;
route->in_addr.in = gateway;
route->prefsrc_addr.in = address;
- route->metrics = DHCP_ROUTE_METRIC;
+ route->metrics = link->network->dhcp_route_metric;
r = route_configure(route, link, &dhcp4_route_handler);
if (r < 0) {
- log_warning_link(link,
+ log_link_warning(link,
"could not set routes: %s",
strerror(-r));
link_enter_failed(link);
if (n == -ENOENT)
return 0;
if (n < 0) {
- log_warning_link(link,
+ log_link_warning(link,
"DHCP error: could not get routes: %s",
strerror(-n));
r = route_new_dynamic(&route, RTPROT_DHCP);
if (r < 0) {
- log_error_link(link, "Could not allocate route: %s",
+ log_link_error(link, "Could not allocate route: %s",
strerror(-r));
return r;
}
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) {
- log_warning_link(link,
+ log_link_warning(link,
"could not set host route: %s",
strerror(-r));
return r;
struct in_addr addr;
struct in_addr netmask;
struct in_addr gateway;
- unsigned prefixlen;
+ unsigned prefixlen = 0;
int r;
assert(link);
assert(link->dhcp_lease);
- log_warning_link(link, "DHCP lease lost");
+ log_link_warning(link, "DHCP lease lost");
if (link->network->dhcp_routes) {
struct sd_dhcp_route *routes;
}
}
- 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) {
if (r >= 0 && link->original_mtu != mtu) {
r = link_set_mtu(link, link->original_mtu);
if (r < 0) {
- log_warning_link(link,
+ log_link_warning(link,
"DHCP error: could not reset MTU");
link_enter_failed(link);
return r;
if (r >= 0 && hostname) {
r = link_set_hostname(link, "");
if (r < 0)
- log_error_link(link,
+ log_link_error(link,
"Failed to reset transient hostname");
}
}
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -EEXIST) {
- log_error_link(link, "could not set DHCPv4 address: %s",
+ log_link_error(link, "could not set DHCPv4 address: %s",
strerror(-r));
link_enter_failed(link);
} else if (r >= 0) {
r = sd_dhcp_client_get_lease(client, &lease);
if (r < 0) {
- log_warning_link(link, "DHCP error: no lease %s",
+ log_link_warning(link, "DHCP error: no lease %s",
strerror(-r));
return r;
}
r = sd_dhcp_lease_get_address(lease, &address);
if (r < 0) {
- log_warning_link(link, "DHCP error: no address: %s",
+ log_link_warning(link, "DHCP error: no address: %s",
strerror(-r));
return r;
}
r = sd_dhcp_lease_get_netmask(lease, &netmask);
if (r < 0) {
- log_warning_link(link, "DHCP error: no netmask: %s",
+ log_link_warning(link, "DHCP error: no netmask: %s",
strerror(-r));
return r;
}
r = sd_dhcp_lease_get_lifetime(link->dhcp_lease,
&lifetime);
if (r < 0) {
- log_warning_link(link,
+ log_link_warning(link,
"DHCP error: no lifetime: %s",
strerror(-r));
return r;
r = dhcp4_update_address(link, &address, &netmask, lifetime);
if (r < 0) {
- log_warning_link(link, "could not update IP address: %s",
+ log_link_warning(link, "could not update IP address: %s",
strerror(-r));
link_enter_failed(link);
return r;
r = sd_dhcp_client_get_lease(client, &lease);
if (r < 0) {
- log_warning_link(link, "DHCP error: no lease: %s",
+ log_link_warning(link, "DHCP error: no lease: %s",
strerror(-r));
return r;
}
r = sd_dhcp_lease_get_address(lease, &address);
if (r < 0) {
- log_warning_link(link, "DHCP error: no address: %s",
+ log_link_warning(link, "DHCP error: no address: %s",
strerror(-r));
return r;
}
r = sd_dhcp_lease_get_netmask(lease, &netmask);
if (r < 0) {
- log_warning_link(link, "DHCP error: no netmask: %s",
+ log_link_warning(link, "DHCP error: no netmask: %s",
strerror(-r));
return r;
}
r = sd_dhcp_lease_get_router(lease, &gateway);
if (r < 0 && r != -ENOENT) {
- log_warning_link(link, "DHCP error: could not get gateway: %s",
+ log_link_warning(link, "DHCP error: could not get gateway: %s",
strerror(-r));
return r;
}
if (r >= 0)
- log_struct_link(LOG_INFO, link,
+ log_link_struct(link, LOG_INFO,
"MESSAGE=%-*s: DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u",
IFNAMSIZ,
link->ifname,
ADDRESS_FMT_VAL(gateway),
NULL);
else
- log_struct_link(LOG_INFO, link,
+ log_link_struct(link, LOG_INFO,
"MESSAGE=%-*s: DHCPv4 address %u.%u.%u.%u/%u",
IFNAMSIZ,
link->ifname,
if (r >= 0) {
r = link_set_mtu(link, mtu);
if (r < 0)
- log_error_link(link, "Failed to set MTU "
+ log_link_error(link, "Failed to set MTU "
"to %" PRIu16, mtu);
}
}
if (r >= 0) {
r = link_set_hostname(link, hostname);
if (r < 0)
- log_error_link(link,
+ log_link_error(link,
"Failed to set transient hostname to '%s'",
hostname);
}
r = sd_dhcp_lease_get_lifetime(link->dhcp_lease,
&lifetime);
if (r < 0) {
- log_warning_link(link,
+ log_link_warning(link,
"DHCP error: no lifetime: %s",
strerror(-r));
return r;
r = dhcp4_update_address(link, &address, &netmask, lifetime);
if (r < 0) {
- log_warning_link(link, "could not update IP address: %s",
+ log_link_warning(link, "could not update IP address: %s",
strerror(-r));
link_enter_failed(link);
return r;
case DHCP_EVENT_STOP:
case DHCP_EVENT_IP_CHANGE:
if (link->network->dhcp_critical) {
- log_error_link(link,
+ log_link_error(link,
"DHCPv4 connection considered system critical, ignoring request to reconfigure it.");
return;
}
break;
default:
if (event < 0)
- log_warning_link(link,
+ log_link_warning(link,
"DHCP error: client failed: %s",
strerror(-event));
else
- log_warning_link(link,
+ log_link_warning(link,
"DHCP unknown event: %d",
event);
break;
if (r < 0)
return r;
- r = sd_dhcp_client_set_mac(link->dhcp_client, &link->mac);
+ r = sd_dhcp_client_set_mac(link->dhcp_client,
+ (const uint8_t *) &link->mac,
+ sizeof (link->mac), ARPHRD_ETHER);
if (r < 0)
return r;