slirp udp fixes
cover slirp udp fixes
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(-)
PATCH 1/2 Fix slirp udp source address contamination
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.
--- slirp/udp.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
slirp/udp.c +2 -1
@@ -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;
Signature · 1 line
1.5.4
PATCH 2/2 Fix slirp mac address init
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.
--- slirp/libslirp.h | 2 ++ slirp/slirp.c | 5 +++++ vl.c | 3 +++ 3 files changed, 10 insertions(+), 0 deletions(-)
slirp/libslirp.h +2 -0
@@ -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);
slirp/slirp.c +5 -0
@@ -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);
vl.c +3 -0
@@ -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); }
Signature · 1 line
1.5.4
Re: [Qemu-devel] [PATCH 2/2] Fix slirp mac address init
Quoted 3 lines · Jason Wessel
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.
Quoted 65 lines
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 <[email protected]>--- slirp/libslirp.h | 2 ++ slirp/slirp.c | 5 +++++ vl.c | 3 +++ 3 files changed, 10 insertions(+), 0 deletions(-)slirp/libslirp.h +2
-0@@ -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);slirp/slirp.c +5
-0@@ -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); vl.c +3
-0@@ -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); }Signature · 1 line
1.5.4
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net
Re: [Qemu-devel] [PATCH 2/2] Fix slirp mac address init
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
[email protected]/,@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.
Quoted 21 lines · Aurelien Jarno
Quoted 4 lines · Jason Wessel
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.
Quoted 9 lines
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.