qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] User Networking: Enable removal of redirections
@ 2009-05-26 11:03 Alexander Graf
  2009-05-26 11:03 ` [Qemu-devel] [PATCH] User networking: Show active connections Alexander Graf
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Alexander Graf @ 2009-05-26 11:03 UTC (permalink / raw)
  To: qemu-devel

Using the new host_net_redir command you can easily create redirections
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 <agraf@suse.de>
---
 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[] = {
     { "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] = "";
+    const char *p = port_str;
+    int is_udp = 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] == '\0') {
+        is_udp = 0;
+    } else if (!strcmp(buf, "udp")) {
+        is_udp = 1;
+    } else {
+        goto fail_syntax;
+    }
+
+    host_port = atoi(p);
+
+    n = 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 = 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 = (is_udp ? &udb : &tcb);
+    int fport = htons(host_port);
+    int n = 0;
+
+ loop_again:
+    for (so = head->so_next; so != head; so = so->so_next) {
+        if (so->so_fport == fport) {
+            close(so->s);
+            sofree(so);
+            n++;
+            goto loop_again;
+        }
+    }
+
+    return n;
+}
+
 int slirp_redir(int is_udp, int host_port,
                 struct in_addr guest_addr, int guest_port)
 {
diff --git a/vl.c b/vl.c
index 2c1f0e0..25dfdd7 100644
--- a/vl.c
+++ b/vl.c
@@ -5153,7 +5153,7 @@ int main(int argc, char **argv, char **envp)
                 break;
 #endif
             case QEMU_OPTION_redir:
-                net_slirp_redir(NULL, optarg);
+                net_slirp_redir(NULL, optarg, NULL);
                 break;
 #endif
             case QEMU_OPTION_bt:
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH] User networking: Show active connections
  2009-05-26 11:03 [Qemu-devel] [PATCH] User Networking: Enable removal of redirections Alexander Graf
@ 2009-05-26 11:03 ` Alexander Graf
  2009-05-27  6:58   ` [Qemu-devel] " Jan Kiszka
  2009-05-27  6:58 ` [Qemu-devel] Re: [PATCH] User Networking: Enable removal of redirections Jan Kiszka
  2009-05-28 21:31 ` Jan Kiszka
  2 siblings, 1 reply; 10+ messages in thread
From: Alexander Graf @ 2009-05-26 11:03 UTC (permalink / raw)
  To: qemu-devel

In case you're wondering what connections exactly you have open
or maybe redir'ed in the past, you can't really find out from qemu
right now.

This patch enables you to see all current connections the host
only networking holds open, so you can kill them using the previous
patch.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 monitor.c        |    3 ++-
 net.c            |   44 ++++++++++++++++++++++++++++++++++++++++++++
 slirp/libslirp.h |    4 ++++
 slirp/slirp.c    |   24 ++++++++++++++++++++++++
 4 files changed, 74 insertions(+), 1 deletions(-)

diff --git a/monitor.c b/monitor.c
index dbab3de..443f6d4 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1761,7 +1761,8 @@ static const mon_cmd_t mon_cmds[] = {
 #ifdef CONFIG_SLIRP
     { "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" },
+      "host_net_redir remove [tcp:|udp:]host-port -- remove redirection\n"
+      "host_net_redir list -- show all redirections" },
 #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 de019b3..80e999c 100644
--- a/net.c
+++ b/net.c
@@ -568,6 +568,45 @@ static int net_slirp_init(VLANState *vlan, const char *model, const char *name)
     return 0;
 }
 
+static void net_slirp_redir_print(void *opaque, int is_udp,
+                                  struct in_addr *laddr, u_int lport,
+                                  struct in_addr *faddr, u_int fport)
+{
+    Monitor *mon = (Monitor *)opaque;
+    uint32_t h_addr;
+    uint32_t g_addr;
+    char buf[16];
+
+    h_addr = ntohl(faddr->s_addr);
+    g_addr = ntohl(laddr->s_addr);
+
+    monitor_printf(mon, "  %s |", is_udp ? "udp" : "tcp" );
+    snprintf(buf, 15, "%d.%d.%d.%d", (h_addr >> 24) & 0xff,
+                                     (h_addr >> 16) & 0xff,
+                                     (h_addr >> 8) & 0xff,
+                                     (h_addr) & 0xff);
+    monitor_printf(mon, " %15s |", buf);
+    monitor_printf(mon, " %5d |", fport);
+
+    snprintf(buf, 15, "%d.%d.%d.%d", (g_addr >> 24) & 0xff,
+                                     (g_addr >> 16) & 0xff,
+                                     (g_addr >> 8) & 0xff,
+                                     (g_addr) & 0xff);
+    monitor_printf(mon, " %15s |", buf);
+    monitor_printf(mon, " %5d\n", lport);
+
+}
+
+static void net_slirp_redir_list(Monitor *mon)
+{
+    if (!mon)
+        return;
+
+    monitor_printf(mon, " Prot |    Host Addr    | HPort |    Guest Addr   | GPort\n");
+    monitor_printf(mon, "      |                 |       |                 |      \n");
+    slirp_redir_loop(net_slirp_redir_print, mon);
+}
+
 static void net_slirp_redir_rm(Monitor *mon, const char *port_str)
 {
     int host_port;
@@ -622,6 +661,11 @@ void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2
         return;
     }
 
+    if (!strcmp(redir_str, "list")) {
+        net_slirp_redir_list(mon);
+        return;
+    }
+
     p = redir_str;
     if (get_str_sep(buf, sizeof(buf), &p, ':') < 0)
         goto fail_syntax;
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 6fc2c32..b2313b4 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -18,6 +18,10 @@ 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);
 
+void slirp_redir_loop(void (*func)(void *opaque, int is_udp,
+                                  struct in_addr *laddr, u_int lport,              
+                                  struct in_addr *faddr, u_int fport),
+                     void *opaque);
 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);
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 33397c0..9cab731 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -734,6 +734,30 @@ void if_encap(const uint8_t *ip_data, int ip_data_len)
     }
 }
 
+static void _slirp_redir_loop(void (*func)(void *opaque, int is_udp,
+                                           struct in_addr *laddr, u_int lport,
+                                           struct in_addr *faddr, u_int fport),
+                              void *opaque, int is_udp)
+{
+    struct socket *head = (is_udp ? &udb : &tcb);
+    struct socket *so;
+
+    for (so = head->so_next; so != head; so = so->so_next) {
+        func(opaque, is_udp,
+             &so->so_laddr, ntohs(so->so_lport),
+             &so->so_faddr, ntohs(so->so_fport));
+    }
+}
+
+void slirp_redir_loop(void (*func)(void *opaque, int is_udp,
+                                  struct in_addr *laddr, u_int lport,
+                                  struct in_addr *faddr, u_int fport),
+                     void *opaque)
+{
+    _slirp_redir_loop(func, opaque, 0);
+    _slirp_redir_loop(func, opaque, 1);
+}
+
 /* Unlistens a redirection
  *
  * Return value: number of redirs removed */
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] Re: [PATCH] User Networking: Enable removal of redirections
  2009-05-26 11:03 [Qemu-devel] [PATCH] User Networking: Enable removal of redirections Alexander Graf
  2009-05-26 11:03 ` [Qemu-devel] [PATCH] User networking: Show active connections Alexander Graf
