* [Qemu-devel] [PATCH] Separate alias_addr (10.0.2.2) from our_addr in slirp
@ 2006-05-02 0:11 Ed Swierk
0 siblings, 0 replies; 3+ messages in thread
From: Ed Swierk @ 2006-05-02 0:11 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1026 bytes --]
On 5/1/06, Fabrice Bellard <fabrice@bellard.org> wrote:
> I am not sure this patch is sufficient: sometimes our_addr is used to
> open socket on the host side and 10.0.2.2 has a meanning only on the VM
> side.
Indeed, our_addr seems to be used for two distinct purposes:
- application protocol emulation code (like udp_emu() in udp.c) uses
the "host" address for opening sockets on the host; I'm not familiar
with the details of these protocols, but in any event it must be some
address that is meaningful to applications running on the host side;
- elsewhere in slirp, the "alias" address (10.0.2.2) is used to
rewrite the source address of packets originating from the host to the
VM; this address makes sense only within the VM.
The attached patch adds a new global, alias_addr, that is set to
10.0.2.2 and replaces our_addr in the latter cases. The patch also
changes getouraddr() so that it always returns either a "real" address
(as determined by gethostbyname(gethostname()) or 127.0.0.1, but never
10.0.2.2.
--Ed
[-- Attachment #2: qemu-alias-addr.patch --]
[-- Type: text/x-patch, Size: 4557 bytes --]
diff -BurN qemu.orig/slirp/ip_icmp.c qemu/slirp/ip_icmp.c
--- qemu.orig/slirp/ip_icmp.c 2004-04-22 00:10:47.000000000 +0000
+++ qemu/slirp/ip_icmp.c 2006-05-01 22:05:05.000000000 +0000
@@ -114,8 +114,7 @@
case ICMP_ECHO:
icp->icmp_type = ICMP_ECHOREPLY;
ip->ip_len += hlen; /* since ip_input subtracts this */
- if (ip->ip_dst.s_addr == our_addr.s_addr ||
- (ip->ip_dst.s_addr == (special_addr.s_addr|htonl(CTL_ALIAS))) ) {
+ if (ip->ip_dst.s_addr == alias_addr.s_addr) {
icmp_reflect(m);
} else {
struct socket *so;
@@ -161,7 +160,7 @@
icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno));
udp_detach(so);
}
- } /* if ip->ip_dst.s_addr == our_addr.s_addr */
+ } /* if ip->ip_dst.s_addr == alias_addr.s_addr */
break;
case ICMP_UNREACH:
/* XXX? report error? close socket? */
@@ -311,7 +310,7 @@
ip->ip_ttl = MAXTTL;
ip->ip_p = IPPROTO_ICMP;
ip->ip_dst = ip->ip_src; /* ip adresses */
- ip->ip_src = our_addr;
+ ip->ip_src = alias_addr;
(void ) ip_output((struct socket *)NULL, m);
diff -BurN qemu.orig/slirp/main.h qemu/slirp/main.h
--- qemu.orig/slirp/main.h 2004-07-12 22:33:04.000000000 +0000
+++ qemu/slirp/main.h 2006-05-01 22:05:05.000000000 +0000
@@ -34,6 +34,7 @@
extern fd_set *global_readfds, *global_writefds, *global_xfds;
extern struct in_addr ctl_addr;
extern struct in_addr special_addr;
+extern struct in_addr alias_addr;
extern struct in_addr our_addr;
extern struct in_addr loopback_addr;
extern struct in_addr dns_addr;
diff -BurN qemu.orig/slirp/misc.c qemu/slirp/misc.c
--- qemu.orig/slirp/misc.c 2006-04-23 19:41:17.000000000 +0000
+++ qemu/slirp/misc.c 2006-05-01 22:06:08.000000000 +0000
@@ -94,10 +94,8 @@
he = gethostbyname(buff);
if (he)
our_addr = *(struct in_addr *)he->h_addr;
- /* If the host doesn't have a useful IP address then use the
- guest side address. */
- if (our_addr.s_addr == 0 || our_addr.s_addr == loopback_addr.s_addr)
- our_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS);
+ if (our_addr.s_addr == 0)
+ our_addr.s_addr == loopback_addr.s_addr;
}
#if SIZEOF_CHAR_P == 8
diff -BurN qemu.orig/slirp/slirp.c qemu/slirp/slirp.c
--- qemu.orig/slirp/slirp.c 2006-05-01 16:05:27.000000000 +0000
+++ qemu/slirp/slirp.c 2006-05-01 22:05:05.000000000 +0000
@@ -9,6 +9,8 @@
/* address for slirp virtual addresses */
struct in_addr special_addr;
+/* virtual address alias for host */
+struct in_addr alias_addr;
const uint8_t special_ethaddr[6] = {
0x52, 0x54, 0x00, 0x12, 0x35, 0x00
@@ -154,6 +156,7 @@
}
inet_aton(CTL_SPECIAL, &special_addr);
+ alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS);
getouraddr();
}
diff -BurN qemu.orig/slirp/socket.c qemu/slirp/socket.c
--- qemu.orig/slirp/socket.c 2006-04-25 22:36:06.000000000 +0000
+++ qemu/slirp/socket.c 2006-05-01 22:05:05.000000000 +0000
@@ -596,7 +596,7 @@
getsockname(s,(struct sockaddr *)&addr,&addrlen);
so->so_fport = addr.sin_port;
if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr)
- so->so_faddr = our_addr;
+ so->so_faddr = alias_addr;
else
so->so_faddr = addr.sin_addr;
diff -BurN qemu.orig/slirp/tcp_subr.c qemu/slirp/tcp_subr.c
--- qemu.orig/slirp/tcp_subr.c 2004-09-18 19:33:56.000000000 +0000
+++ qemu/slirp/tcp_subr.c 2006-05-01 22:05:05.000000000 +0000
@@ -504,7 +504,7 @@
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 = our_addr;
+ so->so_faddr = alias_addr;
/* Close the accept() socket, set right state */
if (inso->so_state & SS_FACCEPTONCE) {
@@ -840,7 +840,7 @@
if (ns->so_faddr.s_addr == 0 ||
ns->so_faddr.s_addr == loopback_addr.s_addr)
- ns->so_faddr = our_addr;
+ ns->so_faddr = alias_addr;
ns->so_iptos = tcp_tos(ns);
tp = sototcpcb(ns);
diff -BurN qemu.orig/slirp/udp.c qemu/slirp/udp.c
--- qemu.orig/slirp/udp.c 2005-07-03 17:08:43.000000000 +0000
+++ qemu/slirp/udp.c 2006-05-01 22:05:05.000000000 +0000
@@ -657,7 +657,7 @@
getsockname(so->s,(struct sockaddr *)&addr,&addrlen);
so->so_fport = addr.sin_port;
if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr)
- so->so_faddr = our_addr;
+ so->so_faddr = alias_addr;
else
so->so_faddr = addr.sin_addr;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] Separate alias_addr (10.0.2.2) from our_addr in slirp
@ 2006-05-02 0:58 Ben Taylor
2006-05-02 4:41 ` Ed Swierk
0 siblings, 1 reply; 3+ messages in thread
From: Ben Taylor @ 2006-05-02 0:58 UTC (permalink / raw)
To: qemu-devel
---- Ed Swierk <eswierk@arastra.com> wrote:
> On 5/1/06, Fabrice Bellard <fabrice@bellard.org> wrote:
> I am not sure this patch is sufficient: sometimes our_addr is used to
> open socket on the host side and 10.0.2.2 has a meanning only on the VM
> side.
Indeed, our_addr seems to be used for two distinct purposes:
- application protocol emulation code (like udp_emu() in udp.c) uses
the "host" address for opening sockets on the host; I'm not familiar
with the details of these protocols, but in any event it must be some
address that is meaningful to applications running on the host side;
- elsewhere in slirp, the "alias" address (10.0.2.2) is used to
rewrite the source address of packets originating from the host to the
VM; this address makes sense only within the VM.
The attached patch adds a new global, alias_addr, that is set to
10.0.2.2 and replaces our_addr in the latter cases. The patch also
changes getouraddr() so that it always returns either a "real" address
(as determined by gethostbyname(gethostname()) or 127.0.0.1, but never
10.0.2.2.
--Ed
Am I seeing a problem in line 98 of slirp/misc.c? The line above reads:
if (our_addr.s_addr == 0)
our_addr.s_addr == loopback_addr.s_addr:
Shouldn't that be "our_addr.s_addr = loopback_addr.s_addr;" (Single =)
Ben
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] Separate alias_addr (10.0.2.2) from our_addr in slirp
2006-05-02 0:58 Ben Taylor
@ 2006-05-02 4:41 ` Ed Swierk
0 siblings, 0 replies; 3+ messages in thread
From: Ed Swierk @ 2006-05-02 4:41 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 168 bytes --]
On 5/1/06, Ben Taylor <sol10x86@cox.net> wrote:
> Am I seeing a problem in line 98 of slirp/misc.c?
Yes--thanks for finding that.
An amended patch is attached.
--Ed
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: qemu-alias-addr.patch --]
[-- Type: text/x-patch; name="qemu-alias-addr.patch", Size: 4556 bytes --]
diff -BurN qemu.orig/slirp/ip_icmp.c qemu/slirp/ip_icmp.c
--- qemu.orig/slirp/ip_icmp.c 2004-04-22 00:10:47.000000000 +0000
+++ qemu/slirp/ip_icmp.c 2006-05-01 22:05:05.000000000 +0000
@@ -114,8 +114,7 @@
case ICMP_ECHO:
icp->icmp_type = ICMP_ECHOREPLY;
ip->ip_len += hlen; /* since ip_input subtracts this */
- if (ip->ip_dst.s_addr == our_addr.s_addr ||
- (ip->ip_dst.s_addr == (special_addr.s_addr|htonl(CTL_ALIAS))) ) {
+ if (ip->ip_dst.s_addr == alias_addr.s_addr) {
icmp_reflect(m);
} else {
struct socket *so;
@@ -161,7 +160,7 @@
icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno));
udp_detach(so);
}
- } /* if ip->ip_dst.s_addr == our_addr.s_addr */
+ } /* if ip->ip_dst.s_addr == alias_addr.s_addr */
break;
case ICMP_UNREACH:
/* XXX? report error? close socket? */
@@ -311,7 +310,7 @@
ip->ip_ttl = MAXTTL;
ip->ip_p = IPPROTO_ICMP;
ip->ip_dst = ip->ip_src; /* ip adresses */
- ip->ip_src = our_addr;
+ ip->ip_src = alias_addr;
(void ) ip_output((struct socket *)NULL, m);
diff -BurN qemu.orig/slirp/main.h qemu/slirp/main.h
--- qemu.orig/slirp/main.h 2004-07-12 22:33:04.000000000 +0000
+++ qemu/slirp/main.h 2006-05-01 22:05:05.000000000 +0000
@@ -34,6 +34,7 @@
extern fd_set *global_readfds, *global_writefds, *global_xfds;
extern struct in_addr ctl_addr;
extern struct in_addr special_addr;
+extern struct in_addr alias_addr;
extern struct in_addr our_addr;
extern struct in_addr loopback_addr;
extern struct in_addr dns_addr;
diff -BurN qemu.orig/slirp/misc.c qemu/slirp/misc.c
--- qemu.orig/slirp/misc.c 2006-04-23 19:41:17.000000000 +0000
+++ qemu/slirp/misc.c 2006-05-01 22:06:08.000000000 +0000
@@ -94,10 +94,8 @@
he = gethostbyname(buff);
if (he)
our_addr = *(struct in_addr *)he->h_addr;
- /* If the host doesn't have a useful IP address then use the
- guest side address. */
- if (our_addr.s_addr == 0 || our_addr.s_addr == loopback_addr.s_addr)
- our_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS);
+ if (our_addr.s_addr == 0)
+ our_addr.s_addr = loopback_addr.s_addr;
}
#if SIZEOF_CHAR_P == 8
diff -BurN qemu.orig/slirp/slirp.c qemu/slirp/slirp.c
--- qemu.orig/slirp/slirp.c 2006-05-01 16:05:27.000000000 +0000
+++ qemu/slirp/slirp.c 2006-05-01 22:05:05.000000000 +0000
@@ -9,6 +9,8 @@
/* address for slirp virtual addresses */
struct in_addr special_addr;
+/* virtual address alias for host */
+struct in_addr alias_addr;
const uint8_t special_ethaddr[6] = {
0x52, 0x54, 0x00, 0x12, 0x35, 0x00
@@ -154,6 +156,7 @@
}
inet_aton(CTL_SPECIAL, &special_addr);
+ alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS);
getouraddr();
}
diff -BurN qemu.orig/slirp/socket.c qemu/slirp/socket.c
--- qemu.orig/slirp/socket.c 2006-04-25 22:36:06.000000000 +0000
+++ qemu/slirp/socket.c 2006-05-01 22:05:05.000000000 +0000
@@ -596,7 +596,7 @@
getsockname(s,(struct sockaddr *)&addr,&addrlen);
so->so_fport = addr.sin_port;
if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr)
- so->so_faddr = our_addr;
+ so->so_faddr = alias_addr;
else
so->so_faddr = addr.sin_addr;
diff -BurN qemu.orig/slirp/tcp_subr.c qemu/slirp/tcp_subr.c
--- qemu.orig/slirp/tcp_subr.c 2004-09-18 19:33:56.000000000 +0000
+++ qemu/slirp/tcp_subr.c 2006-05-01 22:05:05.000000000 +0000
@@ -504,7 +504,7 @@
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 = our_addr;
+ so->so_faddr = alias_addr;
/* Close the accept() socket, set right state */
if (inso->so_state & SS_FACCEPTONCE) {
@@ -840,7 +840,7 @@
if (ns->so_faddr.s_addr == 0 ||
ns->so_faddr.s_addr == loopback_addr.s_addr)
- ns->so_faddr = our_addr;
+ ns->so_faddr = alias_addr;
ns->so_iptos = tcp_tos(ns);
tp = sototcpcb(ns);
diff -BurN qemu.orig/slirp/udp.c qemu/slirp/udp.c
--- qemu.orig/slirp/udp.c 2005-07-03 17:08:43.000000000 +0000
+++ qemu/slirp/udp.c 2006-05-01 22:05:05.000000000 +0000
@@ -657,7 +657,7 @@
getsockname(so->s,(struct sockaddr *)&addr,&addrlen);
so->so_fport = addr.sin_port;
if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr)
- so->so_faddr = our_addr;
+ so->so_faddr = alias_addr;
else
so->so_faddr = addr.sin_addr;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-05-02 4:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-02 0:11 [Qemu-devel] [PATCH] Separate alias_addr (10.0.2.2) from our_addr in slirp Ed Swierk
-- strict thread matches above, loose matches on Subject: below --
2006-05-02 0:58 Ben Taylor
2006-05-02 4:41 ` Ed Swierk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).