summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2013-11-18 11:54:09 +0100
committerTom Gundersen <teg@jklm.no>2013-11-19 14:39:19 +0100
commit0617ffabe86a6d366252477eafbe59a888b149d4 (patch)
tree9fa24943465d2ce0dbc6d6b306c677d14b092496 /src
parentbc9cdba5ddf78d0ecb5c64f55621bb2f474ea280 (diff)
networkd: make sure Links and Networks are freed
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-link.c28
-rw-r--r--src/network/networkd-manager.c10
-rw-r--r--src/network/networkd-network.c2
-rw-r--r--src/network/networkd.h2
-rw-r--r--src/network/test-network.c2
5 files changed, 27 insertions, 17 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index dcc5cfe65a..d41fe80f20 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -28,7 +28,6 @@
int link_new(Manager *manager, struct udev_device *device, Link **ret) {
_cleanup_link_free_ Link *link = NULL;
- uint64_t ifindex;
const char *mac;
int r;
@@ -39,8 +38,8 @@ int link_new(Manager *manager, struct udev_device *device, Link **ret) {
if (!link)
return -ENOMEM;
- ifindex = udev_device_get_ifindex(device);
- if (ifindex <= 0)
+ link->ifindex = udev_device_get_ifindex(device);
+ if (link->ifindex <= 0)
return -EINVAL;
mac = udev_device_get_sysattr_value(device, "address");
@@ -48,11 +47,10 @@ int link_new(Manager *manager, struct udev_device *device, Link **ret) {
return -EINVAL;
memcpy(&link->mac.ether_addr_octet[0], ether_aton(mac), ETH_ALEN);
- link->ifindex = ifindex;
link->manager = manager;
link->state = _LINK_STATE_INVALID;
- r = hashmap_put(manager->links, &ifindex, link);
+ r = hashmap_put(manager->links, &link->ifindex, link);
if (r < 0)
return r;
@@ -66,9 +64,9 @@ void link_free(Link *link) {
if (!link)
return;
- network_free(link->network);
+ assert(link->manager);
- hashmap_remove(link->manager->links, link);
+ hashmap_remove(link->manager->links, &link->ifindex);
free(link);
}
@@ -125,7 +123,7 @@ static bool link_is_up(Link *link) {
}
static int link_enter_routes_set(Link *link) {
- log_info("Routes set for link %d", link->ifindex);
+ log_info("Routes set for link %u", (unsigned)link->ifindex);
if (link_is_up(link))
return link_enter_configured(link);
@@ -149,8 +147,8 @@ static int route_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -EEXIST) {
- log_warning("Could not set route on interface %d: %s",
- link->ifindex, strerror(-r));
+ log_warning("Could not set route on interface %u: %s",
+ (unsigned)link->ifindex, strerror(-r));
return link_enter_failed(link);
}
@@ -184,7 +182,7 @@ static int link_enter_set_routes(Link *link) {
}
static int link_enter_addresses_set(Link *link) {
- log_info("Addresses set for link %d", link->ifindex);
+ log_info("Addresses set for link %u", (unsigned)link->ifindex);
link->state = LINK_STATE_ADDRESSES_SET;
@@ -205,8 +203,8 @@ static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -EEXIST) {
- log_warning("Could not set address on interface %d: %s",
- link->ifindex, strerror(-r));
+ log_warning("Could not set address on interface %u: %s",
+ (unsigned)link->ifindex, strerror(-r));
link_enter_failed(link);
}
@@ -244,8 +242,8 @@ static int link_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
r = sd_rtnl_message_get_errno(m);
if (r < 0) {
- log_warning("Could not bring up interface %d: %s",
- link->ifindex, strerror(-r));
+ log_warning("Could not bring up interface %u: %s",
+ (unsigned)link->ifindex, strerror(-r));
return link_enter_failed(link);
}
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 5000674bd9..e376d38872 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -73,11 +73,21 @@ int manager_new(Manager **ret) {
}
void manager_free(Manager *m) {
+ Network *network;
+ Link *link;
+
udev_monitor_unref(m->udev_monitor);
udev_unref(m->udev);
sd_event_source_unref(m->udev_event_source);
sd_event_unref(m->event);
+
+ while ((network = m->networks))
+ network_free(network);
+
+ while ((link = hashmap_first(m->links)))
+ link_free(link);
hashmap_free(m->links);
+
strv_free(m->network_dirs);
sd_rtnl_unref(m->rtnl);
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 638343459c..d4239ab8d0 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -56,6 +56,8 @@ static int network_load_one(Manager *manager, const char *filename) {
if (!network->filename)
return log_oom();
+ network->manager = manager;
+
LIST_PREPEND(networks, manager->networks, network);
network = NULL;
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 7c23793cf9..498f2cdf09 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -101,7 +101,7 @@ typedef enum LinkState {
struct Link {
Manager *manager;
- int ifindex;
+ uint64_t ifindex;
struct ether_addr mac;
unsigned flags;
diff --git a/src/network/test-network.c b/src/network/test-network.c
index 7a7840ee16..822a334607 100644
--- a/src/network/test-network.c
+++ b/src/network/test-network.c
@@ -23,7 +23,7 @@
static void test_link(struct udev_device *loopback) {
_cleanup_manager_free_ Manager *manager = NULL;
- _cleanup_link_free_ Link *link = NULL;
+ Link *link = NULL;
manager_new(&manager);