@ 2009-05-27  6:58 ` Jan Kiszka
  2009-05-27  7:21   ` Jan Kiszka
  2009-05-28 21:31 ` Jan Kiszka
  2 siblings, 1 reply; 10+ messages in thread
From: Jan Kiszka @ 2009-05-27  6:58 UTC (permalink / raw)
  To: Alexander Graf; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2127 bytes --]

Alexander Graf wrote:
> Using the new host_net_redir command you can easily create redirections
> 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.

Cool. I was just too lazy to hack on slirp for this so far, but now you
did it.

> 
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
>  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[] = {
>      { "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"

If going for a single command, this should rather look like this:

"[tcp|udp]:host-port:[guest-host]:guest-port |
 remove [tcp|udp]:host-port"

BTW, I didn't refactor this interface along with the command line
changes, but I should actually. To remain consistent, we should call it
host_net_fwd (-redir will be replaced with hostfwd=<rule>) or even take
the chance and split it into host_net_fwd_add and host_net_fwd_remove.

> +      "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)" },

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] Re: [PATCH] User networking: Show active connections
  2009-05-26 11:03 ` [Qemu-devel] [PATCH] User networking: Show active connections Alexander Graf
@ 2009-05-27  6:58   ` Jan Kiszka
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Kiszka @ 2009-05-27  6:58 UTC (permalink / raw)
  To: Alexander Graf; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1331 bytes --]

Alexander Graf wrote:
> In case you're wondering what connections exactly you have open
> or maybe redir'ed in the past, you can't really find out from qemu
> right now.
> 
> This patch enables you to see all current connections the host
> only networking holds open, so you can kill them using the previous
> patch.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
>  monitor.c        |    3 ++-
>  net.c            |   44 ++++++++++++++++++++++++++++++++++++++++++++
>  slirp/libslirp.h |    4 ++++
>  slirp/slirp.c    |   24 ++++++++++++++++++++++++
>  4 files changed, 74 insertions(+), 1 deletions(-)
> 
> diff --git a/monitor.c b/monitor.c
> index dbab3de..443f6d4 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -1761,7 +1761,8 @@ static const mon_cmd_t mon_cmds[] = {
>  #ifdef CONFIG_SLIRP
>      { "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" },
> +      "host_net_redir remove [tcp:|udp:]host-port -- remove redirection\n"
> +      "host_net_redir list -- show all redirections" },

info redir (or using the new term: info hostfwd)? Would look a bit more
consistent.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] Re: [PATCH] User Networking: Enable removal of redirections
  2009-05-27  6:58 ` [Qemu-devel] Re: [PATCH] User Networking: Enable removal of redirections Jan Kiszka
