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).
<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
{ "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
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,
* 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
.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;
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;
}
/* 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;
--- /dev/null
+#!/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