From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549548739185701.2972430645445; Thu, 7 Feb 2019 06:12:19 -0800 (PST) Received: from localhost ([127.0.0.1]:40701 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkPV-0008Od-4T for importer@patchew.org; Thu, 07 Feb 2019 09:12:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHR-00023a-0y for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHP-0000y3-TM for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:52 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41818) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHN-0000rV-KR for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 46C29CD23; Thu, 7 Feb 2019 15:03:27 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5Fh8i_39pN0Y; Thu, 7 Feb 2019 15:03:23 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id BE8EBCD1E; Thu, 7 Feb 2019 15:03:18 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGq-0004D0-P0; Thu, 07 Feb 2019 15:03:16 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:45 +0200 Message-Id: <20190207140316.16103-2-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 01/32] slirp: Avoid unaligned 16bit memory access 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: Samuel Thibault , Richard Henderson , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" pkt parameter may be unaligned, so we must access it byte-wise. This fixes sparc64 host SIGBUS during pxe boot. Signed-off-by: Samuel Thibault Reviewed-by: Richard Henderson --- slirp/slirp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slirp/slirp.c b/slirp/slirp.c index a9674ab090..739f364770 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -829,7 +829,7 @@ void slirp_input(Slirp *slirp, const uint8_t *pkt, int = pkt_len) if (pkt_len < ETH_HLEN) return; =20 - proto =3D ntohs(*(uint16_t *)(pkt + 12)); + proto =3D (((uint16_t) pkt[12]) << 8) + pkt[13]; switch(proto) { case ETH_P_ARP: arp_input(slirp, pkt, pkt_len); --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 1549548361360917.7747841582434; Thu, 7 Feb 2019 06:06:01 -0800 (PST) Received: from localhost ([127.0.0.1]:40607 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkJQ-0003Gc-6d for importer@patchew.org; Thu, 07 Feb 2019 09:05:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHG-0001we-1X for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHD-0000rF-Jd for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:41 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49540) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkGy-0000lp-Gw for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:28 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 25873C8A7; Thu, 7 Feb 2019 15:03:22 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xejfqT4Jvwgx; Thu, 7 Feb 2019 15:03:18 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 62A81CC15; Thu, 7 Feb 2019 15:03:18 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGq-0004D2-QH; Thu, 07 Feb 2019 15:03:16 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:46 +0200 Message-Id: <20190207140316.16103-3-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 02/32] slirp: Avoid marking naturally packed structs as QEMU_PACKED 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: jan.kiszka@siemens.com, stefanha@redhat.com, Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Peter Maydell Various ipv6 structs in the slirp headers are marked QEMU_PACKED, but they are actually naturally aligned and will have no padding in them. Instead of marking them with the 'packed' attribute, assert at compile time that they are the size we expect. This allows us to take the address of fields within the structs without risking undefined behaviour, and suppresses clang -Waddress-of-packed-member warnings. Signed-off-by: Peter Maydell Reviewed-by: Eric Blake Signed-off-by: Samuel Thibault --- slirp/ip6.h | 12 ++++++++++-- slirp/ip6_icmp.h | 20 +++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/slirp/ip6.h b/slirp/ip6.h index 14e9c78735..1e3e329ce6 100644 --- a/slirp/ip6.h +++ b/slirp/ip6.h @@ -133,7 +133,7 @@ struct ip6 { uint8_t ip_nh; /* next header */ uint8_t ip_hl; /* hop limit */ struct in6_addr ip_src, ip_dst; /* source and dest address */ -} QEMU_PACKED; +}; =20 /* * IPv6 pseudo-header used by upper-layer protocols @@ -145,7 +145,15 @@ struct ip6_pseudohdr { uint16_t ih_zero_hi; /* zero */ uint8_t ih_zero_lo; /* zero */ uint8_t ih_nh; /* next header */ -} QEMU_PACKED; +}; =20 +/* + * We don't want to mark these ip6 structs as packed as they are naturally + * correctly aligned; instead assert that there is no stray padding. + * If we marked the struct as packed then we would be unable to take + * the address of any of the fields in it. + */ +QEMU_BUILD_BUG_ON(sizeof(struct ip6) !=3D 40); +QEMU_BUILD_BUG_ON(sizeof(struct ip6_pseudohdr) !=3D 40); =20 #endif diff --git a/slirp/ip6_icmp.h b/slirp/ip6_icmp.h index 32b0914055..2ad2b75e67 100644 --- a/slirp/ip6_icmp.h +++ b/slirp/ip6_icmp.h @@ -48,12 +48,16 @@ struct ndp_ra { /* Router Advertisement Message */ uint16_t lifetime; /* Router Lifetime */ uint32_t reach_time; /* Reachable Time */ uint32_t retrans_time; /* Retrans Timer */ -} QEMU_PACKED; +}; + +QEMU_BUILD_BUG_ON(sizeof(struct ndp_ra) !=3D 12); =20 struct ndp_ns { /* Neighbor Solicitation Message */ uint32_t reserved; struct in6_addr target; /* Target Address */ -} QEMU_PACKED; +}; + +QEMU_BUILD_BUG_ON(sizeof(struct ndp_ns) !=3D 20); =20 struct ndp_na { /* Neighbor Advertisement Message */ #if G_BYTE_ORDER =3D=3D G_BIG_ENDIAN @@ -72,13 +76,17 @@ struct ndp_na { /* Neighbor Advertisement Message */ reserved_lo:24; #endif struct in6_addr target; /* Target Address */ -} QEMU_PACKED; +}; + +QEMU_BUILD_BUG_ON(sizeof(struct ndp_na) !=3D 20); =20 struct ndp_redirect { uint32_t reserved; struct in6_addr target; /* Target Address */ struct in6_addr dest; /* Destination Address */ -} QEMU_PACKED; +}; + +QEMU_BUILD_BUG_ON(sizeof(struct ndp_redirect) !=3D 36); =20 /* * Structure of an icmpv6 header. @@ -103,7 +111,9 @@ struct icmp6 { #define icmp6_nns icmp6_body.ndp_ns #define icmp6_nna icmp6_body.ndp_na #define icmp6_redirect icmp6_body.ndp_redirect -} QEMU_PACKED; +}; + +QEMU_BUILD_BUG_ON(sizeof(struct icmp6) !=3D 40); =20 #define ICMP6_MINLEN 4 #define ICMP6_ERROR_MINLEN 8 --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549548382841774.0253294801519; Thu, 7 Feb 2019 06:06:22 -0800 (PST) Received: from localhost ([127.0.0.1]:40621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkJh-0003Si-Oo for importer@patchew.org; Thu, 07 Feb 2019 09:06:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57258) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHJ-0001wr-V9 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHC-0000qa-7h for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:43 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41586) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkGy-0000m0-Es for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:27 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 825E9CC15; Thu, 7 Feb 2019 15:03:22 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8tCbRXnn4VTf; Thu, 7 Feb 2019 15:03:19 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 8AED0CD1C; Thu, 7 Feb 2019 15:03:18 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGq-0004D4-Ro; Thu, 07 Feb 2019 15:03:16 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:47 +0200 Message-Id: <20190207140316.16103-4-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 03/32] slirp: Don't mark struct ipq or struct ipasfrag as packed 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: jan.kiszka@siemens.com, stefanha@redhat.com, Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Peter Maydell There is no reason to mark the struct ipq and struct ipasfrag as packed: they are naturally aligned anyway, and are not representing any on-the-wire packet format. Indeed they vary in size depending on the size of pointers on the host system, because the 'struct qlink' members include 'void *' fields. Dropping the 'packed' annotation fixes clang -Waddress-of-packed-member warnings and probably lets the compiler generate better code too. The only thing we do care about in the layout of the struct is that the frag_link matches up with the ipf_link of the struct ipasfrag, as documented in the comment on that struct; assert at build time that this is the case. Signed-off-by: Peter Maydell Reviewed-by: Eric Blake Signed-off-by: Samuel Thibault --- slirp/ip.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/slirp/ip.h b/slirp/ip.h index 243b6c8b24..20614f3b53 100644 --- a/slirp/ip.h +++ b/slirp/ip.h @@ -217,7 +217,7 @@ struct ipq { uint8_t ipq_p; /* protocol of this fragment */ uint16_t ipq_id; /* sequence id for reassembly */ struct in_addr ipq_src,ipq_dst; -} QEMU_PACKED; +}; =20 /* * Ip header, when holding a fragment. @@ -227,7 +227,10 @@ struct ipq { struct ipasfrag { struct qlink ipf_link; struct ip ipf_ip; -} QEMU_PACKED; +}; + +QEMU_BUILD_BUG_ON(offsetof(struct ipq, frag_link) !=3D + offsetof(struct ipasfrag, ipf_link)); =20 #define ipf_off ipf_ip.ip_off #define ipf_tos ipf_ip.ip_tos --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549549658716498.66277334607435; Thu, 7 Feb 2019 06:27:38 -0800 (PST) Received: from localhost ([127.0.0.1]:40927 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkeK-0004Yq-Ki for importer@patchew.org; Thu, 07 Feb 2019 09:27:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHV-00027M-1w for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHP-0000yI-TK for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:56 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41618) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHN-0000mk-Nr for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 35AF9CD08; Thu, 7 Feb 2019 15:03:24 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0FZuO3obu4Y4; Thu, 7 Feb 2019 15:03:22 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id B34F5CD1D; Thu, 7 Feb 2019 15:03:18 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGq-0004D6-Th; Thu, 07 Feb 2019 15:03:16 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:48 +0200 Message-Id: <20190207140316.16103-5-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 04/32] slirp: generalize guestfwd with a callback based approach 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Instead of calling into QEMU chardev directly, and mixing it with slirp_add_exec() handling, add a new function slirp_add_guestfwd() which takes a write callback. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 14 ++++++++++---- slirp/libslirp.h | 6 +++++- slirp/misc.c | 37 +++++++++++++++++++++++-------------- slirp/misc.h | 15 +++++++++++++-- slirp/slirp.c | 27 +++++++++++++++++++-------- slirp/socket.h | 4 +++- slirp/tcp_subr.c | 4 ++-- 7 files changed, 75 insertions(+), 32 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index f98425ee9f..ec07f662c0 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -704,8 +704,8 @@ static int slirp_smb(SlirpState* s, const char *exporte= d_dir, CONFIG_SMBD_COMMAND, s->smb_dir, smb_conf); g_free(smb_conf); =20 - if (slirp_add_exec(s->slirp, NULL, smb_cmdline, &vserver_addr, 139) < = 0 || - slirp_add_exec(s->slirp, NULL, smb_cmdline, &vserver_addr, 445) < = 0) { + if (slirp_add_exec(s->slirp, smb_cmdline, &vserver_addr, 139) < 0 || + slirp_add_exec(s->slirp, smb_cmdline, &vserver_addr, 445) < 0) { slirp_smb_cleanup(s); g_free(smb_cmdline); error_setg(errp, "Conflicting/invalid smbserver address"); @@ -736,6 +736,11 @@ static void guestfwd_read(void *opaque, const uint8_t = *buf, int size) slirp_socket_recv(fwd->slirp, fwd->server, fwd->port, buf, size); } =20 +static int guestfwd_write(const void *buf, size_t len, void *chr) +{ + return qemu_chr_fe_write_all(chr, buf, len); +} + static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **e= rrp) { struct in_addr server =3D { .s_addr =3D 0 }; @@ -769,7 +774,7 @@ static int slirp_guestfwd(SlirpState *s, const char *co= nfig_str, Error **errp) snprintf(buf, sizeof(buf), "guestfwd.tcp.%d", port); =20 if ((strlen(p) > 4) && !strncmp(p, "cmd:", 4)) { - if (slirp_add_exec(s->slirp, NULL, &p[4], &server, port) < 0) { + if (slirp_add_exec(s->slirp, &p[4], &server, port) < 0) { error_setg(errp, "Conflicting/invalid host:port in guest " "forwarding rule '%s'", config_str); return -1; @@ -796,7 +801,8 @@ static int slirp_guestfwd(SlirpState *s, const char *co= nfig_str, Error **errp) return -1; } =20 - if (slirp_add_exec(s->slirp, &fwd->hd, NULL, &server, port) < 0) { + if (slirp_add_guestfwd(s->slirp, guestfwd_write, &fwd->hd, + &server, port) < 0) { error_setg(errp, "Conflicting/invalid host:port in guest " "forwarding rule '%s'", config_str); g_free(fwd); diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 4611a7447b..ea019828e8 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -5,6 +5,8 @@ =20 typedef struct Slirp Slirp; =20 +typedef int (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); + /* * Callbacks from slirp * @@ -45,7 +47,9 @@ int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr guest_addr, int guest_port); int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, int host_port); -int slirp_add_exec(Slirp *slirp, void *chardev, const char *cmdline, +int slirp_add_exec(Slirp *slirp, const char *cmdline, + struct in_addr *guest_addr, int guest_port); +int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque, struct in_addr *guest_addr, int guest_port); =20 char *slirp_connection_info(Slirp *slirp); diff --git a/slirp/misc.c b/slirp/misc.c index eae9596a55..b8a2bf971a 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -32,24 +32,33 @@ remque(void *a) element->qh_rlink =3D NULL; } =20 -int add_exec(struct gfwd_list **ex_ptr, void *chardev, const char *cmdline, +struct gfwd_list * +add_guestfwd(struct gfwd_list **ex_ptr, + SlirpWriteCb write_cb, void *opaque, struct in_addr addr, int port) { - struct gfwd_list *tmp_ptr; - - tmp_ptr =3D *ex_ptr; - *ex_ptr =3D g_new0(struct gfwd_list, 1); - (*ex_ptr)->ex_fport =3D port; - (*ex_ptr)->ex_addr =3D addr; - if (chardev) { - (*ex_ptr)->ex_chardev =3D chardev; - } else { - (*ex_ptr)->ex_exec =3D g_strdup(cmdline); - } - (*ex_ptr)->ex_next =3D tmp_ptr; - return 0; + struct gfwd_list *f =3D g_new0(struct gfwd_list, 1); + + f->write_cb =3D write_cb; + f->opaque =3D opaque; + f->ex_fport =3D port; + f->ex_addr =3D addr; + f->ex_next =3D *ex_ptr; + *ex_ptr =3D f; + + return f; } =20 +struct gfwd_list * +add_exec(struct gfwd_list **ex_ptr, const char *cmdline, + struct in_addr addr, int port) +{ + struct gfwd_list *f =3D add_guestfwd(ex_ptr, NULL, NULL, addr, port); + + f->ex_exec =3D g_strdup(cmdline); + + return f; +} =20 static int slirp_socketpair_with_oob(int sv[2]) diff --git a/slirp/misc.h b/slirp/misc.h index 1df707c052..c2ceadb591 100644 --- a/slirp/misc.h +++ b/slirp/misc.h @@ -8,8 +8,11 @@ #ifndef MISC_H #define MISC_H =20 +#include "libslirp.h" + struct gfwd_list { - void *ex_chardev; + SlirpWriteCb write_cb; + void *opaque; struct in_addr ex_addr; /* Server address */ int ex_fport; /* Port to telnet to */ char *ex_exec; /* Command line of what to exec */ @@ -51,7 +54,15 @@ struct slirp_quehead { =20 void slirp_insque(void *, void *); void slirp_remque(void *); -int add_exec(struct gfwd_list **, void *, const char *, struct in_addr, in= t); int fork_exec(struct socket *so, const char *ex); =20 +struct gfwd_list * +add_guestfwd(struct gfwd_list **ex_ptr, + SlirpWriteCb write_cb, void *opaque, + struct in_addr addr, int port); + +struct gfwd_list * +add_exec(struct gfwd_list **ex_ptr, const char *cmdline, + struct in_addr addr, int port); + #endif diff --git a/slirp/slirp.c b/slirp/slirp.c index 739f364770..a411221914 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -25,7 +25,6 @@ #include "qemu-common.h" #include "qemu/timer.h" #include "qemu/error-report.h" -#include "chardev/char-fe.h" #include "migration/register.h" #include "slirp.h" #include "hw/hw.h" @@ -1068,23 +1067,35 @@ check_guestfwd(Slirp *slirp, struct in_addr *guest_= addr, int guest_port) return true; } =20 -int slirp_add_exec(Slirp *slirp, void *chardev, const char *cmdline, +int slirp_add_exec(Slirp *slirp, const char *cmdline, struct in_addr *guest_addr, int guest_port) { if (!check_guestfwd(slirp, guest_addr, guest_port)) { return -1; } =20 - return add_exec(&slirp->guestfwd_list, chardev, cmdline, *guest_addr, - htons(guest_port)); + add_exec(&slirp->guestfwd_list, cmdline, *guest_addr, htons(guest_port= )); + return 0; +} + +int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque, + struct in_addr *guest_addr, int guest_port) +{ + if (!check_guestfwd(slirp, guest_addr, guest_port)) { + return -1; + } + + add_guestfwd(&slirp->guestfwd_list, write_cb, opaque, + *guest_addr, htons(guest_port)); + return 0; } =20 ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int fla= gs) { - if (so->s =3D=3D -1 && so->chardev) { + if (so->s =3D=3D -1 && so->guestfwd) { /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ - qemu_chr_fe_write_all(so->chardev, buf, len); + so->guestfwd->write_cb(buf, len, so->guestfwd->opaque); return len; } =20 @@ -1449,7 +1460,7 @@ static void slirp_state_save(QEMUFile *f, void *opaqu= e) struct gfwd_list *ex_ptr; =20 for (ex_ptr =3D slirp->guestfwd_list; ex_ptr; ex_ptr =3D ex_ptr->ex_ne= xt) - if (ex_ptr->ex_chardev) { + if (ex_ptr->write_cb) { struct socket *so; so =3D slirp_find_ctl_socket(slirp, ex_ptr->ex_addr, ntohs(ex_ptr->ex_fport)); @@ -1484,7 +1495,7 @@ static int slirp_state_load(QEMUFile *f, void *opaque= , int version_id) return -EINVAL; } for (ex_ptr =3D slirp->guestfwd_list; ex_ptr; ex_ptr =3D ex_ptr->e= x_next) { - if (ex_ptr->ex_chardev && + if (ex_ptr->write_cb && so->so_faddr.s_addr =3D=3D ex_ptr->ex_addr.s_addr && so->so_fport =3D=3D ex_ptr->ex_fport) { break; diff --git a/slirp/socket.h b/slirp/socket.h index 930ed95972..fc35ca5f72 100644 --- a/slirp/socket.h +++ b/slirp/socket.h @@ -8,6 +8,8 @@ #ifndef SLIRP_SOCKET_H #define SLIRP_SOCKET_H =20 +#include "misc.h" + #define SO_EXPIRE 240000 #define SO_EXPIREFAST 10000 =20 @@ -25,6 +27,7 @@ struct socket { struct socket *so_next,*so_prev; /* For a linked list of sockets */ =20 int s; /* The actual socket */ + struct gfwd_list *guestfwd; =20 int pollfds_idx; /* GPollFD GArray index */ =20 @@ -67,7 +70,6 @@ struct socket { =20 struct sbuf so_rcv; /* Receive buffer */ struct sbuf so_snd; /* Send buffer */ - void * chardev; }; =20 =20 diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 23a841f26e..4e81736d6f 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -964,9 +964,9 @@ int tcp_ctl(struct socket *so) for (ex_ptr =3D slirp->guestfwd_list; ex_ptr; ex_ptr =3D ex_ptr->e= x_next) { if (ex_ptr->ex_fport =3D=3D so->so_fport && so->so_faddr.s_addr =3D=3D ex_ptr->ex_addr.s_addr) { - if (ex_ptr->ex_chardev) { + if (ex_ptr->write_cb) { so->s =3D -1; - so->chardev =3D ex_ptr->ex_chardev; + so->guestfwd =3D ex_ptr; return 1; } DEBUG_MISC(" executing %s", ex_ptr->ex_exec); --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549549489394617.1150517195916; Thu, 7 Feb 2019 06:24:49 -0800 (PST) Received: from localhost ([127.0.0.1]:40868 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkbb-0001p7-C0 for importer@patchew.org; Thu, 07 Feb 2019 09:24:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHX-00029E-06 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHP-0000yN-TT for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:58 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49754) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHP-0000qg-KF for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 5DB8FCD20; Thu, 7 Feb 2019 15:03:25 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dM2Z3PxRgZTV; Thu, 7 Feb 2019 15:03:24 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 0337BCD1F; Thu, 7 Feb 2019 15:03:18 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGq-0004D8-VJ; Thu, 07 Feb 2019 15:03:16 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:49 +0200 Message-Id: <20190207140316.16103-6-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 05/32] net/slirp: simplify checking for cmd: prefix 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/slirp.c b/net/slirp.c index ec07f662c0..b91741b8fc 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -773,7 +773,7 @@ static int slirp_guestfwd(SlirpState *s, const char *co= nfig_str, Error **errp) =20 snprintf(buf, sizeof(buf), "guestfwd.tcp.%d", port); =20 - if ((strlen(p) > 4) && !strncmp(p, "cmd:", 4)) { + if (g_str_has_prefix(p, "cmd:")) { if (slirp_add_exec(s->slirp, &p[4], &server, port) < 0) { error_setg(errp, "Conflicting/invalid host:port in guest " "forwarding rule '%s'", config_str); --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549549004716557.0334772506782; Thu, 7 Feb 2019 06:16:44 -0800 (PST) Received: from localhost ([127.0.0.1]:40761 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkTm-0003iz-HX for importer@patchew.org; Thu, 07 Feb 2019 09:16:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHX-00029F-05 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHP-0000xY-Qk for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:58 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49588) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHN-0000n1-Nf for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id C6134CD1D; Thu, 7 Feb 2019 15:03:24 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SA-PKKAmLWvY; Thu, 7 Feb 2019 15:03:24 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id EAE18CD20; Thu, 7 Feb 2019 15:03:18 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004DA-0S; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:50 +0200 Message-Id: <20190207140316.16103-7-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 06/32] net/slirp: free forwarding rules on cleanup 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index b91741b8fc..750105a466 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -75,6 +75,13 @@ struct slirp_config_str { char str[1024]; }; =20 +struct GuestFwd { + CharBackend hd; + struct in_addr server; + int port; + Slirp *slirp; +}; + typedef struct SlirpState { NetClientState nc; QTAILQ_ENTRY(SlirpState) entry; @@ -83,6 +90,7 @@ typedef struct SlirpState { #ifndef _WIN32 gchar *smb_dir; #endif + GSList *fwd; } SlirpState; =20 static struct slirp_config_str *slirp_configs; @@ -122,10 +130,19 @@ static void slirp_smb_exit(Notifier *n, void *data) slirp_smb_cleanup(s); } =20 +static void slirp_free_fwd(gpointer data) +{ + struct GuestFwd *fwd =3D data; + + qemu_chr_fe_deinit(&fwd->hd, true); + g_free(data); +} + static void net_slirp_cleanup(NetClientState *nc) { SlirpState *s =3D DO_UPCAST(SlirpState, nc, nc); =20 + g_slist_free_full(s->fwd, slirp_free_fwd); slirp_cleanup(s->slirp); if (s->exit_notifier.notify) { qemu_remove_exit_notifier(&s->exit_notifier); @@ -717,13 +734,6 @@ static int slirp_smb(SlirpState* s, const char *export= ed_dir, =20 #endif /* !defined(_WIN32) */ =20 -struct GuestFwd { - CharBackend hd; - struct in_addr server; - int port; - Slirp *slirp; -}; - static int guestfwd_can_read(void *opaque) { struct GuestFwd *fwd =3D opaque; @@ -814,6 +824,7 @@ static int slirp_guestfwd(SlirpState *s, const char *co= nfig_str, Error **errp) =20 qemu_chr_fe_set_handlers(&fwd->hd, guestfwd_can_read, guestfwd_rea= d, NULL, NULL, fwd, NULL, true); + s->fwd =3D g_slist_append(s->fwd, fwd); } return 0; =20 --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 15495489190039.269772719333446; Thu, 7 Feb 2019 06:15:19 -0800 (PST) Received: from localhost ([127.0.0.1]:40727 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkSK-0002UV-1S for importer@patchew.org; Thu, 07 Feb 2019 09:15:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHX-00029H-0A for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHP-0000y8-TU for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:58 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41798) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHN-0000qi-NL for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 03735CD1F; Thu, 7 Feb 2019 15:03:26 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id R4QBtrZkaIAV; Thu, 7 Feb 2019 15:03:25 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 5045BCD22; Thu, 7 Feb 2019 15:03:18 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004DC-29; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:51 +0200 Message-Id: <20190207140316.16103-8-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 07/32] net/slirp: fix leaks on forwarding rule registration error 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/slirp.c b/net/slirp.c index 750105a466..0b15f427f5 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -807,6 +807,7 @@ static int slirp_guestfwd(SlirpState *s, const char *co= nfig_str, Error **errp) qemu_chr_fe_init(&fwd->hd, chr, &err); if (err) { error_propagate(errp, err); + object_unparent(OBJECT(chr)); g_free(fwd); return -1; } @@ -815,6 +816,7 @@ static int slirp_guestfwd(SlirpState *s, const char *co= nfig_str, Error **errp) &server, port) < 0) { error_setg(errp, "Conflicting/invalid host:port in guest " "forwarding rule '%s'", config_str); + qemu_chr_fe_deinit(&fwd->hd, true); g_free(fwd); return -1; } --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 1549548452381195.5547847856252; Thu, 7 Feb 2019 06:07:32 -0800 (PST) Received: from localhost ([127.0.0.1]:40623 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkKx-0004WI-83 for importer@patchew.org; Thu, 07 Feb 2019 09:07:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHS-00024V-8u for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHP-0000yD-TO for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41816) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHN-0000rT-IY for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id A5DD4CD22; Thu, 7 Feb 2019 15:03:26 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nVUCbbOgeHPp; Thu, 7 Feb 2019 15:03:26 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 622FACD23; Thu, 7 Feb 2019 15:03:18 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004DE-44; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:52 +0200 Message-Id: <20190207140316.16103-9-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 08/32] slirp: add callbacks for timer 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 21 +++++++++++++++++++++ slirp/ip6_icmp.c | 16 +++++++--------- slirp/libslirp.h | 14 +++++++++++--- slirp/slirp.h | 2 +- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 0b15f427f5..c24a779425 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -168,10 +168,31 @@ static int64_t net_slirp_clock_get_ns(void) return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); } =20 +static void *net_slirp_timer_new(SlirpTimerCb cb, void *opaque) +{ + return timer_new_full(NULL, QEMU_CLOCK_VIRTUAL, + SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL, + cb, opaque); +} + +static void net_slirp_timer_free(void *timer) +{ + timer_del(timer); + timer_free(timer); +} + +static void net_slirp_timer_mod(void *timer, int64_t expire_timer) +{ + timer_mod(timer, expire_timer); +} + static const SlirpCb slirp_cb =3D { .output =3D net_slirp_output, .guest_error =3D net_slirp_guest_error, .clock_get_ns =3D net_slirp_clock_get_ns, + .timer_new =3D net_slirp_timer_new, + .timer_free =3D net_slirp_timer_free, + .timer_mod =3D net_slirp_timer_mod, }; =20 static int net_slirp_init(NetClientState *peer, const char *model, diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 5261baae27..e72c57a81d 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -16,8 +16,9 @@ static void ra_timer_handler(void *opaque) { Slirp *slirp =3D opaque; - timer_mod(slirp->ra_timer, - slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interval); + + slirp->cb->timer_mod(slirp->ra_timer, + slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interv= al); ndp_send_ra(slirp); } =20 @@ -27,11 +28,9 @@ void icmp6_init(Slirp *slirp) return; } =20 - slirp->ra_timer =3D timer_new_full(NULL, QEMU_CLOCK_VIRTUAL, - SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL, - ra_timer_handler, slirp); - timer_mod(slirp->ra_timer, - slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interval); + slirp->ra_timer =3D slirp->cb->timer_new(ra_timer_handler, slirp); + slirp->cb->timer_mod(slirp->ra_timer, + slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interv= al); } =20 void icmp6_cleanup(Slirp *slirp) @@ -40,8 +39,7 @@ void icmp6_cleanup(Slirp *slirp) return; } =20 - timer_del(slirp->ra_timer); - timer_free(slirp->ra_timer); + slirp->cb->timer_free(slirp->ra_timer); } =20 static void icmp6_send_echoreply(struct mbuf *m, Slirp *slirp, struct ip6 = *ip, diff --git a/slirp/libslirp.h b/slirp/libslirp.h index ea019828e8..3e75dadfa3 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -6,19 +6,27 @@ typedef struct Slirp Slirp; =20 typedef int (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); +typedef void (*SlirpTimerCb)(void *opaque); =20 /* * Callbacks from slirp - * - * The opaque parameter comes from the opaque parameter given to slirp_ini= t(). */ typedef struct SlirpCb { - /* Send an ethernet frame to the guest network. */ + /* + * Send an ethernet frame to the guest network. The opaque parameter + * is the one given to slirp_init(). + */ void (*output)(void *opaque, const uint8_t *pkt, int pkt_len); /* Print a message for an error due to guest misbehavior. */ void (*guest_error)(const char *msg); /* Return the virtual clock value in nanoseconds */ int64_t (*clock_get_ns)(void); + /* Create a new timer with the given callback and opaque data */ + void *(*timer_new)(SlirpTimerCb cb, void *opaque); + /* Remove and free a timer */ + void (*timer_free)(void *timer); + /* Modify a timer to expire at @expire_time */ + void (*timer_mod)(void *timer, int64_t expire_time); } SlirpCb; =20 =20 diff --git a/slirp/slirp.h b/slirp/slirp.h index 9aa245715d..17056f4b83 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -193,7 +193,7 @@ struct Slirp { NdpTable ndp_table; =20 GRand *grand; - QEMUTimer *ra_timer; + void *ra_timer; =20 const SlirpCb *cb; void *opaque; --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549548562097916.7897237017443; Thu, 7 Feb 2019 06:09:22 -0800 (PST) Received: from localhost ([127.0.0.1]:40643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkMY-0005lF-JA for importer@patchew.org; Thu, 07 Feb 2019 09:09:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57290) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHN-0001z1-M0 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHL-0000uK-Pf for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:49 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41820) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHJ-0000rW-Ue for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:47 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id AD7F8CD1E; Thu, 7 Feb 2019 15:03:27 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mrFUBQn9u82U; Thu, 7 Feb 2019 15:03:26 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 74F6ECD24; Thu, 7 Feb 2019 15:03:18 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004DG-5q; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:53 +0200 Message-Id: <20190207140316.16103-10-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 09/32] slirp: replace trace functions with DEBUG calls 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Remove a dependency on QEMU. Use the existing logging facilities. Set SLIRP_DEBUG=3Dtftp to get tftp log. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- Makefile.objs | 1 - slirp/debug.h | 13 ++++++++++--- slirp/slirp.c | 1 + slirp/tftp.c | 7 ++++--- slirp/trace-events | 5 ----- 5 files changed, 15 insertions(+), 12 deletions(-) delete mode 100644 slirp/trace-events diff --git a/Makefile.objs b/Makefile.objs index 67a054b08a..b7aae33367 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -192,7 +192,6 @@ trace-events-subdirs +=3D net trace-events-subdirs +=3D qapi trace-events-subdirs +=3D qom trace-events-subdirs +=3D scsi -trace-events-subdirs +=3D slirp trace-events-subdirs +=3D target/arm trace-events-subdirs +=3D target/i386 trace-events-subdirs +=3D target/mips diff --git a/slirp/debug.h b/slirp/debug.h index 269d97d807..44d922df37 100644 --- a/slirp/debug.h +++ b/slirp/debug.h @@ -8,9 +8,10 @@ #ifndef DEBUG_H_ #define DEBUG_H_ =20 -#define DBG_CALL 0x1 -#define DBG_MISC 0x2 -#define DBG_ERROR 0x4 +#define DBG_CALL (1 << 0) +#define DBG_MISC (1 << 1) +#define DBG_ERROR (1 << 2) +#define DBG_TFTP (1 << 3) =20 extern int slirp_debug; =20 @@ -38,4 +39,10 @@ extern int slirp_debug; } \ } while (0) =20 +#define DEBUG_TFTP(fmt, ...) do { \ + if (G_UNLIKELY(slirp_debug & DBG_TFTP)) { \ + g_debug(fmt, ##__VA_ARGS__); \ + } \ +} while (0) + #endif /* DEBUG_H_ */ diff --git a/slirp/slirp.c b/slirp/slirp.c index a411221914..12677e5da7 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -270,6 +270,7 @@ static void slirp_init_once(void) { "call", DBG_CALL }, { "misc", DBG_MISC }, { "error", DBG_ERROR }, + { "tftp", DBG_TFTP }, }; slirp_debug =3D g_parse_debug_string(debug, keys, G_N_ELEMENTS(key= s)); } diff --git a/slirp/tftp.c b/slirp/tftp.c index a9ba1480db..6fb381ef33 100644 --- a/slirp/tftp.c +++ b/slirp/tftp.c @@ -26,7 +26,6 @@ #include "slirp.h" #include "qemu-common.h" #include "qemu/cutils.h" -#include "trace.h" =20 static inline int tftp_session_in_use(struct tftp_session *spt) { @@ -205,7 +204,8 @@ static void tftp_send_error(struct tftp_session *spt, struct mbuf *m; struct tftp_t *tp; =20 - trace_slirp_tftp_error(msg); + DEBUG_TFTP("tftp error msg: %s", msg); + m =3D m_get(spt->slirp); =20 if (!m) { @@ -325,7 +325,8 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockad= dr_storage *srcsas, break; } } - trace_slirp_tftp_rrq(req_fname); + + DEBUG_TFTP("tftp rrq file: %s", req_fname); =20 /* check mode */ if ((pktlen - k) < 6) { diff --git a/slirp/trace-events b/slirp/trace-events deleted file mode 100644 index ff8f656e8c..0000000000 --- a/slirp/trace-events +++ /dev/null @@ -1,5 +0,0 @@ -# See docs/devel/tracing.txt for syntax documentation. - -# slirp/tftp.c -slirp_tftp_rrq(const char *file) "file: %s" -slirp_tftp_error(const char *file) "msg: %s" --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 1549548731094654.4540178173385; Thu, 7 Feb 2019 06:12:11 -0800 (PST) Received: from localhost ([127.0.0.1]:40699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkPP-0008Ld-So for importer@patchew.org; Thu, 07 Feb 2019 09:12:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHS-00024g-FN for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHN-0000v8-Kg for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49780) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHL-0000ra-Ly for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:48 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id CAC48CD42; Thu, 7 Feb 2019 15:03:28 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZCxMvUAfhCwB; Thu, 7 Feb 2019 15:03:27 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 8D805CD25; Thu, 7 Feb 2019 15:03:19 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004DI-7i; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:54 +0200 Message-Id: <20190207140316.16103-11-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 10/32] slirp: replace QEMU_PACKED with SLIRP_PACKED 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/ip.h | 10 +++++----- slirp/ip6_icmp.h | 6 +++--- slirp/slirp.h | 5 +++-- slirp/util.h | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 slirp/util.h diff --git a/slirp/ip.h b/slirp/ip.h index 20614f3b53..2baeeb9a3a 100644 --- a/slirp/ip.h +++ b/slirp/ip.h @@ -89,7 +89,7 @@ struct ip { uint8_t ip_p; /* protocol */ uint16_t ip_sum; /* checksum */ struct in_addr ip_src,ip_dst; /* source and dest address */ -} QEMU_PACKED; +} SLIRP_PACKED; =20 #define IP_MAXPACKET 65535 /* maximum packet size */ =20 @@ -151,7 +151,7 @@ struct ip_timestamp { n_long ipt_time; } ipt_ta[1]; } ipt_timestamp; -} QEMU_PACKED; +} SLIRP_PACKED; =20 /* flag bits for ipt_flg */ #define IPOPT_TS_TSONLY 0 /* timestamps only */ @@ -181,11 +181,11 @@ struct ip_timestamp { struct mbuf_ptr { struct mbuf *mptr; uint32_t dummy; -} QEMU_PACKED; +} SLIRP_PACKED; #else struct mbuf_ptr { struct mbuf *mptr; -} QEMU_PACKED; +} SLIRP_PACKED; #endif struct qlink { void *next, *prev; @@ -201,7 +201,7 @@ struct ipovly { uint16_t ih_len; /* protocol length */ struct in_addr ih_src; /* source internet address */ struct in_addr ih_dst; /* destination internet address */ -} QEMU_PACKED; +} SLIRP_PACKED; =20 /* * Ip reassembly queue structure. Each fragment diff --git a/slirp/ip6_icmp.h b/slirp/ip6_icmp.h index 2ad2b75e67..3f44ed2f49 100644 --- a/slirp/ip6_icmp.h +++ b/slirp/ip6_icmp.h @@ -144,16 +144,16 @@ struct ndpopt { uint32_t pref_lt; /* Preferred Lifetime */ uint32_t reserved2; struct in6_addr prefix; - } QEMU_PACKED prefixinfo; + } SLIRP_PACKED prefixinfo; #define ndpopt_prefixinfo ndpopt_body.prefixinfo struct rdnss { uint16_t reserved; uint32_t lifetime; struct in6_addr addr; - } QEMU_PACKED rdnss; + } SLIRP_PACKED rdnss; #define ndpopt_rdnss ndpopt_body.rdnss } ndpopt_body; -} QEMU_PACKED; +} SLIRP_PACKED; =20 /* NDP options type */ #define NDPOPT_LINKLAYER_SOURCE 1 /* Source Link-Layer Address */ diff --git a/slirp/slirp.h b/slirp/slirp.h index 17056f4b83..67ff4d610c 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -45,6 +45,7 @@ typedef char *caddr_t; #define quehead slirp_quehead =20 #include "debug.h" +#include "util.h" =20 #include "qemu/queue.h" #include "qemu/sockets.h" @@ -93,7 +94,7 @@ struct slirp_arphdr { uint32_t ar_sip; /* sender IP address */ unsigned char ar_tha[ETH_ALEN]; /* target hardware address */ uint32_t ar_tip; /* target IP address */ -} QEMU_PACKED; +} SLIRP_PACKED; =20 #define ARP_TABLE_SIZE 16 =20 @@ -110,7 +111,7 @@ bool arp_table_search(Slirp *slirp, uint32_t ip_addr, struct ndpentry { unsigned char eth_addr[ETH_ALEN]; /* sender hardware address */ struct in6_addr ip_addr; /* sender IP address */ -} QEMU_PACKED; +} SLIRP_PACKED; =20 #define NDP_TABLE_SIZE 16 =20 diff --git a/slirp/util.h b/slirp/util.h new file mode 100644 index 0000000000..00291c30a6 --- /dev/null +++ b/slirp/util.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2010-2019 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ +#ifndef UTIL_H_ +#define UTIL_H_ + +#if defined(_WIN32) +# define SLIRP_PACKED __attribute__((gcc_struct, packed)) +#else +# define SLIRP_PACKED __attribute__((packed)) +#endif + +#endif --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549549116174751.4652856112245; Thu, 7 Feb 2019 06:18:36 -0800 (PST) Received: from localhost ([127.0.0.1]:40785 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkVa-0004yD-07 for importer@patchew.org; Thu, 07 Feb 2019 09:18:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHV-00027I-14 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHQ-0000zB-6I for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:56 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49838) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHP-0000vQ-OY for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:52 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 1561ACD25; Thu, 7 Feb 2019 15:03:31 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id haOjKunH9aov; Thu, 7 Feb 2019 15:03:29 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id BED84CD28; Thu, 7 Feb 2019 15:03:19 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004DK-9f; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:55 +0200 Message-Id: <20190207140316.16103-12-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 11/32] slirp: replace most qemu socket utilities with slirp own version 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau qemu_set_nonblock() is slightly more problematic and will be dealt with in a separate patch. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/Makefile.objs | 3 +- slirp/ip_icmp.c | 6 +- slirp/misc.c | 20 ++--- slirp/socket.c | 18 ++--- slirp/tcp_subr.c | 18 ++--- slirp/udp.c | 8 +- slirp/util.c | 176 ++++++++++++++++++++++++++++++++++++++++++++ slirp/util.h | 61 +++++++++++++++ 8 files changed, 274 insertions(+), 36 deletions(-) create mode 100644 slirp/util.c diff --git a/slirp/Makefile.objs b/slirp/Makefile.objs index 959558c732..d2ead94b3b 100644 --- a/slirp/Makefile.objs +++ b/slirp/Makefile.objs @@ -27,6 +27,7 @@ slirp.mo-objs =3D \ tftp.o \ udp.o \ udp6.o \ + util.o \ $(NULL) =20 -slirp.mo-cflags =3D -DG_LOG_DOMAIN=3D\"Slirp\" +slirp.mo-cflags =3D -DG_LOG_DOMAIN=3D\"Slirp\" -DWITH_QEMU diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index 7c7e042049..b59daa801d 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -83,7 +83,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, i= nt hlen) struct ip *ip =3D mtod(m, struct ip *); struct sockaddr_in addr; =20 - so->s =3D qemu_socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); + so->s =3D slirp_socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); if (so->s =3D=3D -1) { return -1; } @@ -114,7 +114,7 @@ static int icmp_send(struct socket *so, struct mbuf *m,= int hlen) =20 void icmp_detach(struct socket *so) { - closesocket(so->s); + slirp_closesocket(so->s); sofree(so); } =20 @@ -421,7 +421,7 @@ void icmp_receive(struct socket *so) icp =3D mtod(m, struct icmp *); =20 id =3D icp->icmp_id; - len =3D qemu_recv(so->s, icp, M_ROOM(m), 0); + len =3D slirp_recv(so->s, icp, M_ROOM(m), 0); /* * The behavior of reading SOCK_DGRAM+IPPROTO_ICMP sockets is inconsis= tent * between host OSes. On Linux, only the ICMP header and payload is diff --git a/slirp/misc.c b/slirp/misc.c index b8a2bf971a..32ec02a525 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -72,14 +72,14 @@ slirp_socketpair_with_oob(int sv[2]) int ret, s; =20 sv[1] =3D -1; - s =3D qemu_socket(AF_INET, SOCK_STREAM, 0); + s =3D slirp_socket(AF_INET, SOCK_STREAM, 0); if (s < 0 || bind(s, (struct sockaddr *)&addr, addrlen) < 0 || listen(s, 1) < 0 || getsockname(s, (struct sockaddr *)&addr, &addrlen) < 0) { goto err; } =20 - sv[1] =3D qemu_socket(AF_INET, SOCK_STREAM, 0); + sv[1] =3D slirp_socket(AF_INET, SOCK_STREAM, 0); if (sv[1] < 0) { goto err; } @@ -102,16 +102,16 @@ slirp_socketpair_with_oob(int sv[2]) goto err; } =20 - closesocket(s); + slirp_closesocket(s); return 0; =20 err: g_critical("slirp_socketpair(): %s", strerror(errno)); if (s >=3D 0) { - closesocket(s); + slirp_closesocket(s); } if (sv[1] >=3D 0) { - closesocket(sv[1]); + slirp_closesocket(sv[1]); } return -1; } @@ -153,16 +153,16 @@ fork_exec(struct socket *so, const char *ex) if (err) { g_critical("fork_exec: %s", err->message); g_error_free(err); - closesocket(sp[0]); - closesocket(sp[1]); + slirp_closesocket(sp[0]); + slirp_closesocket(sp[1]); return 0; } =20 so->s =3D sp[0]; - closesocket(sp[1]); - socket_set_fast_reuse(so->s); + slirp_closesocket(sp[1]); + slirp_socket_set_fast_reuse(so->s); opt =3D 1; - qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); + slirp_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); qemu_set_nonblock(so->s); return 1; } diff --git a/slirp/socket.c b/slirp/socket.c index 5ffbaa064a..5805d30f3d 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -187,7 +187,7 @@ soread(struct socket *so) */ sopreprbuf(so, iov, &n); =20 - nn =3D qemu_recv(so->s, iov[0].iov_base, iov[0].iov_len,0); + nn =3D slirp_recv(so->s, iov[0].iov_base, iov[0].iov_len,0); if (nn <=3D 0) { if (nn < 0 && (errno =3D=3D EINTR || errno =3D=3D EAGAIN)) return 0; @@ -203,7 +203,7 @@ soread(struct socket *so) if (getpeername(so->s, paddr, &alen) < 0) { err =3D errno; } else { - getsockopt(so->s, SOL_SOCKET, SO_ERROR, + slirp_getsockopt(so->s, SOL_SOCKET, SO_ERROR, &err, &elen); } } @@ -233,7 +233,7 @@ soread(struct socket *so) */ if (n =3D=3D 2 && nn =3D=3D iov[0].iov_len) { int ret; - ret =3D qemu_recv(so->s, iov[1].iov_base, iov[1].iov_len,0); + ret =3D slirp_recv(so->s, iov[1].iov_base, iov[1].iov_len,0); if (ret > 0) nn +=3D ret; } @@ -554,7 +554,7 @@ sorecvfrom(struct socket *so) */ len =3D M_FREEROOM(m); /* if (so->so_fport !=3D htons(53)) { */ - ioctlsocket(so->s, FIONREAD, &n); + slirp_ioctlsocket(so->s, FIONREAD, &n); =20 if (n > len) { n =3D (m->m_data - m->m_dat) + m->m_len + n + 1; @@ -719,14 +719,14 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport,= uint32_t laddr, addr.sin_addr.s_addr =3D haddr; addr.sin_port =3D hport; =20 - if (((s =3D qemu_socket(AF_INET,SOCK_STREAM,0)) < 0) || - (socket_set_fast_reuse(s) < 0) || + if (((s =3D slirp_socket(AF_INET,SOCK_STREAM,0)) < 0) || + (slirp_socket_set_fast_reuse(s) < 0) || (bind(s,(struct sockaddr *)&addr, sizeof(addr)) < 0) || (listen(s,1) < 0)) { int tmperrno =3D errno; /* Don't clobber the real reason we failed */ =20 if (s >=3D 0) { - closesocket(s); + slirp_closesocket(s); } sofree(so); /* Restore the real errno */ @@ -737,9 +737,9 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, u= int32_t laddr, #endif return NULL; } - qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); + slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); opt =3D 1; - qemu_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int)); + slirp_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int)); =20 getsockname(s,(struct sockaddr *)&addr,&addrlen); so->so_ffamily =3D AF_INET; diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 4e81736d6f..3567f320ff 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -337,7 +337,7 @@ tcp_close(struct tcpcb *tp) /* clobber input socket cache if we're closing the cached connection */ if (so =3D=3D slirp->tcp_last_so) slirp->tcp_last_so =3D &slirp->tcb; - closesocket(so->s); + slirp_closesocket(so->s); sbfree(&so->so_rcv); sbfree(&so->so_snd); sofree(so); @@ -407,17 +407,17 @@ int tcp_fconnect(struct socket *so, unsigned short af) DEBUG_CALL("tcp_fconnect"); DEBUG_ARG("so =3D %p", so); =20 - ret =3D so->s =3D qemu_socket(af, SOCK_STREAM, 0); + ret =3D so->s =3D slirp_socket(af, SOCK_STREAM, 0); if (ret >=3D 0) { int opt, s=3Dso->s; struct sockaddr_storage addr; =20 qemu_set_nonblock(s); - socket_set_fast_reuse(s); + slirp_socket_set_fast_reuse(s); opt =3D 1; - qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt)); + slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt)); opt =3D 1; - qemu_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)); + slirp_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)); =20 addr =3D so->fhost.ss; DEBUG_CALL(" connect()ing"); @@ -485,10 +485,10 @@ void tcp_connect(struct socket *inso) return; } qemu_set_nonblock(s); - socket_set_fast_reuse(s); + slirp_socket_set_fast_reuse(s); opt =3D 1; - qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); - socket_set_nodelay(s); + slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); + slirp_socket_set_nodelay(s); =20 so->fhost.ss =3D addr; sotranslate_accept(so); @@ -496,7 +496,7 @@ void tcp_connect(struct socket *inso) /* Close the accept() socket, set right state */ if (inso->so_state & SS_FACCEPTONCE) { /* If we only accept once, close the accept() socket */ - closesocket(so->s); + slirp_closesocket(so->s); =20 /* Don't select it yet, even though we have an FD */ /* if it's not FACCEPTONCE, it's already NOFDREF */ diff --git a/slirp/udp.c b/slirp/udp.c index 309feb9aae..6c3fb9a29f 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -281,7 +281,7 @@ int udp_output(struct socket *so, struct mbuf *m, int udp_attach(struct socket *so, unsigned short af) { - so->s =3D qemu_socket(af, SOCK_DGRAM, 0); + so->s =3D slirp_socket(af, SOCK_DGRAM, 0); if (so->s !=3D -1) { so->so_expire =3D curtime + SO_EXPIRE; insque(so, &so->slirp->udb); @@ -292,7 +292,7 @@ udp_attach(struct socket *so, unsigned short af) void udp_detach(struct socket *so) { - closesocket(so->s); + slirp_closesocket(so->s); sofree(so); } =20 @@ -327,7 +327,7 @@ udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, u= int32_t laddr, socklen_t addrlen =3D sizeof(struct sockaddr_in); =20 so =3D socreate(slirp); - so->s =3D qemu_socket(AF_INET,SOCK_DGRAM,0); + so->s =3D slirp_socket(AF_INET,SOCK_DGRAM,0); if (so->s < 0) { sofree(so); return NULL; @@ -343,7 +343,7 @@ udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, u= int32_t laddr, udp_detach(so); return NULL; } - socket_set_fast_reuse(so->s); + slirp_socket_set_fast_reuse(so->s); =20 getsockname(so->s,(struct sockaddr *)&addr,&addrlen); so->fhost.sin =3D addr; diff --git a/slirp/util.c b/slirp/util.c new file mode 100644 index 0000000000..b1a36b27bc --- /dev/null +++ b/slirp/util.c @@ -0,0 +1,176 @@ +/* + * util.c (mostly based on QEMU os-win32.c) + * + * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2010-2016 Red Hat, Inc. + * + * QEMU library functions for win32 which are shared between QEMU and + * the QEMU tools. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ +#include "util.h" + +#include +#include +#include + +#if defined(_WIN32) && !defined(WITH_QEMU) +int inet_aton(const char *cp, struct in_addr *ia) +{ + uint32_t addr =3D inet_addr(cp); + if (addr =3D=3D 0xffffffff) { + return 0; + } + ia->s_addr =3D addr; + return 1; +} +#endif + +static void slirp_set_cloexec(int fd) +{ +#ifndef _WIN32 + int f; + f =3D fcntl(fd, F_GETFD); + assert(f !=3D -1); + f =3D fcntl(fd, F_SETFD, f | FD_CLOEXEC); + assert(f !=3D -1); +#endif +} + +/* + * Opens a socket with FD_CLOEXEC set + */ +int slirp_socket(int domain, int type, int protocol) +{ + int ret; + +#ifdef SOCK_CLOEXEC + ret =3D socket(domain, type | SOCK_CLOEXEC, protocol); + if (ret !=3D -1 || errno !=3D EINVAL) { + return ret; + } +#endif + ret =3D socket(domain, type, protocol); + if (ret >=3D 0) { + slirp_set_cloexec(ret); + } + + return ret; +} + +#ifdef _WIN32 +static int socket_error(void) +{ + switch (WSAGetLastError()) { + case 0: + return 0; + case WSAEINTR: + return EINTR; + case WSAEINVAL: + return EINVAL; + case WSA_INVALID_HANDLE: + return EBADF; + case WSA_NOT_ENOUGH_MEMORY: + return ENOMEM; + case WSA_INVALID_PARAMETER: + return EINVAL; + case WSAENAMETOOLONG: + return ENAMETOOLONG; + case WSAENOTEMPTY: + return ENOTEMPTY; + case WSAEWOULDBLOCK: + /* not using EWOULDBLOCK as we don't want code to have + * to check both EWOULDBLOCK and EAGAIN */ + return EAGAIN; + case WSAEINPROGRESS: + return EINPROGRESS; + case WSAEALREADY: + return EALREADY; + case WSAENOTSOCK: + return ENOTSOCK; + case WSAEDESTADDRREQ: + return EDESTADDRREQ; + case WSAEMSGSIZE: + return EMSGSIZE; + case WSAEPROTOTYPE: + return EPROTOTYPE; + case WSAENOPROTOOPT: + return ENOPROTOOPT; + case WSAEPROTONOSUPPORT: + return EPROTONOSUPPORT; + case WSAEOPNOTSUPP: + return EOPNOTSUPP; + case WSAEAFNOSUPPORT: + return EAFNOSUPPORT; + case WSAEADDRINUSE: + return EADDRINUSE; + case WSAEADDRNOTAVAIL: + return EADDRNOTAVAIL; + case WSAENETDOWN: + return ENETDOWN; + case WSAENETUNREACH: + return ENETUNREACH; + case WSAENETRESET: + return ENETRESET; + case WSAECONNABORTED: + return ECONNABORTED; + case WSAECONNRESET: + return ECONNRESET; + case WSAENOBUFS: + return ENOBUFS; + case WSAEISCONN: + return EISCONN; + case WSAENOTCONN: + return ENOTCONN; + case WSAETIMEDOUT: + return ETIMEDOUT; + case WSAECONNREFUSED: + return ECONNREFUSED; + case WSAELOOP: + return ELOOP; + case WSAEHOSTUNREACH: + return EHOSTUNREACH; + default: + return EIO; + } +} + +#undef ioctlsocket +int slirp_ioctlsocket(int fd, int req, void *val) +{ + int ret; + ret =3D ioctlsocket(fd, req, val); + if (ret < 0) { + errno =3D socket_error(); + } + return ret; +} + +#undef closesocket +int slirp_closesocket(int fd) +{ + int ret; + ret =3D closesocket(fd); + if (ret < 0) { + errno =3D socket_error(); + } + return ret; +} +#endif /* WIN32 */ diff --git a/slirp/util.h b/slirp/util.h index 00291c30a6..fe6f1fbb62 100644 --- a/slirp/util.h +++ b/slirp/util.h @@ -23,10 +23,71 @@ #ifndef UTIL_H_ #define UTIL_H_ =20 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#include +#include +#else +#include +#include +#include +#endif + #if defined(_WIN32) # define SLIRP_PACKED __attribute__((gcc_struct, packed)) #else # define SLIRP_PACKED __attribute__((packed)) #endif =20 +#ifdef _WIN32 +int slirp_closesocket(int fd); +int slirp_ioctlsocket(int fd, int req, void *val); +#ifndef WITH_QEMU +int inet_aton(const char *cp, struct in_addr *ia); +#endif +#define slirp_getsockopt(sockfd, level, optname, optval, optlen) \ + getsockopt(sockfd, level, optname, (void *)optval, optlen) +#define slirp_setsockopt(sockfd, level, optname, optval, optlen) \ + setsockopt(sockfd, level, optname, (const void *)optval, optlen) +#define slirp_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len,= flags) +#else +#define slirp_setsockopt setsockopt +#define slirp_getsockopt getsockopt +#define slirp_recv recv +#define slirp_closesocket close +#define slirp_ioctlsocket ioctl +#endif + +int slirp_socket(int domain, int type, int protocol); + +static inline int slirp_socket_set_nodelay(int fd) +{ + int v =3D 1; + return slirp_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v)); +} + +static inline int slirp_socket_set_fast_reuse(int fd) +{ +#ifndef _WIN32 + int v =3D 1; + return slirp_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v)); +#else + /* Enabling the reuse of an endpoint that was used by a socket still in + * TIME_WAIT state is usually performed by setting SO_REUSEADDR. On Wi= ndows + * fast reuse is the default and SO_REUSEADDR does strange things. So = we + * don't have to do anything here. More info can be found at: + * http://msdn.microsoft.com/en-us/library/windows/desktop/ms740621.as= px */ + return 0; +#endif +} + #endif --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 1549549299126777.0893017841573; Thu, 7 Feb 2019 06:21:39 -0800 (PST) Received: from localhost ([127.0.0.1]:40838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkYa-0007db-4o for importer@patchew.org; Thu, 07 Feb 2019 09:21:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHi-0002I8-N5 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHg-0001C3-2R for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:10 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHd-0000yb-VZ for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:06 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 5B987CD26; Thu, 7 Feb 2019 15:03:33 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZTqVPgFOF0y7; Thu, 7 Feb 2019 15:03:32 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 031D5CD2D; Thu, 7 Feb 2019 15:03:19 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004DM-BL; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:56 +0200 Message-Id: <20190207140316.16103-13-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 12/32] slirp: replace qemu_set_nonblock() 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Replace qemu_set_nonblock() with slirp_set_nonblock() qemu_set_nonblock() does some event registration with the main loop. Add a new callback register_poll_fd() for that reason. Always build the fd-register stub, to avoid #if WIN32. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 6 ++++++ slirp/libslirp.h | 2 ++ slirp/misc.c | 3 ++- slirp/tcp_subr.c | 6 ++++-- slirp/util.c | 14 ++++++++++++++ slirp/util.h | 1 + stubs/Makefile.objs | 2 +- 7 files changed, 30 insertions(+), 4 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index c24a779425..6f756a4dcc 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -186,6 +186,11 @@ static void net_slirp_timer_mod(void *timer, int64_t e= xpire_timer) timer_mod(timer, expire_timer); } =20 +static void net_slirp_register_poll_fd(int fd) +{ + qemu_fd_register(fd); +} + static const SlirpCb slirp_cb =3D { .output =3D net_slirp_output, .guest_error =3D net_slirp_guest_error, @@ -193,6 +198,7 @@ static const SlirpCb slirp_cb =3D { .timer_new =3D net_slirp_timer_new, .timer_free =3D net_slirp_timer_free, .timer_mod =3D net_slirp_timer_mod, + .register_poll_fd =3D net_slirp_register_poll_fd, }; =20 static int net_slirp_init(NetClientState *peer, const char *model, diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 3e75dadfa3..70e99139bf 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -27,6 +27,8 @@ typedef struct SlirpCb { void (*timer_free)(void *timer); /* Modify a timer to expire at @expire_time */ void (*timer_mod)(void *timer, int64_t expire_time); + /* Register a fd for future polling */ + void (*register_poll_fd)(int fd); } SlirpCb; =20 =20 diff --git a/slirp/misc.c b/slirp/misc.c index 32ec02a525..4ee20a10e4 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -163,7 +163,8 @@ fork_exec(struct socket *so, const char *ex) slirp_socket_set_fast_reuse(so->s); opt =3D 1; slirp_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); - qemu_set_nonblock(so->s); + slirp_set_nonblock(so->s); + so->slirp->cb->register_poll_fd(so->s); return 1; } =20 diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 3567f320ff..8087ffc047 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -412,7 +412,8 @@ int tcp_fconnect(struct socket *so, unsigned short af) int opt, s=3Dso->s; struct sockaddr_storage addr; =20 - qemu_set_nonblock(s); + slirp_set_nonblock(s); + so->slirp->cb->register_poll_fd(so->s); slirp_socket_set_fast_reuse(s); opt =3D 1; slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt)); @@ -484,7 +485,8 @@ void tcp_connect(struct socket *inso) tcp_close(sototcpcb(so)); /* This will sofree() as well */ return; } - qemu_set_nonblock(s); + slirp_set_nonblock(s); + so->slirp->cb->register_poll_fd(so->s); slirp_socket_set_fast_reuse(s); opt =3D 1; slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); diff --git a/slirp/util.c b/slirp/util.c index b1a36b27bc..59f6713c8b 100644 --- a/slirp/util.c +++ b/slirp/util.c @@ -43,6 +43,20 @@ int inet_aton(const char *cp, struct in_addr *ia) } #endif =20 +void slirp_set_nonblock(int fd) +{ +#ifndef _WIN32 + int f; + f =3D fcntl(fd, F_GETFL); + assert(f !=3D -1); + f =3D fcntl(fd, F_SETFL, f | O_NONBLOCK); + assert(f !=3D -1); +#else + unsigned long opt =3D 1; + ioctlsocket(fd, FIONBIO, &opt); +#endif +} + static void slirp_set_cloexec(int fd) { #ifndef _WIN32 diff --git a/slirp/util.h b/slirp/util.h index fe6f1fbb62..4f6e80c3ed 100644 --- a/slirp/util.h +++ b/slirp/util.h @@ -68,6 +68,7 @@ int inet_aton(const char *cp, struct in_addr *ia); #endif =20 int slirp_socket(int domain, int type, int protocol); +void slirp_set_nonblock(int fd); =20 static inline int slirp_socket_set_nodelay(int fd) { diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 5dd0aeeec6..cda0efa4e8 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -33,7 +33,7 @@ stub-obj-y +=3D trace-control.o stub-obj-y +=3D uuid.o stub-obj-y +=3D vm-stop.o stub-obj-y +=3D vmstate.o -stub-obj-$(CONFIG_WIN32) +=3D fd-register.o +stub-obj-y +=3D fd-register.o stub-obj-y +=3D qmp_memory_device.o stub-obj-y +=3D target-monitor-defs.o stub-obj-y +=3D target-get-monitor-def.o --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549548564101939.346270263459; Thu, 7 Feb 2019 06:09:24 -0800 (PST) Received: from localhost ([127.0.0.1]:40645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkMa-0005oC-O6 for importer@patchew.org; Thu, 07 Feb 2019 09:09:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHS-00024a-CF for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHP-0000xv-TL for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41878) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHN-0000uQ-M4 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id E3196CD24; Thu, 7 Feb 2019 15:03:29 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DtGVIOZo8rYf; Thu, 7 Feb 2019 15:03:28 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 9EC00CD26; Thu, 7 Feb 2019 15:03:19 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004DO-DF; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:57 +0200 Message-Id: <20190207140316.16103-14-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 13/32] slirp: add unregister_poll_fd() callback 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Add a counter-part to register_poll_fd() for completeness. (so far, register_poll_fd() is called only on struct socket fd) Suggested-by: Paolo Bonzini Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 6 ++++++ slirp/ip_icmp.c | 1 + slirp/libslirp.h | 2 ++ slirp/slirp.c | 3 ++- slirp/tcp_subr.c | 2 ++ slirp/udp.c | 1 + 6 files changed, 14 insertions(+), 1 deletion(-) diff --git a/net/slirp.c b/net/slirp.c index 6f756a4dcc..78ba96b63f 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -191,6 +191,11 @@ static void net_slirp_register_poll_fd(int fd) qemu_fd_register(fd); } =20 +static void net_slirp_unregister_poll_fd(int fd) +{ + /* no qemu_fd_unregister */ +} + static const SlirpCb slirp_cb =3D { .output =3D net_slirp_output, .guest_error =3D net_slirp_guest_error, @@ -199,6 +204,7 @@ static const SlirpCb slirp_cb =3D { .timer_free =3D net_slirp_timer_free, .timer_mod =3D net_slirp_timer_mod, .register_poll_fd =3D net_slirp_register_poll_fd, + .unregister_poll_fd =3D net_slirp_unregister_poll_fd, }; =20 static int net_slirp_init(NetClientState *peer, const char *model, diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index b59daa801d..19e247f773 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -114,6 +114,7 @@ static int icmp_send(struct socket *so, struct mbuf *m,= int hlen) =20 void icmp_detach(struct socket *so) { + so->slirp->cb->unregister_poll_fd(so->s); slirp_closesocket(so->s); sofree(so); } diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 70e99139bf..8ce69f0be3 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -29,6 +29,8 @@ typedef struct SlirpCb { void (*timer_mod)(void *timer, int64_t expire_time); /* Register a fd for future polling */ void (*register_poll_fd)(int fd); + /* Unregister a fd */ + void (*unregister_poll_fd)(int fd); } SlirpCb; =20 =20 diff --git a/slirp/slirp.c b/slirp/slirp.c index 12677e5da7..f0bd59fd6f 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -1015,7 +1015,8 @@ int slirp_remove_hostfwd(Slirp *slirp, int is_udp, st= ruct in_addr host_addr, getsockname(so->s, (struct sockaddr *)&addr, &addr_len) =3D=3D= 0 && addr.sin_addr.s_addr =3D=3D host_addr.s_addr && addr.sin_port =3D=3D port) { - close(so->s); + so->slirp->cb->unregister_poll_fd(so->s); + slirp_closesocket(so->s); sofree(so); return 0; } diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 8087ffc047..d8846a33b0 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -337,6 +337,7 @@ tcp_close(struct tcpcb *tp) /* clobber input socket cache if we're closing the cached connection */ if (so =3D=3D slirp->tcp_last_so) slirp->tcp_last_so =3D &slirp->tcb; + so->slirp->cb->unregister_poll_fd(so->s); slirp_closesocket(so->s); sbfree(&so->so_rcv); sbfree(&so->so_snd); @@ -498,6 +499,7 @@ void tcp_connect(struct socket *inso) /* Close the accept() socket, set right state */ if (inso->so_state & SS_FACCEPTONCE) { /* If we only accept once, close the accept() socket */ + so->slirp->cb->unregister_poll_fd(so->s); slirp_closesocket(so->s); =20 /* Don't select it yet, even though we have an FD */ diff --git a/slirp/udp.c b/slirp/udp.c index 6c3fb9a29f..3915971b50 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -292,6 +292,7 @@ udp_attach(struct socket *so, unsigned short af) void udp_detach(struct socket *so) { + so->slirp->cb->unregister_poll_fd(so->s); slirp_closesocket(so->s); sofree(so); } --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549548574367506.7363031443856; Thu, 7 Feb 2019 06:09:34 -0800 (PST) Received: from localhost ([127.0.0.1]:40647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkMo-0005yM-7L for importer@patchew.org; Thu, 07 Feb 2019 09:09:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHS-00024O-4j for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHP-0000xn-Rr for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49834) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHN-0000uR-N0 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id E9402CD21; Thu, 7 Feb 2019 15:03:28 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id impem3-ONRoD; Thu, 7 Feb 2019 15:03:27 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id B5139CD27; Thu, 7 Feb 2019 15:03:19 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004DQ-F2; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:58 +0200 Message-Id: <20190207140316.16103-15-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 14/32] slirp: replace qemu_notify_event() with a callback 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Introduce a SlirpCb callback to kick the main io-thread. Add an intermediary sodrop() function that will call SlirpCb.notify callback when sbdrop() returns true. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 1 + slirp/libslirp.h | 2 ++ slirp/sbuf.c | 6 ++++-- slirp/sbuf.h | 2 +- slirp/socket.c | 7 +++++++ slirp/socket.h | 1 + slirp/tcp_input.c | 6 +++--- 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 78ba96b63f..7b4f9f5c5e 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -205,6 +205,7 @@ static const SlirpCb slirp_cb =3D { .timer_mod =3D net_slirp_timer_mod, .register_poll_fd =3D net_slirp_register_poll_fd, .unregister_poll_fd =3D net_slirp_unregister_poll_fd, + .notify =3D qemu_notify_event, }; =20 static int net_slirp_init(NetClientState *peer, const char *model, diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 8ce69f0be3..679a25422b 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -31,6 +31,8 @@ typedef struct SlirpCb { void (*register_poll_fd)(int fd); /* Unregister a fd */ void (*unregister_poll_fd)(int fd); + /* Kick the io-thread, to signal that new events may be processed */ + void (*notify)(void); } SlirpCb; =20 =20 diff --git a/slirp/sbuf.c b/slirp/sbuf.c index 912f235f65..17f28e97a6 100644 --- a/slirp/sbuf.c +++ b/slirp/sbuf.c @@ -17,7 +17,7 @@ sbfree(struct sbuf *sb) free(sb->sb_data); } =20 -void +bool sbdrop(struct sbuf *sb, int num) { int limit =3D sb->sb_datalen / 2; @@ -34,8 +34,10 @@ sbdrop(struct sbuf *sb, int num) sb->sb_rptr -=3D sb->sb_datalen; =20 if (sb->sb_cc < limit && sb->sb_cc + num >=3D limit) { - qemu_notify_event(); + return true; } + + return false; } =20 void diff --git a/slirp/sbuf.h b/slirp/sbuf.h index 644c201341..1cb9a42834 100644 --- a/slirp/sbuf.h +++ b/slirp/sbuf.h @@ -21,7 +21,7 @@ struct sbuf { }; =20 void sbfree(struct sbuf *); -void sbdrop(struct sbuf *, int); +bool sbdrop(struct sbuf *, int); void sbreserve(struct sbuf *, int); void sbappend(struct socket *, struct mbuf *); void sbcopy(struct sbuf *, int, int, char *); diff --git a/slirp/socket.c b/slirp/socket.c index 5805d30f3d..2e8dc22fb6 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -928,3 +928,10 @@ void sotranslate_accept(struct socket *so) break; } } + +void sodrop(struct socket *s, int num) +{ + if (sbdrop(&s->so_snd, num)) { + s->slirp->cb->notify(); + } +} diff --git a/slirp/socket.h b/slirp/socket.h index fc35ca5f72..1c1c8b5871 100644 --- a/slirp/socket.h +++ b/slirp/socket.h @@ -156,6 +156,7 @@ int soreadbuf(struct socket *so, const char *buf, int s= ize); void sotranslate_out(struct socket *, struct sockaddr_storage *); void sotranslate_in(struct socket *, struct sockaddr_storage *); void sotranslate_accept(struct socket *); +void sodrop(struct socket *, int num); =20 =20 #endif /* SLIRP_SOCKET_H */ diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c index de5b74a52b..7c1fe18fec 100644 --- a/slirp/tcp_input.c +++ b/slirp/tcp_input.c @@ -506,7 +506,7 @@ findso: SEQ_GT(ti->ti_ack, tp->t_rtseq)) tcp_xmit_timer(tp, tp->t_rtt); acked =3D ti->ti_ack - tp->snd_una; - sbdrop(&so->so_snd, acked); + sodrop(so, acked); tp->snd_una =3D ti->ti_ack; m_free(m); =20 @@ -1118,10 +1118,10 @@ trimthenstep6: } if (acked > so->so_snd.sb_cc) { tp->snd_wnd -=3D so->so_snd.sb_cc; - sbdrop(&so->so_snd, (int )so->so_snd.sb_cc); + sodrop(so, (int)so->so_snd.sb_cc); ourfinisacked =3D 1; } else { - sbdrop(&so->so_snd, acked); + sodrop(so, acked); tp->snd_wnd -=3D acked; ourfinisacked =3D 0; } --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549549319408911.0278993763671; Thu, 7 Feb 2019 06:21:59 -0800 (PST) Received: from localhost ([127.0.0.1]:40845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkYr-0007oa-3F for importer@patchew.org; Thu, 07 Feb 2019 09:21:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHX-00029G-0B for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHR-000107-Rz for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:58 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49842) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHQ-0000yT-Vh for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id AF6AECD28; Thu, 7 Feb 2019 15:03:32 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l7CD3wpiytOQ; Thu, 7 Feb 2019 15:03:30 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id CD9C6CD29; Thu, 7 Feb 2019 15:03:19 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004DS-Gu; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:02:59 +0200 Message-Id: <20190207140316.16103-16-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 15/32] slirp: move QEMU state saving to a separate unit 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Make state saving optional: this will allow to build SLIRP without QEMU. (eventually, the vmstate helpers will be extracted, so an external project & process could save its state) Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/Makefile.objs | 1 + slirp/slirp.c | 372 ++--------------------------------------- slirp/slirp.h | 3 + slirp/state.c | 394 ++++++++++++++++++++++++++++++++++++++++++++ slirp/state.h | 9 + 5 files changed, 418 insertions(+), 361 deletions(-) create mode 100644 slirp/state.c create mode 100644 slirp/state.h diff --git a/slirp/Makefile.objs b/slirp/Makefile.objs index d2ead94b3b..88340a583b 100644 --- a/slirp/Makefile.objs +++ b/slirp/Makefile.objs @@ -20,6 +20,7 @@ slirp.mo-objs =3D \ sbuf.o \ slirp.o \ socket.o \ + state.o \ tcp_input.o \ tcp_output.o \ tcp_subr.o \ diff --git a/slirp/slirp.c b/slirp/slirp.c index f0bd59fd6f..9ec1e4c62f 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -30,6 +30,10 @@ #include "hw/hw.h" #include "qemu/cutils.h" =20 +#ifdef WITH_QEMU +#include "state.h" +#endif + #ifndef _WIN32 #include #endif @@ -278,14 +282,6 @@ static void slirp_init_once(void) =20 } =20 -static void slirp_state_save(QEMUFile *f, void *opaque); -static int slirp_state_load(QEMUFile *f, void *opaque, int version_id); - -static SaveVMHandlers savevm_slirp_state =3D { - .save_state =3D slirp_state_save, - .load_state =3D slirp_state_load, -}; - Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork, struct in_addr vnetmask, struct in_addr vhost, bool in6_enabled, @@ -341,8 +337,9 @@ Slirp *slirp_init(int restricted, bool in_enabled, stru= ct in_addr vnetwork, =20 slirp->opaque =3D opaque; =20 - register_savevm_live(NULL, "slirp", 0, 4, &savevm_slirp_state, slirp); - +#ifdef WITH_QEMU + slirp_state_register(slirp); +#endif QTAILQ_INSERT_TAIL(&slirp_instances, slirp, entry); =20 return slirp; @@ -359,9 +356,9 @@ void slirp_cleanup(Slirp *slirp) } =20 QTAILQ_REMOVE(&slirp_instances, slirp, entry); - - unregister_savevm(NULL, "slirp", slirp); - +#ifdef WITH_QEMU + slirp_state_unregister(slirp); +#endif ip_cleanup(slirp); ip6_cleanup(slirp); m_cleanup(slirp); @@ -1115,7 +1112,7 @@ ssize_t slirp_send(struct socket *so, const void *buf= , size_t len, int flags) return send(so->s, buf, len, flags); } =20 -static struct socket * +struct socket * slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, int guest_p= ort) { struct socket *so; @@ -1162,350 +1159,3 @@ void slirp_socket_recv(Slirp *slirp, struct in_addr= guest_addr, int guest_port, if (ret > 0) tcp_output(sototcpcb(so)); } - -static int slirp_tcp_post_load(void *opaque, int version) -{ - tcp_template((struct tcpcb *)opaque); - - return 0; -} - -static const VMStateDescription vmstate_slirp_tcp =3D { - .name =3D "slirp-tcp", - .version_id =3D 0, - .post_load =3D slirp_tcp_post_load, - .fields =3D (VMStateField[]) { - VMSTATE_INT16(t_state, struct tcpcb), - VMSTATE_INT16_ARRAY(t_timer, struct tcpcb, TCPT_NTIMERS), - VMSTATE_INT16(t_rxtshift, struct tcpcb), - VMSTATE_INT16(t_rxtcur, struct tcpcb), - VMSTATE_INT16(t_dupacks, struct tcpcb), - VMSTATE_UINT16(t_maxseg, struct tcpcb), - VMSTATE_UINT8(t_force, struct tcpcb), - VMSTATE_UINT16(t_flags, struct tcpcb), - VMSTATE_UINT32(snd_una, struct tcpcb), - VMSTATE_UINT32(snd_nxt, struct tcpcb), - VMSTATE_UINT32(snd_up, struct tcpcb), - VMSTATE_UINT32(snd_wl1, struct tcpcb), - VMSTATE_UINT32(snd_wl2, struct tcpcb), - VMSTATE_UINT32(iss, struct tcpcb), - VMSTATE_UINT32(snd_wnd, struct tcpcb), - VMSTATE_UINT32(rcv_wnd, struct tcpcb), - VMSTATE_UINT32(rcv_nxt, struct tcpcb), - VMSTATE_UINT32(rcv_up, struct tcpcb), - VMSTATE_UINT32(irs, struct tcpcb), - VMSTATE_UINT32(rcv_adv, struct tcpcb), - VMSTATE_UINT32(snd_max, struct tcpcb), - VMSTATE_UINT32(snd_cwnd, struct tcpcb), - VMSTATE_UINT32(snd_ssthresh, struct tcpcb), - VMSTATE_INT16(t_idle, struct tcpcb), - VMSTATE_INT16(t_rtt, struct tcpcb), - VMSTATE_UINT32(t_rtseq, struct tcpcb), - VMSTATE_INT16(t_srtt, struct tcpcb), - VMSTATE_INT16(t_rttvar, struct tcpcb), - VMSTATE_UINT16(t_rttmin, struct tcpcb), - VMSTATE_UINT32(max_sndwnd, struct tcpcb), - VMSTATE_UINT8(t_oobflags, struct tcpcb), - VMSTATE_UINT8(t_iobc, struct tcpcb), - VMSTATE_INT16(t_softerror, struct tcpcb), - VMSTATE_UINT8(snd_scale, struct tcpcb), - VMSTATE_UINT8(rcv_scale, struct tcpcb), - VMSTATE_UINT8(request_r_scale, struct tcpcb), - VMSTATE_UINT8(requested_s_scale, struct tcpcb), - VMSTATE_UINT32(ts_recent, struct tcpcb), - VMSTATE_UINT32(ts_recent_age, struct tcpcb), - VMSTATE_UINT32(last_ack_sent, struct tcpcb), - VMSTATE_END_OF_LIST() - } -}; - -/* The sbuf has a pair of pointers that are migrated as offsets; - * we calculate the offsets and restore the pointers using - * pre_save/post_load on a tmp structure. - */ -struct sbuf_tmp { - struct sbuf *parent; - uint32_t roff, woff; -}; - -static int sbuf_tmp_pre_save(void *opaque) -{ - struct sbuf_tmp *tmp =3D opaque; - tmp->woff =3D tmp->parent->sb_wptr - tmp->parent->sb_data; - tmp->roff =3D tmp->parent->sb_rptr - tmp->parent->sb_data; - - return 0; -} - -static int sbuf_tmp_post_load(void *opaque, int version) -{ - struct sbuf_tmp *tmp =3D opaque; - uint32_t requested_len =3D tmp->parent->sb_datalen; - - /* Allocate the buffer space used by the field after the tmp */ - sbreserve(tmp->parent, tmp->parent->sb_datalen); - - if (tmp->parent->sb_datalen !=3D requested_len) { - return -ENOMEM; - } - if (tmp->woff >=3D requested_len || - tmp->roff >=3D requested_len) { - g_critical("invalid sbuf offsets r/w=3D%u/%u len=3D%u", - tmp->roff, tmp->woff, requested_len); - return -EINVAL; - } - - tmp->parent->sb_wptr =3D tmp->parent->sb_data + tmp->woff; - tmp->parent->sb_rptr =3D tmp->parent->sb_data + tmp->roff; - - return 0; -} - - -static const VMStateDescription vmstate_slirp_sbuf_tmp =3D { - .name =3D "slirp-sbuf-tmp", - .post_load =3D sbuf_tmp_post_load, - .pre_save =3D sbuf_tmp_pre_save, - .version_id =3D 0, - .fields =3D (VMStateField[]) { - VMSTATE_UINT32(woff, struct sbuf_tmp), - VMSTATE_UINT32(roff, struct sbuf_tmp), - VMSTATE_END_OF_LIST() - } -}; - -static const VMStateDescription vmstate_slirp_sbuf =3D { - .name =3D "slirp-sbuf", - .version_id =3D 0, - .fields =3D (VMStateField[]) { - VMSTATE_UINT32(sb_cc, struct sbuf), - VMSTATE_UINT32(sb_datalen, struct sbuf), - VMSTATE_WITH_TMP(struct sbuf, struct sbuf_tmp, vmstate_slirp_sbuf_= tmp), - VMSTATE_VBUFFER_UINT32(sb_data, struct sbuf, 0, NULL, sb_datalen), - VMSTATE_END_OF_LIST() - } -}; - -static bool slirp_older_than_v4(void *opaque, int version_id) -{ - return version_id < 4; -} - -static bool slirp_family_inet(void *opaque, int version_id) -{ - union slirp_sockaddr *ssa =3D (union slirp_sockaddr *)opaque; - return ssa->ss.ss_family =3D=3D AF_INET; -} - -static int slirp_socket_pre_load(void *opaque) -{ - struct socket *so =3D opaque; - if (tcp_attach(so) < 0) { - return -ENOMEM; - } - /* Older versions don't load these fields */ - so->so_ffamily =3D AF_INET; - so->so_lfamily =3D AF_INET; - return 0; -} - -#ifndef _WIN32 -#define VMSTATE_SIN4_ADDR(f, s, t) VMSTATE_UINT32_TEST(f, s, t) -#else -/* Win uses u_long rather than uint32_t - but it's still 32bits long */ -#define VMSTATE_SIN4_ADDR(f, s, t) VMSTATE_SINGLE_TEST(f, s, t, 0, \ - vmstate_info_uint32, u_long) -#endif - -/* The OS provided ss_family field isn't that portable; it's size - * and type varies (16/8 bit, signed, unsigned) - * and the values it contains aren't fully portable. - */ -typedef struct SS_FamilyTmpStruct { - union slirp_sockaddr *parent; - uint16_t portable_family; -} SS_FamilyTmpStruct; - -#define SS_FAMILY_MIG_IPV4 2 /* Linux, BSD, Win... */ -#define SS_FAMILY_MIG_IPV6 10 /* Linux */ -#define SS_FAMILY_MIG_OTHER 0xffff - -static int ss_family_pre_save(void *opaque) -{ - SS_FamilyTmpStruct *tss =3D opaque; - - tss->portable_family =3D SS_FAMILY_MIG_OTHER; - - if (tss->parent->ss.ss_family =3D=3D AF_INET) { - tss->portable_family =3D SS_FAMILY_MIG_IPV4; - } else if (tss->parent->ss.ss_family =3D=3D AF_INET6) { - tss->portable_family =3D SS_FAMILY_MIG_IPV6; - } - - return 0; -} - -static int ss_family_post_load(void *opaque, int version_id) -{ - SS_FamilyTmpStruct *tss =3D opaque; - - switch (tss->portable_family) { - case SS_FAMILY_MIG_IPV4: - tss->parent->ss.ss_family =3D AF_INET; - break; - case SS_FAMILY_MIG_IPV6: - case 23: /* compatibility: AF_INET6 from mingw */ - case 28: /* compatibility: AF_INET6 from FreeBSD sys/socket.h */ - tss->parent->ss.ss_family =3D AF_INET6; - break; - default: - g_critical("invalid ss_family type %x", tss->portable_family); - return -EINVAL; - } - - return 0; -} - -static const VMStateDescription vmstate_slirp_ss_family =3D { - .name =3D "slirp-socket-addr/ss_family", - .pre_save =3D ss_family_pre_save, - .post_load =3D ss_family_post_load, - .fields =3D (VMStateField[]) { - VMSTATE_UINT16(portable_family, SS_FamilyTmpStruct), - VMSTATE_END_OF_LIST() - } -}; - -static const VMStateDescription vmstate_slirp_socket_addr =3D { - .name =3D "slirp-socket-addr", - .version_id =3D 4, - .fields =3D (VMStateField[]) { - VMSTATE_WITH_TMP(union slirp_sockaddr, SS_FamilyTmpStruct, - vmstate_slirp_ss_family), - VMSTATE_SIN4_ADDR(sin.sin_addr.s_addr, union slirp_sockaddr, - slirp_family_inet), - VMSTATE_UINT16_TEST(sin.sin_port, union slirp_sockaddr, - slirp_family_inet), - -#if 0 - /* Untested: Needs checking by someone with IPv6 test */ - VMSTATE_BUFFER_TEST(sin6.sin6_addr, union slirp_sockaddr, - slirp_family_inet6), - VMSTATE_UINT16_TEST(sin6.sin6_port, union slirp_sockaddr, - slirp_family_inet6), - VMSTATE_UINT32_TEST(sin6.sin6_flowinfo, union slirp_sockaddr, - slirp_family_inet6), - VMSTATE_UINT32_TEST(sin6.sin6_scope_id, union slirp_sockaddr, - slirp_family_inet6), -#endif - - VMSTATE_END_OF_LIST() - } -}; - -static const VMStateDescription vmstate_slirp_socket =3D { - .name =3D "slirp-socket", - .version_id =3D 4, - .pre_load =3D slirp_socket_pre_load, - .fields =3D (VMStateField[]) { - VMSTATE_UINT32(so_urgc, struct socket), - /* Pre-v4 versions */ - VMSTATE_SIN4_ADDR(so_faddr.s_addr, struct socket, - slirp_older_than_v4), - VMSTATE_SIN4_ADDR(so_laddr.s_addr, struct socket, - slirp_older_than_v4), - VMSTATE_UINT16_TEST(so_fport, struct socket, slirp_older_than_v4), - VMSTATE_UINT16_TEST(so_lport, struct socket, slirp_older_than_v4), - /* v4 and newer */ - VMSTATE_STRUCT(fhost, struct socket, 4, vmstate_slirp_socket_addr, - union slirp_sockaddr), - VMSTATE_STRUCT(lhost, struct socket, 4, vmstate_slirp_socket_addr, - union slirp_sockaddr), - - VMSTATE_UINT8(so_iptos, struct socket), - VMSTATE_UINT8(so_emu, struct socket), - VMSTATE_UINT8(so_type, struct socket), - VMSTATE_INT32(so_state, struct socket), - VMSTATE_STRUCT(so_rcv, struct socket, 0, vmstate_slirp_sbuf, - struct sbuf), - VMSTATE_STRUCT(so_snd, struct socket, 0, vmstate_slirp_sbuf, - struct sbuf), - VMSTATE_STRUCT_POINTER(so_tcpcb, struct socket, vmstate_slirp_tcp, - struct tcpcb), - VMSTATE_END_OF_LIST() - } -}; - -static const VMStateDescription vmstate_slirp_bootp_client =3D { - .name =3D "slirp_bootpclient", - .fields =3D (VMStateField[]) { - VMSTATE_UINT16(allocated, BOOTPClient), - VMSTATE_BUFFER(macaddr, BOOTPClient), - VMSTATE_END_OF_LIST() - } -}; - -static const VMStateDescription vmstate_slirp =3D { - .name =3D "slirp", - .version_id =3D 4, - .fields =3D (VMStateField[]) { - VMSTATE_UINT16_V(ip_id, Slirp, 2), - VMSTATE_STRUCT_ARRAY(bootp_clients, Slirp, NB_BOOTP_CLIENTS, 3, - vmstate_slirp_bootp_client, BOOTPClient), - VMSTATE_END_OF_LIST() - } -}; - -static void slirp_state_save(QEMUFile *f, void *opaque) -{ - Slirp *slirp =3D opaque; - struct gfwd_list *ex_ptr; - - for (ex_ptr =3D slirp->guestfwd_list; ex_ptr; ex_ptr =3D ex_ptr->ex_ne= xt) - if (ex_ptr->write_cb) { - struct socket *so; - so =3D slirp_find_ctl_socket(slirp, ex_ptr->ex_addr, - ntohs(ex_ptr->ex_fport)); - if (!so) - continue; - - qemu_put_byte(f, 42); - vmstate_save_state(f, &vmstate_slirp_socket, so, NULL); - } - qemu_put_byte(f, 0); - - vmstate_save_state(f, &vmstate_slirp, slirp, NULL); -} - - -static int slirp_state_load(QEMUFile *f, void *opaque, int version_id) -{ - Slirp *slirp =3D opaque; - struct gfwd_list *ex_ptr; - - while (qemu_get_byte(f)) { - int ret; - struct socket *so =3D socreate(slirp); - - ret =3D vmstate_load_state(f, &vmstate_slirp_socket, so, version_i= d); - - if (ret < 0) - return ret; - - if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) !=3D - slirp->vnetwork_addr.s_addr) { - return -EINVAL; - } - for (ex_ptr =3D slirp->guestfwd_list; ex_ptr; ex_ptr =3D ex_ptr->e= x_next) { - if (ex_ptr->write_cb && - so->so_faddr.s_addr =3D=3D ex_ptr->ex_addr.s_addr && - so->so_fport =3D=3D ex_ptr->ex_fport) { - break; - } - } - if (!ex_ptr) - return -EINVAL; - } - - return vmstate_load_state(f, &vmstate_slirp, slirp, version_id); -} diff --git a/slirp/slirp.h b/slirp/slirp.h index 67ff4d610c..8d9d72ca9d 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -271,4 +271,7 @@ int tcp_emu(struct socket *, struct mbuf *); int tcp_ctl(struct socket *); struct tcpcb *tcp_drop(struct tcpcb *tp, int err); =20 +struct socket * +slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, int guest_p= ort); + #endif diff --git a/slirp/state.c b/slirp/state.c new file mode 100644 index 0000000000..0e5a706e87 --- /dev/null +++ b/slirp/state.c @@ -0,0 +1,394 @@ +/* + * libslirp + * + * Copyright (c) 2004-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ +#include "qemu/osdep.h" + +#include "slirp.h" +#include "state.h" +#include "migration/vmstate.h" +#include "migration/qemu-file-types.h" +#include "migration/register.h" + +static int slirp_tcp_post_load(void *opaque, int version) +{ + tcp_template((struct tcpcb *)opaque); + + return 0; +} + +static const VMStateDescription vmstate_slirp_tcp =3D { + .name =3D "slirp-tcp", + .version_id =3D 0, + .post_load =3D slirp_tcp_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_INT16(t_state, struct tcpcb), + VMSTATE_INT16_ARRAY(t_timer, struct tcpcb, TCPT_NTIMERS), + VMSTATE_INT16(t_rxtshift, struct tcpcb), + VMSTATE_INT16(t_rxtcur, struct tcpcb), + VMSTATE_INT16(t_dupacks, struct tcpcb), + VMSTATE_UINT16(t_maxseg, struct tcpcb), + VMSTATE_UINT8(t_force, struct tcpcb), + VMSTATE_UINT16(t_flags, struct tcpcb), + VMSTATE_UINT32(snd_una, struct tcpcb), + VMSTATE_UINT32(snd_nxt, struct tcpcb), + VMSTATE_UINT32(snd_up, struct tcpcb), + VMSTATE_UINT32(snd_wl1, struct tcpcb), + VMSTATE_UINT32(snd_wl2, struct tcpcb), + VMSTATE_UINT32(iss, struct tcpcb), + VMSTATE_UINT32(snd_wnd, struct tcpcb), + VMSTATE_UINT32(rcv_wnd, struct tcpcb), + VMSTATE_UINT32(rcv_nxt, struct tcpcb), + VMSTATE_UINT32(rcv_up, struct tcpcb), + VMSTATE_UINT32(irs, struct tcpcb), + VMSTATE_UINT32(rcv_adv, struct tcpcb), + VMSTATE_UINT32(snd_max, struct tcpcb), + VMSTATE_UINT32(snd_cwnd, struct tcpcb), + VMSTATE_UINT32(snd_ssthresh, struct tcpcb), + VMSTATE_INT16(t_idle, struct tcpcb), + VMSTATE_INT16(t_rtt, struct tcpcb), + VMSTATE_UINT32(t_rtseq, struct tcpcb), + VMSTATE_INT16(t_srtt, struct tcpcb), + VMSTATE_INT16(t_rttvar, struct tcpcb), + VMSTATE_UINT16(t_rttmin, struct tcpcb), + VMSTATE_UINT32(max_sndwnd, struct tcpcb), + VMSTATE_UINT8(t_oobflags, struct tcpcb), + VMSTATE_UINT8(t_iobc, struct tcpcb), + VMSTATE_INT16(t_softerror, struct tcpcb), + VMSTATE_UINT8(snd_scale, struct tcpcb), + VMSTATE_UINT8(rcv_scale, struct tcpcb), + VMSTATE_UINT8(request_r_scale, struct tcpcb), + VMSTATE_UINT8(requested_s_scale, struct tcpcb), + VMSTATE_UINT32(ts_recent, struct tcpcb), + VMSTATE_UINT32(ts_recent_age, struct tcpcb), + VMSTATE_UINT32(last_ack_sent, struct tcpcb), + VMSTATE_END_OF_LIST() + } +}; + +/* The sbuf has a pair of pointers that are migrated as offsets; + * we calculate the offsets and restore the pointers using + * pre_save/post_load on a tmp structure. + */ +struct sbuf_tmp { + struct sbuf *parent; + uint32_t roff, woff; +}; + +static int sbuf_tmp_pre_save(void *opaque) +{ + struct sbuf_tmp *tmp =3D opaque; + tmp->woff =3D tmp->parent->sb_wptr - tmp->parent->sb_data; + tmp->roff =3D tmp->parent->sb_rptr - tmp->parent->sb_data; + + return 0; +} + +static int sbuf_tmp_post_load(void *opaque, int version) +{ + struct sbuf_tmp *tmp =3D opaque; + uint32_t requested_len =3D tmp->parent->sb_datalen; + + /* Allocate the buffer space used by the field after the tmp */ + sbreserve(tmp->parent, tmp->parent->sb_datalen); + + if (tmp->parent->sb_datalen !=3D requested_len) { + return -ENOMEM; + } + if (tmp->woff >=3D requested_len || + tmp->roff >=3D requested_len) { + g_critical("invalid sbuf offsets r/w=3D%u/%u len=3D%u", + tmp->roff, tmp->woff, requested_len); + return -EINVAL; + } + + tmp->parent->sb_wptr =3D tmp->parent->sb_data + tmp->woff; + tmp->parent->sb_rptr =3D tmp->parent->sb_data + tmp->roff; + + return 0; +} + + +static const VMStateDescription vmstate_slirp_sbuf_tmp =3D { + .name =3D "slirp-sbuf-tmp", + .post_load =3D sbuf_tmp_post_load, + .pre_save =3D sbuf_tmp_pre_save, + .version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(woff, struct sbuf_tmp), + VMSTATE_UINT32(roff, struct sbuf_tmp), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_slirp_sbuf =3D { + .name =3D "slirp-sbuf", + .version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(sb_cc, struct sbuf), + VMSTATE_UINT32(sb_datalen, struct sbuf), + VMSTATE_WITH_TMP(struct sbuf, struct sbuf_tmp, vmstate_slirp_sbuf_= tmp), + VMSTATE_VBUFFER_UINT32(sb_data, struct sbuf, 0, NULL, sb_datalen), + VMSTATE_END_OF_LIST() + } +}; + +static bool slirp_older_than_v4(void *opaque, int version_id) +{ + return version_id < 4; +} + +static bool slirp_family_inet(void *opaque, int version_id) +{ + union slirp_sockaddr *ssa =3D (union slirp_sockaddr *)opaque; + return ssa->ss.ss_family =3D=3D AF_INET; +} + +static int slirp_socket_pre_load(void *opaque) +{ + struct socket *so =3D opaque; + if (tcp_attach(so) < 0) { + return -ENOMEM; + } + /* Older versions don't load these fields */ + so->so_ffamily =3D AF_INET; + so->so_lfamily =3D AF_INET; + return 0; +} + +#ifndef _WIN32 +#define VMSTATE_SIN4_ADDR(f, s, t) VMSTATE_UINT32_TEST(f, s, t) +#else +/* Win uses u_long rather than uint32_t - but it's still 32bits long */ +#define VMSTATE_SIN4_ADDR(f, s, t) VMSTATE_SINGLE_TEST(f, s, t, 0, \ + vmstate_info_uint32, u_long) +#endif + +/* The OS provided ss_family field isn't that portable; it's size + * and type varies (16/8 bit, signed, unsigned) + * and the values it contains aren't fully portable. + */ +typedef struct SS_FamilyTmpStruct { + union slirp_sockaddr *parent; + uint16_t portable_family; +} SS_FamilyTmpStruct; + +#define SS_FAMILY_MIG_IPV4 2 /* Linux, BSD, Win... */ +#define SS_FAMILY_MIG_IPV6 10 /* Linux */ +#define SS_FAMILY_MIG_OTHER 0xffff + +static int ss_family_pre_save(void *opaque) +{ + SS_FamilyTmpStruct *tss =3D opaque; + + tss->portable_family =3D SS_FAMILY_MIG_OTHER; + + if (tss->parent->ss.ss_family =3D=3D AF_INET) { + tss->portable_family =3D SS_FAMILY_MIG_IPV4; + } else if (tss->parent->ss.ss_family =3D=3D AF_INET6) { + tss->portable_family =3D SS_FAMILY_MIG_IPV6; + } + + return 0; +} + +static int ss_family_post_load(void *opaque, int version_id) +{ + SS_FamilyTmpStruct *tss =3D opaque; + + switch (tss->portable_family) { + case SS_FAMILY_MIG_IPV4: + tss->parent->ss.ss_family =3D AF_INET; + break; + case SS_FAMILY_MIG_IPV6: + case 23: /* compatibility: AF_INET6 from mingw */ + case 28: /* compatibility: AF_INET6 from FreeBSD sys/socket.h */ + tss->parent->ss.ss_family =3D AF_INET6; + break; + default: + g_critical("invalid ss_family type %x", tss->portable_family); + return -EINVAL; + } + + return 0; +} + +static const VMStateDescription vmstate_slirp_ss_family =3D { + .name =3D "slirp-socket-addr/ss_family", + .pre_save =3D ss_family_pre_save, + .post_load =3D ss_family_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_UINT16(portable_family, SS_FamilyTmpStruct), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_slirp_socket_addr =3D { + .name =3D "slirp-socket-addr", + .version_id =3D 4, + .fields =3D (VMStateField[]) { + VMSTATE_WITH_TMP(union slirp_sockaddr, SS_FamilyTmpStruct, + vmstate_slirp_ss_family), + VMSTATE_SIN4_ADDR(sin.sin_addr.s_addr, union slirp_sockaddr, + slirp_family_inet), + VMSTATE_UINT16_TEST(sin.sin_port, union slirp_sockaddr, + slirp_family_inet), + +#if 0 + /* Untested: Needs checking by someone with IPv6 test */ + VMSTATE_BUFFER_TEST(sin6.sin6_addr, union slirp_sockaddr, + slirp_family_inet6), + VMSTATE_UINT16_TEST(sin6.sin6_port, union slirp_sockaddr, + slirp_family_inet6), + VMSTATE_UINT32_TEST(sin6.sin6_flowinfo, union slirp_sockaddr, + slirp_family_inet6), + VMSTATE_UINT32_TEST(sin6.sin6_scope_id, union slirp_sockaddr, + slirp_family_inet6), +#endif + + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_slirp_socket =3D { + .name =3D "slirp-socket", + .version_id =3D 4, + .pre_load =3D slirp_socket_pre_load, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(so_urgc, struct socket), + /* Pre-v4 versions */ + VMSTATE_SIN4_ADDR(so_faddr.s_addr, struct socket, + slirp_older_than_v4), + VMSTATE_SIN4_ADDR(so_laddr.s_addr, struct socket, + slirp_older_than_v4), + VMSTATE_UINT16_TEST(so_fport, struct socket, slirp_older_than_v4), + VMSTATE_UINT16_TEST(so_lport, struct socket, slirp_older_than_v4), + /* v4 and newer */ + VMSTATE_STRUCT(fhost, struct socket, 4, vmstate_slirp_socket_addr, + union slirp_sockaddr), + VMSTATE_STRUCT(lhost, struct socket, 4, vmstate_slirp_socket_addr, + union slirp_sockaddr), + + VMSTATE_UINT8(so_iptos, struct socket), + VMSTATE_UINT8(so_emu, struct socket), + VMSTATE_UINT8(so_type, struct socket), + VMSTATE_INT32(so_state, struct socket), + VMSTATE_STRUCT(so_rcv, struct socket, 0, vmstate_slirp_sbuf, + struct sbuf), + VMSTATE_STRUCT(so_snd, struct socket, 0, vmstate_slirp_sbuf, + struct sbuf), + VMSTATE_STRUCT_POINTER(so_tcpcb, struct socket, vmstate_slirp_tcp, + struct tcpcb), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_slirp_bootp_client =3D { + .name =3D "slirp_bootpclient", + .fields =3D (VMStateField[]) { + VMSTATE_UINT16(allocated, BOOTPClient), + VMSTATE_BUFFER(macaddr, BOOTPClient), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_slirp =3D { + .name =3D "slirp", + .version_id =3D 4, + .fields =3D (VMStateField[]) { + VMSTATE_UINT16_V(ip_id, Slirp, 2), + VMSTATE_STRUCT_ARRAY(bootp_clients, Slirp, NB_BOOTP_CLIENTS, 3, + vmstate_slirp_bootp_client, BOOTPClient), + VMSTATE_END_OF_LIST() + } +}; + +static void slirp_state_save(QEMUFile *f, void *opaque) +{ + Slirp *slirp =3D opaque; + struct gfwd_list *ex_ptr; + + for (ex_ptr =3D slirp->guestfwd_list; ex_ptr; ex_ptr =3D ex_ptr->ex_ne= xt) + if (ex_ptr->write_cb) { + struct socket *so; + so =3D slirp_find_ctl_socket(slirp, ex_ptr->ex_addr, + ntohs(ex_ptr->ex_fport)); + if (!so) { + continue; + } + + qemu_put_byte(f, 42); + vmstate_save_state(f, &vmstate_slirp_socket, so, NULL); + } + qemu_put_byte(f, 0); + + vmstate_save_state(f, &vmstate_slirp, slirp, NULL); +} + + +static int slirp_state_load(QEMUFile *f, void *opaque, int version_id) +{ + Slirp *slirp =3D opaque; + struct gfwd_list *ex_ptr; + + while (qemu_get_byte(f)) { + int ret; + struct socket *so =3D socreate(slirp); + + ret =3D vmstate_load_state(f, &vmstate_slirp_socket, so, version_i= d); + if (ret < 0) { + return ret; + } + + if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) !=3D + slirp->vnetwork_addr.s_addr) { + return -EINVAL; + } + for (ex_ptr =3D slirp->guestfwd_list; ex_ptr; ex_ptr =3D ex_ptr->e= x_next) { + if (ex_ptr->write_cb && + so->so_faddr.s_addr =3D=3D ex_ptr->ex_addr.s_addr && + so->so_fport =3D=3D ex_ptr->ex_fport) { + break; + } + } + if (!ex_ptr) { + return -EINVAL; + } + } + + return vmstate_load_state(f, &vmstate_slirp, slirp, version_id); +} + +void slirp_state_register(Slirp *slirp) +{ + static SaveVMHandlers savevm_slirp_state =3D { + .save_state =3D slirp_state_save, + .load_state =3D slirp_state_load, + }; + + register_savevm_live(NULL, "slirp", 0, 4, &savevm_slirp_state, slirp); +} + +void slirp_state_unregister(Slirp *slirp) +{ + unregister_savevm(NULL, "slirp", slirp); +} diff --git a/slirp/state.h b/slirp/state.h new file mode 100644 index 0000000000..154866898f --- /dev/null +++ b/slirp/state.h @@ -0,0 +1,9 @@ +#ifndef SLIRP_STATE_H_ +#define SLIRP_STATE_H_ + +#include "libslirp.h" + +void slirp_state_register(Slirp *slirp); +void slirp_state_unregister(Slirp *slirp); + +#endif /* SLIRP_STATE_H_ */ --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 1549549107017888.6255813112182; Thu, 7 Feb 2019 06:18:27 -0800 (PST) Received: from localhost ([127.0.0.1]:40782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkVT-0004v0-S5 for importer@patchew.org; Thu, 07 Feb 2019 09:18:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHc-0002CK-Az for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHQ-0000yg-3U for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:02 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41882) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHP-0000vU-Pb for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id E168ACD27; Thu, 7 Feb 2019 15:03:31 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id awK0Yvf9160l; Thu, 7 Feb 2019 15:03:31 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id EBEE8CD2A; Thu, 7 Feb 2019 15:03:19 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004DY-IM; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:00 +0200 Message-Id: <20190207140316.16103-17-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 16/32] slirp: do not include qemu headers in libslirp.h public API header 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/libslirp.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 679a25422b..02cbec9f8b 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -1,7 +1,17 @@ #ifndef LIBSLIRP_H #define LIBSLIRP_H =20 -#include "qemu-common.h" +#include +#include +#include + +#ifdef _WIN32 +#include +#include +#else +#include +#include +#endif =20 typedef struct Slirp Slirp; =20 --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549549537998598.7908134946107; Thu, 7 Feb 2019 06:25:37 -0800 (PST) Received: from localhost ([127.0.0.1]:40873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkcN-0002br-Vl for importer@patchew.org; Thu, 07 Feb 2019 09:25:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57710) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHq-0002RY-G7 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHg-0001Cn-Ld for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:16 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49846) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHg-0000yX-18 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:08 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 9EDC1CD29; Thu, 7 Feb 2019 15:03:33 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id B3z8jwLV8owE; Thu, 7 Feb 2019 15:03:32 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id F0684CD2C; Thu, 7 Feb 2019 15:03:19 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004Db-K8; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:01 +0200 Message-Id: <20190207140316.16103-18-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 17/32] slirp: improve windows headers inclusion 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Our API usage requires Vista, set WIN32_LEAN_AND_MEAN to fix a number of issues (winsock2.h include order for ex, which is better to include first for legacy reasons). While at it, group redundants #ifndef _WIN32 blocks. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/slirp.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/slirp/slirp.h b/slirp/slirp.h index 8d9d72ca9d..5a830ddcb8 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -3,10 +3,19 @@ =20 #ifdef _WIN32 =20 +/* as defined in sdkddkver.h */ +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 /* Vista */ +#endif +/* reduces the number of implicitly included headers */ +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + typedef char *caddr_t; =20 -# include # include +# include # include # include # include @@ -19,19 +28,10 @@ typedef char *caddr_t; =20 #ifndef _WIN32 #include -#endif - -#ifndef _WIN32 #include #include -#endif - -#ifndef _WIN32 #include -#endif - -#ifndef _WIN32 -# include +#include #endif =20 #ifdef __APPLE__ --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 1549549387359283.5437659176624; Thu, 7 Feb 2019 06:23:07 -0800 (PST) Received: from localhost ([127.0.0.1]:40851 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grka0-0000RQ-8K for importer@patchew.org; Thu, 07 Feb 2019 09:23:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHh-0002G6-07 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHf-0001BH-9H for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:08 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41890) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHc-0000yc-LN for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:06 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 62E1DCD2A; Thu, 7 Feb 2019 15:03:34 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jDQ14b1hzP-b; Thu, 7 Feb 2019 15:03:33 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 23D9BCD2E; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004De-M7; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:02 +0200 Message-Id: <20190207140316.16103-19-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 18/32] slirp: add slirp own version of pstrcpy 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Remove a dependency on qemu util. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/slirp.c | 4 ++-- slirp/tftp.c | 2 +- slirp/util.c | 17 +++++++++++++++++ slirp/util.h | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/slirp/slirp.c b/slirp/slirp.c index 9ec1e4c62f..b5c4788489 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -320,8 +320,8 @@ Slirp *slirp_init(int restricted, bool in_enabled, stru= ct in_addr vnetwork, slirp->vprefix_len =3D vprefix_len; slirp->vhost_addr6 =3D vhost6; if (vhostname) { - pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname), - vhostname); + slirp_pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostnam= e), + vhostname); } slirp->tftp_prefix =3D g_strdup(tftp_path); slirp->bootp_filename =3D g_strdup(bootfile); diff --git a/slirp/tftp.c b/slirp/tftp.c index 6fb381ef33..f0bcc72c92 100644 --- a/slirp/tftp.c +++ b/slirp/tftp.c @@ -216,7 +216,7 @@ static void tftp_send_error(struct tftp_session *spt, =20 tp->tp_op =3D htons(TFTP_ERROR); tp->x.tp_error.tp_error_code =3D htons(errorcode); - pstrcpy((char *)tp->x.tp_error.tp_msg, sizeof(tp->x.tp_error.tp_msg), ms= g); + slirp_pstrcpy((char *)tp->x.tp_error.tp_msg, sizeof(tp->x.tp_error.tp_ms= g), msg); =20 m->m_len =3D sizeof(struct tftp_t) - (TFTP_BLOCKSIZE_MAX + 2) + 3 + strl= en(msg) - sizeof(struct udphdr); diff --git a/slirp/util.c b/slirp/util.c index 59f6713c8b..84f5afdbc3 100644 --- a/slirp/util.c +++ b/slirp/util.c @@ -188,3 +188,20 @@ int slirp_closesocket(int fd) return ret; } #endif /* WIN32 */ + +void slirp_pstrcpy(char *buf, int buf_size, const char *str) +{ + int c; + char *q =3D buf; + + if (buf_size <=3D 0) + return; + + for(;;) { + c =3D *str++; + if (c =3D=3D 0 || q >=3D buf + buf_size - 1) + break; + *q++ =3D c; + } + *q =3D '\0'; +} diff --git a/slirp/util.h b/slirp/util.h index 4f6e80c3ed..586517bb30 100644 --- a/slirp/util.h +++ b/slirp/util.h @@ -91,4 +91,6 @@ static inline int slirp_socket_set_fast_reuse(int fd) #endif } =20 +void slirp_pstrcpy(char *buf, int buf_size, const char *str); + #endif --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549549209644590.5146804798685; Thu, 7 Feb 2019 06:20:09 -0800 (PST) Received: from localhost ([127.0.0.1]:40789 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkX5-0006CL-J7 for importer@patchew.org; Thu, 07 Feb 2019 09:20:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHZ-0002Bj-05 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHS-00010v-9B for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:00 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41896) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHR-0000yu-Bb for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 3490DCD2E; Thu, 7 Feb 2019 15:03:36 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id E2cKL8k6AeV7; Thu, 7 Feb 2019 15:03:35 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 5ED55CD35; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004Dh-Nt; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:03 +0200 Message-Id: <20190207140316.16103-20-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 19/32] slirp: remove qemu timer.h dependency 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/if.c | 1 - slirp/ip6_icmp.c | 1 - slirp/slirp.c | 1 - slirp/util.h | 2 ++ 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/slirp/if.c b/slirp/if.c index 73e3705740..90b9078687 100644 --- a/slirp/if.c +++ b/slirp/if.c @@ -7,7 +7,6 @@ =20 #include "qemu/osdep.h" #include "slirp.h" -#include "qemu/timer.h" =20 static void ifs_insque(struct mbuf *ifm, struct mbuf *ifmhead) diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index e72c57a81d..682597e676 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -6,7 +6,6 @@ #include "qemu/osdep.h" #include "slirp.h" #include "ip6_icmp.h" -#include "qemu/timer.h" #include "qemu/error-report.h" #include "qemu/log.h" =20 diff --git a/slirp/slirp.c b/slirp/slirp.c index b5c4788489..7a5d97c77f 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -23,7 +23,6 @@ */ #include "qemu/osdep.h" #include "qemu-common.h" -#include "qemu/timer.h" #include "qemu/error-report.h" #include "migration/register.h" #include "slirp.h" diff --git a/slirp/util.h b/slirp/util.h index 586517bb30..922077435e 100644 --- a/slirp/util.h +++ b/slirp/util.h @@ -48,6 +48,8 @@ # define SLIRP_PACKED __attribute__((packed)) #endif =20 +#define SCALE_MS 1000000 + #ifdef _WIN32 int slirp_closesocket(int fd); int slirp_ioctlsocket(int fd, int req, void *val); --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549548821028202.98491546041362; Thu, 7 Feb 2019 06:13:41 -0800 (PST) Received: from localhost ([127.0.0.1]:40707 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkQo-00017U-SZ for importer@patchew.org; Thu, 07 Feb 2019 09:13:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHV-00027K-1h for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHS-000110-8b for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:56 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49850) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHR-0000yY-5p for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id BF522CD2D; Thu, 7 Feb 2019 15:03:34 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id M-vcRA5BnPKH; Thu, 7 Feb 2019 15:03:33 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 2AF08CD33; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004Dk-Ph; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:04 +0200 Message-Id: <20190207140316.16103-21-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 20/32] slirp: remove now useless QEMU headers inclusions 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Some of those could have been squashed earlier, but it is easier to do it all here. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: samuel Thibault --- slirp/dhcpv6.c | 1 - slirp/ip6_icmp.c | 2 -- slirp/misc.c | 2 -- slirp/sbuf.c | 1 - slirp/slirp.c | 4 ---- slirp/slirp.h | 1 - slirp/tftp.c | 1 - slirp/util.h | 2 -- 8 files changed, 14 deletions(-) diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c index 752df40536..e27d9a46f8 100644 --- a/slirp/dhcpv6.c +++ b/slirp/dhcpv6.c @@ -21,7 +21,6 @@ */ =20 #include "qemu/osdep.h" -#include "qemu/log.h" #include "slirp.h" #include "dhcpv6.h" =20 diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 682597e676..b3b7e50a31 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -6,8 +6,6 @@ #include "qemu/osdep.h" #include "slirp.h" #include "ip6_icmp.h" -#include "qemu/error-report.h" -#include "qemu/log.h" =20 #define NDP_Interval g_rand_int_range(slirp->grand, \ NDP_MinRtrAdvInterval, NDP_MaxRtrAdvInterval) diff --git a/slirp/misc.c b/slirp/misc.c index 4ee20a10e4..a77cc34b30 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -8,8 +8,6 @@ #include "qemu/osdep.h" #include "slirp.h" #include "libslirp.h" -#include "qemu/error-report.h" -#include "qemu/main-loop.h" =20 inline void insque(void *a, void *b) diff --git a/slirp/sbuf.c b/slirp/sbuf.c index 17f28e97a6..c83e4dd8ed 100644 --- a/slirp/sbuf.c +++ b/slirp/sbuf.c @@ -7,7 +7,6 @@ =20 #include "qemu/osdep.h" #include "slirp.h" -#include "qemu/main-loop.h" =20 static void sbappendsb(struct sbuf *sb, struct mbuf *m); =20 diff --git a/slirp/slirp.c b/slirp/slirp.c index 7a5d97c77f..ec1f606d72 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -23,11 +23,7 @@ */ #include "qemu/osdep.h" #include "qemu-common.h" -#include "qemu/error-report.h" -#include "migration/register.h" #include "slirp.h" -#include "hw/hw.h" -#include "qemu/cutils.h" =20 #ifdef WITH_QEMU #include "state.h" diff --git a/slirp/slirp.h b/slirp/slirp.h index 5a830ddcb8..5707805be2 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -48,7 +48,6 @@ typedef char *caddr_t; #include "util.h" =20 #include "qemu/queue.h" -#include "qemu/sockets.h" #include "net/eth.h" =20 #include "libslirp.h" diff --git a/slirp/tftp.c b/slirp/tftp.c index f0bcc72c92..5c31886190 100644 --- a/slirp/tftp.c +++ b/slirp/tftp.c @@ -25,7 +25,6 @@ #include "qemu/osdep.h" #include "slirp.h" #include "qemu-common.h" -#include "qemu/cutils.h" =20 static inline int tftp_session_in_use(struct tftp_session *spt) { diff --git a/slirp/util.h b/slirp/util.h index 922077435e..4664e8159b 100644 --- a/slirp/util.h +++ b/slirp/util.h @@ -53,9 +53,7 @@ #ifdef _WIN32 int slirp_closesocket(int fd); int slirp_ioctlsocket(int fd, int req, void *val); -#ifndef WITH_QEMU int inet_aton(const char *cp, struct in_addr *ia); -#endif #define slirp_getsockopt(sockfd, level, optname, optval, optlen) \ getsockopt(sockfd, level, optname, (void *)optval, optlen) #define slirp_setsockopt(sockfd, level, optname, optval, optlen) \ --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 1549548744184323.95983721435505; Thu, 7 Feb 2019 06:12:24 -0800 (PST) Received: from localhost ([127.0.0.1]:40703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkPe-00004z-6e for importer@patchew.org; Thu, 07 Feb 2019 09:12:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHV-00027L-1q for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHS-00010V-4u for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:56 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41894) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHR-0000yk-7V for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 4CB1FCD2C; Thu, 7 Feb 2019 15:03:35 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tbk74aXOQ_Ok; Thu, 7 Feb 2019 15:03:34 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 589D8CD34; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004Dn-RW; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:05 +0200 Message-Id: <20190207140316.16103-22-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 21/32] slirp: replace net/eth.h inclusion with own defines 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/ip6.h | 1 - slirp/slirp.h | 1 - slirp/util.h | 10 ++++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/slirp/ip6.h b/slirp/ip6.h index 1e3e329ce6..4e7c366505 100644 --- a/slirp/ip6.h +++ b/slirp/ip6.h @@ -7,7 +7,6 @@ #define SLIRP_IP6_H =20 #include -#include "net/eth.h" =20 #define ALLNODES_MULTICAST { .s6_addr =3D \ { 0xff, 0x02, 0x00, 0x00,\ diff --git a/slirp/slirp.h b/slirp/slirp.h index 5707805be2..c9f9143801 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -48,7 +48,6 @@ typedef char *caddr_t; #include "util.h" =20 #include "qemu/queue.h" -#include "net/eth.h" =20 #include "libslirp.h" #include "ip.h" diff --git a/slirp/util.h b/slirp/util.h index 4664e8159b..ef75804560 100644 --- a/slirp/util.h +++ b/slirp/util.h @@ -50,6 +50,16 @@ =20 #define SCALE_MS 1000000 =20 +#define ETH_ALEN 6 +#define ETH_HLEN 14 +#define ETH_P_IP (0x0800) /* Internet Protocol packe= t */ +#define ETH_P_ARP (0x0806) /* Address Resolution pack= et */ +#define ETH_P_IPV6 (0x86dd) +#define ETH_P_VLAN (0x8100) +#define ETH_P_DVLAN (0x88a8) +#define ETH_P_NCSI (0x88f8) +#define ETH_P_UNKNOWN (0xffff) + #ifdef _WIN32 int slirp_closesocket(int fd); int slirp_ioctlsocket(int fd, int req, void *val); --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549549563115251.70321895385302; Thu, 7 Feb 2019 06:26:03 -0800 (PST) Received: from localhost ([127.0.0.1]:40909 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkcm-00033b-Uh for importer@patchew.org; Thu, 07 Feb 2019 09:25:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHa-0002CG-Ln for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHS-00010c-5v for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:00 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49858) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHR-0000yq-4a for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 93A02CD35; Thu, 7 Feb 2019 15:03:37 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mQsSK20s8h_Z; Thu, 7 Feb 2019 15:03:34 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 6199CCD36; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004Dq-TR; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:06 +0200 Message-Id: <20190207140316.16103-23-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 22/32] slirp: replace qemu qtailq with slirp own copy 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/qtailq.h | 193 +++++++++++++++++++++++++++++++++++++++++++++++++ slirp/slirp.h | 3 +- 2 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 slirp/qtailq.h diff --git a/slirp/qtailq.h b/slirp/qtailq.h new file mode 100644 index 0000000000..a89b0c439a --- /dev/null +++ b/slirp/qtailq.h @@ -0,0 +1,193 @@ +/* $NetBSD: queue.h,v 1.52 2009/04/20 09:56:08 mschuett Exp $ */ + +/* + * slirp version: Copy from QEMU, removed all but tail queues. + */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP= OSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR= ICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + */ + +#ifndef QTAILQ_H +#define QTAILQ_H + +/* + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + */ +typedef struct QTailQLink { + void *tql_next; + struct QTailQLink *tql_prev; +} QTailQLink; + +/* + * Tail queue definitions. The union acts as a poor man template, as if + * it were QTailQLink. + */ +#define QTAILQ_HEAD(name, type) \ + union name { \ + struct type *tqh_first; /* first element */ \ + QTailQLink tqh_circ; /* link for circular backwards list = */ \ + } + +#define QTAILQ_HEAD_INITIALIZER(head) \ + { .tqh_circ =3D { NULL, &(head).tqh_circ } } + +#define QTAILQ_ENTRY(type) \ + union { \ + struct type *tqe_next; /* next element */ \ + QTailQLink tqe_circ; /* link for circular backwards list = */ \ + } + +#define QTAILQ_INIT(head) do { \ + (head)->tqh_first =3D NULL; \ + (head)->tqh_circ.tql_prev =3D &(head)->tqh_circ; \ +} while (/*CONSTCOND*/0) + +#define QTAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.tqe_next =3D (head)->tqh_first) !=3D NULL) = \ + (head)->tqh_first->field.tqe_circ.tql_prev =3D \ + &(elm)->field.tqe_circ; \ + else \ + (head)->tqh_circ.tql_prev =3D &(elm)->field.tqe_circ; \ + (head)->tqh_first =3D (elm); \ + (elm)->field.tqe_circ.tql_prev =3D &(head)->tqh_circ; \ +} while (/*CONSTCOND*/0) + +#define QTAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.tqe_next =3D NULL; \ + (elm)->field.tqe_circ.tql_prev =3D (head)->tqh_circ.tql_prev; \ + (head)->tqh_circ.tql_prev->tql_next =3D (elm); \ + (head)->tqh_circ.tql_prev =3D &(elm)->field.tqe_circ; \ +} while (/*CONSTCOND*/0) + +#define QTAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.tqe_next =3D (listelm)->field.tqe_next) !=3D NUL= L)\ + (elm)->field.tqe_next->field.tqe_circ.tql_prev =3D \ + &(elm)->field.tqe_circ; \ + else \ + (head)->tqh_circ.tql_prev =3D &(elm)->field.tqe_circ; \ + (listelm)->field.tqe_next =3D (elm); \ + (elm)->field.tqe_circ.tql_prev =3D &(listelm)->field.tqe_circ; \ +} while (/*CONSTCOND*/0) + +#define QTAILQ_INSERT_BEFORE(listelm, elm, field) do { = \ + (elm)->field.tqe_circ.tql_prev =3D (listelm)->field.tqe_circ.tql_p= rev; \ + (elm)->field.tqe_next =3D (listelm); = \ + (listelm)->field.tqe_circ.tql_prev->tql_next =3D (elm); = \ + (listelm)->field.tqe_circ.tql_prev =3D &(elm)->field.tqe_circ; = \ +} while (/*CONSTCOND*/0) + +#define QTAILQ_REMOVE(head, elm, field) do { \ + if (((elm)->field.tqe_next) !=3D NULL) \ + (elm)->field.tqe_next->field.tqe_circ.tql_prev =3D \ + (elm)->field.tqe_circ.tql_prev; \ + else \ + (head)->tqh_circ.tql_prev =3D (elm)->field.tqe_circ.tql_prev; \ + (elm)->field.tqe_circ.tql_prev->tql_next =3D (elm)->field.tqe_next= ; \ + (elm)->field.tqe_circ.tql_prev =3D NULL; \ +} while (/*CONSTCOND*/0) + +#define QTAILQ_FOREACH(var, head, field) \ + for ((var) =3D ((head)->tqh_first); \ + (var); \ + (var) =3D ((var)->field.tqe_next)) + +#define QTAILQ_FOREACH_SAFE(var, head, field, next_var) \ + for ((var) =3D ((head)->tqh_first); \ + (var) && ((next_var) =3D ((var)->field.tqe_next), 1); \ + (var) =3D (next_var)) + +#define QTAILQ_FOREACH_REVERSE(var, head, field) \ + for ((var) =3D QTAILQ_LAST(head); \ + (var); \ + (var) =3D QTAILQ_PREV(var, field)) + +#define QTAILQ_FOREACH_REVERSE_SAFE(var, head, field, prev_var) \ + for ((var) =3D QTAILQ_LAST(head); \ + (var) && ((prev_var) =3D QTAILQ_PREV(var, field)); \ + (var) =3D (prev_var)) + +/* + * Tail queue access methods. + */ +#define QTAILQ_EMPTY(head) ((head)->tqh_first =3D=3D NULL) +#define QTAILQ_FIRST(head) ((head)->tqh_first) +#define QTAILQ_NEXT(elm, field) ((elm)->field.tqe_next) +#define QTAILQ_IN_USE(elm, field) ((elm)->field.tqe_circ.tql_prev != =3D NULL) + +#define QTAILQ_LINK_PREV(link) \ + ((link).tql_prev->tql_prev->tql_next) +#define QTAILQ_LAST(head) \ + ((typeof((head)->tqh_first)) QTAILQ_LINK_PREV((head)->tqh_circ)) +#define QTAILQ_PREV(elm, field) \ + ((typeof((elm)->field.tqe_next)) QTAILQ_LINK_PREV((elm)->field.tqe= _circ)) + +#define field_at_offset(base, offset, type) = \ + ((type *) (((char *) (base)) + (offset))) + +/* + * Raw access of elements of a tail queue head. Offsets are all zero + * because it's a union. + */ +#define QTAILQ_RAW_FIRST(head) = \ + field_at_offset(head, 0, void *) +#define QTAILQ_RAW_TQH_CIRC(head) = \ + field_at_offset(head, 0, QTailQLink) + +/* + * Raw access of elements of a tail entry + */ +#define QTAILQ_RAW_NEXT(elm, entry) = \ + field_at_offset(elm, entry, void *) +#define QTAILQ_RAW_TQE_CIRC(elm, entry) = \ + field_at_offset(elm, entry, QTailQLink) +/* + * Tail queue traversal using pointer arithmetic. + */ +#define QTAILQ_RAW_FOREACH(elm, head, entry) = \ + for ((elm) =3D *QTAILQ_RAW_FIRST(head); = \ + (elm); = \ + (elm) =3D *QTAILQ_RAW_NEXT(elm, entry)) +/* + * Tail queue insertion using pointer arithmetic. + */ +#define QTAILQ_RAW_INSERT_TAIL(head, elm, entry) do { = \ + *QTAILQ_RAW_NEXT(elm, entry) =3D NULL; = \ + QTAILQ_RAW_TQE_CIRC(elm, entry)->tql_prev =3D QTAILQ_RAW_TQH_CIRC(= head)->tql_prev; \ + QTAILQ_RAW_TQH_CIRC(head)->tql_prev->tql_next =3D (elm); = \ + QTAILQ_RAW_TQH_CIRC(head)->tql_prev =3D QTAILQ_RAW_TQE_CIRC(elm, e= ntry); \ +} while (/*CONSTCOND*/0) + +#endif /* QTAILQ_H */ diff --git a/slirp/slirp.h b/slirp/slirp.h index c9f9143801..0e4d973c2a 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -46,8 +46,7 @@ typedef char *caddr_t; =20 #include "debug.h" #include "util.h" - -#include "qemu/queue.h" +#include "qtailq.h" =20 #include "libslirp.h" #include "ip.h" --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549548645173149.5289893701339; Thu, 7 Feb 2019 06:10:45 -0800 (PST) Received: from localhost ([127.0.0.1]:40649 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkNz-00074Z-1b for importer@patchew.org; Thu, 07 Feb 2019 09:10:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHT-00025H-0c for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHS-00010L-09 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:54 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49860) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHR-0000yi-0G for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id CD973CD33; Thu, 7 Feb 2019 15:03:37 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xIJ3JsxnH1tJ; Thu, 7 Feb 2019 15:03:36 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 7EB15CD37; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004Dt-Ul; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:07 +0200 Message-Id: <20190207140316.16103-24-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 23/32] slirp: replace QEMU_BUILD_BUG_ON with G_STATIC_ASSERT 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: jan.kiszka@siemens.com, Richard Henderson , stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Stefano Garzarella Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" to remove another dependency on qemu. Signed-off-by: Samuel Thibault Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Richard Henderson Reviewed-by: Stefano Garzarella Reviewed-by: Alex Benn=C3=A9e --- slirp/ip.h | 4 ++-- slirp/ip6.h | 4 ++-- slirp/ip6_icmp.h | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/slirp/ip.h b/slirp/ip.h index 2baeeb9a3a..73a4d2a3d2 100644 --- a/slirp/ip.h +++ b/slirp/ip.h @@ -229,8 +229,8 @@ struct ipasfrag { struct ip ipf_ip; }; =20 -QEMU_BUILD_BUG_ON(offsetof(struct ipq, frag_link) !=3D - offsetof(struct ipasfrag, ipf_link)); +G_STATIC_ASSERT(offsetof(struct ipq, frag_link) =3D=3D + offsetof(struct ipasfrag, ipf_link)); =20 #define ipf_off ipf_ip.ip_off #define ipf_tos ipf_ip.ip_tos diff --git a/slirp/ip6.h b/slirp/ip6.h index 4e7c366505..5361bd7449 100644 --- a/slirp/ip6.h +++ b/slirp/ip6.h @@ -152,7 +152,7 @@ struct ip6_pseudohdr { * If we marked the struct as packed then we would be unable to take * the address of any of the fields in it. */ -QEMU_BUILD_BUG_ON(sizeof(struct ip6) !=3D 40); -QEMU_BUILD_BUG_ON(sizeof(struct ip6_pseudohdr) !=3D 40); +G_STATIC_ASSERT(sizeof(struct ip6) =3D=3D 40); +G_STATIC_ASSERT(sizeof(struct ip6_pseudohdr) =3D=3D 40); =20 #endif diff --git a/slirp/ip6_icmp.h b/slirp/ip6_icmp.h index 3f44ed2f49..e8ed753db5 100644 --- a/slirp/ip6_icmp.h +++ b/slirp/ip6_icmp.h @@ -50,14 +50,14 @@ struct ndp_ra { /* Router Advertisement Message */ uint32_t retrans_time; /* Retrans Timer */ }; =20 -QEMU_BUILD_BUG_ON(sizeof(struct ndp_ra) !=3D 12); +G_STATIC_ASSERT(sizeof(struct ndp_ra) =3D=3D 12); =20 struct ndp_ns { /* Neighbor Solicitation Message */ uint32_t reserved; struct in6_addr target; /* Target Address */ }; =20 -QEMU_BUILD_BUG_ON(sizeof(struct ndp_ns) !=3D 20); +G_STATIC_ASSERT(sizeof(struct ndp_ns) =3D=3D 20); =20 struct ndp_na { /* Neighbor Advertisement Message */ #if G_BYTE_ORDER =3D=3D G_BIG_ENDIAN @@ -78,7 +78,7 @@ struct ndp_na { /* Neighbor Advertisement Message */ struct in6_addr target; /* Target Address */ }; =20 -QEMU_BUILD_BUG_ON(sizeof(struct ndp_na) !=3D 20); +G_STATIC_ASSERT(sizeof(struct ndp_na) =3D=3D 20); =20 struct ndp_redirect { uint32_t reserved; @@ -86,7 +86,7 @@ struct ndp_redirect { struct in6_addr dest; /* Destination Address */ }; =20 -QEMU_BUILD_BUG_ON(sizeof(struct ndp_redirect) !=3D 36); +G_STATIC_ASSERT(sizeof(struct ndp_redirect) =3D=3D 36); =20 /* * Structure of an icmpv6 header. @@ -113,7 +113,7 @@ struct icmp6 { #define icmp6_redirect icmp6_body.ndp_redirect }; =20 -QEMU_BUILD_BUG_ON(sizeof(struct icmp6) !=3D 40); +G_STATIC_ASSERT(sizeof(struct icmp6) =3D=3D 40); =20 #define ICMP6_MINLEN 4 #define ICMP6_ERROR_MINLEN 8 --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 154954891764345.61054568844372; Thu, 7 Feb 2019 06:15:17 -0800 (PST) Received: from localhost ([127.0.0.1]:40725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkSI-0002Sr-9P for importer@patchew.org; Thu, 07 Feb 2019 09:15:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHY-0002Ba-S5 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHS-00010G-07 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:00 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHR-0000ya-1U for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:53 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id C3B24CD34; Thu, 7 Feb 2019 15:03:36 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id joyuvxcg6ZbX; Thu, 7 Feb 2019 15:03:36 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 830E1CD38; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGr-0004Dw-W3; Thu, 07 Feb 2019 15:03:17 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:08 +0200 Message-Id: <20190207140316.16103-25-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 24/32] slirp: Move g_spawn_async_with_fds_qemu compatibility to slirp/ 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: Samuel Thibault , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Only slirp actually needs it, and will need it along in libslirp. Signed-off-by: Samuel Thibault Reviewed-by: Marc-Andr=C3=A9 Lureau --- include/glib-compat.h | 57 --------------------------------------- slirp/misc.c | 62 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 57 deletions(-) diff --git a/include/glib-compat.h b/include/glib-compat.h index 8a078c5288..1291628e09 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -83,63 +83,6 @@ static inline gboolean g_strv_contains_qemu(const gchar = *const *strv, } #define g_strv_contains(a, b) g_strv_contains_qemu(a, b) =20 -#if !GLIB_CHECK_VERSION(2, 58, 0) -typedef struct QemuGSpawnFds { - GSpawnChildSetupFunc child_setup; - gpointer user_data; - gint stdin_fd; - gint stdout_fd; - gint stderr_fd; -} QemuGSpawnFds; - -static inline void -qemu_gspawn_fds_setup(gpointer user_data) -{ - QemuGSpawnFds *q =3D (QemuGSpawnFds *)user_data; - - dup2(q->stdin_fd, 0); - dup2(q->stdout_fd, 1); - dup2(q->stderr_fd, 2); - q->child_setup(q->user_data); -} -#endif - -static inline gboolean -g_spawn_async_with_fds_qemu(const gchar *working_directory, - gchar **argv, - gchar **envp, - GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, - GPid *child_pid, - gint stdin_fd, - gint stdout_fd, - gint stderr_fd, - GError **error) -{ -#if GLIB_CHECK_VERSION(2, 58, 0) - return g_spawn_async_with_fds(working_directory, argv, envp, flags, - child_setup, user_data, - child_pid, stdin_fd, stdout_fd, stderr_f= d, - error); -#else - QemuGSpawnFds setup =3D { - .child_setup =3D child_setup, - .user_data =3D user_data, - .stdin_fd =3D stdin_fd, - .stdout_fd =3D stdout_fd, - .stderr_fd =3D stderr_fd, - }; - - return g_spawn_async(working_directory, argv, envp, flags, - qemu_gspawn_fds_setup, &setup, - child_pid, error); -#endif -} - -#define g_spawn_async_with_fds(wd, argv, env, f, c, d, p, ifd, ofd, efd, e= rr) \ - g_spawn_async_with_fds_qemu(wd, argv, env, f, c, d, p, ifd, ofd, efd, = err) - #if defined(_WIN32) && !GLIB_CHECK_VERSION(2, 50, 0) /* * g_poll has a problem on Windows when using diff --git a/slirp/misc.c b/slirp/misc.c index a77cc34b30..ee77aff337 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -122,6 +122,68 @@ fork_exec_child_setup(gpointer data) #endif } =20 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + +#if !GLIB_CHECK_VERSION(2, 58, 0) +typedef struct SlirpGSpawnFds { + GSpawnChildSetupFunc child_setup; + gpointer user_data; + gint stdin_fd; + gint stdout_fd; + gint stderr_fd; +} SlirpGSpawnFds; + +static inline void +slirp_gspawn_fds_setup(gpointer user_data) +{ + SlirpGSpawnFds *q =3D (SlirpGSpawnFds *)user_data; + + dup2(q->stdin_fd, 0); + dup2(q->stdout_fd, 1); + dup2(q->stderr_fd, 2); + q->child_setup(q->user_data); +} +#endif + +static inline gboolean +g_spawn_async_with_fds_slirp(const gchar *working_directory, + gchar **argv, + gchar **envp, + GSpawnFlags flags, + GSpawnChildSetupFunc child_setup, + gpointer user_data, + GPid *child_pid, + gint stdin_fd, + gint stdout_fd, + gint stderr_fd, + GError **error) +{ +#if GLIB_CHECK_VERSION(2, 58, 0) + return g_spawn_async_with_fds(working_directory, argv, envp, flags, + child_setup, user_data, + child_pid, stdin_fd, stdout_fd, stderr_f= d, + error); +#else + SlirpGSpawnFds setup =3D { + .child_setup =3D child_setup, + .user_data =3D user_data, + .stdin_fd =3D stdin_fd, + .stdout_fd =3D stdout_fd, + .stderr_fd =3D stderr_fd, + }; + + return g_spawn_async(working_directory, argv, envp, flags, + slirp_gspawn_fds_setup, &setup, + child_pid, error); +#endif +} + +#define g_spawn_async_with_fds(wd, argv, env, f, c, d, p, ifd, ofd, efd, e= rr) \ + g_spawn_async_with_fds_slirp(wd, argv, env, f, c, d, p, ifd, ofd, efd,= err) + +#pragma GCC diagnostic pop + int fork_exec(struct socket *so, const char *ex) { --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 15495492055241007.8355317205672; Thu, 7 Feb 2019 06:20:05 -0800 (PST) Received: from localhost ([127.0.0.1]:40787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkX4-0006C2-9n for importer@patchew.org; Thu, 07 Feb 2019 09:20:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHi-0002IC-Nt for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHg-0001CY-Jl for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:10 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41906) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHe-0000yz-Hs for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:08 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 7CE19CD36; Thu, 7 Feb 2019 15:03:39 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6M_DGYc3E5g2; Thu, 7 Feb 2019 15:03:37 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 9D915CD39; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGs-0004Dy-19; Thu, 07 Feb 2019 15:03:18 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:09 +0200 Message-Id: <20190207140316.16103-26-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 25/32] slirp: replace remaining qemu headers dependency 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Except for the migration code which is gated by WITH_QEMU, only include our own headers, so libslirp can be built standalone. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/arp_table.c | 3 ++- slirp/bootp.c | 1 - slirp/cksum.c | 1 - slirp/dhcpv6.c | 1 - slirp/dnssearch.c | 1 - slirp/if.c | 1 - slirp/ip6.h | 1 + slirp/ip6_icmp.c | 1 - slirp/ip6_input.c | 1 - slirp/ip6_output.c | 2 -- slirp/ip_icmp.c | 1 - slirp/ip_input.c | 1 - slirp/ip_output.c | 1 - slirp/mbuf.c | 1 - slirp/misc.c | 2 -- slirp/ncsi.c | 1 - slirp/ndp_table.c | 2 -- slirp/sbuf.c | 1 - slirp/slirp.c | 2 -- slirp/socket.c | 2 -- slirp/tcp_input.c | 1 - slirp/tcp_output.c | 1 - slirp/tcp_subr.c | 1 - slirp/tcp_timer.c | 1 - slirp/tftp.c | 6 ++++-- slirp/udp.c | 1 - slirp/udp6.c | 2 -- slirp/util.h | 21 +++++++++++++++++++++ 28 files changed, 28 insertions(+), 33 deletions(-) diff --git a/slirp/arp_table.c b/slirp/arp_table.c index bf71b984ad..58eafdcfd8 100644 --- a/slirp/arp_table.c +++ b/slirp/arp_table.c @@ -22,9 +22,10 @@ * THE SOFTWARE. */ =20 -#include "qemu/osdep.h" #include "slirp.h" =20 +#include + void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALE= N]) { const uint32_t broadcast_addr =3D diff --git a/slirp/bootp.c b/slirp/bootp.c index 4c9a77eb98..d396849a05 100644 --- a/slirp/bootp.c +++ b/slirp/bootp.c @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN * THE SOFTWARE. */ -#include "qemu/osdep.h" #include "slirp.h" =20 #if defined(_WIN32) diff --git a/slirp/cksum.c b/slirp/cksum.c index 84c858fafb..25bfa67348 100644 --- a/slirp/cksum.c +++ b/slirp/cksum.c @@ -30,7 +30,6 @@ * in_cksum.c,v 1.2 1994/08/02 07:48:16 davidg Exp */ =20 -#include "qemu/osdep.h" #include "slirp.h" =20 /* diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c index e27d9a46f8..9ffba38e8f 100644 --- a/slirp/dhcpv6.c +++ b/slirp/dhcpv6.c @@ -20,7 +20,6 @@ * along with this program; if not, see . */ =20 -#include "qemu/osdep.h" #include "slirp.h" #include "dhcpv6.h" =20 diff --git a/slirp/dnssearch.c b/slirp/dnssearch.c index 8fb563321b..c459cece8d 100644 --- a/slirp/dnssearch.c +++ b/slirp/dnssearch.c @@ -22,7 +22,6 @@ * THE SOFTWARE. */ =20 -#include "qemu/osdep.h" #include "slirp.h" =20 static const uint8_t RFC3397_OPT_DOMAIN_SEARCH =3D 119; diff --git a/slirp/if.c b/slirp/if.c index 90b9078687..2ad03b8a79 100644 --- a/slirp/if.c +++ b/slirp/if.c @@ -5,7 +5,6 @@ * terms and conditions of the copyright. */ =20 -#include "qemu/osdep.h" #include "slirp.h" =20 static void diff --git a/slirp/ip6.h b/slirp/ip6.h index 5361bd7449..1b3364f960 100644 --- a/slirp/ip6.h +++ b/slirp/ip6.h @@ -7,6 +7,7 @@ #define SLIRP_IP6_H =20 #include +#include =20 #define ALLNODES_MULTICAST { .s6_addr =3D \ { 0xff, 0x02, 0x00, 0x00,\ diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index b3b7e50a31..2a432ebbd4 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -3,7 +3,6 @@ * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. */ =20 -#include "qemu/osdep.h" #include "slirp.h" #include "ip6_icmp.h" =20 diff --git a/slirp/ip6_input.c b/slirp/ip6_input.c index ab656a0a9d..1b8c003c66 100644 --- a/slirp/ip6_input.c +++ b/slirp/ip6_input.c @@ -3,7 +3,6 @@ * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. */ =20 -#include "qemu/osdep.h" #include "slirp.h" #include "ip6_icmp.h" =20 diff --git a/slirp/ip6_output.c b/slirp/ip6_output.c index 52c88ad691..19d1ae7748 100644 --- a/slirp/ip6_output.c +++ b/slirp/ip6_output.c @@ -3,8 +3,6 @@ * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. */ =20 -#include "qemu/osdep.h" -#include "qemu-common.h" #include "slirp.h" =20 /* Number of packets queued before we start sending diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index 19e247f773..6b6344b776 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -30,7 +30,6 @@ * ip_icmp.c,v 1.7 1995/05/30 08:09:42 rgrimes Exp */ =20 -#include "qemu/osdep.h" #include "slirp.h" #include "ip_icmp.h" =20 diff --git a/slirp/ip_input.c b/slirp/ip_input.c index d360620838..774ce662e6 100644 --- a/slirp/ip_input.c +++ b/slirp/ip_input.c @@ -38,7 +38,6 @@ * terms and conditions of the copyright. */ =20 -#include "qemu/osdep.h" #include "slirp.h" #include "ip_icmp.h" =20 diff --git a/slirp/ip_output.c b/slirp/ip_output.c index db403f04c1..f6ec141df5 100644 --- a/slirp/ip_output.c +++ b/slirp/ip_output.c @@ -38,7 +38,6 @@ * terms and conditions of the copyright. */ =20 -#include "qemu/osdep.h" #include "slirp.h" =20 /* Number of packets queued before we start sending diff --git a/slirp/mbuf.c b/slirp/mbuf.c index d8d275e0e7..521c02c967 100644 --- a/slirp/mbuf.c +++ b/slirp/mbuf.c @@ -15,7 +15,6 @@ * the flags */ =20 -#include "qemu/osdep.h" #include "slirp.h" =20 #define MBUF_THRESH 30 diff --git a/slirp/misc.c b/slirp/misc.c index ee77aff337..3c02510101 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -5,9 +5,7 @@ * terms and conditions of the copyright. */ =20 -#include "qemu/osdep.h" #include "slirp.h" -#include "libslirp.h" =20 inline void insque(void *a, void *b) diff --git a/slirp/ncsi.c b/slirp/ncsi.c index 8594382270..327f17543c 100644 --- a/slirp/ncsi.c +++ b/slirp/ncsi.c @@ -6,7 +6,6 @@ * This code is licensed under the GPL version 2 or later. See the * COPYING file in the top-level directory. */ -#include "qemu/osdep.h" #include "slirp.h" =20 #include "ncsi-pkt.h" diff --git a/slirp/ndp_table.c b/slirp/ndp_table.c index b7b73722f7..34ea4fdf1f 100644 --- a/slirp/ndp_table.c +++ b/slirp/ndp_table.c @@ -3,8 +3,6 @@ * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. */ =20 -#include "qemu/osdep.h" -#include "qemu-common.h" #include "slirp.h" =20 void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr, diff --git a/slirp/sbuf.c b/slirp/sbuf.c index c83e4dd8ed..51a9f0cc7d 100644 --- a/slirp/sbuf.c +++ b/slirp/sbuf.c @@ -5,7 +5,6 @@ * terms and conditions of the copyright. */ =20 -#include "qemu/osdep.h" #include "slirp.h" =20 static void sbappendsb(struct sbuf *sb, struct mbuf *m); diff --git a/slirp/slirp.c b/slirp/slirp.c index ec1f606d72..730b78255c 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -21,8 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN * THE SOFTWARE. */ -#include "qemu/osdep.h" -#include "qemu-common.h" #include "slirp.h" =20 #ifdef WITH_QEMU diff --git a/slirp/socket.c b/slirp/socket.c index 2e8dc22fb6..dea201f5ce 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -5,8 +5,6 @@ * terms and conditions of the copyright. */ =20 -#include "qemu/osdep.h" -#include "qemu-common.h" #include "slirp.h" #include "ip_icmp.h" #ifdef __sun__ diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c index 7c1fe18fec..864da7d857 100644 --- a/slirp/tcp_input.c +++ b/slirp/tcp_input.c @@ -38,7 +38,6 @@ * terms and conditions of the copyright. */ =20 -#include "qemu/osdep.h" #include "slirp.h" #include "ip_icmp.h" =20 diff --git a/slirp/tcp_output.c b/slirp/tcp_output.c index 6dd1ecf5d9..2b4335eb34 100644 --- a/slirp/tcp_output.c +++ b/slirp/tcp_output.c @@ -38,7 +38,6 @@ * terms and conditions of the copyright. */ =20 -#include "qemu/osdep.h" #include "slirp.h" =20 static const u_char tcp_outflags[TCP_NSTATES] =3D { diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index d8846a33b0..879a7dcd29 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -38,7 +38,6 @@ * terms and conditions of the copyright. */ =20 -#include "qemu/osdep.h" #include "slirp.h" =20 /* patchable/settable parameters for tcp */ diff --git a/slirp/tcp_timer.c b/slirp/tcp_timer.c index a843e57a2b..703907eb37 100644 --- a/slirp/tcp_timer.c +++ b/slirp/tcp_timer.c @@ -30,7 +30,6 @@ * tcp_timer.c,v 1.2 1994/08/02 07:49:10 davidg Exp */ =20 -#include "qemu/osdep.h" #include "slirp.h" =20 static struct tcpcb *tcp_timers(register struct tcpcb *tp, int timer); diff --git a/slirp/tftp.c b/slirp/tftp.c index 5c31886190..2d8f978786 100644 --- a/slirp/tftp.c +++ b/slirp/tftp.c @@ -22,9 +22,11 @@ * THE SOFTWARE. */ =20 -#include "qemu/osdep.h" #include "slirp.h" -#include "qemu-common.h" + +#include +#include +#include =20 static inline int tftp_session_in_use(struct tftp_session *spt) { diff --git a/slirp/udp.c b/slirp/udp.c index 3915971b50..ac42be0d8e 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -38,7 +38,6 @@ * terms and conditions of the copyright. */ =20 -#include "qemu/osdep.h" #include "slirp.h" #include "ip_icmp.h" =20 diff --git a/slirp/udp6.c b/slirp/udp6.c index fa531e03c4..be5cba1f54 100644 --- a/slirp/udp6.c +++ b/slirp/udp6.c @@ -3,8 +3,6 @@ * Guillaume Subiron */ =20 -#include "qemu/osdep.h" -#include "qemu-common.h" #include "slirp.h" #include "udp.h" #include "dhcpv6.h" diff --git a/slirp/util.h b/slirp/util.h index ef75804560..4963747aef 100644 --- a/slirp/util.h +++ b/slirp/util.h @@ -48,6 +48,27 @@ # define SLIRP_PACKED __attribute__((packed)) #endif =20 +#ifndef DIV_ROUND_UP +#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) +#endif + +#ifndef container_of +#define container_of(ptr, type, member) __extension__ ({ \ + void *__mptr =3D (void *)(ptr); \ + ((type *)(__mptr - offsetof(type, member))); }) +#endif + +#if defined(_WIN32) /* CONFIG_IOVEC */ +# if !defined(IOV_MAX) /* XXX: to avoid duplicate with QEMU osdep.h */ +struct iovec { + void *iov_base; + size_t iov_len; +}; +# endif +#else +#include +#endif + #define SCALE_MS 1000000 =20 #define ETH_ALEN 6 --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549549733168980.4563541256307; Thu, 7 Feb 2019 06:28:53 -0800 (PST) Received: from localhost ([127.0.0.1]:40935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkfW-0005bQ-TY for importer@patchew.org; Thu, 07 Feb 2019 09:28:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHi-0002IA-NQ for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHg-0001Bs-1q for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:10 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49870) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHc-0000zI-Gj for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:06 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 5DAFACD1C; Thu, 7 Feb 2019 15:03:43 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IsZcuWyjzFya; Thu, 7 Feb 2019 15:03:40 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id C8B67CD3E; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGs-0004E1-3C; Thu, 07 Feb 2019 15:03:18 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:10 +0200 Message-Id: <20190207140316.16103-27-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 26/32] slirp: prefer c99 types over BSD kind 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Replace: - u_char -> uint8_t - u_short -> uint16_t - u_long -> uint32_t - u_int -> unsigned - caddr_t -> char * Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/ip_icmp.c | 6 +++--- slirp/ip_icmp.h | 18 +++++++++--------- slirp/ip_input.c | 4 ++-- slirp/main.h | 2 +- slirp/mbuf.h | 2 +- slirp/slirp.c | 12 ++++++------ slirp/slirp.h | 8 +++----- slirp/socket.c | 6 +++--- slirp/socket.h | 4 ++-- slirp/tcp_input.c | 22 +++++++++++----------- slirp/tcp_output.c | 12 ++++++------ slirp/tcp_subr.c | 18 +++++++++--------- slirp/tcp_timer.c | 2 +- slirp/tcp_var.h | 14 +++++++------- slirp/udp.c | 6 +++--- slirp/udp.h | 2 +- util/osdep.c | 2 +- 17 files changed, 69 insertions(+), 71 deletions(-) diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index 6b6344b776..7c5cb75ae5 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -240,7 +240,7 @@ end_error: =20 #define ICMP_MAXDATALEN (IP_MSS-28) void -icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int minsize, +icmp_send_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize, const char *message) { unsigned hlen, shlen, s_ip_len; @@ -388,7 +388,7 @@ icmp_reflect(struct mbuf *m) * Strip out original options by copying rest of first * mbuf's data back, and adjust the IP length. */ - memmove((caddr_t)(ip + 1), (caddr_t)ip + hlen, + memmove((char *)(ip + 1), (char *)ip + hlen, (unsigned )(m->m_len - hlen)); hlen -=3D optlen; ip->ip_hl =3D hlen >> 2; @@ -412,7 +412,7 @@ void icmp_receive(struct socket *so) struct mbuf *m =3D so->so_m; struct ip *ip =3D mtod(m, struct ip *); int hlen =3D ip->ip_hl << 2; - u_char error_code; + uint8_t error_code; struct icmp *icp; int id, len; =20 diff --git a/slirp/ip_icmp.h b/slirp/ip_icmp.h index d88ab34c1b..a4e5b8b265 100644 --- a/slirp/ip_icmp.h +++ b/slirp/ip_icmp.h @@ -44,22 +44,22 @@ typedef uint32_t n_time; * Structure of an icmp header. */ struct icmp { - u_char icmp_type; /* type of message, see below */ - u_char icmp_code; /* type sub code */ - u_short icmp_cksum; /* ones complement cksum of struct */ + uint8_t icmp_type; /* type of message, see below */ + uint8_t icmp_code; /* type sub code */ + uint16_t icmp_cksum; /* ones complement cksum of struct */ union { - u_char ih_pptr; /* ICMP_PARAMPROB */ + uint8_t ih_pptr; /* ICMP_PARAMPROB */ struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ struct ih_idseq { - u_short icd_id; - u_short icd_seq; + uint16_t icd_id; + uint16_t icd_seq; } ih_idseq; int ih_void; =20 /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */ struct ih_pmtu { - u_short ipm_void; - u_short ipm_nextmtu; + uint16_t ipm_void; + uint16_t ipm_nextmtu; } ih_pmtu; } icmp_hun; #define icmp_pptr icmp_hun.ih_pptr @@ -156,7 +156,7 @@ struct icmp { void icmp_init(Slirp *slirp); void icmp_cleanup(Slirp *slirp); void icmp_input(struct mbuf *, int); -void icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int mins= ize, +void icmp_send_error(struct mbuf *msrc, uint8_t type, uint8_t code, int mi= nsize, const char *message); void icmp_reflect(struct mbuf *); void icmp_receive(struct socket *so); diff --git a/slirp/ip_input.c b/slirp/ip_input.c index 774ce662e6..e0b94b0e42 100644 --- a/slirp/ip_input.c +++ b/slirp/ip_input.c @@ -458,11 +458,11 @@ ip_stripoptions(register struct mbuf *m, struct mbuf = *mopt) { register int i; struct ip *ip =3D mtod(m, struct ip *); - register caddr_t opts; + register char *opts; int olen; =20 olen =3D (ip->ip_hl<<2) - sizeof (struct ip); - opts =3D (caddr_t)(ip + 1); + opts =3D (char *)(ip + 1); i =3D m->m_len - (sizeof (struct ip) + olen); memcpy(opts, opts + olen, (unsigned)i); m->m_len -=3D olen; diff --git a/slirp/main.h b/slirp/main.h index 4bc05fb904..f11d4572b7 100644 --- a/slirp/main.h +++ b/slirp/main.h @@ -8,7 +8,7 @@ #ifndef SLIRP_MAIN_H #define SLIRP_MAIN_H =20 -extern u_int curtime; +extern unsigned curtime; extern struct in_addr loopback_addr; extern unsigned long loopback_mask; =20 diff --git a/slirp/mbuf.h b/slirp/mbuf.h index cbf17e136b..e2d443418a 100644 --- a/slirp/mbuf.h +++ b/slirp/mbuf.h @@ -85,7 +85,7 @@ struct mbuf { int m_size; /* Size of mbuf, from m_dat or m_ext */ struct socket *m_so; =20 - caddr_t m_data; /* Current location of data */ + char *m_data; /* Current location of data */ int m_len; /* Amount of data in this mbuf, from m_data */ =20 Slirp *slirp; diff --git a/slirp/slirp.c b/slirp/slirp.c index 730b78255c..3304c83001 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -46,7 +46,7 @@ static const uint8_t special_ethaddr[ETH_ALEN] =3D { 0x52, 0x55, 0x00, 0x00, 0x00, 0x00 }; =20 -u_int curtime; +unsigned curtime; =20 static QTAILQ_HEAD(, Slirp) slirp_instances =3D QTAILQ_HEAD_INITIALIZER(slirp_instances); @@ -55,9 +55,9 @@ static struct in_addr dns_addr; #ifndef _WIN32 static struct in6_addr dns6_addr; #endif -static u_int dns_addr_time; +static unsigned dns_addr_time; #ifndef _WIN32 -static u_int dns6_addr_time; +static unsigned dns6_addr_time; #endif =20 #define TIMEOUT_FAST 2 /* milliseconds */ @@ -92,7 +92,7 @@ int get_dns_addr(struct in_addr *pdns_addr) } =20 if ((ret =3D GetNetworkParams(FixedInfo, &BufLen)) !=3D ERROR_SUCCESS)= { - printf("GetNetworkParams failed. ret =3D %08x\n", (u_int)ret ); + printf("GetNetworkParams failed. ret =3D %08x\n", (unsigned)ret ); if (FixedInfo) { GlobalFree(FixedInfo); FixedInfo =3D NULL; @@ -126,7 +126,7 @@ static void winsock_cleanup(void) =20 static int get_dns_addr_cached(void *pdns_addr, void *cached_addr, socklen_t addrlen, - struct stat *cached_stat, u_int *cached_tim= e) + struct stat *cached_stat, unsigned *cached_= time) { struct stat old_stat; if (curtime - *cached_time < TIMEOUT_DEFAULT) { @@ -149,7 +149,7 @@ static int get_dns_addr_cached(void *pdns_addr, void *c= ached_addr, =20 static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_= addr, socklen_t addrlen, uint32_t *scope_id, - u_int *cached_time) + unsigned *cached_time) { char buff[512]; char buff2[257]; diff --git a/slirp/slirp.h b/slirp/slirp.h index 0e4d973c2a..05b8364c07 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -12,8 +12,6 @@ #define WIN32_LEAN_AND_MEAN #endif =20 -typedef char *caddr_t; - # include # include # include @@ -124,8 +122,8 @@ bool ndp_table_search(Slirp *slirp, struct in6_addr ip_= addr, =20 struct Slirp { QTAILQ_ENTRY(Slirp) entry; - u_int time_fasttimo; - u_int last_slowtimo; + unsigned time_fasttimo; + unsigned last_slowtimo; bool do_slowtimo; =20 bool in_enabled, in6_enabled; @@ -245,7 +243,7 @@ int ip6_output(struct socket *, struct mbuf *, int fast= ); =20 /* tcp_input.c */ void tcp_input(register struct mbuf *, int, struct socket *, unsigned shor= t af); -int tcp_mss(register struct tcpcb *, u_int); +int tcp_mss(register struct tcpcb *, unsigned); =20 /* tcp_output.c */ int tcp_output(register struct tcpcb *); diff --git a/slirp/socket.c b/slirp/socket.c index dea201f5ce..c896fa6da3 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -506,7 +506,7 @@ sorecvfrom(struct socket *so) /* XXX Check if reply is "correct"? */ =20 if(len =3D=3D -1 || len =3D=3D 0) { - u_char code=3DICMP_UNREACH_PORT; + uint8_t code=3DICMP_UNREACH_PORT; =20 if(errno =3D=3D EHOSTUNREACH) code=3DICMP_UNREACH_HOST; else if(errno =3D=3D ENETUNREACH) code=3DICMP_UNREACH_NET; @@ -676,8 +676,8 @@ sosendto(struct socket *so, struct mbuf *m) * Listen for incoming TCP connections */ struct socket * -tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr, - u_int lport, int flags) +tcp_listen(Slirp *slirp, uint32_t haddr, unsigned hport, uint32_t laddr, + unsigned lport, int flags) { struct sockaddr_in addr; struct socket *so; diff --git a/slirp/socket.h b/slirp/socket.h index 1c1c8b5871..e4d12cd591 100644 --- a/slirp/socket.h +++ b/slirp/socket.h @@ -61,7 +61,7 @@ struct socket { int32_t so_state; /* internal state flags SS_*, below */ =20 struct tcpcb *so_tcpcb; /* pointer to TCP protocol control block */ - u_int so_expire; /* When the socket will expire */ + unsigned so_expire; /* When the socket will expire */ =20 int so_queued; /* Number of packets queued from this socket */ int so_nqueued; /* Number of packets queued in a row @@ -144,7 +144,7 @@ int sosendoob(struct socket *); int sowrite(struct socket *); void sorecvfrom(struct socket *); int sosendto(struct socket *, struct mbuf *); -struct socket * tcp_listen(Slirp *, uint32_t, u_int, uint32_t, u_int, +struct socket * tcp_listen(Slirp *, uint32_t, unsigned, uint32_t, unsigned, int); void soisfconnecting(register struct socket *); void soisfconnected(register struct socket *); diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c index 864da7d857..6749b32f5d 100644 --- a/slirp/tcp_input.c +++ b/slirp/tcp_input.c @@ -76,7 +76,7 @@ } \ } =20 -static void tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, +static void tcp_dooptions(struct tcpcb *tp, uint8_t *cp, int cnt, struct tcpiphdr *ti); static void tcp_xmit_timer(register struct tcpcb *tp, int rtt); =20 @@ -197,7 +197,7 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *in= so, unsigned short af) struct ip save_ip, *ip; struct ip6 save_ip6, *ip6; register struct tcpiphdr *ti; - caddr_t optp =3D NULL; + char *optp =3D NULL; int optlen =3D 0; int len, tlen, off; register struct tcpcb *tp =3D NULL; @@ -205,7 +205,7 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *in= so, unsigned short af) struct socket *so =3D NULL; int todrop, acked, ourfinisacked, needoutput =3D 0; int iss =3D 0; - u_long tiwin; + uint32_t tiwin; int ret; struct sockaddr_storage lhost, fhost; struct sockaddr_in *lhost4, *fhost4; @@ -327,7 +327,7 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *in= so, unsigned short af) ti->ti_len =3D tlen; if (off > sizeof (struct tcphdr)) { optlen =3D off - sizeof (struct tcphdr); - optp =3D mtod(m, caddr_t) + sizeof (struct tcpiphdr); + optp =3D mtod(m, char *) + sizeof (struct tcpiphdr); } tiflags =3D ti->ti_flags; =20 @@ -469,7 +469,7 @@ findso: * else do it below (after getting remote address). */ if (optp && tp->t_state !=3D TCPS_LISTEN) - tcp_dooptions(tp, (u_char *)optp, optlen, ti); + tcp_dooptions(tp, (uint8_t *)optp, optlen, ti); =20 /* * Header prediction: check for the two common cases @@ -724,7 +724,7 @@ findso: tcp_template(tp); =20 if (optp) - tcp_dooptions(tp, (u_char *)optp, optlen, ti); + tcp_dooptions(tp, (uint8_t *)optp, optlen, ti); =20 if (iss) tp->iss =3D iss; @@ -1039,7 +1039,7 @@ trimthenstep6: tp->t_dupacks =3D 0; else if (++tp->t_dupacks =3D=3D TCPREXMTTHRESH) { tcp_seq onxt =3D tp->snd_nxt; - u_int win =3D + unsigned win =3D MIN(tp->snd_wnd, tp->snd_c= wnd) / 2 / tp->t_maxseg; =20 @@ -1108,8 +1108,8 @@ trimthenstep6: * (maxseg^2 / cwnd per packet). */ { - register u_int cw =3D tp->snd_cwnd; - register u_int incr =3D tp->t_maxseg; + register unsigned cw =3D tp->snd_cwnd; + register unsigned incr =3D tp->t_maxseg; =20 if (cw > tp->snd_ssthresh) incr =3D incr * incr / cw; @@ -1381,7 +1381,7 @@ drop: } =20 static void -tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti) +tcp_dooptions(struct tcpcb *tp, uint8_t *cp, int cnt, struct tcpiphdr *ti) { uint16_t mss; int opt, optlen; @@ -1511,7 +1511,7 @@ tcp_xmit_timer(register struct tcpcb *tp, int rtt) */ =20 int -tcp_mss(struct tcpcb *tp, u_int offer) +tcp_mss(struct tcpcb *tp, unsigned offer) { struct socket *so =3D tp->t_socket; int mss; diff --git a/slirp/tcp_output.c b/slirp/tcp_output.c index 2b4335eb34..e9674df121 100644 --- a/slirp/tcp_output.c +++ b/slirp/tcp_output.c @@ -40,7 +40,7 @@ =20 #include "slirp.h" =20 -static const u_char tcp_outflags[TCP_NSTATES] =3D { +static const uint8_t tcp_outflags[TCP_NSTATES] =3D { TH_RST|TH_ACK, 0, TH_SYN, TH_SYN|TH_ACK, TH_ACK, TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_ACK, TH_ACK, @@ -63,7 +63,7 @@ tcp_output(struct tcpcb *tp) register struct tcpiphdr *ti, tcpiph_save; struct ip *ip; struct ip6 *ip6; - u_char opt[MAX_TCPOPTLEN]; + uint8_t opt[MAX_TCPOPTLEN]; unsigned optlen, hdrlen; int idle, sendalot; =20 @@ -271,7 +271,7 @@ send: opt[0] =3D TCPOPT_MAXSEG; opt[1] =3D 4; mss =3D htons((uint16_t) tcp_mss(tp, 0)); - memcpy((caddr_t)(opt + 2), (caddr_t)&mss, sizeof(mss)); + memcpy((char *)(opt + 2), (char *)&mss, sizeof(mss)); optlen =3D 4; } } @@ -301,7 +301,7 @@ send: m->m_data +=3D IF_MAXLINKHDR; m->m_len =3D hdrlen; =20 - sbcopy(&so->so_snd, off, (int) len, mtod(m, caddr_t) + hdrlen); + sbcopy(&so->so_snd, off, (int) len, mtod(m, char *) + hdrlen); m->m_len +=3D len; =20 /* @@ -324,7 +324,7 @@ send: =20 ti =3D mtod(m, struct tcpiphdr *); =20 - memcpy((caddr_t)ti, &tp->t_template, sizeof (struct tcpiphdr)); + memcpy((char *)ti, &tp->t_template, sizeof (struct tcpiphdr)); =20 /* * Fill in fields, remembering maximum advertised @@ -353,7 +353,7 @@ send: ti->ti_seq =3D htonl(tp->snd_max); ti->ti_ack =3D htonl(tp->rcv_nxt); if (optlen) { - memcpy((caddr_t)(ti + 1), (caddr_t)opt, optlen); + memcpy((char *)(ti + 1), (char *)opt, optlen); ti->ti_off =3D (sizeof (struct tcphdr) + optlen) >> 2; } ti->ti_flags =3D flags; diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 879a7dcd29..e35628a892 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -163,7 +163,7 @@ tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, stru= ct mbuf *m, * ti points into m so the next line is just making * the mbuf point to ti */ - m->m_data =3D (caddr_t)ti; + m->m_data =3D (char *)ti; =20 m->m_len =3D sizeof (struct tcpiphdr); tlen =3D 0; @@ -182,7 +182,7 @@ tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, stru= ct mbuf *m, } #undef xchg } - ti->ti_len =3D htons((u_short)(sizeof (struct tcphdr) + tlen)); + ti->ti_len =3D htons((uint16_t)(sizeof (struct tcphdr) + tlen)); tlen +=3D sizeof (struct tcpiphdr); m->m_len =3D tlen; =20 @@ -613,10 +613,10 @@ int tcp_emu(struct socket *so, struct mbuf *m) { Slirp *slirp =3D so->slirp; - u_int n1, n2, n3, n4, n5, n6; + unsigned n1, n2, n3, n4, n5, n6; char buff[257]; uint32_t laddr; - u_int lport; + unsigned lport; char *bptr; =20 DEBUG_CALL("tcp_emu"); @@ -853,7 +853,7 @@ tcp_emu(struct socket *so, struct mbuf *m) =20 bptr =3D m->m_data; while (bptr < m->m_data + m->m_len) { - u_short p; + uint16_t p; static int ra =3D 0; char ra_tbl[4]; =20 @@ -909,8 +909,8 @@ tcp_emu(struct socket *so, struct mbuf *m) /* This is the field containing the port * number that RA-player is listening to. */ - lport =3D (((u_char*)bptr)[0] << 8) - + ((u_char *)bptr)[1]; + lport =3D (((uint8_t*)bptr)[0] << 8) + + ((uint8_t *)bptr)[1]; if (lport < 6970) lport +=3D 256; /* don't know why */ if (lport < 6970 || lport > 7170) @@ -928,8 +928,8 @@ tcp_emu(struct socket *so, struct mbuf *m) } if (p =3D=3D 7071) p =3D 0; - *(u_char *)bptr++ =3D (p >> 8) & 0xff; - *(u_char *)bptr =3D p & 0xff; + *(uint8_t *)bptr++ =3D (p >> 8) & 0xff; + *(uint8_t *)bptr =3D p & 0xff; ra =3D 0; return 1; /* port redirected, we're done */ break; diff --git a/slirp/tcp_timer.c b/slirp/tcp_timer.c index 703907eb37..7be54570af 100644 --- a/slirp/tcp_timer.c +++ b/slirp/tcp_timer.c @@ -232,7 +232,7 @@ tcp_timers(register struct tcpcb *tp, int timer) * to go below this.) */ { - u_int win =3D MIN(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_m= axseg; + unsigned win =3D MIN(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->= t_maxseg; if (win < 2) win =3D 2; tp->snd_cwnd =3D tp->t_maxseg; diff --git a/slirp/tcp_var.h b/slirp/tcp_var.h index 895ef6df1e..27ef1a51cb 100644 --- a/slirp/tcp_var.h +++ b/slirp/tcp_var.h @@ -47,9 +47,9 @@ struct tcpcb { short t_rxtshift; /* log(2) of rexmt exp. backoff */ short t_rxtcur; /* current retransmit value */ short t_dupacks; /* consecutive dup acks recd */ - u_short t_maxseg; /* maximum segment size */ + uint16_t t_maxseg; /* maximum segment size */ uint8_t t_force; /* 1 if forcing out a byte */ - u_short t_flags; + uint16_t t_flags; #define TF_ACKNOW 0x0001 /* ack peer immediately */ #define TF_DELACK 0x0002 /* ack, but try to delay it */ #define TF_NODELAY 0x0004 /* don't delay packets to coalesce */ @@ -105,7 +105,7 @@ struct tcpcb { tcp_seq t_rtseq; /* sequence number being timed */ short t_srtt; /* smoothed round-trip time */ short t_rttvar; /* variance in round-trip time */ - u_short t_rttmin; /* minimum rtt allowed */ + uint16_t t_rttmin; /* minimum rtt allowed */ uint32_t max_sndwnd; /* largest window peer has offered */ =20 /* out-of-band data */ @@ -116,10 +116,10 @@ struct tcpcb { short t_softerror; /* possible error not yet reported */ =20 /* RFC 1323 variables */ - u_char snd_scale; /* window scaling for send window */ - u_char rcv_scale; /* window scaling for recv window */ - u_char request_r_scale; /* pending window scaling */ - u_char requested_s_scale; + uint8_t snd_scale; /* window scaling for send window */ + uint8_t rcv_scale; /* window scaling for recv window */ + uint8_t request_r_scale; /* pending window scaling */ + uint8_t requested_s_scale; uint32_t ts_recent; /* timestamp echo data */ uint32_t ts_recent_age; /* when last updated */ tcp_seq last_ack_sent; diff --git a/slirp/udp.c b/slirp/udp.c index ac42be0d8e..5baa604b33 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -92,7 +92,7 @@ udp_input(register struct mbuf *m, int iphlen) * Get IP and UDP header together in first mbuf. */ ip =3D mtod(m, struct ip *); - uh =3D (struct udphdr *)((caddr_t)ip + iphlen); + uh =3D (struct udphdr *)((char *)ip + iphlen); =20 /* * Make mbuf data length reflect UDP length. @@ -319,8 +319,8 @@ udp_tos(struct socket *so) } =20 struct socket * -udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr, - u_int lport, int flags) +udp_listen(Slirp *slirp, uint32_t haddr, unsigned hport, uint32_t laddr, + unsigned lport, int flags) { struct sockaddr_in addr; struct socket *so; diff --git a/slirp/udp.h b/slirp/udp.h index be657cf922..3d29504caa 100644 --- a/slirp/udp.h +++ b/slirp/udp.h @@ -78,7 +78,7 @@ void udp_cleanup(Slirp *); void udp_input(register struct mbuf *, int); int udp_attach(struct socket *, unsigned short af); void udp_detach(struct socket *); -struct socket * udp_listen(Slirp *, uint32_t, u_int, uint32_t, u_int, +struct socket * udp_listen(Slirp *, uint32_t, unsigned, uint32_t, unsigned, int); int udp_output(struct socket *so, struct mbuf *m, struct sockaddr_in *saddr, struct sockaddr_in *daddr, diff --git a/util/osdep.c b/util/osdep.c index 4b5dc7287d..3f04326040 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -29,7 +29,7 @@ #include /* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=3D7156) for discussion about Solaris header problems */ -extern int madvise(caddr_t, size_t, int); +extern int madvise(char *, size_t, int); #endif =20 #include "qemu-common.h" --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549550075156704.1345813198982; Thu, 7 Feb 2019 06:34:35 -0800 (PST) Received: from localhost ([127.0.0.1]:41055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkl2-0001vx-2x for importer@patchew.org; Thu, 07 Feb 2019 09:34:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHi-0002I7-Mf for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHg-0001Bx-1z for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:10 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41908) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHc-0000z1-JL for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:06 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id BEAF8C8A7; Thu, 7 Feb 2019 15:03:40 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rkTPcij5ey7G; Thu, 7 Feb 2019 15:03:38 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id BB49ECD3C; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGs-0004E4-4L; Thu, 07 Feb 2019 15:03:18 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:11 +0200 Message-Id: <20190207140316.16103-28-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 27/32] slirp: improve send_packet() callback 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Use a more descriptive name for the callback. Reuse the SlirpWriteCb type. Wrap it to check that all data has been writte= n. Return a ssize_t for potential error handling and data-loss reporting. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- include/net/net.h | 2 +- net/net.c | 4 ++-- net/slirp.c | 9 +++++---- slirp/libslirp.h | 11 +++++++---- slirp/ncsi.c | 2 +- slirp/slirp.c | 18 +++++++++++++++--- slirp/slirp.h | 2 ++ 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 643295d163..075cc01267 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -146,7 +146,7 @@ ssize_t qemu_sendv_packet(NetClientState *nc, const str= uct iovec *iov, int iovcnt); ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *io= v, int iovcnt, NetPacketSent *sent_cb); -void qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size); +ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size); ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int s= ize); ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf, int size, NetPacketSent *sent_cb); diff --git a/net/net.c b/net/net.c index 3acbdccd61..5dcff7fe2a 100644 --- a/net/net.c +++ b/net/net.c @@ -668,9 +668,9 @@ ssize_t qemu_send_packet_async(NetClientState *sender, buf, size, sent_cb); } =20 -void qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size) +ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size) { - qemu_send_packet_async(nc, buf, size, NULL); + return qemu_send_packet_async(nc, buf, size, NULL); } =20 ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int s= ize) diff --git a/net/slirp.c b/net/slirp.c index 7b4f9f5c5e..664ff1c002 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -108,11 +108,12 @@ static void slirp_smb_cleanup(SlirpState *s); static inline void slirp_smb_cleanup(SlirpState *s) { } #endif =20 -static void net_slirp_output(void *opaque, const uint8_t *pkt, int pkt_len) +static ssize_t net_slirp_send_packet(const void *pkt, size_t pkt_len, + void *opaque) { SlirpState *s =3D opaque; =20 - qemu_send_packet(&s->nc, pkt, pkt_len); + return qemu_send_packet(&s->nc, pkt, pkt_len); } =20 static ssize_t net_slirp_receive(NetClientState *nc, const uint8_t *buf, s= ize_t size) @@ -197,7 +198,7 @@ static void net_slirp_unregister_poll_fd(int fd) } =20 static const SlirpCb slirp_cb =3D { - .output =3D net_slirp_output, + .send_packet =3D net_slirp_send_packet, .guest_error =3D net_slirp_guest_error, .clock_get_ns =3D net_slirp_clock_get_ns, .timer_new =3D net_slirp_timer_new, @@ -780,7 +781,7 @@ static void guestfwd_read(void *opaque, const uint8_t *= buf, int size) slirp_socket_recv(fwd->slirp, fwd->server, fwd->port, buf, size); } =20 -static int guestfwd_write(const void *buf, size_t len, void *chr) +static ssize_t guestfwd_write(const void *buf, size_t len, void *chr) { return qemu_chr_fe_write_all(chr, buf, len); } diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 02cbec9f8b..8e5d4ed11b 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -15,7 +15,7 @@ =20 typedef struct Slirp Slirp; =20 -typedef int (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); +typedef ssize_t (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); typedef void (*SlirpTimerCb)(void *opaque); =20 /* @@ -23,10 +23,13 @@ typedef void (*SlirpTimerCb)(void *opaque); */ typedef struct SlirpCb { /* - * Send an ethernet frame to the guest network. The opaque parameter - * is the one given to slirp_init(). + * Send an ethernet frame to the guest network. The opaque + * parameter is the one given to slirp_init(). The function + * doesn't need to send all the data and may return cb->output(slirp->opaque, ncsi_reply, ETH_HLEN + ncsi_rsp_len); + slirp_send_packet_all(slirp, ncsi_reply, ETH_HLEN + ncsi_rsp_len); } diff --git a/slirp/slirp.c b/slirp/slirp.c index 3304c83001..2bc53e3e12 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -800,7 +800,7 @@ static void arp_input(Slirp *slirp, const uint8_t *pkt,= int pkt_len) rah->ar_sip =3D ah->ar_tip; memcpy(rah->ar_tha, ah->ar_sha, ETH_ALEN); rah->ar_tip =3D ah->ar_sip; - slirp->cb->output(slirp->opaque, arp_reply, sizeof(arp_reply)); + slirp_send_packet_all(slirp, arp_reply, sizeof(arp_reply)); } break; case ARPOP_REPLY: @@ -900,7 +900,7 @@ static int if_encap4(Slirp *slirp, struct mbuf *ifm, st= ruct ethhdr *eh, /* target IP */ rah->ar_tip =3D iph->ip_dst.s_addr; slirp->client_ipaddr =3D iph->ip_dst; - slirp->cb->output(slirp->opaque, arp_req, sizeof(arp_req)); + slirp_send_packet_all(slirp, arp_req, sizeof(arp_req)); ifm->resolution_requested =3D true; =20 /* Expire request and drop outgoing packet after 1 second */ @@ -985,7 +985,7 @@ int if_encap(Slirp *slirp, struct mbuf *ifm) eh->h_dest[0], eh->h_dest[1], eh->h_dest[2], eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]); memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len); - slirp->cb->output(slirp->opaque, buf, ifm->m_len + ETH_HLEN); + slirp_send_packet_all(slirp, buf, ifm->m_len + ETH_HLEN); return 1; } =20 @@ -1152,3 +1152,15 @@ void slirp_socket_recv(Slirp *slirp, struct in_addr = guest_addr, int guest_port, if (ret > 0) tcp_output(sototcpcb(so)); } + +void slirp_send_packet_all(Slirp *slirp, const void *buf, size_t len) +{ + ssize_t ret =3D slirp->cb->send_packet(buf, len, slirp->opaque); + + if (ret < 0) { + g_critical("Failed to send packet, ret: %ld", (long) ret); + } else if (ret < len) { + DEBUG_ERROR("send_packet() didn't send all data: %ld < %lu", + (long) ret, (unsigned long) len); + } +} diff --git a/slirp/slirp.h b/slirp/slirp.h index 05b8364c07..752a4cd8c8 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -269,4 +269,6 @@ struct tcpcb *tcp_drop(struct tcpcb *tp, int err); struct socket * slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, int guest_p= ort); =20 +void slirp_send_packet_all(Slirp *slirp, const void *buf, size_t len); + #endif --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549550213847930.6181904932909; Thu, 7 Feb 2019 06:36:53 -0800 (PST) Received: from localhost ([127.0.0.1]:41130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grknF-0003c8-MW for importer@patchew.org; Thu, 07 Feb 2019 09:36:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHo-0002PJ-KE for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHg-0001CV-JT for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:12 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49868) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHe-0000ys-KH for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:08 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 52FAECD37; Thu, 7 Feb 2019 15:03:42 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Y2eHLCKPiQOE; Thu, 7 Feb 2019 15:03:39 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id BFA88CD3D; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGs-0004E6-5Q; Thu, 07 Feb 2019 15:03:18 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:12 +0200 Message-Id: <20190207140316.16103-29-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 28/32] slirp: replace global polling with per-instance & notifier 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Remove hard-coded dependency on slirp in main-loop, and use a "poll" notifier instead. The notifier is registered per slirp instance. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- include/qemu/main-loop.h | 15 ++ net/slirp.c | 24 ++ slirp/libslirp.h | 4 +- slirp/slirp.c | 555 +++++++++++++++++++-------------------- stubs/Makefile.objs | 1 - stubs/slirp.c | 13 - util/main-loop.c | 30 ++- 7 files changed, 333 insertions(+), 309 deletions(-) delete mode 100644 stubs/slirp.c diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index e59f9ae1e9..f6ba78ea73 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -302,4 +302,19 @@ void qemu_fd_register(int fd); QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque); void qemu_bh_schedule_idle(QEMUBH *bh); =20 +enum { + MAIN_LOOP_POLL_FILL, + MAIN_LOOP_POLL_ERR, + MAIN_LOOP_POLL_OK, +}; + +typedef struct MainLoopPoll { + int state; + uint32_t timeout; + GArray *pollfds; +} MainLoopPoll; + +void main_loop_poll_add_notifier(Notifier *notify); +void main_loop_poll_remove_notifier(Notifier *notify); + #endif diff --git a/net/slirp.c b/net/slirp.c index 664ff1c002..4d55f64168 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -86,6 +86,7 @@ typedef struct SlirpState { NetClientState nc; QTAILQ_ENTRY(SlirpState) entry; Slirp *slirp; + Notifier poll_notifier; Notifier exit_notifier; #ifndef _WIN32 gchar *smb_dir; @@ -144,6 +145,7 @@ static void net_slirp_cleanup(NetClientState *nc) SlirpState *s =3D DO_UPCAST(SlirpState, nc, nc); =20 g_slist_free_full(s->fwd, slirp_free_fwd); + main_loop_poll_remove_notifier(&s->poll_notifier); slirp_cleanup(s->slirp); if (s->exit_notifier.notify) { qemu_remove_exit_notifier(&s->exit_notifier); @@ -209,6 +211,25 @@ static const SlirpCb slirp_cb =3D { .notify =3D qemu_notify_event, }; =20 +static void net_slirp_poll_notify(Notifier *notifier, void *data) +{ + MainLoopPoll *poll =3D data; + SlirpState *s =3D container_of(notifier, SlirpState, poll_notifier); + + switch (poll->state) { + case MAIN_LOOP_POLL_FILL: + slirp_pollfds_fill(s->slirp, poll->pollfds, &poll->timeout); + break; + case MAIN_LOOP_POLL_OK: + case MAIN_LOOP_POLL_ERR: + slirp_pollfds_poll(s->slirp, poll->pollfds, + poll->state =3D=3D MAIN_LOOP_POLL_ERR); + break; + default: + g_assert_not_reached(); + } +} + static int net_slirp_init(NetClientState *peer, const char *model, const char *name, int restricted, bool ipv4, const char *vnetwork, const char *vho= st, @@ -429,6 +450,9 @@ static int net_slirp_init(NetClientState *peer, const c= har *model, &slirp_cb, s); QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry); =20 + s->poll_notifier.notify =3D net_slirp_poll_notify; + main_loop_poll_add_notifier(&s->poll_notifier); + for (config =3D slirp_configs; config; config =3D config->next) { if (config->flags & SLIRP_CFG_HOSTFWD) { if (slirp_hostfwd(s, config->str, errp) < 0) { diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 8e5d4ed11b..18d5fb0133 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -63,9 +63,9 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct= in_addr vnetwork, void *opaque); void slirp_cleanup(Slirp *slirp); =20 -void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout); +void slirp_pollfds_fill(Slirp *slirp, GArray *pollfds, uint32_t *timeout); =20 -void slirp_pollfds_poll(GArray *pollfds, int select_error); +void slirp_pollfds_poll(Slirp *slirp, GArray *pollfds, int select_error); =20 void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len); =20 diff --git a/slirp/slirp.c b/slirp/slirp.c index 2bc53e3e12..3a8d1bc459 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -368,9 +368,8 @@ void slirp_cleanup(Slirp *slirp) #define CONN_CANFSEND(so) (((so)->so_state & (SS_FCANTSENDMORE|SS_ISFCONNE= CTED)) =3D=3D SS_ISFCONNECTED) #define CONN_CANFRCV(so) (((so)->so_state & (SS_FCANTRCVMORE|SS_ISFCONNECT= ED)) =3D=3D SS_ISFCONNECTED) =20 -static void slirp_update_timeout(uint32_t *timeout) +static void slirp_update_timeout(Slirp *slirp, uint32_t *timeout) { - Slirp *slirp; uint32_t t; =20 if (*timeout <=3D TIMEOUT_FAST) { @@ -382,370 +381,352 @@ static void slirp_update_timeout(uint32_t *timeout) /* If we have tcp timeout with slirp, then we will fill @timeout with * more precise value. */ - QTAILQ_FOREACH(slirp, &slirp_instances, entry) { - if (slirp->time_fasttimo) { - *timeout =3D TIMEOUT_FAST; - return; - } - if (slirp->do_slowtimo) { - t =3D MIN(TIMEOUT_SLOW, t); - } + if (slirp->time_fasttimo) { + *timeout =3D TIMEOUT_FAST; + return; + } + if (slirp->do_slowtimo) { + t =3D MIN(TIMEOUT_SLOW, t); } *timeout =3D t; } =20 -void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout) +void slirp_pollfds_fill(Slirp *slirp, GArray *pollfds, uint32_t *timeout) { - Slirp *slirp; struct socket *so, *so_next; =20 - if (QTAILQ_EMPTY(&slirp_instances)) { - return; - } - /* * First, TCP sockets */ =20 - QTAILQ_FOREACH(slirp, &slirp_instances, entry) { - /* - * *_slowtimo needs calling if there are IP fragments - * in the fragment queue, or there are TCP connections active - */ - slirp->do_slowtimo =3D ((slirp->tcb.so_next !=3D &slirp->tcb) || - (&slirp->ipq.ip_link !=3D slirp->ipq.ip_link.next)); - - for (so =3D slirp->tcb.so_next; so !=3D &slirp->tcb; - so =3D so_next) { - int events =3D 0; - - so_next =3D so->so_next; + /* + * *_slowtimo needs calling if there are IP fragments + * in the fragment queue, or there are TCP connections active + */ + slirp->do_slowtimo =3D ((slirp->tcb.so_next !=3D &slirp->tcb) || + (&slirp->ipq.ip_link !=3D slirp->ipq.ip_link.nex= t)); =20 - so->pollfds_idx =3D -1; + for (so =3D slirp->tcb.so_next; so !=3D &slirp->tcb; so =3D so_next) { + int events =3D 0; =20 - /* - * See if we need a tcp_fasttimo - */ - if (slirp->time_fasttimo =3D=3D 0 && - so->so_tcpcb->t_flags & TF_DELACK) { - slirp->time_fasttimo =3D curtime; /* Flag when want a fast= timo */ - } + so_next =3D so->so_next; =20 - /* - * NOFDREF can include still connecting to local-host, - * newly socreated() sockets etc. Don't want to select these. - */ - if (so->so_state & SS_NOFDREF || so->s =3D=3D -1) { - continue; - } + so->pollfds_idx =3D -1; =20 - /* - * Set for reading sockets which are accepting - */ - if (so->so_state & SS_FACCEPTCONN) { - GPollFD pfd =3D { - .fd =3D so->s, - .events =3D G_IO_IN | G_IO_HUP | G_IO_ERR, - }; - so->pollfds_idx =3D pollfds->len; - g_array_append_val(pollfds, pfd); - continue; - } + /* + * See if we need a tcp_fasttimo + */ + if (slirp->time_fasttimo =3D=3D 0 && + so->so_tcpcb->t_flags & TF_DELACK) { + slirp->time_fasttimo =3D curtime; /* Flag when want a fasttimo= */ + } =20 - /* - * Set for writing sockets which are connecting - */ - if (so->so_state & SS_ISFCONNECTING) { - GPollFD pfd =3D { - .fd =3D so->s, - .events =3D G_IO_OUT | G_IO_ERR, - }; - so->pollfds_idx =3D pollfds->len; - g_array_append_val(pollfds, pfd); - continue; - } + /* + * NOFDREF can include still connecting to local-host, + * newly socreated() sockets etc. Don't want to select these. + */ + if (so->so_state & SS_NOFDREF || so->s =3D=3D -1) { + continue; + } =20 - /* - * Set for writing if we are connected, can send more, and - * we have something to send - */ - if (CONN_CANFSEND(so) && so->so_rcv.sb_cc) { - events |=3D G_IO_OUT | G_IO_ERR; - } + /* + * Set for reading sockets which are accepting + */ + if (so->so_state & SS_FACCEPTCONN) { + GPollFD pfd =3D { + .fd =3D so->s, + .events =3D G_IO_IN | G_IO_HUP | G_IO_ERR, + }; + so->pollfds_idx =3D pollfds->len; + g_array_append_val(pollfds, pfd); + continue; + } =20 - /* - * Set for reading (and urgent data) if we are connected, can - * receive more, and we have room for it XXX /2 ? - */ - if (CONN_CANFRCV(so) && - (so->so_snd.sb_cc < (so->so_snd.sb_datalen/2))) { - events |=3D G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI; - } + /* + * Set for writing sockets which are connecting + */ + if (so->so_state & SS_ISFCONNECTING) { + GPollFD pfd =3D { + .fd =3D so->s, + .events =3D G_IO_OUT | G_IO_ERR, + }; + so->pollfds_idx =3D pollfds->len; + g_array_append_val(pollfds, pfd); + continue; + } =20 - if (events) { - GPollFD pfd =3D { - .fd =3D so->s, - .events =3D events, - }; - so->pollfds_idx =3D pollfds->len; - g_array_append_val(pollfds, pfd); - } + /* + * Set for writing if we are connected, can send more, and + * we have something to send + */ + if (CONN_CANFSEND(so) && so->so_rcv.sb_cc) { + events |=3D G_IO_OUT | G_IO_ERR; } =20 /* - * UDP sockets + * Set for reading (and urgent data) if we are connected, can + * receive more, and we have room for it XXX /2 ? */ - for (so =3D slirp->udb.so_next; so !=3D &slirp->udb; - so =3D so_next) { - so_next =3D so->so_next; + if (CONN_CANFRCV(so) && + (so->so_snd.sb_cc < (so->so_snd.sb_datalen/2))) { + events |=3D G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI; + } =20 - so->pollfds_idx =3D -1; + if (events) { + GPollFD pfd =3D { + .fd =3D so->s, + .events =3D events, + }; + so->pollfds_idx =3D pollfds->len; + g_array_append_val(pollfds, pfd); + } + } =20 - /* - * See if it's timed out - */ - if (so->so_expire) { - if (so->so_expire <=3D curtime) { - udp_detach(so); - continue; - } else { - slirp->do_slowtimo =3D true; /* Let socket expire */ - } - } + /* + * UDP sockets + */ + for (so =3D slirp->udb.so_next; so !=3D &slirp->udb; so =3D so_next) { + so_next =3D so->so_next; =20 - /* - * When UDP packets are received from over the - * link, they're sendto()'d straight away, so - * no need for setting for writing - * Limit the number of packets queued by this session - * to 4. Note that even though we try and limit this - * to 4 packets, the session could have more queued - * if the packets needed to be fragmented - * (XXX <=3D 4 ?) - */ - if ((so->so_state & SS_ISFCONNECTED) && so->so_queued <=3D 4) { - GPollFD pfd =3D { - .fd =3D so->s, - .events =3D G_IO_IN | G_IO_HUP | G_IO_ERR, - }; - so->pollfds_idx =3D pollfds->len; - g_array_append_val(pollfds, pfd); + so->pollfds_idx =3D -1; + + /* + * See if it's timed out + */ + if (so->so_expire) { + if (so->so_expire <=3D curtime) { + udp_detach(so); + continue; + } else { + slirp->do_slowtimo =3D true; /* Let socket expire */ } } =20 /* - * ICMP sockets + * When UDP packets are received from over the + * link, they're sendto()'d straight away, so + * no need for setting for writing + * Limit the number of packets queued by this session + * to 4. Note that even though we try and limit this + * to 4 packets, the session could have more queued + * if the packets needed to be fragmented + * (XXX <=3D 4 ?) */ - for (so =3D slirp->icmp.so_next; so !=3D &slirp->icmp; - so =3D so_next) { - so_next =3D so->so_next; + if ((so->so_state & SS_ISFCONNECTED) && so->so_queued <=3D 4) { + GPollFD pfd =3D { + .fd =3D so->s, + .events =3D G_IO_IN | G_IO_HUP | G_IO_ERR, + }; + so->pollfds_idx =3D pollfds->len; + g_array_append_val(pollfds, pfd); + } + } =20 - so->pollfds_idx =3D -1; + /* + * ICMP sockets + */ + for (so =3D slirp->icmp.so_next; so !=3D &slirp->icmp; so =3D so_next)= { + so_next =3D so->so_next; =20 - /* - * See if it's timed out - */ - if (so->so_expire) { - if (so->so_expire <=3D curtime) { - icmp_detach(so); - continue; - } else { - slirp->do_slowtimo =3D true; /* Let socket expire */ - } - } + so->pollfds_idx =3D -1; =20 - if (so->so_state & SS_ISFCONNECTED) { - GPollFD pfd =3D { - .fd =3D so->s, - .events =3D G_IO_IN | G_IO_HUP | G_IO_ERR, - }; - so->pollfds_idx =3D pollfds->len; - g_array_append_val(pollfds, pfd); + /* + * See if it's timed out + */ + if (so->so_expire) { + if (so->so_expire <=3D curtime) { + icmp_detach(so); + continue; + } else { + slirp->do_slowtimo =3D true; /* Let socket expire */ } } + + if (so->so_state & SS_ISFCONNECTED) { + GPollFD pfd =3D { + .fd =3D so->s, + .events =3D G_IO_IN | G_IO_HUP | G_IO_ERR, + }; + so->pollfds_idx =3D pollfds->len; + g_array_append_val(pollfds, pfd); + } } - slirp_update_timeout(timeout); + + slirp_update_timeout(slirp, timeout); } =20 -void slirp_pollfds_poll(GArray *pollfds, int select_error) +void slirp_pollfds_poll(Slirp *slirp, GArray *pollfds, int select_error) { - Slirp *slirp =3D QTAILQ_FIRST(&slirp_instances); struct socket *so, *so_next; int ret; =20 - if (!slirp) { - return; - } - curtime =3D slirp->cb->clock_get_ns() / SCALE_MS; =20 - QTAILQ_FOREACH(slirp, &slirp_instances, entry) { - /* - * See if anything has timed out - */ - if (slirp->time_fasttimo && - ((curtime - slirp->time_fasttimo) >=3D TIMEOUT_FAST)) { - tcp_fasttimo(slirp); - slirp->time_fasttimo =3D 0; - } - if (slirp->do_slowtimo && - ((curtime - slirp->last_slowtimo) >=3D TIMEOUT_SLOW)) { - ip_slowtimo(slirp); - tcp_slowtimo(slirp); - slirp->last_slowtimo =3D curtime; - } + /* + * See if anything has timed out + */ + if (slirp->time_fasttimo && + ((curtime - slirp->time_fasttimo) >=3D TIMEOUT_FAST)) { + tcp_fasttimo(slirp); + slirp->time_fasttimo =3D 0; + } + if (slirp->do_slowtimo && + ((curtime - slirp->last_slowtimo) >=3D TIMEOUT_SLOW)) { + ip_slowtimo(slirp); + tcp_slowtimo(slirp); + slirp->last_slowtimo =3D curtime; + } =20 + /* + * Check sockets + */ + if (!select_error) { /* - * Check sockets + * Check TCP sockets */ - if (!select_error) { - /* - * Check TCP sockets - */ - for (so =3D slirp->tcb.so_next; so !=3D &slirp->tcb; - so =3D so_next) { - int revents; + for (so =3D slirp->tcb.so_next; so !=3D &slirp->tcb; + so =3D so_next) { + int revents; =20 - so_next =3D so->so_next; + so_next =3D so->so_next; =20 - revents =3D 0; - if (so->pollfds_idx !=3D -1) { - revents =3D g_array_index(pollfds, GPollFD, - so->pollfds_idx).revents; - } + revents =3D 0; + if (so->pollfds_idx !=3D -1) { + revents =3D g_array_index(pollfds, GPollFD, + so->pollfds_idx).revents; + } =20 - if (so->so_state & SS_NOFDREF || so->s =3D=3D -1) { + if (so->so_state & SS_NOFDREF || so->s =3D=3D -1) { + continue; + } + + /* + * Check for URG data + * This will soread as well, so no need to + * test for G_IO_IN below if this succeeds + */ + if (revents & G_IO_PRI) { + ret =3D sorecvoob(so); + if (ret < 0) { + /* Socket error might have resulted in the socket being + * removed, do not try to do anything more with it. */ continue; } - + } + /* + * Check sockets for reading + */ + else if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) { /* - * Check for URG data - * This will soread as well, so no need to - * test for G_IO_IN below if this succeeds + * Check for incoming connections */ - if (revents & G_IO_PRI) { - ret =3D sorecvoob(so); - if (ret < 0) { - /* Socket error might have resulted in the socket = being - * removed, do not try to do anything more with it= . */ - continue; - } + if (so->so_state & SS_FACCEPTCONN) { + tcp_connect(so); + continue; + } /* else */ + ret =3D soread(so); + + /* Output it if we read something */ + if (ret > 0) { + tcp_output(sototcpcb(so)); + } + if (ret < 0) { + /* Socket error might have resulted in the socket being + * removed, do not try to do anything more with it. */ + continue; } + } + + /* + * Check sockets for writing + */ + if (!(so->so_state & SS_NOFDREF) && + (revents & (G_IO_OUT | G_IO_ERR))) { /* - * Check sockets for reading + * Check for non-blocking, still-connecting sockets */ - else if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) { - /* - * Check for incoming connections - */ - if (so->so_state & SS_FACCEPTCONN) { - tcp_connect(so); - continue; - } /* else */ - ret =3D soread(so); + if (so->so_state & SS_ISFCONNECTING) { + /* Connected */ + so->so_state &=3D ~SS_ISFCONNECTING; =20 - /* Output it if we read something */ - if (ret > 0) { - tcp_output(sototcpcb(so)); - } + ret =3D send(so->s, (const void *) &ret, 0, 0); if (ret < 0) { - /* Socket error might have resulted in the socket = being - * removed, do not try to do anything more with it= . */ - continue; + /* XXXXX Must fix, zero bytes is a NOP */ + if (errno =3D=3D EAGAIN || errno =3D=3D EWOULDBLOC= K || + errno =3D=3D EINPROGRESS || errno =3D=3D ENOTC= ONN) { + continue; + } + + /* else failed */ + so->so_state &=3D SS_PERSISTENT_MASK; + so->so_state |=3D SS_NOFDREF; } - } + /* else so->so_state &=3D ~SS_ISFCONNECTING; */ =20 - /* - * Check sockets for writing - */ - if (!(so->so_state & SS_NOFDREF) && - (revents & (G_IO_OUT | G_IO_ERR))) { /* - * Check for non-blocking, still-connecting sockets + * Continue tcp_input */ - if (so->so_state & SS_ISFCONNECTING) { - /* Connected */ - so->so_state &=3D ~SS_ISFCONNECTING; - - ret =3D send(so->s, (const void *) &ret, 0, 0); - if (ret < 0) { - /* XXXXX Must fix, zero bytes is a NOP */ - if (errno =3D=3D EAGAIN || errno =3D=3D EWOULD= BLOCK || - errno =3D=3D EINPROGRESS || errno =3D=3D E= NOTCONN) { - continue; - } - - /* else failed */ - so->so_state &=3D SS_PERSISTENT_MASK; - so->so_state |=3D SS_NOFDREF; - } - /* else so->so_state &=3D ~SS_ISFCONNECTING; */ - - /* - * Continue tcp_input - */ - tcp_input((struct mbuf *)NULL, sizeof(struct ip), = so, - so->so_ffamily); - /* continue; */ - } else { - ret =3D sowrite(so); - if (ret > 0) { - /* Call tcp_output in case we need to send a w= indow - * update to the guest, otherwise it will be s= tuck - * until it sends a window probe. */ - tcp_output(sototcpcb(so)); - } + tcp_input((struct mbuf *)NULL, sizeof(struct ip), so, + so->so_ffamily); + /* continue; */ + } else { + ret =3D sowrite(so); + if (ret > 0) { + /* Call tcp_output in case we need to send a window + * update to the guest, otherwise it will be stuck + * until it sends a window probe. */ + tcp_output(sototcpcb(so)); } } } + } =20 - /* - * Now UDP sockets. - * Incoming packets are sent straight away, they're not buffer= ed. - * Incoming UDP data isn't buffered either. - */ - for (so =3D slirp->udb.so_next; so !=3D &slirp->udb; - so =3D so_next) { - int revents; + /* + * Now UDP sockets. + * Incoming packets are sent straight away, they're not buffered. + * Incoming UDP data isn't buffered either. + */ + for (so =3D slirp->udb.so_next; so !=3D &slirp->udb; + so =3D so_next) { + int revents; =20 - so_next =3D so->so_next; + so_next =3D so->so_next; =20 - revents =3D 0; - if (so->pollfds_idx !=3D -1) { - revents =3D g_array_index(pollfds, GPollFD, - so->pollfds_idx).revents; - } + revents =3D 0; + if (so->pollfds_idx !=3D -1) { + revents =3D g_array_index(pollfds, GPollFD, + so->pollfds_idx).revents; + } =20 - if (so->s !=3D -1 && - (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) { - sorecvfrom(so); - } + if (so->s !=3D -1 && + (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) { + sorecvfrom(so); } + } =20 - /* - * Check incoming ICMP relies. - */ - for (so =3D slirp->icmp.so_next; so !=3D &slirp->icmp; - so =3D so_next) { - int revents; + /* + * Check incoming ICMP relies. + */ + for (so =3D slirp->icmp.so_next; so !=3D &slirp->icmp; + so =3D so_next) { + int revents; =20 - so_next =3D so->so_next; + so_next =3D so->so_next; =20 - revents =3D 0; - if (so->pollfds_idx !=3D -1) { - revents =3D g_array_index(pollfds, GPollFD, - so->pollfds_idx).revents; - } + revents =3D 0; + if (so->pollfds_idx !=3D -1) { + revents =3D g_array_index(pollfds, GPollFD, + so->pollfds_idx).revents; + } =20 - if (so->s !=3D -1 && - (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) { - icmp_receive(so); - } + if (so->s !=3D -1 && + (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) { + icmp_receive(so); } } - - if_start(slirp); } + + if_start(slirp); } =20 static void arp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index cda0efa4e8..1558ff1fe7 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -26,7 +26,6 @@ stub-obj-y +=3D qtest.o stub-obj-y +=3D replay.o stub-obj-y +=3D runstate-check.o stub-obj-y +=3D set-fd-handler.o -stub-obj-y +=3D slirp.o stub-obj-y +=3D sysbus.o stub-obj-y +=3D tpm.o stub-obj-y +=3D trace-control.o diff --git a/stubs/slirp.c b/stubs/slirp.c deleted file mode 100644 index 70704346fd..0000000000 --- a/stubs/slirp.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu-common.h" -#include "qemu/host-utils.h" -#include "slirp/libslirp.h" - -void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout) -{ -} - -void slirp_pollfds_poll(GArray *pollfds, int select_error) -{ -} - diff --git a/util/main-loop.c b/util/main-loop.c index 443cb4cfe8..d4a521caeb 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -469,25 +469,42 @@ static int os_host_main_loop_wait(int64_t timeout) } #endif =20 +static NotifierList main_loop_poll_notifiers =3D + NOTIFIER_LIST_INITIALIZER(main_loop_poll_notifiers); + +void main_loop_poll_add_notifier(Notifier *notify) +{ + notifier_list_add(&main_loop_poll_notifiers, notify); +} + +void main_loop_poll_remove_notifier(Notifier *notify) +{ + notifier_remove(notify); +} + void main_loop_wait(int nonblocking) { + MainLoopPoll mlpoll =3D { + .state =3D MAIN_LOOP_POLL_FILL, + .timeout =3D UINT32_MAX, + .pollfds =3D gpollfds, + }; int ret; - uint32_t timeout =3D UINT32_MAX; int64_t timeout_ns; =20 if (nonblocking) { - timeout =3D 0; + mlpoll.timeout =3D 0; } =20 /* poll any events */ g_array_set_size(gpollfds, 0); /* reset for new iteration */ /* XXX: separate device handlers from system ones */ - slirp_pollfds_fill(gpollfds, &timeout); + notifier_list_notify(&main_loop_poll_notifiers, &mlpoll); =20 - if (timeout =3D=3D UINT32_MAX) { + if (mlpoll.timeout =3D=3D UINT32_MAX) { timeout_ns =3D -1; } else { - timeout_ns =3D (uint64_t)timeout * (int64_t)(SCALE_MS); + timeout_ns =3D (uint64_t)mlpoll.timeout * (int64_t)(SCALE_MS); } =20 timeout_ns =3D qemu_soonest_timeout(timeout_ns, @@ -495,7 +512,8 @@ void main_loop_wait(int nonblocking) &main_loop_tlg)); =20 ret =3D os_host_main_loop_wait(timeout_ns); - slirp_pollfds_poll(gpollfds, (ret < 0)); + mlpoll.state =3D ret < 0 ? MAIN_LOOP_POLL_ERR : MAIN_LOOP_POLL_OK; + notifier_list_notify(&main_loop_poll_notifiers, &mlpoll); =20 /* CPU thread can infinitely wait for event after missing the warp */ --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 15495497021051004.5799137282357; Thu, 7 Feb 2019 06:28:22 -0800 (PST) Received: from localhost ([127.0.0.1]:40929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkf4-0005Ch-Ue for importer@patchew.org; Thu, 07 Feb 2019 09:28:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHs-0002Ri-A0 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHe-0001AW-KU for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:16 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41904) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHc-0000yy-Ga for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:05 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id C1984CC15; Thu, 7 Feb 2019 15:03:38 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1S4jrC_k3737; Thu, 7 Feb 2019 15:03:37 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id BA696CD3B; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGs-0004E9-6U; Thu, 07 Feb 2019 15:03:18 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:13 +0200 Message-Id: <20190207140316.16103-30-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 29/32] slirp: remove slirp_instances list 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Now that polling is done per-instance, we don't need a global list of slirp instances. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/slirp.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/slirp/slirp.c b/slirp/slirp.c index 3a8d1bc459..b37dd34382 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -48,9 +48,6 @@ static const uint8_t special_ethaddr[ETH_ALEN] =3D { =20 unsigned curtime; =20 -static QTAILQ_HEAD(, Slirp) slirp_instances =3D - QTAILQ_HEAD_INITIALIZER(slirp_instances); - static struct in_addr dns_addr; #ifndef _WIN32 static struct in6_addr dns6_addr; @@ -333,7 +330,6 @@ Slirp *slirp_init(int restricted, bool in_enabled, stru= ct in_addr vnetwork, #ifdef WITH_QEMU slirp_state_register(slirp); #endif - QTAILQ_INSERT_TAIL(&slirp_instances, slirp, entry); =20 return slirp; } @@ -348,7 +344,6 @@ void slirp_cleanup(Slirp *slirp) g_free(e); } =20 - QTAILQ_REMOVE(&slirp_instances, slirp, entry); #ifdef WITH_QEMU slirp_state_unregister(slirp); #endif --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549549821870943.7836125837563; Thu, 7 Feb 2019 06:30:21 -0800 (PST) Received: from localhost ([127.0.0.1]:40969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkgv-0007Gq-Mr for importer@patchew.org; Thu, 07 Feb 2019 09:30:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHi-0002I6-MT for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHf-0001BA-9C for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:10 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41916) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHc-0000zT-HS for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:06 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 93FFFCD3B; Thu, 7 Feb 2019 15:03:44 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YIelHFM8iiHU; Thu, 7 Feb 2019 15:03:43 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id F040BCD41; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGs-0004EC-7b; Thu, 07 Feb 2019 15:03:18 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:14 +0200 Message-Id: <20190207140316.16103-31-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 30/32] slirp: use polling callbacks, drop glib requirement 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau It would be legitimate to use libslirp without glib. Let's add_poll/get_revents pair of callbacks to provide the same functionality. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++-- slirp/libslirp.h | 17 ++++++++++-- slirp/slirp.c | 72 +++++++++++++++++------------------------------- 3 files changed, 109 insertions(+), 52 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 4d55f64168..a85e42ff43 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -211,6 +211,71 @@ static const SlirpCb slirp_cb =3D { .notify =3D qemu_notify_event, }; =20 +static int slirp_poll_to_gio(int events) +{ + int ret =3D 0; + + if (events & SLIRP_POLL_IN) { + ret |=3D G_IO_IN; + } + if (events & SLIRP_POLL_OUT) { + ret |=3D G_IO_OUT; + } + if (events & SLIRP_POLL_PRI) { + ret |=3D G_IO_PRI; + } + if (events & SLIRP_POLL_ERR) { + ret |=3D G_IO_ERR; + } + if (events & SLIRP_POLL_HUP) { + ret |=3D G_IO_HUP; + } + + return ret; +} + +static int net_slirp_add_poll(int fd, int events, void *opaque) +{ + GArray *pollfds =3D opaque; + GPollFD pfd =3D { + .fd =3D fd, + .events =3D slirp_poll_to_gio(events), + }; + int idx =3D pollfds->len; + g_array_append_val(pollfds, pfd); + return idx; +} + +static int slirp_gio_to_poll(int events) +{ + int ret =3D 0; + + if (events & G_IO_IN) { + ret |=3D SLIRP_POLL_IN; + } + if (events & G_IO_OUT) { + ret |=3D SLIRP_POLL_OUT; + } + if (events & G_IO_PRI) { + ret |=3D SLIRP_POLL_PRI; + } + if (events & G_IO_ERR) { + ret |=3D SLIRP_POLL_ERR; + } + if (events & G_IO_HUP) { + ret |=3D SLIRP_POLL_HUP; + } + + return ret; +} + +static int net_slirp_get_revents(int idx, void *opaque) +{ + GArray *pollfds =3D opaque; + + return slirp_gio_to_poll(g_array_index(pollfds, GPollFD, idx).revents); +} + static void net_slirp_poll_notify(Notifier *notifier, void *data) { MainLoopPoll *poll =3D data; @@ -218,12 +283,13 @@ static void net_slirp_poll_notify(Notifier *notifier,= void *data) =20 switch (poll->state) { case MAIN_LOOP_POLL_FILL: - slirp_pollfds_fill(s->slirp, poll->pollfds, &poll->timeout); + slirp_pollfds_fill(s->slirp, &poll->timeout, + net_slirp_add_poll, poll->pollfds); break; case MAIN_LOOP_POLL_OK: case MAIN_LOOP_POLL_ERR: - slirp_pollfds_poll(s->slirp, poll->pollfds, - poll->state =3D=3D MAIN_LOOP_POLL_ERR); + slirp_pollfds_poll(s->slirp, poll->state =3D=3D MAIN_LOOP_POLL_ERR, + net_slirp_get_revents, poll->pollfds); break; default: g_assert_not_reached(); diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 18d5fb0133..b5c1b2122b 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -1,7 +1,6 @@ #ifndef LIBSLIRP_H #define LIBSLIRP_H =20 -#include #include #include =20 @@ -15,8 +14,18 @@ =20 typedef struct Slirp Slirp; =20 +enum { + SLIRP_POLL_IN =3D 1 << 0, + SLIRP_POLL_OUT =3D 1 << 1, + SLIRP_POLL_PRI =3D 1 << 2, + SLIRP_POLL_ERR =3D 1 << 3, + SLIRP_POLL_HUP =3D 1 << 4, +}; + typedef ssize_t (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); typedef void (*SlirpTimerCb)(void *opaque); +typedef int (*SlirpAddPollCb)(int fd, int events, void *opaque); +typedef int (*SlirpGetREventsCb)(int idx, void *opaque); =20 /* * Callbacks from slirp @@ -63,9 +72,11 @@ Slirp *slirp_init(int restricted, bool in_enabled, struc= t in_addr vnetwork, void *opaque); void slirp_cleanup(Slirp *slirp); =20 -void slirp_pollfds_fill(Slirp *slirp, GArray *pollfds, uint32_t *timeout); +void slirp_pollfds_fill(Slirp *slirp, uint32_t *timeout, + SlirpAddPollCb add_poll, void *opaque); =20 -void slirp_pollfds_poll(Slirp *slirp, GArray *pollfds, int select_error); +void slirp_pollfds_poll(Slirp *slirp, int select_error, + SlirpGetREventsCb get_revents, void *opaque); =20 void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len); =20 diff --git a/slirp/slirp.c b/slirp/slirp.c index b37dd34382..eedbce23dc 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -386,7 +386,8 @@ static void slirp_update_timeout(Slirp *slirp, uint32_t= *timeout) *timeout =3D t; } =20 -void slirp_pollfds_fill(Slirp *slirp, GArray *pollfds, uint32_t *timeout) +void slirp_pollfds_fill(Slirp *slirp, uint32_t *timeout, + SlirpAddPollCb add_poll, void *opaque) { struct socket *so, *so_next; =20 @@ -428,12 +429,8 @@ void slirp_pollfds_fill(Slirp *slirp, GArray *pollfds,= uint32_t *timeout) * Set for reading sockets which are accepting */ if (so->so_state & SS_FACCEPTCONN) { - GPollFD pfd =3D { - .fd =3D so->s, - .events =3D G_IO_IN | G_IO_HUP | G_IO_ERR, - }; - so->pollfds_idx =3D pollfds->len; - g_array_append_val(pollfds, pfd); + so->pollfds_idx =3D add_poll(so->s, + SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR, opaque); continue; } =20 @@ -441,12 +438,8 @@ void slirp_pollfds_fill(Slirp *slirp, GArray *pollfds,= uint32_t *timeout) * Set for writing sockets which are connecting */ if (so->so_state & SS_ISFCONNECTING) { - GPollFD pfd =3D { - .fd =3D so->s, - .events =3D G_IO_OUT | G_IO_ERR, - }; - so->pollfds_idx =3D pollfds->len; - g_array_append_val(pollfds, pfd); + so->pollfds_idx =3D add_poll(so->s, + SLIRP_POLL_OUT | SLIRP_POLL_ERR, opaque); continue; } =20 @@ -455,7 +448,7 @@ void slirp_pollfds_fill(Slirp *slirp, GArray *pollfds, = uint32_t *timeout) * we have something to send */ if (CONN_CANFSEND(so) && so->so_rcv.sb_cc) { - events |=3D G_IO_OUT | G_IO_ERR; + events |=3D SLIRP_POLL_OUT | SLIRP_POLL_ERR; } =20 /* @@ -464,16 +457,12 @@ void slirp_pollfds_fill(Slirp *slirp, GArray *pollfds= , uint32_t *timeout) */ if (CONN_CANFRCV(so) && (so->so_snd.sb_cc < (so->so_snd.sb_datalen/2))) { - events |=3D G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI; + events |=3D SLIRP_POLL_IN | SLIRP_POLL_HUP | + SLIRP_POLL_ERR | SLIRP_POLL_PRI; } =20 if (events) { - GPollFD pfd =3D { - .fd =3D so->s, - .events =3D events, - }; - so->pollfds_idx =3D pollfds->len; - g_array_append_val(pollfds, pfd); + so->pollfds_idx =3D add_poll(so->s, events, opaque); } } =20 @@ -508,12 +497,8 @@ void slirp_pollfds_fill(Slirp *slirp, GArray *pollfds,= uint32_t *timeout) * (XXX <=3D 4 ?) */ if ((so->so_state & SS_ISFCONNECTED) && so->so_queued <=3D 4) { - GPollFD pfd =3D { - .fd =3D so->s, - .events =3D G_IO_IN | G_IO_HUP | G_IO_ERR, - }; - so->pollfds_idx =3D pollfds->len; - g_array_append_val(pollfds, pfd); + so->pollfds_idx =3D add_poll(so->s, + SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR, opaque); } } =20 @@ -538,19 +523,16 @@ void slirp_pollfds_fill(Slirp *slirp, GArray *pollfds= , uint32_t *timeout) } =20 if (so->so_state & SS_ISFCONNECTED) { - GPollFD pfd =3D { - .fd =3D so->s, - .events =3D G_IO_IN | G_IO_HUP | G_IO_ERR, - }; - so->pollfds_idx =3D pollfds->len; - g_array_append_val(pollfds, pfd); + so->pollfds_idx =3D add_poll(so->s, + SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR, opaque); } } =20 slirp_update_timeout(slirp, timeout); } =20 -void slirp_pollfds_poll(Slirp *slirp, GArray *pollfds, int select_error) +void slirp_pollfds_poll(Slirp *slirp, int select_error, + SlirpGetREventsCb get_revents, void *opaque) { struct socket *so, *so_next; int ret; @@ -587,8 +569,7 @@ void slirp_pollfds_poll(Slirp *slirp, GArray *pollfds, = int select_error) =20 revents =3D 0; if (so->pollfds_idx !=3D -1) { - revents =3D g_array_index(pollfds, GPollFD, - so->pollfds_idx).revents; + revents =3D get_revents(so->pollfds_idx, opaque); } =20 if (so->so_state & SS_NOFDREF || so->s =3D=3D -1) { @@ -598,9 +579,9 @@ void slirp_pollfds_poll(Slirp *slirp, GArray *pollfds, = int select_error) /* * Check for URG data * This will soread as well, so no need to - * test for G_IO_IN below if this succeeds + * test for SLIRP_POLL_IN below if this succeeds */ - if (revents & G_IO_PRI) { + if (revents & SLIRP_POLL_PRI) { ret =3D sorecvoob(so); if (ret < 0) { /* Socket error might have resulted in the socket being @@ -611,7 +592,8 @@ void slirp_pollfds_poll(Slirp *slirp, GArray *pollfds, = int select_error) /* * Check sockets for reading */ - else if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) { + else if (revents & + (SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR)) { /* * Check for incoming connections */ @@ -636,7 +618,7 @@ void slirp_pollfds_poll(Slirp *slirp, GArray *pollfds, = int select_error) * Check sockets for writing */ if (!(so->so_state & SS_NOFDREF) && - (revents & (G_IO_OUT | G_IO_ERR))) { + (revents & (SLIRP_POLL_OUT | SLIRP_POLL_ERR))) { /* * Check for non-blocking, still-connecting sockets */ @@ -689,12 +671,11 @@ void slirp_pollfds_poll(Slirp *slirp, GArray *pollfds= , int select_error) =20 revents =3D 0; if (so->pollfds_idx !=3D -1) { - revents =3D g_array_index(pollfds, GPollFD, - so->pollfds_idx).revents; + revents =3D get_revents(so->pollfds_idx, opaque); } =20 if (so->s !=3D -1 && - (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) { + (revents & (SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ER= R))) { sorecvfrom(so); } } @@ -710,12 +691,11 @@ void slirp_pollfds_poll(Slirp *slirp, GArray *pollfds= , int select_error) =20 revents =3D 0; if (so->pollfds_idx !=3D -1) { - revents =3D g_array_index(pollfds, GPollFD, - so->pollfds_idx).revents; + revents =3D get_revents(so->pollfds_idx, opaque); } =20 if (so->s !=3D -1 && - (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) { + (revents & (SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ER= R))) { icmp_receive(so); } } --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549548929379778.0639710650366; Thu, 7 Feb 2019 06:15:29 -0800 (PST) Received: from localhost ([127.0.0.1]:40729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkSV-0002ev-70 for importer@patchew.org; Thu, 07 Feb 2019 09:15:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHW-00029B-Vc for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHS-000121-VY for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:58 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:49876) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHS-0000zR-96 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:03:54 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 844ECCD3D; Thu, 7 Feb 2019 15:03:45 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7DCOXGfQhT58; Thu, 7 Feb 2019 15:03:44 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id D95D0CD3F; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGs-0004EF-8n; Thu, 07 Feb 2019 15:03:18 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:15 +0200 Message-Id: <20190207140316.16103-32-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULLv4 31/32] slirp: pass opaque to all callbacks 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau This is friendlier for FFI bindings. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 25 ++++++++++++++++--------- slirp/dhcpv6.c | 2 +- slirp/if.c | 2 +- slirp/ip6_icmp.c | 15 +++++++++------ slirp/ip_icmp.c | 2 +- slirp/libslirp.h | 16 ++++++++-------- slirp/misc.c | 2 +- slirp/slirp.c | 13 ++++++------- slirp/socket.c | 2 +- slirp/tcp_subr.c | 8 ++++---- slirp/udp.c | 2 +- 11 files changed, 49 insertions(+), 40 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index a85e42ff43..7a16d8d615 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -161,44 +161,51 @@ static NetClientInfo net_slirp_info =3D { .cleanup =3D net_slirp_cleanup, }; =20 -static void net_slirp_guest_error(const char *msg) +static void net_slirp_guest_error(const char *msg, void *opaque) { qemu_log_mask(LOG_GUEST_ERROR, "%s", msg); } =20 -static int64_t net_slirp_clock_get_ns(void) +static int64_t net_slirp_clock_get_ns(void *opaque) { return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); } =20 -static void *net_slirp_timer_new(SlirpTimerCb cb, void *opaque) +static void *net_slirp_timer_new(SlirpTimerCb cb, + void *cb_opaque, void *opaque) { return timer_new_full(NULL, QEMU_CLOCK_VIRTUAL, SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL, - cb, opaque); + cb, cb_opaque); } =20 -static void net_slirp_timer_free(void *timer) +static void net_slirp_timer_free(void *timer, void *opaque) { timer_del(timer); timer_free(timer); } =20 -static void net_slirp_timer_mod(void *timer, int64_t expire_timer) +static void net_slirp_timer_mod(void *timer, int64_t expire_timer, + void *opaque) { timer_mod(timer, expire_timer); } =20 -static void net_slirp_register_poll_fd(int fd) +static void net_slirp_register_poll_fd(int fd, void *opaque) { qemu_fd_register(fd); } =20 -static void net_slirp_unregister_poll_fd(int fd) +static void net_slirp_unregister_poll_fd(int fd, void *opaque) { /* no qemu_fd_unregister */ } =20 +static void net_slirp_notify(void *opaque) +{ + qemu_notify_event(); +} + static const SlirpCb slirp_cb =3D { .send_packet =3D net_slirp_send_packet, .guest_error =3D net_slirp_guest_error, @@ -208,7 +215,7 @@ static const SlirpCb slirp_cb =3D { .timer_mod =3D net_slirp_timer_mod, .register_poll_fd =3D net_slirp_register_poll_fd, .unregister_poll_fd =3D net_slirp_unregister_poll_fd, - .notify =3D qemu_notify_event, + .notify =3D net_slirp_notify, }; =20 static int slirp_poll_to_gio(int events) diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c index 9ffba38e8f..e655c7d5b1 100644 --- a/slirp/dhcpv6.c +++ b/slirp/dhcpv6.c @@ -59,7 +59,7 @@ static int dhcpv6_parse_info_request(Slirp *slirp, uint8_= t *odata, int olen, int len =3D odata[2] << 8 | odata[3]; =20 if (len + 4 > olen) { - slirp->cb->guest_error("Guest sent bad DHCPv6 packet!"); + slirp->cb->guest_error("Guest sent bad DHCPv6 packet!", slirp-= >opaque); return -E2BIG; } =20 diff --git a/slirp/if.c b/slirp/if.c index 2ad03b8a79..1830cc396c 100644 --- a/slirp/if.c +++ b/slirp/if.c @@ -146,7 +146,7 @@ diddit: */ void if_start(Slirp *slirp) { - uint64_t now =3D slirp->cb->clock_get_ns(); + uint64_t now =3D slirp->cb->clock_get_ns(slirp->opaque); bool from_batchq =3D false; struct mbuf *ifm, *ifm_next, *ifqt; =20 diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 2a432ebbd4..c1e3d30470 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -14,7 +14,8 @@ static void ra_timer_handler(void *opaque) Slirp *slirp =3D opaque; =20 slirp->cb->timer_mod(slirp->ra_timer, - slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interv= al); + slirp->cb->clock_get_ns(slirp->opaque) / SCALE_MS + NDP_Interval, + slirp->opaque); ndp_send_ra(slirp); } =20 @@ -24,9 +25,10 @@ void icmp6_init(Slirp *slirp) return; } =20 - slirp->ra_timer =3D slirp->cb->timer_new(ra_timer_handler, slirp); + slirp->ra_timer =3D slirp->cb->timer_new(ra_timer_handler, slirp, slir= p->opaque); slirp->cb->timer_mod(slirp->ra_timer, - slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interv= al); + slirp->cb->clock_get_ns(slirp->opaque) / SCALE_MS + NDP_Interval, + slirp->opaque); } =20 void icmp6_cleanup(Slirp *slirp) @@ -35,7 +37,7 @@ void icmp6_cleanup(Slirp *slirp) return; } =20 - slirp->cb->timer_free(slirp->ra_timer); + slirp->cb->timer_free(slirp->ra_timer, slirp->opaque); } =20 static void icmp6_send_echoreply(struct mbuf *m, Slirp *slirp, struct ip6 = *ip, @@ -334,7 +336,8 @@ static void ndp_input(struct mbuf *m, Slirp *slirp, str= uct ip6 *ip, =20 case ICMP6_NDP_RA: DEBUG_CALL(" type =3D Router Advertisement"); - slirp->cb->guest_error("Warning: guest sent NDP RA, but shouldn't"= ); + slirp->cb->guest_error("Warning: guest sent NDP RA, but shouldn't", + slirp->opaque); break; =20 case ICMP6_NDP_NS: @@ -368,7 +371,7 @@ static void ndp_input(struct mbuf *m, Slirp *slirp, str= uct ip6 *ip, case ICMP6_NDP_REDIRECT: DEBUG_CALL(" type =3D Redirect"); slirp->cb->guest_error( - "Warning: guest sent NDP REDIRECT, but shouldn't"); + "Warning: guest sent NDP REDIRECT, but shouldn't", slirp->opaq= ue); break; } } diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index 7c5cb75ae5..ce79c0b051 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -113,7 +113,7 @@ static int icmp_send(struct socket *so, struct mbuf *m,= int hlen) =20 void icmp_detach(struct socket *so) { - so->slirp->cb->unregister_poll_fd(so->s); + so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); slirp_closesocket(so->s); sofree(so); } diff --git a/slirp/libslirp.h b/slirp/libslirp.h index b5c1b2122b..9b13d8250c 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -40,21 +40,21 @@ typedef struct SlirpCb { */ SlirpWriteCb send_packet; /* Print a message for an error due to guest misbehavior. */ - void (*guest_error)(const char *msg); + void (*guest_error)(const char *msg, void *opaque); /* Return the virtual clock value in nanoseconds */ - int64_t (*clock_get_ns)(void); + int64_t (*clock_get_ns)(void *opaque); /* Create a new timer with the given callback and opaque data */ - void *(*timer_new)(SlirpTimerCb cb, void *opaque); + void *(*timer_new)(SlirpTimerCb cb, void *cb_opaque, void *opaque); /* Remove and free a timer */ - void (*timer_free)(void *timer); + void (*timer_free)(void *timer, void *opaque); /* Modify a timer to expire at @expire_time */ - void (*timer_mod)(void *timer, int64_t expire_time); + void (*timer_mod)(void *timer, int64_t expire_time, void *opaque); /* Register a fd for future polling */ - void (*register_poll_fd)(int fd); + void (*register_poll_fd)(int fd, void *opaque); /* Unregister a fd */ - void (*unregister_poll_fd)(int fd); + void (*unregister_poll_fd)(int fd, void *opaque); /* Kick the io-thread, to signal that new events may be processed */ - void (*notify)(void); + void (*notify)(void *opaque); } SlirpCb; =20 =20 diff --git a/slirp/misc.c b/slirp/misc.c index 3c02510101..3f4cd852f8 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -222,7 +222,7 @@ fork_exec(struct socket *so, const char *ex) opt =3D 1; slirp_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); slirp_set_nonblock(so->s); - so->slirp->cb->register_poll_fd(so->s); + so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque); return 1; } =20 diff --git a/slirp/slirp.c b/slirp/slirp.c index eedbce23dc..a746c6fd86 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -289,6 +289,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, stru= ct in_addr vnetwork, =20 slirp_init_once(); =20 + slirp->opaque =3D opaque; slirp->cb =3D callbacks; slirp->grand =3D g_rand_new(); slirp->restricted =3D restricted; @@ -325,12 +326,9 @@ Slirp *slirp_init(int restricted, bool in_enabled, str= uct in_addr vnetwork, translate_dnssearch(slirp, vdnssearch); } =20 - slirp->opaque =3D opaque; - #ifdef WITH_QEMU slirp_state_register(slirp); #endif - return slirp; } =20 @@ -537,7 +535,7 @@ void slirp_pollfds_poll(Slirp *slirp, int select_error, struct socket *so, *so_next; int ret; =20 - curtime =3D slirp->cb->clock_get_ns() / SCALE_MS; + curtime =3D slirp->cb->clock_get_ns(slirp->opaque) / SCALE_MS; =20 /* * See if anything has timed out @@ -860,7 +858,8 @@ static int if_encap4(Slirp *slirp, struct mbuf *ifm, st= ruct ethhdr *eh, ifm->resolution_requested =3D true; =20 /* Expire request and drop outgoing packet after 1 second */ - ifm->expiration_date =3D slirp->cb->clock_get_ns() + 100000000= 0ULL; + ifm->expiration_date =3D + slirp->cb->clock_get_ns(slirp->opaque) + 1000000000ULL; } return 0; } else { @@ -886,7 +885,7 @@ static int if_encap6(Slirp *slirp, struct mbuf *ifm, st= ruct ethhdr *eh, if (!ifm->resolution_requested) { ndp_send_ns(slirp, ip6h->ip_dst); ifm->resolution_requested =3D true; - ifm->expiration_date =3D slirp->cb->clock_get_ns() + 100000000= 0ULL; + ifm->expiration_date =3D slirp->cb->clock_get_ns(slirp->opaque= ) + 1000000000ULL; } return 0; } else { @@ -961,7 +960,7 @@ int slirp_remove_hostfwd(Slirp *slirp, int is_udp, stru= ct in_addr host_addr, getsockname(so->s, (struct sockaddr *)&addr, &addr_len) =3D=3D= 0 && addr.sin_addr.s_addr =3D=3D host_addr.s_addr && addr.sin_port =3D=3D port) { - so->slirp->cb->unregister_poll_fd(so->s); + so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); slirp_closesocket(so->s); sofree(so); return 0; diff --git a/slirp/socket.c b/slirp/socket.c index c896fa6da3..ce1d6ffa1d 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -930,6 +930,6 @@ void sotranslate_accept(struct socket *so) void sodrop(struct socket *s, int num) { if (sbdrop(&s->so_snd, num)) { - s->slirp->cb->notify(); + s->slirp->cb->notify(s->slirp->opaque); } } diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index e35628a892..cda94815f6 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -336,7 +336,7 @@ tcp_close(struct tcpcb *tp) /* clobber input socket cache if we're closing the cached connection */ if (so =3D=3D slirp->tcp_last_so) slirp->tcp_last_so =3D &slirp->tcb; - so->slirp->cb->unregister_poll_fd(so->s); + so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); slirp_closesocket(so->s); sbfree(&so->so_rcv); sbfree(&so->so_snd); @@ -413,7 +413,7 @@ int tcp_fconnect(struct socket *so, unsigned short af) struct sockaddr_storage addr; =20 slirp_set_nonblock(s); - so->slirp->cb->register_poll_fd(so->s); + so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque); slirp_socket_set_fast_reuse(s); opt =3D 1; slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt)); @@ -486,7 +486,7 @@ void tcp_connect(struct socket *inso) return; } slirp_set_nonblock(s); - so->slirp->cb->register_poll_fd(so->s); + so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque); slirp_socket_set_fast_reuse(s); opt =3D 1; slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); @@ -498,7 +498,7 @@ void tcp_connect(struct socket *inso) /* Close the accept() socket, set right state */ if (inso->so_state & SS_FACCEPTONCE) { /* If we only accept once, close the accept() socket */ - so->slirp->cb->unregister_poll_fd(so->s); + so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); slirp_closesocket(so->s); =20 /* Don't select it yet, even though we have an FD */ diff --git a/slirp/udp.c b/slirp/udp.c index 5baa604b33..29a31e9400 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -291,7 +291,7 @@ udp_attach(struct socket *so, unsigned short af) void udp_detach(struct socket *so) { - so->slirp->cb->unregister_poll_fd(so->s); + so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); slirp_closesocket(so->s); sofree(so); } --=20 2.20.1 From nobody Wed Apr 24 02:31:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 1549549899423173.38636637974423; Thu, 7 Feb 2019 06:31:39 -0800 (PST) Received: from localhost ([127.0.0.1]:41005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkiE-00005c-80 for importer@patchew.org; Thu, 07 Feb 2019 09:31:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grkHh-0002G5-01 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grkHe-0001AX-KY for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:08 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:41914) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grkHc-0000zM-H8 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 09:04:05 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id E9B88CD38; Thu, 7 Feb 2019 15:03:43 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2Au4GnRg-C5W; Thu, 7 Feb 2019 15:03:42 +0100 (CET) Received: from function (unknown [160.40.205.85]) by hera.aquilenet.fr (Postfix) with ESMTPSA id DC619CD40; Thu, 7 Feb 2019 15:03:20 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1grkGs-0004EH-9t; Thu, 07 Feb 2019 15:03:18 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Feb 2019 16:03:16 +0200 Message-Id: <20190207140316.16103-33-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> References: <20190207140316.16103-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULLv4 32/32] slirp: API is extern C 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Make it possible to use headers easily with C++ projects. Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/libslirp.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 9b13d8250c..fccab42518 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -12,6 +12,10 @@ #include #endif =20 +#ifdef __cplusplus +extern "C" { +#endif + typedef struct Slirp Slirp; =20 enum { @@ -96,5 +100,8 @@ void slirp_socket_recv(Slirp *slirp, struct in_addr gues= t_addr, int guest_port, const uint8_t *buf, int size); size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port); - +#ifdef __cplusplus +} /* extern "C" */ #endif + +#endif /* LIBSLIRP_H */ --=20 2.20.1