From nobody Tue May 24 20:59:52 2022 X-Original-To: dev-commits-src-all@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 7C3AE1B4F7D0; Tue, 24 May 2022 20:59:53 +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 4L765h3Zs9z4jrg; Tue, 24 May 2022 20:59:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653425992; 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=an2ekOoZWwllcZx0ZAvs6TC+rtczm17fngIW4/7n36Q=; b=N7yIGcoO+jutHer3bv+lpqxM4ar/Ar20qtLj6j8AvHnp61612OpB5UTXZHkE67NFQxdg9i MOrygrhVBEqODvHkwVoYKT7fjM4g0muii1Jzq0OJW1DW896QyTvmJCRPHpjhWZf5MZeuFG rxnYWs2a2ggrNWCwihow7C7QD8TOqU0kpggYXC/g2bGY1auzShcJw3ocUazBEIC+syyO2P eHWlUSraDCQmNGKovRc86o9Q095XT3XYnQUDnqyzdWsa83vCXdJ/H+OnS5ovdMCq2d8Iw4 Jnaov+g6YAdZOUqc6jsIMghrhoaC/RU9xfQUR9OFAuFKDavbtvbOru2l2QmrXQ== 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 3812237D6; Tue, 24 May 2022 20:59:52 +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 24OKxqio036729; Tue, 24 May 2022 20:59:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24OKxqcP036728; Tue, 24 May 2022 20:59:52 GMT (envelope-from git) Date: Tue, 24 May 2022 20:59:52 GMT Message-Id: <202205242059.24OKxqcP036728@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: 6ca418e4816a - main - ifconfig: add setifcapnv() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 6ca418e4816a9d1db18f2ce55dcab6c04757be27 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653425992; 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=an2ekOoZWwllcZx0ZAvs6TC+rtczm17fngIW4/7n36Q=; b=Ay+fjpc3JaerBCbTZAxmRn2Rg6uqWM2vtBBh0LxZQ/30RuXcZc1A87J9DyxPPs9ztxKaK+ SLBkL84Ckd0tpn6XsCB/Wt5A+G2HIthd8w94yIFkgZeFOiyupz/QjGQWSSwidljkETSmS8 leI+MFCf4iSMV9mOoj3XYpPzKe1b8k9uLsdhgqyWzzpZG9e11b5WBK6LaJdrAUOBelV4Vd y1Z8mrE9MPQcOfN8BKt1cUifZQpjPnpi1Qk46v8x6xmHMtNUfnPJ1NL/EwO91C6TtxwW4q 8VhJtlwGn/5gY4KueO6LMs4Wq/spg9YMG6M4H3mBxWjyeUoRmQfpTljxAVkf5Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1653425992; a=rsa-sha256; cv=none; b=a+fzxZyjE8JrAI8liigwqVb48vgMsJqOYNYXujr9qpzET9t51/TsLWIM2PEy+wOAqHC4mu wCWUsLuzeI5N7sm+JvsNIaKXDKAEih8MCcTtfpb3YUdCT5pHaIjbyOe2FvDUrBtigJKHR/ 9/xUPf/QGc8IbAphaAOsiiczestSfPZz0RKSDjAcD+nVb8S7gFT/vxqURwhV2s8sFDl72L fA4azkKQuNV58TV9vKyEG+biJQvcBoLC9CoJX4rIjGjGkBKzFz4aNzW3CZLN5eaAShu+0x Uay+dEnULT96XnOYynov4Ryx1oJHxUlW1lbNsWkjsswQ331Nwi6a0mx0wydWpg== 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=6ca418e4816a9d1db18f2ce55dcab6c04757be27 commit 6ca418e4816a9d1db18f2ce55dcab6c04757be27 Author: Konstantin Belousov AuthorDate: 2021-12-15 03:05:18 +0000 Commit: Konstantin Belousov CommitDate: 2022-05-24 20:59:33 +0000 ifconfig: add setifcapnv() which uses SIOCSIFCAPNV to set arbitrary string-named interface capability. Reviewed by: hselasky, jhb, kp Sponsored by: NVIDIA Networking MFC after: 3 weeks Differential revision: https://reviews.freebsd.org/D32551 --- sbin/ifconfig/ifconfig.c | 43 +++++++++++++++++++++++++++++++++++++++++++ sbin/ifconfig/ifconfig.h | 2 ++ 2 files changed, 45 insertions(+) diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 37ce0fb18943..9ee86b2a5169 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -44,6 +44,7 @@ static const char rcsid[] = #include #include #include +#include #include #include #include @@ -1253,6 +1254,48 @@ setifcap(const char *vname, int value, int s, const struct afswtch *afp) Perror(vname); } +void +setifcapnv(const char *vname, const char *arg, int s, const struct afswtch *afp) +{ + nvlist_t *nvcap; + void *buf; + char *marg, *mopt; + size_t nvbuflen; + bool neg; + + if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0) + Perror("ioctl (SIOCGIFCAP)"); + if ((ifr.ifr_curcap & IFCAP_NV) == 0) { + warnx("IFCAP_NV not supported"); + return; /* Not exit() */ + } + + marg = strdup(arg); + if (marg == NULL) + Perror("strdup"); + nvcap = nvlist_create(0); + if (nvcap == NULL) + Perror("nvlist_create"); + while ((mopt = strsep(&marg, ",")) != NULL) { + neg = *mopt == '-'; + if (neg) + mopt++; + nvlist_add_bool(nvcap, mopt, !neg); + } + buf = nvlist_pack(nvcap, &nvbuflen); + if (buf == NULL) { + errx(1, "nvlist_pack error"); + exit(1); + } + ifr.ifr_cap_nv.buf_length = ifr.ifr_cap_nv.length = nvbuflen; + ifr.ifr_cap_nv.buffer = buf; + if (ioctl(s, SIOCSIFCAPNV, (caddr_t)&ifr) < 0) + Perror(vname); + free(buf); + nvlist_destroy(nvcap); + free(marg); +} + static void setifmetric(const char *val, int dummy __unused, int s, const struct afswtch *afp) diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h index 4a9fb380fbab..26f68d67cec2 100644 --- a/sbin/ifconfig/ifconfig.h +++ b/sbin/ifconfig/ifconfig.h @@ -202,6 +202,8 @@ extern int printifname; extern int exit_code; void setifcap(const char *, int value, int s, const struct afswtch *); +void setifcapnv(const char *vname, const char *arg, int s, + const struct afswtch *afp); void Perror(const char *cmd); void printb(const char *s, unsigned value, const char *bits);