From owner-freebsd-hackers@FreeBSD.ORG Sun Oct 13 09:47:22 2013 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id DD8475B9 for ; Sun, 13 Oct 2013 09:47:22 +0000 (UTC) (envelope-from trtrmitya@gmail.com) Received: from mail-lb0-x234.google.com (mail-lb0-x234.google.com [IPv6:2a00:1450:4010:c04::234]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 662A82B46 for ; Sun, 13 Oct 2013 09:47:22 +0000 (UTC) Received: by mail-lb0-f180.google.com with SMTP id q8so4621355lbi.25 for ; Sun, 13 Oct 2013 02:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=CuW3ACdgg3w/tqMcU2CyFiygtw6xwTmy3yR4J/7ot78=; b=W+9eKBq8TmGONa8EcVdnIrp72qE7gy2g+qFI5VnPAmPJj/yuhkFBPm+GqNZvqP+5lA XX5nlpkM/217g27VMdpzF51RoBJRAG8ckQiSsz1evRbAuy5U0wk19DGjSWqNud+OxZPk IB27ELUblMAr20ANQconmr4Hvi28ZJ1MtJQCuXDjb8OHcmvq5InWZajCJPivZv+UbGdJ gyUSfhitJEJCg9qroqRIv+afB4V0aZ+MrQCwQUr+M6tnT1ihKts3+jrIkaHTMUtaTU7Y 2oWqqOC5TA3VshYWJrecWUJg8gWcLsvBjvpWhc+4omkUZlzYVcL+OzU3y7DB/+JrFMsE QeIg== X-Received: by 10.152.22.198 with SMTP id g6mr24925632laf.5.1381657640525; Sun, 13 Oct 2013 02:47:20 -0700 (PDT) Received: from [10.0.1.20] ([176.193.142.218]) by mx.google.com with ESMTPSA id b6sm53982846lae.0.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 13 Oct 2013 02:47:19 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: mmap() question From: Dmitry Sivachenko In-Reply-To: <20131012141440.GN41229@kib.kiev.ua> Date: Sun, 13 Oct 2013 13:47:17 +0400 Content-Transfer-Encoding: quoted-printable Message-Id: References: <95E0B821-BF9B-4EBF-A1E5-1DDCBB1C3D1B@gmail.com> <20131011051702.GE41229@kib.kiev.ua> <20131012095919.GI41229@kib.kiev.ua> <20131012141440.GN41229@kib.kiev.ua> To: Konstantin Belousov X-Mailer: Apple Mail (2.1510) X-Mailman-Approved-At: Sun, 13 Oct 2013 11:45:56 +0000 Cc: "hackers@freebsd.org" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Oct 2013 09:47:22 -0000 On 12.10.2013, at 18:14, Konstantin Belousov = wrote: >>=20 >> First I tried with some swap space configured. The OS started to = swap out my process after it reached about 20GB which is also not what I = expected: what is the reason to swap out regions of read-only mmap()ed = files? Is it the expected behaviour? >>=20 > How did you concluded that the pages from your r/o mappings were paged = out ? > VM never does this. Only anonymous memory could be written to swap = file, > including the shadow pages for the writeable COW mappings. I suspect = that > you have another 20GB of something used on the machine meantime. >=20 Yes, sorry, I tried again with swap space configured and it is really = some other processes which are swapping out: sshd, other user's shells, etc. >>=20 >>>=20 >>> Below is the prototype patch, against HEAD. It is not applicable to >>> stable, please use HEAD kernel for test. >>=20 I tried your patch with stable/10 system and I can confirm that my = process is not killed anymore because of OOM. From owner-freebsd-hackers@FreeBSD.ORG Tue Oct 15 04:51:20 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B1722FA9 for ; Tue, 15 Oct 2013 04:51:20 +0000 (UTC) (envelope-from pkelsey@gmail.com) Received: from mail-bk0-x234.google.com (mail-bk0-x234.google.com [IPv6:2a00:1450:4008:c01::234]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4AF77200B for ; Tue, 15 Oct 2013 04:51:20 +0000 (UTC) Received: by mail-bk0-f52.google.com with SMTP id e11so3011739bkh.11 for ; Mon, 14 Oct 2013 21:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=zkxhcOaGh2qPUUDMDwzt4IZNDkYO8H+tqiHSCSsjH7A=; b=Vm/HmPpuW204FMFj41+986vy0ZRi1myUduTdc55iBiVSzg9Cv5T1k9od6527d/kavR qC8k4ecXVjZ6pG1d6FxdUleCgXTxH9HrpXsRTKifWDfKxDGOqOZaAvW1n8ubZFF17Bhb RsufhXFnAQV9mKTgtFvARU7oN+EIzTgPQTS/cli3ybPRQ3wKjZksV1ULIVocwHW8k7Oh 0avMEJdmcerAA9r9yez/jml6h9TTwn11f3lnEeJZn20Wa6fcMHSFMRQEE3mb1v+kqjoc 0T6zTg2AyPTyf5R/KZWzj4Jh1/scp3JdTe2Ll/puA9WOKyjam6pi+zq1sDDbQvCgb9jo 9tkA== MIME-Version: 1.0 X-Received: by 10.205.35.15 with SMTP id su15mr33173468bkb.21.1381812678481; Mon, 14 Oct 2013 21:51:18 -0700 (PDT) Sender: pkelsey@gmail.com Received: by 10.204.100.69 with HTTP; Mon, 14 Oct 2013 21:51:18 -0700 (PDT) Date: Tue, 15 Oct 2013 00:51:18 -0400 X-Google-Sender-Auth: T45UVzsjAdFCEpXNTDQqcPTFqfw Message-ID: Subject: [patch] 'make DESTDIR=/any/nonroot/dir ... xdev' is broken From: Patrick Kelsey To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 04:51:20 -0000 Hi, The patch below makes building the xdev target with non-default values of DESTDIR work. It also removes the leading '/' from XDTP to clean up path construction using that var. -Patrick Index: Makefile.inc1 =================================================================== --- Makefile.inc1 (revision 256489) +++ Makefile.inc1 (working copy) @@ -1830,7 +1830,7 @@ CPUTYPE=${XDEV_CPUTYPE} XDDIR=${XDEV_ARCH}-freebsd -XDTP=/usr/${XDDIR} +XDTP=usr/${XDDIR} CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \ INSTALL="sh ${.CURDIR}/tools/install.sh" CDENV= ${CDBENV} \ @@ -1843,8 +1843,8 @@ CDTMP= ${MAKEOBJDIRPREFIX}/${XDDIR}/${.CURDIR}/tmp CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${NOFUN} -CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDTP}/usr/bin:${PATH} ${MAKE} ${NOFUN} -XDDESTDIR=${DESTDIR}${XDTP} +CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} ${MAKE} ${NOFUN} +XDDESTDIR=${DESTDIR}/${XDTP} .if !defined(OSREL) OSREL!= uname -r | sed -e 's/[-(].*//' .endif @@ -1924,6 +1924,7 @@ _xi-links: ${_+_}cd ${XDDESTDIR}/usr/bin; \ + mkdir -p ../../../../usr/bin; \ for i in *; do \ ln -sf ../../${XDTP}/usr/bin/$$i \ ../../../../usr/bin/${XDDIR}-$$i; \ From owner-freebsd-hackers@FreeBSD.ORG Tue Oct 15 11:57:10 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id C4E26A62 for ; Tue, 15 Oct 2013 11:57:10 +0000 (UTC) (envelope-from kipcoul@gmail.com) Received: from mail-vc0-x232.google.com (mail-vc0-x232.google.com [IPv6:2607:f8b0:400c:c03::232]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 87D282A5F for ; Tue, 15 Oct 2013 11:57:10 +0000 (UTC) Received: by mail-vc0-f178.google.com with SMTP id lh4so5059778vcb.23 for ; Tue, 15 Oct 2013 04:57:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=qkNZ80yMgxvl4+1bHKmPGfNOFJy8W4i1K+9RexoyPdM=; b=QLkyd0PLumT1RdLVab/Z1WFgV4tlF1w0AMHgJaCdNO8fQgT2rs44SrKw7uMBCJ6aqD ZuS5A34iMjhBdxgWcjrHzItwPsMnQBsp11uvjvsVEmF8oc31yojneYLNEIItyiCRQ+kN 3WBvswM88X0WbeREBqe0V3ie6mmd6rFBBGV6pyboWiAYQuAa/9VAk/rHyZurIWC/iXB0 GilcTLL+5JeS1AMHlG7/BA3I7IOpWK89rSVpcGdWCWHbylKKEevIwM+9vVWgOcKMuucz idtrBhf9yy49avd+7CVxssUO2HlSeYXL8nzdBPMjOezfLhaIX9IqkYPLuqdtwlkRsNCG V6iw== MIME-Version: 1.0 X-Received: by 10.220.1.203 with SMTP id 11mr11507640vcg.15.1381838229640; Tue, 15 Oct 2013 04:57:09 -0700 (PDT) Received: by 10.220.173.7 with HTTP; Tue, 15 Oct 2013 04:57:09 -0700 (PDT) Date: Tue, 15 Oct 2013 13:57:09 +0200 Message-ID: Subject: Frame buffer console From: Kip Coul To: freebsd-hackers@freebsd.org X-Mailman-Approved-At: Tue, 15 Oct 2013 12:00:07 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 11:57:10 -0000 Hello everyone, I would like to have a high resolution console, but I don't want to run a full blown X11 server. If I'm not mistaken, FreeBSD already has a functional frame buffer, because I am able to display a 32-bit screen saver in console mode. Therefore, I would like to know if there was a "frame buffer-based syscons". If not, how can I contribute? Thanks for your answer! Cheers, Kip From owner-freebsd-hackers@FreeBSD.ORG Tue Oct 15 12:03:48 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 5CDF2205 for ; Tue, 15 Oct 2013 12:03:48 +0000 (UTC) (envelope-from jakub.klama@uj.edu.pl) Received: from mail1.uj.edu.pl (mail1.uj.edu.pl [149.156.89.193]) by mx1.freebsd.org (Postfix) with ESMTP id 1A8532B61 for ; Tue, 15 Oct 2013 12:03:48 +0000 (UTC) MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII; format=flowed Received: from mbox.uj.edu.pl ([149.156.89.248]) by mta.uoks.uj.edu.pl (Oracle Communications Messaging Server 7u4-27.01 (7.0.4.27.0) 64bit (built Aug 30 2012)) with ESMTP id <0MUP00710LI4JJ30@mta.uoks.uj.edu.pl> for freebsd-hackers@freebsd.org; Tue, 15 Oct 2013 14:03:40 +0200 (CEST) X-Antivirus: Dr.Web (R) for Unix mail servers drweb plugin ver.6.0.2.2 X-Antivirus-Code: 0x100000 Received: from mbox.uj.edu.pl by saiph.uoks.uj.edu.pl (Dr.Web (R) milter module ver.6.0.2.2) ; Tue, 15 Oct 2013 14:03:40 +0200 Received: from mbox.uj.edu.pl ([149.156.89.248]) by mta.uoks.uj.edu.pl with ESMTP; Tue, 15 Oct 2013 14:03:40 +0200 (CEST) Date: Tue, 15 Oct 2013 14:03:40 +0200 From: Jakub Klama In-reply-to: Message-id: <9caedf25f082f0c9bd4610394fbc1d1a@uj.edu.pl> References: Subject: Re: Frame buffer console To: freebsd-hackers@freebsd.org User-Agent: Roundcube Webmail/0.5 X-Sender: jakub.klama@uj.edu.pl X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 12:03:48 -0000 On Tue, 15 Oct 2013 13:57:09 +0200, Kip Coul wrote: > Hello everyone, > > I would like to have a high resolution console, but I don't want to > run a > full blown X11 server. > If I'm not mistaken, FreeBSD already has a functional frame buffer, > because > I am able to display a 32-bit screen saver in console mode. > > Therefore, I would like to know if there was a "frame buffer-based > syscons". If not, how can I contribute? try: vidcontrol -i mode and then: vidcontrol MODE_ Regards, Jakub From owner-freebsd-hackers@FreeBSD.ORG Tue Oct 15 12:07:34 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 2625C43E for ; Tue, 15 Oct 2013 12:07:34 +0000 (UTC) (envelope-from f0andrey@gmail.com) Received: from mail-wg0-x22d.google.com (mail-wg0-x22d.google.com [IPv6:2a00:1450:400c:c00::22d]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BA63C2BCD for ; Tue, 15 Oct 2013 12:07:33 +0000 (UTC) Received: by mail-wg0-f45.google.com with SMTP id z12so6718356wgg.24 for ; Tue, 15 Oct 2013 05:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=0tJOas+aX9lhWxeqdGY25tUzXZRQLgHH6Kvpgu4SaJw=; b=wmheJNyKYE1yLcX3nljCK9oAxzxl3t4fTnjGH/gDgIsojZIBQid/z6sOwa9xR5Iz1o KCrFdnXkcHagQRD11ytjUkcjacjgi70lc0HWEotdeOd5Rb3B03L/2SX21ZZ4jJDTswdL PJiCusoge0zdPdcYdPttEfh9LILz6sFx3cdUi2rml30RB1SV4rxx20ntqtcenKWke5Ix hHT6CrbnWRXZp32q80ID/dhdb3YGRlCRMTA0rT+tg8CxzgYWISy3rRrp7H1gXijuRYAW QqsUrI5l/+DzHTOZlRtdN/sEAkiopCzJgvD9shRzoylA1SPpfOFp+3fhMkBM8VbrCJSw 7uUw== MIME-Version: 1.0 X-Received: by 10.180.187.202 with SMTP id fu10mr19456164wic.59.1381838852257; Tue, 15 Oct 2013 05:07:32 -0700 (PDT) Received: by 10.194.57.52 with HTTP; Tue, 15 Oct 2013 05:07:32 -0700 (PDT) In-Reply-To: References: Date: Tue, 15 Oct 2013 16:07:32 +0400 Message-ID: Subject: Re: Frame buffer console From: Andrey Fesenko To: Kip Coul Content-Type: text/plain; charset=UTF-8 Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 12:07:34 -0000 On Tue, Oct 15, 2013 at 3:57 PM, Kip Coul wrote: > Hello everyone, > > I would like to have a high resolution console, but I don't want to run a > full blown X11 server. > If I'm not mistaken, FreeBSD already has a functional frame buffer, because > I am able to display a 32-bit screen saver in console mode. > > Therefore, I would like to know if there was a "frame buffer-based > syscons". If not, how can I contribute? > > Thanks for your answer! > Just in time, join the test ;) http://raybsd.blogspot.de/2013/10/continuation-of-newcons-project.html From owner-freebsd-hackers@FreeBSD.ORG Tue Oct 15 15:14:04 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 4F9BE146 for ; Tue, 15 Oct 2013 15:14:04 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from mail.embedded-brains.de (host-82-135-62-35.customer.m-online.net [82.135.62.35]) by mx1.freebsd.org (Postfix) with ESMTP id 313092DC1 for ; Tue, 15 Oct 2013 15:14:02 +0000 (UTC) Received: by mail.embedded-brains.de (Postfix, from userid 65534) id 3C814652CFB; Tue, 15 Oct 2013 17:07:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on fidibusdmz X-Spam-Level: X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from [192.168.96.64] (eb0024.eb.z [192.168.96.64]) by mail.embedded-brains.de (Postfix) with ESMTP id E3FFF65219E for ; Tue, 15 Oct 2013 17:07:33 +0200 (CEST) Message-ID: <525D5A35.4040005@embedded-brains.de> Date: Tue, 15 Oct 2013 17:07:33 +0200 From: Sebastian Huber User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: FreeBSD Hackers Subject: Global variables in system programs Content-Type: multipart/mixed; boundary="------------080606050100070303070204" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 15:14:04 -0000 This is a multi-part message in MIME format. --------------080606050100070303070204 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Hello, I work currently on a port of the FreeBSD network stack to a real-time operating system for embedded targets. Here the applications are statically linked with the operating system and the network stack. We would like to use the standard FreeBSD system programs to configure the network stack, e.g. ROUTE(8), IFCONFIG(8), etc. For example static const char *const argv[] = { "ifconfig", "lo0", "127.0.0.1" }; ifconfig(3, &argv[0]); These programs use some global variables. In a statically linked context we have now the following problems o we cannot call the programs concurrently, o we have to initialize the values each time. We would like to follow the FreeBSD sources to stay up-to-date. So it is desirable for us to keep the divergence from the original sources as small as possible. Are patches acceptable for the FreeBSD project that alter system programs such that o global variables are moved into context structures, o constant global variables are declared as "const", and o variables and functions are declared as "static" if possible? Attached is a patch for the ROUTE(8) program to give an example. -- Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.huber@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG. --------------080606050100070303070204 Content-Type: text/x-patch; name="0001-FIXME-Add-and-use-context-for-route-command.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-FIXME-Add-and-use-context-for-route-command.patch" >From fa564bb20b40c613c7607cb07116fc3813a7055d Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 15 Oct 2013 16:39:53 +0200 Subject: [PATCH] FIXME: Add and use context for route command --- freebsd/sbin/route/route.c | 453 +++++++++++++++++++++++--------------------- 1 files changed, 238 insertions(+), 215 deletions(-) diff --git a/freebsd/sbin/route/route.c b/freebsd/sbin/route/route.c index 206533f..896c7b2 100644 --- a/freebsd/sbin/route/route.c +++ b/freebsd/sbin/route/route.c @@ -72,7 +72,7 @@ static const char rcsid[] = #include #include -struct keytab { +static const struct keytab { char *kt_cp; int kt_i; } keywords[] = { @@ -80,41 +80,53 @@ struct keytab { {0, 0} }; -struct ortentry route; -union sockunion { - struct sockaddr sa; - struct sockaddr_in sin; +struct route_context { + struct ortentry route; + union sockunion { + struct sockaddr sa; + struct sockaddr_in sin; #ifdef INET6 - struct sockaddr_in6 sin6; + struct sockaddr_in6 sin6; #endif - struct sockaddr_at sat; - struct sockaddr_dl sdl; - struct sockaddr_inarp sinarp; - struct sockaddr_storage ss; /* added to avoid memory overrun */ -} so_dst, so_gate, so_mask, so_genmask, so_ifa, so_ifp; + struct sockaddr_at sat; + struct sockaddr_dl sdl; + struct sockaddr_inarp sinarp; + struct sockaddr_storage ss; /* added to avoid memory overrun */ + } so_dst, so_gate, so_mask, so_genmask, so_ifa, so_ifp; + + int pid, rtm_addrs; + int s; + int forcehost, forcenet, nflag, af, qflag, tflag; + int iflag, verbose, aflen; + int locking, lockrest, debugonly; + struct rt_metrics rt_metrics; + u_long rtm_inits; + uid_t uid; + struct { + struct rt_msghdr m_rtm; + char m_space[512]; + } m_rtmsg; +} route_context; typedef union sockunion *sup; -int pid, rtm_addrs; -int s; -int forcehost, forcenet, doflush, nflag, af, qflag, tflag, keyword(); -int iflag, verbose, aflen = sizeof (struct sockaddr_in); -int locking, lockrest, debugonly; -struct rt_metrics rt_metrics; -u_long rtm_inits; -uid_t uid; -int atalk_aton(const char *, struct at_addr *); -char *atalk_ntoa(struct at_addr); -const char *routename(), *netname(); -void flushroutes(), newroute(), monitor(), sockaddr(), sodump(), bprintf(); -void print_getmsg(), print_rtmsg(), pmsg_common(), pmsg_addrs(), mask_addr(); + +static int keyword(); +static int atalk_aton(const char *, struct at_addr *); +static char *atalk_ntoa(struct at_addr); +static const char *routename(), *netname(); +static void interfaces(struct route_context *ctx); +static void set_metric(); +static void flushroutes(), newroute(), monitor(), sockaddr(), sodump(), bprintf(); +static void print_getmsg(), print_rtmsg(), pmsg_common(), pmsg_addrs(), mask_addr(); +static void inet_makenetandmask(); #ifdef INET6 -static int inet6_makenetandmask(struct sockaddr_in6 *, char *); +static int inet6_makenetandmask(struct sockaddr_in6 *, char *); #endif -int getaddr(), rtmsg(), x25_makemask(); -int prefixlen(); -extern char *iso_ntoa(); +static int getaddr(), rtmsg(); +static int prefixlen(); +extern char *iso_ntoa(); -void usage(const char *) __dead2; +static void usage(const char *) __dead2; void usage(cp) @@ -132,27 +144,31 @@ main(argc, argv) int argc; char **argv; { + struct route_context *ctx; int ch; + ctx = &route_context; + ctx->aflen = sizeof (struct sockaddr_in); + if (argc < 2) usage((char *)NULL); while ((ch = getopt(argc, argv, "nqdtv")) != -1) switch(ch) { case 'n': - nflag = 1; + ctx->nflag = 1; break; case 'q': - qflag = 1; + ctx->qflag = 1; break; case 'v': - verbose = 1; + ctx->verbose = 1; break; case 't': - tflag = 1; + ctx->tflag = 1; break; case 'd': - debugonly = 1; + ctx->debugonly = 1; break; case '?': default: @@ -161,34 +177,34 @@ main(argc, argv) argc -= optind; argv += optind; - pid = getpid(); - uid = geteuid(); - if (tflag) - s = open(_PATH_DEVNULL, O_WRONLY, 0); + ctx->pid = getpid(); + ctx->uid = geteuid(); + if (ctx->tflag) + ctx->s = open(_PATH_DEVNULL, O_WRONLY, 0); else - s = socket(PF_ROUTE, SOCK_RAW, 0); - if (s < 0) + ctx->s = socket(PF_ROUTE, SOCK_RAW, 0); + if (ctx->s < 0) err(EX_OSERR, "socket"); if (*argv) switch (keyword(*argv)) { case K_GET: case K_SHOW: - uid = 0; + ctx->uid = 0; /* FALLTHROUGH */ case K_CHANGE: case K_ADD: case K_DEL: case K_DELETE: - newroute(argc, argv); + newroute(ctx, argc, argv); /* NOTREACHED */ case K_MONITOR: - monitor(); + monitor(ctx); /* NOTREACHED */ case K_FLUSH: - flushroutes(argc, argv); + flushroutes(ctx, argc, argv); exit(0); /* NOTREACHED */ } @@ -201,7 +217,8 @@ main(argc, argv) * associated with network interfaces. */ void -flushroutes(argc, argv) +flushroutes(ctx, argc, argv) + struct route_context *ctx; int argc; char *argv[]; { @@ -210,27 +227,27 @@ flushroutes(argc, argv) char *buf, *next, *lim; struct rt_msghdr *rtm; - if (uid && !debugonly) { + if (ctx->uid && !ctx->debugonly) { errx(EX_NOPERM, "must be root to alter routing table"); } - shutdown(s, SHUT_RD); /* Don't want to read back our messages */ + shutdown(ctx->s, SHUT_RD); /* Don't want to read back our messages */ if (argc > 1) { argv++; if (argc == 2 && **argv == '-') switch (keyword(*argv + 1)) { case K_INET: - af = AF_INET; + ctx->af = AF_INET; break; #ifdef INET6 case K_INET6: - af = AF_INET6; + ctx->af = AF_INET6; break; #endif case K_ATALK: - af = AF_APPLETALK; + ctx->af = AF_APPLETALK; break; case K_LINK: - af = AF_LINK; + ctx->af = AF_LINK; break; default: goto bad; @@ -258,26 +275,26 @@ retry: err(EX_OSERR, "route-sysctl-get"); } lim = buf + needed; - if (verbose) + if (ctx->verbose) (void) printf("Examining routing table from sysctl\n"); seqno = 0; /* ??? */ for (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; - if (verbose) - print_rtmsg(rtm, rtm->rtm_msglen); + if (ctx->verbose) + print_rtmsg(ctx, rtm, rtm->rtm_msglen); if ((rtm->rtm_flags & RTF_GATEWAY) == 0) continue; - if (af) { + if (ctx->af) { struct sockaddr *sa = (struct sockaddr *)(rtm + 1); - if (sa->sa_family != af) + if (sa->sa_family != ctx->af) continue; } - if (debugonly) + if (ctx->debugonly) continue; rtm->rtm_type = RTM_DELETE; rtm->rtm_seq = seqno; - rlen = write(s, next, rtm->rtm_msglen); + rlen = write(ctx->s, next, rtm->rtm_msglen); if (rlen < 0 && errno == EPERM) err(1, "write to routing socket"); if (rlen < (int)rtm->rtm_msglen) { @@ -288,14 +305,14 @@ retry: break; } seqno++; - if (qflag) + if (ctx->qflag) continue; - if (verbose) - print_rtmsg(rtm, rlen); + if (ctx->verbose) + print_rtmsg(ctx, rtm, rlen); else { struct sockaddr *sa = (struct sockaddr *)(rtm + 1); (void) printf("%-20.20s ", rtm->rtm_flags & RTF_HOST ? - routename(sa) : netname(sa)); + routename(sa) : netname(ctx, sa)); sa = (struct sockaddr *)(SA_SIZE(sa) + (char *)sa); (void) printf("%-20.20s ", routename(sa)); (void) printf("done\n"); @@ -304,7 +321,8 @@ retry: } const char * -routename(sa) +routename(ctx, sa) + struct route_context *ctx; struct sockaddr *sa; { char *cp; @@ -334,7 +352,7 @@ routename(sa) cp = 0; if (in.s_addr == INADDR_ANY || sa->sa_len < 4) cp = "default"; - if (cp == 0 && !nflag) { + if (cp == 0 && !ctx->nflag) { hp = gethostbyaddr((char *)&in, sizeof (struct in_addr), AF_INET); if (hp) { @@ -373,7 +391,7 @@ routename(sa) sin6.sin6_addr.s6_addr[3] = 0; } #endif - if (nflag) + if (ctx->nflag) niflags |= NI_NUMERICHOST; if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, line, sizeof(line), NULL, 0, niflags) != 0) @@ -413,7 +431,8 @@ routename(sa) * The address is assumed to be that of a net or subnet, not a host. */ const char * -netname(sa) +netname(ctx, sa) + struct route_context *ctx; struct sockaddr *sa; { char *cp = 0; @@ -432,7 +451,7 @@ netname(sa) i = in.s_addr = ntohl(in.s_addr); if (in.s_addr == 0) cp = "default"; - else if (!nflag) { + else if (!ctx->nflag) { if (IN_CLASSA(i)) { mask = IN_CLASSA_NET; subnetshift = 8; @@ -498,7 +517,7 @@ netname(sa) sin6.sin6_addr.s6_addr[3] = 0; } #endif - if (nflag) + if (ctx->nflag) niflags |= NI_NUMERICHOST; if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, line, sizeof(line), NULL, 0, niflags) != 0) @@ -535,7 +554,8 @@ netname(sa) } void -set_metric(value, key) +set_metric(ctx, value, key) + struct route_context *ctx; char *value; int key; { @@ -543,7 +563,7 @@ set_metric(value, key) u_long noval, *valp = &noval; switch (key) { -#define caseof(x, y, z) case x: valp = &rt_metrics.z; flag = y; break +#define caseof(x, y, z) case x: valp = &ctx->rt_metrics.z; flag = y; break caseof(K_MTU, RTV_MTU, rmx_mtu); caseof(K_HOPCOUNT, RTV_HOPCOUNT, rmx_hopcount); caseof(K_EXPIRE, RTV_EXPIRE, rmx_expire); @@ -554,16 +574,17 @@ set_metric(value, key) caseof(K_RTTVAR, RTV_RTTVAR, rmx_rttvar); caseof(K_WEIGHT, RTV_WEIGHT, rmx_weight); } - rtm_inits |= flag; - if (lockrest || locking) - rt_metrics.rmx_locks |= flag; - if (locking) - locking = 0; + ctx->rtm_inits |= flag; + if (ctx->lockrest || ctx->locking) + ctx->rt_metrics.rmx_locks |= flag; + if (ctx->locking) + ctx->locking = 0; *valp = atoi(value); } void -newroute(argc, argv) +newroute(ctx, argc, argv) + struct route_context *ctx; int argc; char **argv; { @@ -572,53 +593,53 @@ newroute(argc, argv) int key; struct hostent *hp = 0; - if (uid) { + if (ctx->uid) { errx(EX_NOPERM, "must be root to alter routing table"); } cmd = argv[0]; if (*cmd != 'g' && *cmd != 's') - shutdown(s, SHUT_RD); /* Don't want to read back our messages */ + shutdown(ctx->s, SHUT_RD); /* Don't want to read back our messages */ while (--argc > 0) { if (**(++argv)== '-') { switch (key = keyword(1 + *argv)) { case K_LINK: - af = AF_LINK; - aflen = sizeof(struct sockaddr_dl); + ctx->af = AF_LINK; + ctx->aflen = sizeof(struct sockaddr_dl); break; case K_INET: - af = AF_INET; - aflen = sizeof(struct sockaddr_in); + ctx->af = AF_INET; + ctx->aflen = sizeof(struct sockaddr_in); break; #ifdef INET6 case K_INET6: - af = AF_INET6; - aflen = sizeof(struct sockaddr_in6); + ctx->af = AF_INET6; + ctx->aflen = sizeof(struct sockaddr_in6); break; #endif case K_ATALK: - af = AF_APPLETALK; - aflen = sizeof(struct sockaddr_at); + ctx->af = AF_APPLETALK; + ctx->aflen = sizeof(struct sockaddr_at); break; case K_SA: - af = PF_ROUTE; - aflen = sizeof(union sockunion); + ctx->af = PF_ROUTE; + ctx->aflen = sizeof(union sockunion); break; case K_IFACE: case K_INTERFACE: - iflag++; + ctx->iflag++; break; case K_NOSTATIC: flags &= ~RTF_STATIC; break; case K_LOCK: - locking = 1; + ctx->locking = 1; break; case K_LOCKREST: - lockrest = 1; + ctx->lockrest = 1; break; case K_HOST: - forcehost++; + ctx->forcehost++; break; case K_REJECT: flags |= RTF_REJECT; @@ -679,16 +700,16 @@ newroute(argc, argv) (void) getaddr(RTA_NETMASK, *++argv, 0); /* FALLTHROUGH */ case K_NET: - forcenet++; + ctx->forcenet++; break; case K_PREFIXLEN: if (!--argc) usage((char *)NULL); - if (prefixlen(*++argv) == -1) { - forcenet = 0; + if (prefixlen(ctx, *++argv) == -1) { + ctx->forcenet = 0; ishost = 1; } else { - forcenet = 1; + ctx->forcenet = 1; ishost = 0; } break; @@ -703,67 +724,67 @@ newroute(argc, argv) case K_WEIGHT: if (!--argc) usage((char *)NULL); - set_metric(*++argv, key); + set_metric(ctx, *++argv, key); break; default: usage(1+*argv); } } else { - if ((rtm_addrs & RTA_DST) == 0) { + if ((ctx->rtm_addrs & RTA_DST) == 0) { dest = *argv; ishost = getaddr(RTA_DST, *argv, &hp); - } else if ((rtm_addrs & RTA_GATEWAY) == 0) { + } else if ((ctx->rtm_addrs & RTA_GATEWAY) == 0) { gateway = *argv; (void) getaddr(RTA_GATEWAY, *argv, &hp); } else { (void) getaddr(RTA_NETMASK, *argv, 0); - forcenet = 1; + ctx->forcenet = 1; } } } - if (forcehost) { + if (ctx->forcehost) { ishost = 1; #ifdef INET6 - if (af == AF_INET6) { - rtm_addrs &= ~RTA_NETMASK; - memset((void *)&so_mask, 0, sizeof(so_mask)); + if (ctx->af == AF_INET6) { + ctx->rtm_addrs &= ~RTA_NETMASK; + memset((void *)&ctx->so_mask, 0, sizeof(ctx->so_mask)); } #endif } - if (forcenet) + if (ctx->forcenet) ishost = 0; flags |= RTF_UP; if (ishost) flags |= RTF_HOST; - if (iflag == 0) + if (ctx->iflag == 0) flags |= RTF_GATEWAY; if (proxy) { - so_dst.sinarp.sin_other = SIN_PROXY; + ctx->so_dst.sinarp.sin_other = SIN_PROXY; flags |= RTF_ANNOUNCE; } for (attempts = 1; ; attempts++) { errno = 0; - if ((ret = rtmsg(*cmd, flags)) == 0) + if ((ret = rtmsg(ctx, *cmd, flags)) == 0) break; if (errno != ENETUNREACH && errno != ESRCH) break; - if (af == AF_INET && *gateway && hp && hp->h_addr_list[1]) { + if (ctx->af == AF_INET && *gateway && hp && hp->h_addr_list[1]) { hp->h_addr_list++; - memmove(&so_gate.sin.sin_addr, hp->h_addr_list[0], - MIN(hp->h_length, sizeof(so_gate.sin.sin_addr))); + memmove(&ctx->so_gate.sin.sin_addr, hp->h_addr_list[0], + MIN(hp->h_length, sizeof(ctx->so_gate.sin.sin_addr))); } else break; } if (*cmd == 'g' || *cmd == 's') exit(ret != 0); - if (!qflag) { + if (!ctx->qflag) { oerrno = errno; (void) printf("%s %s %s", cmd, ishost? "host" : "net", dest); if (*gateway) { (void) printf(": gateway %s", gateway); - if (attempts > 1 && ret == 0 && af == AF_INET) + if (attempts > 1 && ret == 0 && ctx->af == AF_INET) (void) printf(" (%s)", - inet_ntoa(((struct sockaddr_in *)&route.rt_gateway)->sin_addr)); + inet_ntoa(((struct sockaddr_in *)&ctx->route.rt_gateway)->sin_addr)); } if (ret == 0) { (void) printf("\n"); @@ -796,14 +817,15 @@ newroute(argc, argv) } void -inet_makenetandmask(net, sin, bits) +inet_makenetandmask(ctx, net, sin, bits) + struct route_context *ctx; u_long net, bits; struct sockaddr_in *sin; { u_long addr, mask = 0; char *cp; - rtm_addrs |= RTA_NETMASK; + ctx->rtm_addrs |= RTA_NETMASK; /* * XXX: This approach unable to handle 0.0.0.1/32 correctly * as inet_network() converts 0.0.0.1 and 1 equally. @@ -835,7 +857,7 @@ inet_makenetandmask(net, sin, bits) mask = 0xffffffff << (32 - bits); sin->sin_addr.s_addr = htonl(addr); - sin = &so_mask.sin; + sin = &ctx->so_mask.sin; sin->sin_addr.s_addr = htonl(mask); sin->sin_len = 0; sin->sin_family = 0; @@ -871,8 +893,8 @@ inet6_makenetandmask(sin6, plen) if (!plen || strcmp(plen, "128") == 0) return 1; - rtm_addrs |= RTA_NETMASK; - (void)prefixlen(plen); + ctx->rtm_addrs |= RTA_NETMASK; + (void)prefixlen(ctx, plen); return 0; } #endif @@ -882,7 +904,8 @@ inet6_makenetandmask(sin6, plen) * returning 1 if a host address, 0 if a network address. */ int -getaddr(which, s, hpp) +getaddr(ctx, which, s, hpp) + struct route_context *ctx; int which; char *s; struct hostent **hpp; @@ -894,19 +917,19 @@ getaddr(which, s, hpp) char *q; int afamily; /* local copy of af so we can change it */ - if (af == 0) { - af = AF_INET; - aflen = sizeof(struct sockaddr_in); + if (ctx->af == 0) { + ctx->af = AF_INET; + ctx->aflen = sizeof(struct sockaddr_in); } - afamily = af; - rtm_addrs |= which; + afamily = ctx->af; + ctx->rtm_addrs |= which; switch (which) { case RTA_DST: - su = &so_dst; + su = &ctx->so_dst; break; case RTA_GATEWAY: - su = &so_gate; - if (iflag) { + su = &ctx->so_gate; + if (ctx->iflag) { struct ifaddrs *ifap, *ifa; struct sockaddr_dl *sdl = NULL; @@ -938,23 +961,23 @@ getaddr(which, s, hpp) } break; case RTA_NETMASK: - su = &so_mask; + su = &ctx->so_mask; break; case RTA_GENMASK: - su = &so_genmask; + su = &ctx->so_genmask; break; case RTA_IFP: - su = &so_ifp; + su = &ctx->so_ifp; afamily = AF_LINK; break; case RTA_IFA: - su = &so_ifa; + su = &ctx->so_ifa; break; default: usage("internal error"); /*NOTREACHED*/ } - su->sa.sa_len = aflen; + su->sa.sa_len = ctx->aflen; su->sa.sa_family = afamily; /* cases that don't want it have left already */ if (strcmp(s, "default") == 0) { /* @@ -962,7 +985,7 @@ getaddr(which, s, hpp) */ switch (which) { case RTA_DST: - forcenet++; + ctx->forcenet++; #if 0 bzero(su, sizeof(*su)); /* for readability */ #endif @@ -1018,8 +1041,8 @@ getaddr(which, s, hpp) case AF_APPLETALK: if (!atalk_aton(s, &su->sat.sat_addr)) errx(EX_NOHOST, "bad address: %s", s); - rtm_addrs |= RTA_NETMASK; - return(forcehost || su->sat.sat_addr.s_node != 0); + ctx->rtm_addrs |= RTA_NETMASK; + return(ctx->forcehost || su->sat.sat_addr.s_node != 0); case AF_LINK: link_addr(s, &su->sdl); @@ -1045,15 +1068,15 @@ getaddr(which, s, hpp) *q = '\0'; if ((val = inet_network(s)) != INADDR_NONE) { inet_makenetandmask( - val, &su->sin, strtoul(q+1, 0, 0)); + ctx, val, &su->sin, strtoul(q+1, 0, 0)); return (0); } *q = '/'; } - if ((which != RTA_DST || forcenet == 0) && + if ((which != RTA_DST || ctx->forcenet == 0) && inet_aton(s, &su->sin.sin_addr)) { val = su->sin.sin_addr.s_addr; - if (which != RTA_DST || forcehost || + if (which != RTA_DST || ctx->forcehost || inet_lnaof(su->sin.sin_addr) != INADDR_ANY) return (1); else { @@ -1061,11 +1084,11 @@ getaddr(which, s, hpp) goto netdone; } } - if (which == RTA_DST && forcehost == 0 && + if (which == RTA_DST && ctx->forcehost == 0 && ((val = inet_network(s)) != INADDR_NONE || ((np = getnetbyname(s)) != NULL && (val = np->n_net) != 0))) { netdone: - inet_makenetandmask(val, &su->sin, 0); + inet_makenetandmask(ctx, val, &su->sin, 0); return (0); } hp = gethostbyname(s); @@ -1080,24 +1103,25 @@ netdone: } int -prefixlen(s) +prefixlen(ctx, s) + struct route_context *ctx; char *s; { int len = atoi(s), q, r; int max; char *p; - rtm_addrs |= RTA_NETMASK; - switch (af) { + ctx->rtm_addrs |= RTA_NETMASK; + switch (ctx->af) { #ifdef INET6 case AF_INET6: max = 128; - p = (char *)&so_mask.sin6.sin6_addr; + p = (char *)&ctx->so_mask.sin6.sin6_addr; break; #endif case AF_INET: max = 32; - p = (char *)&so_mask.sin.sin_addr; + p = (char *)&ctx->so_mask.sin.sin_addr; break; default: (void) fprintf(stderr, "prefixlen not supported in this af\n"); @@ -1112,8 +1136,8 @@ prefixlen(s) q = len >> 3; r = len & 7; - so_mask.sa.sa_family = af; - so_mask.sa.sa_len = aflen; + ctx->so_mask.sa.sa_family = ctx->af; + ctx->so_mask.sa.sa_len = ctx->aflen; memset((void *)p, 0, max / 8); if (q > 0) memset((void *)p, 0xff, q); @@ -1126,7 +1150,7 @@ prefixlen(s) } void -interfaces() +interfaces(struct route_context *ctx) { size_t needed; int mib[6]; @@ -1156,88 +1180,84 @@ retry2: lim = buf + needed; for (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; - print_rtmsg(rtm, rtm->rtm_msglen); + print_rtmsg(ctx, rtm, rtm->rtm_msglen); } } void -monitor() +monitor(struct route_context *ctx) { int n; char msg[2048]; - verbose = 1; - if (debugonly) { - interfaces(); + ctx->verbose = 1; + if (ctx->debugonly) { + interfaces(ctx); exit(0); } for(;;) { time_t now; - n = read(s, msg, 2048); + n = read(ctx->s, msg, 2048); now = time(NULL); (void) printf("\ngot message of size %d on %s", n, ctime(&now)); - print_rtmsg((struct rt_msghdr *)msg, n); + print_rtmsg(ctx, (struct rt_msghdr *)msg, n); } } -struct { - struct rt_msghdr m_rtm; - char m_space[512]; -} m_rtmsg; - int -rtmsg(cmd, flags) +rtmsg(ctx, cmd, flags) + struct route_context *ctx; int cmd, flags; { static int seq; int rlen; - char *cp = m_rtmsg.m_space; + char *cp = ctx->m_rtmsg.m_space; int l; #define NEXTADDR(w, u) \ - if (rtm_addrs & (w)) {\ + if (ctx->rtm_addrs & (w)) {\ l = SA_SIZE(&(u.sa)); memmove(cp, &(u), l); cp += l;\ - if (verbose) sodump(&(u),#u);\ + if (ctx->verbose) sodump(&(u),#u);\ } errno = 0; - memset(&m_rtmsg, 0, sizeof(m_rtmsg)); + memset(&ctx->m_rtmsg, 0, sizeof(ctx->m_rtmsg)); if (cmd == 'a') cmd = RTM_ADD; else if (cmd == 'c') cmd = RTM_CHANGE; else if (cmd == 'g' || cmd == 's') { cmd = RTM_GET; - if (so_ifp.sa.sa_family == 0) { - so_ifp.sa.sa_family = AF_LINK; - so_ifp.sa.sa_len = sizeof(struct sockaddr_dl); - rtm_addrs |= RTA_IFP; + if (ctx->so_ifp.sa.sa_family == 0) { + ctx->so_ifp.sa.sa_family = AF_LINK; + ctx->so_ifp.sa.sa_len = sizeof(struct sockaddr_dl); + ctx->rtm_addrs |= RTA_IFP; } } else cmd = RTM_DELETE; -#define rtm m_rtmsg.m_rtm +#define rtm ctx->m_rtmsg.m_rtm rtm.rtm_type = cmd; rtm.rtm_flags = flags; rtm.rtm_version = RTM_VERSION; rtm.rtm_seq = ++seq; - rtm.rtm_addrs = rtm_addrs; - rtm.rtm_rmx = rt_metrics; - rtm.rtm_inits = rtm_inits; + rtm.rtm_addrs = ctx->rtm_addrs; + rtm.rtm_rmx = ctx->rt_metrics; + rtm.rtm_inits = ctx->rtm_inits; - if (rtm_addrs & RTA_NETMASK) - mask_addr(); - NEXTADDR(RTA_DST, so_dst); - NEXTADDR(RTA_GATEWAY, so_gate); - NEXTADDR(RTA_NETMASK, so_mask); - NEXTADDR(RTA_GENMASK, so_genmask); - NEXTADDR(RTA_IFP, so_ifp); - NEXTADDR(RTA_IFA, so_ifa); - rtm.rtm_msglen = l = cp - (char *)&m_rtmsg; - if (verbose) - print_rtmsg(&rtm, l); - if (debugonly) + if (ctx->rtm_addrs & RTA_NETMASK) + mask_addr(ctx); + NEXTADDR(RTA_DST, ctx->so_dst); + NEXTADDR(RTA_GATEWAY, ctx->so_gate); + NEXTADDR(RTA_NETMASK, ctx->so_mask); + NEXTADDR(RTA_GENMASK, ctx->so_genmask); + NEXTADDR(RTA_IFP, ctx->so_ifp); + NEXTADDR(RTA_IFA, ctx->so_ifa); + rtm.rtm_msglen = l = cp - (char *)&ctx->m_rtmsg; + if (ctx->verbose) + print_rtmsg(ctx, &rtm, l); + if (ctx->debugonly) return (0); - if ((rlen = write(s, (char *)&m_rtmsg, l)) < 0) { + if ((rlen = write(ctx->s, (char *)&ctx->m_rtmsg, l)) < 0) { if (errno == EPERM) err(1, "writing to routing socket"); warn("writing to routing socket"); @@ -1245,31 +1265,32 @@ rtmsg(cmd, flags) } if (cmd == RTM_GET) { do { - l = read(s, (char *)&m_rtmsg, sizeof(m_rtmsg)); - } while (l > 0 && (rtm.rtm_seq != seq || rtm.rtm_pid != pid)); + l = read(ctx->s, (char *)&ctx->m_rtmsg, sizeof(ctx->m_rtmsg)); + } while (l > 0 && (rtm.rtm_seq != seq || rtm.rtm_pid != ctx->pid)); if (l < 0) warn("read from routing socket"); else - print_getmsg(&rtm, l); + print_getmsg(ctx, &rtm, l); } #undef rtm return (0); } void -mask_addr() +mask_addr(ctx) + struct route_context *ctx; { - int olen = so_mask.sa.sa_len; - char *cp1 = olen + (char *)&so_mask, *cp2; + int olen = ctx->so_mask.sa.sa_len; + char *cp1 = olen + (char *)&ctx->so_mask, *cp2; - for (so_mask.sa.sa_len = 0; cp1 > (char *)&so_mask; ) + for (ctx->so_mask.sa.sa_len = 0; cp1 > (char *)&ctx->so_mask; ) if (*--cp1 != 0) { - so_mask.sa.sa_len = 1 + cp1 - (char *)&so_mask; + ctx->so_mask.sa.sa_len = 1 + cp1 - (char *)&ctx->so_mask; break; } - if ((rtm_addrs & RTA_DST) == 0) + if ((ctx->rtm_addrs & RTA_DST) == 0) return; - switch (so_dst.sa.sa_family) { + switch (ctx->so_dst.sa.sa_family) { case AF_INET: #ifdef INET6 case AF_INET6: @@ -1278,16 +1299,16 @@ mask_addr() case 0: return; } - cp1 = so_mask.sa.sa_len + 1 + (char *)&so_dst; - cp2 = so_dst.sa.sa_len + 1 + (char *)&so_dst; + cp1 = ctx->so_mask.sa.sa_len + 1 + (char *)&ctx->so_dst; + cp2 = ctx->so_dst.sa.sa_len + 1 + (char *)&ctx->so_dst; while (cp2 > cp1) *--cp2 = 0; - cp2 = so_mask.sa.sa_len + 1 + (char *)&so_mask; - while (cp1 > so_dst.sa.sa_data) + cp2 = ctx->so_mask.sa.sa_len + 1 + (char *)&ctx->so_mask; + while (cp1 > ctx->so_dst.sa.sa_data) *--cp1 &= *--cp2; } -char *msgtypes[] = { +static const char *msgtypes[] = { "", "RTM_ADD: Add Route", "RTM_DELETE: Delete Route", @@ -1309,23 +1330,24 @@ char *msgtypes[] = { 0, }; -char metricnames[] = +static const char metricnames[] = "\011weight\010rttvar\7rtt\6ssthresh\5sendpipe\4recvpipe\3expire" "\1mtu"; -char routeflags[] = +static const char routeflags[] = "\1UP\2GATEWAY\3HOST\4REJECT\5DYNAMIC\6MODIFIED\7DONE" "\012XRESOLVE\013LLINFO\014STATIC\015BLACKHOLE" "\017PROTO2\020PROTO1\021PRCLONING\022WASCLONED\023PROTO3" "\025PINNED\026LOCAL\027BROADCAST\030MULTICAST\035STICKY"; -char ifnetflags[] = +static const char ifnetflags[] = "\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5PTP\6b6\7RUNNING\010NOARP" "\011PPROMISC\012ALLMULTI\013OACTIVE\014SIMPLEX\015LINK0\016LINK1" "\017LINK2\020MULTICAST"; -char addrnames[] = +static const char addrnames[] = "\1DST\2GATEWAY\3NETMASK\4GENMASK\5IFP\6IFA\7AUTHOR\010BRD"; void -print_rtmsg(rtm, msglen) +print_rtmsg(ctx, rtm, msglen) + struct route_context *ctx; struct rt_msghdr *rtm; int msglen; { @@ -1337,7 +1359,7 @@ print_rtmsg(rtm, msglen) struct if_announcemsghdr *ifan; char *state; - if (verbose == 0) + if (ctx->verbose == 0) return; if (rtm->rtm_version != RTM_VERSION) { (void) printf("routing message version %d not understood\n", @@ -1408,7 +1430,8 @@ print_rtmsg(rtm, msglen) } void -print_getmsg(rtm, msglen) +print_getmsg(ctx, rtm, msglen) + struct route_context *ctx; struct rt_msghdr *rtm; int msglen; { @@ -1418,7 +1441,7 @@ print_getmsg(rtm, msglen) char *cp; int i; - (void) printf(" route to: %s\n", routename(&so_dst)); + (void) printf(" route to: %s\n", routename(&ctx->so_dst)); if (rtm->rtm_version != RTM_VERSION) { warnx("routing message version %d not understood", rtm->rtm_version); @@ -1461,11 +1484,11 @@ print_getmsg(rtm, msglen) if (dst) (void)printf("destination: %s\n", routename(dst)); if (mask) { - int savenflag = nflag; + int savenflag = ctx->nflag; - nflag = 1; + ctx->nflag = 1; (void)printf(" mask: %s\n", routename(mask)); - nflag = savenflag; + ctx->nflag = savenflag; } if (gate && rtm->rtm_flags & RTF_GATEWAY) (void)printf(" gateway: %s\n", routename(gate)); @@ -1492,7 +1515,7 @@ print_getmsg(rtm, msglen) #undef lock #undef msec #define RTA_IGN (RTA_DST|RTA_GATEWAY|RTA_NETMASK|RTA_IFP|RTA_IFA|RTA_BRD) - if (verbose) + if (ctx->verbose) pmsg_common(rtm); else if (rtm->rtm_addrs &~ RTA_IGN) { (void) printf("sockaddrs: "); @@ -1571,7 +1594,7 @@ int keyword(cp) char *cp; { - struct keytab *kt = keywords; + const struct keytab *kt = keywords; while (kt->kt_cp && strcmp(kt->kt_cp, cp)) kt++; -- 1.7.7 --------------080606050100070303070204-- From owner-freebsd-hackers@FreeBSD.ORG Tue Oct 15 15:44:25 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 43AD2E34 for ; Tue, 15 Oct 2013 15:44:25 +0000 (UTC) (envelope-from alfred@freebsd.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 3273D20B5 for ; Tue, 15 Oct 2013 15:44:24 +0000 (UTC) Received: from Alfreds-MacBook-Pro-9.local (c-76-21-10-192.hsd1.ca.comcast.net [76.21.10.192]) by elvis.mu.org (Postfix) with ESMTPSA id BF9691A3D8F; Tue, 15 Oct 2013 08:44:24 -0700 (PDT) Message-ID: <525D62D9.4050001@freebsd.org> Date: Tue, 15 Oct 2013 08:44:25 -0700 From: Alfred Perlstein User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: Sebastian Huber , FreeBSD Hackers Subject: Re: Global variables in system programs References: <525D5A35.4040005@embedded-brains.de> In-Reply-To: <525D5A35.4040005@embedded-brains.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 15:44:25 -0000 On 10/15/13 8:07 AM, Sebastian Huber wrote: > Hello, > > I work currently on a port of the FreeBSD network stack to a real-time > operating system for embedded targets. Here the applications are > statically linked with the operating system and the network stack. We > would like to use the standard FreeBSD system programs to configure > the network stack, e.g. ROUTE(8), IFCONFIG(8), etc. For example > > static const char *const argv[] = { > "ifconfig", > "lo0", > "127.0.0.1" > }; > > ifconfig(3, &argv[0]); > > These programs use some global variables. In a statically linked > context we have now the following problems > > o we cannot call the programs concurrently, > > o we have to initialize the values each time. > > We would like to follow the FreeBSD sources to stay up-to-date. So it > is desirable for us to keep the divergence from the original sources > as small as possible. Are patches acceptable for the FreeBSD project > that alter system programs such that > > o global variables are moved into context structures, > > o constant global variables are declared as "const", and > > o variables and functions are declared as "static" if possible? > > Attached is a patch for the ROUTE(8) program to give an example. Wow! I would really love to see this sort of change make it into FreeBSD, not only for linking them all together, but also for running them as threads. I have a question about your propose modification... Can you run two instances of route modified like this? How many more programs have you modified? From owner-freebsd-hackers@FreeBSD.ORG Tue Oct 15 15:57:47 2013 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 4AB8B4D3; Tue, 15 Oct 2013 15:57:47 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mho-01-ewr.mailhop.org (mho-03-ewr.mailhop.org [204.13.248.66]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 2205A21C8; Tue, 15 Oct 2013 15:57:46 +0000 (UTC) Received: from c-24-8-230-52.hsd1.co.comcast.net ([24.8.230.52] helo=damnhippie.dyndns.org) by mho-01-ewr.mailhop.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1VW70D-000Dpk-O7; Tue, 15 Oct 2013 15:57:45 +0000 Received: from [172.22.42.240] (revolution.hippie.lan [172.22.42.240]) by damnhippie.dyndns.org (8.14.3/8.14.3) with ESMTP id r9FFvgT9027117; Tue, 15 Oct 2013 09:57:42 -0600 (MDT) (envelope-from ian@FreeBSD.org) X-Mail-Handler: Dyn Standard SMTP by Dyn X-Originating-IP: 24.8.230.52 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/sendlabs/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX1/L5/KrfrBoSdluLfdZZ/gB Subject: Re: Global variables in system programs From: Ian Lepore To: Alfred Perlstein In-Reply-To: <525D62D9.4050001@freebsd.org> References: <525D5A35.4040005@embedded-brains.de> <525D62D9.4050001@freebsd.org> Content-Type: text/plain; charset="us-ascii" Date: Tue, 15 Oct 2013 09:57:42 -0600 Message-ID: <1381852662.42859.130.camel@revolution.hippie.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit Cc: Sebastian Huber , FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 15:57:47 -0000 On Tue, 2013-10-15 at 08:44 -0700, Alfred Perlstein wrote: > On 10/15/13 8:07 AM, Sebastian Huber wrote: > > Hello, > > > > I work currently on a port of the FreeBSD network stack to a real-time > > operating system for embedded targets. Here the applications are > > statically linked with the operating system and the network stack. We > > would like to use the standard FreeBSD system programs to configure > > the network stack, e.g. ROUTE(8), IFCONFIG(8), etc. For example > > > > static const char *const argv[] = { > > "ifconfig", > > "lo0", > > "127.0.0.1" > > }; > > > > ifconfig(3, &argv[0]); > > > > These programs use some global variables. In a statically linked > > context we have now the following problems > > > > o we cannot call the programs concurrently, > > > > o we have to initialize the values each time. > > > > We would like to follow the FreeBSD sources to stay up-to-date. So it > > is desirable for us to keep the divergence from the original sources > > as small as possible. Are patches acceptable for the FreeBSD project > > that alter system programs such that > > > > o global variables are moved into context structures, > > > > o constant global variables are declared as "const", and > > > > o variables and functions are declared as "static" if possible? > > > > Attached is a patch for the ROUTE(8) program to give an example. > > Wow! I would really love to see this sort of change make it into > FreeBSD, not only for linking them all together, but also for running > them as threads. Another factor in trying to turn standalone programs into threads bundled into a larger entity: by design, we do not free allocated memory, we let program-exit handle that. The const and static changes are great. The context thing I'm not so fond of. Might there be a way to handle these bundled-in programs a bit like .ko modules somehow? They can be compiled-in, but invoking one would result in re-initing its data and bss, and because they're still compiled separately and then bundled in later (somehow, see my hands wave here). Compiling them separately would fix the namespace clash problems. Maybe it would even pave the way to handle the malloc/free problem, if it could be made to run in some sort of sandboxed environment that would allow resources to be freed -- it just occurred to me it's not just malloc, it's file descriptors and signal handling environment and maybe other things I'm not thinking of right now). -- Ian From owner-freebsd-hackers@FreeBSD.ORG Tue Oct 15 16:02:44 2013 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A075B823; Tue, 15 Oct 2013 16:02:44 +0000 (UTC) (envelope-from alfred@freebsd.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 8D7702268; Tue, 15 Oct 2013 16:02:44 +0000 (UTC) Received: from Alfreds-MacBook-Pro-9.local (c-76-21-10-192.hsd1.ca.comcast.net [76.21.10.192]) by elvis.mu.org (Postfix) with ESMTPSA id 1A7C61A3C74; Tue, 15 Oct 2013 09:02:44 -0700 (PDT) Message-ID: <525D6724.9020307@freebsd.org> Date: Tue, 15 Oct 2013 09:02:44 -0700 From: Alfred Perlstein User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: Ian Lepore Subject: Re: Global variables in system programs References: <525D5A35.4040005@embedded-brains.de> <525D62D9.4050001@freebsd.org> <1381852662.42859.130.camel@revolution.hippie.lan> In-Reply-To: <1381852662.42859.130.camel@revolution.hippie.lan> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Sebastian Huber , FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 16:02:44 -0000 On 10/15/13 8:57 AM, Ian Lepore wrote: > On Tue, 2013-10-15 at 08:44 -0700, Alfred Perlstein wrote: >> On 10/15/13 8:07 AM, Sebastian Huber wrote: >>> Hello, >>> >>> I work currently on a port of the FreeBSD network stack to a real-time >>> operating system for embedded targets. Here the applications are >>> statically linked with the operating system and the network stack. We >>> would like to use the standard FreeBSD system programs to configure >>> the network stack, e.g. ROUTE(8), IFCONFIG(8), etc. For example >>> >>> static const char *const argv[] = { >>> "ifconfig", >>> "lo0", >>> "127.0.0.1" >>> }; >>> >>> ifconfig(3, &argv[0]); >>> >>> These programs use some global variables. In a statically linked >>> context we have now the following problems >>> >>> o we cannot call the programs concurrently, >>> >>> o we have to initialize the values each time. >>> >>> We would like to follow the FreeBSD sources to stay up-to-date. So it >>> is desirable for us to keep the divergence from the original sources >>> as small as possible. Are patches acceptable for the FreeBSD project >>> that alter system programs such that >>> >>> o global variables are moved into context structures, >>> >>> o constant global variables are declared as "const", and >>> >>> o variables and functions are declared as "static" if possible? >>> >>> Attached is a patch for the ROUTE(8) program to give an example. >> Wow! I would really love to see this sort of change make it into >> FreeBSD, not only for linking them all together, but also for running >> them as threads. > Another factor in trying to turn standalone programs into threads > bundled into a larger entity: by design, we do not free allocated > memory, we let program-exit handle that. > > The const and static changes are great. The context thing I'm not so > fond of. Might there be a way to handle these bundled-in programs a bit > like .ko modules somehow? They can be compiled-in, but invoking one > would result in re-initing its data and bss, and because they're still > compiled separately and then bundled in later (somehow, see my hands > wave here). Compiling them separately would fix the namespace clash > problems. Maybe it would even pave the way to handle the malloc/free > problem, if it could be made to run in some sort of sandboxed > environment that would allow resources to be freed -- it just occurred > to me it's not just malloc, it's file descriptors and signal handling > environment and maybe other things I'm not thinking of right now). Yes! You are very correct. One step at a time we can realize this goal. Apache apr library uses the concepts of pools to attach resources to certain lifecycles. Maybe we can do this? I think Peter just pulled in some form of apr into base. Other options are using a form of per-thread data that sets an implicit pool for resource tracking. -Alfred From owner-freebsd-hackers@FreeBSD.ORG Tue Oct 15 18:01:55 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id E92CF541 for ; Tue, 15 Oct 2013 18:01:54 +0000 (UTC) (envelope-from admin@3dr.org) Received: from futurehost.futurehost.pl (futurehost.futurehost.pl [91.200.185.242]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A8F692BAB for ; Tue, 15 Oct 2013 18:01:54 +0000 (UTC) Received: from agco187.neoplus.adsl.tpnet.pl ([178.43.66.187]:59390 helo=LukaszKomputer) by futurehost.futurehost.pl with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.80) (envelope-from ) id 1VW8wD-0007n9-AM for freebsd-hackers@freebsd.org; Tue, 15 Oct 2013 20:01:45 +0200 From: =?iso-8859-2?Q?=A3ukasz_Piecuch?= To: Subject: FUSE backport from FreeBSD 10 to 9.2 ? Date: Tue, 15 Oct 2013 20:01:39 +0200 Message-ID: MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: Ac7J0Env4yeAmKDMR2igrvaf5TpPKw== Content-Language: pl Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 18:01:55 -0000 Hello, I'm looking for someone who will be able to backport FUSE module that is incorporated into FreeBSD 10 into 9.2 . While installed - fuse from 10 works almost fine - except small issues like not refreshing contents of files changed on other nodes in distributed file systems like MooseFS. Is there anyone able to do this? Luke From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 16 08:12:44 2013 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 06721DCC; Wed, 16 Oct 2013 08:12:44 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from mail.embedded-brains.de (host-82-135-62-35.customer.m-online.net [82.135.62.35]) by mx1.freebsd.org (Postfix) with ESMTP id 177C9293F; Wed, 16 Oct 2013 08:12:42 +0000 (UTC) Received: by mail.embedded-brains.de (Postfix, from userid 65534) id 25E42652CFE; Wed, 16 Oct 2013 10:12:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on fidibusdmz X-Spam-Level: X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from [192.168.100.11] (unknown [192.168.100.11]) by mail.embedded-brains.de (Postfix) with ESMTP id 17F4765253A; Wed, 16 Oct 2013 10:12:36 +0200 (CEST) Message-ID: <525E4A6F.40904@embedded-brains.de> Date: Wed, 16 Oct 2013 10:12:31 +0200 From: Sebastian Huber User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: Ian Lepore Subject: Re: Global variables in system programs References: <525D5A35.4040005@embedded-brains.de> <525D62D9.4050001@freebsd.org> <1381852662.42859.130.camel@revolution.hippie.lan> In-Reply-To: <1381852662.42859.130.camel@revolution.hippie.lan> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Cc: FreeBSD Hackers , Alfred Perlstein X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 08:12:44 -0000 On 2013-10-15 17:57, Ian Lepore wrote: > On Tue, 2013-10-15 at 08:44 -0700, Alfred Perlstein wrote: >> On 10/15/13 8:07 AM, Sebastian Huber wrote: >>> Hello, >>> >>> I work currently on a port of the FreeBSD network stack to a real-time >>> operating system for embedded targets. Here the applications are >>> statically linked with the operating system and the network stack. We >>> would like to use the standard FreeBSD system programs to configure >>> the network stack, e.g. ROUTE(8), IFCONFIG(8), etc. For example >>> >>> static const char *const argv[] = { >>> "ifconfig", >>> "lo0", >>> "127.0.0.1" >>> }; >>> >>> ifconfig(3, &argv[0]); >>> >>> These programs use some global variables. In a statically linked >>> context we have now the following problems >>> >>> o we cannot call the programs concurrently, >>> >>> o we have to initialize the values each time. >>> >>> We would like to follow the FreeBSD sources to stay up-to-date. So it >>> is desirable for us to keep the divergence from the original sources >>> as small as possible. Are patches acceptable for the FreeBSD project >>> that alter system programs such that >>> >>> o global variables are moved into context structures, >>> >>> o constant global variables are declared as "const", and >>> >>> o variables and functions are declared as "static" if possible? >>> >>> Attached is a patch for the ROUTE(8) program to give an example. >> >> Wow! I would really love to see this sort of change make it into >> FreeBSD, not only for linking them all together, but also for running >> them as threads. Out of curiosity, what is the benefit of running these programs in a thread in case you have an operating system with proper processes? > > Another factor in trying to turn standalone programs into threads > bundled into a larger entity: by design, we do not free allocated > memory, we let program-exit handle that. This is not a problem for us. Its easy to add custom set up and tear down code without modifying the original FreeBSD sources. We write unit tests that ensure that we have no resource leaks. We also have to map all calls to exit() to a wrapper function which uses longjmp() to jump to a common program termination section which later returns to the caller of the main() function. > > The const and static changes are great. This would definitely help a lot. Some applications run from flash, so everything which lands in the read-only data section saves RAM space. Turning the global functions into static ones will likely affect the code generation. Is this a problem? What about changing the K&R function declarations into standard ones? > The context thing I'm not so > fond of. Might there be a way to handle these bundled-in programs a bit > like .ko modules somehow? I want to avoid a run-time linker. I think that global static variables are not a real problem for us. We can simply use a mutex and allow at most one invocation of the program at once. A local context is a nice-to-have feature. > They can be compiled-in, but invoking one > would result in re-initing its data and bss, and because they're still > compiled separately and then bundled in later (somehow, see my hands > wave here). Compiling them separately would fix the namespace clash > problems. Maybe it would even pave the way to handle the malloc/free > problem, if it could be made to run in some sort of sandboxed > environment that would allow resources to be freed -- it just occurred > to me it's not just malloc, it's file descriptors and signal handling > environment and maybe other things I'm not thinking of right now). > > -- Ian > > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" > -- Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.huber@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG. From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 16 10:49:16 2013 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D0A6E8A9; Wed, 16 Oct 2013 10:49:16 +0000 (UTC) (envelope-from rank1seeker@gmail.com) Received: from mail-ea0-x22d.google.com (mail-ea0-x22d.google.com [IPv6:2a00:1450:4013:c01::22d]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 386DB238F; Wed, 16 Oct 2013 10:49:16 +0000 (UTC) Received: by mail-ea0-f173.google.com with SMTP id g10so265520eak.18 for ; Wed, 16 Oct 2013 03:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:from:to:cc:subject:date:in-reply-to:references; bh=tjAsUK6VPIkrQUyAzMTbyxZ0E5KkXXkyO5sfUq4Z9XQ=; b=xEutAqJdjteaZdKxeltNbfS9N46+e3HxuxHb+zrEC27YhmyhMMI0kZZajwKBoXgrHN te9OCC8sPya6ZwS21vrVdXl9dxKnM69K8facLsbOWeontryAhH44zjQkQneLmT4i7FJp 0pu2xk6kdJdvzJf7wZic+ExFIUDgLdvtbH/AnMdbeu68DIJj/JvCRPAPXo6xgzMlQrQu LJUovk8gprQOOjDKj4MP+SakagyVKaKb1Wx43wkpIR5T26AkWMFOJUPivHdo12TrA057 DcXKhtwg0TEH1SFlGF8ELhOO5asvzF9qh/WDBQVBF8mEkSqrn5eML7k4s85D1X/jS5W5 Tdig== X-Received: by 10.14.89.7 with SMTP id b7mr3662751eef.10.1381920554472; Wed, 16 Oct 2013 03:49:14 -0700 (PDT) Received: from DOMYPC ([82.193.208.225]) by mx.google.com with ESMTPSA id i1sm178070075eeg.0.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 16 Oct 2013 03:49:13 -0700 (PDT) Message-ID: <20131016.104912.479.1@DOMY-PC> From: rank1seeker@gmail.com To: "John Baldwin" Subject: Re: UFS related panic (daily <-> find) Date: Wed, 16 Oct 2013 12:49:12 +0200 In-Reply-To: <201310071212.05281.jhb@freebsd.org> References: <20130719.174511.786.3@DOMY-PC> <201310021702.49174.jhb@freebsd.org> <20131002.214002.280.2@DOMY-PC> <201310071212.05281.jhb@freebsd.org> X-Mailer: POP Peeper (3.8.1.0) Cc: hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 10:49:17 -0000 I've: Read whole disk with 'dd' Checked FS integrity from single user mode. Did a RAM test for ~5 hours (3 complete tests passed in a loop) via memtest86+. All passed without errors ... Now I'm posting this: FreeBSD 9.2-RELEASE #0 r256015 i386 ====================================================== Fatal trap 12: page fault while in kernel mode fault virtual address = 0x25 fault code = supervisor read, page not present instruction pointer = 0x20:0xc083bd42 stack pointer = 0x28:0xe7bfa7ac frame pointer = 0x28:0xe7bfa7b0 code segment = base 0x0, limit 0xfffff, type 0x1b = DPL 0, pres 1, def32 1, gran 1 processor eflags = interrupt enabled, resume, IOPL = 0 current process = 39060 (find) trap number = 12 panic: page fault Uptime: 1d6h37m19s panic: bufwrite: buffer is not busy??? Uptime: 1d6h37m19s Sleeping thread (tid 100122, pid 39060) owns a non-sleepable lock panic: sleeping thread Uptime: 1d6h37m19s Physical memory: 1014 MB Dumping 162 MB: 147 131 115 99 83 67 51 35 19 3 No symbol "stopped_cpus" in current context. No symbol "stoppcbs" in current context. Reading symbols from /boot/kernel/nfscl.ko...Reading symbols from /boot/kernel/nfscl.ko.symbols...done. done. Loaded symbols for /boot/kernel/nfscl.ko Reading symbols from /boot/kernel/nfslock.ko...Reading symbols from /boot/kernel/nfslock.ko.symbols...done. done. Loaded symbols for /boot/kernel/nfslock.ko Reading symbols from /boot/kernel/nfssvc.ko...Reading symbols from /boot/kernel/nfssvc.ko.symbols...done. done. Loaded symbols for /boot/kernel/nfssvc.ko Reading symbols from /boot/kernel/krpc.ko...Reading symbols from /boot/kernel/krpc.ko.symbols...done. done. Loaded symbols for /boot/kernel/krpc.ko Reading symbols from /boot/kernel/nfscommon.ko...Reading symbols from /boot/kernel/nfscommon.ko.symbols...done. done. Loaded symbols for /boot/kernel/nfscommon.ko Reading symbols from /boot/kernel/nfsd.ko...Reading symbols from /boot/kernel/nfsd.ko.symbols...done. done. Loaded symbols for /boot/kernel/nfsd.ko Reading symbols from /boot/kernel/nfslockd.ko...Reading symbols from /boot/kernel/nfslockd.ko.symbols...done. done. Loaded symbols for /boot/kernel/nfslockd.ko Reading symbols from /usr/local/modules/fuse.ko...done. Loaded symbols for /usr/local/modules/fuse.ko Reading symbols from /usr/local/lib/oss/modules/osscore.ko...done. Loaded symbols for /usr/local/lib/oss/modules/osscore.ko Reading symbols from /usr/local/lib/oss/modules/oss_audigyls.ko...done. Loaded symbols for /usr/local/lib/oss/modules/oss_audigyls.ko Reading symbols from /boot/kernel/cpuctl.ko...Reading symbols from /boot/kernel/cpuctl.ko.symbols...done. done. Loaded symbols for /boot/kernel/cpuctl.ko #0 doadump (textdump=1) at pcpu.h:249 249 pcpu.h: No such file or directory. in pcpu.h (kgdb) #0 doadump (textdump=1) at pcpu.h:249 #1 0xc065edaf in kern_reboot (howto=260) at /usr/src/sys/kern/kern_shutdown.c:449 #2 0xc065efe1 in panic (fmt=) at /usr/src/sys/kern/kern_shutdown.c:637 #3 0xc08bb30a in trap_fatal (frame=0xe7bfa76c, eva=37) at /usr/src/sys/i386/i386/trap.c:1044 #4 0xc08bb3f1 in trap_pfault (frame=0xe7bfa76c, usermode=0, eva=37) at /usr/src/sys/i386/i386/trap.c:896 #5 0xc08bc0a0 in trap (frame=0xe7bfa76c) at /usr/src/sys/i386/i386/trap.c:555 #6 0xc08a94ec in calltrap () at /usr/src/sys/i386/i386/exception.s:170 #7 0xc083bd42 in inodedep_find (inodedephd=, fs=0xc4758800, inum=1130832, inodedeppp=0xe7bfa7fc) at /usr/src/sys/ufs/ffs/ffs_softdep.c:2131 #8 0xc0840520 in inodedep_lookup (mp=0xc479d7ec, inum=1130832, flags=0, inodedeppp=0xe7bfa7fc) at /usr/src/sys/ufs/ffs/ffs_softdep.c:2163 #9 0xc0844e5a in softdep_load_inodeblock (ip=0xc81c1910) at /usr/src/sys/ufs/ffs/ffs_softdep.c:11735 #10 0xc08532b2 in ffs_vgetf (mp=0xc479d7ec, ino=1130832, flags=2097152, vpp=0xe7bfa8f0, ffs_flags=) at /usr/src/sys/ufs/ffs/ffs_vfsops.c:1773 #11 0xc08533cd in ffs_vget (mp=0xc479d7ec, ino=1130832, flags=2097152, vpp=0xe7bfa8f0) at /usr/src/sys/ufs/ffs/ffs_vfsops.c:1656 #12 0xc08602c0 in ufs_lookup_ino (vdp=0xc85aa9fc, vpp=0xe7bfaae8, cnp=0xe7bfaafc, dd_ino=0x0) at /usr/src/sys/ufs/ufs/ufs_lookup.c:749 #13 0xc08602fb in ufs_lookup (ap=0xe7bfa964) at /usr/src/sys/ufs/ufs/ufs_lookup.c:214 #14 0xc08d4736 in VOP_CACHEDLOOKUP_APV (vop=0xc0998b40, a=0xe7bfa964) at vnode_if.c:193 #15 0xc06d675f in vfs_cache_lookup (ap=0xe7bfa9ec) at vnode_if.h:80 #16 0xc08d47dc in VOP_LOOKUP_APV (vop=0xc0998b40, a=0xe7bfa9ec) at vnode_if.c:126 #17 0xc06ddf93 in lookup (ndp=0xe7bfaabc) at vnode_if.h:54 #18 0xc06defcf in namei (ndp=0xe7bfaabc) at /usr/src/sys/kern/vfs_lookup.c:294 #19 0xc06f1089 in kern_statat_vnhook (td=0xc4b1e2f0, flag=512, fd=-100, path=0x284512b8
, pathseg=UIO_USERSPACE, sbp=0xe7bfabe8, hook=0) at /usr/src/sys/kern/vfs_syscalls.c:2432 #20 0xc06f11d2 in kern_statat (td=0xc4b1e2f0, flag=512, fd=-100, path=0x284512b8
, pathseg=UIO_USERSPACE, sbp=0xe7bfabe8) at /usr/src/sys/kern/vfs_syscalls.c:2413 #21 0xc06f120a in kern_lstat (td=0xc4b1e2f0, path=0x284512b8
, pathseg=UIO_USERSPACE, sbp=0xe7bfabe8) at /usr/src/sys/kern/vfs_syscalls.c:2486 #22 0xc06f129e in sys_lstat (td=0xc4b1e2f0, uap=0xe7bfaccc) at /usr/src/sys/kern/vfs_syscalls.c:2476 #23 0xc08bb8bb in syscall (frame=0xe7bfad08) at subr_syscall.c:135 #24 0xc08a9551 in Xint0x80_syscall () at /usr/src/sys/i386/i386/exception.s:270 #25 0x00000033 in ?? () Previous frame inner to this frame (corrupt stack?) (kgdb) ====================================================== Domagoj From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 16 13:29:08 2013 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 24E0030A; Wed, 16 Oct 2013 13:29:08 +0000 (UTC) (envelope-from alfred@freebsd.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 1148C2D4A; Wed, 16 Oct 2013 13:29:07 +0000 (UTC) Received: from Alfreds-MacBook-Pro-9.local (c-76-21-10-192.hsd1.ca.comcast.net [76.21.10.192]) by elvis.mu.org (Postfix) with ESMTPSA id 869371A3C1D; Wed, 16 Oct 2013 06:29:07 -0700 (PDT) Message-ID: <525E94A5.7060809@freebsd.org> Date: Wed, 16 Oct 2013 06:29:09 -0700 From: Alfred Perlstein User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: Sebastian Huber , Ian Lepore Subject: Re: Global variables in system programs References: <525D5A35.4040005@embedded-brains.de> <525D62D9.4050001@freebsd.org> <1381852662.42859.130.camel@revolution.hippie.lan> <525E4A6F.40904@embedded-brains.de> In-Reply-To: <525E4A6F.40904@embedded-brains.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 13:29:08 -0000 On 10/16/13 1:12 AM, Sebastian Huber wrote: > On 2013-10-15 17:57, Ian Lepore wrote: >> On Tue, 2013-10-15 at 08:44 -0700, Alfred Perlstein wrote: >>> On 10/15/13 8:07 AM, Sebastian Huber wrote: >>>> Hello, >>>> >>>> I work currently on a port of the FreeBSD network stack to a real-time >>>> operating system for embedded targets. Here the applications are >>>> statically linked with the operating system and the network stack. We >>>> would like to use the standard FreeBSD system programs to configure >>>> the network stack, e.g. ROUTE(8), IFCONFIG(8), etc. For example >>>> >>>> static const char *const argv[] = { >>>> "ifconfig", >>>> "lo0", >>>> "127.0.0.1" >>>> }; >>>> >>>> ifconfig(3, &argv[0]); >>>> >>>> These programs use some global variables. In a statically linked >>>> context we have now the following problems >>>> >>>> o we cannot call the programs concurrently, >>>> >>>> o we have to initialize the values each time. >>>> >>>> We would like to follow the FreeBSD sources to stay up-to-date. So it >>>> is desirable for us to keep the divergence from the original sources >>>> as small as possible. Are patches acceptable for the FreeBSD project >>>> that alter system programs such that >>>> >>>> o global variables are moved into context structures, >>>> >>>> o constant global variables are declared as "const", and >>>> >>>> o variables and functions are declared as "static" if possible? >>>> >>>> Attached is a patch for the ROUTE(8) program to give an example. >>> >>> Wow! I would really love to see this sort of change make it into >>> FreeBSD, not only for linking them all together, but also for running >>> them as threads. > > Out of curiosity, what is the benefit of running these programs in a > thread in case you have an operating system with proper processes? Imagine a program or some shell which loads a bunch of shared objects so instead of needing to fork/exec for each command can just dispatch to a thread. It would let that program be very fast as opposed to a traditional fork/exec model. -Alfred From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 16 16:47:54 2013 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 531736F6 for ; Wed, 16 Oct 2013 16:47:54 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mho-01-ewr.mailhop.org (mho-03-ewr.mailhop.org [204.13.248.66]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 29E7F2B6E for ; Wed, 16 Oct 2013 16:47:53 +0000 (UTC) Received: from c-24-8-230-52.hsd1.co.comcast.net ([24.8.230.52] helo=damnhippie.dyndns.org) by mho-01-ewr.mailhop.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1VWUGG-0009Oh-T2; Wed, 16 Oct 2013 16:47:53 +0000 Received: from [172.22.42.240] (revolution.hippie.lan [172.22.42.240]) by damnhippie.dyndns.org (8.14.3/8.14.3) with ESMTP id r9GGlou8028549; Wed, 16 Oct 2013 10:47:50 -0600 (MDT) (envelope-from ian@FreeBSD.org) X-Mail-Handler: Dyn Standard SMTP by Dyn X-Originating-IP: 24.8.230.52 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/sendlabs/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX18B0ZpJHfZHrVtqYhegvqq4 Subject: Re: [patch] 'make DESTDIR=/any/nonroot/dir ... xdev' is broken From: Ian Lepore To: Patrick Kelsey In-Reply-To: References: Content-Type: text/plain; charset="us-ascii" Date: Wed, 16 Oct 2013 10:47:50 -0600 Message-ID: <1381942070.1168.42.camel@revolution.hippie.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@FreeBSD.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 16:47:54 -0000 On Tue, 2013-10-15 at 00:51 -0400, Patrick Kelsey wrote: > Hi, > > The patch below makes building the xdev target with non-default values > of DESTDIR work. It also removes the leading '/' from XDTP to clean > up path construction using that var. > > -Patrick > > > Index: Makefile.inc1 > =================================================================== > --- Makefile.inc1 (revision 256489) > +++ Makefile.inc1 (working copy) > @@ -1830,7 +1830,7 @@ > CPUTYPE=${XDEV_CPUTYPE} > > XDDIR=${XDEV_ARCH}-freebsd > -XDTP=/usr/${XDDIR} > +XDTP=usr/${XDDIR} > CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \ > INSTALL="sh ${.CURDIR}/tools/install.sh" > CDENV= ${CDBENV} \ > @@ -1843,8 +1843,8 @@ > > CDTMP= ${MAKEOBJDIRPREFIX}/${XDDIR}/${.CURDIR}/tmp > CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${NOFUN} > -CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDTP}/usr/bin:${PATH} > ${MAKE} ${NOFUN} > -XDDESTDIR=${DESTDIR}${XDTP} > +CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} > ${MAKE} ${NOFUN} > +XDDESTDIR=${DESTDIR}/${XDTP} > .if !defined(OSREL) > OSREL!= uname -r | sed -e 's/[-(].*//' > .endif > @@ -1924,6 +1924,7 @@ > > _xi-links: > ${_+_}cd ${XDDESTDIR}/usr/bin; \ > + mkdir -p ../../../../usr/bin; \ > for i in *; do \ > ln -sf ../../${XDTP}/usr/bin/$$i \ > ../../../../usr/bin/${XDDIR}-$$i; \ I verified that I could not do a 'make xdev' with DESTDIR= set to a non-default value, and it worked sucessfully after this patch was applied. Committed as r256640. -- Ian From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 16 19:57:43 2013 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 84B04F18 for ; Wed, 16 Oct 2013 19:57:43 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mho-02-ewr.mailhop.org (mho-02-ewr.mailhop.org [204.13.248.72]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 5B95D26E3 for ; Wed, 16 Oct 2013 19:57:43 +0000 (UTC) Received: from c-24-8-230-52.hsd1.co.comcast.net ([24.8.230.52] helo=damnhippie.dyndns.org) by mho-02-ewr.mailhop.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1VWXDx-000Psr-T4 for freebsd-hackers@FreeBSD.org; Wed, 16 Oct 2013 19:57:42 +0000 Received: from [172.22.42.240] (revolution.hippie.lan [172.22.42.240]) by damnhippie.dyndns.org (8.14.3/8.14.3) with ESMTP id r9GJvduX028675 for ; Wed, 16 Oct 2013 13:57:39 -0600 (MDT) (envelope-from ian@FreeBSD.org) X-Mail-Handler: Dyn Standard SMTP by Dyn X-Originating-IP: 24.8.230.52 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/sendlabs/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX1/1JvVxcL4mheVZXakDKtKi Subject: why does /dev/md call cpu_dcache_flush()? From: Ian Lepore To: "freebsd-hackers@freebsd.org" Content-Type: text/plain; charset="us-ascii" Date: Wed, 16 Oct 2013 13:57:39 -0600 Message-ID: <1381953459.1168.48.camel@revolution.hippie.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 19:57:43 -0000 The only caller of cpu_dcache_flush() in the entire system appears to be the md device. Does anybody know why it makes the call? -- Ian From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 16 20:39:48 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id DECDDDC4; Wed, 16 Oct 2013 20:39:48 +0000 (UTC) (envelope-from pkelsey@gmail.com) Received: from mail-bk0-x236.google.com (mail-bk0-x236.google.com [IPv6:2a00:1450:4008:c01::236]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 522C22937; Wed, 16 Oct 2013 20:39:48 +0000 (UTC) Received: by mail-bk0-f54.google.com with SMTP id mz12so482987bkb.13 for ; Wed, 16 Oct 2013 13:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=XocITlf+ktEC5TebuJpxrfovcNodeKkg4ACNVlT5lmE=; b=DrULS+7AkDD6BGLWQVg9UnaoAwOMyC/Dq31Ot5nBInHGQOzC7RTlgTIiQG8rYGIcrZ BsV/toZJCBOxjn8uy3kEuWbY4MeNRvz5einh88mE5PEbz+8EDnhb2tJNy6VieegGB5Y0 hqnNmGWxgVFxG0O4F1XvW5sVS3Oe1rEjB5gYV3IbwJhwWkT6ZXd9YHnowHz98Ec5n7h+ 5OtQIBXJokUkn4406gNLWbTXR84KYuiDLIz437CdGRezAr+17l43HqGsO2jMQs47f5En 62Z7eMZCuF2bmFBIk2nF4gZtrzlccFcRGyETnwvtzQBBdA3NfeqEkVWcM7yXy8qpfeMz rLlA== MIME-Version: 1.0 X-Received: by 10.205.22.71 with SMTP id qv7mr4171815bkb.20.1381955986473; Wed, 16 Oct 2013 13:39:46 -0700 (PDT) Sender: pkelsey@gmail.com Received: by 10.204.100.69 with HTTP; Wed, 16 Oct 2013 13:39:46 -0700 (PDT) In-Reply-To: <1381953459.1168.48.camel@revolution.hippie.lan> References: <1381953459.1168.48.camel@revolution.hippie.lan> Date: Wed, 16 Oct 2013 16:39:46 -0400 X-Google-Sender-Auth: f6rjRar_BYJQSeXkN6CRMPc3ZrE Message-ID: Subject: Re: why does /dev/md call cpu_dcache_flush()? From: Patrick Kelsey To: Ian Lepore Content-Type: text/plain; charset=ISO-8859-1 Cc: "freebsd-hackers@freebsd.org" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 20:39:48 -0000 Perhaps it is along the lines of what the comment on most of the implementations suggests: /* * Flush the D-cache for non-DMA I/O so that the I-cache can * be made coherent later. */ void cpu_flush_dcache(void *ptr, size_t len) On a malloc-backed md, servicing a read may result in a D-cache to D-cache transfer if the source and destination buffers are already at least partially in the D-cache. If the originator of the read plans on executing the read data, the I-cache won't find what was just read if part of the read was handled by an intra-D-cache transfer, unless the buffer the data was read into is flushed out to memory first (or I suppose, technically, unless your hardware I-cache happens to check the D-cache also, or they are unified). -Patrick On Wed, Oct 16, 2013 at 3:57 PM, Ian Lepore wrote: > The only caller of cpu_dcache_flush() in the entire system appears to be > the md device. Does anybody know why it makes the call? > > -- Ian > > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 16 20:40:22 2013 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A5330F46 for ; Wed, 16 Oct 2013 20:40:22 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mho-02-ewr.mailhop.org (mho-02-ewr.mailhop.org [204.13.248.72]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7B3042971 for ; Wed, 16 Oct 2013 20:40:22 +0000 (UTC) Received: from c-24-8-230-52.hsd1.co.comcast.net ([24.8.230.52] helo=damnhippie.dyndns.org) by mho-02-ewr.mailhop.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1VWXtF-000ANk-Bi; Wed, 16 Oct 2013 20:40:21 +0000 Received: from [172.22.42.240] (revolution.hippie.lan [172.22.42.240]) by damnhippie.dyndns.org (8.14.3/8.14.3) with ESMTP id r9GKeIJ7028716; Wed, 16 Oct 2013 14:40:18 -0600 (MDT) (envelope-from ian@FreeBSD.org) X-Mail-Handler: Dyn Standard SMTP by Dyn X-Originating-IP: 24.8.230.52 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/sendlabs/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX18dSTG1VQe3SzBJ6jYCW3sA Subject: Re: why does /dev/md call cpu_dcache_flush()? From: Ian Lepore To: Poul-Henning Kamp In-Reply-To: <94783.1381954696@critter.freebsd.dk> References: <1381953459.1168.48.camel@revolution.hippie.lan> <94783.1381954696@critter.freebsd.dk> Content-Type: text/plain; charset="us-ascii" Date: Wed, 16 Oct 2013 14:40:18 -0600 Message-ID: <1381956018.1168.61.camel@revolution.hippie.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit Cc: "freebsd-hackers@freebsd.org" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 20:40:22 -0000 On Wed, 2013-10-16 at 20:18 +0000, Poul-Henning Kamp wrote: > In message <1381953459.1168.48.camel@revolution.hippie.lan>, Ian Lepore writes: > >The only caller of cpu_dcache_flush() in the entire system appears to be > >the md device. Does anybody know why it makes the call? > > r192323 | marcel | 2009-05-18 18:37:18 +0000 (Mon, 18 May 2009) | 20 lines > > Add cpu_flush_dcache() for use after non-DMA based I/O so that a > possible future I-cache coherency operation can succeed. On ARM > for example the L1 cache can be (is) virtually mapped, which > means that any I/O that uses temporary mappings will not see the > I-cache made coherent. On ia64 a similar behaviour has been > observed. By flushing the D-cache, execution of binaries backed > by md(4) and/or NFS work reliably. > For Book-E (powerpc), execution over NFS exhibits SIGILL once in > a while as well, though cpu_flush_dcache() hasn't been implemented > yet. > > Doing an explicit D-cache flush as part of the non-DMA based I/O > read operation eliminates the need to do it as part of the > I-cache coherency operation itself and as such avoids pessimizing > the DMA-based I/O read operations for which D-cache are already > flushed/invalidated. It also allows future optimizations whereby > the bcopy() followed by the D-cache flush can be integrated in a > single operation, which could be implemented using on-chips DMA > engines, by-passing the D-cache altogether. > Hrm. Now I feel dumb for not finding that obviously-available info for myself. But I guess I'll get over that and move on to what I would have posted if I had found it... The first part of the comment about temporary mappings on ARM is outdated, although it would have been true at the time that was written. Nowadays if multiple mappings are made to the same memory on VIVT ARM chips, all mappings are changed to non-cacheable to avoid those problems. I think the rest of it is just wrong. Data read in from any source may be in the caches when the read is done, whether the source was memory or anything else. Even if DMA was involved at some point, if bounce buffers were used that involves copying memory->memory after the DMA completes and it's quite likely some of that data is still in the caches. -- Ian From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 16 20:18:24 2013 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 788118E6; Wed, 16 Oct 2013 20:18:24 +0000 (UTC) (envelope-from phk@phk.freebsd.dk) Received: from phk.freebsd.dk (phk.freebsd.dk [130.225.244.222]) by mx1.freebsd.org (Postfix) with ESMTP id 3BD42281D; Wed, 16 Oct 2013 20:18:24 +0000 (UTC) Received: from critter.freebsd.dk (critter-phk.freebsd.dk [192.168.48.2]) by phk.freebsd.dk (Postfix) with ESMTP id 505553EB5F; Wed, 16 Oct 2013 20:18:17 +0000 (UTC) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.14.7/8.14.7) with ESMTP id r9GKIG3Y094784; Wed, 16 Oct 2013 20:18:17 GMT (envelope-from phk@phk.freebsd.dk) To: Ian Lepore Subject: Re: why does /dev/md call cpu_dcache_flush()? In-reply-to: <1381953459.1168.48.camel@revolution.hippie.lan> From: "Poul-Henning Kamp" References: <1381953459.1168.48.camel@revolution.hippie.lan> Content-Type: text/plain; charset=ISO-8859-1 Date: Wed, 16 Oct 2013 20:18:16 +0000 Message-ID: <94783.1381954696@critter.freebsd.dk> X-Mailman-Approved-At: Wed, 16 Oct 2013 20:56:54 +0000 Cc: "freebsd-hackers@freebsd.org" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 20:18:24 -0000 In message <1381953459.1168.48.camel@revolution.hippie.lan>, Ian Lepore writes: >The only caller of cpu_dcache_flush() in the entire system appears to be >the md device. Does anybody know why it makes the call? r192323 | marcel | 2009-05-18 18:37:18 +0000 (Mon, 18 May 2009) | 20 lines Add cpu_flush_dcache() for use after non-DMA based I/O so that a possible future I-cache coherency operation can succeed. On ARM for example the L1 cache can be (is) virtually mapped, which means that any I/O that uses temporary mappings will not see the I-cache made coherent. On ia64 a similar behaviour has been observed. By flushing the D-cache, execution of binaries backed by md(4) and/or NFS work reliably. For Book-E (powerpc), execution over NFS exhibits SIGILL once in a while as well, though cpu_flush_dcache() hasn't been implemented yet. Doing an explicit D-cache flush as part of the non-DMA based I/O read operation eliminates the need to do it as part of the I-cache coherency operation itself and as such avoids pessimizing the DMA-based I/O read operations for which D-cache are already flushed/invalidated. It also allows future optimizations whereby the bcopy() followed by the D-cache flush can be integrated in a single operation, which could be implemented using on-chips DMA engines, by-passing the D-cache altogether. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 16 21:09:13 2013 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id DCE0D882 for ; Wed, 16 Oct 2013 21:09:13 +0000 (UTC) (envelope-from rozhuk.im@gmail.com) Received: from mail-bk0-x229.google.com (mail-bk0-x229.google.com [IPv6:2a00:1450:4008:c01::229]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 61AD12AFC for ; Wed, 16 Oct 2013 21:09:13 +0000 (UTC) Received: by mail-bk0-f41.google.com with SMTP id na10so496953bkb.0 for ; Wed, 16 Oct 2013 14:09:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=reply-to:from:to:cc:references:in-reply-to:subject:date:message-id :mime-version:content-type:content-transfer-encoding:thread-index :content-language; bh=TEfTR2IT8cgSUC+daAMlyFe9FhhjoRpeV/8HjJ9Q2AA=; b=XFE1UKTpJGM89ecPDkiGEMbv0gGUbPVyEgmkLNotnvuqc8VaKuU6JMaxJPTJEV1ebO cGPl6YYJgHPPt5CAXYkmTTaHSLkXlO0zCy9PMOJg948IgwUXZ47h1b8/TILm5vTNWnqi YSvFALSU5piRWxiJis0i1oJZ7yoYrmZ/kcDvB6qitTBACCy06X7GPuiZJ6n78SnOgGI1 QnNve/I9y9THifa/ab7iBHD4p4TyKQ3NDm1GWxtNvaAstp5Uq7fgvVbbXs31c0NcT/sE tPWnfFCfQxBo9w9nEgiu+4aQveaBFxiwmcOS0NYJBUpNKsGvcPUDOxT9eD63CGTHbRTY 7rMw== X-Received: by 10.205.10.132 with SMTP id pa4mr4235830bkb.15.1381957751311; Wed, 16 Oct 2013 14:09:11 -0700 (PDT) Received: from rimwks1w7x64 ([2001:470:1f15:8e:bd94:d381:96f4:712]) by mx.google.com with ESMTPSA id nv4sm48288421bkb.3.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 16 Oct 2013 14:09:10 -0700 (PDT) From: rozhuk.im@gmail.com To: "'Willem Jan Withagen'" References: <52520d5f.c402cd0a.5f4e.ffffffa2@mx.google.com> <52553F3F.9090707@digiware.nl> <5255478B.9090305@digiware.nl> In-Reply-To: <5255478B.9090305@digiware.nl> Subject: RE: amdtemp need help with testing Date: Thu, 17 Oct 2013 01:09:00 +0400 Message-ID: <525f0076.c402cd0a.5f4e.7f67@mx.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac7E6HaBirTnXBxXR06LiZs9wgZ2XwFyivlQ Content-Language: ru Cc: hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Rozhuk.IM@gmail.com List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 21:09:13 -0000 Thanks for the help with testing! I fixed a bug, added HTC registers, changed the _ident() and the _probe(): no binding processor Family. The latest version here: http://netlab.linkpc.net/download/tmp/amdtemp.c > -----Original Message----- > From: Willem Jan Withagen [mailto:wjw@digiware.nl] > Sent: Wednesday, October 09, 2013 4:10 PM > To: Rozhuk.IM@gmail.com > Cc: hackers@freebsd.org > Subject: Re: amdtemp need help with testing > > On 2013-10-09 13:34, Willem Jan Withagen wrote: > > On 2013-10-07 3:24, rozhuk.im@gmail.com wrote: > >> I updated amdtemp and now I need your help with testing. > >> > >> Now the driver should support all AMD processors. > >> For a family of 15h and 16h, not all sensors are available - for my > >> system does not find drivers for ati SMBus, and other systems based > >> on the AMD I have not. > > > > CPU: AMD Phenom(tm) II X6 1075T Processor (3013.83-MHz K8-class CPU) > > Origin = "AuthenticAMD" Id = 0x100fa0 Family = 0x10 Model = 0xa > > Stepping = 0 > > > Features=0x178bfbff > GE,MCA,CMOV,PAT,PSE36,CLFLUSH,MMX,FXSR,SSE,SSE2,HTT> > > > > Features2=0x802009 > > AMD > > > Features=0xee500800 ow!> > > AMD > > > Features2=0x37ff > IBS,SKINIT,WDT> > > > > TSC: P-state invariant, performance statistics > > L1 2MB data TLB: 48 entries, fully associative > > L1 2MB instruction TLB: 16 entries, fully associative > > L1 4KB data TLB: 48 entries, fully associative > > L1 4KB instruction TLB: 32 entries, fully associative > > L1 data cache: 64 kbytes, 64 bytes/line, 1 lines/tag, 2-way > > associative > > L1 instruction cache: 64 kbytes, 64 bytes/line, 1 lines/tag, 2-way > > associative > > L2 2MB data TLB: 128 entries, 2-way associative > > L2 2MB instruction TLB: 0 entries, 2-way associative > > > > This is what I get with the 10.0-ALPHA4 driver. > > > > sysctl -a | grep amd > > machine amd64 > > hw.machine: amd64 > > hw.machine_arch: amd64 > > hw.snd.version: 2009061500/amd64 > > hw.mca.amd10h_L1TP: 1 > > dev.amdtemp.0.%desc: AMD CPU On-Die Thermal Sensors > > dev.amdtemp.0.%driver: amdtemp > > dev.amdtemp.0.%parent: hostb4 > > dev.amdtemp.0.sensor_offset: 0 > > dev.amdtemp.0.core0.sensor0: 58.0C > > > After bruteforce fixing the compile error by deleting the #ifdef around > the definition... > > --WjW > > freetest# sysctl -a | grep amd > machine amd64 > "Giant","amdtemp" > hw.machine: amd64 > hw.machine_arch: amd64 > hw.snd.version: 2009061500/amd64 > hw.mca.amd10h_L1TP: 1 > dev.amdtemp.0.%desc: AMD CPU On-Die Thermal Sensors > dev.amdtemp.0.%driver: amdtemp > dev.amdtemp.0.%parent: hostb4 > dev.amdtemp.0.rtc.CurTmp: 36.6C > dev.amdtemp.0.rtc.CurTmpTjSel: -12.5C > dev.amdtemp.0.rtc.TmpSlewDnEn: 1 > dev.amdtemp.0.rtc.TmpMaxDiffUp: 3 > dev.amdtemp.0.rtc.PerStepTimeDn: 15 > dev.amdtemp.0.rtc.PerStepTimeUp: 15 > dev.amdtemp.0.rtc.sensor_offset: 0 > dev.amdtemp.0.tsi.sensor0.cpu_temperature: 36.6C > dev.amdtemp.0.tsi.sensor0.high_temperature_threshold: 70.0C > dev.amdtemp.0.tsi.sensor0.low_temperature_threshold: 0.0C > dev.amdtemp.0.tsi.sensor0.cpu_temperature_offset_hi: 0 > dev.amdtemp.0.tsi.sensor0.cpu_temperature_offset_lo: 0 > dev.amdtemp.0.tsi.sensor0.status: 0 > dev.amdtemp.0.tsi.sensor0.cfg3: 0 > dev.amdtemp.0.tsi.sensor0.cfg9: 0 > dev.amdtemp.0.tsi.sensor0.upd_rate: 8 > dev.amdtemp.0.tsi.sensor0.timeout_cfg: 128 > dev.amdtemp.0.tsi.sensor0.alert_threshold: 0 > dev.amdtemp.0.tsi.sensor0.alert_cfg: 0 > dev.amdtemp.0.tsi.sensor0.manufacture_id: 0 > dev.amdtemp.0.tsi.sensor0.revision: 1 > dev.amdtemp.0.tsi.sensor0.sensor_offset: 0 > dev.amdtemp.0.tsi.sensor1.cpu_temperature: 36.6C > dev.amdtemp.0.tsi.sensor1.high_temperature_threshold: 70.0C > dev.amdtemp.0.tsi.sensor1.low_temperature_threshold: 0.0C > dev.amdtemp.0.tsi.sensor1.cpu_temperature_offset_hi: 0 > dev.amdtemp.0.tsi.sensor1.cpu_temperature_offset_lo: 0 > dev.amdtemp.0.tsi.sensor1.status: 0 > dev.amdtemp.0.tsi.sensor1.cfg3: 0 > dev.amdtemp.0.tsi.sensor1.cfg9: 0 > dev.amdtemp.0.tsi.sensor1.upd_rate: 8 > dev.amdtemp.0.tsi.sensor1.timeout_cfg: 128 > dev.amdtemp.0.tsi.sensor1.alert_threshold: 0 > dev.amdtemp.0.tsi.sensor1.alert_cfg: 0 > dev.amdtemp.0.tsi.sensor1.manufacture_id: 0 > dev.amdtemp.0.tsi.sensor1.revision: 1 > dev.amdtemp.0.tsi.sensor1.sensor_offset: 0 > dev.amdtemp.0.tsi.sensor2.cpu_temperature: 36.6C > dev.amdtemp.0.tsi.sensor2.high_temperature_threshold: 70.0C > dev.amdtemp.0.tsi.sensor2.low_temperature_threshold: 0.0C > dev.amdtemp.0.tsi.sensor2.cpu_temperature_offset_hi: 0 > dev.amdtemp.0.tsi.sensor2.cpu_temperature_offset_lo: 0 > dev.amdtemp.0.tsi.sensor2.status: 0 > dev.amdtemp.0.tsi.sensor2.cfg3: 0 > dev.amdtemp.0.tsi.sensor2.cfg9: 0 > dev.amdtemp.0.tsi.sensor2.upd_rate: 8 > dev.amdtemp.0.tsi.sensor2.timeout_cfg: 128 > dev.amdtemp.0.tsi.sensor2.alert_threshold: 0 > dev.amdtemp.0.tsi.sensor2.alert_cfg: 0 > dev.amdtemp.0.tsi.sensor2.manufacture_id: 0 > dev.amdtemp.0.tsi.sensor2.revision: 1 > dev.amdtemp.0.tsi.sensor2.sensor_offset: 0 > dev.amdtemp.0.tsi.sensor3.cpu_temperature: 36.6C > dev.amdtemp.0.tsi.sensor3.high_temperature_threshold: 70.0C > dev.amdtemp.0.tsi.sensor3.low_temperature_threshold: 0.0C > dev.amdtemp.0.tsi.sensor3.cpu_temperature_offset_hi: 0 > dev.amdtemp.0.tsi.sensor3.cpu_temperature_offset_lo: 0 > dev.amdtemp.0.tsi.sensor3.status: 0 > dev.amdtemp.0.tsi.sensor3.cfg3: 0 > dev.amdtemp.0.tsi.sensor3.cfg9: 0 > dev.amdtemp.0.tsi.sensor3.upd_rate: 8 > dev.amdtemp.0.tsi.sensor3.timeout_cfg: 128 > dev.amdtemp.0.tsi.sensor3.alert_threshold: 0 > dev.amdtemp.0.tsi.sensor3.alert_cfg: 0 > dev.amdtemp.0.tsi.sensor3.manufacture_id: 0 > dev.amdtemp.0.tsi.sensor3.revision: 1 > dev.amdtemp.0.tsi.sensor3.sensor_offset: 0 > dev.amdtemp.0.tsi.sensor4.cpu_temperature: 36.6C > dev.amdtemp.0.tsi.sensor4.high_temperature_threshold: 70.0C > dev.amdtemp.0.tsi.sensor4.low_temperature_threshold: 0.0C > dev.amdtemp.0.tsi.sensor4.cpu_temperature_offset_hi: 0 > dev.amdtemp.0.tsi.sensor4.cpu_temperature_offset_lo: 0 > dev.amdtemp.0.tsi.sensor4.status: 0 > dev.amdtemp.0.tsi.sensor4.cfg3: 0 > dev.amdtemp.0.tsi.sensor4.cfg9: 0 > dev.amdtemp.0.tsi.sensor4.upd_rate: 8 > dev.amdtemp.0.tsi.sensor4.timeout_cfg: 128 > dev.amdtemp.0.tsi.sensor4.alert_threshold: 0 > dev.amdtemp.0.tsi.sensor4.alert_cfg: 0 > dev.amdtemp.0.tsi.sensor4.manufacture_id: 0 > dev.amdtemp.0.tsi.sensor4.revision: 1 > dev.amdtemp.0.tsi.sensor4.sensor_offset: 0 > dev.amdtemp.0.tsi.sensor5.cpu_temperature: 36.6C > dev.amdtemp.0.tsi.sensor5.high_temperature_threshold: 70.0C > dev.amdtemp.0.tsi.sensor5.low_temperature_threshold: 0.0C > dev.amdtemp.0.tsi.sensor5.cpu_temperature_offset_hi: 0 > dev.amdtemp.0.tsi.sensor5.cpu_temperature_offset_lo: 0 > dev.amdtemp.0.tsi.sensor5.status: 0 > dev.amdtemp.0.tsi.sensor5.cfg3: 0 > dev.amdtemp.0.tsi.sensor5.cfg9: 0 > dev.amdtemp.0.tsi.sensor5.upd_rate: 8 > dev.amdtemp.0.tsi.sensor5.timeout_cfg: 128 > dev.amdtemp.0.tsi.sensor5.alert_threshold: 0 > dev.amdtemp.0.tsi.sensor5.alert_cfg: 0 > dev.amdtemp.0.tsi.sensor5.manufacture_id: 0 > dev.amdtemp.0.tsi.sensor5.revision: 1 > dev.amdtemp.0.tsi.sensor5.sensor_offset: 0 > dev.amdtemp.0.tsi.sensor6.cpu_temperature: 36.6C > dev.amdtemp.0.tsi.sensor6.high_temperature_threshold: 70.0C > dev.amdtemp.0.tsi.sensor6.low_temperature_threshold: 0.0C > dev.amdtemp.0.tsi.sensor6.cpu_temperature_offset_hi: 0 > dev.amdtemp.0.tsi.sensor6.cpu_temperature_offset_lo: 0 > dev.amdtemp.0.tsi.sensor6.status: 0 > dev.amdtemp.0.tsi.sensor6.cfg3: 0 > dev.amdtemp.0.tsi.sensor6.cfg9: 0 > dev.amdtemp.0.tsi.sensor6.upd_rate: 8 > dev.amdtemp.0.tsi.sensor6.timeout_cfg: 128 > dev.amdtemp.0.tsi.sensor6.alert_threshold: 0 > dev.amdtemp.0.tsi.sensor6.alert_cfg: 0 > dev.amdtemp.0.tsi.sensor6.manufacture_id: 0 > dev.amdtemp.0.tsi.sensor6.revision: 1 > dev.amdtemp.0.tsi.sensor6.sensor_offset: 0 > dev.amdtemp.0.tsi.sensor7.cpu_temperature: 36.6C > dev.amdtemp.0.tsi.sensor7.high_temperature_threshold: 70.0C > dev.amdtemp.0.tsi.sensor7.low_temperature_threshold: 0.0C > dev.amdtemp.0.tsi.sensor7.cpu_temperature_offset_hi: 0 > dev.amdtemp.0.tsi.sensor7.cpu_temperature_offset_lo: 0 > dev.amdtemp.0.tsi.sensor7.status: 0 > dev.amdtemp.0.tsi.sensor7.cfg3: 0 > dev.amdtemp.0.tsi.sensor7.cfg9: 0 > dev.amdtemp.0.tsi.sensor7.upd_rate: 8 > dev.amdtemp.0.tsi.sensor7.timeout_cfg: 128 > dev.amdtemp.0.tsi.sensor7.alert_threshold: 0 > dev.amdtemp.0.tsi.sensor7.alert_cfg: 0 > dev.amdtemp.0.tsi.sensor7.manufacture_id: 0 > dev.amdtemp.0.tsi.sensor7.revision: 1 > dev.amdtemp.0.tsi.sensor7.sensor_offset: 0 > From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 16 21:22:56 2013 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A57ADEAB for ; Wed, 16 Oct 2013 21:22:56 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7F4652BC8 for ; Wed, 16 Oct 2013 21:22:56 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 7F3C9B96E; Wed, 16 Oct 2013 17:22:55 -0400 (EDT) From: John Baldwin To: rank1seeker@gmail.com Subject: Re: UFS related panic (daily <-> find) Date: Wed, 16 Oct 2013 16:50:52 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) References: <20130719.174511.786.3@DOMY-PC> <201310071212.05281.jhb@freebsd.org> <20131016.104912.479.1@DOMY-PC> In-Reply-To: <20131016.104912.479.1@DOMY-PC> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201310161650.52354.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Wed, 16 Oct 2013 17:22:55 -0400 (EDT) Cc: hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 21:22:56 -0000 On Wednesday, October 16, 2013 6:49:12 am rank1seeker@gmail.com wrote: > I've: > Read whole disk with 'dd' > Checked FS integrity from single user mode. > Did a RAM test for ~5 hours (3 complete tests passed in a loop) via > memtest86+. > > All passed without errors ... > Now I'm posting this: > > > FreeBSD 9.2-RELEASE #0 r256015 > i386 > ====================================================== > Fatal trap 12: page fault while in kernel mode > fault virtual address = 0x25 > fault code = supervisor read, page not present > instruction pointer = 0x20:0xc083bd42 Same drill as before, see what instruction this is. Actually, this looks to be in the same location as your last panic, so a NULL pointer is 0x1 instead of 0x0 again. In my experience, this would still indicate failing RAM to me, memtest86+ notwithstanding (memtest86+ is single threaded AFAIK, so it may not stress the hardware quite the same, e.g. if the error is heat related, etc.). -- John Baldwin From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 16 21:43:34 2013 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 4F5F2769; Wed, 16 Oct 2013 21:43:34 +0000 (UTC) (envelope-from amvandemore@gmail.com) Received: from mail-pd0-x22a.google.com (mail-pd0-x22a.google.com [IPv6:2607:f8b0:400e:c02::22a]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 2370F2CE3; Wed, 16 Oct 2013 21:43:34 +0000 (UTC) Received: by mail-pd0-f170.google.com with SMTP id x10so1590010pdj.15 for ; Wed, 16 Oct 2013 14:43:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=OypKWDuWhM0L/1ZGbhnGVMKtnYZt/c861rTX9VoQ9d0=; b=NMzLhn/0w2xubh0j4RBNrmmvVt+9xQig/Ag06Y4bRyDjML774rprSFb8088h/kBAMb OwLbs3vNgACMW93YAavMjlHp4B132oPRZ1OyJcsGbSesecZE95Nz5Mjr/gxySqMJM/k/ nj+aZL5LAirgRBWT0lJ/ubhhq7jyxNHb8nHRGJcMCSLe+ILqj5jvW5+xU7fcd7/lSEz1 O2s6qVJHgcoxYIFzs/2mogc/HnP5R7hJVWP5ug3lzPuq9NkxCPTRs4bmWh9gxE3S3Tsf QddI3VTmOS/qMMFEXiOSIwYvkk4QvaDt4Nr4wj9U5ajVcXiZK5CUJEbkZvs9DKsuO/iU RExg== MIME-Version: 1.0 X-Received: by 10.68.134.65 with SMTP id pi1mr4995110pbb.59.1381959813679; Wed, 16 Oct 2013 14:43:33 -0700 (PDT) Received: by 10.70.92.79 with HTTP; Wed, 16 Oct 2013 14:43:33 -0700 (PDT) In-Reply-To: <201310161650.52354.jhb@freebsd.org> References: <20130719.174511.786.3@DOMY-PC> <201310071212.05281.jhb@freebsd.org> <20131016.104912.479.1@DOMY-PC> <201310161650.52354.jhb@freebsd.org> Date: Wed, 16 Oct 2013 16:43:33 -0500 Message-ID: Subject: Re: UFS related panic (daily <-> find) From: Adam Vande More To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: rank1seeker@gmail.com, hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 21:43:34 -0000 On Wed, Oct 16, 2013 at 3:50 PM, John Baldwin wrote: > Same drill as before, see what instruction this is. Actually, this looks > to > be in the same location as your last panic, so a NULL pointer is 0x1 > instead > of 0x0 again. In my experience, this would still indicate failing RAM to > me, > memtest86+ notwithstanding (memtest86+ is single threaded AFAIK, so it may > not stress the hardware quite the same, e.g. if the error is heat related, > etc.). memtest* cannot conclusively diagnose a dimm as good. Usually the only practical solution is to swap modules with known good ones. -- Adam Vande More From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 17 01:45:52 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 07498B3F for ; Thu, 17 Oct 2013 01:45:52 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-qa0-x233.google.com (mail-qa0-x233.google.com [IPv6:2607:f8b0:400d:c00::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BB8FB28B8 for ; Thu, 17 Oct 2013 01:45:51 +0000 (UTC) Received: by mail-qa0-f51.google.com with SMTP id ii20so1237951qab.3 for ; Wed, 16 Oct 2013 18:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=BITJ/Ib0WnAbo6G6ud/BttdZxADg2TLAtMD/2F/zBQE=; b=tOaHxiOFlLmtJJ0ZuHRgc/NRf7r6jOU9H+jyo5Fku7I9PW2/lRT+mLYV055hl8lBAL M2xGEzXyRpQMhFGoa/YsqfzXKCN6Djf3hJ1C8FCXDqMdH3Vz9psLCHeJ5R0gsKLvoCqB TQQFV+dHXUvYAY2WBsANawS4ysiD2n1YiygHA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=BITJ/Ib0WnAbo6G6ud/BttdZxADg2TLAtMD/2F/zBQE=; b=lnWaNvzcQCJ8fOVl6O4LdAIoeTjVgQqUFx+lEL6p6Qfs6KcG9UTwjf41l+98GFpAwi XNlx9U1TgUrOS943IO/BXbEdFbYDvAtDmQdHcoXiTHRuEwRb3bIMWLz1tZRaWgnmwgsv cs4UvWy1z3kGEHVyP3jqydjbSBVQLZrgz1ZJqYsg27pHY8j6xgwg1DgmDFupJzvsXaWc fe8XracZ3zJdlk9z2qNJ1qybBgLrQyhA5ryjBxoGsZsWkoXp1HcfSl9SmUkX/t0tNG3s aPIDWjNwvXbfjeUsdoRBFVrfoXk7rOl824uRV9aeE3U2OcO65NFDsZLAOoa5Ds3t5Qy1 eeTA== X-Gm-Message-State: ALoCoQnej4YzyG+EZE4qUe7LKDvXrMWoM8L/WkC9XsntraTXR2RxagGtobZW6K56K4RO5P8hoabR X-Received: by 10.224.125.138 with SMTP id y10mr8667335qar.40.1381974350751; Wed, 16 Oct 2013 18:45:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.96.63.101 with HTTP; Wed, 16 Oct 2013 18:45:20 -0700 (PDT) In-Reply-To: <525D5A35.4040005@embedded-brains.de> References: <525D5A35.4040005@embedded-brains.de> From: Eitan Adler Date: Wed, 16 Oct 2013 21:45:20 -0400 Message-ID: Subject: Re: Global variables in system programs To: Sebastian Huber Content-Type: text/plain; charset=UTF-8 Cc: FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 01:45:52 -0000 On Tue, Oct 15, 2013 at 11:07 AM, Sebastian Huber wrote: > These programs use some global variables. In a statically linked context we > have now the following problems This is a pretty awesome idea. I've seen some work like this but it would be great to get FreeBSD into a state where this is easy. Are patches acceptable for the FreeBSD project that alter > system programs such that > o global variables are moved into context structures, Provided that the code remains readable I think these would be fine. > o constant global variables are declared as "const", and > o variables and functions are declared as "static" if possible? There has been a lot of work on this area. Your patch surprises me because I see many changes which were already done. We would absolutely be interested in such patches > Attached is a patch for the ROUTE(8) program to give an example. This patch can not apply for instance patchfile: 960 961 -char metricnames[] = 962 +static const char metricnames[] = 963 "\011weight\010rttvar\7rtt\6ssthresh\5sendpipe\4recvpipe\3expire" 964 "\1mtu"; but actual file: 1557 static const char metricnames[] = 1558 "\011weight\010rttvar\7rtt\6ssthresh\5sendpipe\4recvpipe\3expire" 1559 "\1mtu"; If you can generate patches against HEAD that would be great. I notice you use git: try to generate patches against https://github.com/freebsd/freebsd -- Eitan Adler From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 17 08:08:00 2013 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 9EC3CBE8 for ; Thu, 17 Oct 2013 08:08:00 +0000 (UTC) (envelope-from wjw@digiware.nl) Received: from smtp.digiware.nl (smtp.digiware.nl [31.223.170.169]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 5E6172B33 for ; Thu, 17 Oct 2013 08:07:59 +0000 (UTC) Received: from rack1.digiware.nl (unknown [127.0.0.1]) by smtp.digiware.nl (Postfix) with ESMTP id EC489153437; Thu, 17 Oct 2013 10:07:49 +0200 (CEST) X-Virus-Scanned: amavisd-new at digiware.nl Received: from smtp.digiware.nl ([127.0.0.1]) by rack1.digiware.nl (rack1.digiware.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sp8VSWRhx6VV; Thu, 17 Oct 2013 10:07:49 +0200 (CEST) Received: from [IPv6:2001:4cb8:3:1:fc47:7d66:923:bfe5] (unknown [IPv6:2001:4cb8:3:1:fc47:7d66:923:bfe5]) by smtp.digiware.nl (Postfix) with ESMTP id 511EC153434; Thu, 17 Oct 2013 10:07:49 +0200 (CEST) Message-ID: <525F9AD0.7070501@digiware.nl> Date: Thu, 17 Oct 2013 10:07:44 +0200 From: Willem Jan Withagen Organization: Digiware Management b.v. User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Rozhuk.IM@gmail.com, hackers@freebsd.org Subject: Re: amdtemp need help with testing References: <52520d5f.c402cd0a.5f4e.ffffffa2@mx.google.com> <52553F3F.9090707@digiware.nl> <5255478B.9090305@digiware.nl> <525f0076.c402cd0a.5f4e.7f67@mx.google.com> In-Reply-To: <525f0076.c402cd0a.5f4e.7f67@mx.google.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 08:08:00 -0000 On 2013-10-16 23:09, rozhuk.im@gmail.com wrote: > Thanks for the help with testing! > I fixed a bug, added HTC registers, changed the _ident() and the _probe(): > no binding processor Family. > The latest version here: http://netlab.linkpc.net/download/tmp/amdtemp.c I'm also testing bhyve on the same box, and for that I went back to 10-APLHA2. So I'll have to see how and if I can integrate and test this. But if I do, I'll get back to you. --WjW From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 17 09:09:21 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A259782E for ; Thu, 17 Oct 2013 09:09:21 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from mail.embedded-brains.de (host-82-135-62-35.customer.m-online.net [82.135.62.35]) by mx1.freebsd.org (Postfix) with ESMTP id 1B9DD2E6C for ; Thu, 17 Oct 2013 09:09:20 +0000 (UTC) Received: by mail.embedded-brains.de (Postfix, from userid 65534) id 35DA5652CFB; Thu, 17 Oct 2013 11:09:11 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on fidibusdmz X-Spam-Level: X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from [192.168.100.11] (unknown [192.168.100.11]) by mail.embedded-brains.de (Postfix) with ESMTP id 02E4765219E; Thu, 17 Oct 2013 11:09:08 +0200 (CEST) Message-ID: <525FA92E.40506@embedded-brains.de> Date: Thu, 17 Oct 2013 11:09:02 +0200 From: Sebastian Huber User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: Eitan Adler Subject: Re: Global variables in system programs References: <525D5A35.4040005@embedded-brains.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Cc: FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 09:09:21 -0000 On 2013-10-17 03:45, Eitan Adler wrote: > On Tue, Oct 15, 2013 at 11:07 AM, Sebastian Huber > wrote: > >> These programs use some global variables. In a statically linked context we >> have now the following problems > > This is a pretty awesome idea. I've seen some work like this but it > would be great to get FreeBSD into a state where this is easy. If it is acceptable for the FreeBSD project to turn e.g. ROUTE(8) and IFCONFIG(8) into library functions then this would be great. I can do the work. As noted in a different mail, currently no resource clean up is performed. Adding such code will make the program more complex. Another problem is the usage of exit(). I address this for our wrapper with something like this: /** * @defgroup ExitWrap Exit Wrap * * @brief Wrap the exit() function to support self-contained programs. * * @code * extern some_main(int argc, char **argv); * * int call_some_main(int argc, char **argv) * { * exit_wrap_control ewctrl; * int exit_code; * * if (exit_wrap_initialize(&ewctrl)) { * exit_code = some_main(argc, argv); * } else { * exit_code = exit_wrap_get_exit_code(&ewctrl); * } * * exit_wrap_destroy(&ewctrl); * * return exit_code; * } * @endcode * * @{ */ typedef struct { jmp_buf return_context; int exit_code; } exit_wrap_control; static inline bool exit_wrap_initialize( exit_wrap_control *self ) { self->exit_code = EXIT_FAILURE; return setjmp(self->return_context) == 0; } static inline void exit_wrap( exit_wrap_control *self, int exit_code ) { self->exit_code = exit_code; longjmp(self->return_context, 1); } static inline int exit_wrap_get_exit_code( const exit_wrap_control *self ) { return self->exit_code; } static inline void exit_wrap_destroy( exit_wrap_control *self ) { (void) self; } > > Are patches acceptable for the FreeBSD project that alter >> system programs such that > > >> o global variables are moved into context structures, > > Provided that the code remains readable I think these would be fine. > >> o constant global variables are declared as "const", and >> o variables and functions are declared as "static" if possible? > > There has been a lot of work on this area. Your patch surprises me > because I see many changes which were already done. We would > absolutely be interested in such patches Oh, sorry. This patch was generated against the FreeBSD 8.2 version. Yes, the current ROUTE(8) looks vastly different and the above two problems have been addressed. One minor problem: static const char *msgtypes[] = { "", "RTM_ADD: Add Route", [...] "RTM_IEEE80211: IEEE 802.11 wireless event", }; This should be probably: static const char *const msgtypes[] > >> Attached is a patch for the ROUTE(8) program to give an example. > > This patch can not apply for instance > > patchfile: > 960 > 961 -char metricnames[] = > 962 +static const char metricnames[] = > 963 "\011weight\010rttvar\7rtt\6ssthresh\5sendpipe\4recvpipe\3expire" > 964 "\1mtu"; > > but actual file: > > 1557 static const char metricnames[] = > 1558 "\011weight\010rttvar\7rtt\6ssthresh\5sendpipe\4recvpipe\3expire" > 1559 "\1mtu"; > > > If you can generate patches against HEAD that would be great. > > I notice you use git: try to generate patches against > https://github.com/freebsd/freebsd > > I use this Git repository, but currently I work with the FreeBSD 8.2 branch. The network stack port is a long running stuff for us. The goal is to first get the existing work unit tested and then move to the latest FreeBSD release. -- Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.huber@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG. From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 17 11:53:23 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id ED8531A2 for ; Thu, 17 Oct 2013 11:53:23 +0000 (UTC) (envelope-from bright@mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id C78DC28EE for ; Thu, 17 Oct 2013 11:53:23 +0000 (UTC) Received: from Alfreds-MacBook-Pro-9.local (c-76-21-10-192.hsd1.ca.comcast.net [76.21.10.192]) by elvis.mu.org (Postfix) with ESMTPSA id 037B61A3C19 for ; Thu, 17 Oct 2013 04:53:22 -0700 (PDT) Message-ID: <525FCFB7.2020703@mu.org> Date: Thu, 17 Oct 2013 04:53:27 -0700 From: Alfred Perlstein User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Subject: Re: Global variables in system programs References: <525D5A35.4040005@embedded-brains.de> <525FA92E.40506@embedded-brains.de> In-Reply-To: <525FA92E.40506@embedded-brains.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 11:53:24 -0000 On 10/17/13 2:09 AM, Sebastian Huber wrote: > On 2013-10-17 03:45, Eitan Adler wrote: >> On Tue, Oct 15, 2013 at 11:07 AM, Sebastian Huber >> wrote: >> >>> These programs use some global variables. In a statically linked >>> context we >>> have now the following problems >> >> This is a pretty awesome idea. I've seen some work like this but it >> would be great to get FreeBSD into a state where this is easy. > > If it is acceptable for the FreeBSD project to turn e.g. ROUTE(8) and > IFCONFIG(8) into library functions then this would be great. I can do > the work. > This looks really great. Please cc or send me direct mail as you progress. I would like to help see this make it into FreeBSD. I think one other place to continue this discussion is also "arch@freebsd.org". > As noted in a different mail, currently no resource clean up is > performed. Adding such code will make the program more complex. [[ removed use of setjmp to wrap exit() ]] hmm, I see, I'm not sure there's a way around this without extensively changing/refactoring the programs so it should be OK. At a certain point we will have to track and find leaked fds and memory too. Any ideas? > >> > > I use this Git repository, but currently I work with the FreeBSD 8.2 > branch. The network stack port is a long running stuff for us. The > goal is to first get the existing work unit tested and then move to > the latest FreeBSD release. > Is it on github? Thank you, -- Alfred Perlstein From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 17 13:38:40 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id EA066B12 for ; Thu, 17 Oct 2013 13:38:40 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from mail.embedded-brains.de (host-82-135-62-35.customer.m-online.net [82.135.62.35]) by mx1.freebsd.org (Postfix) with ESMTP id A1DBD2053 for ; Thu, 17 Oct 2013 13:38:40 +0000 (UTC) Received: by mail.embedded-brains.de (Postfix, from userid 65534) id 418AA652CFB; Thu, 17 Oct 2013 15:38:37 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on fidibusdmz X-Spam-Level: X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from [192.168.100.11] (unknown [192.168.100.11]) by mail.embedded-brains.de (Postfix) with ESMTP id 1787F65219E for ; Thu, 17 Oct 2013 15:38:36 +0200 (CEST) Message-ID: <525FE857.4020303@embedded-brains.de> Date: Thu, 17 Oct 2013 15:38:31 +0200 From: Sebastian Huber User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Subject: Re: Global variables in system programs References: <525D5A35.4040005@embedded-brains.de> In-Reply-To: <525D5A35.4040005@embedded-brains.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 13:38:41 -0000 Hello, there is another problem: getopt(). This function uses global variables on its own. Newlib provides a getopt_r() variant, but this seems to be not available on FreeBSD. -- Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.huber@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG. From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 17 13:44:55 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D75EE32C for ; Thu, 17 Oct 2013 13:44:55 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-ob0-x231.google.com (mail-ob0-x231.google.com [IPv6:2607:f8b0:4003:c01::231]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A136D20ED for ; Thu, 17 Oct 2013 13:44:55 +0000 (UTC) Received: by mail-ob0-f177.google.com with SMTP id wm4so1842657obc.36 for ; Thu, 17 Oct 2013 06:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=zURyurxIdXAzZUBT44EOapBaS8Sg93X4VxL4zsCpNSM=; b=oYzw9TJtaUZXZYcOuxkse5/a+3bnKcP6n3HJK+95K1QiOXCwCnTNglkAxzGn3mY+ie T6AZmArehzHJDdmzcR2zYZD+l5ngcuwWGVtmhCdSkkAhQM3AT8MEHaF47F7LFdC3Fayq qxVT/CR/f4EKR/hcg20qzd0aJCVDvM2Pz07q34fn17aH7M0+GfE1Tpxxc1wXXUNgDsHt zQ/lCSRy71RHwU5q7VbGtP9/KnOHZLgjTkB8Sl5d0bo0Y08swhO4ymnxPg4PEw+B0BKh sXtGIGG1Vk02w6jIRPppYnIS6jTL88uiUI7rXvCHWu3IPHPsfUsxsLW4Oc+vjjrgnFdy AqvQ== MIME-Version: 1.0 X-Received: by 10.182.101.198 with SMTP id fi6mr281260obb.79.1382017493956; Thu, 17 Oct 2013 06:44:53 -0700 (PDT) Sender: mdf356@gmail.com Received: by 10.182.110.195 with HTTP; Thu, 17 Oct 2013 06:44:53 -0700 (PDT) In-Reply-To: <525FA92E.40506@embedded-brains.de> References: <525D5A35.4040005@embedded-brains.de> <525FA92E.40506@embedded-brains.de> Date: Thu, 17 Oct 2013 06:44:53 -0700 X-Google-Sender-Auth: Zy8bjMA6dQb59Nn53ooBlINxVzc Message-ID: Subject: Re: Global variables in system programs From: Matthew Fleming To: Sebastian Huber Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: Eitan Adler , FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 13:44:56 -0000 On Thu, Oct 17, 2013 at 2:09 AM, Sebastian Huber < sebastian.huber@embedded-brains.de> wrote: > On 2013-10-17 03:45, Eitan Adler wrote: > >> On Tue, Oct 15, 2013 at 11:07 AM, Sebastian Huber >> > >> wrote: >> >> These programs use some global variables. In a statically linked >>> context we >>> have now the following problems >>> >> >> This is a pretty awesome idea. I've seen some work like this but it >> would be great to get FreeBSD into a state where this is easy. >> > > If it is acceptable for the FreeBSD project to turn e.g. ROUTE(8) and > IFCONFIG(8) into library functions then this would be great. I can do the > work. At a meta level, IMO *most* of the functionality in binaries should be in libraries. How many times writing a C unit test have I wanted to do rm -rf of the temporary files I created? But the recursive remove is in rm(1) not in libutil. And it sounds like the functionality in route/ifconfig is now desired to be accessed programatically, not just from a shell script. So +1 for moving code into a library where it can be re-used. Cheers, matthew From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 17 14:07:03 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 3783B560 for ; Thu, 17 Oct 2013 14:07:03 +0000 (UTC) (envelope-from bright@mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 25F302309 for ; Thu, 17 Oct 2013 14:07:03 +0000 (UTC) Received: from Alfreds-MacBook-Pro-9.local (c-76-21-10-192.hsd1.ca.comcast.net [76.21.10.192]) by elvis.mu.org (Postfix) with ESMTPSA id 59E0F1A3C3E for ; Thu, 17 Oct 2013 07:07:01 -0700 (PDT) Message-ID: <525FEF09.6010507@mu.org> Date: Thu, 17 Oct 2013 07:07:05 -0700 From: Alfred Perlstein User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Subject: Re: Global variables in system programs References: <525D5A35.4040005@embedded-brains.de> <525FE857.4020303@embedded-brains.de> In-Reply-To: <525FE857.4020303@embedded-brains.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 14:07:03 -0000 On 10/17/13 6:38 AM, Sebastian Huber wrote: > Hello, > > there is another problem: getopt(). This function uses global > variables on its own. Newlib provides a getopt_r() variant, but this > seems to be not available on FreeBSD. > Can it be ported to FreeBSD? Maybe under another name and put into libutil to avoid standards issues? -- Alfred Perlstein From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 17 14:09:52 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B43068AA for ; Thu, 17 Oct 2013 14:09:52 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-qc0-x22d.google.com (mail-qc0-x22d.google.com [IPv6:2607:f8b0:400d:c01::22d]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7314F2344 for ; Thu, 17 Oct 2013 14:09:52 +0000 (UTC) Received: by mail-qc0-f173.google.com with SMTP id l13so1572936qcy.18 for ; Thu, 17 Oct 2013 07:09:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=eZ1cPb6+4xGtKBa0V3TZpZRcITz7fPbBvqfpXw9Psj0=; b=YcBZCXHpKMKkTRExYOLlRqGjDhvQ7ObOuDCykI/jYJgfDMHusE6VERslgnzOR7GVcW 9AdcSrEtKLWovzuICvGWv+Gh9WVTpSSBhi/CNWmtRB/OMBHa4OzKzO+RbuXV+g3NTyAf oXUbRlRgqDAgXeFXNZdLbqgzxi9nb9fubPxKM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=eZ1cPb6+4xGtKBa0V3TZpZRcITz7fPbBvqfpXw9Psj0=; b=ftoBRBX/V4/PHqRT7XrtPfjB0KZbrCnK3tkIGwU35lVCXcPiZNvw+UuQ7mlb8/hChp H5p5jsq96sMnGmRXp1ILP9m8/wnl92I4VucTalOzZAgIyMhe6TszKAa+8PuXDdouD+AN oVD9OotojVGgcXcfOfupdhriTZdVWZACtY9mp67DreNqupBiOhqVA8AMyKLr+sc6IftF J7dcXcjXmcRGbRnuFMlfj9Q6M+Hl2aZDQnUddgMZwCGUFHIQ/bCK25QVt2Xl24jyIRhy md+Vq4fJU+A1d9X+Pahm3CT2D2xEgZZu7GDSLsvAT4uLT1AY/1/sCDqHLhp473zou5sQ ncxw== X-Gm-Message-State: ALoCoQnSvqwre3wtZv8agaWIrKG2T1fDGaKCzY9NBnWweOhBu2Nr4hfrcM7iMtgbQErsJJ9C3h/C X-Received: by 10.49.96.42 with SMTP id dp10mr2763212qeb.94.1382018991423; Thu, 17 Oct 2013 07:09:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.96.63.101 with HTTP; Thu, 17 Oct 2013 07:09:21 -0700 (PDT) In-Reply-To: <525FE857.4020303@embedded-brains.de> References: <525D5A35.4040005@embedded-brains.de> <525FE857.4020303@embedded-brains.de> From: Eitan Adler Date: Thu, 17 Oct 2013 10:09:21 -0400 Message-ID: Subject: Re: Global variables in system programs To: Sebastian Huber Content-Type: text/plain; charset=UTF-8 Cc: FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 14:09:52 -0000 On Thu, Oct 17, 2013 at 9:38 AM, Sebastian Huber wrote: > Hello, > > there is another problem: getopt(). This function uses global variables on > its own. Newlib provides a getopt_r() variant, but this seems to be not > available on FreeBSD. It shouldn't be hard to port this to FreeBSD (it just requires that the global variables be passed in as pointers-to-values). Please do so! -- Eitan Adler From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 17 15:31:53 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 3F3DFD1C for ; Thu, 17 Oct 2013 15:31:53 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from mail.embedded-brains.de (host-82-135-62-35.customer.m-online.net [82.135.62.35]) by mx1.freebsd.org (Postfix) with ESMTP id 109A72A99 for ; Thu, 17 Oct 2013 15:31:51 +0000 (UTC) Received: by mail.embedded-brains.de (Postfix, from userid 65534) id 7B460652CFB; Thu, 17 Oct 2013 17:31:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on fidibusdmz X-Spam-Level: X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from [192.168.100.11] (unknown [192.168.100.11]) by mail.embedded-brains.de (Postfix) with ESMTP id B1DA265219E for ; Thu, 17 Oct 2013 17:31:46 +0200 (CEST) Message-ID: <526002DD.6050704@embedded-brains.de> Date: Thu, 17 Oct 2013 17:31:41 +0200 From: Sebastian Huber User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Subject: Re: Global variables in system programs References: <525D5A35.4040005@embedded-brains.de> In-Reply-To: <525D5A35.4040005@embedded-brains.de> Content-Type: multipart/mixed; boundary="------------060103010809050906000908" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 15:31:53 -0000 This is a multi-part message in MIME format. --------------060103010809050906000908 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Hello, here is an updated patch set that introduces the context structure (struct rt_ctx) which contains all global data used by ROUTE(8) directly. Its just to give an idea how this may look like. The patch set is against the current development version of FreeBSD (commit 000c45f54a05a448b302309b63ffb95e1c98856d). Remaining issues are o resource leaks, o usage of exit() (also indirectly via the warn and error functions), o getopt(). If I use the wrong mailing list, then please let me know. -- Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.huber@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG. --------------060103010809050906000908 Content-Type: text/x-patch; name="0001-route-Change-into-local-variable.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-route-Change-into-local-variable.patch" >From 9158cfdd37194d55e44688c03361b1c0b8a41b5d Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 17 Oct 2013 16:09:58 +0200 Subject: [PATCH 01/10] route: Change into local variable --- sbin/route/route.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index 6c2bbe2..78b1d87 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -496,7 +496,8 @@ routename(struct sockaddr *sa) const char *cp; static char line[NI_MAXHOST]; static char domain[MAXHOSTNAMELEN + 1]; - static int first = 1, n; + static int first = 1; + int n; if (first) { first = 0; -- 1.7.7 --------------060103010809050906000908 Content-Type: text/x-patch; name="0002-route-Avoid-static-buffer-in-atalk_ntoa.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0002-route-Avoid-static-buffer-in-atalk_ntoa.patch" >From 62fc2134a28fc62efa12e2369ee1e263b6340951 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 17 Oct 2013 16:22:53 +0200 Subject: [PATCH 02/10] route: Avoid static buffer in atalk_ntoa() --- sbin/route/route.c | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index 78b1d87..ad1fcfe 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -91,7 +91,7 @@ static int defaultfib; static int numfibs; static int atalk_aton(const char *, struct at_addr *); -static char *atalk_ntoa(struct at_addr); +static char *atalk_ntoa(struct at_addr, char [20]); static void printb(int, const char *); static void flushroutes(int argc, char *argv[]); static int flushroutes_fib(int); @@ -494,6 +494,7 @@ routename(struct sockaddr *sa) { struct sockaddr_dl *sdl; const char *cp; + char atalk_buf[20]; static char line[NI_MAXHOST]; static char domain[MAXHOSTNAMELEN + 1]; static int first = 1; @@ -576,7 +577,8 @@ routename(struct sockaddr *sa) #endif case AF_APPLETALK: (void)snprintf(line, sizeof(line), "atalk %s", - atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr)); + atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr, + atalk_buf)); break; case AF_LINK: @@ -621,6 +623,7 @@ netname(struct sockaddr *sa) { struct sockaddr_dl *sdl; static char line[MAXHOSTNAMELEN + 1]; + char atalk_buf[20]; int n; #ifdef INET struct netent *np = NULL; @@ -684,7 +687,8 @@ netname(struct sockaddr *sa) case AF_APPLETALK: (void)snprintf(line, sizeof(line), "atalk %s", - atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr)); + atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr, + atalk_buf)); break; case AF_LINK: @@ -1838,6 +1842,7 @@ keyword(const char *cp) static void sodump(struct sockaddr *sa, const char *which) { + char atalk_buf[20]; #ifdef INET6 char nbuf[INET6_ADDRSTRLEN]; #endif @@ -1862,7 +1867,8 @@ sodump(struct sockaddr *sa, const char *which) #endif case AF_APPLETALK: (void)printf("%s: atalk %s; ", which, - atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr)); + atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr, + atalk_buf)); break; } (void)fflush(stdout); @@ -1932,10 +1938,8 @@ atalk_aton(const char *text, struct at_addr *addr) } static char * -atalk_ntoa(struct at_addr at) +atalk_ntoa(struct at_addr at, char buf[20]) { - static char buf[20]; - (void)snprintf(buf, sizeof(buf), "%u.%u", ntohs(at.s_net), at.s_node); buf[sizeof(buf) - 1] = '\0'; return(buf); -- 1.7.7 --------------060103010809050906000908 Content-Type: text/x-patch; name="0003-route-Add-const-qualifier.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0003-route-Add-const-qualifier.patch" >From 332d7da2c8967c8c927582c92c081b5b1ba61349 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 17 Oct 2013 16:23:37 +0200 Subject: [PATCH 03/10] route: Add const qualifier --- sbin/route/route.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index ad1fcfe..3cf16a0 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1542,7 +1542,7 @@ rtmsg(int cmd, int flags, int fib) return (0); } -static const char *msgtypes[] = { +static const char *const msgtypes[] = { "", "RTM_ADD: Add Route", "RTM_DELETE: Delete Route", -- 1.7.7 --------------060103010809050906000908 Content-Type: text/x-patch; name="0004-route-Move-domain-buffer-to-function-scope.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0004-route-Move-domain-buffer-to-function-scope.patch" >From 6f0e7adb2cc000634d15edbfdf9fd6887f6c2c0a Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 17 Oct 2013 16:26:48 +0200 Subject: [PATCH 04/10] route: Move domain buffer to function scope --- sbin/route/route.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index 3cf16a0..eaf5e39 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -89,6 +89,8 @@ static u_long rtm_inits; static uid_t uid; static int defaultfib; static int numfibs; +static char domain[MAXHOSTNAMELEN + 1]; +static int domain_initialized; static int atalk_aton(const char *, struct at_addr *); static char *atalk_ntoa(struct at_addr, char [20]); @@ -496,12 +498,10 @@ routename(struct sockaddr *sa) const char *cp; char atalk_buf[20]; static char line[NI_MAXHOST]; - static char domain[MAXHOSTNAMELEN + 1]; - static int first = 1; int n; - if (first) { - first = 0; + if (domain_initialized) { + domain_initialized = 1; if (gethostname(domain, MAXHOSTNAMELEN) == 0 && (cp = strchr(domain, '.'))) { domain[MAXHOSTNAMELEN] = '\0'; -- 1.7.7 --------------060103010809050906000908 Content-Type: text/x-patch; name="0005-route-Move-route-message-seq-to-function-scope.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0005-route-Move-route-message-seq-to-function-scope.patch" >From 728732ceff07847b1935471cfc5fa31ad93a9d94 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 17 Oct 2013 16:31:42 +0200 Subject: [PATCH 05/10] route: Move route message seq to function scope --- sbin/route/route.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index eaf5e39..657fee4 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -91,6 +91,7 @@ static int defaultfib; static int numfibs; static char domain[MAXHOSTNAMELEN + 1]; static int domain_initialized; +static int rtm_seq; static int atalk_aton(const char *, struct at_addr *); static char *atalk_ntoa(struct at_addr, char [20]); @@ -1471,7 +1472,6 @@ static struct { static int rtmsg(int cmd, int flags, int fib) { - static int seq; int rlen; char *cp = m_rtmsg.m_space; int l; @@ -1507,7 +1507,7 @@ rtmsg(int cmd, int flags, int fib) rtm.rtm_type = cmd; rtm.rtm_flags = flags; rtm.rtm_version = RTM_VERSION; - rtm.rtm_seq = ++seq; + rtm.rtm_seq = ++rtm_seq; rtm.rtm_addrs = rtm_addrs; rtm.rtm_rmx = rt_metrics; rtm.rtm_inits = rtm_inits; @@ -1532,7 +1532,7 @@ rtmsg(int cmd, int flags, int fib) if (cmd == RTM_GET) { do { l = read(s, (char *)&m_rtmsg, sizeof(m_rtmsg)); - } while (l > 0 && (rtm.rtm_seq != seq || rtm.rtm_pid != pid)); + } while (l > 0 && (rtm.rtm_seq != rtm_seq || rtm.rtm_pid != pid)); if (l < 0) warn("read from routing socket"); else -- 1.7.7 --------------060103010809050906000908 Content-Type: text/x-patch; name="0006-route-Move-route-name-line-to-function-scope.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0006-route-Move-route-name-line-to-function-scope.patch" >From 0e2ebe1f19526c8efce37bbb7d17e3714b100ce1 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 17 Oct 2013 16:35:28 +0200 Subject: [PATCH 06/10] route: Move route name line to function scope --- sbin/route/route.c | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index 657fee4..f63d09f 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -92,6 +92,7 @@ static int numfibs; static char domain[MAXHOSTNAMELEN + 1]; static int domain_initialized; static int rtm_seq; +static char rt_line[NI_MAXHOST]; static int atalk_aton(const char *, struct at_addr *); static char *atalk_ntoa(struct at_addr, char [20]); @@ -498,7 +499,6 @@ routename(struct sockaddr *sa) struct sockaddr_dl *sdl; const char *cp; char atalk_buf[20]; - static char line[NI_MAXHOST]; int n; if (domain_initialized) { @@ -560,24 +560,24 @@ routename(struct sockaddr *sa) else if (sa->sa_family == AF_INET6) ss.ss_len = sizeof(struct sockaddr_in6); error = getnameinfo((struct sockaddr *)&ss, ss.ss_len, - line, sizeof(line), NULL, 0, + rt_line, sizeof(rt_line), NULL, 0, (nflag == 0) ? 0 : NI_NUMERICHOST); if (error) { warnx("getnameinfo(): %s", gai_strerror(error)); - strncpy(line, "invalid", sizeof(line)); + strncpy(rt_line, "invalid", sizeof(rt_line)); } /* Remove the domain part if any. */ - p = strchr(line, '.'); + p = strchr(rt_line, '.'); if (p != NULL && strcmp(p + 1, domain) == 0) *p = '\0'; - return (line); + return (rt_line); break; } #endif case AF_APPLETALK: - (void)snprintf(line, sizeof(line), "atalk %s", + (void)snprintf(rt_line, sizeof(rt_line), "atalk %s", atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr, atalk_buf)); break; @@ -588,11 +588,11 @@ routename(struct sockaddr *sa) if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) { - n = snprintf(line, sizeof(line), "link#%d", + n = snprintf(rt_line, sizeof(rt_line), "link#%d", sdl->sdl_index); - if (n > (int)sizeof(line)) - line[0] = '\0'; - return (line); + if (n > (int)sizeof(rt_line)) + rt_line[0] = '\0'; + return (rt_line); } else return (link_ntoa(sdl)); break; @@ -601,8 +601,8 @@ routename(struct sockaddr *sa) { u_short *sp = (u_short *)(void *)sa; u_short *splim = sp + ((sa->sa_len + 1) >> 1); - char *cps = line + sprintf(line, "(%d)", sa->sa_family); - char *cpe = line + sizeof(line); + char *cps = rt_line + sprintf(rt_line, "(%d)", sa->sa_family); + char *cpe = rt_line + sizeof(rt_line); while (++sp < splim && cps < cpe) /* start with sa->sa_data */ if ((n = snprintf(cps, cpe - cps, " %x", *sp)) > 0) @@ -612,7 +612,7 @@ routename(struct sockaddr *sa) break; } } - return (line); + return (rt_line); } /* -- 1.7.7 --------------060103010809050906000908 Content-Type: text/x-patch; name="0007-route-Move-net-name-line-to-function-scope.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0007-route-Move-net-name-line-to-function-scope.patch" >From 277edbe68aa36700d54d0f99bf669e2f37084b8b Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 17 Oct 2013 16:35:49 +0200 Subject: [PATCH 07/10] route: Move net name line to function scope --- sbin/route/route.c | 34 +++++++++++++++++----------------- 1 files changed, 17 insertions(+), 17 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index f63d09f..e80d610 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -93,6 +93,7 @@ static char domain[MAXHOSTNAMELEN + 1]; static int domain_initialized; static int rtm_seq; static char rt_line[NI_MAXHOST]; +static char net_line[MAXHOSTNAMELEN + 1]; static int atalk_aton(const char *, struct at_addr *); static char *atalk_ntoa(struct at_addr, char [20]); @@ -623,7 +624,6 @@ static const char * netname(struct sockaddr *sa) { struct sockaddr_dl *sdl; - static char line[MAXHOSTNAMELEN + 1]; char atalk_buf[20]; int n; #ifdef INET @@ -649,17 +649,17 @@ netname(struct sockaddr *sa) } #define C(x) (unsigned)((x) & 0xff) if (cp != NULL) - strncpy(line, cp, sizeof(line)); + strncpy(net_line, cp, sizeof(net_line)); else if ((in.s_addr & 0xffffff) == 0) - (void)sprintf(line, "%u", C(in.s_addr >> 24)); + (void)sprintf(net_line, "%u", C(in.s_addr >> 24)); else if ((in.s_addr & 0xffff) == 0) - (void)sprintf(line, "%u.%u", C(in.s_addr >> 24), + (void)sprintf(net_line, "%u.%u", C(in.s_addr >> 24), C(in.s_addr >> 16)); else if ((in.s_addr & 0xff) == 0) - (void)sprintf(line, "%u.%u.%u", C(in.s_addr >> 24), + (void)sprintf(net_line, "%u.%u.%u", C(in.s_addr >> 24), C(in.s_addr >> 16), C(in.s_addr >> 8)); else - (void)sprintf(line, "%u.%u.%u.%u", C(in.s_addr >> 24), + (void)sprintf(net_line, "%u.%u.%u.%u", C(in.s_addr >> 24), C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr)); #undef C @@ -679,15 +679,15 @@ netname(struct sockaddr *sa) if (nflag) niflags |= NI_NUMERICHOST; if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, - line, sizeof(line), NULL, 0, niflags) != 0) - strncpy(line, "invalid", sizeof(line)); + net_line, sizeof(net_line), NULL, 0, niflags) != 0) + strncpy(net_line, "invalid", sizeof(net_line)); - return(line); + return(net_line); } #endif case AF_APPLETALK: - (void)snprintf(line, sizeof(line), "atalk %s", + (void)snprintf(net_line, sizeof(net_line), "atalk %s", atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr, atalk_buf)); break; @@ -698,11 +698,11 @@ netname(struct sockaddr *sa) if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) { - n = snprintf(line, sizeof(line), "link#%d", + n = snprintf(net_line, sizeof(net_line), "link#%d", sdl->sdl_index); - if (n > (int)sizeof(line)) - line[0] = '\0'; - return (line); + if (n > (int)sizeof(net_line)) + net_line[0] = '\0'; + return (net_line); } else return (link_ntoa(sdl)); break; @@ -711,8 +711,8 @@ netname(struct sockaddr *sa) { u_short *sp = (u_short *)(void *)sa->sa_data; u_short *splim = sp + ((sa->sa_len + 1)>>1); - char *cps = line + sprintf(line, "af %d:", sa->sa_family); - char *cpe = line + sizeof(line); + char *cps = net_line + sprintf(net_line, "af %d:", sa->sa_family); + char *cpe = net_line + sizeof(net_line); while (sp < splim && cps < cpe) if ((n = snprintf(cps, cpe - cps, " %x", *sp++)) > 0) @@ -722,7 +722,7 @@ netname(struct sockaddr *sa) break; } } - return (line); + return (net_line); } static void -- 1.7.7 --------------060103010809050906000908 Content-Type: text/x-patch; name="0008-route-Move-static-data-to-top-of-file.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0008-route-Move-static-data-to-top-of-file.patch" >From 3da91486ee83138fa0a9d63cc7c75ce1bc824b0b Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 17 Oct 2013 16:39:28 +0200 Subject: [PATCH 08/10] route: Move static data to top of file --- sbin/route/route.c | 30 +++++++++++++++--------------- 1 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index e80d610..2c040aa 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -70,6 +70,14 @@ __FBSDID("$FreeBSD$"); #include #include +struct fibl { + TAILQ_ENTRY(fibl) fl_next; + + int fl_num; + int fl_error; + int fl_errno; +}; + static struct keytab { const char *kt_cp; int kt_i; @@ -95,6 +103,13 @@ static int rtm_seq; static char rt_line[NI_MAXHOST]; static char net_line[MAXHOSTNAMELEN + 1]; +static struct { + struct rt_msghdr m_rtm; + char m_space[512]; +} m_rtmsg; + +static TAILQ_HEAD(fibl_head_t, fibl) fibl_head; + static int atalk_aton(const char *, struct at_addr *); static char *atalk_ntoa(struct at_addr, char [20]); static void printb(int, const char *); @@ -125,16 +140,6 @@ static void set_metric(char *, int); static int set_sofib(int); static void sockaddr(char *, struct sockaddr *, size_t); static void sodump(struct sockaddr *, const char *); - -struct fibl { - TAILQ_ENTRY(fibl) fl_next; - - int fl_num; - int fl_error; - int fl_errno; -}; -static TAILQ_HEAD(fibl_head_t, fibl) fibl_head; - static int fiboptlist_csv(const char *, struct fibl_head_t *); static int fiboptlist_range(const char *, struct fibl_head_t *); @@ -1464,11 +1469,6 @@ monitor(int argc, char *argv[]) } } -static struct { - struct rt_msghdr m_rtm; - char m_space[512]; -} m_rtmsg; - static int rtmsg(int cmd, int flags, int fib) { -- 1.7.7 --------------060103010809050906000908 Content-Type: text/x-patch; name="0009-route-Add-const-qualifier.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0009-route-Add-const-qualifier.patch" >From a173c00f8f7980fd5b91ed394aaa2cb1e20d1ab2 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 17 Oct 2013 16:40:13 +0200 Subject: [PATCH 09/10] route: Add const qualifier --- sbin/route/route.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index 2c040aa..110f72a 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -81,7 +81,7 @@ struct fibl { static struct keytab { const char *kt_cp; int kt_i; -} keywords[] = { +} const keywords[] = { #include "keywords.h" {0, 0} }; @@ -1832,7 +1832,7 @@ printb(int b, const char *str) int keyword(const char *cp) { - struct keytab *kt = keywords; + const struct keytab *kt = keywords; while (kt->kt_cp != NULL && strcmp(kt->kt_cp, cp) != 0) kt++; -- 1.7.7 --------------060103010809050906000908 Content-Type: text/x-patch; name="0010-route-Collect-static-data-into-new-struct-rt_ctx.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0010-route-Collect-static-data-into-new-struct-rt_ctx.patch" >From 004a6d35e64e58052c46e72595e8f9fac031a6d0 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 17 Oct 2013 16:53:30 +0200 Subject: [PATCH 10/10] route: Collect static data into new struct rt_ctx --- sbin/route/route.c | 567 ++++++++++++++++++++++++++-------------------------- 1 files changed, 286 insertions(+), 281 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index 110f72a..45f9205 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -86,36 +86,38 @@ static struct keytab { {0, 0} }; -static struct sockaddr_storage so[RTAX_MAX]; -static int pid, rtm_addrs; -static int s; -static int forcehost, forcenet, nflag, af, qflag, tflag; -static int verbose, aflen; -static int locking, lockrest, debugonly; -static struct rt_metrics rt_metrics; -static u_long rtm_inits; -static uid_t uid; -static int defaultfib; -static int numfibs; -static char domain[MAXHOSTNAMELEN + 1]; -static int domain_initialized; -static int rtm_seq; -static char rt_line[NI_MAXHOST]; -static char net_line[MAXHOSTNAMELEN + 1]; +static struct rt_ctx { + struct sockaddr_storage so[RTAX_MAX]; + int pid, rtm_addrs; + int s; + int forcehost, forcenet, nflag, af, qflag, tflag; + int verbose, aflen; + int locking, lockrest, debugonly; + struct rt_metrics rt_metrics; + u_long rtm_inits; + uid_t uid; + int defaultfib; + int numfibs; + char domain[MAXHOSTNAMELEN + 1]; + int domain_initialized; + int rtm_seq; + char rt_line[NI_MAXHOST]; + char net_line[MAXHOSTNAMELEN + 1]; -static struct { - struct rt_msghdr m_rtm; - char m_space[512]; -} m_rtmsg; + struct { + struct rt_msghdr m_rtm; + char m_space[512]; + } m_rtmsg; -static TAILQ_HEAD(fibl_head_t, fibl) fibl_head; + TAILQ_HEAD(fibl_head_t, fibl) fibl_head; +} rt_ctx; static int atalk_aton(const char *, struct at_addr *); static char *atalk_ntoa(struct at_addr, char [20]); static void printb(int, const char *); -static void flushroutes(int argc, char *argv[]); -static int flushroutes_fib(int); -static int getaddr(int, char *, struct hostent **, int); +static void flushroutes(struct rt_ctx *, int argc, char *argv[]); +static int flushroutes_fib(struct rt_ctx *, int); +static int getaddr(struct rt_ctx *, int, char *, struct hostent **, int); static int keyword(const char *); #ifdef INET static void inet_makenetandmask(u_long, struct sockaddr_in *, @@ -124,24 +126,26 @@ static void inet_makenetandmask(u_long, struct sockaddr_in *, #ifdef INET6 static int inet6_makenetandmask(struct sockaddr_in6 *, const char *); #endif -static void interfaces(void); -static void monitor(int, char*[]); -static const char *netname(struct sockaddr *); -static void newroute(int, char **); -static int newroute_fib(int, char *, int); -static void pmsg_addrs(char *, int, size_t); -static void pmsg_common(struct rt_msghdr *, size_t); -static int prefixlen(const char *); -static void print_getmsg(struct rt_msghdr *, int, int); -static void print_rtmsg(struct rt_msghdr *, size_t); -static const char *routename(struct sockaddr *); -static int rtmsg(int, int, int); -static void set_metric(char *, int); -static int set_sofib(int); +static void interfaces(struct rt_ctx * ); +static void monitor(struct rt_ctx *, int, char*[]); +static const char *netname(struct rt_ctx *, struct sockaddr *); +static void newroute(struct rt_ctx *, int, char **); +static int newroute_fib(struct rt_ctx *, int, char *, int); +static void pmsg_addrs(struct rt_ctx *, char *, int, size_t); +static void pmsg_common(struct rt_ctx *, struct rt_msghdr *, size_t); +static int prefixlen(struct rt_ctx *, const char *); +static void print_getmsg(struct rt_ctx *, struct rt_msghdr *, int, int); +static void print_rtmsg(struct rt_ctx *, struct rt_msghdr *, size_t); +static const char *routename(struct rt_ctx *, struct sockaddr *); +static int rtmsg(struct rt_ctx *, int, int, int); +static void set_metric(struct rt_ctx *, char *, int); +static int set_sofib(struct rt_ctx *, int); static void sockaddr(char *, struct sockaddr *, size_t); static void sodump(struct sockaddr *, const char *); -static int fiboptlist_csv(const char *, struct fibl_head_t *); -static int fiboptlist_range(const char *, struct fibl_head_t *); +static int fiboptlist_csv(struct rt_ctx *, const char *, + struct fibl_head_t *); +static int fiboptlist_range(struct rt_ctx *, const char *, + struct fibl_head_t *); static void usage(const char *) __dead2; @@ -157,6 +161,7 @@ usage(const char *cp) int main(int argc, char **argv) { + struct rt_ctx *c = &rt_ctx; int ch; size_t len; @@ -166,19 +171,19 @@ main(int argc, char **argv) while ((ch = getopt(argc, argv, "nqdtv")) != -1) switch(ch) { case 'n': - nflag = 1; + c->nflag = 1; break; case 'q': - qflag = 1; + c->qflag = 1; break; case 'v': - verbose = 1; + c->verbose = 1; break; case 't': - tflag = 1; + c->tflag = 1; break; case 'd': - debugonly = 1; + c->debugonly = 1; break; case '?': default: @@ -187,45 +192,45 @@ main(int argc, char **argv) argc -= optind; argv += optind; - pid = getpid(); - uid = geteuid(); - if (tflag) - s = open(_PATH_DEVNULL, O_WRONLY, 0); + c->pid = getpid(); + c->uid = geteuid(); + if (c->tflag) + c->s = open(_PATH_DEVNULL, O_WRONLY, 0); else - s = socket(PF_ROUTE, SOCK_RAW, 0); - if (s < 0) + c->s = socket(PF_ROUTE, SOCK_RAW, 0); + if (c->s < 0) err(EX_OSERR, "socket"); - len = sizeof(numfibs); - if (sysctlbyname("net.fibs", (void *)&numfibs, &len, NULL, 0) == -1) - numfibs = -1; + len = sizeof(c->numfibs); + if (sysctlbyname("net.fibs", (void *)&c->numfibs, &len, NULL, 0) == -1) + c->numfibs = -1; - len = sizeof(defaultfib); - if (numfibs != -1 && - sysctlbyname("net.my_fibnum", (void *)&defaultfib, &len, NULL, + len = sizeof(c->defaultfib); + if (c->numfibs != -1 && + sysctlbyname("net.my_fibnum", (void *)&c->defaultfib, &len, NULL, 0) == -1) - defaultfib = -1; + c->defaultfib = -1; if (*argv != NULL) switch (keyword(*argv)) { case K_GET: case K_SHOW: - uid = 0; + c->uid = 0; /* FALLTHROUGH */ case K_CHANGE: case K_ADD: case K_DEL: case K_DELETE: - newroute(argc, argv); + newroute(c, argc, argv); /* NOTREACHED */ case K_MONITOR: - monitor(argc, argv); + monitor(c, argc, argv); /* NOTREACHED */ case K_FLUSH: - flushroutes(argc, argv); + flushroutes(c, argc, argv); exit(0); /* NOTREACHED */ } @@ -234,17 +239,17 @@ main(int argc, char **argv) } static int -set_sofib(int fib) +set_sofib(struct rt_ctx *c, int fib) { if (fib < 0) return (0); - return (setsockopt(s, SOL_SOCKET, SO_SETFIB, (void *)&fib, + return (setsockopt(c->s, SOL_SOCKET, SO_SETFIB, (void *)&fib, sizeof(fib))); } static int -fiboptlist_range(const char *arg, struct fibl_head_t *flh) +fiboptlist_range(struct rt_ctx *c, const char *arg, struct fibl_head_t *flh) { struct fibl *fl; char *str0, *str, *token, *endptr; @@ -262,7 +267,7 @@ fiboptlist_range(const char *arg, struct fibl_head_t *flh) if (errno == 0) { if (*endptr != '\0' || fib[i] < 0 || - (numfibs != -1 && fib[i] > numfibs - 1)) + (c->numfibs != -1 && fib[i] > c->numfibs - 1)) errno = EINVAL; } if (errno) @@ -295,7 +300,7 @@ fiboptlist_range_ret: #define ALLSTRLEN 64 static int -fiboptlist_csv(const char *arg, struct fibl_head_t *flh) +fiboptlist_csv(struct rt_ctx *c, const char *arg, struct fibl_head_t *flh) { struct fibl *fl; char *str0, *str, *token, *endptr; @@ -308,8 +313,8 @@ fiboptlist_csv(const char *arg, struct fibl_head_t *flh) error = 1; goto fiboptlist_csv_ret; } - if (numfibs > 1) - snprintf(str, ALLSTRLEN - 1, "%d-%d", 0, numfibs - 1); + if (c->numfibs > 1) + snprintf(str, ALLSTRLEN - 1, "%d-%d", 0, c->numfibs - 1); else snprintf(str, ALLSTRLEN - 1, "%d", 0); } else if (strcmp("default", arg) == 0) { @@ -318,14 +323,14 @@ fiboptlist_csv(const char *arg, struct fibl_head_t *flh) error = 1; goto fiboptlist_csv_ret; } - snprintf(str, ALLSTRLEN - 1, "%d", defaultfib); + snprintf(str, ALLSTRLEN - 1, "%d", c->defaultfib); } else str0 = str = strdup(arg); error = 0; while ((token = strsep(&str, ",")) != NULL) { if (*token != '-' && strchr(token, '-') != NULL) { - error = fiboptlist_range(token, flh); + error = fiboptlist_range(c, token, flh); if (error) goto fiboptlist_csv_ret; } else { @@ -334,7 +339,7 @@ fiboptlist_csv(const char *arg, struct fibl_head_t *flh) if (errno == 0) { if (*endptr != '\0' || fib < 0 || - (numfibs != -1 && fib > numfibs - 1)) + (c->numfibs != -1 && fib > c->numfibs - 1)) errno = EINVAL; } if (errno) { @@ -361,16 +366,16 @@ fiboptlist_csv_ret: * associated with network interfaces. */ static void -flushroutes(int argc, char *argv[]) +flushroutes(struct rt_ctx *c, int argc, char *argv[]) { struct fibl *fl; int error; - if (uid != 0 && !debugonly && !tflag) + if (c->uid != 0 && !c->debugonly && !c->tflag) errx(EX_NOPERM, "must be root to alter routing table"); - shutdown(s, SHUT_RD); /* Don't want to read back our messages */ + shutdown(c->s, SHUT_RD); /* Don't want to read back our messages */ - TAILQ_INIT(&fibl_head); + TAILQ_INIT(&c->fibl_head); while (argc > 1) { argc--; argv++; @@ -379,24 +384,24 @@ flushroutes(int argc, char *argv[]) switch (keyword(*argv + 1)) { #ifdef INET case K_INET: - af = AF_INET; + c->af = AF_INET; break; #endif #ifdef INET6 case K_INET6: - af = AF_INET6; + c->af = AF_INET6; break; #endif case K_ATALK: - af = AF_APPLETALK; + c->af = AF_APPLETALK; break; case K_LINK: - af = AF_LINK; + c->af = AF_LINK; break; case K_FIB: if (!--argc) usage(*argv); - error = fiboptlist_csv(*++argv, &fibl_head); + error = fiboptlist_csv(c, *++argv, &c->fibl_head); if (error) errx(EX_USAGE, "invalid fib number: %s", *argv); break; @@ -404,17 +409,17 @@ flushroutes(int argc, char *argv[]) usage(*argv); } } - if (TAILQ_EMPTY(&fibl_head)) { - error = fiboptlist_csv("default", &fibl_head); + if (TAILQ_EMPTY(&c->fibl_head)) { + error = fiboptlist_csv(c, "default", &c->fibl_head); if (error) errx(EX_OSERR, "fiboptlist_csv failed."); } - TAILQ_FOREACH(fl, &fibl_head, fl_next) - flushroutes_fib(fl->fl_num); + TAILQ_FOREACH(fl, &c->fibl_head, fl_next) + flushroutes_fib(c, fl->fl_num); } static int -flushroutes_fib(int fib) +flushroutes_fib(struct rt_ctx *c, int fib) { struct rt_msghdr *rtm; size_t needed; @@ -422,7 +427,7 @@ flushroutes_fib(int fib) int mib[7], rlen, seqno, count = 0; int error; - error = set_sofib(fib); + error = set_sofib(c, fib); if (error) { warn("fib number %d is ignored", fib); return (error); @@ -450,26 +455,26 @@ retry: err(EX_OSERR, "route-sysctl-get"); } lim = buf + needed; - if (verbose) + if (c->verbose) (void)printf("Examining routing table from sysctl\n"); seqno = 0; /* ??? */ for (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)(void *)next; - if (verbose) - print_rtmsg(rtm, rtm->rtm_msglen); + if (c->verbose) + print_rtmsg(c, rtm, rtm->rtm_msglen); if ((rtm->rtm_flags & RTF_GATEWAY) == 0) continue; - if (af != 0) { + if (c->af != 0) { struct sockaddr *sa = (struct sockaddr *)(rtm + 1); - if (sa->sa_family != af) + if (sa->sa_family != c->af) continue; } - if (debugonly) + if (c->debugonly) continue; rtm->rtm_type = RTM_DELETE; rtm->rtm_seq = seqno; - rlen = write(s, next, rtm->rtm_msglen); + rlen = write(c->s, next, rtm->rtm_msglen); if (rlen < 0 && errno == EPERM) err(1, "write to routing socket"); if (rlen < (int)rtm->rtm_msglen) { @@ -480,17 +485,17 @@ retry: break; } seqno++; - if (qflag) + if (c->qflag) continue; - if (verbose) - print_rtmsg(rtm, rlen); + if (c->verbose) + print_rtmsg(c, rtm, rlen); else { struct sockaddr *sa = (struct sockaddr *)(rtm + 1); printf("%-20.20s ", rtm->rtm_flags & RTF_HOST ? - routename(sa) : netname(sa)); + routename(c, sa) : netname(c, sa)); sa = (struct sockaddr *)(SA_SIZE(sa) + (char *)sa); - printf("%-20.20s ", routename(sa)); + printf("%-20.20s ", routename(c, sa)); if (fib >= 0) printf("-fib %-3d ", fib); printf("done\n"); @@ -500,32 +505,32 @@ retry: } static const char * -routename(struct sockaddr *sa) +routename(struct rt_ctx *c, struct sockaddr *sa) { struct sockaddr_dl *sdl; const char *cp; char atalk_buf[20]; int n; - if (domain_initialized) { - domain_initialized = 1; - if (gethostname(domain, MAXHOSTNAMELEN) == 0 && - (cp = strchr(domain, '.'))) { - domain[MAXHOSTNAMELEN] = '\0'; - (void)strcpy(domain, cp + 1); + if (c->domain_initialized) { + c->domain_initialized = 1; + if (gethostname(c->domain, MAXHOSTNAMELEN) == 0 && + (cp = strchr(c->domain, '.'))) { + c->domain[MAXHOSTNAMELEN] = '\0'; + (void)strcpy(c->domain, cp + 1); } else - domain[0] = '\0'; + c->domain[0] = '\0'; } /* If the address is zero-filled, use "default". */ - if (sa->sa_len == 0 && nflag == 0) + if (sa->sa_len == 0 && c->nflag == 0) return ("default"); #if defined(INET) || defined(INET6) switch (sa->sa_family) { #ifdef INET case AF_INET: /* If the address is zero-filled, use "default". */ - if (nflag == 0 && + if (c->nflag == 0 && ((struct sockaddr_in *)(void *)sa)->sin_addr.s_addr == INADDR_ANY) return("default"); @@ -534,7 +539,7 @@ routename(struct sockaddr *sa) #ifdef INET6 case AF_INET6: /* If the address is zero-filled, use "default". */ - if (nflag == 0 && + if (c->nflag == 0 && IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)(void *)sa)->sin6_addr)) return("default"); break; @@ -566,24 +571,24 @@ routename(struct sockaddr *sa) else if (sa->sa_family == AF_INET6) ss.ss_len = sizeof(struct sockaddr_in6); error = getnameinfo((struct sockaddr *)&ss, ss.ss_len, - rt_line, sizeof(rt_line), NULL, 0, - (nflag == 0) ? 0 : NI_NUMERICHOST); + c->rt_line, sizeof(c->rt_line), NULL, 0, + (c->nflag == 0) ? 0 : NI_NUMERICHOST); if (error) { warnx("getnameinfo(): %s", gai_strerror(error)); - strncpy(rt_line, "invalid", sizeof(rt_line)); + strncpy(c->rt_line, "invalid", sizeof(c->rt_line)); } /* Remove the domain part if any. */ - p = strchr(rt_line, '.'); - if (p != NULL && strcmp(p + 1, domain) == 0) + p = strchr(c->rt_line, '.'); + if (p != NULL && strcmp(p + 1, c->domain) == 0) *p = '\0'; - return (rt_line); + return (c->rt_line); break; } #endif case AF_APPLETALK: - (void)snprintf(rt_line, sizeof(rt_line), "atalk %s", + (void)snprintf(c->rt_line, sizeof(c->rt_line), "atalk %s", atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr, atalk_buf)); break; @@ -594,11 +599,11 @@ routename(struct sockaddr *sa) if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) { - n = snprintf(rt_line, sizeof(rt_line), "link#%d", + n = snprintf(c->rt_line, sizeof(c->rt_line), "link#%d", sdl->sdl_index); - if (n > (int)sizeof(rt_line)) - rt_line[0] = '\0'; - return (rt_line); + if (n > (int)sizeof(c->rt_line)) + c->rt_line[0] = '\0'; + return (c->rt_line); } else return (link_ntoa(sdl)); break; @@ -607,8 +612,8 @@ routename(struct sockaddr *sa) { u_short *sp = (u_short *)(void *)sa; u_short *splim = sp + ((sa->sa_len + 1) >> 1); - char *cps = rt_line + sprintf(rt_line, "(%d)", sa->sa_family); - char *cpe = rt_line + sizeof(rt_line); + char *cps = c->rt_line + sprintf(c->rt_line, "(%d)", sa->sa_family); + char *cpe = c->rt_line + sizeof(c->rt_line); while (++sp < splim && cps < cpe) /* start with sa->sa_data */ if ((n = snprintf(cps, cpe - cps, " %x", *sp)) > 0) @@ -618,7 +623,7 @@ routename(struct sockaddr *sa) break; } } - return (rt_line); + return (c->rt_line); } /* @@ -626,7 +631,7 @@ routename(struct sockaddr *sa) * The address is assumed to be that of a net, not a host. */ static const char * -netname(struct sockaddr *sa) +netname(struct rt_ctx *c, struct sockaddr *sa) { struct sockaddr_dl *sdl; char atalk_buf[20]; @@ -647,24 +652,24 @@ netname(struct sockaddr *sa) i = in.s_addr = ntohl(in.s_addr); if (in.s_addr == 0) cp = "default"; - else if (!nflag) { + else if (!c->nflag) { np = getnetbyaddr(i, AF_INET); if (np != NULL) cp = np->n_name; } #define C(x) (unsigned)((x) & 0xff) if (cp != NULL) - strncpy(net_line, cp, sizeof(net_line)); + strncpy(c->net_line, cp, sizeof(c->net_line)); else if ((in.s_addr & 0xffffff) == 0) - (void)sprintf(net_line, "%u", C(in.s_addr >> 24)); + (void)sprintf(c->net_line, "%u", C(in.s_addr >> 24)); else if ((in.s_addr & 0xffff) == 0) - (void)sprintf(net_line, "%u.%u", C(in.s_addr >> 24), + (void)sprintf(c->net_line, "%u.%u", C(in.s_addr >> 24), C(in.s_addr >> 16)); else if ((in.s_addr & 0xff) == 0) - (void)sprintf(net_line, "%u.%u.%u", C(in.s_addr >> 24), + (void)sprintf(c->net_line, "%u.%u.%u", C(in.s_addr >> 24), C(in.s_addr >> 16), C(in.s_addr >> 8)); else - (void)sprintf(net_line, "%u.%u.%u.%u", C(in.s_addr >> 24), + (void)sprintf(c->net_line, "%u.%u.%u.%u", C(in.s_addr >> 24), C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr)); #undef C @@ -681,18 +686,18 @@ netname(struct sockaddr *sa) memcpy(&sin6, sa, sa->sa_len); sin6.sin6_len = sizeof(sin6); sin6.sin6_family = AF_INET6; - if (nflag) + if (c->nflag) niflags |= NI_NUMERICHOST; if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, - net_line, sizeof(net_line), NULL, 0, niflags) != 0) - strncpy(net_line, "invalid", sizeof(net_line)); + c->net_line, sizeof(c->net_line), NULL, 0, niflags) != 0) + strncpy(c->net_line, "invalid", sizeof(c->net_line)); - return(net_line); + return(c->net_line); } #endif case AF_APPLETALK: - (void)snprintf(net_line, sizeof(net_line), "atalk %s", + (void)snprintf(c->net_line, sizeof(c->net_line), "atalk %s", atalk_ntoa(((struct sockaddr_at *)(void *)sa)->sat_addr, atalk_buf)); break; @@ -703,11 +708,11 @@ netname(struct sockaddr *sa) if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) { - n = snprintf(net_line, sizeof(net_line), "link#%d", + n = snprintf(c->net_line, sizeof(c->net_line), "link#%d", sdl->sdl_index); - if (n > (int)sizeof(net_line)) - net_line[0] = '\0'; - return (net_line); + if (n > (int)sizeof(c->net_line)) + c->net_line[0] = '\0'; + return (c->net_line); } else return (link_ntoa(sdl)); break; @@ -716,8 +721,8 @@ netname(struct sockaddr *sa) { u_short *sp = (u_short *)(void *)sa->sa_data; u_short *splim = sp + ((sa->sa_len + 1)>>1); - char *cps = net_line + sprintf(net_line, "af %d:", sa->sa_family); - char *cpe = net_line + sizeof(net_line); + char *cps = c->net_line + sprintf(c->net_line, "af %d:", sa->sa_family); + char *cpe = c->net_line + sizeof(c->net_line); while (sp < splim && cps < cpe) if ((n = snprintf(cps, cpe - cps, " %x", *sp++)) > 0) @@ -727,17 +732,17 @@ netname(struct sockaddr *sa) break; } } - return (net_line); + return (c->net_line); } static void -set_metric(char *value, int key) +set_metric(struct rt_ctx *c, char *value, int key) { int flag = 0; u_long noval, *valp = &noval; switch (key) { -#define caseof(x, y, z) case x: valp = &rt_metrics.z; flag = y; break +#define caseof(x, y, z) case x: valp = &c->rt_metrics.z; flag = y; break caseof(K_MTU, RTV_MTU, rmx_mtu); caseof(K_HOPCOUNT, RTV_HOPCOUNT, rmx_hopcount); caseof(K_EXPIRE, RTV_EXPIRE, rmx_expire); @@ -748,11 +753,11 @@ set_metric(char *value, int key) caseof(K_RTTVAR, RTV_RTTVAR, rmx_rttvar); caseof(K_WEIGHT, RTV_WEIGHT, rmx_weight); } - rtm_inits |= flag; - if (lockrest || locking) - rt_metrics.rmx_locks |= flag; - if (locking) - locking = 0; + c->rtm_inits |= flag; + if (c->lockrest || c->locking) + c->rt_metrics.rmx_locks |= flag; + if (c->locking) + c->locking = 0; *valp = atoi(value); } @@ -763,7 +768,7 @@ set_metric(char *value, int key) #define F_INTERFACE 0x10 static void -newroute(int argc, char **argv) +newroute(struct rt_ctx *c, int argc, char **argv) { struct hostent *hp; struct fibl *fl; @@ -771,44 +776,44 @@ newroute(int argc, char **argv) const char *dest, *gateway, *errmsg; int key, error, flags, nrflags, fibnum; - if (uid != 0 && !debugonly && !tflag) + if (c->uid != 0 && !c->debugonly && !c->tflag) errx(EX_NOPERM, "must be root to alter routing table"); dest = NULL; gateway = NULL; flags = RTF_STATIC; nrflags = 0; hp = NULL; - TAILQ_INIT(&fibl_head); + TAILQ_INIT(&c->fibl_head); cmd = argv[0]; if (*cmd != 'g' && *cmd != 's') - shutdown(s, SHUT_RD); /* Don't want to read back our messages */ + shutdown(c->s, SHUT_RD); /* Don't want to read back our messages */ while (--argc > 0) { if (**(++argv)== '-') { switch (key = keyword(1 + *argv)) { case K_LINK: - af = AF_LINK; - aflen = sizeof(struct sockaddr_dl); + c->af = AF_LINK; + c->aflen = sizeof(struct sockaddr_dl); break; #ifdef INET case K_INET: - af = AF_INET; - aflen = sizeof(struct sockaddr_in); + c->af = AF_INET; + c->aflen = sizeof(struct sockaddr_in); break; #endif #ifdef INET6 case K_INET6: - af = AF_INET6; - aflen = sizeof(struct sockaddr_in6); + c->af = AF_INET6; + c->aflen = sizeof(struct sockaddr_in6); break; #endif case K_ATALK: - af = AF_APPLETALK; - aflen = sizeof(struct sockaddr_at); + c->af = AF_APPLETALK; + c->aflen = sizeof(struct sockaddr_at); break; case K_SA: - af = PF_ROUTE; - aflen = sizeof(struct sockaddr_storage); + c->af = PF_ROUTE; + c->aflen = sizeof(struct sockaddr_storage); break; case K_IFACE: case K_INTERFACE: @@ -818,10 +823,10 @@ newroute(int argc, char **argv) flags &= ~RTF_STATIC; break; case K_LOCK: - locking = 1; + c->locking = 1; break; case K_LOCKREST: - lockrest = 1; + c->lockrest = 1; break; case K_HOST: nrflags |= F_FORCEHOST; @@ -856,7 +861,7 @@ newroute(int argc, char **argv) case K_FIB: if (!--argc) usage(NULL); - error = fiboptlist_csv(*++argv, &fibl_head); + error = fiboptlist_csv(c, *++argv, &c->fibl_head); if (error) errx(EX_USAGE, "invalid fib number: %s", *argv); @@ -864,35 +869,35 @@ newroute(int argc, char **argv) case K_IFA: if (!--argc) usage(NULL); - getaddr(RTAX_IFA, *++argv, 0, nrflags); + getaddr(c, RTAX_IFA, *++argv, 0, nrflags); break; case K_IFP: if (!--argc) usage(NULL); - getaddr(RTAX_IFP, *++argv, 0, nrflags); + getaddr(c, RTAX_IFP, *++argv, 0, nrflags); break; case K_GENMASK: if (!--argc) usage(NULL); - getaddr(RTAX_GENMASK, *++argv, 0, nrflags); + getaddr(c, RTAX_GENMASK, *++argv, 0, nrflags); break; case K_GATEWAY: if (!--argc) usage(NULL); - getaddr(RTAX_GATEWAY, *++argv, 0, nrflags); + getaddr(c, RTAX_GATEWAY, *++argv, 0, nrflags); gateway = *argv; break; case K_DST: if (!--argc) usage(NULL); - if (getaddr(RTAX_DST, *++argv, &hp, nrflags)) + if (getaddr(c, RTAX_DST, *++argv, &hp, nrflags)) nrflags |= F_ISHOST; dest = *argv; break; case K_NETMASK: if (!--argc) usage(NULL); - getaddr(RTAX_NETMASK, *++argv, 0, nrflags); + getaddr(c, RTAX_NETMASK, *++argv, 0, nrflags); /* FALLTHROUGH */ case K_NET: nrflags |= F_FORCENET; @@ -900,7 +905,7 @@ newroute(int argc, char **argv) case K_PREFIXLEN: if (!--argc) usage(NULL); - if (prefixlen(*++argv) == -1) { + if (prefixlen(c, *++argv) == -1) { nrflags &= ~F_FORCENET; nrflags |= F_ISHOST; } else { @@ -919,27 +924,27 @@ newroute(int argc, char **argv) case K_WEIGHT: if (!--argc) usage(NULL); - set_metric(*++argv, key); + set_metric(c, *++argv, key); break; default: usage(1+*argv); } } else { - if ((rtm_addrs & RTA_DST) == 0) { + if ((c->rtm_addrs & RTA_DST) == 0) { dest = *argv; - if (getaddr(RTAX_DST, *argv, &hp, nrflags)) + if (getaddr(c, RTAX_DST, *argv, &hp, nrflags)) nrflags |= F_ISHOST; - } else if ((rtm_addrs & RTA_GATEWAY) == 0) { + } else if ((c->rtm_addrs & RTA_GATEWAY) == 0) { gateway = *argv; - getaddr(RTAX_GATEWAY, *argv, &hp, nrflags); + getaddr(c, RTAX_GATEWAY, *argv, &hp, nrflags); } else { - getaddr(RTAX_NETMASK, *argv, 0, nrflags); + getaddr(c, RTAX_NETMASK, *argv, 0, nrflags); nrflags |= F_FORCENET; } } } - if (so[RTAX_DST].ss_len == 0) { + if (c->so[RTAX_DST].ss_len == 0) { warnx("destination parameter required"); usage(NULL); } @@ -947,9 +952,9 @@ newroute(int argc, char **argv) if (nrflags & F_FORCEHOST) { nrflags |= F_ISHOST; #ifdef INET6 - if (af == AF_INET6) { - rtm_addrs &= ~RTA_NETMASK; - memset(&so[RTAX_NETMASK], 0, sizeof(so[RTAX_NETMASK])); + if (c->af == AF_INET6) { + c->rtm_addrs &= ~RTA_NETMASK; + memset(&c->so[RTAX_NETMASK], 0, sizeof(c->so[RTAX_NETMASK])); } #endif } @@ -967,14 +972,14 @@ newroute(int argc, char **argv) if (gateway == NULL) gateway = ""; - if (TAILQ_EMPTY(&fibl_head)) { - error = fiboptlist_csv("default", &fibl_head); + if (TAILQ_EMPTY(&c->fibl_head)) { + error = fiboptlist_csv(c, "default", &c->fibl_head); if (error) errx(EX_OSERR, "fiboptlist_csv failed."); } error = 0; - TAILQ_FOREACH(fl, &fibl_head, fl_next) { - fl->fl_error = newroute_fib(fl->fl_num, cmd, flags); + TAILQ_FOREACH(fl, &c->fibl_head, fl_next) { + fl->fl_error = newroute_fib(c, fl->fl_num, cmd, flags); if (fl->fl_error) fl->fl_errno = errno; error += fl->fl_error; @@ -983,9 +988,9 @@ newroute(int argc, char **argv) exit(error); error = 0; - if (!qflag) { + if (!c->qflag) { fibnum = 0; - TAILQ_FOREACH(fl, &fibl_head, fl_next) { + TAILQ_FOREACH(fl, &c->fibl_head, fl_next) { if (fl->fl_error == 0) fibnum++; } @@ -997,8 +1002,8 @@ newroute(int argc, char **argv) if (*gateway) printf(": gateway %s", gateway); - if (numfibs > 1) { - TAILQ_FOREACH(fl, &fibl_head, fl_next) { + if (c->numfibs > 1) { + TAILQ_FOREACH(fl, &c->fibl_head, fl_next) { if (fl->fl_error == 0 && fl->fl_num >= 0) { if (firstfib) { @@ -1015,7 +1020,7 @@ newroute(int argc, char **argv) } fibnum = 0; - TAILQ_FOREACH(fl, &fibl_head, fl_next) { + TAILQ_FOREACH(fl, &c->fibl_head, fl_next) { if (fl->fl_error != 0) { printf("%s %s %s", cmd, (nrflags & F_ISHOST) ? "host" : "net", dest); @@ -1058,17 +1063,17 @@ newroute(int argc, char **argv) } static int -newroute_fib(int fib, char *cmd, int flags) +newroute_fib(struct rt_ctx *c, int fib, char *cmd, int flags) { int error; - error = set_sofib(fib); + error = set_sofib(c, fib); if (error) { warn("fib number %d is ignored", fib); return (error); } - error = rtmsg(*cmd, flags, fib); + error = rtmsg(c, *cmd, flags, fib); return (error); } @@ -1079,7 +1084,7 @@ inet_makenetandmask(u_long net, struct sockaddr_in *sin, { u_long mask = 0; - rtm_addrs |= RTA_NETMASK; + c->rtm_addrs |= RTA_NETMASK; /* * MSB of net should be meaningful. 0/0 is exception. @@ -1138,8 +1143,8 @@ inet6_makenetandmask(struct sockaddr_in6 *sin6, const char *plen) if (plen == NULL || strcmp(plen, "128") == 0) return (1); - rtm_addrs |= RTA_NETMASK; - prefixlen(plen); + c->rtm_addrs |= RTA_NETMASK; + prefixlen(c, plen); return (0); } #endif @@ -1149,7 +1154,7 @@ inet6_makenetandmask(struct sockaddr_in6 *sin6, const char *plen) * returning 1 if a host address, 0 if a network address. */ static int -getaddr(int idx, char *str, struct hostent **hpp, int nrflags) +getaddr(struct rt_ctx *c, int idx, char *str, struct hostent **hpp, int nrflags) { struct sockaddr *sa; #if defined(INET) @@ -1164,25 +1169,25 @@ getaddr(int idx, char *str, struct hostent **hpp, int nrflags) if (idx < 0 || idx >= RTAX_MAX) usage("internal error"); - if (af == 0) { + if (c->af == 0) { #if defined(INET) - af = AF_INET; - aflen = sizeof(struct sockaddr_in); + c->af = AF_INET; + c->aflen = sizeof(struct sockaddr_in); #elif defined(INET6) - af = AF_INET6; - aflen = sizeof(struct sockaddr_in6); + c->af = AF_INET6; + c->aflen = sizeof(struct sockaddr_in6); #else - af = AF_LINK; - aflen = sizeof(struct sockaddr_dl); + c->af = AF_LINK; + c->aflen = sizeof(struct sockaddr_dl); #endif } #ifndef INET hpp = NULL; #endif - rtm_addrs |= (1 << idx); - sa = (struct sockaddr *)&so[idx]; - sa->sa_family = af; - sa->sa_len = aflen; + c->rtm_addrs |= (1 << idx); + sa = (struct sockaddr *)&c->so[idx]; + sa->sa_family = c->af; + sa->sa_len = c->aflen; switch (idx) { case RTAX_GATEWAY: @@ -1226,8 +1231,8 @@ getaddr(int idx, char *str, struct hostent **hpp, int nrflags) */ switch (idx) { case RTAX_DST: - forcenet++; - getaddr(RTAX_NETMASK, str, 0, nrflags); + c->forcenet++; + getaddr(c, RTAX_NETMASK, str, 0, nrflags); break; } return (0); @@ -1265,8 +1270,8 @@ getaddr(int idx, char *str, struct hostent **hpp, int nrflags) if (!atalk_aton(str, &sat->sat_addr)) errx(EX_NOHOST, "bad address: %s", str); - rtm_addrs |= RTA_NETMASK; - return(forcehost || sat->sat_addr.s_node != 0); + c->rtm_addrs |= RTA_NETMASK; + return(c->forcehost || sat->sat_addr.s_node != 0); } case AF_LINK: link_addr(str, (struct sockaddr_dl *)(void *)sa); @@ -1293,16 +1298,16 @@ getaddr(int idx, char *str, struct hostent **hpp, int nrflags) *q = '\0'; if ((val = inet_network(str)) != INADDR_NONE) { inet_makenetandmask(val, sin, - (struct sockaddr_in *)&so[RTAX_NETMASK], + (struct sockaddr_in *)&c->so[RTAX_NETMASK], strtoul(q+1, 0, 0)); return (0); } *q = '/'; } - if ((idx != RTAX_DST || forcenet == 0) && + if ((idx != RTAX_DST || c->forcenet == 0) && inet_aton(str, &sin->sin_addr)) { val = sin->sin_addr.s_addr; - if (idx != RTAX_DST || forcehost || + if (idx != RTAX_DST || c->forcehost || inet_lnaof(sin->sin_addr) != INADDR_ANY) return (1); else { @@ -1310,12 +1315,12 @@ getaddr(int idx, char *str, struct hostent **hpp, int nrflags) goto netdone; } } - if (idx == RTAX_DST && forcehost == 0 && + if (idx == RTAX_DST && c->forcehost == 0 && ((val = inet_network(str)) != INADDR_NONE || ((np = getnetbyname(str)) != NULL && (val = np->n_net) != 0))) { netdone: inet_makenetandmask(val, sin, - (struct sockaddr_in *)&so[RTAX_NETMASK], 0); + (struct sockaddr_in *)&c->so[RTAX_NETMASK], 0); return (0); } hp = gethostbyname(str); @@ -1331,19 +1336,19 @@ netdone: } static int -prefixlen(const char *str) +prefixlen(struct rt_ctx *c, const char *str) { int len = atoi(str), q, r; int max; char *p; - rtm_addrs |= RTA_NETMASK; - switch (af) { + c->rtm_addrs |= RTA_NETMASK; + switch (c->af) { #ifdef INET6 case AF_INET6: { struct sockaddr_in6 *sin6 = - (struct sockaddr_in6 *)&so[RTAX_NETMASK]; + (struct sockaddr_in6 *)&c->so[RTAX_NETMASK]; max = 128; p = (char *)&sin6->sin6_addr; @@ -1356,7 +1361,7 @@ prefixlen(const char *str) case AF_INET: { struct sockaddr_in *sin = - (struct sockaddr_in *)&so[RTAX_NETMASK]; + (struct sockaddr_in *)&c->so[RTAX_NETMASK]; max = 32; p = (char *)&sin->sin_addr; @@ -1386,7 +1391,7 @@ prefixlen(const char *str) } static void -interfaces(void) +interfaces(struct rt_ctx *c) { size_t needed; int mib[6]; @@ -1416,17 +1421,17 @@ retry2: lim = buf + needed; for (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)(void *)next; - print_rtmsg(rtm, rtm->rtm_msglen); + print_rtmsg(c, rtm, rtm->rtm_msglen); } } static void -monitor(int argc, char *argv[]) +monitor(struct rt_ctx *c, int argc, char *argv[]) { int n, fib, error; char msg[2048], *endptr; - fib = defaultfib; + fib = c->defaultfib; while (argc > 1) { argc--; argv++; @@ -1441,7 +1446,7 @@ monitor(int argc, char *argv[]) if (errno == 0) { if (*endptr != '\0' || fib < 0 || - (numfibs != -1 && fib > numfibs - 1)) + (c->numfibs != -1 && fib > c->numfibs - 1)) errno = EINVAL; } if (errno) @@ -1451,79 +1456,79 @@ monitor(int argc, char *argv[]) usage(*argv); } } - error = set_sofib(fib); + error = set_sofib(c, fib); if (error) errx(EX_USAGE, "invalid fib number: %d", fib); - verbose = 1; - if (debugonly) { - interfaces(); + c->verbose = 1; + if (c->debugonly) { + interfaces(c); exit(0); } for (;;) { time_t now; - n = read(s, msg, 2048); + n = read(c->s, msg, 2048); now = time(NULL); (void)printf("\ngot message of size %d on %s", n, ctime(&now)); - print_rtmsg((struct rt_msghdr *)(void *)msg, n); + print_rtmsg(c, (struct rt_msghdr *)(void *)msg, n); } } static int -rtmsg(int cmd, int flags, int fib) +rtmsg(struct rt_ctx *c, int cmd, int flags, int fib) { int rlen; - char *cp = m_rtmsg.m_space; + char *cp = c->m_rtmsg.m_space; int l; #define NEXTADDR(w, u) \ - if (rtm_addrs & (w)) { \ + if (c->rtm_addrs & (w)) { \ l = (((struct sockaddr *)&(u))->sa_len == 0) ? \ sizeof(long) : \ 1 + ((((struct sockaddr *)&(u))->sa_len - 1) \ | (sizeof(long) - 1)); \ memmove(cp, (char *)&(u), l); \ cp += l; \ - if (verbose) \ + if (c->verbose) \ sodump((struct sockaddr *)&(u), #w); \ } errno = 0; - memset(&m_rtmsg, 0, sizeof(m_rtmsg)); + memset(&c->m_rtmsg, 0, sizeof(c->m_rtmsg)); if (cmd == 'a') cmd = RTM_ADD; else if (cmd == 'c') cmd = RTM_CHANGE; else if (cmd == 'g' || cmd == 's') { cmd = RTM_GET; - if (so[RTAX_IFP].ss_family == 0) { - so[RTAX_IFP].ss_family = AF_LINK; - so[RTAX_IFP].ss_len = sizeof(struct sockaddr_dl); - rtm_addrs |= RTA_IFP; + if (c->so[RTAX_IFP].ss_family == 0) { + c->so[RTAX_IFP].ss_family = AF_LINK; + c->so[RTAX_IFP].ss_len = sizeof(struct sockaddr_dl); + c->rtm_addrs |= RTA_IFP; } } else cmd = RTM_DELETE; -#define rtm m_rtmsg.m_rtm +#define rtm c->m_rtmsg.m_rtm rtm.rtm_type = cmd; rtm.rtm_flags = flags; rtm.rtm_version = RTM_VERSION; - rtm.rtm_seq = ++rtm_seq; - rtm.rtm_addrs = rtm_addrs; - rtm.rtm_rmx = rt_metrics; - rtm.rtm_inits = rtm_inits; + rtm.rtm_seq = ++c->rtm_seq; + rtm.rtm_addrs = c->rtm_addrs; + rtm.rtm_rmx = c->rt_metrics; + rtm.rtm_inits = c->rtm_inits; - NEXTADDR(RTA_DST, so[RTAX_DST]); - NEXTADDR(RTA_GATEWAY, so[RTAX_GATEWAY]); - NEXTADDR(RTA_NETMASK, so[RTAX_NETMASK]); - NEXTADDR(RTA_GENMASK, so[RTAX_GENMASK]); - NEXTADDR(RTA_IFP, so[RTAX_IFP]); - NEXTADDR(RTA_IFA, so[RTAX_IFA]); - rtm.rtm_msglen = l = cp - (char *)&m_rtmsg; - if (verbose) - print_rtmsg(&rtm, l); - if (debugonly) + NEXTADDR(RTA_DST, c->so[RTAX_DST]); + NEXTADDR(RTA_GATEWAY, c->so[RTAX_GATEWAY]); + NEXTADDR(RTA_NETMASK, c->so[RTAX_NETMASK]); + NEXTADDR(RTA_GENMASK, c->so[RTAX_GENMASK]); + NEXTADDR(RTA_IFP, c->so[RTAX_IFP]); + NEXTADDR(RTA_IFA, c->so[RTAX_IFA]); + rtm.rtm_msglen = l = cp - (char *)&c->m_rtmsg; + if (c->verbose) + print_rtmsg(c, &rtm, l); + if (c->debugonly) return (0); - if ((rlen = write(s, (char *)&m_rtmsg, l)) < 0) { + if ((rlen = write(c->s, (char *)&c->m_rtmsg, l)) < 0) { if (errno == EPERM) err(1, "writing to routing socket"); warn("writing to routing socket"); @@ -1531,12 +1536,12 @@ rtmsg(int cmd, int flags, int fib) } if (cmd == RTM_GET) { do { - l = read(s, (char *)&m_rtmsg, sizeof(m_rtmsg)); - } while (l > 0 && (rtm.rtm_seq != rtm_seq || rtm.rtm_pid != pid)); + l = read(c->s, (char *)&c->m_rtmsg, sizeof(c->m_rtmsg)); + } while (l > 0 && (rtm.rtm_seq != c->rtm_seq || rtm.rtm_pid != c->pid)); if (l < 0) warn("read from routing socket"); else - print_getmsg(&rtm, l, fib); + print_getmsg(c, &rtm, l, fib); } #undef rtm return (0); @@ -1583,7 +1588,7 @@ static const char errfmt[] = "\n%s: truncated route message, only %zu bytes left\n"; static void -print_rtmsg(struct rt_msghdr *rtm, size_t msglen) +print_rtmsg(struct rt_ctx *c, struct rt_msghdr *rtm, size_t msglen) { struct if_msghdr *ifm; struct ifa_msghdr *ifam; @@ -1593,7 +1598,7 @@ print_rtmsg(struct rt_msghdr *rtm, size_t msglen) struct if_announcemsghdr *ifan; const char *state; - if (verbose == 0) + if (c->verbose == 0) return; if (rtm->rtm_version != RTM_VERSION) { (void)printf("routing message version %d not understood\n", @@ -1631,7 +1636,7 @@ print_rtmsg(struct rt_msghdr *rtm, size_t msglen) } (void)printf("link: %s, flags:", state); printb(ifm->ifm_flags, ifnetflags); - pmsg_addrs((char *)(ifm + 1), ifm->ifm_addrs, msglen); + pmsg_addrs(c, (char *)(ifm + 1), ifm->ifm_addrs, msglen); break; case RTM_NEWADDR: case RTM_DELADDR: @@ -1639,14 +1644,14 @@ print_rtmsg(struct rt_msghdr *rtm, size_t msglen) ifam = (struct ifa_msghdr *)rtm; (void)printf("metric %d, flags:", ifam->ifam_metric); printb(ifam->ifam_flags, routeflags); - pmsg_addrs((char *)(ifam + 1), ifam->ifam_addrs, msglen); + pmsg_addrs(c, (char *)(ifam + 1), ifam->ifam_addrs, msglen); break; #ifdef RTM_NEWMADDR case RTM_NEWMADDR: case RTM_DELMADDR: REQUIRE(struct ifma_msghdr); ifmam = (struct ifma_msghdr *)rtm; - pmsg_addrs((char *)(ifmam + 1), ifmam->ifmam_addrs, msglen); + pmsg_addrs(c, (char *)(ifmam + 1), ifmam->ifmam_addrs, msglen); break; #endif case RTM_IFANNOUNCE: @@ -1672,7 +1677,7 @@ print_rtmsg(struct rt_msghdr *rtm, size_t msglen) printf("pid: %ld, seq %d, errno %d, flags:", (long)rtm->rtm_pid, rtm->rtm_seq, rtm->rtm_errno); printb(rtm->rtm_flags, routeflags); - pmsg_common(rtm, msglen); + pmsg_common(c, rtm, msglen); } return; @@ -1683,7 +1688,7 @@ badlen: } static void -print_getmsg(struct rt_msghdr *rtm, int msglen, int fib) +print_getmsg(struct rt_ctx *c, struct rt_msghdr *rtm, int msglen, int fib) { struct sockaddr *sp[RTAX_MAX]; char *cp; @@ -1691,7 +1696,7 @@ print_getmsg(struct rt_msghdr *rtm, int msglen, int fib) memset(sp, 0, sizeof(sp)); (void)printf(" route to: %s\n", - routename((struct sockaddr *)&so[RTAX_DST])); + routename(c, (struct sockaddr *)&c->so[RTAX_DST])); if (rtm->rtm_version != RTM_VERSION) { warnx("routing message version %d not understood", rtm->rtm_version); @@ -1720,11 +1725,11 @@ print_getmsg(struct rt_msghdr *rtm, int msglen, int fib) if (sp[RTAX_DST] && sp[RTAX_NETMASK]) sp[RTAX_NETMASK]->sa_family = sp[RTAX_DST]->sa_family; /* XXX */ if (sp[RTAX_DST]) - (void)printf("destination: %s\n", routename(sp[RTAX_DST])); + (void)printf("destination: %s\n", routename(c, sp[RTAX_DST])); if (sp[RTAX_NETMASK]) - (void)printf(" mask: %s\n", routename(sp[RTAX_NETMASK])); + (void)printf(" mask: %s\n", routename(c, sp[RTAX_NETMASK])); if (sp[RTAX_GATEWAY] && (rtm->rtm_flags & RTF_GATEWAY)) - (void)printf(" gateway: %s\n", routename(sp[RTAX_GATEWAY])); + (void)printf(" gateway: %s\n", routename(c, sp[RTAX_GATEWAY])); if (fib >= 0) (void)printf(" fib: %u\n", (unsigned int)fib); if (sp[RTAX_IFP]) @@ -1750,8 +1755,8 @@ print_getmsg(struct rt_msghdr *rtm, int msglen, int fib) #undef lock #undef msec #define RTA_IGN (RTA_DST|RTA_GATEWAY|RTA_NETMASK|RTA_IFP|RTA_IFA|RTA_BRD) - if (verbose) - pmsg_common(rtm, msglen); + if (c->verbose) + pmsg_common(c, rtm, msglen); else if (rtm->rtm_addrs &~ RTA_IGN) { (void)printf("sockaddrs: "); printb(rtm->rtm_addrs, addrnames); @@ -1761,7 +1766,7 @@ print_getmsg(struct rt_msghdr *rtm, int msglen, int fib) } static void -pmsg_common(struct rt_msghdr *rtm, size_t msglen) +pmsg_common(struct rt_ctx *c, struct rt_msghdr *rtm, size_t msglen) { (void)printf("\nlocks: "); @@ -1769,14 +1774,14 @@ pmsg_common(struct rt_msghdr *rtm, size_t msglen) (void)printf(" inits: "); printb(rtm->rtm_inits, metricnames); if (msglen > sizeof(struct rt_msghdr)) - pmsg_addrs(((char *)(rtm + 1)), rtm->rtm_addrs, + pmsg_addrs(c, ((char *)(rtm + 1)), rtm->rtm_addrs, msglen - sizeof(struct rt_msghdr)); else (void)fflush(stdout); } static void -pmsg_addrs(char *cp, int addrs, size_t len) +pmsg_addrs(struct rt_ctx *c, char *cp, int addrs, size_t len) { struct sockaddr *sa; int i; @@ -1795,7 +1800,7 @@ pmsg_addrs(char *cp, int addrs, size_t len) (void)printf(errfmt, __func__, len); break; } - (void)printf(" %s", routename(sa)); + (void)printf(" %s", routename(c, sa)); len -= SA_SIZE(sa); cp += SA_SIZE(sa); } -- 1.7.7 --------------060103010809050906000908-- From owner-freebsd-hackers@FreeBSD.ORG Fri Oct 18 04:48:29 2013 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B7B80F45 for ; Fri, 18 Oct 2013 04:48:29 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from felyko.com (felyko.com [174.136.100.2]) by mx1.freebsd.org (Postfix) with ESMTP id A26DC2AED for ; Fri, 18 Oct 2013 04:48:29 +0000 (UTC) Received: from [IPv6:2601:9:4d00:119:21e1:469c:b8c0:7be9] (unknown [IPv6:2601:9:4d00:119:21e1:469c:b8c0:7be9]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by felyko.com (Postfix) with ESMTPSA id 6E63D39821; Thu, 17 Oct 2013 21:48:22 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.0 \(1812\)) Subject: Re: amdtemp need help with testing From: Rui Paulo In-Reply-To: <525f0076.c402cd0a.5f4e.7f67@mx.google.com> Date: Thu, 17 Oct 2013 21:48:20 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: <52520d5f.c402cd0a.5f4e.ffffffa2@mx.google.com> <52553F3F.9090707@digiware.nl> <5255478B.9090305@digiware.nl> <525f0076.c402cd0a.5f4e.7f67@mx.google.com> To: Rozhuk.IM@gmail.com X-Mailer: Apple Mail (2.1812) Cc: hackers@freebsd.org, Willem Jan Withagen X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 04:48:29 -0000 On 16 Oct 2013, at 14:09, rozhuk.im@gmail.com wrote: > Thanks for the help with testing! > I fixed a bug, added HTC registers, changed the _ident() and the = _probe(): > no binding processor Family. > The latest version here: = http://netlab.linkpc.net/download/tmp/amdtemp.c Please read the style(9) man page and fix your code accordingly. = Otherwise we can't integrate it. It would also be best to send a patch to the mailing list. Thanks! -- Rui Paulo From owner-freebsd-hackers@FreeBSD.ORG Fri Oct 18 15:33:08 2013 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 7BD1E5A9 for ; Fri, 18 Oct 2013 15:33:08 +0000 (UTC) (envelope-from prvs=1003132fe8=killing@multiplay.co.uk) Received: from mail1.multiplay.co.uk (mail1.multiplay.co.uk [85.236.96.23]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1DFDC2BA9 for ; Fri, 18 Oct 2013 15:33:07 +0000 (UTC) Received: from r2d2 ([82.69.141.170]) by mail1.multiplay.co.uk (mail1.multiplay.co.uk [85.236.96.23]) (MDaemon PRO v10.0.4) with ESMTP id md50006443500.msg for ; Fri, 18 Oct 2013 16:33:05 +0100 X-Spam-Processed: mail1.multiplay.co.uk, Fri, 18 Oct 2013 16:33:05 +0100 (not processed: message from valid local sender) X-MDDKIM-Result: neutral (mail1.multiplay.co.uk) X-MDRemoteIP: 82.69.141.170 X-Return-Path: prvs=1003132fe8=killing@multiplay.co.uk X-Envelope-From: killing@multiplay.co.uk X-MDaemon-Deliver-To: hackers@freebsd.org Message-ID: From: "Steven Hartland" To: Subject: panic on close of /dev/xen/evtchn Date: Fri, 18 Oct 2013 16:33:27 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 15:33:08 -0000 Just had my test box panic while doing a: find / -print0 | xargs -0 cat Ignoring the fact thats a silly command to run, the panic appears to be when it ran: cat /dev/xen/evtchn On the session it then printed: cat: /dev/xen/evtchn: Interrupted system call At this point the system paniced. Panic transcribed from screen is: Stopped at evtchn_close:0x67: lock bts| %ebx,0xa00(%rax) db> bt Tracing pdi 1533 tid 100370 td 0xfffff8000796e920 evtchn_close() at evtchn_close+0x67/frame ... devfs_close() at devs_close+0x188/frame ... VOP_CLOSE_APV() at VOP_CLOSE_APV+0x139/frame ... vn_close() at vn_close+0x139/frame ... vn_closefile() at vn_closefile+0x48/frame ... _fdrop() at _fdrop+0x29/frame ... closef() at closef+0x1d1/frame ... closefp() at closefp+0xa0/frame ... amd64_syscall() at amd64_syscall+0x265/frame ... Xfast_syscall() at Xfast_syscall+0xfb/frame ... --- syscall (6, FreeBSD ELF64, sys_close), rip = 0x80094a9ea, rsp = 0x7ffffffb8e28, rbp -= 0x7ffffffb8f70 --- Regards Steve ================================================ This e.mail is private and confidential between Multiplay (UK) Ltd. and the person or entity to whom it is addressed. In the event of misdirection, the recipient is prohibited from using, copying, printing or otherwise disseminating it or any information contained in it. In the event of misdirection, illegible or incomplete transmission please telephone +44 845 868 1337 or return the E.mail to postmaster@multiplay.co.uk. From owner-freebsd-hackers@FreeBSD.ORG Sat Oct 19 00:04:33 2013 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 51C998AC; Sat, 19 Oct 2013 00:04:33 +0000 (UTC) (envelope-from prvs=100478bcf4=killing@multiplay.co.uk) Received: from mail1.multiplay.co.uk (mail1.multiplay.co.uk [85.236.96.23]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B8EDD27CE; Sat, 19 Oct 2013 00:04:32 +0000 (UTC) Received: from r2d2 ([82.69.141.170]) by mail1.multiplay.co.uk (mail1.multiplay.co.uk [85.236.96.23]) (MDaemon PRO v10.0.4) with ESMTP id md50006446446.msg; Sat, 19 Oct 2013 01:04:21 +0100 X-Spam-Processed: mail1.multiplay.co.uk, Sat, 19 Oct 2013 01:04:21 +0100 (not processed: message from valid local sender) X-MDDKIM-Result: neutral (mail1.multiplay.co.uk) X-MDRemoteIP: 82.69.141.170 X-Return-Path: prvs=100478bcf4=killing@multiplay.co.uk X-Envelope-From: killing@multiplay.co.uk Message-ID: <67CB0311850E47498A3E288F7A6CB9B5@multiplay.co.uk> From: "Steven Hartland" To: , References: Subject: Re: panic on close of /dev/xen/evtchn Date: Sat, 19 Oct 2013 01:04:39 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Oct 2013 00:04:33 -0000 Having a quick look I believe this device shouldn't even be initialised unless its running under xen so I believe the correct fix is:- svn diff sys/xen/evtchn/evtchn_dev.c Index: sys/xen/evtchn/evtchn_dev.c =================================================================== --- sys/xen/evtchn/evtchn_dev.c (revision 256554) +++ sys/xen/evtchn/evtchn_dev.c (working copy) @@ -325,23 +325,23 @@ .d_name = "evtchn", }; - /* XXX - if this device is ever supposed to support use by more than one process * this global static will have to go away */ static struct cdev *evtchn_dev; - - -static int +static void evtchn_dev_init(void *dummy __unused) { + if (!is_running_on_xen()) + return; + /* XXX I believe we don't need these leaving them here for now until we * have some semblance of it working */ mtx_init(&upcall_lock, "evtchup", NULL, MTX_DEF); - /* (DEVFS) create '/dev/misc/evtchn'. */ + /* (DEVFS) create '/dev/xen/evtchn'. */ evtchn_dev = make_dev(&evtchn_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "xen/evtchn"); mtx_init(&lock, "evch", NULL, MTX_SPIN | MTX_NOWITNESS); @@ -351,8 +351,6 @@ if (bootverbose) printf("Event-channel device installed.\n"); - - return 0; } SYSINIT(evtchn_dev_init, SI_SUB_DRIVERS, SI_ORDER_FIRST, evtchn_dev_init, NULL); Yes / No? Regards Steve ----- Original Message ----- From: "Steven Hartland" To: Sent: Friday, October 18, 2013 4:33 PM Subject: panic on close of /dev/xen/evtchn > Just had my test box panic while doing a: > find / -print0 | xargs -0 cat > > Ignoring the fact thats a silly command to run, the > panic appears to be when it ran: > cat /dev/xen/evtchn > > On the session it then printed: > cat: /dev/xen/evtchn: Interrupted system call > > At this point the system paniced. > > Panic transcribed from screen is: > > Stopped at evtchn_close:0x67: lock bts| %ebx,0xa00(%rax) > > db> bt > Tracing pdi 1533 tid 100370 td 0xfffff8000796e920 > evtchn_close() at evtchn_close+0x67/frame ... > devfs_close() at devs_close+0x188/frame ... > VOP_CLOSE_APV() at VOP_CLOSE_APV+0x139/frame ... > vn_close() at vn_close+0x139/frame ... > vn_closefile() at vn_closefile+0x48/frame ... > _fdrop() at _fdrop+0x29/frame ... > closef() at closef+0x1d1/frame ... > closefp() at closefp+0xa0/frame ... > amd64_syscall() at amd64_syscall+0x265/frame ... > Xfast_syscall() at Xfast_syscall+0xfb/frame ... > --- syscall (6, FreeBSD ELF64, sys_close), rip = 0x80094a9ea, rsp = 0x7ffffffb8e28, rbp -= 0x7ffffffb8f70 --- > > Regards > Steve > > ================================================ > This e.mail is private and confidential between Multiplay (UK) Ltd. and the person or entity to whom it is addressed. In the > event of misdirection, the recipient is prohibited from using, copying, printing or otherwise disseminating it or any > information contained in it. > In the event of misdirection, illegible or incomplete transmission please telephone +44 845 868 1337 > or return the E.mail to postmaster@multiplay.co.uk. > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" > ================================================ This e.mail is private and confidential between Multiplay (UK) Ltd. and the person or entity to whom it is addressed. In the event of misdirection, the recipient is prohibited from using, copying, printing or otherwise disseminating it or any information contained in it. In the event of misdirection, illegible or incomplete transmission please telephone +44 845 868 1337 or return the E.mail to postmaster@multiplay.co.uk. From owner-freebsd-hackers@FreeBSD.ORG Sat Oct 19 00:18:00 2013 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 57EB2CCB for ; Sat, 19 Oct 2013 00:18:00 +0000 (UTC) (envelope-from gibbs@FreeBSD.org) Received: from aslan.scsiguy.com (aslan.scsiguy.com [70.89.174.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1F6BB284F for ; Sat, 19 Oct 2013 00:17:59 +0000 (UTC) Received: from [10.0.0.21] (65.105.242.98.ptr.us.xo.net [65.105.242.98]) (authenticated bits=0) by aslan.scsiguy.com (8.14.7/8.14.5) with ESMTP id r9J0HomQ001362 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Fri, 18 Oct 2013 18:17:52 -0600 (MDT) (envelope-from gibbs@FreeBSD.org) Subject: Re: panic on close of /dev/xen/evtchn Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Content-Type: text/plain; charset=iso-8859-1 From: "Justin T. Gibbs" X-Priority: 3 In-Reply-To: <67CB0311850E47498A3E288F7A6CB9B5@multiplay.co.uk> Date: Fri, 18 Oct 2013 18:17:47 -0600 Content-Transfer-Encoding: quoted-printable Message-Id: <96E387D7-C92C-4945-AD7B-F9C917BCCDC6@FreeBSD.org> References: <67CB0311850E47498A3E288F7A6CB9B5@multiplay.co.uk> To: "Steven Hartland" X-Mailer: Apple Mail (2.1510) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (aslan.scsiguy.com [70.89.174.89]); Fri, 18 Oct 2013 18:17:53 -0600 (MDT) Cc: hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Oct 2013 00:18:00 -0000 With the roto-tilling of the event channel stuff, I'm not sure that the = evtchn device works properly in a Xen environment. We should probably just disable it = globally for now. I will look into it more later tonight and tomorrow. -- Justin On Oct 18, 2013, at 6:04 PM, "Steven Hartland" = wrote: > Having a quick look I believe this device shouldn't even > be initialised unless its running under xen so I believe > the correct fix is:- >=20 > svn diff sys/xen/evtchn/evtchn_dev.c > Index: sys/xen/evtchn/evtchn_dev.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- sys/xen/evtchn/evtchn_dev.c (revision 256554) > +++ sys/xen/evtchn/evtchn_dev.c (working copy) > @@ -325,23 +325,23 @@ > .d_name =3D "evtchn", > }; >=20 > - > /* XXX - if this device is ever supposed to support use by more than = one process > * this global static will have to go away > */ > static struct cdev *evtchn_dev; >=20 > - > - > -static int > +static void > evtchn_dev_init(void *dummy __unused) > { > + if (!is_running_on_xen()) > + return; > + > /* XXX I believe we don't need these leaving them here for now = until we > * have some semblance of it working > */ > mtx_init(&upcall_lock, "evtchup", NULL, MTX_DEF); >=20 > - /* (DEVFS) create '/dev/misc/evtchn'. */ > + /* (DEVFS) create '/dev/xen/evtchn'. */ > evtchn_dev =3D make_dev(&evtchn_devsw, 0, UID_ROOT, GID_WHEEL, = 0600, "xen/evtchn"); >=20 > mtx_init(&lock, "evch", NULL, MTX_SPIN | MTX_NOWITNESS); > @@ -351,8 +351,6 @@ >=20 > if (bootverbose) > printf("Event-channel device installed.\n"); > - > - return 0; > } >=20 > SYSINIT(evtchn_dev_init, SI_SUB_DRIVERS, SI_ORDER_FIRST, = evtchn_dev_init, NULL); >=20 > Yes / No? >=20 > Regards > Steve > ----- Original Message ----- From: "Steven Hartland" = > To: > Sent: Friday, October 18, 2013 4:33 PM > Subject: panic on close of /dev/xen/evtchn >=20 >=20 >> Just had my test box panic while doing a: >> find / -print0 | xargs -0 cat >>=20 >> Ignoring the fact thats a silly command to run, the >> panic appears to be when it ran: >> cat /dev/xen/evtchn >>=20 >> On the session it then printed: >> cat: /dev/xen/evtchn: Interrupted system call >>=20 >> At this point the system paniced. >>=20 >> Panic transcribed from screen is: >>=20 >> Stopped at evtchn_close:0x67: lock bts| %ebx,0xa00(%rax) >>=20 >> db> bt >> Tracing pdi 1533 tid 100370 td 0xfffff8000796e920 >> evtchn_close() at evtchn_close+0x67/frame ... >> devfs_close() at devs_close+0x188/frame ... >> VOP_CLOSE_APV() at VOP_CLOSE_APV+0x139/frame ... >> vn_close() at vn_close+0x139/frame ... >> vn_closefile() at vn_closefile+0x48/frame ... >> _fdrop() at _fdrop+0x29/frame ... >> closef() at closef+0x1d1/frame ... >> closefp() at closefp+0xa0/frame ... >> amd64_syscall() at amd64_syscall+0x265/frame ... >> Xfast_syscall() at Xfast_syscall+0xfb/frame ... >> --- syscall (6, FreeBSD ELF64, sys_close), rip =3D 0x80094a9ea, rsp =3D= 0x7ffffffb8e28, rbp -=3D 0x7ffffffb8f70 --- >>=20 >> Regards >> Steve >>=20 >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> This e.mail is private and confidential between Multiplay (UK) Ltd. = and the person or entity to whom it is addressed. In the event of = misdirection, the recipient is prohibited from using, copying, printing = or otherwise disseminating it or any information contained in it. >> In the event of misdirection, illegible or incomplete transmission = please telephone +44 845 868 1337 >> or return the E.mail to postmaster@multiplay.co.uk. >>=20 >> _______________________________________________ >> freebsd-hackers@freebsd.org mailing list >> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers >> To unsubscribe, send any mail to = "freebsd-hackers-unsubscribe@freebsd.org" >=20 >=20 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > This e.mail is private and confidential between Multiplay (UK) Ltd. = and the person or entity to whom it is addressed. In the event of = misdirection, the recipient is prohibited from using, copying, printing = or otherwise disseminating it or any information contained in it.=20 > In the event of misdirection, illegible or incomplete transmission = please telephone +44 845 868 1337 > or return the E.mail to postmaster@multiplay.co.uk. >=20 >=20 From owner-freebsd-hackers@FreeBSD.ORG Sat Oct 19 14:16:25 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 7EBCA969 for ; Sat, 19 Oct 2013 14:16:25 +0000 (UTC) (envelope-from electreg@list.ru) Received: from fallback3.mail.ru (fallback3.mail.ru [94.100.176.58]) by mx1.freebsd.org (Postfix) with ESMTP id 31CF02C23 for ; Sat, 19 Oct 2013 14:16:24 +0000 (UTC) Received: from f257.i.mail.ru (f257.i.mail.ru [94.100.178.222]) by fallback3.mail.ru (mPOP.Fallback_MX) with ESMTP id 055B4FBB00CF for ; Sat, 19 Oct 2013 18:15:57 +0400 (MSK) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=list.ru; s=mail; h=Content-Type:Message-ID:Reply-To:Date:Mime-Version:Subject:To:From; bh=uPGD+QYIrpLuD3M1c/fqbAqjQpg93DSYve5erRMCj5c=; b=QYB4RXLAElEgKGBl+WgH7KJIyPvmzLqgsvcem49RrFwC3WgWig//RBwQ7KjZYZYUvVZj9vmyoQ6rC+I6qqlBHH5Cg3TCEg5VLk8So0fSJjd//KtrZiRsxDBKbltpl2lp+6KmguBsfR0RO5zO6CT845KT2s6c9rEtWfGjkphUGaM=; Received: from mail by f257.i.mail.ru with local (envelope-from ) id 1VXXJk-0001n2-It for freebsd-hackers@freebsd.org; Sat, 19 Oct 2013 18:15:48 +0400 Received: from [188.16.132.92] by e.mail.ru with HTTP; Sat, 19 Oct 2013 18:15:48 +0400 From: =?UTF-8?B?QWxleGV5IEVnb3Jvdg==?= To: freebsd-hackers@freebsd.org Subject: =?UTF-8?B?ZGV0ZXJtaW5lIGRyaXZlJ3MgU0FTIHBvcnQ=?= Mime-Version: 1.0 X-Mailer: Mail.Ru Mailer 1.0 X-Originating-IP: [188.16.132.92] Date: Sat, 19 Oct 2013 18:15:48 +0400 X-Priority: 3 (Normal) Message-ID: <1382192148.119437035@f257.i.mail.ru> X-Mras: Ok X-Spam: undefined X-Mailman-Approved-At: Sat, 19 Oct 2013 14:49:58 +0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: =?UTF-8?B?QWxleGV5IEVnb3Jvdg==?= List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Oct 2013 14:16:25 -0000 IEhlbGxvIGFsbCwKCkkgaGF2ZSBhIHNlcnZlciB3aXRoIExTSSBIQkEgY2FyZCwgYW5kIHdoZW4g SSByZW1vdmUgZHJpdmUgSSBjYW4gc2VlIGZvbGxvd2luZyBtZXNzYWdlcyBpbiBsb2c6CgooZGEw Om1wczA6MDo1OjApOiBsb3N0IGRldmljZSAtIDAgb3V0c3RhbmRpbmcsIDIgcmVmcwooZGEwOm1w czA6MDo1OjApOiByZW1vdmluZyBkZXZpY2UgZW50cnkKCklzIHRoZXJlIGEgd2F5IHRvIGRldGVy bWluZSBwaHlzaWNhbCBwb3J0IChudW1iZXIgIjUiIGluICIoZGEwOm1wczA6MDo1OjAp77u/77u/ Iikgd2hlbiBkcml2ZSBpcyBpbnNlcnRlZD8gKEkgbmVlZCB0aGlzIHRvIGJlIGFibGUgdG8gY3Jl YXRlIGRldmljZSBzeW1saW5rcyBiYXNlZCBvbiBwaHlzaWNhbCBwb3J0KS4KClRoYW5rcyBpbiBh ZHZhbmNlLsKg From owner-freebsd-hackers@FreeBSD.ORG Sat Oct 19 19:52:15 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B6A005B1 for ; Sat, 19 Oct 2013 19:52:15 +0000 (UTC) (envelope-from list_freebsd@bluerosetech.com) Received: from yoshi.bluerosetech.com (yoshi.bluerosetech.com [IPv6:2607:f2f8:a450::66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9DAD92D6E for ; Sat, 19 Oct 2013 19:52:15 +0000 (UTC) Received: from chombo.houseloki.net (c-76-27-220-79.hsd1.wa.comcast.net [76.27.220.79]) by yoshi.bluerosetech.com (Postfix) with ESMTPSA id 8CB91E6069; Sat, 19 Oct 2013 12:52:14 -0700 (PDT) Received: from [IPv6:2601:7:1680:365:ecd7:4ff9:1462:7499] (unknown [IPv6:2601:7:1680:365:ecd7:4ff9:1462:7499]) by chombo.houseloki.net (Postfix) with ESMTPSA id 5FDCDDF4; Sat, 19 Oct 2013 12:52:13 -0700 (PDT) Message-ID: <5262E2DD.6030703@bluerosetech.com> Date: Sat, 19 Oct 2013 12:51:57 -0700 From: Darren Pilgrim User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: Alexey Egorov , freebsd-hackers@freebsd.org Subject: Re: determine drive's SAS port References: <1382192148.119437035@f257.i.mail.ru> In-Reply-To: <1382192148.119437035@f257.i.mail.ru> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Oct 2013 19:52:15 -0000 On 10/19/2013 7:15 AM, Alexey Egorov wrote: > Hello all, > > I have a server with LSI HBA card, and when I remove drive I can see > following messages in log: > > (da0:mps0:0:5:0): lost device - 0 outstanding, 2 refs > (da0:mps0:0:5:0): removing device entry > > Is there a way to determine physical port (number "5" in > "(da0:mps0:0:5:0)") when drive is inserted? (I need this to be able > to create device symlinks based on physical port). Many RAID cards can indicate a port by blinking the activity light. If not, perhaps you can trace the cables and get a PCB diagram? This is exactly why I write the WWN, serial and, for ZFS/graid, GPT label on a visible edge of the disk/sled.