From nobody Tue Apr 7 01:06:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1773736330; cv=none; d=zohomail.com; s=zohoarc; b=IE1eT9zSqb34isQop5T0hVl5dpuevMHQh8VokVWTCRp5vuJowkQhy+P14KF73LODOqWbke/xcitChmyI9NR689z7ntAiSEF5c4sEkvnJn3JDqlvHK3Qx27LsQ+rmyDsKMtwfhc/jz0fsMDk5YrMG151+E1XJ9Gm694BKDG3NUmU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773736330; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pSrlUlyXOigDwuRwu4ru0h6Wm5fmy+TstTOHZeCJ/to=; b=UdGsgEUX+UmYLEuQUoVuSdsElkWzrVbVoM+gdemXnF7kXIEPSqVpGuISIeqDVOPBgFdFGtHmUMoRkQlr6q4S8A5C5VhUrSmKkSFoKeeBdt7+ziup1KFSGL/mh5rYml/1d6jKVymF/asft2c683pI+egXHiJg2/yH2Rsfzz+lL90= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773736326346776.8832224041361; Tue, 17 Mar 2026 01:32:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2Ppm-0000te-83; Tue, 17 Mar 2026 04:31:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2Ppk-0000tR-II; Tue, 17 Mar 2026 04:31:24 -0400 Received: from isrv.corpit.ru ([212.248.84.144]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2Pph-0000Pp-Pj; Tue, 17 Mar 2026 04:31:24 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id DB90A19435E; Tue, 17 Mar 2026 11:31:11 +0300 (MSK) Received: from think4mjt.tls.msk.ru (mjtthink.wg.tls.msk.ru [192.168.177.146]) by tsrv.corpit.ru (Postfix) with ESMTP id E24C4381049; Tue, 17 Mar 2026 11:31:16 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tls.msk.ru; s=202602; t=1773736271; bh=Y38zX+TH4wKoRrc0z4ZeVSVneQS/3iIy/GomhQJ8Nms=; h=From:To:Cc:Subject:Date; b=J8TXR9sohbBbPr9gwpN6QG8Yf0jyVoiqGom39/ReLk+apRRpvg5jLLAAqlwu/Pur4 rHXwK/5kHqDzORsFiVVHmzqeplCz1nRe4YQPj0IwWno6KuwoztyUarsfhk3TFYMc8/ uPqbIE4Q6UsksYWbVNNVKJ/X6TitSCiIvObZZ/gshRfN03U08VXWuE8HGHJfnr1HKU yLg2YsD7p/+yw0v0TcN2vsZXIHJ9O3oNHRPUL0PKop57fbdKeCfsmXNgS54le3J1yX Qra78JFfgSL2ThWzwtNciwtVbdYca3yKC1LF6HR/hc/VDSfbMclbNKERBlKtXRv01s 8B4s3CX+4wUng== From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, Michael Tokarev , Christopher Palmer-Richez Subject: [PATCH RFC] net/slirp: allow hostfwd socket paths with dashes Date: Tue, 17 Mar 2026 11:31:08 +0300 Message-ID: <20260317083108.163043-1-mjt@tls.msk.ru> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=212.248.84.144; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @tls.msk.ru) X-ZM-MESSAGEID: 1773736343843158500 Content-Type: text/plain; charset="utf-8" The format of hostfwd parameter is: hostfwd=3Dhostpart-guestaddr:guestport so a minus sign can not be part of the hostpart. If hostpart specifies a unix socket path, this becomes problematic. To solve this, look for the LAST minus/dash char in the string, not first. Unfortunately, [-guestaddr] is optional (defaults to 10.0.0.15), so we still can't parse the thing in an uniform way. Extend get_str_sep() to accept one more parameter, to indicate if first or last separator is needed, and modify all callers to ask for first separator. Update slirp_hostfwd to search for the last separator when parsing unix domain socket path. Inspired-by: Christopher Palmer-Richez Resolves: https://gitlab.com/qemu-project/qemu/-/issues/347 --- net/slirp.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 04925f3318..804d430890 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -49,12 +49,18 @@ #include "migration/vmstate.h" #include "migration/qemu-file-types.h" =20 -static int get_str_sep(char *buf, int buf_size, const char **pp, int sep) +typedef enum { + SEP_FIRST, + SEP_LAST +} sep_type; + +static int get_str_sep(char *buf, int buf_size, const char **pp, int sep, + sep_type which) { const char *p, *p1; int len; p =3D *pp; - p1 =3D strchr(p, sep); + p1 =3D which =3D=3D SEP_FIRST ? strchr(p, sep) : strrchr(p, sep); if (!p1) return -1; len =3D p1 - p; @@ -479,7 +485,7 @@ static int net_slirp_init(NetClientState *peer, const c= har *model, } =20 if (vnetwork) { - if (get_str_sep(buf, sizeof(buf), &vnetwork, '/') < 0) { + if (get_str_sep(buf, sizeof(buf), &vnetwork, '/', SEP_FIRST) < 0) { if (!inet_aton(vnetwork, &net)) { error_setg(errp, "Failed to parse netmask"); return -1; @@ -760,7 +766,7 @@ void hmp_hostfwd_remove(Monitor *mon, const QDict *qdic= t) } =20 p =3D src_str; - if (!p || get_str_sep(buf, sizeof(buf), &p, ':') < 0) { + if (!p || get_str_sep(buf, sizeof(buf), &p, ':', SEP_FIRST) < 0) { goto fail_syntax; } =20 @@ -772,7 +778,7 @@ void hmp_hostfwd_remove(Monitor *mon, const QDict *qdic= t) goto fail_syntax; } =20 - if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) { + if (get_str_sep(buf, sizeof(buf), &p, ':', SEP_FIRST) < 0) { goto fail_syntax; } if (buf[0] !=3D '\0' && !inet_aton(buf, &host_addr.sin_addr)) { @@ -827,7 +833,7 @@ static int slirp_hostfwd(SlirpState *s, const char *red= ir_str, Error **errp) socklen_t host_addr_size; =20 p =3D redir_str; - if (!p || get_str_sep(buf, sizeof(buf), &p, ':') < 0) { + if (!p || get_str_sep(buf, sizeof(buf), &p, ':', SEP_FIRST) < 0) { fail_reason =3D "No : separators"; goto fail_syntax; } @@ -848,7 +854,7 @@ static int slirp_hostfwd(SlirpState *s, const char *red= ir_str, Error **errp) =20 #if !defined(WIN32) && SLIRP_CHECK_VERSION(4, 7, 0) if (is_unix) { - if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) { + if (get_str_sep(buf, sizeof(buf), &p, '-', SEP_LAST) < 0) { fail_reason =3D "Missing - separator"; goto fail_syntax; } @@ -888,7 +894,7 @@ static int slirp_hostfwd(SlirpState *s, const char *red= ir_str, Error **errp) host_addr.in.sin_family =3D AF_INET; host_addr.in.sin_addr.s_addr =3D INADDR_ANY; =20 - if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) { + if (get_str_sep(buf, sizeof(buf), &p, ':', SEP_FIRST) < 0) { fail_reason =3D "Missing : separator"; goto fail_syntax; } @@ -898,7 +904,7 @@ static int slirp_hostfwd(SlirpState *s, const char *red= ir_str, Error **errp) goto fail_syntax; } =20 - if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) { + if (get_str_sep(buf, sizeof(buf), &p, '-', SEP_FIRST) < 0) { fail_reason =3D "Bad host port separator"; goto fail_syntax; } @@ -913,7 +919,7 @@ static int slirp_hostfwd(SlirpState *s, const char *red= ir_str, Error **errp) host_addr_size =3D sizeof(host_addr.in); } =20 - if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) { + if (get_str_sep(buf, sizeof(buf), &p, ':', SEP_FIRST) < 0) { fail_reason =3D "Missing guest address"; goto fail_syntax; } @@ -1125,19 +1131,19 @@ static int slirp_guestfwd(SlirpState *s, const char= *config_str, Error **errp) int port; =20 p =3D config_str; - if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) { + if (get_str_sep(buf, sizeof(buf), &p, ':', SEP_FIRST) < 0) { goto fail_syntax; } if (strcmp(buf, "tcp") && buf[0] !=3D '\0') { goto fail_syntax; } - if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) { + if (get_str_sep(buf, sizeof(buf), &p, ':', SEP_FIRST) < 0) { goto fail_syntax; } if (buf[0] !=3D '\0' && !inet_aton(buf, &server)) { goto fail_syntax; } - if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) { + if (get_str_sep(buf, sizeof(buf), &p, '-', SEP_FIRST) < 0) { goto fail_syntax; } port =3D strtol(buf, &end, 10); --=20 2.47.3