diff mbox series

[OSSTEST,14/36] preseed_base, ts-host-install: Change NIC NamePolicy to "mac"

Message ID 20240318165545.3898-15-anthony.perard@citrix.com (mailing list archive)
State New, archived
Headers show
Series Switch to Debian Bookworm | expand

Commit Message

Anthony PERARD March 18, 2024, 4:55 p.m. UTC
On "italia?" machine, the two network interfaces are competing to have
"eno1", base on the "onboard" naming policy. So the name of the
network interface can change between "eno1" and "eth0".

Switching to "mac" should avoid the unpredictable name based on
"onboard" or "slot" policy.

The "mac" naming policy break `vif-bridge` for the "vif*.*" network
interfaces. So we will avoid the "mac" policy if the driver is "vif".
This also have an impact on guest created with ./ts-debian-install, as
they use the initrd from dom0, so the interface in the guest will be
renamed according to default policy (which rename eth0 to enX0).

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 Osstest/Debian.pm | 22 ++++++++++++++++++++++
 ts-host-install   | 16 ++++++++++++++++
 2 files changed, 38 insertions(+)
diff mbox series

Patch

diff --git a/Osstest/Debian.pm b/Osstest/Debian.pm
index 102b0246..31d32d6f 100644
--- a/Osstest/Debian.pm
+++ b/Osstest/Debian.pm
@@ -962,6 +962,28 @@  cp /$RULESDIR/70-persistent-*.rules /target/$RULESDIR 2>/dev/null || true
 
 END
 
+    if ($ho->{Suite} !~ m/lenny|squeeze|wheezy|jessie|stretch|buster/) {
+        # Always use MAC address in network interface names.
+        #
+        # But keep the default policy if the driver is "vif", which match the
+        # "vif$domid.$idx" interface in dom0, and the interface in domU. This file
+        # is going to be added to dom0's initrd, which is used by some guests
+        # (created with ts-debian-install).
+        preseed_hook_installscript($ho, $sfx,
+            '/usr/lib/base-installer.d/', '05ifnamepolicy', <<'END');
+#!/bin/sh -e
+linkfile=/target/etc/systemd/network/90-eth-mac-policy.link
+mkdir -p `dirname $linkfile`
+cat > $linkfile <<EOF
+[Match]
+Type=ether
+Driver=!vif
+[Link]
+NamePolicy=mac
+EOF
+END
+    }
+
     debian_overlays($ho, sub {
 	my ($srcdir, $tfilename) = @_;
 	preseed_hook_overlay($ho, $sfx, $srcdir, $tfilename);
diff --git a/ts-host-install b/ts-host-install
index 88481038..0b6aaeea 100755
--- a/ts-host-install
+++ b/ts-host-install
@@ -248,6 +248,22 @@  END
     print CANARY "\n# - canary - came via initramfs\n" or die $!;
     close CANARY or die $!;
 
+    if ($ho->{Suite} !~ m/lenny|squeeze|wheezy|jessie|stretch|buster/) {
+        # Switch to more predictale nic name based on mac address, instead of the
+        # policy "onboard" which can try to set the same name ("eno1") to two
+        # differents nic, or "slot". New names are "enx$mac".
+        system_checked(qw(mkdir -p --), "$initrd_overlay.d/lib/systemd/network");
+        file_simple_write_contents
+            ("$initrd_overlay.d/lib/systemd/network/90-eth-mac-policy.link",
+                <<END);
+[Match]
+Type=ether
+Driver=!vif
+[Link]
+NamePolicy=mac
+END
+    }
+
     my %xopts;
 
     di_special_kernel($ho, sub {