---
src/connman.h | 6 ++++
src/dhcp.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/ipconfig.c | 23 +++++++++++++
src/service.c | 6 ++++
4 files changed, 135 insertions(+)
diff --git a/src/connman.h b/src/connman.h
index 0e3ec47..acf3db6 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -392,6 +392,8 @@ char *__connman_ipconfig_get_dhcp_address(struct
connman_ipconfig *ipconfig);
void __connman_ipconfig_set_dhcpv6_prefixes(struct connman_ipconfig *ipconfig,
char **prefixes);
char **__connman_ipconfig_get_dhcpv6_prefixes(struct connman_ipconfig
*ipconfig);
+void __connman_ipconfig_set_dhcp(struct connman_ipconfig *ipconfig,
+ void *dhcp);
int __connman_ipconfig_load(struct connman_ipconfig *ipconfig,
GKeyFile *keyfile, const char *identifier, const char *prefix);
@@ -438,6 +440,8 @@ int __connman_dhcp_start(struct connman_network *network,
dhcp_cb callback);
void __connman_dhcp_stop(struct connman_network *network);
int __connman_dhcp_init(void);
void __connman_dhcp_cleanup(void);
+void __connman_dhcp_append_stats( DBusMessageIter *iter,
+ void *dhcp);
int __connman_dhcpv6_init(void);
void __connman_dhcpv6_cleanup(void);
int __connman_dhcpv6_start_info(struct connman_network *network,
@@ -710,6 +714,8 @@ void __connman_service_return_error(struct connman_service
*service,
void __connman_service_reply_dbus_pending(DBusMessage *pending, int error,
const char *path);
+void __connman_service_ipconfig_changed(struct connman_service *service,
+ struct connman_ipconfig *ipconfig);
int __connman_service_provision_changed(const char *ident);
void __connman_service_set_config(struct connman_service *service,
const char *file_id, const char *section);
diff --git a/src/dhcp.c b/src/dhcp.c
index ac12ff4..25e7488 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -52,6 +52,13 @@ struct connman_dhcp {
GDHCPClient *dhcp_client;
char *ipv4ll_debug_prefix;
char *dhcp_debug_prefix;
+
+ char* state;
+ time_t lease_time;
+ uint32_t lease_seconds;
+ time_t last_renew;
+ time_t last_rebind;
+ time_t expire;
};
static GHashTable *network_table;
@@ -120,6 +127,13 @@ static void dhcp_invalidate(struct connman_dhcp *dhcp,
bool callback)
__connman_ipconfig_set_dhcp_address(ipconfig,
__connman_ipconfig_get_local(ipconfig));
+ __connman_ipconfig_set_dhcp(ipconfig, NULL);
+
+ dhcp->lease_seconds = 0;
+ dhcp->last_renew = 0;
+ dhcp->last_rebind = 0;
+ dhcp->expire = 0;
+
DBG("last address %s", __connman_ipconfig_get_dhcp_address(ipconfig));
__connman_ipconfig_address_remove(ipconfig);
@@ -331,10 +345,15 @@ static void lease_available_cb(GDHCPClient *dhcp_client,
gpointer user_data)
c_prefixlen = __connman_ipconfig_get_prefixlen(ipconfig);
address = g_dhcp_client_get_address(dhcp_client);
+ dhcp->lease_time = time(NULL);
__connman_ipconfig_set_dhcp_address(ipconfig, address);
+ __connman_ipconfig_set_dhcp(ipconfig, dhcp);
DBG("last address %s", address);
+ g_dhcp_client_get_timeouts(dhcp_client,&(dhcp->lease_seconds),
+
&(dhcp->last_renew),&(dhcp->last_rebind),&(dhcp->expire));
+
option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET);
if (option)
netmask = g_strdup(option->data);
@@ -457,6 +476,51 @@ static void lease_available_cb(GDHCPClient *dhcp_client,
gpointer user_data)
g_free(gateway);
}
+static void lease_renew_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+ struct connman_dhcp *dhcp = user_data;
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig;
+
+ //copy info into local storage
+ g_dhcp_client_get_timeouts(dhcp_client,&(dhcp->lease_seconds),
+
&(dhcp->last_renew),&(dhcp->last_rebind),&(dhcp->expire));
+ //inform service about the change
+ service = connman_service_lookup_from_network(dhcp->network);
+ if (service == NULL)
+ return;
+
+ ipconfig = __connman_service_get_ip4config(service);
+ if (ipconfig == NULL)
+ return;
+ __connman_service_ipconfig_changed(service,ipconfig);
+}
+
+static void dhcp_state_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+
+ struct connman_dhcp *dhcp = user_data;
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig;
+ const char *state;
+
+ state = g_dhcp_client_get_state(dhcp_client);
+
+ g_free(dhcp->state);
+ dhcp->state = g_strdup(state);
+
+ //inform service about the change
+ service = connman_service_lookup_from_network(dhcp->network);
+ if (service == NULL)
+ return;
+ ipconfig = __connman_service_get_ip4config(service);
+ if (ipconfig == NULL)
+ return;
+ __connman_service_ipconfig_changed(service,ipconfig);
+
+}
+
+
static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client, gpointer user_data)
{
struct connman_dhcp *dhcp = user_data;
@@ -544,6 +608,12 @@ static int dhcp_request(struct connman_dhcp *dhcp)
g_dhcp_client_register_event(dhcp_client,
G_DHCP_CLIENT_EVENT_NO_LEASE, no_lease_cb, dhcp);
+ g_dhcp_client_register_event(dhcp_client,
+ G_DHCP_CLIENT_EVENT_RENEW, lease_renew_cb, dhcp);
+
+ g_dhcp_client_register_event(dhcp_client,
+ G_DHCP_CLIENT_EVENT_CHANGED, dhcp_state_cb, dhcp);
+
dhcp->dhcp_client = dhcp_client;
ipconfig = __connman_service_get_ip4config(service);
@@ -646,3 +716,33 @@ void __connman_dhcp_cleanup(void)
g_hash_table_destroy(network_table);
network_table = NULL;
}
+
+void __connman_dhcp_append_stats( DBusMessageIter *iter,
+ void *dhcp_in)
+{
+ struct connman_dhcp *dhcp = dhcp_in;
+
+ if (dhcp_in == NULL)
+ return;
+
+ if (dhcp->lease_time!= 0)
+ connman_dbus_dict_append_basic(iter, "LeaseTime",
+ DBUS_TYPE_UINT32, &dhcp->lease_time);
+
+ if (dhcp->last_renew!= 0)
+ connman_dbus_dict_append_basic(iter, "LastRenew",
+ DBUS_TYPE_UINT32, &dhcp->last_renew);
+
+ if (dhcp->last_rebind!= 0)
+ connman_dbus_dict_append_basic(iter, "LastRebind",
+ DBUS_TYPE_UINT32, &dhcp->last_rebind);
+
+ if (dhcp->expire!= 0)
+ connman_dbus_dict_append_basic(iter, "LeaseExpiration",
+ DBUS_TYPE_UINT32, &dhcp->expire);
+
+ if (dhcp->state!= NULL)
+ connman_dbus_dict_append_basic(iter, "State",
+ DBUS_TYPE_STRING, &dhcp->state);
+
+}
diff --git a/src/ipconfig.c b/src/ipconfig.c
index cfa8a7a..a5f0873 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -58,6 +58,7 @@ struct connman_ipconfig {
int ipv6_privacy_config;
char *last_dhcp_address;
char **last_dhcpv6_prefixes;
+ void *dhcp;
};
struct connman_ipdevice {
@@ -1478,6 +1479,16 @@ void __connman_ipconfig_set_dhcp_address(struct
connman_ipconfig *ipconfig,
ipconfig->last_dhcp_address = g_strdup(address);
}
+void __connman_ipconfig_set_dhcp(struct connman_ipconfig *ipconfig,
+ void *dhcp)
+{
+ if (ipconfig == NULL)
+ return;
+
+ ipconfig->dhcp= dhcp;
+
+}
+
char *__connman_ipconfig_get_dhcp_address(struct connman_ipconfig *ipconfig)
{
if (!ipconfig)
@@ -1793,6 +1804,12 @@ int __connman_ipconfig_ipv6_set_privacy(struct
connman_ipconfig *ipconfig,
return 0;
}
+static void append_dhcp(DBusMessageIter *iter, void *user_data)
+{
+ struct connman_dhcp* dhcp = user_data;
+ __connman_dhcp_append_stats(iter, dhcp);
+
+}
void __connman_ipconfig_append_ipv4(struct connman_ipconfig *ipconfig,
DBusMessageIter *iter)
{
@@ -1847,6 +1864,12 @@ void __connman_ipconfig_append_ipv4(struct
connman_ipconfig *ipconfig,
if (append_addr->gateway)
connman_dbus_dict_append_basic(iter, "Gateway",
DBUS_TYPE_STRING, &append_addr->gateway);
+
+ if (ipconfig->method == CONNMAN_IPCONFIG_METHOD_DHCP){
+ connman_dbus_dict_append_dict(iter, "DHCP",
+ append_dhcp,ipconfig->dhcp);
+
+ }
}
void __connman_ipconfig_append_ipv6(struct connman_ipconfig *ipconfig,
diff --git a/src/service.c b/src/service.c
index 8753247..9989bda 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1811,6 +1811,12 @@ static void settings_changed(struct connman_service
*service,
__connman_notifier_ipconfig_changed(service, ipconfig);
}
+void __connman_service_ipconfig_changed(struct connman_service *service,
+ struct connman_ipconfig *ipconfig)
+{
+ settings_changed(service, ipconfig);
+}
+
static void ipv4_configuration_changed(struct connman_service *service)
{
if (!allow_property_changed(service))
--
1.7.9.5
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman