From nobody Thu Apr 25 20:38:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515701672423224.32689481483635; Thu, 11 Jan 2018 12:14:32 -0800 (PST) Received: from localhost ([::1]:39337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZjEz-0000ay-Pv for importer@patchew.org; Thu, 11 Jan 2018 15:14:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37172) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZj3x-0006H5-Da for qemu-devel@nongnu.org; Thu, 11 Jan 2018 15:02:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZj3t-00017u-HF for qemu-devel@nongnu.org; Thu, 11 Jan 2018 15:02:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58160) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eZj3t-000144-97 for qemu-devel@nongnu.org; Thu, 11 Jan 2018 15:02:53 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F3D8EC054C5F; Thu, 11 Jan 2018 20:02:45 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-54.ams2.redhat.com [10.36.116.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D6CE9092; Thu, 11 Jan 2018 20:02:41 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org, Jason Wang , Samuel Thibault Date: Thu, 11 Jan 2018 21:02:40 +0100 Message-Id: <1515700960-26388-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 11 Jan 2018 20:02:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] net: Allow netdevs to be used with 'hostfwd_add' and 'hostfwd_remove' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It does not make much sense to limit these commands to the legacy 'vlan' concept only, they should work with the modern netdevs, too. So now it is possible to use this command with one, two or three parameters. With one parameter, the command installs a hostfwd rule on the default "user" network: hostfwd_add tcp:... With two parameters, the command installs a hostfwd rule on a netdev (that's the new way of using this command): hostfwd_add netdev_id tcp:... With three parameters, the command installs a rule on a 'vlan' (aka hub): hostfwd_add hub_id name tcp:... Same applies to the hostfwd_remove command now. Signed-off-by: Thomas Huth --- hmp-commands.hx | 4 ++-- net/slirp.c | 33 +++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 1a680c7..0ef2008 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1353,7 +1353,7 @@ ETEXI { .name =3D "hostfwd_add", .args_type =3D "arg1:s,arg2:s?,arg3:s?", - .params =3D "[vlan_id name] [tcp|udp]:[hostaddr]:hostport-[gue= staddr]:guestport", + .params =3D "[hub_id name]|[netdev_id] [tcp|udp]:[hostaddr]:ho= stport-[guestaddr]:guestport", .help =3D "redirect TCP or UDP connections from host to gues= t (requires -net user)", .cmd =3D hmp_hostfwd_add, }, @@ -1368,7 +1368,7 @@ ETEXI { .name =3D "hostfwd_remove", .args_type =3D "arg1:s,arg2:s?,arg3:s?", - .params =3D "[vlan_id name] [tcp|udp]:[hostaddr]:hostport", + .params =3D "[hub_id name]|[netdev_id] [tcp|udp]:[hostaddr]:ho= stport", .help =3D "remove host-to-guest TCP or UDP redirection", .cmd =3D hmp_hostfwd_remove, }, diff --git a/net/slirp.c b/net/slirp.c index cb8ca23..7044d29 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -405,16 +405,23 @@ error: return -1; } =20 -static SlirpState *slirp_lookup(Monitor *mon, const char *vlan, - const char *stack) +static SlirpState *slirp_lookup(Monitor *mon, const char *hub_id, + const char *name) { - - if (vlan) { + if (name) { NetClientState *nc; - nc =3D net_hub_find_client_by_name(strtol(vlan, NULL, 0), stack); - if (!nc) { - monitor_printf(mon, "unrecognized (vlan-id, stackname) pair\n"= ); - return NULL; + if (hub_id) { + nc =3D net_hub_find_client_by_name(strtol(hub_id, NULL, 0), na= me); + if (!nc) { + monitor_printf(mon, "unrecognized (vlan-id, stackname) pai= r\n"); + return NULL; + } + } else { + nc =3D qemu_find_netdev(name); + if (!nc) { + monitor_printf(mon, "unrecognized netdev id '%s'\n", name); + return NULL; + } } if (strcmp(nc->model, "user")) { monitor_printf(mon, "invalid device specified\n"); @@ -443,9 +450,12 @@ void hmp_hostfwd_remove(Monitor *mon, const QDict *qdi= ct) const char *arg2 =3D qdict_get_try_str(qdict, "arg2"); const char *arg3 =3D qdict_get_try_str(qdict, "arg3"); =20 - if (arg2) { + if (arg3) { s =3D slirp_lookup(mon, arg1, arg2); src_str =3D arg3; + } else if (arg2) { + s =3D slirp_lookup(mon, NULL, arg1); + src_str =3D arg2; } else { s =3D slirp_lookup(mon, NULL, NULL); src_str =3D arg1; @@ -570,9 +580,12 @@ void hmp_hostfwd_add(Monitor *mon, const QDict *qdict) const char *arg2 =3D qdict_get_try_str(qdict, "arg2"); const char *arg3 =3D qdict_get_try_str(qdict, "arg3"); =20 - if (arg2) { + if (arg3) { s =3D slirp_lookup(mon, arg1, arg2); redir_str =3D arg3; + } else if (arg2) { + s =3D slirp_lookup(mon, NULL, arg1); + redir_str =3D arg2; } else { s =3D slirp_lookup(mon, NULL, NULL); redir_str =3D arg1; --=20 1.8.3.1