richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
bd1529
From 8c263758fe196624005f19bd6f46d63e3841c5be Mon Sep 17 00:00:00 2001
bd1529
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
bd1529
Date: Tue, 11 Dec 2018 23:28:29 +0100
bd1529
Subject: [PATCH] meson: make net.naming-scheme= default configurable
bd1529
bd1529
This is useful for distributions, where the stability of interface names should
bd1529
be preseved after an upgrade of systemd. So when some specific release of the
bd1529
distro is made available, systemd defaults to the latest & greatest naming
bd1529
scheme, and subsequent updates set the same default. This default may still
bd1529
be overriden through the kernel and env var options.
bd1529
bd1529
A special value "latest" is also allowed. Without a specific name, it is harder
bd1529
to verride from meson. In case of 'combo' options, meson reads the default
bd1529
during the initial configuration, and "remembers" this choice. When systemd is
bd1529
updated, old build/ directories could keep the old default, which would be
bd1529
annoying. Hence, "latest" is introduced to make it explicit, yet follow the
bd1529
upstream. This is actually useful for the user too, because it may be used
bd1529
as an override, without having to actually specify a version.
bd1529
bd1529
(cherry picked from commit 06da5c63dd697ea4087e76c6d809b60b5780b87c)
bd1529
bd1529
Related: #1827462
bd1529
bd1529
[msekleta: note that our default is not latest but rhel-8.0]
bd1529
---
bd1529
 doc/ENVIRONMENT.md             | 15 +++++++-------
bd1529
 man/systemd-udevd.service.xml  | 24 ++++++++++++---------
bd1529
 meson.build                    |  4 ++++
bd1529
 meson_options.txt              |  3 +++
bd1529
 src/udev/udev-builtin-net_id.c | 38 ++++++++++++++++++++--------------
bd1529
 5 files changed, 51 insertions(+), 33 deletions(-)
bd1529
bd1529
diff --git a/doc/ENVIRONMENT.md b/doc/ENVIRONMENT.md
bd1529
index 1a4aa01ef4..0e763b6302 100644
bd1529
--- a/doc/ENVIRONMENT.md
bd1529
+++ b/doc/ENVIRONMENT.md
bd1529
@@ -77,13 +77,14 @@ systemd-logind:
bd1529
   for it.
bd1529
 
bd1529
 * `$NET_NAMING_SCHEME=` – if set, takes a network naming scheme (i.e. one of
bd1529
-  v238, v239, v240 …) as parameter. If specified udev's net_id builtin will
bd1529
-  follow the specified naming scheme when determining stable network interface
bd1529
-  names. This may be used to revert to naming schemes of older udev versions,
bd1529
-  in order to provide more stable naming across updates. This environment
bd1529
-  variable takes precedence over the kernel command line option
bd1529
-  `net.naming-scheme=`, except if the value is prefixed with `:` in which case
bd1529
-  the kernel command line option takes precedence, if it is specified as well.
bd1529
+  "rhel-8.0", "rhel-8.1", "rhel-8.2"…, or the special value "latest") as
bd1529
+  parameter. If specified udev's net_id builtin will follow the specified
bd1529
+  naming scheme when determining stable network interface names. This may be
bd1529
+  used to revert to naming schemes of older udev versions, in order to provide
bd1529
+  more stable naming across updates. This environment variable takes precedence
bd1529
+  over the kernel command line option `net.naming-scheme=`, except if the value
bd1529
+  is prefixed with `:` in which case the kernel command line option takes
bd1529
+  precedence, if it is specified as well.
bd1529
 
bd1529
 installed systemd tests:
bd1529
 
bd1529
diff --git a/man/systemd-udevd.service.xml b/man/systemd-udevd.service.xml
bd1529
index 6449103441..b738591c93 100644
bd1529
--- a/man/systemd-udevd.service.xml
bd1529
+++ b/man/systemd-udevd.service.xml
bd1529
@@ -174,16 +174,20 @@
bd1529
         <term><varname>net.naming-scheme=</varname></term>
bd1529
         <listitem>
bd1529
           <para>Network interfaces are renamed to give them predictable names when possible (unless
bd1529
-          <varname>net.ifnames=0</varname> is specified, see above). The names are derived from various device metadata
bd1529
-          fields. Newer versions of <filename>systemd-udevd.service</filename> take more of these fields into account,
bd1529
-          improving (and thus possibly changing) the names used for the same devices. With this kernel command line
bd1529
-          option it is possible to pick a specific version of this algorithm. It expects a naming scheme identifier as
bd1529
-          argument. Currently the following identifiers are known: <literal>v238</literal>, <literal>v239</literal>,
bd1529
-          <literal>v240</literal> which each implement the naming scheme that was the default in the indicated systemd
bd1529
-          version. Note that selecting a specific scheme is not sufficient to fully stabilize interface naming: the
bd1529
-          naming is generally derived from driver attributes exposed by the kernel. As the kernel is updated,
bd1529
-          previously missing attributes <filename>systemd-udevd.service</filename> is checking might appear, which
bd1529
-          affects older name derivation algorithms, too.</para>
bd1529
+          <varname>net.ifnames=0</varname> is specified, see above). The names are derived from various
bd1529
+          device metadata fields. Newer versions of <filename>systemd-udevd.service</filename> take more of
bd1529
+          these fields into account, improving (and thus possibly changing) the names used for the same
bd1529
+          devices. With this kernel command line option it is possible to pick a specific version of this
bd1529
+          algorithm. It expects a naming scheme identifier as argument. Currently the following identifiers
bd1529
+          are known: <literal>rhel-8.0</literal>, <literal>rhel-8.1</literal>, <literal>rhel-8.2</literal>,
bd1529
+          <literal>rhel-8.3</literal> which each implement the naming scheme that was the default in the
bd1529
+          indicated Red Hat Enterprise Linux minor version. In addition, <literal>latest</literal> may be
bd1529
+          used to designate the latest scheme known (to this particular version of
bd1529
+          <filename>systemd-udevd.service</filename>).</para>
bd1529
+          <para>Note that selecting a specific scheme is not sufficient to fully stabilize interface naming:
bd1529
+          the naming is generally derived from driver attributes exposed by the kernel. As the kernel is
bd1529
+          updated, previously missing attributes <filename>systemd-udevd.service</filename> is checking might
bd1529
+          appear, which affects older name derivation algorithms, too.</para>
bd1529
         </listitem>
bd1529
       </varlistentry>
bd1529
     </variablelist>
bd1529
diff --git a/meson.build b/meson.build
bd1529
index 65c1d0785e..57de947367 100644
bd1529
--- a/meson.build
bd1529
+++ b/meson.build
bd1529
@@ -639,6 +639,9 @@ else
bd1529
         conf.set('DEFAULT_HIERARCHY', 'CGROUP_UNIFIED_ALL')
bd1529
 endif
bd1529
 
bd1529
+default_net_naming_scheme = get_option('default-net-naming-scheme')
bd1529
+conf.set_quoted('DEFAULT_NET_NAMING_SCHEME', default_net_naming_scheme)
bd1529
+
bd1529
 time_epoch = get_option('time-epoch')
bd1529
 if time_epoch == ''
bd1529
         NEWS = files('NEWS')
bd1529
@@ -2925,6 +2928,7 @@ status = [
bd1529
         'default DNSSEC mode:               @0@'.format(default_dnssec),
bd1529
         'default DNS-over-TLS mode:         @0@'.format(default_dns_over_tls),
bd1529
         'default cgroup hierarchy:          @0@'.format(default_hierarchy),
bd1529
+        'default net.naming-scheme setting: @0@'.format(default_net_naming_scheme),
bd1529
         'default KillUserProcesses setting: @0@'.format(kill_user_processes)]
