Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
DISCONTINUED:openSUSE:11.1:Update
kvm
kvm-qemu-pre11-redir-2.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File kvm-qemu-pre11-redir-2.patch of Package kvm
From 9e9f9a0773af77918d795106d1246972a27b45d5 Mon Sep 17 00:00:00 2001 From: Alexander Graf <agraf@suse.de> Date: Tue, 26 May 2009 10:49:57 +0200 Subject: [PATCH] User Networking: Enable removal of redirections 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 +++-- vl.c | 43 ++++++++++++++++++++++++++++++++++++++++++- net.h | 2 +- slirp/libslirp.h | 1 + slirp/slirp.c | 23 +++++++++++++++++++++++ vl.c | 2 +- 6 files changed, 71 insertions(+), 5 deletions(-) Index: qemu-kvm-0.10.5/monitor.c =================================================================== --- qemu-kvm-0.10.5.orig/monitor.c +++ qemu-kvm-0.10.5/monitor.c @@ -1598,8 +1598,9 @@ static const term_cmd_t term_cmds[] = { { "host_net_remove", "is", net_host_device_remove, "vlan_id name", "remove host VLAN client" }, #endif - { "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" }, { "balloon", "i", do_balloon, "target", "request VM to change it's memory allocation (in MB)" }, { "set_link", "ss", do_set_link, Index: qemu-kvm-0.10.5/net.c =================================================================== --- qemu-kvm-0.10.5.orig/net.c +++ qemu-kvm-0.10.5/net.c @@ -536,7 +536,43 @@ static int net_slirp_init(VLANState *vla return 0; } -void net_slirp_redir(const char *redir_str) +static void net_slirp_redir_rm(const char *port_str) +{ + int host_port; + char buf[256] = ""; + const char *p = port_str; + int is_udp = 0; + int n; + + + + + 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); + + term_printf("removed %d redirections to %s port %d\n", n, + is_udp ? "udp" : "tcp", host_port); + return; + + fail_syntax: + term_printf("invalid format\n"); +} + +void net_slirp_redir(const char *redir_str, const char *redir_opt2) { int is_udp; char buf[256], *r; @@ -549,6 +585,11 @@ void net_slirp_redir(const char *redir_s slirp_init(slirp_restrict, slirp_ip); } + if (!strcmp(redir_str, "remove")) { + net_slirp_redir_rm(redir_opt2); + return; + } + p = redir_str; if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) goto fail_syntax; Index: qemu-kvm-0.10.5/net.h =================================================================== --- qemu-kvm-0.10.5.orig/net.h +++ qemu-kvm-0.10.5/net.h @@ -114,7 +114,7 @@ int net_client_init(const char *device, 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(const char *redir_str); +void net_slirp_redir(const char *redir_str, const char *redir_opt2); void net_cleanup(void); int slirp_is_inited(void); void net_client_check(void); Index: qemu-kvm-0.10.5/slirp/libslirp.h =================================================================== --- qemu-kvm-0.10.5.orig/slirp/libslirp.h +++ qemu-kvm-0.10.5/slirp/libslirp.h @@ -18,6 +18,7 @@ void slirp_input(const uint8_t *pkt, int 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, Index: qemu-kvm-0.10.5/slirp/slirp.c =================================================================== --- qemu-kvm-0.10.5.orig/slirp/slirp.c +++ qemu-kvm-0.10.5/slirp/slirp.c @@ -734,6 +734,29 @@ void if_encap(const uint8_t *ip_data, in } } +/* 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) { Index: qemu-kvm-0.10.5/vl.c =================================================================== --- qemu-kvm-0.10.5.orig/vl.c +++ qemu-kvm-0.10.5/vl.c @@ -5201,7 +5201,7 @@ int main(int argc, char **argv, char **e break; #endif case QEMU_OPTION_redir: - net_slirp_redir(optarg); + net_slirp_redir(optarg, NULL); break; #endif case QEMU_OPTION_bt:
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor