From owner-freebsd-current@FreeBSD.ORG Tue Jul 10 19:07:16 2007 Return-Path: X-Original-To: current@freebsd.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 163A516A46D for ; Tue, 10 Jul 2007 19:07:16 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (66-23-211-162.clients.speedfactory.net [66.23.211.162]) by mx1.freebsd.org (Postfix) with ESMTP id 7BBCD13C468 for ; Tue, 10 Jul 2007 19:07:15 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.13.8/8.13.8) with ESMTP id l6AJ7DQF076531; Tue, 10 Jul 2007 15:07:13 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: current@freebsd.org Date: Tue, 10 Jul 2007 15:07:06 -0400 User-Agent: KMail/1.9.6 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200707101507.06713.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Tue, 10 Jul 2007 15:07:13 -0400 (EDT) X-Virus-Scanned: ClamAV 0.88.3/3624/Tue Jul 10 13:00:38 2007 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: gnn@freebsd.org Subject: [PATCH] Restore netstat -M functionality X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Jul 2007 19:07:16 -0000 The primary purpose of this patch is to restore -M functionality of netstat so that it can pull information out of crash dumps. Right now it just silently pulls stats from the running kernel for functions that use sysctl which is even worse than missing functionality: it lies. It also fixes a subtle bug in the recent IPSEC changes which didn't renumber the N_xxx constants in the name list after removing a symbol which currently breaks all the IPSec stats. The biggest things the patch does are: - Add a global 'live' variable that is true if netstat is running against the live kernel and false if -M has been specified. - Stop abusing the sysctl flag in the protocol tables to hold the protocol number. Instead, the protocol is now its own field in the tables, and it is passed as a separate parameter to the PCB and stat routines rather than overloading the KVM offset parameter. - Don't run PCB or stats functions who don't have a namelist offset if we are being run against a crash dump (!live). - For the inet and unix PCB routines, we generate the same buffer from KVM that the sysctl usually generates complete with the header and trailer. - Don't run bpf stats for !live (before it would just silently always run live). - kread() no longer trashes memory when opening the buffer if there is an error on open and the passed in buffer is smaller than _POSIX2_LINE_MAX. - The multicast routing code doesn't fallback to kvm on live kernels if the sysctl fails. Keeping this made the code rather hairy, and netstat is already tied to the kernel ABI anyway (even when using sysctl's since things like xinpcb contain an inpcb) so any kernels this is run against that have the multicast routing stuff should have the sysctls. - Don't try to dig around in the kernel linker in the netgraph PCB routine for core dumps. One thing not done: - sctp's PCB routine only works on live kernels, it looked rather complicated to generate all the same stuff via KVM. Someone can always add it later if desired though. Other stuff: - Fix the ipsec removal bug where N_xxx for IPSEC stats weren't renumbered. - Use sysctlbyname() everywhere rather than hardcoded mib values. Patch is at http://www.FreeBSD.org/~jhb/patches/netstat_core_7.patch A patch for 6.x is also available as netstat_core.patch Barring any objections/feedback I will be committing this to CVS in a few days (subject to re@ approval of course). -- John Baldwin