commit
5bdb79bfb3
@ -0,0 +1,2 @@
|
||||
SOURCES/prefixdevname-0.1.0-vendor.tar.gz
|
||||
SOURCES/prefixdevname-0.1.0.tar.gz
|
@ -0,0 +1,2 @@
|
||||
045edc3e08ddd3d75a34b261a0a7ae69890f1885 SOURCES/prefixdevname-0.1.0-vendor.tar.gz
|
||||
e8de41af594bd790aa3fc190a45f335271896d00 SOURCES/prefixdevname-0.1.0.tar.gz
|
@ -0,0 +1,43 @@
|
||||
From 1657894cf9a7a67de4e945d127d3a8ec8e3782a7 Mon Sep 17 00:00:00 2001
|
||||
From: Michal Sekletar <msekleta@redhat.com>
|
||||
Date: Tue, 14 Aug 2018 10:43:25 +0000
|
||||
Subject: [PATCH] udev: assign new name to the interface directly and don't
|
||||
rely on net_setup_link
|
||||
|
||||
---
|
||||
rules/71-prefixdevname.rules | 2 +-
|
||||
src/main.rs | 6 ++++--
|
||||
2 files changed, 5 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/rules/71-prefixdevname.rules b/rules/71-prefixdevname.rules
|
||||
index 15e2e1e..c45da2f 100644
|
||||
--- a/rules/71-prefixdevname.rules
|
||||
+++ b/rules/71-prefixdevname.rules
|
||||
@@ -6,6 +6,6 @@ ATTR{type}!="1", GOTO="net_ifnames_prefix_end"
|
||||
|
||||
IMPORT{cmdline}="net.ifnames.prefix"
|
||||
ENV{net.ifnames.prefix}!="?*", GOTO="net_ifnames_prefix_end"
|
||||
-PROGRAM="/usr/lib/udev/prefixdevname"
|
||||
+PROGRAM="/usr/lib/udev/prefixdevname", RESULT=="?*", NAME="$result"
|
||||
|
||||
LABEL="net_ifnames_prefix_end"
|
||||
diff --git a/src/main.rs b/src/main.rs
|
||||
index 15bb6fa..54f4de4 100644
|
||||
--- a/src/main.rs
|
||||
+++ b/src/main.rs
|
||||
@@ -86,8 +86,10 @@ fn main() {
|
||||
exit_maybe_unlock(Some(&mut sema), 1);
|
||||
}
|
||||
|
||||
- info!("New link file was generated at {}", link_config.link_file_path().into_os_string().into_string().unwrap());
|
||||
- info!("Consider rebuilding initrd image, using \"dracut -f\"");
|
||||
+ debug!("New link file was generated at {}", link_config.link_file_path().into_os_string().into_string().unwrap());
|
||||
+ debug!("Consider rebuilding initrd image, using \"dracut -f\"");
|
||||
+
|
||||
+ println!("{}", next_link_name);
|
||||
|
||||
sema.unlock();
|
||||
}
|
||||
--
|
||||
2.17.1
|
||||
|
@ -0,0 +1,49 @@
|
||||
From b157be43805d90aef60c24530b9a0492abf00ebc Mon Sep 17 00:00:00 2001
|
||||
From: Michal Sekletar <msekleta@redhat.com>
|
||||
Date: Wed, 12 Sep 2018 14:36:34 +0000
|
||||
Subject: [PATCH] dracut: introduce new dracut module prefixdevname-tools
|
||||
|
||||
This module will be used by lorax to make sure that prefixdevname is
|
||||
included in initrd.img used for system installation.
|
||||
---
|
||||
Makefile | 2 ++
|
||||
dracut/71prefixdevname-tools/module-setup.sh | 11 +++++++++++
|
||||
2 files changed, 13 insertions(+)
|
||||
create mode 100755 dracut/71prefixdevname-tools/module-setup.sh
|
||||
|
||||
diff --git a/Makefile b/Makefile
|
||||
index fb930d4..982c5d9 100644
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
@@ -25,9 +25,11 @@ check:
|
||||
install:
|
||||
mkdir -p $(DESTDIR)/usr/lib/udev/rules.d
|
||||
mkdir -p $(DESTDIR)/usr/lib/dracut/modules.d/71prefixdevname
|
||||
+ mkdir -p $(DESTDIR)/usr/lib/dracut/modules.d/71prefixdevname-tools
|
||||
install -p -m 0755 target/release/$(NAME) $(DESTDIR)/usr/lib/udev/
|
||||
install -p -m 644 rules/71-prefixdevname.rules $(DESTDIR)/usr/lib/udev/rules.d/
|
||||
install -p -m 0755 dracut/71prefixdevname/module-setup.sh $(DESTDIR)/usr/lib/dracut/modules.d/71prefixdevname/
|
||||
+ install -p -m 0755 dracut/71prefixdevname-tools/module-setup.sh $(DESTDIR)/usr/lib/dracut/modules.d/71prefixdevname-tools/
|
||||
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)/usr/lib/udev/$(NAME)
|
||||
diff --git a/dracut/71prefixdevname-tools/module-setup.sh b/dracut/71prefixdevname-tools/module-setup.sh
|
||||
new file mode 100755
|
||||
index 0000000..0ff010e
|
||||
--- /dev/null
|
||||
+++ b/dracut/71prefixdevname-tools/module-setup.sh
|
||||
@@ -0,0 +1,11 @@
|
||||
+#!/bin/bash
|
||||
+
|
||||
+# Include the prefixdevname tools only if this was explicitely requested
|
||||
+check() {
|
||||
+ return 255
|
||||
+}
|
||||
+
|
||||
+install() {
|
||||
+ inst /usr/lib/udev/prefixdevname
|
||||
+ inst_rules 71-prefixdevname.rules
|
||||
+}
|
||||
--
|
||||
2.17.1
|
||||
|
@ -0,0 +1,73 @@
|
||||
From c55c64cce2449b4616b3f71b42fedc1e3098a04c Mon Sep 17 00:00:00 2001
|
||||
From: Michal Sekletar <msekleta@redhat.com>
|
||||
Date: Fri, 21 Sep 2018 08:42:58 +0000
|
||||
Subject: [PATCH] core: don't rename interfaces that already have the name in
|
||||
expected format
|
||||
|
||||
---
|
||||
src/main.rs | 5 +++++
|
||||
src/util.rs | 27 +++++++++++++++++++++++++++
|
||||
2 files changed, 32 insertions(+)
|
||||
|
||||
diff --git a/src/main.rs b/src/main.rs
|
||||
index 54f4de4..5c1a42b 100644
|
||||
--- a/src/main.rs
|
||||
+++ b/src/main.rs
|
||||
@@ -37,6 +37,11 @@ fn main() {
|
||||
exit_maybe_unlock(None, 0);
|
||||
}
|
||||
|
||||
+ if ! rename_needed(&prefix).unwrap() {
|
||||
+ info!("Interface name already has expected format, not renaming again");
|
||||
+ exit_maybe_unlock(None, 0);
|
||||
+ }
|
||||
+
|
||||
let mut sema = match Semaphore::new_with_name("net-prefix-ifnames") {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
diff --git a/src/util.rs b/src/util.rs
|
||||
index 85a1090..8727074 100644
|
||||
--- a/src/util.rs
|
||||
+++ b/src/util.rs
|
||||
@@ -11,6 +11,14 @@ use regex::Regex;
|
||||
|
||||
use sema::*;
|
||||
|
||||
+pub fn rename_needed(prefix: &str) -> Result<bool, Box<Error>> {
|
||||
+ // TODO: if INTERFACE is unset we should probably check sysname
|
||||
+ let ifname = env::var("INTERFACE").unwrap_or("".to_string());
|
||||
+ let re: Regex = Regex::new(&format!("{}\\d+", prefix)).unwrap();
|
||||
+
|
||||
+ Ok(!re.is_match(&ifname))
|
||||
+}
|
||||
+
|
||||
pub fn hwaddr_valid<T: ToString>(hwaddr: &T) -> bool {
|
||||
use std::num::ParseIntError;
|
||||
|
||||
@@ -161,4 +169,23 @@ mod tests {
|
||||
fn long_prefix_not_ok() {
|
||||
assert_eq!(false, prefix_ok(&"neeeeeeeeeeeeeeet"));
|
||||
}
|
||||
+
|
||||
+ #[test]
|
||||
+ fn rename_is_needed() {
|
||||
+ env::set_var("INTERFACE", "eth0");
|
||||
+
|
||||
+ assert_eq!(rename_needed("net").unwrap(), true);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn rename_not_needed() {
|
||||
+ env::set_var("INTERFACE", "net0");
|
||||
+
|
||||
+ assert_eq!(rename_needed("net").unwrap(), false);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn rename_needed_interface_unset() {
|
||||
+ assert_eq!(rename_needed("net").unwrap(), true);
|
||||
+ }
|
||||
}
|
||||
--
|
||||
2.17.1
|
||||
|
@ -0,0 +1,90 @@
|
||||
From 7f395e0bdb529f2ea6fe2234956e04869a3464e6 Mon Sep 17 00:00:00 2001
|
||||
From: Michal Sekletar <msekleta@redhat.com>
|
||||
Date: Fri, 2 Nov 2018 12:10:12 +0000
|
||||
Subject: [PATCH] core: if interface already has name in expected format (i.e.
|
||||
<prefix><number>) print the name to stdout
|
||||
|
||||
This is needed in order to prevent renaming back to name given by one of
|
||||
built-in naming schemes.
|
||||
|
||||
For example, NIC appears in initrd (during system installation) and gets
|
||||
renamed to net0. Later we switch root to anaconda's stage2 and all HW is
|
||||
cold-plugged. Prefixdevname should figure out that renaming is not
|
||||
necessary. However, if we don't print anything to stdout (i.e. nothing
|
||||
gets assigned to NAME= variable) then logic in subsequent rules
|
||||
eventually renames interface to some other name determined by net_id.
|
||||
---
|
||||
src/main.rs | 6 ++++--
|
||||
src/util.rs | 20 ++++++++++----------
|
||||
2 files changed, 14 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/src/main.rs b/src/main.rs
|
||||
index 5c1a42b..b0c02b8 100644
|
||||
--- a/src/main.rs
|
||||
+++ b/src/main.rs
|
||||
@@ -37,8 +37,10 @@ fn main() {
|
||||
exit_maybe_unlock(None, 0);
|
||||
}
|
||||
|
||||
- if ! rename_needed(&prefix).unwrap() {
|
||||
- info!("Interface name already has expected format, not renaming again");
|
||||
+ let ifname = event_device_name();
|
||||
+
|
||||
+ if ! rename_needed(&ifname, &prefix).unwrap() {
|
||||
+ println!("{}", ifname);
|
||||
exit_maybe_unlock(None, 0);
|
||||
}
|
||||
|
||||
diff --git a/src/util.rs b/src/util.rs
|
||||
index 8727074..98eb32f 100644
|
||||
--- a/src/util.rs
|
||||
+++ b/src/util.rs
|
||||
@@ -11,14 +11,18 @@ use regex::Regex;
|
||||
|
||||
use sema::*;
|
||||
|
||||
-pub fn rename_needed(prefix: &str) -> Result<bool, Box<Error>> {
|
||||
- // TODO: if INTERFACE is unset we should probably check sysname
|
||||
- let ifname = env::var("INTERFACE").unwrap_or("".to_string());
|
||||
+pub fn rename_needed(ifname: &str, prefix: &str) -> Result<bool, Box<Error>> {
|
||||
let re: Regex = Regex::new(&format!("{}\\d+", prefix)).unwrap();
|
||||
|
||||
Ok(!re.is_match(&ifname))
|
||||
}
|
||||
|
||||
+pub fn event_device_name() -> String {
|
||||
+ let ifname = env::var("INTERFACE").unwrap_or("".to_string());
|
||||
+
|
||||
+ ifname.to_string()
|
||||
+}
|
||||
+
|
||||
pub fn hwaddr_valid<T: ToString>(hwaddr: &T) -> bool {
|
||||
use std::num::ParseIntError;
|
||||
|
||||
@@ -172,20 +176,16 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rename_is_needed() {
|
||||
- env::set_var("INTERFACE", "eth0");
|
||||
-
|
||||
- assert_eq!(rename_needed("net").unwrap(), true);
|
||||
+ assert_eq!(rename_needed("eth0", "net").unwrap(), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_not_needed() {
|
||||
- env::set_var("INTERFACE", "net0");
|
||||
-
|
||||
- assert_eq!(rename_needed("net").unwrap(), false);
|
||||
+ assert_eq!(rename_needed("net0", "net").unwrap(), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_needed_interface_unset() {
|
||||
- assert_eq!(rename_needed("net").unwrap(), true);
|
||||
+ assert_eq!(rename_needed("", "net").unwrap(), true);
|
||||
}
|
||||
}
|
||||
--
|
||||
2.17.2
|
||||
|
@ -0,0 +1,65 @@
|
||||
From 58886377310bb2190c6364aa3df83d1858183446 Mon Sep 17 00:00:00 2001
|
||||
From: Michal Sekletar <msekleta@redhat.com>
|
||||
Date: Fri, 2 Nov 2018 16:25:58 +0000
|
||||
Subject: [PATCH] core: don't assign names to virtual network devices
|
||||
|
||||
---
|
||||
src/main.rs | 5 +++++
|
||||
src/util.rs | 20 ++++++++++++++++++++
|
||||
2 files changed, 25 insertions(+)
|
||||
|
||||
diff --git a/src/main.rs b/src/main.rs
|
||||
index b0c02b8..6eeb793 100644
|
||||
--- a/src/main.rs
|
||||
+++ b/src/main.rs
|
||||
@@ -37,6 +37,11 @@ fn main() {
|
||||
exit_maybe_unlock(None, 0);
|
||||
}
|
||||
|
||||
+ if event_device_virtual() {
|
||||
+ debug!("Called for virtual network device, ignoring");
|
||||
+ exit_maybe_unlock(None, 0);
|
||||
+ }
|
||||
+
|
||||
let ifname = event_device_name();
|
||||
|
||||
if ! rename_needed(&ifname, &prefix).unwrap() {
|
||||
diff --git a/src/util.rs b/src/util.rs
|
||||
index 98eb32f..50c6677 100644
|
||||
--- a/src/util.rs
|
||||
+++ b/src/util.rs
|
||||
@@ -23,6 +23,12 @@ pub fn event_device_name() -> String {
|
||||
ifname.to_string()
|
||||
}
|
||||
|
||||
+pub fn event_device_virtual() -> bool {
|
||||
+ let devpath = env::var("DEVPATH").unwrap_or("".to_string());
|
||||
+
|
||||
+ devpath.starts_with("/devices/virtual")
|
||||
+}
|
||||
+
|
||||
pub fn hwaddr_valid<T: ToString>(hwaddr: &T) -> bool {
|
||||
use std::num::ParseIntError;
|
||||
|
||||
@@ -188,4 +194,18 @@ mod tests {
|
||||
fn rename_needed_interface_unset() {
|
||||
assert_eq!(rename_needed("", "net").unwrap(), true);
|
||||
}
|
||||
+
|
||||
+ #[test]
|
||||
+ fn event_device_not_virtual() {
|
||||
+ env::set_var("DEVPATH", "/devices/pci0000:00/0000:00:03.0/virtio0/net/eth0");
|
||||
+
|
||||
+ assert_eq!(event_device_virtual(), false);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn event_device_is_virtual() {
|
||||
+ env::set_var("DEVPATH", "/devices/virtual/net/bond0");
|
||||
+
|
||||
+ assert_eq!(event_device_virtual(), true);
|
||||
+ }
|
||||
}
|
||||
--
|
||||
2.17.2
|
||||
|
@ -0,0 +1,25 @@
|
||||
From 7205027f998d956df125da517d0eb9c03515f1f1 Mon Sep 17 00:00:00 2001
|
||||
From: rpm-build <rpm-build>
|
||||
Date: Fri, 10 Aug 2018 18:58:54 +0200
|
||||
Subject: [PATCH] sema: fix cast (needed to build with rust-1.26)
|
||||
|
||||
---
|
||||
src/sema.rs | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/sema.rs b/src/sema.rs
|
||||
index 4a9a63e..5be3dc8 100644
|
||||
--- a/src/sema.rs
|
||||
+++ b/src/sema.rs
|
||||
@@ -16,7 +16,7 @@ impl Semaphore {
|
||||
|
||||
let s;
|
||||
unsafe {
|
||||
- s = libc::sem_open(raw_sema_name.as_ptr() as *const i8, libc::O_CREAT, libc::S_IRUSR | libc::S_IWUSR, 1);
|
||||
+ s = libc::sem_open(raw_sema_name.as_ptr() as *const u8, libc::O_CREAT, libc::S_IRUSR | libc::S_IWUSR, 1);
|
||||
if s.is_null() {
|
||||
return Err(From::from("Failed to allocate named semaphore, sem_open() failed"));
|
||||
}
|
||||
--
|
||||
2.14.4
|
||||
|
@ -0,0 +1,88 @@
|
||||
Name: prefixdevname
|
||||
Version: 0.1.0
|
||||
Release: 8%{?dist}
|
||||
Summary: Udev helper utility that provides network interface naming using user defined prefix
|
||||
|
||||
License: MIT
|
||||
URL: https://www.github.com/msekletar/prefixdevname
|
||||
Source0: https://github.com/msekletar/%{name}/releases/download/v%{version}/%{name}-%{version}.tar.gz
|
||||
Source1: %{name}-%{version}-vendor.tar.gz
|
||||
|
||||
Patch0001: 0001-udev-assign-new-name-to-the-interface-directly-and-d.patch
|
||||
Patch0002: 0002-dracut-introduce-new-dracut-module-prefixdevname-too.patch
|
||||
Patch0003: 0003-core-don-t-rename-interfaces-that-already-have-the-n.patch
|
||||
Patch0004: 0004-core-if-interface-already-has-name-in-expected-forma.patch
|
||||
Patch0005: 0005-core-don-t-assign-names-to-virtual-network-devices.patch
|
||||
|
||||
Patch0999: 0999-sema-fix-cast-needed-to-build-with-rust-1.26.patch
|
||||
|
||||
ExclusiveArch: %{rust_arches}
|
||||
|
||||
BuildRequires: rust-toolset
|
||||
BuildRequires: git
|
||||
BuildRequires: systemd-devel
|
||||
|
||||
%description
|
||||
This package provides udev helper utility that tries to consistently name all ethernet NICs using
|
||||
user defined prefix (e.g. net.ifnames.prefix=net produces NIC names net0, net1, ...). Utility is
|
||||
called from udev rule and it determines NIC name and writes out configuration file for udev's
|
||||
net_setup_link built-in (e.g. /etc/systemd/network/71-net-ifnames-prefix-net0.link).
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%patch1 -p1
|
||||
%patch2 -p1
|
||||
%patch3 -p1
|
||||
%patch4 -p1
|
||||
%patch5 -p1
|
||||
|
||||
%ifarch s390 s390x ppc %{power64} aarch64
|
||||
%patch999 -p1 -b .cast
|
||||
%endif
|
||||
|
||||
%cargo_prep -V 1
|
||||
|
||||
%build
|
||||
%cargo_build
|
||||
|
||||
%install
|
||||
%make_install
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
%license LICENSE
|
||||
%doc README.md
|
||||
%{_prefix}/lib/udev/%{name}
|
||||
%{_prefix}/lib/udev/rules.d/*.rules
|
||||
%dir %{_prefix}/lib/dracut/modules.d/71%{name}
|
||||
%{_prefix}/lib/dracut/modules.d/71%{name}/*
|
||||
%dir %{_prefix}/lib/dracut/modules.d/71%{name}-tools
|
||||
%{_prefix}/lib/dracut/modules.d/71%{name}-tools/*
|
||||
|
||||
%changelog
|
||||
* Tue Aug 10 2021 Mohan Boddu <mboddu@redhat.com> - 0.1.0-8
|
||||
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
|
||||
Related: rhbz#1991688
|
||||
|
||||
* Fri Apr 16 2021 Mohan Boddu <mboddu@redhat.com> - 0.1.0-7
|
||||
- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937
|
||||
|
||||
* Wed Dec 19 2018 Michal Sekletár <msekleta@redhat.com> - 0.1.0-6
|
||||
- rebuild with non-SCL toolset
|
||||
|
||||
* Mon Nov 05 2018 Michal Sekletár <msekleta@redhat.com> - 0.1.0-5
|
||||
- if interface has name in expected format print it to stdout (#1643515)
|
||||
- don't assign names to virtual devices (#1644294)
|
||||
|
||||
* Fri Sep 21 2018 Michal Sekletár <msekleta@redhat.com> - 0.1.0-4
|
||||
- never rename interfaces that already have names in expected format (#1631650)
|
||||
|
||||
* Wed Sep 12 2018 Michal Sekletár <msekleta@redhat.com> - 0.1.0-3
|
||||
- dracut: introduce new dracut module that includes prefixdevname to initrd.img
|
||||
|
||||
* Tue Aug 14 2018 Michal Sekletár <msekleta@redhat.com> - 0.1.0-2
|
||||
- udev: assign new name to the interface directly by assigning to NAME
|
||||
|
||||
* Wed Aug 08 2018 Michal Sekletar <msekleta@redhat.com> - 0.1.0-1
|
||||
- initial package
|
Loading…
Reference in new issue