@ 2009-05-27  7:21   ` Jan Kiszka
  2009-05-27  7:26     ` Alexander Graf
  0 siblings, 1 reply; 10+ messages in thread
From: Jan Kiszka @ 2009-05-27  7:21 UTC (permalink / raw)
  To: Alexander Graf; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2313 bytes --]

Jan Kiszka wrote:
> Alexander Graf wrote:
>> Using the new host_net_redir command you can easily create redirections
>> 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.
> 
> Cool. I was just too lazy to hack on slirp for this so far, but now you
> did it.
> 
>> Signed-off-by: Alexander Graf <agraf@suse.de>
>> ---
>>  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[] = {
>>      { "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"
> 
> If going for a single command, this should rather look like this:
> 
> "[tcp|udp]:host-port:[guest-host]:guest-port |
>  remove [tcp|udp]:host-port"
> 
> BTW, I didn't refactor this interface along with the command line
> changes, but I should actually. To remain consistent, we should call it
> host_net_fwd (-redir will be replaced with hostfwd=<rule>) or even take
> the chance and split it into host_net_fwd_add and host_net_fwd_remove.
> 
>> +      "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)" },

Before I forget: You also have to update to monitor-related
documentation when adding/changing commands.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] Re: [PATCH] User Networking: Enable removal of redirections
  2009-05-27  7:21   ` Jan Kiszka
@ 2009-05-27  7:26     ` Alexander Graf
  2009-05-27  8:04       ` Jan Kiszka
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Graf @ 2009-05-27  7:26 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: qemu-devel


On 27.05.2009, at 09:21, Jan Kiszka wrote:

> Jan Kiszka wrote:
>> Alexander Graf wrote:
>>> Using the new host_net_redir command you can easily create  
>>> redirections
>>> 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.
>>
>> Cool. I was just too lazy to hack on slirp for this so far, but now  
>> you
>> did it.
>>
>>> Signed-off-by: Alexander Graf <agraf@suse.de>
>>> ---
>>> 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[] = {
>>>     { "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"
>>
>> If going for a single command, this should rather look like this:
>>
>> "[tcp|udp]:host-port:[guest-host]:guest-port |
>> remove [tcp|udp]:host-port"
>>
>> BTW, I didn't refactor this interface along with the command line
>> changes, but I should actually. To remain consistent, we should  
>> call it
>> host_net_fwd (-redir will be replaced with hostfwd=<rule>) or even  
>> take
>> the chance and split it into host_net_fwd_add and  
>> host_net_fwd_remove.
>>
>>> +      "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)" },
>
> Before I forget: You also have to update to monitor-related
> documentation when adding/changing commands.

What monitor-related documentation? I did a grep -R host_net_redir  
qemu and didn't find any other occurence of that command :o.

Alex

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] Re: [PATCH] User Networking: Enable removal of redirections
  2009-05-27  7:26     ` Alexander Graf
