libexec/rc: 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 b1b17432aa,
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
MFC-after:	2 weeks
This commit is contained in:
Eugene Grosbein 2025-07-01 21:13:10 +07:00
parent b1b17432aa
commit 6d3bc576ab
2 changed files with 29 additions and 8 deletions

View file

@ -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 1
_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()

View file

@ -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