From 7a74f89c8faf0834aa7de8d7724b868754632de3 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Mon, 25 Jul 2011 16:24:32 +0200 Subject: [PATCH] ethernet: Take ownership of network objects Therefore destroy network objects when the carrier goes offline. --- plugins/ethernet.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/plugins/ethernet.c b/plugins/ethernet.c index 2ccd498..5c02640 100644 --- a/plugins/ethernet.c +++ b/plugins/ethernet.c @@ -82,7 +82,8 @@ static struct connman_network_driver cable_driver = { .disconnect = cable_disconnect, }; -static void add_network(struct connman_device *device) +static void add_network(struct connman_device *device, + struct ethernet_data *ethernet) { struct connman_network *network; int index; @@ -107,6 +108,23 @@ static void add_network(struct connman_device *device) connman_network_set_group(network, "cable"); connman_network_set_connected(network, TRUE); + + ethernet->network = network; +} + +static void remove_network(struct connman_device *device, + struct ethernet_data *ethernet) +{ + const char *identifier; + + if (ethernet->network == NULL) + return; + + identifier = connman_network_get_identifier(ethernet->network); + connman_device_remove_network(device, identifier); + connman_network_unref(ethernet->network); + + ethernet->network = NULL; } static void ethernet_newlink(unsigned flags, unsigned change, void *user_data) @@ -129,10 +147,10 @@ static void ethernet_newlink(unsigned flags, unsigned change, void *user_data) if ((ethernet->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) { if (flags & IFF_LOWER_UP) { DBG("carrier on"); - add_network(device); + add_network(device, ethernet); } else { DBG("carrier off"); - connman_device_remove_all_networks(device); + remove_network(device, ethernet); } } @@ -170,7 +188,7 @@ static void ethernet_remove(struct connman_device *device) connman_rtnl_remove_watch(ethernet->watch); - connman_device_remove_all_networks(device); + remove_network(device, ethernet); g_free(ethernet); } -- 2.7.4