chiark / gitweb /
networkd: make sure Network and Link can always be freed
[elogind.git] / src / network / networkd-link.c
index d41fe80f208e62f170bc2fe79799716729a1b3d6..b93df63f211b205cc6d04ef3a1136d26a2d8c208 100644 (file)
@@ -29,6 +29,7 @@
 int link_new(Manager *manager, struct udev_device *device, Link **ret) {
         _cleanup_link_free_ Link *link = NULL;
         const char *mac;
+        struct ether_addr *mac_addr;
         int r;
 
         assert(device);
@@ -38,17 +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;
-
-        memcpy(&link->mac.ether_addr_octet[0], ether_aton(mac), ETH_ALEN);
-        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)