]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: introduce new netif naming scheme flag to strictly replace ifname
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Jun 2021 07:10:26 +0000 (16:10 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Jun 2021 07:10:26 +0000 (16:10 +0900)
src/shared/netif-naming-scheme.h
src/udev/udev-rules.c

index c0f94d0407cd04f8b121d7ea5c3f4070a4b72632..119b80178f1ac15c1f3583d155cf65d45b4f307b 100644 (file)
@@ -34,6 +34,7 @@ typedef enum NamingSchemeFlags {
         NAMING_BRIDGE_NO_SLOT      = 1 << 9, /* Don't use PCI hotplug slot information if the corresponding device is a PCI bridge */
         NAMING_SLOT_FUNCTION_ID    = 1 << 10, /* Use function_id if present to identify PCI hotplug slots */
         NAMING_16BIT_INDEX         = 1 << 11, /* Allow full 16-bit for the onboard index */
+        NAMING_REPLACE_STRICTLY    = 1 << 12, /* Use udev_replace_ifname() for NAME= rule */
 
         /* And now the masks that combine the features above */
         NAMING_V238 = 0,
@@ -43,7 +44,7 @@ typedef enum NamingSchemeFlags {
         NAMING_V243 = NAMING_V241 | NAMING_NETDEVSIM | NAMING_LABEL_NOPREFIX,
         NAMING_V245 = NAMING_V243 | NAMING_NSPAWN_LONG_HASH,
         NAMING_V247 = NAMING_V245 | NAMING_BRIDGE_NO_SLOT,
-        NAMING_V249 = NAMING_V247 | NAMING_SLOT_FUNCTION_ID | NAMING_16BIT_INDEX,
+        NAMING_V249 = NAMING_V247 | NAMING_SLOT_FUNCTION_ID | NAMING_16BIT_INDEX | NAMING_REPLACE_STRICTLY,
 
         _NAMING_SCHEME_FLAGS_INVALID = -EINVAL,
 } NamingSchemeFlags;
index d2fc1fcced4e51c23b1c29669d0177d6a63c6e6c..8e5b043658928982d438c2008ac25119bec80dce 100644 (file)
@@ -17,6 +17,7 @@
 #include "glob-util.h"
 #include "list.h"
 #include "mkdir.h"
+#include "netif-naming-scheme.h"
 #include "nulstr-util.h"
 #include "parse-util.h"
 #include "path-util.h"
@@ -2062,7 +2063,10 @@ static int udev_rule_apply_token_to_event(
 
                 (void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false);
                 if (IN_SET(event->esc, ESCAPE_UNSET, ESCAPE_REPLACE)) {
-                        count = udev_replace_chars(buf, "/");
+                        if (naming_scheme_has(NAMING_REPLACE_STRICTLY))
+                                count = udev_replace_ifname(buf);
+                        else
+                                count = udev_replace_chars(buf, "/");
                         if (count > 0)
                                 log_rule_debug(dev, rules, "Replaced %zu character(s) from result of NAME=\"%s\"",
                                                count, token->value);