|
|
76e7ff |
From c9fd1e80d3c87e1f844edcd86e9d36ae499ce717 Mon Sep 17 00:00:00 2001
|
|
|
76e7ff |
From: Gris Ge <fge@redhat.com>
|
|
|
76e7ff |
Date: Sun, 23 Apr 2023 16:01:29 +0800
|
|
|
76e7ff |
Subject: [PATCH] cli: Do nothing for `persist-nic-names` when got
|
|
|
76e7ff |
`net.ifnames=0`
|
|
|
76e7ff |
|
|
|
76e7ff |
When `net.ifnames=0` is defined in kernel argument, systemd will disable
|
|
|
76e7ff |
the predicable network interface name which make no sense for nmstate to
|
|
|
76e7ff |
pin the interface names. Hence we do nothing in `persist-nic-names` in
|
|
|
76e7ff |
that case.
|
|
|
76e7ff |
|
|
|
76e7ff |
Manually tested in CentOS stream 9 VM.
|
|
|
76e7ff |
|
|
|
76e7ff |
Signed-off-by: Gris Ge <fge@redhat.com>
|
|
|
76e7ff |
---
|
|
|
76e7ff |
rust/src/cli/persist_nic.rs | 19 +++++++++++++++++++
|
|
|
76e7ff |
1 file changed, 19 insertions(+)
|
|
|
76e7ff |
|
|
|
76e7ff |
diff --git a/rust/src/cli/persist_nic.rs b/rust/src/cli/persist_nic.rs
|
|
|
76e7ff |
index 6b126d58..61b07dbb 100644
|
|
|
76e7ff |
--- a/rust/src/cli/persist_nic.rs
|
|
|
76e7ff |
+++ b/rust/src/cli/persist_nic.rs
|
|
|
76e7ff |
@@ -7,6 +7,8 @@
|
|
|
76e7ff |
//!
|
|
|
76e7ff |
//! The logic currently is:
|
|
|
76e7ff |
//!
|
|
|
76e7ff |
+//! - Do nothing if kernel argument contains `net.ifnames=0` which disabled the
|
|
|
76e7ff |
+//! predicable network interface name, hence not fit our use case here.
|
|
|
76e7ff |
//! - Iterate over all active NICs
|
|
|
76e7ff |
//! - Pin every ethernet interface to its MAC address (prefer permanent MAC
|
|
|
76e7ff |
//! address)
|
|
|
76e7ff |
@@ -70,6 +72,14 @@ pub(crate) fn run_persist_immediately(
|
|
|
76e7ff |
PersistAction::CleanUpDryRun => return clean_up(root, true),
|
|
|
76e7ff |
};
|
|
|
76e7ff |
|
|
|
76e7ff |
+ if is_prediable_ifname_disabled() {
|
|
|
76e7ff |
+ log::info!(
|
|
|
76e7ff |
+ "Systemd predicable network interface name is disabled \
|
|
|
76e7ff |
+ by kernel argument `net.ifnames=0`, will do nothing"
|
|
|
76e7ff |
+ );
|
|
|
76e7ff |
+ return Ok("".to_string());
|
|
|
76e7ff |
+ }
|
|
|
76e7ff |
+
|
|
|
76e7ff |
let stamp_path = Path::new(root)
|
|
|
76e7ff |
.join(SYSTEMD_NETWORK_LINK_FOLDER)
|
|
|
76e7ff |
.join(NMSTATE_PERSIST_STAMP);
|
|
|
76e7ff |
@@ -317,3 +327,12 @@ fn is_nmstate_generated_systemd_link_file(file_path: &PathBuf) -> bool {
|
|
|
76e7ff |
.map(|_| buff == PERSIST_GENERATED_BY.as_bytes())
|
|
|
76e7ff |
.unwrap_or_default()
|
|
|
76e7ff |
}
|
|
|
76e7ff |
+
|
|
|
76e7ff |
+const KERNEL_CMDLINE_FILE: &str = "/proc/cmdline";
|
|
|
76e7ff |
+
|
|
|
76e7ff |
+fn is_prediable_ifname_disabled() -> bool {
|
|
|
76e7ff |
+ std::fs::read(KERNEL_CMDLINE_FILE)
|
|
|
76e7ff |
+ .map(|v| String::from_utf8(v).unwrap_or_default())
|
|
|
76e7ff |
+ .map(|c| c.contains("net.ifnames=0"))
|
|
|
76e7ff |
+ .unwrap_or_default()
|
|
|
76e7ff |
+}
|
|
|
76e7ff |
--
|
|
|
76e7ff |
2.40.0
|
|
|
76e7ff |
|