From 94cfe59ff90a8e874696a7574555f56986b781ac Mon Sep 17 00:00:00 2001 From: Eric Gumtow Date: Tue, 17 Feb 2026 16:09:15 -0800 Subject: [PATCH 1/2] down network interfaces behind USB ports --- custom_files/disable_disconnected_nics.sh | 30 +++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/custom_files/disable_disconnected_nics.sh b/custom_files/disable_disconnected_nics.sh index 745df23..f9f3995 100755 --- a/custom_files/disable_disconnected_nics.sh +++ b/custom_files/disable_disconnected_nics.sh @@ -3,9 +3,35 @@ # Get a list of all network interfaces (excluding loopback) interfaces=$(ls /sys/class/net | grep -v lo) +should_down() +{ + # Check if the interface is disconnected (carrier not detected) + if [[ -f "/sys/class/net/$1/carrier" && "$(cat /sys/class/net/$1/carrier)" == "0" ]]; then + return 1 + fi + + # Check if the interface is bridged by USB (PCI -> USB -> ethernet) + if [[ "$1" =~ enp0s[0-9]{1,}f[0-9]u[0-9]{1,} ]] ; then + # Naming convention documentation: https://www.freedesktop.org/software/systemd/man/latest/systemd.net-naming-scheme.html + # Table 3: slot naming schemes + # en --> ethernet + # p0 --> PCI domain 0 + # s[0-9]{1,} --> PCI slot 0 or higher, seems to be decimal from code (safe_atou*()) + # f[0-9] --> PCI function 0 to 9 + # u[0-9]{1,} --> USB port 0 or higher + # + # Minh has "enp0s20f0u7u4", which matches and additionally is behind a second USB port (u7u4). + return 1 + fi + + return 0 +} + for iface in $interfaces; do - # Check if the interface is disconnected (carrier detected) - if [[ -f "/sys/class/net/$iface/carrier" ]] && [[ "$(cat /sys/class/net/$iface/carrier)" == "0" ]]; then + if [[ $(should_down $iface) == "1" ]]; then + echo "downing iface $iface" ip link set dev $iface down + else + echo "up iface $iface" fi done From 86bce7ec2fca1ee9f2b0f1dc1152599d406ddd88 Mon Sep 17 00:00:00 2001 From: Eric Gumtow Date: Wed, 18 Feb 2026 09:55:24 -0800 Subject: [PATCH 2/2] use + one-or-more matching, and match PCI domains higher than 0 --- custom_files/disable_disconnected_nics.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/custom_files/disable_disconnected_nics.sh b/custom_files/disable_disconnected_nics.sh index f9f3995..fece9af 100755 --- a/custom_files/disable_disconnected_nics.sh +++ b/custom_files/disable_disconnected_nics.sh @@ -11,14 +11,15 @@ should_down() fi # Check if the interface is bridged by USB (PCI -> USB -> ethernet) - if [[ "$1" =~ enp0s[0-9]{1,}f[0-9]u[0-9]{1,} ]] ; then + if [[ "$1" =~ enp[0-9]+s[0-9]+f[0-9]u[0-9]+ ]] ; then # Naming convention documentation: https://www.freedesktop.org/software/systemd/man/latest/systemd.net-naming-scheme.html # Table 3: slot naming schemes - # en --> ethernet - # p0 --> PCI domain 0 - # s[0-9]{1,} --> PCI slot 0 or higher, seems to be decimal from code (safe_atou*()) - # f[0-9] --> PCI function 0 to 9 - # u[0-9]{1,} --> USB port 0 or higher + # en --> ethernet + # p[0-9]+ --> PCI domain 0 or higher + # s[0-9]+ --> PCI slot 0 or higher + # f[0-9] --> PCI function 0 to 9 + # u[0-9]+ --> USB port 0 or higher + # all numbers seem to be in decimal from examining the code (safe_atou*()). # # Minh has "enp0s20f0u7u4", which matches and additionally is behind a second USB port (u7u4). return 1