From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M9wqi-0004xB-Ea for qemu-devel@nongnu.org; Fri, 29 May 2009 03:49:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M9wqd-0004pb-L7 for qemu-devel@nongnu.org; Fri, 29 May 2009 03:49:55 -0400 Received: from [199.232.76.173] (port=51278 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M9wqd-0004pB-8F for qemu-devel@nongnu.org; Fri, 29 May 2009 03:49:51 -0400 Received: from mx20.gnu.org ([199.232.41.8]:46586) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1M9wqc-0006eK-Ob for qemu-devel@nongnu.org; Fri, 29 May 2009 03:49:50 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M9wqZ-0007Wd-Tr for qemu-devel@nongnu.org; Fri, 29 May 2009 03:49:48 -0400 Message-ID: <4A1F934F.2010309@web.de> Date: Fri, 29 May 2009 09:48:31 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <1243335807-9495-1-git-send-email-agraf@suse.de> <4A1F029D.7020901@web.de> <5649673C-346E-45A4-AA6A-E10815087FF7@suse.de> In-Reply-To: <5649673C-346E-45A4-AA6A-E10815087FF7@suse.de> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigE3C3438A4427C222F8355225" Sender: jan.kiszka@web.de Subject: [Qemu-devel] Re: [PATCH] User Networking: Enable removal of redirections List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf Cc: qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigE3C3438A4427C222F8355225 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Alexander Graf wrote: >=20 > On 28.05.2009, at 23:31, Jan Kiszka wrote: >=20 >> Alexander Graf wrote: >>> Using the new host_net_redir command you can easily create redirectio= ns >>> on the fly while your VM is running. >>> >>> While that's great, it's missing the removal of redirections, in case= >>> you >>> want to have a port closed again at a later point in time. >>> >>> This patch adds support for removal of redirections. >>> >>> Signed-off-by: Alexander Graf >>> --- >>> monitor.c | 5 +++-- >>> net.c | 43 ++++++++++++++++++++++++++++++++++++++++++- >>> net.h | 2 +- >>> slirp/libslirp.h | 1 + >>> slirp/slirp.c | 23 +++++++++++++++++++++++ >>> vl.c | 2 +- >>> 6 files changed, 71 insertions(+), 5 deletions(-) >>> >>> diff --git a/monitor.c b/monitor.c >>> index 0f38c71..dbab3de 100644 >>> --- a/monitor.c >>> +++ b/monitor.c >>> @@ -1759,8 +1759,9 @@ static const mon_cmd_t mon_cmds[] =3D { >>> { "host_net_remove", "is", net_host_device_remove, >>> "vlan_id name", "remove host VLAN client" }, >>> #ifdef CONFIG_SLIRP >>> - { "host_net_redir", "s", net_slirp_redir, >>> - "[tcp|udp]:host-port:[guest-host]:guest-port", "redirect TCP >>> or UDP connections from host to guest (requires -net user)" }, >>> + { "host_net_redir", "ss?", net_slirp_redir, >>> + "[tcp|udp]:host-port:[guest-host]:guest-port", "redirect TCP >>> or UDP connections from host to guest (requires -net user)\n" >>> + "host_net_redir remove [tcp:|udp:]host-port -- remove >>> redirection" }, >>> #endif >>> { "balloon", "i", do_balloon, >>> "target", "request VM to change it's memory allocation (in MB)"= }, >>> diff --git a/net.c b/net.c >>> index 31ee95a..de019b3 100644 >>> --- a/net.c >>> +++ b/net.c >>> @@ -568,7 +568,43 @@ static int net_slirp_init(VLANState *vlan, const= >>> char *model, const char *name) >>> return 0; >>> } >>> >>> -void net_slirp_redir(Monitor *mon, const char *redir_str) >>> +static void net_slirp_redir_rm(Monitor *mon, const char *port_str) >>> +{ >>> + int host_port; >>> + char buf[256] =3D ""; >>> + const char *p =3D port_str; >>> + int is_udp =3D 0; >>> + int n; >>> + >>> + if (!mon) >>> + return; >>> + >>> + if (!port_str || !port_str[0]) >>> + goto fail_syntax; >>> + >>> + get_str_sep(buf, sizeof(buf), &p, ':'); >>> + >>> + if (!strcmp(buf, "tcp") || buf[0] =3D=3D '\0') { >>> + is_udp =3D 0; >>> + } else if (!strcmp(buf, "udp")) { >>> + is_udp =3D 1; >>> + } else { >>> + goto fail_syntax; >>> + } >>> + >>> + host_port =3D atoi(p); >>> + >>> + n =3D slirp_redir_rm(is_udp, host_port); >>> + >>> + monitor_printf(mon, "removed %d redirections to %s port %d\n", n= , >>> + is_udp ? "udp" : "tcp", host_port); >>> + return; >>> + >>> + fail_syntax: >>> + monitor_printf(mon, "invalid format\n"); >>> +} >>> + >>> +void net_slirp_redir(Monitor *mon, const char *redir_str, const char= >>> *redir_opt2) >>> { >>> int is_udp; >>> char buf[256], *r; >>> @@ -581,6 +617,11 @@ void net_slirp_redir(Monitor *mon, const char >>> *redir_str) >>> slirp_init(slirp_restrict, slirp_ip); >>> } >>> >>> + if (!strcmp(redir_str, "remove")) { >>> + net_slirp_redir_rm(mon, redir_opt2); >>> + return; >>> + } >>> + >>> p =3D redir_str; >>> if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) >>> goto fail_syntax; >>> diff --git a/net.h b/net.h >>> index 41a3082..feee021 100644 >>> --- a/net.h >>> +++ b/net.h >>> @@ -112,7 +112,7 @@ int net_client_init(const char *device, const >>> char *p); >>> void net_client_uninit(NICInfo *nd); >>> int net_client_parse(const char *str); >>> void net_slirp_smb(const char *exported_dir); >>> -void net_slirp_redir(Monitor *mon, const char *redir_str); >>> +void net_slirp_redir(Monitor *mon, const char *redir_str, const char= >>> *redir_opt2); >>> void net_cleanup(void); >>> int slirp_is_inited(void); >>> void net_client_check(void); >>> diff --git a/slirp/libslirp.h b/slirp/libslirp.h >>> index a1cd70e..6fc2c32 100644 >>> --- a/slirp/libslirp.h >>> +++ b/slirp/libslirp.h >>> @@ -18,6 +18,7 @@ void slirp_input(const uint8_t *pkt, int pkt_len); >>> int slirp_can_output(void); >>> void slirp_output(const uint8_t *pkt, int pkt_len); >>> >>> +int slirp_redir_rm(int is_udp, int host_port); >>> int slirp_redir(int is_udp, int host_port, >>> struct in_addr guest_addr, int guest_port); >>> int slirp_add_exec(int do_pty, const void *args, int addr_low_byte, >>> diff --git a/slirp/slirp.c b/slirp/slirp.c >>> index 04d3ded..33397c0 100644 >>> --- a/slirp/slirp.c >>> +++ b/slirp/slirp.c >>> @@ -734,6 +734,29 @@ void if_encap(const uint8_t *ip_data, int >>> ip_data_len) >>> } >>> } >>> >>> +/* Unlistens a redirection >>> + * >>> + * Return value: number of redirs removed */ >>> +int slirp_redir_rm(int is_udp, int host_port) >>> +{ >>> + struct socket *so; >>> + struct socket *head =3D (is_udp ? &udb : &tcb); >>> + int fport =3D htons(host_port); >>> + int n =3D 0; >>> + >>> + loop_again: >>> + for (so =3D head->so_next; so !=3D head; so =3D so->so_next) { >>> + if (so->so_fport =3D=3D fport) { >>> + close(so->s); >>> + sofree(so); >>> + n++; >>> + goto loop_again; >>> + } >>> + } >> >> Unfortunately, this does not only target host->guest redirection socke= ts >> but also sockets slirp uses for NAT'ing guest originated connections. >> The same applies to your "host_net_redir list". So giving this in user= >> hand, unwanted damaged can be caused to guest network sessions. What w= e >> need is a tag in struct socket to identify static redirection sockets.= >=20 > Right - with the current infrastructure there's no easy way to find out= > if a socket was created for incoming (listen) or outgoing purposes FWIW= =2E > So a flag might make sense. >=20 > I'm not really sure if that works out for UDP sockets though. Why not? We will tag the socket during tcp/udp_listen, right after socreate e.g. >=20 >> What's your current plan regarding these two commits? We should >> coordinate as my work touches the same area. >=20 > Eh - good question. I'd like to get some means of removing and listing > redirs upstream. The best case for me would be if you'd take that into > your trees so I don't have to worry about it :-). I was afraid you'll say this :). As you patches were already merged, I have to deal with them earlier than expected anyway. OK, will pick this u= p. Jan --------------enigE3C3438A4427C222F8355225 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAkofk18ACgkQniDOoMHTA+mhwgCggDf/or8/rGNn4Y4hw8wL9Tal XHUAn1luotaCqTxmV+6YbR4fniOxNUY4 =8R0L -----END PGP SIGNATURE----- --------------enigE3C3438A4427C222F8355225--