git: bacbebb16d84 - stable/13 - ifconfig: improve trimming off interface number at end
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 26 Jun 2023 12:08:24 UTC
The branch stable/13 has been updated by bz:
URL: https://cgit.FreeBSD.org/src/commit/?id=bacbebb16d844100eefdb3b98007952272428e45
commit bacbebb16d844100eefdb3b98007952272428e45
Author: Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2023-05-17 20:40:47 +0000
Commit: Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2023-06-26 09:04:18 +0000
ifconfig: improve trimming off interface number at end
When trying to auto-load a module, we trim the interface number off
the end. Currently we stop at the first digit. For interfaces which
have numbers in the driver name this does not work well.
In the current example ifconfig ath10k0 would load ath(4) instead of
ath10k(4). For module/interface names like rtw88[0] we never guess
correctly.
To improve for the case we can, start trimming off digits from the
end rather than the front.
Sponsored by: The FreeBSD Foundation
Reported by: thierry
Reviewed by: melifaro, thierry
Differential Revision: https://reviews.freebsd.org/D40137
(cherry picked from commit 2e6756b752e07878ae5f5e3e9b74934231f9fd17)
---
sbin/ifconfig/ifconfig.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index f01f40e46a8b..6deeebba9f01 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -1566,11 +1566,13 @@ ifmaybeload(const char *name)
/* trim the interface number off the end */
strlcpy(ifname, name, sizeof(ifname));
- for (dp = ifname; *dp != 0; dp++)
- if (isdigit(*dp)) {
- *dp = 0;
+ dp = ifname + strlen(ifname) - 1;
+ for (; dp > ifname; dp--) {
+ if (isdigit(*dp))
+ *dp = '\0';
+ else
break;
- }
+ }
/* Either derive it from the map or guess otherwise */
*ifkind = '\0';