From 78e9bb837c258ac0ec7712b3d612cc2f407e731e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 05:50:42 +0200 Subject: Merging upstream version 256. Signed-off-by: Daniel Baumann --- src/shared/netif-naming-scheme.c | 83 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) (limited to 'src/shared/netif-naming-scheme.c') diff --git a/src/shared/netif-naming-scheme.c b/src/shared/netif-naming-scheme.c index fbaf5c5..2955b6e 100644 --- a/src/shared/netif-naming-scheme.c +++ b/src/shared/netif-naming-scheme.c @@ -1,6 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-device.h" + #include "alloc-util.h" +#include "device-private.h" #include "netif-naming-scheme.h" #include "proc-cmdline.h" #include "string-util.h" @@ -50,7 +53,7 @@ const NamingScheme* naming_scheme(void) { return cache; /* Acquire setting from the kernel command line */ - (void) proc_cmdline_get_key("net.naming-scheme", 0, &buffer); + (void) proc_cmdline_get_key("net.naming_scheme", 0, &buffer); /* Also acquire it from an env var */ e = getenv("NET_NAMING_SCHEME"); @@ -101,3 +104,81 @@ static const char* const alternative_names_policy_table[_NAMEPOLICY_MAX] = { }; DEFINE_STRING_TABLE_LOOKUP(alternative_names_policy, NamePolicy); + +static int naming_sysattr_allowed_by_default(sd_device *dev) { + int r; + + assert(dev); + + r = device_get_property_bool(dev, "ID_NET_NAME_ALLOW"); + if (r == -ENOENT) + return true; + + return r; +} + +static int naming_sysattr_allowed(sd_device *dev, const char *sysattr) { + char *sysattr_property; + int r; + + assert(dev); + assert(sysattr); + + sysattr_property = strjoina("ID_NET_NAME_ALLOW_", sysattr); + ascii_strupper(sysattr_property); + + r = device_get_property_bool(dev, sysattr_property); + if (r == -ENOENT) + /* If ID_NET_NAME_ALLOW is not set or set to 1 default is to allow */ + return naming_sysattr_allowed_by_default(dev); + + return r; +} + +int device_get_sysattr_int_filtered(sd_device *device, const char *sysattr, int *ret_value) { + int r; + + r = naming_sysattr_allowed(device, sysattr); + if (r < 0) + return r; + if (r == 0) + return -ENOENT; + + return device_get_sysattr_int(device, sysattr, ret_value); +} + +int device_get_sysattr_unsigned_filtered(sd_device *device, const char *sysattr, unsigned *ret_value) { + int r; + + r = naming_sysattr_allowed(device, sysattr); + if (r < 0) + return r; + if (r == 0) + return -ENOENT; + + return device_get_sysattr_unsigned(device, sysattr, ret_value); +} + +int device_get_sysattr_bool_filtered(sd_device *device, const char *sysattr) { + int r; + + r = naming_sysattr_allowed(device, sysattr); + if (r < 0) + return r; + if (r == 0) + return -ENOENT; + + return device_get_sysattr_bool(device, sysattr); +} + +int device_get_sysattr_value_filtered(sd_device *device, const char *sysattr, const char **ret_value) { + int r; + + r = naming_sysattr_allowed(device, sysattr); + if (r < 0) + return r; + if (r == 0) + return -ENOENT; + + return sd_device_get_sysattr_value(device, sysattr, ret_value); +} -- cgit v1.2.3