Date: Fri, 7 Jan 2011 16:38:59 +0300 From: Eygene Ryabinkin <rea@freebsd.org> To: joris dedieu <joris.dedieu@gmail.com> Cc: freebsd-hackers <freebsd-hackers@freebsd.org> Subject: Re: binding non local ip. Message-ID: <I0E3jOweM2JFYO1RRyeZ3hfTJPY@5UW8B3LwPEGInFShts5A7R/S2Yo> In-Reply-To: <AANLkTimJBkTdgs4P=XjHyTCinfCOn0Ku8bEVcR-q=Dzc@mail.gmail.com> References: <AANLkTimJBkTdgs4P=XjHyTCinfCOn0Ku8bEVcR-q=Dzc@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?I0E3jOweM2JFYO1RRyeZ3hfTJPY>