1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-19 22:50:17 +03:00

udev/net: fix assignment of ID_NET_NAME=

E.g. sd_device object of network interface 'hoge!foo' has sysname 'hoge/foo'.
So, previously udevd assigned 'hoge/foo' rather than 'hoge!foo' to ID_NET_NAME,
hence even when renaming is not requested, such interface was renamed to 'hoge_foo'
(note '/' cannot be used in network interface name, hence escaped to underbar).
This commit is contained in:
Yu Watanabe 2025-03-06 07:25:28 +09:00
parent b3157fc912
commit b15053de89
6 changed files with 68 additions and 2 deletions

View File

@ -540,6 +540,16 @@
<xi:include href="version-info.xml" xpointer="v257"/>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>v258</constant></term>
<listitem><para>When no renaming is requested, <varname>ID_NET_NAME</varname> property is now
equivalent to <varname>INTERFACE</varname> property.</para>
<xi:include href="version-info.xml" xpointer="v258"/>
</listitem>
</varlistentry>
</variablelist>
<para>Note that <constant>latest</constant> may be used to denote the latest scheme known (to this

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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;

View File

@ -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 <<EOF
[Match]
OriginalName=testif
[Link]
Name=te!st!if
EOF
udevadm control --log-level=debug --reload
# Check if any interfaces originally named with '!' in their name have been renamed unexpectedly.
ip link add 'hoge!foo' type dummy
udevadm wait --settle --timeout=30 '/sys/class/net/hoge!foo'
output=$(udevadm info --query property '/sys/class/net/hoge!foo')
assert_in 'INTERFACE=hoge!foo' "$output"
assert_in 'ID_NET_DRIVER=dummy' "$output"
assert_in 'ID_NET_NAME=hoge!foo' "$output"
assert_not_in 'ID_RENAMING=' "$output"
ip link show dev 'hoge!foo'
ip link del dev 'hoge!foo'
# Check if the interface renamed to include '!' as expected.
ip link add 'testif' type dummy
udevadm wait --settle --timeout=30 '/sys/class/net/te!st!if'
output=$(udevadm info --query property '/sys/class/net/te!st!if')
assert_in 'INTERFACE=te!st!if' "$output"
assert_in 'ID_NET_DRIVER=dummy' "$output"
assert_in 'ID_NET_NAME=te!st!if' "$output"
assert_not_in 'ID_RENAMING=' "$output"
ip link show dev 'te!st!if'
ip link del dev 'te!st!if'
# cleanup
rm -f /run/systemd/network/10-rename-test.link
udevadm control --log-level=info --reload
exit 0