@ 2009-05-27  8:04       ` Jan Kiszka
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Kiszka @ 2009-05-27  8:04 UTC (permalink / raw)
  To: Alexander Graf; +Cc: Blue Swirl, qemu-devel

Alexander Graf wrote:
> 
> On 27.05.2009, at 09:21, Jan Kiszka wrote:
> 
>> Jan Kiszka wrote:
>>> Alexander Graf wrote:
>>>> Using the new host_net_redir command you can easily create redirections
>>>> 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.
>>>
>>> Cool. I was just too lazy to hack on slirp for this so far, but now you
>>> did it.
>>>
>>>> Signed-off-by: Alexander Graf <agraf@suse.de>
>>>> ---
>>>> 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[] = {
>>>>     { "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"
>>>
>>> If going for a single command, this should rather look like this:
>>>
>>> "[tcp|udp]:host-port:[guest-host]:guest-port |
>>> remove [tcp|udp]:host-port"
>>>
>>> BTW, I didn't refactor this interface along with the command line
>>> changes, but I should actually. To remain consistent, we should call it
>>> host_net_fwd (-redir will be replaced with hostfwd=<rule>) or even take
>>> the chance and split it into host_net_fwd_add and host_net_fwd_remove.
>>>
>>>> +      "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)" },
>>
>> Before I forget: You also have to update to monitor-related
>> documentation when adding/changing commands.
> 
> What monitor-related documentation? I did a grep -R host_net_redir qemu
> and didn't find any other occurence of that command :o.

Yeah, I also failed in the discipline of properly updating qemu-doc.texi
when adding host_net_redir. :->

I think Blueswirl recently posted patch to fold monitor options and
documentations into one file just like we already have for the command
line. Would be helpful if that get merged soon

Jan

-- 
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] Re: [PATCH] User Networking: Enable removal of redirections
  2009-05-26 11:03 [Qemu-devel] [PATCH] User Networking: Enable removal of redirections Alexander Graf
  2009-05-26 11:03 ` [Qemu-devel] [PATCH] User networking: Show active connections Alexander Graf
  2009-05-27  6:58 ` [Qemu-devel] Re: [PATCH] User Networking: Enable removal of redirections Jan Kiszka
@ 2009-05-28 21:31 ` Jan Kiszka
  2009-05-28 22:17   ` Alexander Graf
  2 siblings, 1 reply; 10+ messages in thread
From: Jan Kiszka @ 2009-05-28 21:31 UTC (permalink / raw)
  To: Alexander Graf; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 5649 bytes --]

Alexander Graf wrote:
> Using the new host_net_redir command you can easily create redirections
> 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 <agraf@suse.de>
> ---
>  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[] = {
>      { "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] = "";
> +    const char *p = port_str;
> +    int is_udp = 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] == '\0') {
> +        is_udp = 0;
> +    } else if (!strcmp(buf, "udp")) {
> +        is_udp = 1;
> +    } else {
> +        goto fail_syntax;
> +    }
> +
> +    host_port = atoi(p);
> +
> +    n = 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 = 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 = (is_udp ? &udb : &tcb);
> +    int fport = htons(host_port);
> +    int n = 0;
> +
> + loop_again:
> +    for (so = head->so_next; so != head; so = so->so_next) {
> +        if (so->so_fport == fport) {
> +            close(so->s);
> +            sofree(so);
> +            n++;
> +            goto loop_again;
> +        }
> +    }

Unfortunately, this does not only target host->guest redirection sockets
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 we
need is a tag in struct socket to identify static redirection sockets.

What's your current plan regarding these two commits? We should
coordinate as my work touches the same area.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] Re: [PATCH] User Networking: Enable removal of redirections
  2009-05-28 21:31 ` Jan Kiszka
