From nobody Mon Dec 13 00:29:11 2021 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 DD34D18F52F1; Mon, 13 Dec 2021 00:29:12 +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 4JC2SS20yPz3hWC; Mon, 13 Dec 2021 00:29:12 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 CA8BF2D9C; Mon, 13 Dec 2021 00:29:11 +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 1BD0TB5T060153; Mon, 13 Dec 2021 00:29:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BD0TBnk060152; Mon, 13 Dec 2021 00:29:11 GMT (envelope-from git) Date: Mon, 13 Dec 2021 00:29:11 GMT Message-Id: <202112130029.1BD0TBnk060152@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: faa8d81cf7a2 - stable/12 - add SIOCGIFDATA ioctl 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: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: faa8d81cf7a25db3b7ea45acbef0cb28d80eefe0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639355352; 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=6q+jD2wAC7CyJt5KrcW9es0u5wO3kUSoThgI2vwPEbQ=; b=lPYA++KT5kCAWtOeeS4soQGGDS6edfyasiL+IDUvJlQKNCpIZ10m61z1ywFI2vUop5dAOW P7Hs1YDIdLaHcl4bwc5XpSD7fZse+8GnOQv1TqTOZoEi5PPQYdHlCaOoBa4FNtqgtSdzhn OGHg+k5zuhcaNRPspp20lbi6tdAl6ih/UUkFaZkB0dV1RUvgdtNAkCEYaaC8eLPmyI4lgc vkVHB5KLTGB8Yuwwc5suH6+zFzsNHjUeeZW4lOITVyDerwyR4FA/oxcXNafXoADhYzF1Z2 XoYo7NWcFXHvG2CUE+2HKUYHcKpn46mtgMgZm7XYIx/rxWyzTZx1mS735NojxA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639355352; a=rsa-sha256; cv=none; b=fQc6yc8pNbnxsYSHPXbR10Lc/MOG1ZPhaUvevSfRUMSp/8EfQoOht+rXvt3FTqjPqn+pEN Gu2xW4/A3RRZI8o+/Mdkez9bxcO5aBgxLJ4WkGf4Nu34fXflrqh5XA/qILrh7d+Qj80qNL Xu3l8w/PTWvdoP/iFMUcgpdT84da010Pk3RzQMc1RHWKLm6IKsgpftbuPYuZpMyCghAY9R pcKuSmJDOkEllYzkYNY/hhR2dDXw6/7Ls8AJlgP++ZQ5onEJapyoXu+YeJq4BHRRT7Dcuh qwLpT1VlOz7gqFUs5kjRSDtZbzBU1ChdORQK3YsVmORjAxfZgckygDeXlPgK8g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=faa8d81cf7a25db3b7ea45acbef0cb28d80eefe0 commit faa8d81cf7a25db3b7ea45acbef0cb28d80eefe0 Author: Ed Maste AuthorDate: 2020-09-28 16:54:39 +0000 Commit: Ed Maste CommitDate: 2021-12-12 22:42:08 +0000 add SIOCGIFDATA ioctl For interfaces that do not support SIOCGIFMEDIA (for which there are quite a few) the only fallback is to query the interface for if_data->ifi_link_state. While it's possible to get at if_data for an interface via getifaddrs(3) or sysctl, both are heavy weight mechanisms. SIOCGIFDATA is a simple ioctl to retrieve this fast with very little resource use in comparison. This implementation mirrors that of other similar ioctls in FreeBSD. Submitted by: Roy Marples Reviewed by: markj MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D26538 (cherry picked from commit c1aedfcbd9896401f637bc815ba4e51dca107f6f) --- share/man/man9/ifnet.9 | 5 +++-- sys/net/if.c | 12 ++++++++++++ sys/sys/sockio.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/share/man/man9/ifnet.9 b/share/man/man9/ifnet.9 index ebe202079588..eb12a91eb603 100644 --- a/share/man/man9/ifnet.9 +++ b/share/man/man9/ifnet.9 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 14, 2018 +.Dd September 28, 2020 .Dt IFNET 9 .Os .Sh NAME @@ -1276,12 +1276,13 @@ list. Caller must have appropriate privilege. (No call-down to driver.) .It Dv SIOCGIFCAP +.It Dv SIOCGIFDATA .It Dv SIOCGIFFIB .It Dv SIOCGIFFLAGS .It Dv SIOCGIFMETRIC .It Dv SIOCGIFMTU .It Dv SIOCGIFPHYS -Get interface capabilities, FIB, flags, metric, MTU, medium selection. +Get interface capabilities, data, FIB, flags, metric, MTU, medium selection. (No call-down to driver.) .Pp .It Dv SIOCSIFCAP diff --git a/sys/net/if.c b/sys/net/if.c index f2ef88d3f28e..d93d63f82f23 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -2633,6 +2633,18 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) ifr->ifr_curcap = ifp->if_capenable; break; + case SIOCGIFDATA: + { + struct if_data ifd; + + /* Ensure uninitialised padding is not leaked. */ + memset(&ifd, 0, sizeof(ifd)); + + if_data_copy(ifp, &ifd); + error = copyout(&ifd, ifr_data_get_ptr(ifr), sizeof(ifd)); + break; + } + #ifdef MAC case SIOCGIFMAC: error = mac_ifnet_ioctl_get(td->td_ucred, ifr, ifp); diff --git a/sys/sys/sockio.h b/sys/sys/sockio.h index 2e5a56200e1b..93b8af28e171 100644 --- a/sys/sys/sockio.h +++ b/sys/sys/sockio.h @@ -83,6 +83,7 @@ #define SIOCSIFDESCR _IOW('i', 41, struct ifreq) /* set ifnet descr */ #define SIOCGIFDESCR _IOWR('i', 42, struct ifreq) /* get ifnet descr */ #define SIOCAIFADDR _IOW('i', 43, struct ifaliasreq)/* add/chg IF alias */ +#define SIOCGIFDATA _IOW('i', 44, struct ifreq) /* get if_data */ #define SIOCGIFALIAS _IOWR('i', 45, struct ifaliasreq)/* get IF alias */ #define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */