From nobody Tue May 24 20:59:54 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 7A1EC1B4F970; Tue, 24 May 2022 20:59:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4L765k6pl8z4jvB; Tue, 24 May 2022 20:59:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653425995; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eoluY82K8gaau2YZCILkEE5ztZwtYww7NGks3Ui9c3w=; b=nK9Py2234Nl0V+VBkRWLStxC1230stJq7UyPKZBY3rNMWhzwtZFh64dCzFFXjtsb4CWgVH dO6uEm5jvN7GKy1p+9huKTp0msHyUDDrdk44WSRYf2YpjBnwztV7v69DdGvEq8y0bX3k+m LoNsMbibySpFDADnx4ue+88bvGCkRO5P8PaVDww6M8smkiUYWsYXa0pFekieLcS5kbgX7Q 59+e7gmFcJ9uxqG3HuTa8aOybEjJ0MvAktuFPzQzEeolc8T/1pbDh7BNMq2ldGHr9bx5ZT pUZrP02BMgNLIvoWcbYcsq0KHsvis0fkg2uZw+dPYjtGYQDeB6B1bBvwSfixfw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7DC093AA5; Tue, 24 May 2022 20:59:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 24OKxsWp036777; Tue, 24 May 2022 20:59:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24OKxs1d036776; Tue, 24 May 2022 20:59:54 GMT (envelope-from git) Date: Tue, 24 May 2022 20:59:54 GMT Message-Id: <202205242059.24OKxs1d036776@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: d72ea9fb3ff7 - main - ifconfig: Use SIOCGIFCAPNV if supported List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d72ea9fb3ff7b80da8084b9423d8e58cbd621acf Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653425995; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eoluY82K8gaau2YZCILkEE5ztZwtYww7NGks3Ui9c3w=; b=RVfYA+0CjAMOjJrA+gt7luDTWaC24k62Y3IU02bLk82UL7ZE89ht0APKmGXSbYqLAUEm8z pyGl8OivdAFzs8mBo70j7Ca03SUfm216f36Nviu5qw5+E32Dujm3X8s1/nwDtMaTlVNZmJ 0FLo+TDh3ImorscSonesMyRIvJ52LjiTpgXsKkQLpdd7Lx3TT0svLbP0HZ0ZCakwja2fF3 iROUkD+/tVRSQIc1h4LoSGSkPQ13u2t2vRQHCpVuzoSGo+E4f55Mg6HWBmgE4Nq9PkMmIf x4ZFGSXOBExNjLnWNbqpedCDIHO2a3UGaTrAaU2/bKqAYHHDVzbHTBSg78Pjng== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1653425995; a=rsa-sha256; cv=none; b=BNYzSjmpmBzeorFilD5QsIP7dQ86VYcQynIufANVGXIvsF9QCakOeDpis2OA1El/lWY1Ve kNGrMAkqhF07Nku6dqfjt9J6p2hOVFFhTBU1BtmJsc2h7Zw1NGFo6EUjs4URsam22n0S4X IrAsGQmC41nAqgxTdqidKnYHr7ec9ky49ypWKLKAmruWOJ3UX16NfAIi81P1gOqJptlb3G v5nYMiasNGYENCaI9MIXTCFWE+QHI7uuTS3cq+T/ZXEHNuRWruhSxr5ADLEm1We+ukP3BF 91c7GNaOtHcFs18z0iWojGzpzSyFqxAPzvY/avBeMzPhiYS4cUBEh7Q2xtQTag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=d72ea9fb3ff7b80da8084b9423d8e58cbd621acf commit d72ea9fb3ff7b80da8084b9423d8e58cbd621acf Author: Konstantin Belousov AuthorDate: 2021-12-15 03:46:33 +0000 Commit: Konstantin Belousov CommitDate: 2022-05-24 20:59:33 +0000 ifconfig: Use SIOCGIFCAPNV if supported Reviewed by: hselasky, jhb, kp (previous version) Sponsored by: NVIDIA Networking MFC after: 3 weeks Differential revision: https://reviews.freebsd.org/D32551 --- sbin/ifconfig/ifconfig.c | 65 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 2ed7d43ac50c..4a0c3522c8e5 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1425,8 +1425,12 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, struct ifaddrs *ifa) { struct ifaddrs *ift; - int allfamilies, s; struct ifstat ifs; + nvlist_t *nvcap; + const char *nvname; + void *buf, *cookie; + int allfamilies, s, type; + bool first, val; if (afp == NULL) { allfamilies = 1; @@ -1471,13 +1475,62 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, } if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) { - if (ifr.ifr_curcap != 0) { + if ((ifr.ifr_curcap & IFCAP_NV) != 0) { + buf = malloc(IFR_CAP_NV_MAXBUFSIZE); + if (buf == NULL) + Perror("malloc"); + ifr.ifr_cap_nv.buffer = buf; + ifr.ifr_cap_nv.buf_length = IFR_CAP_NV_MAXBUFSIZE; + if (ioctl(s, SIOCGIFCAPNV, (caddr_t)&ifr) != 0) + Perror("ioctl (SIOCGIFCAPNV)"); + nvcap = nvlist_unpack(ifr.ifr_cap_nv.buffer, + ifr.ifr_cap_nv.length, 0); + if (nvcap == NULL) + Perror("nvlist_unpack"); + printf("\toptions"); + cookie = NULL; + for (first = true;; first = false) { + nvname = nvlist_next(nvcap, &type, &cookie); + if (nvname == NULL) { + printf("\n"); + break; + } + if (type == NV_TYPE_BOOL) { + val = nvlist_get_bool(nvcap, nvname); + if (val) { + printf("%c%s", + first ? ' ' : ',', nvname); + } + } + } + if (supmedia) { + printf("\tcapabilities"); + cookie = NULL; + for (first = true;; first = false) { + nvname = nvlist_next(nvcap, &type, + &cookie); + if (nvname == NULL) { + printf("\n"); + break; + } + if (type == NV_TYPE_BOOL) + printf("%c%s", first ? ' ' : + ',', nvname); + } + } + nvlist_destroy(nvcap); + free(buf); + + if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) != 0) + Perror("ioctl (SIOCGIFCAP)"); + } else if (ifr.ifr_curcap != 0) { printb("\toptions", ifr.ifr_curcap, IFCAPBITS); putchar('\n'); - } - if (supmedia && ifr.ifr_reqcap != 0) { - printb("\tcapabilities", ifr.ifr_reqcap, IFCAPBITS); - putchar('\n'); + if (supmedia && ifr.ifr_reqcap != 0) { + printb("\tcapabilities", ifr.ifr_reqcap, + IFCAPBITS); + putchar('\n'); + } } }