dhcp: track last IPv4 address on start for renewal

Really only used by systemd because it doesn't have as good lease
handling, but it's also necessary if we switch DHCP clients mid-stream
(which we'll be doing later) since the new DHCP client won't
have a lease file for the current IP address, and thus has nowhere
to pull the current IP address from to request the same address
from the DHCP server.
This commit is contained in:
Dan Williams
2014-11-03 22:35:22 -06:00
parent 034917e129
commit 49cac9f32f
8 changed files with 32 additions and 23 deletions

View File

@@ -515,7 +515,7 @@ get_arp_type (const GByteArray *hwaddr)
}
static gboolean
ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr)
ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last_ip4_address)
{
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (client);
const char *iface = nm_dhcp_client_get_iface (client);
@@ -524,7 +524,7 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr)
GBytes *override_client_id;
const uint8_t *client_id = NULL;
size_t client_id_len = 0;
struct in_addr last_addr;
struct in_addr last_addr = { 0 };
const char *hostname;
int r, i;
@@ -578,14 +578,16 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr)
sd_dhcp_lease_load (priv->lease_file, &lease);
if (lease) {
r = sd_dhcp_lease_get_address (lease, &last_addr);
if (r == 0) {
r = sd_dhcp_client_set_request_address (priv->client4, &last_addr);
if (r < 0) {
nm_log_warn (LOGD_DHCP4, "(%s): failed to set last IPv4 address (%d)", iface, r);
goto error;
}
if (last_ip4_address)
inet_pton (AF_INET, last_ip4_address, &last_addr);
else if (lease)
sd_dhcp_lease_get_address (lease, &last_addr);
if (last_addr.s_addr) {
r = sd_dhcp_client_set_request_address (priv->client4, &last_addr);
if (r < 0) {
nm_log_warn (LOGD_DHCP4, "(%s): failed to set last IPv4 address (%d)", iface, r);
goto error;
}
}