Do not pin NIC name if net.ifnames=0
Resolves: RHBZ#2182769 Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
parent
edbf672f15
commit
a3995d2ed8
62
BZ_2182769-skip_if_ifnetifnames_0.patch
Normal file
62
BZ_2182769-skip_if_ifnetifnames_0.patch
Normal file
@ -0,0 +1,62 @@
|
||||
From d8b4c29ab17a53bad6f189acf76bab78e29ee333 Mon Sep 17 00:00:00 2001
|
||||
From: Gris Ge <fge@redhat.com>
|
||||
Date: Sun, 23 Apr 2023 16:01:29 +0800
|
||||
Subject: [PATCH] cli: Do nothing for `persist-nic-names` when got
|
||||
`net.ifnames=0`
|
||||
|
||||
When `net.ifnames=0` is defined in kernel argument, systemd will disable
|
||||
the predicable network interface name which make no sense for nmstate to
|
||||
pin the interface names. Hence we do nothing in `persist-nic-names` in
|
||||
that case.
|
||||
|
||||
Manually tested in CentOS stream 9 VM.
|
||||
|
||||
Signed-off-by: Gris Ge <fge@redhat.com>
|
||||
---
|
||||
rust/src/cli/persist_nic.rs | 19 +++++++++++++++++++
|
||||
1 file changed, 19 insertions(+)
|
||||
|
||||
diff --git a/rust/src/cli/persist_nic.rs b/rust/src/cli/persist_nic.rs
|
||||
index 6b126d58..61b07dbb 100644
|
||||
--- a/rust/src/cli/persist_nic.rs
|
||||
+++ b/rust/src/cli/persist_nic.rs
|
||||
@@ -7,6 +7,8 @@
|
||||
//!
|
||||
//! The logic currently is:
|
||||
//!
|
||||
+//! - Do nothing if kernel argument contains `net.ifnames=0` which disabled the
|
||||
+//! predicable network interface name, hence not fit our use case here.
|
||||
//! - Iterate over all active NICs
|
||||
//! - Pin every ethernet interface to its MAC address (prefer permanent MAC
|
||||
//! address)
|
||||
@@ -70,6 +72,14 @@ pub(crate) fn run_persist_immediately(
|
||||
PersistAction::CleanUpDryRun => return clean_up(root, true),
|
||||
};
|
||||
|
||||
+ if is_prediable_ifname_disabled() {
|
||||
+ log::info!(
|
||||
+ "Systemd predicable network interface name is disabled \
|
||||
+ by kernel argument `net.ifnames=0`, will do nothing"
|
||||
+ );
|
||||
+ return Ok("".to_string());
|
||||
+ }
|
||||
+
|
||||
let stamp_path = Path::new(root)
|
||||
.join(SYSTEMD_NETWORK_LINK_FOLDER)
|
||||
.join(NMSTATE_PERSIST_STAMP);
|
||||
@@ -317,3 +327,12 @@ fn is_nmstate_generated_systemd_link_file(file_path: &PathBuf) -> bool {
|
||||
.map(|_| buff == PERSIST_GENERATED_BY.as_bytes())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
+
|
||||
+const KERNEL_CMDLINE_FILE: &str = "/proc/cmdline";
|
||||
+
|
||||
+fn is_prediable_ifname_disabled() -> bool {
|
||||
+ std::fs::read(KERNEL_CMDLINE_FILE)
|
||||
+ .map(|v| String::from_utf8(v).unwrap_or_default())
|
||||
+ .map(|c| c.contains("net.ifnames=0"))
|
||||
+ .unwrap_or_default()
|
||||
+}
|
||||
--
|
||||
2.40.0
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
Name: nmstate
|
||||
Version: 2.2.10
|
||||
Release: 1%{?dist}
|
||||
Release: 2%{?dist}
|
||||
Summary: Declarative network manager API
|
||||
License: LGPLv2+
|
||||
URL: https://github.com/%{srcname}/%{srcname}
|
||||
@ -12,6 +12,7 @@ Source0: https://github.com/nmstate/nmstate/releases/download/v%{version}
|
||||
Source1: https://github.com/nmstate/nmstate/releases/download/v%{version}/nmstate-%{version}.tar.gz.asc
|
||||
Source2: https://nmstate.io/nmstate.gpg
|
||||
Source3: https://github.com/nmstate/nmstate/releases/download/v%{version}/nmstate-vendor-%{version}.tar.xz
|
||||
Patch1: BZ_2182769-skip_if_ifnetifnames_0.patch
|
||||
BuildRequires: python3-devel
|
||||
BuildRequires: python3-setuptools
|
||||
BuildRequires: gnupg2
|
||||
@ -150,6 +151,9 @@ popd
|
||||
/sbin/ldconfig
|
||||
|
||||
%changelog
|
||||
* Sun Apr 23 2023 Gris Ge <fge@redhat.com> - 2.2.10-2
|
||||
- Do not pin NIC if `net.ifnames=0`
|
||||
|
||||
* Thu Mar 23 2023 Gris Ge <fge@redhat.com> - 2.2.9-1
|
||||
- Upgrade to 2.2.9
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user