Commit f3546deb079fd9e069870b9fd2f22bb48d5c8254
Committed by
Anthony Liguori
1 parent
2ad82cf9
slirp: Rework monitor commands for host forwarding
Improve the monitor interface for adding and removing host forwarding rules by splitting it up in two commands and rename them to hostfwd_add and hostfwd_remove. Also split up the paths taken for legacy -redir support and the monitor add command as the latter will be extended later on. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
4 changed files
with
29 additions
and
22 deletions
net.c
| @@ -871,7 +871,7 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model, | @@ -871,7 +871,7 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model, | ||
| 871 | return 0; | 871 | return 0; |
| 872 | } | 872 | } |
| 873 | 873 | ||
| 874 | -static void net_slirp_hostfwd_remove(Monitor *mon, const char *port_str) | 874 | +void net_slirp_hostfwd_remove(Monitor *mon, const char *port_str) |
| 875 | { | 875 | { |
| 876 | int host_port; | 876 | int host_port; |
| 877 | char buf[256] = ""; | 877 | char buf[256] = ""; |
| @@ -879,8 +879,10 @@ static void net_slirp_hostfwd_remove(Monitor *mon, const char *port_str) | @@ -879,8 +879,10 @@ static void net_slirp_hostfwd_remove(Monitor *mon, const char *port_str) | ||
| 879 | int is_udp = 0; | 879 | int is_udp = 0; |
| 880 | int n; | 880 | int n; |
| 881 | 881 | ||
| 882 | - if (!mon) | 882 | + if (!slirp_inited) { |
| 883 | + monitor_printf(mon, "user mode network stack not in use\n"); | ||
| 883 | return; | 884 | return; |
| 885 | + } | ||
| 884 | 886 | ||
| 885 | if (!port_str || !port_str[0]) | 887 | if (!port_str || !port_str[0]) |
| 886 | goto fail_syntax; | 888 | goto fail_syntax; |
| @@ -958,29 +960,30 @@ static void slirp_hostfwd(Monitor *mon, const char *redir_str) | @@ -958,29 +960,30 @@ static void slirp_hostfwd(Monitor *mon, const char *redir_str) | ||
| 958 | config_error(mon, "invalid host forwarding rule '%s'\n", redir_str); | 960 | config_error(mon, "invalid host forwarding rule '%s'\n", redir_str); |
| 959 | } | 961 | } |
| 960 | 962 | ||
| 961 | -void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2) | 963 | +void net_slirp_hostfwd_add(Monitor *mon, const char *redir_str) |
| 962 | { | 964 | { |
| 963 | - struct slirp_config_str *config; | ||
| 964 | - | ||
| 965 | if (!slirp_inited) { | 965 | if (!slirp_inited) { |
| 966 | - if (mon) { | ||
| 967 | - monitor_printf(mon, "user mode network stack not in use\n"); | ||
| 968 | - } else { | ||
| 969 | - config = qemu_malloc(sizeof(*config)); | ||
| 970 | - pstrcpy(config->str, sizeof(config->str), redir_str); | ||
| 971 | - config->flags = SLIRP_CFG_HOSTFWD; | ||
| 972 | - config->next = slirp_configs; | ||
| 973 | - slirp_configs = config; | ||
| 974 | - } | 966 | + monitor_printf(mon, "user mode network stack not in use\n"); |
| 975 | return; | 967 | return; |
| 976 | } | 968 | } |
| 977 | 969 | ||
| 978 | - if (!strcmp(redir_str, "remove")) { | ||
| 979 | - net_slirp_hostfwd_remove(mon, redir_opt2); | 970 | + slirp_hostfwd(mon, redir_str); |
| 971 | +} | ||
| 972 | + | ||
| 973 | +void net_slirp_redir(const char *redir_str) | ||
| 974 | +{ | ||
| 975 | + struct slirp_config_str *config; | ||
| 976 | + | ||
| 977 | + if (!slirp_inited) { | ||
| 978 | + config = qemu_malloc(sizeof(*config)); | ||
| 979 | + pstrcpy(config->str, sizeof(config->str), redir_str); | ||
| 980 | + config->flags = SLIRP_CFG_HOSTFWD; | ||
| 981 | + config->next = slirp_configs; | ||
| 982 | + slirp_configs = config; | ||
| 980 | return; | 983 | return; |
| 981 | } | 984 | } |
| 982 | 985 | ||
| 983 | - slirp_hostfwd(mon, redir_str); | 986 | + slirp_hostfwd(NULL, redir_str); |
| 984 | } | 987 | } |
| 985 | 988 | ||
| 986 | #ifndef _WIN32 | 989 | #ifndef _WIN32 |
net.h
| @@ -132,7 +132,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p); | @@ -132,7 +132,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p); | ||
| 132 | void net_client_uninit(NICInfo *nd); | 132 | void net_client_uninit(NICInfo *nd); |
| 133 | int net_client_parse(const char *str); | 133 | int net_client_parse(const char *str); |
| 134 | void net_slirp_smb(const char *exported_dir); | 134 | void net_slirp_smb(const char *exported_dir); |
| 135 | -void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2); | 135 | +void net_slirp_hostfwd_add(Monitor *mon, const char *redir_str); |
| 136 | +void net_slirp_hostfwd_remove(Monitor *mon, const char *port_str); | ||
| 137 | +void net_slirp_redir(const char *redir_str); | ||
| 136 | void net_cleanup(void); | 138 | void net_cleanup(void); |
| 137 | int slirp_is_inited(void); | 139 | int slirp_is_inited(void); |
| 138 | void net_client_check(void); | 140 | void net_client_check(void); |
qemu-monitor.hx
| @@ -536,9 +536,11 @@ Remove host VLAN client. | @@ -536,9 +536,11 @@ Remove host VLAN client. | ||
| 536 | ETEXI | 536 | ETEXI |
| 537 | 537 | ||
| 538 | #ifdef CONFIG_SLIRP | 538 | #ifdef CONFIG_SLIRP |
| 539 | - { "host_net_redir", "ss?", net_slirp_redir, | ||
| 540 | - "[tcp|udp]:host-port:[guest-host]:guest-port", "redirect TCP or UDP connections from host to guest (requires -net user)\n" | ||
| 541 | - "host_net_redir remove [tcp:|udp:]host-port -- remove redirection" }, | 539 | + { "hostfwd_add", "s", net_slirp_hostfwd_add, |
| 540 | + "[tcp|udp]:hostport:[guestaddr]:guestport", | ||
| 541 | + "redirect TCP or UDP connections from host to guest (requires -net user)" }, | ||
| 542 | + { "hostfwd_remove", "s", net_slirp_hostfwd_remove, | ||
| 543 | + "[tcp|udp]:hostport", "remove host-to-guest TCP or UDP redirection" }, | ||
| 542 | #endif | 544 | #endif |
| 543 | STEXI | 545 | STEXI |
| 544 | @item host_net_redir | 546 | @item host_net_redir |
vl.c
| @@ -5319,7 +5319,7 @@ int main(int argc, char **argv, char **envp) | @@ -5319,7 +5319,7 @@ int main(int argc, char **argv, char **envp) | ||
| 5319 | break; | 5319 | break; |
| 5320 | #endif | 5320 | #endif |
| 5321 | case QEMU_OPTION_redir: | 5321 | case QEMU_OPTION_redir: |
| 5322 | - net_slirp_redir(NULL, optarg, NULL); | 5322 | + net_slirp_redir(optarg); |
| 5323 | break; | 5323 | break; |
| 5324 | #endif | 5324 | #endif |
| 5325 | case QEMU_OPTION_bt: | 5325 | case QEMU_OPTION_bt: |