This fix sends the DHCP_REQUESTED_IP option to server.
Fixes BMC #21068
---
gdhcp/client.c | 22 ++++++++++++++++++----
gdhcp/gdhcp.h | 2 +-
src/dhcp.c | 23 ++++++++++++++++++++++-
tools/dhcp-test.c | 2 +-
4 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/gdhcp/client.c b/gdhcp/client.c
index 0cf39cd..9ac7752 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -109,6 +109,7 @@ struct _GDHCPClient {
gpointer address_conflict_data;
GDHCPDebugFunc debug_func;
gpointer debug_data;
+ char *last_address;
};
static inline void debug(GDHCPClient *client, const char *format, ...)
@@ -879,7 +880,7 @@ static void restart_dhcp(GDHCPClient *dhcp_client, int
retry_times)
dhcp_client->requested_ip = 0;
switch_listening_mode(dhcp_client, L2);
- g_dhcp_client_start(dhcp_client);
+ g_dhcp_client_start(dhcp_client, dhcp_client->last_address);
}
static gboolean start_rebound_timeout(gpointer user_data)
@@ -1240,7 +1241,7 @@ static gboolean discover_timeout(gpointer user_data)
dhcp_client->retry_times++;
- g_dhcp_client_start(dhcp_client);
+ g_dhcp_client_start(dhcp_client, dhcp_client->last_address);
return FALSE;
}
@@ -1306,9 +1307,10 @@ static gboolean ipv4ll_probe_timeout(gpointer dhcp_data)
return FALSE;
}
-int g_dhcp_client_start(GDHCPClient *dhcp_client)
+int g_dhcp_client_start(GDHCPClient *dhcp_client, const char *last_address)
{
int re;
+ uint32_t addr;
if (dhcp_client->retry_times == DISCOVER_RETRIES) {
ipv4ll_start(dhcp_client);
@@ -1327,7 +1329,18 @@ int g_dhcp_client_start(GDHCPClient *dhcp_client)
dhcp_client->xid = rand();
}
- send_discover(dhcp_client, 0);
+ if (last_address == NULL)
+ addr = 0;
+ else {
+ addr = inet_addr(last_address);
+ if (addr == 0xFFFFFFFF)
+ addr = 0;
+ else {
+ g_free(dhcp_client->last_address);
+ dhcp_client->last_address = g_strdup(last_address);
+ }
+ }
+ send_discover(dhcp_client, addr);
dhcp_client->timeout = g_timeout_add_seconds_full(G_PRIORITY_HIGH,
DISCOVER_TIMEOUT,
@@ -1505,6 +1518,7 @@ void g_dhcp_client_unref(GDHCPClient *dhcp_client)
g_free(dhcp_client->interface);
g_free(dhcp_client->assigned_ip);
+ g_free(dhcp_client->last_address);
g_list_free(dhcp_client->request_list);
g_list_free(dhcp_client->require_list);
diff --git a/gdhcp/gdhcp.h b/gdhcp/gdhcp.h
index 4f583ff..d89446e 100644
--- a/gdhcp/gdhcp.h
+++ b/gdhcp/gdhcp.h
@@ -73,7 +73,7 @@ typedef void (*GDHCPDebugFunc)(const char *str, gpointer
user_data);
GDHCPClient *g_dhcp_client_new(GDHCPType type, int index,
GDHCPClientError *error);
-int g_dhcp_client_start(GDHCPClient *client);
+int g_dhcp_client_start(GDHCPClient *client, const char *last_address);
void g_dhcp_client_stop(GDHCPClient *client);
GDHCPClient *g_dhcp_client_ref(GDHCPClient *client);
diff --git a/src/dhcp.c b/src/dhcp.c
index 20fc599..63edfe9 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -42,6 +42,7 @@ struct connman_dhcp {
char **nameservers;
char *timeserver;
char *pac;
+ char *last_address;
GDHCPClient *dhcp_client;
};
@@ -53,10 +54,12 @@ static void dhcp_free(struct connman_dhcp *dhcp)
g_strfreev(dhcp->nameservers);
g_free(dhcp->timeserver);
g_free(dhcp->pac);
+ g_free(dhcp->last_address);
dhcp->nameservers = NULL;
dhcp->timeserver = NULL;
dhcp->pac = NULL;
+ dhcp->last_address = NULL;
}
/**
@@ -103,6 +106,10 @@ static void dhcp_invalidate(struct connman_dhcp *dhcp,
connman_bool_t callback)
}
}
+ __connman_ipconfig_set_dhcp_address(ipconfig, dhcp->last_address);
+
+ DBG("last address %s", dhcp->last_address);
+
__connman_ipconfig_address_remove(ipconfig);
__connman_ipconfig_set_local(ipconfig, NULL);
@@ -204,6 +211,12 @@ static void lease_available_cb(GDHCPClient *dhcp_client,
gpointer user_data)
address = g_dhcp_client_get_address(dhcp_client);
+ g_free(dhcp->last_address);
+ dhcp->last_address = g_strdup(address);
+ __connman_ipconfig_set_dhcp_address(ipconfig, dhcp->last_address);
+
+ DBG("last address %s", address);
+
option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET);
if (option != NULL)
netmask = g_strdup(option->data);
@@ -409,7 +422,7 @@ static int dhcp_request(struct connman_dhcp *dhcp)
dhcp->dhcp_client = dhcp_client;
- return g_dhcp_client_start(dhcp_client);
+ return g_dhcp_client_start(dhcp_client, dhcp->last_address);
}
static int dhcp_release(struct connman_dhcp *dhcp)
@@ -442,6 +455,8 @@ static void remove_network(gpointer user_data)
int __connman_dhcp_start(struct connman_network *network, dhcp_cb callback)
{
struct connman_dhcp *dhcp;
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig;
DBG("");
@@ -452,6 +467,12 @@ int __connman_dhcp_start(struct connman_network *network,
dhcp_cb callback)
dhcp->network = network;
dhcp->callback = callback;
+ service = __connman_service_lookup_from_network(network);
+ ipconfig = __connman_service_get_ip4config(service);
+ dhcp->last_address = __connman_ipconfig_get_dhcp_address(ipconfig);
+
+ DBG("last address %s", dhcp->last_address);
+
g_hash_table_replace(network_table, network, dhcp);
return dhcp_request(dhcp);
diff --git a/tools/dhcp-test.c b/tools/dhcp-test.c
index 1fbf1f9..18527c8 100644
--- a/tools/dhcp-test.c
+++ b/tools/dhcp-test.c
@@ -170,7 +170,7 @@ int main(int argc, char *argv[])
timer = g_timer_new();
- g_dhcp_client_start(dhcp_client);
+ g_dhcp_client_start(dhcp_client, NULL);
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sig_term;
--
1.7.1
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman