teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0477-meson-make-net.naming-scheme-default-configurable.patch

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