From owner-freebsd-net@FreeBSD.ORG Tue Jan 26 16:41:03 2010 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 994A61065693; Tue, 26 Jan 2010 16:41:03 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 6D8EF8FC12; Tue, 26 Jan 2010 16:41:03 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 07E7246B2C; Tue, 26 Jan 2010 11:41:03 -0500 (EST) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPA id 564C08A01F; Tue, 26 Jan 2010 11:41:02 -0500 (EST) From: John Baldwin To: d@delphij.net Date: Tue, 26 Jan 2010 11:40:50 -0500 User-Agent: KMail/1.12.1 (FreeBSD/7.2-CBSD-20100120; KDE/4.3.1; amd64; ; ) References: <4B5E16DB.2080203@delphij.net> In-Reply-To: <4B5E16DB.2080203@delphij.net> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201001261140.51006.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Tue, 26 Jan 2010 11:41:02 -0500 (EST) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: delphij@freebsd.org, freebsd-net@freebsd.org, Robert Watson Subject: Re: [PATCH] Interface description X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jan 2010 16:41:03 -0000 On Monday 25 January 2010 5:10:35 pm Xin LI wrote: > Hi, > > I have revised the patchset based on feedback received. This version: > > - Unbreak the case when libpcap is being built for pre-ifdescr world. > - Documents the descr and -descr primitives for ifconfig(8), they are > intended for OpenBSD compatibility. > - Simplify and concentrate memory allocation in ifconfig(8) > - Document the use of nul terminated buffer and the meaning of length > parameter > - Use char* instead of sbuf and simplify the logic in kernel part. > > Hopefully this version would address all problems raised by reviewers. > Comments? I just have two suggestions/comments: @@ -295,6 +295,7 @@ struct ifreq { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; + struct { size_t length; caddr_t buffer; } ifru_buffer; short ifru_flags[2]; short ifru_index; int ifru_jid; I prefer to not have this all on one line, but to instead be: struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct { size_t length; caddr_t buffer; } ifru_buffer; Even better would be to actually define a separate type earlier in the file I think: struct ifreq_buffer { void *buffer; size_t length; }; and then just use: struct ifreq_buffer ifru_buffer; I think caddr_t is deprecated in favor of void * for new APIs at least. Second, it would be nice if SIOCGIFDESCR provided length feedback to userland similar to sysctl(3). Maybe change the code to set ifr.ifr_buffer.length to the required length when returning ENAMETOOLONG. Userland can then just skip to that length directly, or instead use an idiom similar to sysctl where it does the following: ifr.ifr_buffer.buffer = NULL; ifr.ifr_buffer.length = 0; for (;;) { if (ioctl(s, SIOCGIFDESCR, &ifr) == 0) { /* have descr in ifr.ifr_buffer.buffer */ } else if (errno == ENAMETOOLONG) { ifr.ifr_buffer.buffer = reallocf(ifr.ifr_buffer.buffer, ifr.ifr_buffer.length); if (ifr.ifr_buffer.buffer == NULL) { /* handle realloc() failure, break */ } continue; } else { /* handle error, break */ } } -- John Baldwin