Commit 2ad82cf9e2c2adad874fbecabd48e1cf699b7c84
Committed by
Anthony Liguori
1 parent
c92ef6a2
slirp: Fix port comparision in slirp_remove_hostfwd
For UDP host forwardings, fport is not stable, every outgoing packet of the redirection can modify it. Use getsockname instead to look up the port that is actually used on the host side. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
1 changed file
with
6 additions
and
2 deletions
slirp/slirp.c
... | ... | @@ -761,12 +761,16 @@ int slirp_remove_hostfwd(int is_udp, int host_port) |
761 | 761 | { |
762 | 762 | struct socket *so; |
763 | 763 | struct socket *head = (is_udp ? &udb : &tcb); |
764 | - int fport = htons(host_port); | |
764 | + struct sockaddr_in addr; | |
765 | + int port = htons(host_port); | |
766 | + socklen_t addr_len; | |
765 | 767 | int n = 0; |
766 | 768 | |
767 | 769 | loop_again: |
768 | 770 | for (so = head->so_next; so != head; so = so->so_next) { |
769 | - if (so->so_fport == fport) { | |
771 | + addr_len = sizeof(addr); | |
772 | + if (getsockname(so->s, (struct sockaddr *)&addr, &addr_len) == 0 && | |
773 | + addr.sin_port == port) { | |
770 | 774 | close(so->s); |
771 | 775 | sofree(so); |
772 | 776 | n++; | ... | ... |