From owner-freebsd-hackers@freebsd.org Wed Apr 18 17:19:45 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D6A5AF9BD28 for ; Wed, 18 Apr 2018 17:19:45 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8127F85D27 for ; Wed, 18 Apr 2018 17:19:45 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from ralph.baldwin.cx (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id 6BCC810AFD4; Wed, 18 Apr 2018 13:19:44 -0400 (EDT) From: John Baldwin To: freebsd-hackers@freebsd.org Cc: Kevin Day Subject: Re: sysctl(8) can't read IFMIB nodes Date: Wed, 18 Apr 2018 09:21:57 -0700 Message-ID: <5477049.PC1KtAaiLR@ralph.baldwin.cx> User-Agent: KMail/4.14.10 (FreeBSD/11.1-STABLE; KDE/4.14.30; amd64; ; ) In-Reply-To: <18D7A1E9-8564-47D7-90D7-CA2E94F7F9F7@dragondata.com> References: <18D7A1E9-8564-47D7-90D7-CA2E94F7F9F7@dragondata.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (mail.baldwin.cx); Wed, 18 Apr 2018 13:19:44 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.99.2 at mail.baldwin.cx X-Virus-Status: Clean X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Apr 2018 17:19:46 -0000 On Friday, January 12, 2018 09:09:26 AM Kevin Day wrote: > > IFMIB doesn't work with the command-line tool sysctl(8). src/tools/tools/ifinfo uses IFMIB correctly though, so I looked at why: > > ifinfo is calling sysctlbyname() directly: > > 86387 ifinfo CALL __sysctl(0x7fffffffe510,0x6,0x7fffffffe530,0x7fffffffe100,0,0) > 86387 ifinfo SCTL "net.link.generic.ifdata.1.1" > 86387 ifinfo RET __sysctl 0 > > But using sysctl directly doesn't: > > # ktrace sysctl net.link.generic.ifdata.1.1 > sysctl: unknown oid 'net.link.generic.ifdata.1.1': No such file or directory > > The problem is that sysctl(8) is calling sysctl.name2oid on it first, so that it can get type information on it: > > 21090 sysctl CALL __sysctl(0x7fffffffda00,0x2,0x7fffffffd970,0x7fffffffd9f8,0x7fffffffe210,0x1b) > 21090 sysctl SCTL "sysctl.name2oid" > 21090 sysctl RET __sysctl -1 errno 2 No such file or directory > 21090 sysctl CALL write(0x2,0x7fffffffd2d0,0x8) > 21090 sysctl GIO fd 2 wrote 8 bytes > "sysctl: " > 21090 sysctl RET write 8 > 21090 sysctl CALL write(0x2,0x7fffffffd3c0,0x29) > 21090 sysctl GIO fd 2 wrote 41 bytes > "unknown oid 'net.link.generic.ifdata.1.1'" > > This fails because in the kernel, ifmib isn't setting up oids for every possible entry under ifdata, it configures the parent node then captures every request under it. > > I'm specifically looking to be able to get link state/speed on all interfaces from what's essentially a shell script using tools that only exist in a base install. > > If I were trying to fix this with a patch that would likely get accepted, what's the best way of fixing this? > > 1) Making IFMIB create sysctls for every interface? This would require it get involved every time an interface is added or deleted, which might not be popular because this is a very infrequently used feature. > > 2) Allowing sysctl(8) to forge ahead anyway with reading/writing to sysctls without oids (maybe only if the -o flag is present?) I would fix sysctl by extending it to handle a MIB which is written as either all integers or with a prefix that is a name. -- John Baldwin