diff --git a/man/systemd.net-naming-scheme.xml b/man/systemd.net-naming-scheme.xml index 6e77af99293..96688ed3c91 100644 --- a/man/systemd.net-naming-scheme.xml +++ b/man/systemd.net-naming-scheme.xml @@ -540,6 +540,16 @@ + + + v258 + + When no renaming is requested, ID_NET_NAME property is now + equivalent to INTERFACE property. + + + + Note that latest may be used to denote the latest scheme known (to this diff --git a/src/shared/netif-naming-scheme.c b/src/shared/netif-naming-scheme.c index 67b7eb4d904..8e05598c5e8 100644 --- a/src/shared/netif-naming-scheme.c +++ b/src/shared/netif-naming-scheme.c @@ -25,6 +25,7 @@ static const NamingScheme naming_schemes[] = { { "v254", NAMING_V254 }, { "v255", NAMING_V255 }, { "v257", NAMING_V257 }, + { "v258", NAMING_V258 }, /* … add more schemes here, as the logic to name devices is updated … */ EXTRA_NET_NAMING_MAP diff --git a/src/shared/netif-naming-scheme.h b/src/shared/netif-naming-scheme.h index 3ab1d752c87..5ead1f85d78 100644 --- a/src/shared/netif-naming-scheme.h +++ b/src/shared/netif-naming-scheme.h @@ -45,6 +45,7 @@ typedef enum NamingSchemeFlags { NAMING_SR_IOV_R = 1 << 17, /* Use "r" suffix for SR-IOV VF representors */ NAMING_FIRMWARE_NODE_SUN = 1 << 18, /* Use firmware_node/sun to get PCI slot number */ NAMING_DEVICETREE_PORT_ALIASES = 1 << 19, /* Include aliases of OF nodes of a netdev itself, not just its parent. See PR #33958. */ + NAMING_USE_INTERFACE_PROPERTY = 1 << 20, /* Use INTERFACE udev property, rather than sysname, when no renaming is requested. */ /* And now the masks that combine the features above */ NAMING_V238 = 0, @@ -65,6 +66,7 @@ typedef enum NamingSchemeFlags { * systemd version 255, naming scheme "v255". */ NAMING_V255 = NAMING_V254 & ~NAMING_BRIDGE_MULTIFUNCTION_SLOT, NAMING_V257 = NAMING_V255 | NAMING_FIRMWARE_NODE_SUN | NAMING_DEVICETREE_PORT_ALIASES, + NAMING_V258 = NAMING_V257 | NAMING_USE_INTERFACE_PROPERTY, EXTRA_NET_NAMING_SCHEMES diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 3400286566f..b3bb164bbe5 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -400,7 +400,7 @@ int link_new(LinkConfigContext *ctx, UdevEvent *event, Link **ret) { .event = udev_event_ref(event), }; - r = sd_device_get_sysname(dev, &link->ifname); + r = device_get_ifname(dev, &link->ifname); if (r < 0) return r; @@ -804,6 +804,9 @@ static int link_generate_new_name(Link *link) { log_link_debug(link, "Policies didn't yield a name and Name= is not given, not renaming."); no_rename: + if (!naming_scheme_has(NAMING_USE_INTERFACE_PROPERTY)) + return sd_device_get_sysname(device, &link->new_name); + link->new_name = link->ifname; return 0; } diff --git a/src/udev/udev-builtin-net_setup_link.c b/src/udev/udev-builtin-net_setup_link.c index 0062a85db58..0d59a72a062 100644 --- a/src/udev/udev-builtin-net_setup_link.c +++ b/src/udev/udev-builtin-net_setup_link.c @@ -35,7 +35,11 @@ static int builtin_net_setup_link(UdevEvent *event, int argc, char **argv) { /* Set ID_NET_NAME= with the current interface name. */ const char *value; - if (sd_device_get_sysname(dev, &value) >= 0) + if (naming_scheme_has(NAMING_USE_INTERFACE_PROPERTY)) + r = device_get_ifname(dev, &value); + else + r = sd_device_get_sysname(dev, &value); + if (r >= 0) (void) udev_builtin_add_property(event, "ID_NET_NAME", value); return 0; diff --git a/test/units/TEST-17-UDEV.netif-INTERFACE-property.sh b/test/units/TEST-17-UDEV.netif-INTERFACE-property.sh new file mode 100755 index 00000000000..deb115626d9 --- /dev/null +++ b/test/units/TEST-17-UDEV.netif-INTERFACE-property.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -ex +set -o pipefail + +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh + +mkdir -p /run/systemd/network/ +cat >/run/systemd/network/10-rename-test.link <