From owner-freebsd-net@FreeBSD.ORG Thu Sep 1 07:54:51 2005 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 157BD16A41F for ; Thu, 1 Sep 2005 07:54:51 +0000 (GMT) (envelope-from vanhu@zeninc.net) Received: from corwin.easynet.fr (smarthost162.mail.easynet.fr [212.180.1.162]) by mx1.FreeBSD.org (Postfix) with ESMTP id B0B3E43D49 for ; Thu, 1 Sep 2005 07:54:49 +0000 (GMT) (envelope-from vanhu@zeninc.net) Received: from easyconnect2121135-233.clients.easynet.fr ([212.11.35.233] helo=smtp.zeninc.net) by corwin.easynet.fr with esmtp (Exim 4.50) id 1EAjuG-0000mv-3k for freebsd-net@freebsd.org; Thu, 01 Sep 2005 09:54:44 +0200 Received: by smtp.zeninc.net (smtpd, from userid 1000) id E5A273F61; Thu, 1 Sep 2005 09:54:42 +0200 (CEST) Date: Thu, 1 Sep 2005 09:54:42 +0200 From: VANHULLEBUS Yvan To: freebsd-net@freebsd.org Message-ID: <20050901075442.GA18666@zen.inc> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: All mail clients suck. This one just sucks less. Subject: sbspace() / sbappendaddr() problem 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: Thu, 01 Sep 2005 07:54:51 -0000 Hi all. I have some reccurent problems with PFKey interafce for a while, whith ENOBUFS errors. While tracking down the problem, I found that a test goes wrong in sbappendaddr(), in kern_uipc_socket2.c, because the "space" variable (an int) gets "bigger" than the result of sbspace(sb), which shlould not happen. After having a deeper look at sbspace() macro, I noticed that there are some potential cast/sign problems with this macro (this is specified in the comments of the macro). So I wrote a new version of the macro, which should avoir all problems: #define sbspace(sb) \ (ulmin( ( (sb)->sb_hiwat > (sb)->sb_cc ? (sb)->sb_hiwat - (sb)->sb_cc : 0), \ (sb)->sb_mbmax > (sb)->sb_mbcnt ? (sb)->sb_mbmax - (sb)->sb_mbcnt : 0))) Then I set up the type of "space" variable in sbappendaddr() as u_long, and I have no more problems for now. But as this function and this macro are used on some other parts of the kernel, I don't know if I solved all problems, or if I generated new problems elsewhere while solving one. Does someone have any comments on this new sbspace() ? Yvan. -- NETASQ - Secure Internet Connectivity http://www.netasq.com