From owner-freebsd-hackers@FreeBSD.ORG Fri Jan 7 13:39:04 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 822C91065670 for ; Fri, 7 Jan 2011 13:39:04 +0000 (UTC) (envelope-from rea@codelabs.ru) Received: from 0.mx.codelabs.ru (0.mx.codelabs.ru [144.206.177.45]) by mx1.freebsd.org (Postfix) with ESMTP id 34CA48FC12 for ; Fri, 7 Jan 2011 13:39:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codelabs.ru; s=two; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=qtdhg+y3Ay0/ZkMAgchedcFfrAzirOKWMgQRLiPMIMY=; b=QmqPSKhS6PkrwGhtG1wZn3+lyVwnY3NQ9kbyuuuwr+zncuMFjtCSqXUaztjGeSfdb5zFe184++x6zqyyG/JocGVnOj5iHUVAHkKmXMAYzXBdt/3Gf7GYaHgCS3E0KhIdsa3JfDg/vQdtdhMycxMVfhSNStwhhdEaFHXD4yCZ+XDF2WZeuy6rQ0wPVXnS7gjvk5eWcnfmYaLZ6Q+ZeYvWQ/aeetwhi8dfykajQgmTRzvjEPrjdDcRogaS825uW6vhBAseiEBvX7I9qglM5rr3WKtW9R8kSCzwzveB5Q50O21imCHyUk6K/6XLquP7lKvmVnOKqIa+aUAWVNIe1qR6WA==; Received: from amnesiac.at.no.dns (ppp85-141-65-122.pppoe.mtu-net.ru [85.141.65.122]) by 0.mx.codelabs.ru with esmtpsa (TLSv1:AES256-SHA:256) id 1PbCX0-000HkF-MG; Fri, 07 Jan 2011 16:39:02 +0300 Date: Fri, 7 Jan 2011 16:38:59 +0300 From: Eygene Ryabinkin To: joris dedieu Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="IR1Y5IvQhrKgS4e6" Content-Disposition: inline In-Reply-To: Sender: rea@codelabs.ru Cc: freebsd-hackers Subject: Re: binding non local ip. X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jan 2011 13:39:04 -0000 --IR1Y5IvQhrKgS4e6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Fri, Jan 07, 2011 at 01:57:21PM +0100, joris dedieu wrote: > What do you think about it ? [...] > +static int bindany =3D 0; /* 1 allows to bind a non local ip */ > +SYSCTL_INT(_net_inet_ip, OID_AUTO, bindany, CTLFLAG_RW, &bindany, 0, > + "Allow to bind a non local ip"); On at least 8.x, you will likely want to use VNET_* macros to enable your new sysctl to be virtualized. Something like this: {{{ VNET_DEFINE(int, inp_bindany) =3D 0; SYSCTL_VNET_INT(_net_inet_ip, OID_AUTO, bindany, CTLFLAG_RW, &VNET_NAME(inp_bindany), 0, "Force INP_BINDANY on all sockets"); }}} and use VNET(inp_bindany) in subsequent code. > if ((inp->inp_flags & INP_BINDANY) =3D=3D 0 && > - ifa_ifwithaddr_check((struct sockaddr *)sin) = =3D=3D 0) > - return (EADDRNOTAVAIL); > + ifa_ifwithaddr_check((struct sockaddr *)sin) = =3D=3D 0) { > + if(bindany > 0) > + inp->inp_flags |=3D INP_BINDANY; > + else > + return (EADDRNOTAVAIL); > + } The check is better to be rewritten as {{{ if (VNET(inp_bindany) > 0) inp->inp_flags |=3D INP_BINDANY; else if ((inp->inp_flags & INP_BINDANY) =3D=3D 0 && ifa_ifwithaddr_check((struct sockaddr *)sin) = =3D=3D 0) return (EADDRNOTAVAIL); }}} it will save you two conditionals if bindany is enabled. On the other hand, if you will set the value of VNET(inp_bindany) to INP_BINDANY instead of 1, you can even do {{{ inp->inp_flags |=3D VNET(inp_bindany); if ((inp->inp_flags & INP_BINDANY) =3D=3D 0 && ifa_ifwithaddr_check((struct sockaddr *)sin) = =3D=3D 0) return (EADDRNOTAVAIL); }}} and this will eliminate one branching instruction at the expense of memory access and fast logical operation. --=20 Eygene Ryabinkin ,,,^..^,,, [ Life's unfair - but root password helps! | codelabs.ru ] [ 82FE 06BC D497 C0DE 49EC 4FF0 16AF 9EAE 8152 ECFB | freebsd.org ] --IR1Y5IvQhrKgS4e6 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (FreeBSD) iF4EAREIAAYFAk0nF3MACgkQFq+eroFS7PuMGQD/YB6OMYyGB1djniDCYAr+PVYh StIjtDcjFWMgjOiWEoQA/0G9mJnH0UcjAXLAVhGkqxP2xbCOvBejXe6gCzIM8Wp+ =b8TD -----END PGP SIGNATURE----- --IR1Y5IvQhrKgS4e6--