From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7PHF-0005Ut-Qj for qemu-devel@nongnu.org; Fri, 11 Dec 2015 10:06:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a7PHB-0005mj-9s for qemu-devel@nongnu.org; Fri, 11 Dec 2015 10:06:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58928) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7PHB-0005mY-4Q for qemu-devel@nongnu.org; Fri, 11 Dec 2015 10:06:29 -0500 References: <20151211001505.GV2905@var.home> <1449792930-27293-1-git-send-email-samuel.thibault@ens-lyon.org> <1449792930-27293-6-git-send-email-samuel.thibault@ens-lyon.org> From: Thomas Huth Message-ID: <566AE66E.1030902@redhat.com> Date: Fri, 11 Dec 2015 16:06:22 +0100 MIME-Version: 1.0 In-Reply-To: <1449792930-27293-6-git-send-email-samuel.thibault@ens-lyon.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 06/18] slirp: Factorizing and cleaning solookup() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Samuel Thibault , qemu-devel@nongnu.org Cc: zhanghailiang , Li Zhijian , Stefan Hajnoczi , Jason Wang , Dave Gilbert , Vasiliy Tolstov , Huangpeng , Gonglei , Jan Kiszka , Yang Hongyang , Guillaume Subiron On 11/12/15 01:15, Samuel Thibault wrote: > From: Guillaume Subiron >=20 > This patch makes solookup() compatible with varying address families. A= lso, > this function was only compatible with TCP. Having the socket list in > argument, it is now compatible with UDP too. Finally, some optimization > code is factorized inside the function (the function look at the last > returned result before browsing the complete socket list). >=20 > This also adds a sockaddr_equal() function to compare two > sockaddr_storage. I'd maybe also split this patch into two - first introduce the sockaddr_equal() function, then do the other changes. If you do too much stuff in one patch, it gets more difficult to read. > Signed-off-by: Guillaume Subiron > Signed-off-by: Samuel Thibault > --- [...] > diff --git a/slirp/socket.h b/slirp/socket.h > index b27bbb2..644216c 100644 > --- a/slirp/socket.h > +++ b/slirp/socket.h > @@ -87,7 +87,28 @@ struct socket { > #define SS_HOSTFWD 0x1000 /* Socket describes host->guest forwarding = */ > #define SS_INCOMING 0x2000 /* Connection was initiated by a host on t= he internet */ > =20 > -struct socket * solookup(struct socket *, struct in_addr, u_int, struc= t in_addr, u_int); > +static inline int sockaddr_equal(struct sockaddr_storage *a, > + struct sockaddr_storage *b) > +{ > + if (a->ss_family !=3D b->ss_family) { > + return 0; > + } else { > + switch (a->ss_family) { > + case AF_INET: > + { > + struct sockaddr_in *a4 =3D (struct sockaddr_in *) a; > + struct sockaddr_in *b4 =3D (struct sockaddr_in *) b; > + return (a4->sin_addr.s_addr =3D=3D b4->sin_addr.s_addr > + && a4->sin_port =3D=3D b4->sin_port); > + } > + default: > + assert(0); > + } > + } > +} Since the first part of the if statement always returns, you could get rid of one level of indentation here by removing the "else". Thomas