[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 40/41] slirp: Make hostfwd_add/remove multi-instance
From: |
Jan Kiszka |
Subject: |
[Qemu-devel] [PATCH 40/41] slirp: Make hostfwd_add/remove multi-instance-aware |
Date: |
Wed, 24 Jun 2009 14:42:32 +0200 |
User-agent: |
StGIT/0.14.3 |
Extend the syntax of hostfwd_add/remove to optionally take a tuple of
VLAN ID and slirp stack name. If those are omitted, the commands will
continue to work on the first registered slirp stack.
Signed-off-by: Jan Kiszka <address@hidden>
---
net.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++---------
net.h | 6 ++++-
qemu-monitor.hx | 8 ++++---
3 files changed, 60 insertions(+), 16 deletions(-)
diff --git a/net.c b/net.c
index 030c29b..573179e 100644
--- a/net.c
+++ b/net.c
@@ -907,23 +907,56 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan,
const char *model,
return 0;
}
-void net_slirp_hostfwd_remove(Monitor *mon, const char *src_str)
+static SlirpState *slirp_lookup(Monitor *mon, const char *vlan,
+ const char *stack)
+{
+ VLANClientState *vc;
+
+ if (vlan) {
+ vc = qemu_find_vlan_client_by_name(mon, strtol(vlan, NULL, 0), stack);
+ if (!vc) {
+ return NULL;
+ }
+ if (strcmp(vc->model, "user")) {
+ monitor_printf(mon, "invalid device specified\n");
+ return NULL;
+ }
+ return vc->opaque;
+ } else {
+ if (TAILQ_EMPTY(&slirp_stacks)) {
+ monitor_printf(mon, "user mode network stack not in use\n");
+ return NULL;
+ }
+ return TAILQ_FIRST(&slirp_stacks);
+ }
+}
+
+void net_slirp_hostfwd_remove(Monitor *mon, const char *arg1,
+ const char *arg2, const char *arg3)
{
struct in_addr host_addr = { .s_addr = INADDR_ANY };
int host_port;
char buf[256] = "";
- const char *p = src_str;
+ const char *src_str, *p;
+ SlirpState *s;
int is_udp = 0;
int err;
- if (TAILQ_EMPTY(&slirp_stacks)) {
- monitor_printf(mon, "user mode network stack not in use\n");
+ if (arg2) {
+ s = slirp_lookup(mon, arg1, arg2);
+ src_str = arg3;
+ } else {
+ s = slirp_lookup(mon, NULL, NULL);
+ src_str = arg1;
+ }
+ if (!s) {
return;
}
if (!src_str || !src_str[0])
goto fail_syntax;
+ p = src_str;
get_str_sep(buf, sizeof(buf), &p, ':');
if (!strcmp(buf, "tcp") || buf[0] == '\0') {
@@ -966,7 +999,7 @@ static void slirp_hostfwd(SlirpState *s, Monitor *mon,
const char *redir_str,
char *end;
p = redir_str;
- if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
+ if (!p || get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
goto fail_syntax;
}
if (!strcmp(buf, "tcp") || buf[0] == '\0') {
@@ -1017,14 +1050,23 @@ static void slirp_hostfwd(SlirpState *s, Monitor *mon,
const char *redir_str,
config_error(mon, "invalid host forwarding rule '%s'\n", redir_str);
}
-void net_slirp_hostfwd_add(Monitor *mon, const char *redir_str)
+void net_slirp_hostfwd_add(Monitor *mon, const char *arg1,
+ const char *arg2, const char *arg3)
{
- if (TAILQ_EMPTY(&slirp_stacks)) {
- monitor_printf(mon, "user mode network stack not in use\n");
- return;
+ const char *redir_str;
+ SlirpState *s;
+
+ if (arg2) {
+ s = slirp_lookup(mon, arg1, arg2);
+ redir_str = arg3;
+ } else {
+ s = slirp_lookup(mon, NULL, NULL);
+ redir_str = arg1;
+ }
+ if (s) {
+ slirp_hostfwd(s, mon, redir_str, 0);
}
- slirp_hostfwd(TAILQ_FIRST(&slirp_stacks), mon, redir_str, 0);
}
void net_slirp_redir(const char *redir_str)
diff --git a/net.h b/net.h
index 9fba4c6..4dad82d 100644
--- a/net.h
+++ b/net.h
@@ -130,8 +130,10 @@ int net_client_init(Monitor *mon, 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_hostfwd_add(Monitor *mon, const char *redir_str);
-void net_slirp_hostfwd_remove(Monitor *mon, const char *src_str);
+void net_slirp_hostfwd_add(Monitor *mon, const char *arg1,
+ const char *arg2, const char *arg3);
+void net_slirp_hostfwd_remove(Monitor *mon, const char *arg1,
+ const char *arg2, const char *arg3);
void net_slirp_redir(const char *redir_str);
void net_cleanup(void);
void net_client_check(void);
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index e320f9f..66c6ad9 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -536,11 +536,11 @@ Remove host VLAN client.
ETEXI
#ifdef CONFIG_SLIRP
- { "hostfwd_add", "s", net_slirp_hostfwd_add,
- "[tcp|udp]:[hostaddr]:hostport-[guestaddr]:guestport",
+ { "hostfwd_add", "ss?s?", net_slirp_hostfwd_add,
+ "[vlan_id name] [tcp|udp]:[hostaddr]:hostport-[guestaddr]:guestport",
"redirect TCP or UDP connections from host to guest (requires -net
user)" },
- { "hostfwd_remove", "s", net_slirp_hostfwd_remove,
- "[tcp|udp]:[hostaddr]:hostport",
+ { "hostfwd_remove", "ss?s?", net_slirp_hostfwd_remove,
+ "[vlan_id name] [tcp|udp]:[hostaddr]:hostport",
"remove host-to-guest TCP or UDP redirection" },
#endif
STEXI
- [Qemu-devel] [PATCH 27/41] slirp: Kill slirp_is_inited, (continued)
- [Qemu-devel] [PATCH 27/41] slirp: Kill slirp_is_inited, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 28/41] slirp: Drop redundant checks from slirp_output, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 36/41] slirp: Use shell to erase smb directory, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 35/41] slirp: Save/restore bootp client states, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 32/41] slirp: Use internal state in interface, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 33/41] slirp: Allocate/free stack instance dynamically, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 31/41] slirp: Factor out internal state structure, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 34/41] slirp: Enable multiple instances, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 41/41] slirp: Basic VLAN client info_str, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 39/41] net: Provide VLAN client lookup helper, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 40/41] slirp: Make hostfwd_add/remove multi-instance-aware,
Jan Kiszka <=
- [Qemu-devel] [PATCH 37/41] slirp: Improve error handling in slirp_smb, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 38/41] slirp: Enable multi-instance support for the smb service, Jan Kiszka, 2009/06/24
- [Qemu-devel] Re: [PATCH 00/41] Slirp Fixes and Enhancements - Reloaded, Anthony Liguori, 2009/06/24
- [Qemu-devel] [PATCH 30/41] slirp: Drop link_up checks from if_output and slirp_socket_can_recv, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 22/41] slirp: tftp: Refactor tftp_handle_rrq, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 05/41] slirp: Move smb, redir, tftp and bootp parameters and -net channel, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 16/41] slirp: Drop dead code, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 14/41] slirp: Mark sockets of incoming TCP connections, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 04/41] Introduce get_next_param_value, Jan Kiszka, 2009/06/24
- [Qemu-devel] [PATCH 18/41] slirp: Cleanup and basic reanimation of debug code, Jan Kiszka, 2009/06/24