* [Qemu-devel] [PATCH 0/2] slirp udp fixes @ 2008-04-10 4:22 Jason Wessel 2008-04-10 4:22 ` [Qemu-devel] [PATCH 1/2] Fix slirp udp source address contamination Jason Wessel 0 siblings, 1 reply; 5+ messages in thread From: Jason Wessel @ 2008-04-10 4:22 UTC (permalink / raw) To: qemu-devel 2 patches follow to fix some udp problems with slirp Jason Wessel (2): Fix slirp udp source address contamination Fix slirp mac address init slirp/libslirp.h | 2 ++ slirp/slirp.c | 5 +++++ slirp/udp.c | 3 ++- vl.c | 3 +++ 4 files changed, 12 insertions(+), 1 deletions(-) ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/2] Fix slirp udp source address contamination 2008-04-10 4:22 [Qemu-devel] [PATCH 0/2] slirp udp fixes Jason Wessel @ 2008-04-10 4:22 ` Jason Wessel 2008-04-10 4:22 ` [Qemu-devel] [PATCH 2/2] Fix slirp mac address init Jason Wessel 0 siblings, 1 reply; 5+ messages in thread From: Jason Wessel @ 2008-04-10 4:22 UTC (permalink / raw) To: qemu-devel When using slirp the "special address" translation should only be used when the source address is the loopback, else the udp packets show up with the wrong source address and cannot be routed back to the original source by applications running inside the QEMU instance. The problem can be observed by using kgdboe from inside QEMU where you add a port redirection with slirp networking such as "-redir udp:4445::6443". Using a second host or connecting gdb to the IP address address of the host that the QEMU instance is running on instead of using the loopback address will fail because the source address will get translated when it goes through the redirection. With the patch, you can connect to kgdboe via the loopback on port 4445 or from another host. Signed-off-by: Jason Wessel <jason.wessel@windriver.com> --- slirp/udp.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/slirp/udp.c b/slirp/udp.c index c48923b..0dd7da6 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -318,7 +318,8 @@ int udp_output(struct socket *so, struct mbuf *m, struct sockaddr_in saddr, daddr; saddr = *addr; - if ((so->so_faddr.s_addr & htonl(0xffffff00)) == special_addr.s_addr) { + if ((so->so_faddr.s_addr & htonl(0xffffff00)) == special_addr.s_addr && + addr->sin_addr.s_addr == htonl(0x7f000001)) { saddr.sin_addr.s_addr = so->so_faddr.s_addr; if ((so->so_faddr.s_addr & htonl(0x000000ff)) == htonl(0xff)) saddr.sin_addr.s_addr = alias_addr.s_addr; -- 1.5.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/2] Fix slirp mac address init 2008-04-10 4:22 ` [Qemu-devel] [PATCH 1/2] Fix slirp udp source address contamination Jason Wessel @ 2008-04-10 4:22 ` Jason Wessel 2008-04-12 12:44 ` Aurelien Jarno 0 siblings, 1 reply; 5+ messages in thread From: Jason Wessel @ 2008-04-10 4:22 UTC (permalink / raw) To: qemu-devel It is not possible to communicate to a qemu instance via a slirp redirected udp port until the OS running in qemu has executed a dhcp request. This is because the internal qemu dhcp server populates the slirp mac address. Until the dhcp request is processed the translated mac address is zeroed out and the packets bound for the target OS will not correctly get the mac address of the qemu ethernet adapter. The solution is to initialize the slirp mac address when the qemu network adapter client is initialized. This allows the use bi-directional udp redirection with a static IP address configured on the qemu ethernet adapter. Signed-off-by: Jason Wessel <jason.wessel@windriver.com> --- slirp/libslirp.h | 2 ++ slirp/slirp.c | 5 +++++ vl.c | 3 +++ 3 files changed, 10 insertions(+), 0 deletions(-) diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 7e4cfa9..e862de6 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -7,6 +7,8 @@ extern "C" { void slirp_init(void); +void slirp_initial_mac(uint8_t *macaddr); + void slirp_select_fill(int *pnfds, fd_set *readfds, fd_set *writefds, fd_set *xfds); diff --git a/slirp/slirp.c b/slirp/slirp.c index 303f482..8adc027 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -136,6 +136,11 @@ static void slirp_cleanup(void) } #endif +void slirp_initial_mac(uint8_t *macaddr) +{ + memcpy(client_ethaddr, macaddr, sizeof(client_ethaddr)); +} + void slirp_init(void) { // debug_init("/tmp/slirp.log", DEBUG_DEFAULT); diff --git a/vl.c b/vl.c index 6aa27c2..2fd1868 100644 --- a/vl.c +++ b/vl.c @@ -4792,6 +4792,9 @@ static int net_client_init(const char *str) return -1; } } +#ifdef CONFIG_SLIRP + slirp_initial_mac(macaddr); +#endif if (get_param_value(buf, sizeof(buf), "model", p)) { nd->model = strdup(buf); } -- 1.5.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 2/2] Fix slirp mac address init 2008-04-10 4:22 ` [Qemu-devel] [PATCH 2/2] Fix slirp mac address init Jason Wessel @ 2008-04-12 12:44 ` Aurelien Jarno 2008-04-12 14:21 ` Jason Wessel 0 siblings, 1 reply; 5+ messages in thread From: Aurelien Jarno @ 2008-04-12 12:44 UTC (permalink / raw) To: qemu-devel On Wed, Apr 09, 2008 at 11:22:23PM -0500, Jason Wessel wrote: > It is not possible to communicate to a qemu instance via a slirp > redirected udp port until the OS running in qemu has executed a dhcp > request. This is because the internal qemu dhcp server populates the Could you please more details? I am unable to reproduce the problem. A simple netcat listening on a UDP port in the guest, and another netcat in the host to send data works here. > slirp mac address. Until the dhcp request is processed the translated > mac address is zeroed out and the packets bound for the target OS will > not correctly get the mac address of the qemu ethernet adapter. > > The solution is to initialize the slirp mac address when the qemu > network adapter client is initialized. This allows the use > bi-directional udp redirection with a static IP address configured on > the qemu ethernet adapter. > > Signed-off-by: Jason Wessel <jason.wessel@windriver.com> > --- > slirp/libslirp.h | 2 ++ > slirp/slirp.c | 5 +++++ > vl.c | 3 +++ > 3 files changed, 10 insertions(+), 0 deletions(-) > > diff --git a/slirp/libslirp.h b/slirp/libslirp.h > index 7e4cfa9..e862de6 100644 > --- a/slirp/libslirp.h > +++ b/slirp/libslirp.h > @@ -7,6 +7,8 @@ extern "C" { > > void slirp_init(void); > > +void slirp_initial_mac(uint8_t *macaddr); > + > void slirp_select_fill(int *pnfds, > fd_set *readfds, fd_set *writefds, fd_set *xfds); > > diff --git a/slirp/slirp.c b/slirp/slirp.c > index 303f482..8adc027 100644 > --- a/slirp/slirp.c > +++ b/slirp/slirp.c > @@ -136,6 +136,11 @@ static void slirp_cleanup(void) > } > #endif > > +void slirp_initial_mac(uint8_t *macaddr) > +{ > + memcpy(client_ethaddr, macaddr, sizeof(client_ethaddr)); > +} > + > void slirp_init(void) > { > // debug_init("/tmp/slirp.log", DEBUG_DEFAULT); > diff --git a/vl.c b/vl.c > index 6aa27c2..2fd1868 100644 > --- a/vl.c > +++ b/vl.c > @@ -4792,6 +4792,9 @@ static int net_client_init(const char *str) > return -1; > } > } > +#ifdef CONFIG_SLIRP > + slirp_initial_mac(macaddr); > +#endif > if (get_param_value(buf, sizeof(buf), "model", p)) { > nd->model = strdup(buf); > } > -- > 1.5.4 > > > > -- .''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' aurel32@debian.org | aurelien@aurel32.net `- people.debian.org/~aurel32 | www.aurel32.net ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 2/2] Fix slirp mac address init 2008-04-12 12:44 ` Aurelien Jarno @ 2008-04-12 14:21 ` Jason Wessel 0 siblings, 0 replies; 5+ messages in thread From: Jason Wessel @ 2008-04-12 14:21 UTC (permalink / raw) To: qemu-devel I figured most people do not have kgdboe as a built-in, and the qemu patch is definitely against an edge case. The problem is better described by the case where no packets have been transmitted by the qemu target and you desire to have the first communication occur externally. The edge case can happen if you do something like use kgdboe before the kernel is booted up. The OS will configure the ethernet interface to listen and wait for the debugger to attach, and in this case the MAC address is not set in the slirp because no packets have ever been transmitted yet. You would have do something like: qemu-redir udp:4445::6443 -append "console=ttyS0 kgdboe=@10.0.2.15/,@10.0.2.2/ kgdbwait" Then you would connect gdb with "target remote udp:localhost:4445". I will gladly provide you with a kernel that has kgdboe built in and some exact boot arguments if you would like to see the problem first hand. Jason. Aurelien Jarno wrote: > On Wed, Apr 09, 2008 at 11:22:23PM -0500, Jason Wessel wrote: > >> It is not possible to communicate to a qemu instance via a slirp >> redirected udp port until the OS running in qemu has executed a dhcp >> request. This is because the internal qemu dhcp server populates the >> > > Could you please more details? I am unable to reproduce the problem. A > simple netcat listening on a UDP port in the guest, and another netcat > in the host to send data works here. > > >> slirp mac address. Until the dhcp request is processed the translated >> mac address is zeroed out and the packets bound for the target OS will >> not correctly get the mac address of the qemu ethernet adapter. >> >> The solution is to initialize the slirp mac address when the qemu >> network adapter client is initialized. This allows the use >> bi-directional udp redirection with a static IP address configured on >> the qemu ethernet adapter. >> ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-04-12 14:22 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-04-10 4:22 [Qemu-devel] [PATCH 0/2] slirp udp fixes Jason Wessel 2008-04-10 4:22 ` [Qemu-devel] [PATCH 1/2] Fix slirp udp source address contamination Jason Wessel 2008-04-10 4:22 ` [Qemu-devel] [PATCH 2/2] Fix slirp mac address init Jason Wessel 2008-04-12 12:44 ` Aurelien Jarno 2008-04-12 14:21 ` Jason Wessel
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).