Date: Mon, 28 Sep 2020 16:54:39 +0000 (UTC) From: Ed Maste <emaste@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366230 - in head: share/man/man9 sys/net sys/sys Message-ID: <202009281654.08SGsdce041551@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: emaste Date: Mon Sep 28 16:54:39 2020 New Revision: 366230 URL: https://svnweb.freebsd.org/changeset/base/366230 Log: 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 <roy@marples.name> Reviewed by: markj MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D26538 Modified: head/share/man/man9/ifnet.9 head/sys/net/if.c head/sys/sys/sockio.h Modified: head/share/man/man9/ifnet.9 ============================================================================== --- head/share/man/man9/ifnet.9 Mon Sep 28 16:19:29 2020 (r366229) +++ head/share/man/man9/ifnet.9 Mon Sep 28 16:54:39 2020 (r366230) @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 14, 2018 +.Dd September 28, 2020 .Dt IFNET 9 .Os .Sh NAME @@ -1310,12 +1310,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 Modified: head/sys/net/if.c ============================================================================== --- head/sys/net/if.c Mon Sep 28 16:19:29 2020 (r366229) +++ head/sys/net/if.c Mon Sep 28 16:54:39 2020 (r366230) @@ -2518,6 +2518,18 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, 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); Modified: head/sys/sys/sockio.h ============================================================================== --- head/sys/sys/sockio.h Mon Sep 28 16:19:29 2020 (r366229) +++ head/sys/sys/sockio.h Mon Sep 28 16:54:39 2020 (r366230) @@ -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 SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */ #define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202009281654.08SGsdce041551>