chiark / gitweb /
sd-dhcp-lease: fix double realloc
[elogind.git] / src / libsystemd-network / network-internal.c
index eed0fda92df2248c13d11b3edddf3acf74998b7d..e7ba628fc71e8ef2030d0986c9f5d71a4b0cb5f1 100644 (file)
@@ -38,7 +38,7 @@
 
 int net_get_unique_predictable_data(struct udev_device *device, uint8_t result[8]) {
         size_t l, sz = 0;
-        const char *name, *field = NULL;
+        const char *name = NULL, *field = NULL;
         int r;
         uint8_t *v;
 
@@ -79,7 +79,7 @@ bool net_match_config(const struct ether_addr *match_mac,
                       Condition *match_virt,
                       Condition *match_kernel,
                       Condition *match_arch,
-                      const char *dev_mac,
+                      const struct ether_addr *dev_mac,
                       const char *dev_path,
                       const char *dev_parent_driver,
                       const char *dev_driver,
@@ -98,7 +98,7 @@ bool net_match_config(const struct ether_addr *match_mac,
         if (match_arch && !condition_test_architecture(match_arch))
                 return 0;
 
-        if (match_mac && (!dev_mac || memcmp(match_mac, ether_aton(dev_mac), ETH_ALEN)))
+        if (match_mac && (!dev_mac || memcmp(match_mac, dev_mac, ETH_ALEN)))
                 return 0;
 
         if (match_path && (!dev_path || fnmatch(match_path, dev_path, 0)))
@@ -326,3 +326,17 @@ int net_parse_inaddr(const char *address, unsigned char *family, void *dst) {
 
         return 0;
 }
+
+bool link_has_carrier(unsigned flags, uint8_t operstate) {
+        /* see Documentation/networking/operstates.txt in the kernel sources */
+
+        if (operstate == IF_OPER_UP)
+                return true;
+
+        if (operstate == IF_OPER_UNKNOWN)
+                /* operstate may not be implemented, so fall back to flags */
+                if ((flags & IFF_LOWER_UP) && !(flags & IFF_DORMANT))
+                        return true;
+
+        return false;
+}