bd1529
 
bd1529
 alt_dns_servers = '\n                                            '.join(dns_servers.split(' '))
bd1529
diff --git a/meson_options.txt b/meson_options.txt
bd1529
index 0996891177..213079ac15 100644
bd1529
--- a/meson_options.txt
bd1529
+++ b/meson_options.txt
bd1529
@@ -158,6 +158,9 @@ option('default-hierarchy', type : 'combo',
bd1529
        description : 'default cgroup hierarchy')
bd1529
 option('time-epoch', type : 'string',
bd1529
        description : 'time epoch for time clients')
bd1529
+option('default-net-naming-scheme', type : 'combo',
bd1529
+       choices : ['rhel-8.0', 'rhel-8.1', 'rhel-8.2', 'rhel-8.3', 'latest'],
bd1529
+       description : 'default net.naming-scheme= value')
bd1529
 option('system-uid-max', type : 'string',
bd1529
        description : 'maximum system UID')
bd1529
 option('system-gid-max', type : 'string',
bd1529
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
bd1529
index 148696183e..d85dc2848b 100644
bd1529
--- a/src/udev/udev-builtin-net_id.c
bd1529
+++ b/src/udev/udev-builtin-net_id.c
bd1529
@@ -185,6 +185,19 @@ struct virtfn_info {
bd1529
         char suffix[IFNAMSIZ];
bd1529
 };
bd1529
 
bd1529
+static const NamingScheme* naming_scheme_from_name(const char *name) {
bd1529
+        size_t i;
bd1529
+
bd1529
+        if (streq(name, "latest"))
bd1529
+                return naming_schemes + ELEMENTSOF(naming_schemes) - 1;
bd1529
+
bd1529
+        for (i = 0; i < ELEMENTSOF(naming_schemes); i++)
bd1529
+                if (streq(naming_schemes[i].name, name))
bd1529
+                        return naming_schemes + i;
bd1529
+
bd1529
+        return NULL;
bd1529
+}
bd1529
+
bd1529
 static const NamingScheme* naming_scheme(void) {
bd1529
         static const NamingScheme *cache = NULL;
bd1529
         _cleanup_free_ char *buffer = NULL;
bd1529
@@ -208,25 +221,18 @@ static const NamingScheme* naming_scheme(void) {
bd1529
                 k = buffer;
bd1529
 
bd1529
         if (k) {
bd1529
-                size_t i;
bd1529
-
bd1529
-                for (i = 0; i < ELEMENTSOF(naming_schemes); i++)
bd1529
-                        if (streq(naming_schemes[i].name, k)) {
bd1529
-                                cache = naming_schemes + i;
bd1529
-                                break;
bd1529
-                        }
bd1529
+                cache = naming_scheme_from_name(k);
bd1529
+                if (cache) {
bd1529
+                        log_info("Using interface naming scheme '%s'.", cache->name);
bd1529
+                        return cache;
bd1529
+                }
bd1529
 
bd1529
-                if (!cache)
bd1529
-                        log_warning("Unknown interface naming scheme '%s' requested, ignoring.", k);
bd1529
+                log_warning("Unknown interface naming scheme '%s' requested, ignoring.", k);
bd1529
         }
bd1529
 
bd1529
-        if (cache)
bd1529
-                log_info("Using interface naming scheme '%s'.", cache->name);
bd1529
-        else {
bd1529
-                /* RHEL-only: here we differ from the upstream and if no naming scheme was selected we default to naming from systemd-239 */
bd1529
-                cache = &naming_schemes[2];
bd1529
-                log_info("Using default interface naming scheme '%s'.", cache->name);
bd1529
-        }
bd1529
+        cache = naming_scheme_from_name(DEFAULT_NET_NAMING_SCHEME);
bd1529
+        assert(cache);
bd1529
+        log_info("Using default interface naming scheme '%s'.", cache->name);
bd1529
 
bd1529
         return cache;
bd1529
 }