diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c index b3b134d650..9e7838527c 100644 --- a/src/libsystemd-network/network-internal.c +++ b/src/libsystemd-network/network-internal.c @@ -10,6 +10,7 @@ #include "alloc-util.h" #include "condition.h" #include "conf-parser.h" +#include "device-util.h" #include "dhcp-lease-internal.h" #include "ether-addr-util.h" #include "hexdecoct.h" @@ -40,31 +41,35 @@ const char *net_get_name(sd_device *device) { int net_get_unique_predictable_data(sd_device *device, uint64_t *result) { size_t l, sz = 0; - const char *name = NULL; + const char *name; int r; uint8_t *v; assert(device); + /* net_get_name() will return one of the device names based on stable information about the + * device. If this is not available, we fall back to using the device name. */ name = net_get_name(device); if (!name) - return -ENOENT; + (void) sd_device_get_sysname(device, &name); + if (!name) + return log_device_debug_errno(device, SYNTHETIC_ERRNO(ENODATA), + "No stable identifying information found"); + log_device_debug(device, "Using \"%s\" as stable identifying information", name); l = strlen(name); sz = sizeof(sd_id128_t) + l; v = alloca(sz); - /* fetch some persistent data unique to this machine */ + /* Fetch some persistent data unique to this machine */ r = sd_id128_get_machine((sd_id128_t*) v); if (r < 0) return r; memcpy(v + sizeof(sd_id128_t), name, l); - /* Let's hash the machine ID plus the device name. We - * use a fixed, but originally randomly created hash - * key here. */ + /* Let's hash the machine ID plus the device name. We use + * a fixed, but originally randomly created hash key here. */ *result = htole64(siphash24(v, sz, HASH_KEY.bytes)); - return 0; } diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index eb2477cea4..0fda4d16b9 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -313,8 +313,7 @@ static bool mac_is_random(sd_device *device) { return type == NET_ADDR_RANDOM; } -static int get_mac(sd_device *device, bool want_random, - struct ether_addr *mac) { +static int get_mac(sd_device *device, bool want_random, struct ether_addr *mac) { int r; if (want_random) @@ -459,7 +458,7 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, case MACPOLICY_PERSISTENT: if (mac_is_random(device)) { r = get_mac(device, false, &generated_mac); - if (r == -ENOENT) { + if (r == -ENODATA) { log_warning_errno(r, "Could not generate persistent MAC address for %s: %m", old_name); break; } else if (r < 0) @@ -470,7 +469,7 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, case MACPOLICY_RANDOM: if (!mac_is_random(device)) { r = get_mac(device, true, &generated_mac); - if (r == -ENOENT) { + if (r == -ENODATA) { log_warning_errno(r, "Could not generate random MAC address for %s: %m", old_name); break; } else if (r < 0)