diff options
author | Jan Kiszka <jan.kiszka@siemens.com> | 2009-06-24 14:42:29 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-06-29 08:52:46 -0500 |
commit | 9c12a6f24d8bfd0e0d81a4a77f515e32d15547c1 (patch) | |
tree | a53e06d779f761417aa6ec1325047bfb7c317725 /slirp | |
parent | 6dd5ffb661a4aec28c8296b1673abdf280038cf6 (diff) |
slirp: Do not allow to remove non-hostfwd sockets
Prevent that the users accidentally shoots down dynamic sockets. This
allows to remove looping for removals as there can now only be one
match.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'slirp')
-rw-r--r-- | slirp/slirp.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/slirp/slirp.c b/slirp/slirp.c index ad35c1fb24..35de4e380b 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -757,9 +757,7 @@ void if_encap(const uint8_t *ip_data, int ip_data_len) } } -/* Unlistens a redirection - * - * Return value: number of redirs removed */ +/* Drop host forwarding rule, return 0 if found. */ int slirp_remove_hostfwd(int is_udp, struct in_addr host_addr, int host_port) { struct socket *so; @@ -767,22 +765,20 @@ int slirp_remove_hostfwd(int is_udp, struct in_addr host_addr, int host_port) struct sockaddr_in addr; int port = htons(host_port); socklen_t addr_len; - int n = 0; - loop_again: for (so = head->so_next; so != head; so = so->so_next) { addr_len = sizeof(addr); - if (getsockname(so->s, (struct sockaddr *)&addr, &addr_len) == 0 && + if ((so->so_state & SS_HOSTFWD) && + getsockname(so->s, (struct sockaddr *)&addr, &addr_len) == 0 && addr.sin_addr.s_addr == host_addr.s_addr && addr.sin_port == port) { close(so->s); sofree(so); - n++; - goto loop_again; + return 0; } } - return n; + return -1; } int slirp_add_hostfwd(int is_udp, struct in_addr host_addr, int host_port, |