summaryrefslogtreecommitdiff
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2013-11-21 21:04:04 +0100
committerTom Gundersen <teg@jklm.no>2013-11-21 21:04:04 +0100
commit5a3eb5a77d7c491a31818c4dfdcf8fd7dcaaadb2 (patch)
treecc860127113bc99e7907998995e7765ee7418726 /src/network/networkd-link.c
parent602cc437e8b4a3ab760b5a23fa4f3112134d9c36 (diff)
networkd: make sure Network and Link can always be freed
Also, don't fail a link just because we can't find its MAC address.
Diffstat (limited to 'src/network/networkd-link.c')
-rw-r--r--src/network/networkd-link.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index c03472216c..b93df63f21 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -39,22 +39,19 @@ int link_new(Manager *manager, struct udev_device *device, Link **ret) {
if (!link)
return -ENOMEM;
+ link->manager = manager;
+ link->state = _LINK_STATE_INVALID;
+
link->ifindex = udev_device_get_ifindex(device);
if (link->ifindex <= 0)
return -EINVAL;
mac = udev_device_get_sysattr_value(device, "address");
- if (!mac)
- return -EINVAL;
-
- mac_addr = ether_aton(mac);
- if (!mac_addr)
- return -EINVAL;
-
- memcpy(&link->mac, mac_addr, sizeof(struct ether_addr));
-
- link->manager = manager;
- link->state = _LINK_STATE_INVALID;
+ if (mac) {
+ mac_addr = ether_aton(mac);
+ if (mac_addr)
+ memcpy(&link->mac, mac_addr, sizeof(struct ether_addr));
+ }
r = hashmap_put(manager->links, &link->ifindex, link);
if (r < 0)