Skip to content

Commit

Permalink
slirp: Handle whole 127.0.0.0/8 network as local addresses.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
wanders authored and jan-kiszka committed Aug 3, 2012
1 parent 0f66998 commit 648cd33
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions slirp/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions slirp/slirp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions slirp/tcp_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,11 @@ 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)) {
so->so_faddr = slirp->vhost_addr;
}

/* Close the accept() socket, set right state */
if (inso->so_state & SS_FACCEPTONCE) {
Expand Down

0 comments on commit 648cd33

Please sign in to comment.