From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37525) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SphNG-0003G5-KK for qemu-devel@nongnu.org; Fri, 13 Jul 2012 11:01:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SphNA-0000z8-He for qemu-devel@nongnu.org; Fri, 13 Jul 2012 11:01:42 -0400 Received: from mail-yw0-f45.google.com ([209.85.213.45]:43335) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SphNA-0000yx-E1 for qemu-devel@nongnu.org; Fri, 13 Jul 2012 11:01:36 -0400 Received: by yhpp34 with SMTP id p34so1946146yhp.4 for ; Fri, 13 Jul 2012 08:01:35 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20120713103717.GA5111@gagarin.0x63.nu> References: <1339503122-32264-1-git-send-email-anders@0x63.nu> <4FF624BA.7000208@web.de> <20120713103717.GA5111@gagarin.0x63.nu> From: Blue Swirl Date: Fri, 13 Jul 2012 15:01:14 +0000 Message-ID: Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH v2] slirp: Handle whole 127.0.0.0/8 network as local addresses. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anders Waldenborg Cc: Jan Kiszka , qemu-devel@nongnu.org On Fri, Jul 13, 2012 at 10:37 AM, Anders Waldenborg wrote: > Changes so translation of remote address to the host's ip address in > the virtual network happens for all addresses in the 127.0.0.0/8 > network, not just 127.0.0.1. > > This fixes so that hostfwd bound to addresses such as 127.0.0.2 works. > > Signed-off-by: Anders Waldenborg > --- > > Thanks for the review! > > Patch updated according to comments. > > Notice that the surrounding code in tcp_subr.c uses tabs for > indentation. Should I still use space as the coding style mandates > (and which makes checkpatch happy)? Yes, the goal is to get rid of tabs. > > slirp/main.h | 1 + > slirp/slirp.c | 3 +++ > slirp/tcp_subr.c | 6 ++++-- > 3 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/slirp/main.h b/slirp/main.h > index 028df4b..bf601e2 100644 > --- a/slirp/main.h > +++ b/slirp/main.h > @@ -31,6 +31,7 @@ extern char *exec_shell; > extern u_int curtime; > extern fd_set *global_readfds, *global_writefds, *global_xfds; > extern struct in_addr loopback_addr; > +extern in_addr_t loopback_mask; > extern char *username; > extern char *socket_path; > extern int towrite_max; > diff --git a/slirp/slirp.c b/slirp/slirp.c > index 90473eb..9787104 100644 > --- a/slirp/slirp.c > +++ b/slirp/slirp.c > @@ -29,6 +29,8 @@ > > /* host loopback address */ > struct in_addr loopback_addr; > +/* host loopback network mask */ > +in_addr_t loopback_mask; > > /* emulated hosts use the MAC addr 52:55:IP:IP:IP:IP */ > static const uint8_t special_ethaddr[ETH_ALEN] = { > @@ -191,6 +193,7 @@ static void slirp_init_once(void) > #endif > > loopback_addr.s_addr = htonl(INADDR_LOOPBACK); > + loopback_mask = htonl(IN_CLASSA_NET); > } > > static void slirp_state_save(QEMUFile *f, void *opaque); > diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c > index 0a545c4..064b5e8 100644 > --- a/slirp/tcp_subr.c > +++ b/slirp/tcp_subr.c > @@ -435,8 +435,10 @@ tcp_connect(struct socket *inso) > so->so_fport = addr.sin_port; > so->so_faddr = addr.sin_addr; > /* Translate connections from localhost to the real hostname */ > - if (so->so_faddr.s_addr == 0 || so->so_faddr.s_addr == loopback_addr.s_addr) > - so->so_faddr = slirp->vhost_addr; > + if (so->so_faddr.s_addr == 0 || > + (so->so_faddr.s_addr & loopback_mask) == > + (loopback_addr.s_addr & loopback_mask)) Please add braces. > + so->so_faddr = slirp->vhost_addr; > > /* Close the accept() socket, set right state */ > if (inso->so_state & SS_FACCEPTONCE) { > -- > 1.7.2.5 > >