]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
link-config: add "keep" policy and use it by default
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 16 Jan 2019 13:26:29 +0000 (14:26 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 17 Jan 2019 12:56:02 +0000 (13:56 +0100)
If "keep" policy is specified, and the interface has a name that is
NET_NAME_USER or NET_NAME_RENAMED, we stop processing rules. "keep" should
probably be specified either first or last depending on the preference.

This partially reimplements 55b6530baacf4658a183b15b010a8cf3483fde08, in the
sense that if the "keep" policy is not specified, and if the interface has
a NamingPolicy, it will be renamed, even if it had a name previously.
So this breaks backwards compatibility in this case, but that's more in line
with what users expect.

Closes #9006.

man/systemd.link.xml
network/99-default.link
src/udev/net/link-config.c
src/udev/net/link-config.h

index f74edd0186b4797eabb5c2fe87079b3aefc3e369..22713e0316717a7aa6e4706b075b260dd372ac77 100644 (file)
       <varlistentry>
         <term><varname>NamePolicy=</varname></term>
         <listitem>
-          <para>An ordered, space-separated list of policies by which
-          the interface name should be set.
-          <literal>NamePolicy</literal> may be disabled by specifying
-          <literal>net.ifnames=0</literal> on the kernel command line.
-          Each of the policies may fail, and the first successful one
-          is used. The name is not set directly, but is exported to
-          udev as the property <literal>ID_NET_NAME</literal>, which
-          is, by default, used by a udev rule to set
-          <literal>NAME</literal>. If the name has already been set by
-          userspace, no renaming is performed. The available policies
-          are:</para>
+          <para>An ordered, space-separated list of policies by which the interface name should be set.
+          <literal>NamePolicy</literal> may be disabled by specifying <literal>net.ifnames=0</literal> on the
+          kernel command line.  Each of the policies may fail, and the first successful one is used. The name
+          is not set directly, but is exported to udev as the property <literal>ID_NET_NAME</literal>, which
+          is, by default, used by a udev rule to set <literal>NAME</literal>. The available policies are:
+          </para>
 
           <variablelist>
             <varlistentry>
                 <literal>ID_NET_NAME_MAC</literal>.</para>
               </listitem>
             </varlistentry>
+            <varlistentry>
+              <term><literal>keep</literal></term>
+              <listitem>
+                <para>If the device already had a name given by userspace (as part of creation of the device
+                or a rename), keep it.</para>
+              </listitem>
+            </varlistentry>
           </variablelist>
         </listitem>
       </varlistentry>
index 561bf329e485f57e7714a90f4a3c961fd8869474..92fcbe83eab91751854094023ff4d9c602378c98 100644 (file)
@@ -8,5 +8,5 @@
 #  (at your option) any later version.
 
 [Link]
-NamePolicy=kernel database onboard slot path
+NamePolicy=keep kernel database onboard slot path
 MACAddressPolicy=persistent
index dc0f02bde93ad29dc5910e8318867fd2808cd9e0..dfb00485d12faea602e406ab324c1f4a00bad8a2 100644 (file)
@@ -399,11 +399,6 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
 
         (void) link_name_type(device, &name_type);
 
-        if (IN_SET(name_type, NET_NAME_USER, NET_NAME_RENAMED)) {
-                log_device_info(device, "Device already has a name given by userspace, not renaming.");
-                goto no_rename;
-        }
-
         if (ctx->enable_name_policy && config->name_policy)
                 for (NamePolicy *p = config->name_policy; !new_name && *p != _NAMEPOLICY_INVALID; p++) {
                         policy = *p;
@@ -417,6 +412,13 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
                                 log_device_debug(device, "Policy *%s*: keeping predictable kernel name",
                                                  name_policy_to_string(policy));
                                 goto no_rename;
+                        case NAMEPOLICY_KEEP:
+                                if (!IN_SET(name_type, NET_NAME_USER, NET_NAME_RENAMED))
+                                        continue;
+
+                                log_device_debug(device, "Policy *%s*: keeping existing userspace name",
+                                                 name_policy_to_string(policy));
+                                goto no_rename;
                         case NAMEPOLICY_DATABASE:
                                 (void) sd_device_get_property_value(device, "ID_NET_NAME_FROM_DATABASE", &new_name);
                                 break;
@@ -503,7 +505,7 @@ int link_get_driver(link_config_ctx *ctx, sd_device *device, char **ret) {
 static const char* const mac_policy_table[_MACPOLICY_MAX] = {
         [MACPOLICY_PERSISTENT] = "persistent",
         [MACPOLICY_RANDOM] = "random",
-        [MACPOLICY_NONE] = "none"
+        [MACPOLICY_NONE] = "none",
 };
 
 DEFINE_STRING_TABLE_LOOKUP(mac_policy, MACPolicy);
@@ -512,11 +514,12 @@ DEFINE_CONFIG_PARSE_ENUM(config_parse_mac_policy, mac_policy, MACPolicy,
 
 static const char* const name_policy_table[_NAMEPOLICY_MAX] = {
         [NAMEPOLICY_KERNEL] = "kernel",
+        [NAMEPOLICY_KEEP] = "keep",
         [NAMEPOLICY_DATABASE] = "database",
         [NAMEPOLICY_ONBOARD] = "onboard",
         [NAMEPOLICY_SLOT] = "slot",
         [NAMEPOLICY_PATH] = "path",
-        [NAMEPOLICY_MAC] = "mac"
+        [NAMEPOLICY_MAC] = "mac",
 };
 
 DEFINE_STRING_TABLE_LOOKUP(name_policy, NamePolicy);
index 820495903462d7873532658be6d890b894c0e769..1113b1052e7d752b0ea5a3a673b101bc0c2da199 100644 (file)
@@ -22,6 +22,7 @@ typedef enum MACPolicy {
 
 typedef enum NamePolicy {
         NAMEPOLICY_KERNEL,
+        NAMEPOLICY_KEEP,
         NAMEPOLICY_DATABASE,
         NAMEPOLICY_ONBOARD,
         NAMEPOLICY_SLOT,