[PATCH] network: Properly remove addresses When DHCPv4 lease is lost

2014-05-14 Thread Patrik Flykt
As addresses were not properly removed, the D-Bus API showed IP
addresses even if the interface addresses and routing is removed
when the DHCP lease has been lost. Also ensure that the network
is no longer associating, should the lease have been lost at
startup.

As the DHCP will nowadays continue trying after a lease is lost,
don't make the upper layers stop the DHCP procedure. Add better
logging so that lease acquired and lost can be properly noticed.
---
 src/network.c | 21 ++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/network.c b/src/network.c
index ce6fa85..39ab8e9 100644
--- a/src/network.c
+++ b/src/network.c
@@ -157,6 +157,8 @@ static void dhcp_success(struct connman_network *network)
 
network-connecting = false;
 
+   DBG(lease acquired for ipconfig %p, ipconfig_ipv4);
+
ipconfig_ipv4 = __connman_service_get_ip4config(service);
err = __connman_ipconfig_address_add(ipconfig_ipv4);
if (err  0)
@@ -175,14 +177,27 @@ err:
 
 static void dhcp_failure(struct connman_network *network)
 {
-   __connman_dhcp_stop(network);
+   struct connman_service *service;
+   struct connman_ipconfig *ipconfig_ipv4;
+
+   service = connman_service_lookup_from_network(network);
+   if (!service)
+   return;
+
+   connman_network_set_associating(network, false);
+   network-connecting = false;
+
+   ipconfig_ipv4 = __connman_service_get_ip4config(service);
+
+   DBG(lease lost for ipconfig %p, ipconfig_ipv4);
+
+   __connman_ipconfig_address_remove(ipconfig_ipv4);
+   __connman_ipconfig_gateway_remove(ipconfig_ipv4);
 }
 
 static void dhcp_callback(struct connman_network *network,
bool success, gpointer data)
 {
-   DBG(success %d, success);
-
if (success)
dhcp_success(network);
else
-- 
1.9.1

___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman


Re: [PATCH] network: Properly remove addresses When DHCPv4 lease is lost

2014-05-14 Thread Patrik Flykt
On Wed, 2014-05-14 at 09:35 +0300, Patrik Flykt wrote:
 As addresses were not properly removed, the D-Bus API showed IP
 addresses even if the interface addresses and routing is removed
 when the DHCP lease has been lost. Also ensure that the network
 is no longer associating, should the lease have been lost at
 startup.
 
 As the DHCP will nowadays continue trying after a lease is lost,
 don't make the upper layers stop the DHCP procedure. Add better
 logging so that lease acquired and lost can be properly noticed.

Applied, fixed commit message and checked that ipconfig_ipv4 is non-NULL
before use.

Patrik

___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman