summaryrefslogtreecommitdiff
path: root/plugins/ethernet.c
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2011-07-25 16:24:32 +0200
committerMarcel Holtmann <marcel@holtmann.org>2011-07-26 01:21:45 +0200
commit7a74f89c8faf0834aa7de8d7724b868754632de3 (patch)
tree43fbfd03c2f442b817344a5470d3473dfc7accbb /plugins/ethernet.c
parent033a47bed7bd72eb712f7f51dd17985b89c087e0 (diff)
downloadconnman-7a74f89c8faf0834aa7de8d7724b868754632de3.tar.gz
connman-7a74f89c8faf0834aa7de8d7724b868754632de3.tar.bz2
connman-7a74f89c8faf0834aa7de8d7724b868754632de3.zip
ethernet: Take ownership of network objects
Therefore destroy network objects when the carrier goes offline.
Diffstat (limited to 'plugins/ethernet.c')
-rw-r--r--plugins/ethernet.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/plugins/ethernet.c b/plugins/ethernet.c
index 2ccd4989..5c026405 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);
}