From owner-freebsd-hackers@freebsd.org Fri Jan 12 15:09:29 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 469CCE69F6A for ; Fri, 12 Jan 2018 15:09:29 +0000 (UTC) (envelope-from toasty@dragondata.com) Received: from mail-it0-x22e.google.com (mail-it0-x22e.google.com [IPv6:2607:f8b0:4001:c0b::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 146E66EEC3 for ; Fri, 12 Jan 2018 15:09:29 +0000 (UTC) (envelope-from toasty@dragondata.com) Received: by mail-it0-x22e.google.com with SMTP id c16so9401598itc.5 for ; Fri, 12 Jan 2018 07:09:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dragondata.com; s=google; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=KQ6xC8q8YBbsUlZSdSP1DmNgTvHvQMPc5LEaI9cVu20=; b=m/F/wZtr5yCn4cPPksDjlQm+jKj9I7vFJgwQ9RCOqRkhJGqF8aqh03pSNLbjGALEIG 95LvrEryUes4jAevtlz9Dq5GCTgmDBTVeFRZN8DzLhxrd41qeS+FemigLumGC0Q1ibC7 VXGfxMDTnz9WmTfsIxAuVFVQISa3Da02a3yvM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=KQ6xC8q8YBbsUlZSdSP1DmNgTvHvQMPc5LEaI9cVu20=; b=RBsxb5mMUJfXpaVTAB4lNH8/pfnoIXy3WHa23BU+kdxFHGOFOXB3KO9Z7MKXhJk+Oq pWAg8Br3TyESrN2R7jHpYPF+iWuTuYdhtqMUoQH1ErjuwoBYrA6WZCDlmtnjpUU/Wj2i 0q09tJOpc+FaVAJWNIW9KxGvWapUd2Qa9UOtL/Q+IjEZZfI9minxJGT+O+naKdvet8pa EczicSF8iR+kXrGTGgJmpr4yQOvdEUtGanqOHOjl7v4zBX2wp6uWz4R33tkjlDIKfwe9 5Qnog0DVztSGVu0yQCnvjkDyEc0XMprPT1YcAX2zXtOT2g2vscinFaVKoSomGiiPW0P5 VIww== X-Gm-Message-State: AKwxytc38XB74jrMn4wAEPqf6ED97EH3RT9d1HTIOvXGjtPDp1Wfl9Uf 6rPfl+xHitcpYKMIeNGafEaDVFHkhUA= X-Google-Smtp-Source: ACJfBouKi5461oSR/ptR3bG+Vq8kMc4UrqtbzaS7dp/qXfAcFqU1MKO9ffKW5meJTEUlvhautSAyAA== X-Received: by 10.36.9.144 with SMTP id 138mr4893596itm.125.1515769767989; Fri, 12 Jan 2018 07:09:27 -0800 (PST) Received: from unassigned.v6.your.org ([2001:4978:1:45:f8d5:9e8:2741:8367]) by smtp.gmail.com with ESMTPSA id z102sm9924168ioi.86.2018.01.12.07.09.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 07:09:27 -0800 (PST) From: Kevin Day Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: sysctl(8) can't read IFMIB nodes Message-Id: <18D7A1E9-8564-47D7-90D7-CA2E94F7F9F7@dragondata.com> Date: Fri, 12 Jan 2018 09:09:26 -0600 To: freebsd-hackers@freebsd.org X-Mailer: Apple Mail (2.3445.5.20) 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: Fri, 12 Jan 2018 15:09:29 -0000 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,0= x1b) 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?) 3) Overhauling sysctl.oidfmt and oiddescr to somehow work by names as = well as oids so that sysctl(8) doesn't need to translate them to oids = first