@ 2009-05-28 22:17   ` Alexander Graf
  2009-05-29  7:48     ` Jan Kiszka
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Graf @ 2009-05-28 22:17 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: qemu-devel


On 28.05.2009, at 23:31, Jan Kiszka wrote:

> Alexander Graf wrote:
>> Using the new host_net_redir command you can easily create  
>> redirections
>> 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 <agraf@suse.de>
>> ---
>> 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[] = {
>>     { "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] = "";
>> +    const char *p = port_str;
>> +    int is_udp = 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] == '\0') {
>> +        is_udp = 0;
>> +    } else if (!strcmp(buf, "udp")) {
>> +        is_udp = 1;
>> +    } else {
>> +        goto fail_syntax;
>> +    }
>> +
>> +    host_port = atoi(p);
>> +
>> +    n = 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 = 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 = (is_udp ? &udb : &tcb);
>> +    int fport = htons(host_port);
>> +    int n = 0;
>> +
>> + loop_again:
>> +    for (so = head->so_next; so != head; so = so->so_next) {
>> +        if (so->so_fport == fport) {
>> +            close(so->s);
>> +            sofree(so);
>> +            n++;
>> +            goto loop_again;
>> +        }
>> +    }
>
> Unfortunately, this does not only target host->guest redirection  
> sockets
> 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  
> we
> need is a tag in struct socket to identify static redirection sockets.

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. So a flag might make sense.

I'm not really sure if that works out for UDP sockets though.

> What's your current plan regarding these two commits? We should
> coordinate as my work touches the same area.

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 :-).

Alex

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] Re: [PATCH] User Networking: Enable removal of redirections
  2009-05-28 22:17   ` Alexander Graf
@ 2009-05-29  7:48     ` Jan Kiszka
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Kiszka @ 2009-05-29  7:48 UTC (permalink / raw)
  To: Alexander Graf; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 6748 bytes --]

Alexander Graf wrote:
> 
> On 28.05.2009, at 23:31, Jan Kiszka wrote:
> 
>> Alexander Graf wrote:
>>> Using the new host_net_redir command you can easily create redirections
>>> 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 <agraf@suse.de>
>>> ---
>>> 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[] = {
>>>     { "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] = "";
>>> +    const char *p = port_str;
>>> +    int is_udp = 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] == '\0') {
>>> +        is_udp = 0;
>>> +    } else if (!strcmp(buf, "udp")) {
>>> +        is_udp = 1;
>>> +    } else {
>>> +        goto fail_syntax;
>>> +    }
>>> +
>>> +    host_port = atoi(p);
>>> +
>>> +    n = 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 = 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 = (is_udp ? &udb : &tcb);
>>> +    int fport = htons(host_port);
>>> +    int n = 0;
>>> +
>>> + loop_again:
>>> +    for (so = head->so_next; so != head; so = so->so_next) {
>>> +        if (so->so_fport == fport) {
>>> +            close(so->s);
>>> +            sofree(so);
>>> +            n++;
>>> +            goto loop_again;
>>> +        }
>>> +    }
>>
>> Unfortunately, this does not only target host->guest redirection sockets
>> 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 we
>> need is a tag in struct socket to identify static redirection sockets.
> 
> 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.
> So a flag might make sense.
> 
> 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.

> 
>> What's your current plan regarding these two commits? We should
>> coordinate as my work touches the same area.
> 
> 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 up.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-05-29  7:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-26 11:03 [Qemu-devel] [PATCH] User Networking: Enable removal of redirections Alexander Graf
2009-05-26 11:03 ` [Qemu-devel] [PATCH] User networking: Show active connections Alexander Graf
2009-05-27  6:58   ` [Qemu-devel] " Jan Kiszka
2009-05-27  6:58 ` [Qemu-devel] Re: [PATCH] User Networking: Enable removal of redirections Jan Kiszka
2009-05-27  7:21   ` Jan Kiszka
2009-05-27  7:26     ` Alexander Graf
2009-05-27  8:04       ` Jan Kiszka
2009-05-28 21:31 ` Jan Kiszka
2009-05-28 22:17   ` Alexander Graf
2009-05-29  7:48     ` Jan Kiszka

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).