git: 5d15e09a26c6 - stable/13 - libexec/rc: MFC: improve performance of pccard_ether script
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 13 Jul 2025 15:49:17 UTC
The branch stable/13 has been updated by eugen:
URL: https://cgit.FreeBSD.org/src/commit/?id=5d15e09a26c6b08fc0d5cd7deca082ba5b9cabd4
commit 5d15e09a26c6b08fc0d5cd7deca082ba5b9cabd4
Author: Eugene Grosbein <eugen@FreeBSD.org>
AuthorDate: 2025-07-01 14:13:10 +0000
Commit: Eugene Grosbein <eugen@FreeBSD.org>
CommitDate: 2025-07-13 15:48:37 +0000
libexec/rc: MFC: improve performance of pccard_ether script
Replace "ifconfig -ul" with "ifconfig -n" because netlink-enabled
/sbin/ifconfig utility has sub-optimal performance for listing.
Combined with the commit b1b17432aa1be670564161232d110461a5dde4ce,
these changes mostly eliminate performance regression of the command
"service devd start" for a system having hundreds of network interfaces
created before devd starts, after FreeBSD 14+ switched
/sbin/ifconfig to netlink(4)
PR: 287872
(cherry picked from commit 6d3bc576abbd84f736d917f5bfec4e3fe7e6c125)
(cherry picked from commit 24e8ed535ff673b9ea751c3d3b2a68ef0a29b0e2)
---
libexec/rc/network.subr | 20 ++++++++++++++++++++
libexec/rc/pccard_ether | 17 +++++++++--------
2 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/libexec/rc/network.subr b/libexec/rc/network.subr
index 931fbec19a60..5e4f2c1f39a0 100644
--- a/libexec/rc/network.subr
+++ b/libexec/rc/network.subr
@@ -653,6 +653,26 @@ ifexists()
${IFCONFIG_CMD} -n $1 > /dev/null 2>&1
}
+# ifisup if
+# Returns 0 if the interface exists and UP,
+# returns 1 if the interface exists and not UP,
+# returns 2 otherwise.
+ifisup()
+{
+ local _if
+
+ [ -z "$1" ] && return 2
+ _if="$1"
+
+ set -- $(${IFCONFIG_CMD} -n ${_if} 2>/dev/null)
+ case "$1$2" in
+ ${_if}:*'<UP'[,\>]*) return 0 ;;
+ ${_if}:*) return 1 ;;
+ esac
+
+ return 2
+}
+
# ipv4_up if
# add IPv4 addresses to the interface $if
ipv4_up()
diff --git a/libexec/rc/pccard_ether b/libexec/rc/pccard_ether
index 7ca58f210085..957983e55a8e 100755
--- a/libexec/rc/pccard_ether
+++ b/libexec/rc/pccard_ether
@@ -69,16 +69,17 @@ checkauto()
pccard_ether_start()
{
- ifexists $ifn || exit 1
-
- if [ -z "$rc_force" ]; then
- for uif in `ifconfig -ul`; do
- if [ "${uif}" = "${ifn}" ]; then
- # Interface is already up, so ignore it.
+ ifisup $ifn
+ case $? in
+ 0) # Interface is already up, so ignore it.
+ if [ -z "$rc_force"]; then
exit 0
fi
- done
- fi
+ ;;
+ 2) # Interface does not exist.
+ exit 1
+ ;;
+ esac
/etc/rc.d/netif quietstart $ifn