From patchwork Wed Nov 21 22:06:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001419 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cBx4PB3z9s29 for ; Thu, 22 Nov 2018 09:07:53 +1100 (AEDT) Received: from localhost ([::1]:42558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPaf1-0003fc-4K for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:07:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPaeK-0003bt-7m for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPaeI-0000pH-43 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59162) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPaeG-0000lP-40 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:06 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74AB23DBEC; Wed, 21 Nov 2018 22:07:01 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id C51471054FD3; Wed, 21 Nov 2018 22:06:57 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:18 +0400 Message-Id: <20181121220647.18844-2-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 21 Nov 2018 22:07:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 01/30] fixup! net: do not depend on slirp internals 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Somehow, I broke the build and failed to detect it. Please squash! Signed-off-by: Marc-André Lureau --- net/colo.h | 1 + net/util.h | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/net/colo.h b/net/colo.h index 420d916af2..b2f60e4d56 100644 --- a/net/colo.h +++ b/net/colo.h @@ -18,6 +18,7 @@ #include "qemu/jhash.h" #include "qemu/timer.h" #include "net/eth.h" +#include "util.h" #define HASHTABLE_MAX_SIZE 16384 diff --git a/net/util.h b/net/util.h index 358185fd50..0e0748913a 100644 --- a/net/util.h +++ b/net/util.h @@ -25,6 +25,9 @@ #ifndef QEMU_NET_UTIL_H #define QEMU_NET_UTIL_H +#include "qemu/osdep.h" + +typedef uint32_t tcp_seq; /* * Structure of an internet header, naked of options. @@ -50,6 +53,29 @@ struct ip { struct in_addr ip_src, ip_dst; /* source and dest address */ } QEMU_PACKED; +/* + * TCP header. + * Per RFC 793, September, 1981. + */ +#define tcphdr slirp_tcphdr +struct tcphdr { + uint16_t th_sport; /* source port */ + uint16_t th_dport; /* destination port */ + tcp_seq th_seq; /* sequence number */ + tcp_seq th_ack; /* acknowledgement number */ +#ifdef HOST_WORDS_BIGENDIAN + uint8_t th_off:4, /* data offset */ + th_x2:4; /* (unused) */ +#else + uint8_t th_x2:4, /* (unused) */ + th_off:4; /* data offset */ +#endif + uint8_t th_flags; + uint16_t th_win; /* window */ + uint16_t th_sum; /* checksum */ + uint16_t th_urp; /* urgent pointer */ +}; + static inline bool in6_equal_net(const struct in6_addr *a, const struct in6_addr *b, int prefix_len) From patchwork Wed Nov 21 22:06:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cFz5yKgz9s3C for ; Thu, 22 Nov 2018 09:10:31 +1100 (AEDT) Received: from localhost ([::1]:42568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPahZ-0006J4-5M for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:10:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPaeV-0003jj-Jj for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPaeP-00013B-O8 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40720) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPaeK-0000v2-1g for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:10 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D5F1300441E; Wed, 21 Nov 2018 22:07:07 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74CF15D75C; Wed, 21 Nov 2018 22:07:05 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:19 +0400 Message-Id: <20181121220647.18844-3-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 21 Nov 2018 22:07:07 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 02/30] slirp: drop List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Since commit 12f8def0e02232d7c6416ad9b66640f973c531d1 (v2.9), qemu requires Vista. Let's remove some conditional code. Note that this introduces a missing declaration warning with mingw. warning: implicit declaration of function 'inet_ntop' See also: https://sourceforge.net/p/mingw-w64/mailman/message/36473782/ We could workaround it by declaring it ourself depending on __MINGW64_VERSION_*: WINSOCK_API_LINKAGE INT WSAAPI inet_pton(int Family, PCTSTR pszAddrString, PVOID pAddrBuf); Signed-off-by: Marc-André Lureau --- net/slirp.c | 22 ---------------------- slirp/ip6_icmp.c | 10 ++++------ slirp/ndp_table.c | 14 ++++++-------- 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 30eda2cca1..4d890287ba 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -290,17 +290,6 @@ static int net_slirp_init(NetClientState *peer, const char *model, } #endif -#if defined(_WIN32) && (_WIN32_WINNT < 0x0600) - /* No inet_pton helper before Vista... */ - if (vprefix6) { - /* Unsupported */ - error_setg(errp, "IPv6 prefix not supported"); - return -1; - } - memset(&ip6_prefix, 0, sizeof(ip6_prefix)); - ip6_prefix.s6_addr[0] = 0xfe; - ip6_prefix.s6_addr[1] = 0xc0; -#else if (!vprefix6) { vprefix6 = "fec0::"; } @@ -308,7 +297,6 @@ static int net_slirp_init(NetClientState *peer, const char *model, error_setg(errp, "Failed to parse IPv6 prefix"); return -1; } -#endif if (!vprefix6_len) { vprefix6_len = 64; @@ -320,10 +308,6 @@ static int net_slirp_init(NetClientState *peer, const char *model, } if (vhost6) { -#if defined(_WIN32) && (_WIN32_WINNT < 0x0600) - error_setg(errp, "IPv6 host not supported"); - return -1; -#else if (!inet_pton(AF_INET6, vhost6, &ip6_host)) { error_setg(errp, "Failed to parse IPv6 host"); return -1; @@ -332,17 +316,12 @@ static int net_slirp_init(NetClientState *peer, const char *model, error_setg(errp, "IPv6 Host doesn't belong to network"); return -1; } -#endif } else { ip6_host = ip6_prefix; ip6_host.s6_addr[15] |= 2; } if (vnameserver6) { -#if defined(_WIN32) && (_WIN32_WINNT < 0x0600) - error_setg(errp, "IPv6 DNS not supported"); - return -1; -#else if (!inet_pton(AF_INET6, vnameserver6, &ip6_dns)) { error_setg(errp, "Failed to parse IPv6 DNS"); return -1; @@ -351,7 +330,6 @@ static int net_slirp_init(NetClientState *peer, const char *model, error_setg(errp, "IPv6 DNS doesn't belong to network"); return -1; } -#endif } else { ip6_dns = ip6_prefix; ip6_dns.s6_addr[15] |= 3; diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 3f74d172f4..595a62c8d4 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -74,6 +74,7 @@ void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code) Slirp *slirp = m->slirp; struct mbuf *t; struct ip6 *ip = mtod(m, struct ip6 *); + char addrstr[INET6_ADDRSTRLEN]; DEBUG_CALL("icmp6_send_error"); DEBUG_ARGS(" type = %d, code = %d\n", type, code); @@ -90,11 +91,8 @@ void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code) struct ip6 *rip = mtod(t, struct ip6 *); rip->ip_src = (struct in6_addr)LINKLOCAL_ADDR; rip->ip_dst = ip->ip_src; -#if !defined(_WIN32) || (_WIN32_WINNT >= 0x0600) - char addrstr[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, &rip->ip_dst, addrstr, INET6_ADDRSTRLEN); DEBUG_ARG("target = %s", addrstr); -#endif rip->ip_nh = IPPROTO_ICMPV6; const int error_data_len = MIN(m->m_len, @@ -222,12 +220,12 @@ void ndp_send_ra(Slirp *slirp) */ void ndp_send_ns(Slirp *slirp, struct in6_addr addr) { - DEBUG_CALL("ndp_send_ns"); -#if !defined(_WIN32) || (_WIN32_WINNT >= 0x0600) char addrstr[INET6_ADDRSTRLEN]; + inet_ntop(AF_INET6, &addr, addrstr, INET6_ADDRSTRLEN); + + DEBUG_CALL("ndp_send_ns"); DEBUG_ARG("target = %s", addrstr); -#endif /* Build IPv6 packet */ struct mbuf *t = m_get(slirp); diff --git a/slirp/ndp_table.c b/slirp/ndp_table.c index a4e6421fd3..1401e1b322 100644 --- a/slirp/ndp_table.c +++ b/slirp/ndp_table.c @@ -10,15 +10,14 @@ void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr, uint8_t ethaddr[ETH_ALEN]) { + char addrstr[INET6_ADDRSTRLEN]; NdpTable *ndp_table = &slirp->ndp_table; int i; - DEBUG_CALL("ndp_table_add"); -#if !defined(_WIN32) || (_WIN32_WINNT >= 0x0600) - char addrstr[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, &(ip_addr), addrstr, INET6_ADDRSTRLEN); + + DEBUG_CALL("ndp_table_add"); DEBUG_ARG("ip = %s", addrstr); -#endif DEBUG_ARGS(" hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n", ethaddr[0], ethaddr[1], ethaddr[2], ethaddr[3], ethaddr[4], ethaddr[5]); @@ -50,15 +49,14 @@ void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr, bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr, uint8_t out_ethaddr[ETH_ALEN]) { + char addrstr[INET6_ADDRSTRLEN]; NdpTable *ndp_table = &slirp->ndp_table; int i; - DEBUG_CALL("ndp_table_search"); -#if !defined(_WIN32) || (_WIN32_WINNT >= 0x0600) - char addrstr[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, &(ip_addr), addrstr, INET6_ADDRSTRLEN); + + DEBUG_CALL("ndp_table_search"); DEBUG_ARG("ip = %s", addrstr); -#endif assert(!in6_zero(&ip_addr)); From patchwork Wed Nov 21 22:06:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001421 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cCC2Wwbz9s29 for ; Thu, 22 Nov 2018 09:08:07 +1100 (AEDT) Received: from localhost ([::1]:42559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPafE-0003ob-Vq for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:08:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPaeZ-0003mW-Jy for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPaeW-0001A2-8b for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:64343) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPaeU-00013X-Pp for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:20 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D81D6C0860A6; Wed, 21 Nov 2018 22:07:13 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 023225C21E; Wed, 21 Nov 2018 22:07:10 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:20 +0400 Message-Id: <20181121220647.18844-4-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 21 Nov 2018 22:07:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 03/30] glib-compat: add g_spawn_async_with_fds() fallback 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Marc-André Lureau Reviewed-by: Samuel Thibault --- include/glib-compat.h | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/include/glib-compat.h b/include/glib-compat.h index fdf95a255d..8a078c5288 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -83,6 +83,62 @@ static inline gboolean g_strv_contains_qemu(const gchar *const *strv, } #define g_strv_contains(a, b) g_strv_contains_qemu(a, b) +#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 = (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_fd, + error); +#else + QemuGSpawnFds setup = { + .child_setup = child_setup, + .user_data = user_data, + .stdin_fd = stdin_fd, + .stdout_fd = stdout_fd, + .stderr_fd = 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, err) \ + 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) /* From patchwork Wed Nov 21 22:06:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cGb66rfz9s29 for ; Thu, 22 Nov 2018 09:11:03 +1100 (AEDT) Received: from localhost ([::1]:42574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPai5-0006qH-Cn for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:11:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPaea-0003n8-Am for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPaeZ-0001KW-BB for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48042) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPaeZ-0001I9-3g for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:23 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5DF68307D874; Wed, 21 Nov 2018 22:07:22 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id E22EB16C14; Wed, 21 Nov 2018 22:07:17 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:21 +0400 Message-Id: <20181121220647.18844-5-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 21 Nov 2018 22:07:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 04/30] slirp: simplify fork_exec() 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Use g_spawn_async_with_fds() to setup the child. GSpawn handles reaping the child, and closing parent file descriptors. Signed-off-by: Marc-André Lureau --- slirp/misc.c | 75 +++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/slirp/misc.c b/slirp/misc.c index ee3492a2ae..753b3da25b 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -129,56 +129,53 @@ err: return -1; } +static void +fork_exec_child_setup(gpointer data) +{ + setsid(); +} + int fork_exec(struct socket *so, const char *ex) { - char **argv; - int opt, c, sp[2]; - pid_t pid; + GError *err = NULL; + char **argv; + int opt, sp[2]; - DEBUG_CALL("fork_exec"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("ex = %p", ex); + DEBUG_CALL("fork_exec"); + DEBUG_ARG("so = %p", so); + DEBUG_ARG("ex = %p", ex); if (slirp_socketpair_with_oob(sp) < 0) { return 0; } - pid = fork(); - switch(pid) { - case -1: - error_report("Error: fork failed: %s", strerror(errno)); - closesocket(sp[0]); - closesocket(sp[1]); - return 0; - - case 0: - setsid(); - dup2(sp[1], 0); - dup2(sp[1], 1); - dup2(sp[1], 2); - for (c = getdtablesize() - 1; c >= 3; c--) - close(c); + argv = g_strsplit(ex, " ", -1); + g_spawn_async_with_fds(NULL /* cwd */, + argv, + NULL /* env */, + G_SPAWN_SEARCH_PATH, + fork_exec_child_setup, NULL /* data */, + NULL /* child_pid */, + sp[1], sp[1], sp[1], + &err); + g_strfreev(argv); - argv = g_strsplit(ex, " ", -1); - execvp(argv[0], (char **)argv); - - /* Ooops, failed, let's tell the user why */ - fprintf(stderr, "Error: execvp of %s failed: %s\n", - argv[0], strerror(errno)); - close(0); close(1); close(2); /* XXX */ - exit(1); + if (err) { + error_report("%s", err->message); + g_error_free(err); + closesocket(sp[0]); + closesocket(sp[1]); + return 0; + } - default: - so->s = sp[0]; - closesocket(sp[1]); - qemu_add_child_watch(pid); - socket_set_fast_reuse(so->s); - opt = 1; - qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); - qemu_set_nonblock(so->s); - return 1; - } + so->s = sp[0]; + closesocket(sp[1]); + socket_set_fast_reuse(so->s); + opt = 1; + qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); + qemu_set_nonblock(so->s); + return 1; } #endif From patchwork Wed Nov 21 22:06:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001433 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cKv5H6Cz9s29 for ; Thu, 22 Nov 2018 09:13:55 +1100 (AEDT) Received: from localhost ([::1]:42591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPakr-00018S-AU for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:13:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPaem-0003si-6W for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPaei-0001fQ-5G for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPaeh-0001ZR-UF for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:32 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C0CB73084032; Wed, 21 Nov 2018 22:07:29 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59AC0648BA; Wed, 21 Nov 2018 22:07:26 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:22 +0400 Message-Id: <20181121220647.18844-6-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 21 Nov 2018 22:07:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 05/30] slirp: rename exec_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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This list is not only used to handle command to execute on guest connection, it can also redirect to an arbitrary object, such as a chardev. Let's rename the struct and the field to "guestfwd". Signed-off-by: Marc-André Lureau --- slirp/misc.h | 6 +++--- slirp/slirp.h | 2 +- slirp/misc.c | 6 +++--- slirp/slirp.c | 18 +++++++++--------- slirp/tcp_input.c | 6 +++--- slirp/tcp_subr.c | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/slirp/misc.h b/slirp/misc.h index 0bc5e74bc5..1df707c052 100644 --- a/slirp/misc.h +++ b/slirp/misc.h @@ -8,12 +8,12 @@ #ifndef MISC_H #define MISC_H -struct ex_list { +struct gfwd_list { void *ex_chardev; struct in_addr ex_addr; /* Server address */ int ex_fport; /* Port to telnet to */ char *ex_exec; /* Command line of what to exec */ - struct ex_list *ex_next; + struct gfwd_list *ex_next; }; #define EMU_NONE 0x0 @@ -51,7 +51,7 @@ struct slirp_quehead { void slirp_insque(void *, void *); void slirp_remque(void *); -int add_exec(struct ex_list **, void *, const char *, struct in_addr, int); +int add_exec(struct gfwd_list **, void *, const char *, struct in_addr, int); int fork_exec(struct socket *so, const char *ex); #endif diff --git a/slirp/slirp.h b/slirp/slirp.h index fdf397256b..9aa245715d 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -147,7 +147,7 @@ struct Slirp { char client_hostname[33]; int restricted; - struct ex_list *exec_list; + struct gfwd_list *guestfwd_list; /* mbuf states */ struct quehead m_freelist; diff --git a/slirp/misc.c b/slirp/misc.c index 753b3da25b..cf7cc3a787 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -36,10 +36,10 @@ remque(void *a) element->qh_rlink = NULL; } -int add_exec(struct ex_list **ex_ptr, void *chardev, const char *cmdline, +int add_exec(struct gfwd_list **ex_ptr, void *chardev, const char *cmdline, struct in_addr addr, int port) { - struct ex_list *tmp_ptr; + struct gfwd_list *tmp_ptr; /* First, check if the port is "bound" */ for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) { @@ -49,7 +49,7 @@ int add_exec(struct ex_list **ex_ptr, void *chardev, const char *cmdline, } tmp_ptr = *ex_ptr; - *ex_ptr = g_new0(struct ex_list, 1); + *ex_ptr = g_new0(struct gfwd_list, 1); (*ex_ptr)->ex_fport = port; (*ex_ptr)->ex_addr = addr; if (chardev) { diff --git a/slirp/slirp.c b/slirp/slirp.c index 8da528afaa..4949d17c73 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -345,9 +345,9 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork, void slirp_cleanup(Slirp *slirp) { - struct ex_list *e, *next; + struct gfwd_list *e, *next; - for (e = slirp->exec_list; e; e = next) { + for (e = slirp->guestfwd_list; e; e = next) { next = e->ex_next; g_free(e->ex_exec); g_free(e); @@ -760,7 +760,7 @@ static void arp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) struct ethhdr *reh = (struct ethhdr *)arp_reply; struct slirp_arphdr *rah = (struct slirp_arphdr *)(arp_reply + ETH_HLEN); int ar_op; - struct ex_list *ex_ptr; + struct gfwd_list *ex_ptr; if (!slirp->in_enabled) { return; @@ -780,7 +780,7 @@ static void arp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) if (ah->ar_tip == slirp->vnameserver_addr.s_addr || ah->ar_tip == slirp->vhost_addr.s_addr) goto arp_ok; - for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { + for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { if (ex_ptr->ex_addr.s_addr == ah->ar_tip) goto arp_ok; } @@ -1052,7 +1052,7 @@ int slirp_add_exec(Slirp *slirp, void *chardev, const char *cmdline, return -1; } - return add_exec(&slirp->exec_list, chardev, cmdline, *guest_addr, + return add_exec(&slirp->guestfwd_list, chardev, cmdline, *guest_addr, htons(guest_port)); } @@ -1423,9 +1423,9 @@ static const VMStateDescription vmstate_slirp = { static void slirp_state_save(QEMUFile *f, void *opaque) { Slirp *slirp = opaque; - struct ex_list *ex_ptr; + struct gfwd_list *ex_ptr; - for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) + for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) if (ex_ptr->ex_chardev) { struct socket *so; so = slirp_find_ctl_socket(slirp, ex_ptr->ex_addr, @@ -1445,7 +1445,7 @@ static void slirp_state_save(QEMUFile *f, void *opaque) static int slirp_state_load(QEMUFile *f, void *opaque, int version_id) { Slirp *slirp = opaque; - struct ex_list *ex_ptr; + struct gfwd_list *ex_ptr; while (qemu_get_byte(f)) { int ret; @@ -1460,7 +1460,7 @@ static int slirp_state_load(QEMUFile *f, void *opaque, int version_id) slirp->vnetwork_addr.s_addr) { return -EINVAL; } - for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { + for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { if (ex_ptr->ex_chardev && so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr && so->so_fport == ex_ptr->ex_fport) { diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c index b67ec24075..bc4aa60046 100644 --- a/slirp/tcp_input.c +++ b/slirp/tcp_input.c @@ -211,7 +211,7 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *inso, unsigned short af) struct sockaddr_storage lhost, fhost; struct sockaddr_in *lhost4, *fhost4; struct sockaddr_in6 *lhost6, *fhost6; - struct ex_list *ex_ptr; + struct gfwd_list *ex_ptr; Slirp *slirp; DEBUG_CALL("tcp_input"); @@ -394,7 +394,7 @@ findso: * for non-hostfwd connections. These should be dropped, unless it * happens to be a guestfwd. */ - for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { + for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { if (ex_ptr->ex_fport == ti->ti_dport && ti->ti_dst.s_addr == ex_ptr->ex_addr.s_addr) { break; @@ -616,7 +616,7 @@ findso: if (so->so_faddr.s_addr != slirp->vhost_addr.s_addr && so->so_faddr.s_addr != slirp->vnameserver_addr.s_addr) { /* May be an add exec */ - for (ex_ptr = slirp->exec_list; ex_ptr; + for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { if(ex_ptr->ex_fport == so->so_fport && so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr) { diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 00cee73163..3b14684107 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -949,14 +949,14 @@ int tcp_ctl(struct socket *so) { Slirp *slirp = so->slirp; struct sbuf *sb = &so->so_snd; - struct ex_list *ex_ptr; + struct gfwd_list *ex_ptr; DEBUG_CALL("tcp_ctl"); DEBUG_ARG("so = %p", so); if (so->so_faddr.s_addr != slirp->vhost_addr.s_addr) { /* Check if it's pty_exec */ - for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { + for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { if (ex_ptr->ex_fport == so->so_fport && so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr) { if (ex_ptr->ex_chardev) { From patchwork Wed Nov 21 22:06:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cKM2H5Fz9s29 for ; Thu, 22 Nov 2018 09:13:27 +1100 (AEDT) Received: from localhost ([::1]:42586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPakP-0000Uh-00 for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:13:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50547) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPaeq-0003vH-33 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPaeo-0001iq-9j for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48336) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPaeo-0001iU-4x for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:38 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 613E23082AFC; Wed, 21 Nov 2018 22:07:37 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDACF6A51B; Wed, 21 Nov 2018 22:07:33 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:23 +0400 Message-Id: <20181121220647.18844-7-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 21 Nov 2018 22:07:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 06/30] slirp: factor out guestfwd addition checks 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This will allow reusing the function in a following patch. Signed-off-by: Marc-André Lureau --- slirp/misc.c | 7 ------- slirp/slirp.c | 23 +++++++++++++++++++++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/slirp/misc.c b/slirp/misc.c index cf7cc3a787..03bfa31f20 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -41,13 +41,6 @@ int add_exec(struct gfwd_list **ex_ptr, void *chardev, const char *cmdline, { struct gfwd_list *tmp_ptr; - /* First, check if the port is "bound" */ - for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) { - if (port == tmp_ptr->ex_fport && - addr.s_addr == tmp_ptr->ex_addr.s_addr) - return -1; - } - tmp_ptr = *ex_ptr; *ex_ptr = g_new0(struct gfwd_list, 1); (*ex_ptr)->ex_fport = port; diff --git a/slirp/slirp.c b/slirp/slirp.c index 4949d17c73..e7256ec05c 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -1038,9 +1038,11 @@ int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, return 0; } -int slirp_add_exec(Slirp *slirp, void *chardev, const char *cmdline, - struct in_addr *guest_addr, int guest_port) +static bool +check_guestfwd(Slirp *slirp, struct in_addr *guest_addr, int guest_port) { + struct gfwd_list *tmp_ptr; + if (!guest_addr->s_addr) { guest_addr->s_addr = slirp->vnetwork_addr.s_addr | (htonl(0x0204) & ~slirp->vnetwork_mask.s_addr); @@ -1049,6 +1051,23 @@ int slirp_add_exec(Slirp *slirp, void *chardev, const char *cmdline, slirp->vnetwork_addr.s_addr || guest_addr->s_addr == slirp->vhost_addr.s_addr || guest_addr->s_addr == slirp->vnameserver_addr.s_addr) { + return false; + } + + /* check if the port is "bound" */ + for (tmp_ptr = slirp->guestfwd_list; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) { + if (guest_port == tmp_ptr->ex_fport && + guest_addr->s_addr == tmp_ptr->ex_addr.s_addr) + return false; + } + + return true; +} + +int slirp_add_exec(Slirp *slirp, void *chardev, const char *cmdline, + struct in_addr *guest_addr, int guest_port) +{ + if (!check_guestfwd(slirp, guest_addr, guest_port)) { return -1; } From patchwork Wed Nov 21 22:06:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cNf0l26z9s3C for ; Thu, 22 Nov 2018 09:16:18 +1100 (AEDT) Received: from localhost ([::1]:42604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPan9-0003ca-Kz for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:16:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPaf1-00049o-03 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPaew-0001sT-Tk for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53196) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPaew-0001qt-Kp for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:46 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA3C2C0587EC; Wed, 21 Nov 2018 22:07:45 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E2986A6B2; Wed, 21 Nov 2018 22:07:40 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:24 +0400 Message-Id: <20181121220647.18844-8-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 21 Nov 2018 22:07:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 07/30] 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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é Lureau --- slirp/libslirp.h | 6 +++++- slirp/misc.h | 15 +++++++++++++-- slirp/socket.h | 4 +++- net/slirp.c | 14 ++++++++++---- slirp/misc.c | 37 +++++++++++++++++++++++-------------- slirp/slirp.c | 27 +++++++++++++++++++-------- slirp/tcp_subr.c | 4 ++-- 7 files changed, 75 insertions(+), 32 deletions(-) diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 3e0aa19f4b..d7c2b1ae71 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -5,6 +5,8 @@ typedef struct Slirp Slirp; +typedef int (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); + /* * Callbacks from slirp * @@ -43,7 +45,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); char *slirp_connection_info(Slirp *slirp); 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 +#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 { void slirp_insque(void *, void *); void slirp_remque(void *); -int add_exec(struct gfwd_list **, void *, const char *, struct in_addr, int); int fork_exec(struct socket *so, const char *ex); +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/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 +#include "misc.h" + #define SO_EXPIRE 240000 #define SO_EXPIREFAST 10000 @@ -25,6 +27,7 @@ struct socket { struct socket *so_next,*so_prev; /* For a linked list of sockets */ int s; /* The actual socket */ + struct gfwd_list *guestfwd; int pollfds_idx; /* GPollFD GArray index */ @@ -67,7 +70,6 @@ struct socket { struct sbuf so_rcv; /* Receive buffer */ struct sbuf so_snd; /* Send buffer */ - void * chardev; }; diff --git a/net/slirp.c b/net/slirp.c index 4d890287ba..53adb92dd5 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -698,8 +698,8 @@ static int slirp_smb(SlirpState* s, const char *exported_dir, CONFIG_SMBD_COMMAND, s->smb_dir, smb_conf); g_free(smb_conf); - 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"); @@ -730,6 +730,11 @@ static void guestfwd_read(void *opaque, const uint8_t *buf, int size) slirp_socket_recv(fwd->slirp, fwd->server, fwd->port, buf, size); } +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 **errp) { struct in_addr server = { .s_addr = 0 }; @@ -763,7 +768,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **errp) snprintf(buf, sizeof(buf), "guestfwd.tcp.%d", port); 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; @@ -790,7 +795,8 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **errp) return -1; } - 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/misc.c b/slirp/misc.c index 03bfa31f20..7c2ed8c67f 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -36,24 +36,33 @@ remque(void *a) element->qh_rlink = NULL; } -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 = *ex_ptr; - *ex_ptr = g_new0(struct gfwd_list, 1); - (*ex_ptr)->ex_fport = port; - (*ex_ptr)->ex_addr = addr; - if (chardev) { - (*ex_ptr)->ex_chardev = chardev; - } else { - (*ex_ptr)->ex_exec = g_strdup(cmdline); - } - (*ex_ptr)->ex_next = tmp_ptr; - return 0; + struct gfwd_list *f = g_new0(struct gfwd_list, 1); + + f->write_cb = write_cb; + f->opaque = opaque; + f->ex_fport = port; + f->ex_addr = addr; + f->ex_next = *ex_ptr; + *ex_ptr = f; + + return f; } +struct gfwd_list * +add_exec(struct gfwd_list **ex_ptr, const char *cmdline, + struct in_addr addr, int port) +{ + struct gfwd_list *f = add_guestfwd(ex_ptr, NULL, NULL, addr, port); + + f->ex_exec = g_strdup(cmdline); + + return f; +} #ifdef _WIN32 diff --git a/slirp/slirp.c b/slirp/slirp.c index e7256ec05c..cc361885ed 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" @@ -1064,23 +1063,35 @@ check_guestfwd(Slirp *slirp, struct in_addr *guest_addr, int guest_port) return true; } -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; } - 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; } ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags) { - if (so->s == -1 && so->chardev) { + if (so->s == -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; } @@ -1445,7 +1456,7 @@ static void slirp_state_save(QEMUFile *f, void *opaque) struct gfwd_list *ex_ptr; for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) - if (ex_ptr->ex_chardev) { + if (ex_ptr->write_cb) { struct socket *so; so = slirp_find_ctl_socket(slirp, ex_ptr->ex_addr, ntohs(ex_ptr->ex_fport)); @@ -1480,7 +1491,7 @@ static int slirp_state_load(QEMUFile *f, void *opaque, int version_id) return -EINVAL; } for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { - if (ex_ptr->ex_chardev && + if (ex_ptr->write_cb && so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr && so->so_fport == ex_ptr->ex_fport) { break; diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 3b14684107..042fa1e4fb 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -959,9 +959,9 @@ int tcp_ctl(struct socket *so) for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { if (ex_ptr->ex_fport == so->so_fport && so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr) { - if (ex_ptr->ex_chardev) { + if (ex_ptr->write_cb) { so->s = -1; - so->chardev = ex_ptr->ex_chardev; + so->guestfwd = ex_ptr; return 1; } DEBUG_MISC(" executing %s\n", ex_ptr->ex_exec); From patchwork Wed Nov 21 22:06:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cSd5ssYz9s29 for ; Thu, 22 Nov 2018 09:19:45 +1100 (AEDT) Received: from localhost ([::1]:42616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPaqV-0006mG-3Y for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:19:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPaf3-0004DV-OS for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPaf2-00020i-15 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55054) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPaf1-0001zf-Rj for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:51 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C6F0394D54; Wed, 21 Nov 2018 22:07:51 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7AD1298C9; Wed, 21 Nov 2018 22:07:49 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:25 +0400 Message-Id: <20181121220647.18844-9-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 21 Nov 2018 22:07:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 08/30] 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Marc-André Lureau --- net/slirp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/slirp.c b/net/slirp.c index 53adb92dd5..9f07923925 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -767,7 +767,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **errp) snprintf(buf, sizeof(buf), "guestfwd.tcp.%d", port); - 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); From patchwork Wed Nov 21 22:06:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cD120t5z9s29 for ; Thu, 22 Nov 2018 09:08:49 +1100 (AEDT) Received: from localhost ([::1]:42562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPafu-0004Zw-U0 for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:08:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPafD-0004Wj-IX for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPaf9-0002AE-GF for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48504) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPaf8-00028e-MG for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:07:59 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03F4630024F0; Wed, 21 Nov 2018 22:07:58 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id F25EE5D75C; Wed, 21 Nov 2018 22:07:54 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:26 +0400 Message-Id: <20181121220647.18844-10-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 21 Nov 2018 22:07:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 09/30] net/slirp: fix a few memory leaks 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Handle chardev removal on failure to register the forward rule. Free all the guestfwd data on cleanup. Signed-off-by: Marc-André Lureau --- net/slirp.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 9f07923925..6eeb54d7b1 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -75,6 +75,13 @@ struct slirp_config_str { char str[1024]; }; +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; static struct slirp_config_str *slirp_configs; @@ -122,10 +130,19 @@ static void slirp_smb_exit(Notifier *n, void *data) slirp_smb_cleanup(s); } +static void slirp_free_fwd(gpointer data) +{ + struct GuestFwd *fwd = data; + + qemu_chr_fe_deinit(&fwd->hd, true); + g_free(data); +} + static void net_slirp_cleanup(NetClientState *nc) { SlirpState *s = DO_UPCAST(SlirpState, nc, nc); + 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); @@ -711,13 +728,6 @@ static int slirp_smb(SlirpState* s, const char *exported_dir, #endif /* !defined(_WIN32) */ -struct GuestFwd { - CharBackend hd; - struct in_addr server; - int port; - Slirp *slirp; -}; - static int guestfwd_can_read(void *opaque) { struct GuestFwd *fwd = opaque; @@ -791,6 +801,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_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; } @@ -799,6 +810,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_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; } @@ -808,6 +820,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **errp) qemu_chr_fe_set_handlers(&fwd->hd, guestfwd_can_read, guestfwd_read, NULL, NULL, fwd, NULL, true); + s->fwd = g_slist_append(s->fwd, fwd); } return 0; From patchwork Wed Nov 21 22:06:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cGG1rfVz9s3C for ; Thu, 22 Nov 2018 09:10:46 +1100 (AEDT) Received: from localhost ([::1]:42570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPahn-0006V7-SI for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:10:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50756) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPafI-0004ld-26 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPafH-0002FU-8L for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43752) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPafH-0002F7-3O for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:07 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68D5888314; Wed, 21 Nov 2018 22:08:06 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 015A25C21E; Wed, 21 Nov 2018 22:08:01 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:27 +0400 Message-Id: <20181121220647.18844-11-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 21 Nov 2018 22:08:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 10/30] slirp: use virtual time for packet expiration 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Paolo Bonzini , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Make all packets expiration time based on virtual clock. Suggested-by: Paolo Bonzini Signed-off-by: Marc-André Lureau --- slirp/if.c | 2 +- slirp/slirp.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/slirp/if.c b/slirp/if.c index aa88cc4e76..ce4f5fac53 100644 --- a/slirp/if.c +++ b/slirp/if.c @@ -148,7 +148,7 @@ diddit: */ void if_start(Slirp *slirp) { - uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); + uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); bool from_batchq = false; struct mbuf *ifm, *ifm_next, *ifqt; diff --git a/slirp/slirp.c b/slirp/slirp.c index cc361885ed..9ace0e3d4b 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -581,7 +581,7 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error) return; } - curtime = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + curtime = qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL); QTAILQ_FOREACH(slirp, &slirp_instances, entry) { /* @@ -908,7 +908,8 @@ static int if_encap4(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh, ifm->resolution_requested = true; /* Expire request and drop outgoing packet after 1 second */ - ifm->expiration_date = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + 1000000000ULL; + ifm->expiration_date = + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 1000000000ULL; } return 0; } else { @@ -935,7 +936,7 @@ static int if_encap6(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh, ndp_send_ns(slirp, ip6h->ip_dst); ifm->resolution_requested = true; ifm->expiration_date = - qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + 1000000000ULL; + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 1000000000ULL; } return 0; } else { From patchwork Wed Nov 21 22:06:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cXC1P9lz9s29 for ; Thu, 22 Nov 2018 09:22:51 +1100 (AEDT) Received: from localhost ([::1]:42634 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPatU-0000ke-RS for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:22:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPafV-0004wy-22 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPafQ-0002JW-CH for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46130) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPafQ-0002Ih-5P for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:16 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F16A881DF0; Wed, 21 Nov 2018 22:08:13 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3866F84F3; Wed, 21 Nov 2018 22:08:09 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:28 +0400 Message-Id: <20181121220647.18844-12-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 21 Nov 2018 22:08:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 11/30] slirp: add clock_get_ns() 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Marc-André Lureau --- slirp/libslirp.h | 2 ++ net/slirp.c | 6 ++++++ slirp/if.c | 2 +- slirp/ip6_icmp.c | 4 ++-- slirp/slirp.c | 12 +++++------- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/slirp/libslirp.h b/slirp/libslirp.h index d7c2b1ae71..ea019828e8 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -17,6 +17,8 @@ typedef struct SlirpCb { 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); } SlirpCb; diff --git a/net/slirp.c b/net/slirp.c index 6eeb54d7b1..c7062b51c2 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -163,9 +163,15 @@ static void net_slirp_guest_error(const char *msg) qemu_log_mask(LOG_GUEST_ERROR, "%s", msg); } +static int64_t net_slirp_clock_get_ns(void) +{ + return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); +} + static const SlirpCb slirp_cb = { .output = net_slirp_output, .guest_error = net_slirp_guest_error, + .clock_get_ns = net_slirp_clock_get_ns, }; static int net_slirp_init(NetClientState *peer, const char *model, diff --git a/slirp/if.c b/slirp/if.c index ce4f5fac53..73e3705740 100644 --- a/slirp/if.c +++ b/slirp/if.c @@ -148,7 +148,7 @@ diddit: */ void if_start(Slirp *slirp) { - uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + uint64_t now = slirp->cb->clock_get_ns(); bool from_batchq = false; struct mbuf *ifm, *ifm_next, *ifqt; diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 595a62c8d4..6e2d952f17 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -17,7 +17,7 @@ static void ra_timer_handler(void *opaque) { Slirp *slirp = opaque; timer_mod(slirp->ra_timer, - qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval); + slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interval); ndp_send_ra(slirp); } @@ -31,7 +31,7 @@ void icmp6_init(Slirp *slirp) SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL, ra_timer_handler, slirp); timer_mod(slirp->ra_timer, - qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval); + slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interval); } void icmp6_cleanup(Slirp *slirp) diff --git a/slirp/slirp.c b/slirp/slirp.c index 9ace0e3d4b..76b1f2f3e0 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -573,15 +573,15 @@ void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout) void slirp_pollfds_poll(GArray *pollfds, int select_error) { - Slirp *slirp; + Slirp *slirp = QTAILQ_FIRST(&slirp_instances); struct socket *so, *so_next; int ret; - if (QTAILQ_EMPTY(&slirp_instances)) { + if (!slirp) { return; } - curtime = qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL); + curtime = slirp->cb->clock_get_ns() / SCALE_MS; QTAILQ_FOREACH(slirp, &slirp_instances, entry) { /* @@ -908,8 +908,7 @@ static int if_encap4(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh, ifm->resolution_requested = true; /* Expire request and drop outgoing packet after 1 second */ - ifm->expiration_date = - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 1000000000ULL; + ifm->expiration_date = slirp->cb->clock_get_ns() + 1000000000ULL; } return 0; } else { @@ -935,8 +934,7 @@ static int if_encap6(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh, if (!ifm->resolution_requested) { ndp_send_ns(slirp, ip6h->ip_dst); ifm->resolution_requested = true; - ifm->expiration_date = - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 1000000000ULL; + ifm->expiration_date = slirp->cb->clock_get_ns() + 1000000000ULL; } return 0; } else { From patchwork Wed Nov 21 22:06:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cKZ1ZB5z9s29 for ; Thu, 22 Nov 2018 09:13:38 +1100 (AEDT) Received: from localhost ([::1]:42588 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPakZ-0000ta-OA for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:13:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPafZ-00050r-MU for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPafY-0002MK-99 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41128) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPafY-0002Lf-22 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:24 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C98E308FE94; Wed, 21 Nov 2018 22:08:22 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 094EC57B0; Wed, 21 Nov 2018 22:08:17 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:29 +0400 Message-Id: <20181121220647.18844-13-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 21 Nov 2018 22:08:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 12/30] 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Marc-André Lureau --- slirp/libslirp.h | 14 +++++++++++--- slirp/slirp.h | 2 +- net/slirp.c | 21 +++++++++++++++++++++ slirp/ip6_icmp.c | 16 +++++++--------- 4 files changed, 40 insertions(+), 13 deletions(-) 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; typedef int (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); +typedef void (*SlirpTimerCb)(void *opaque); /* * Callbacks from slirp - * - * The opaque parameter comes from the opaque parameter given to slirp_init(). */ 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; 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; GRand *grand; - QEMUTimer *ra_timer; + void *ra_timer; const SlirpCb *cb; void *opaque; diff --git a/net/slirp.c b/net/slirp.c index c7062b51c2..f7cdf8398b 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); } +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 = { .output = net_slirp_output, .guest_error = net_slirp_guest_error, .clock_get_ns = net_slirp_clock_get_ns, + .timer_new = net_slirp_timer_new, + .timer_free = net_slirp_timer_free, + .timer_mod = net_slirp_timer_mod, }; static int net_slirp_init(NetClientState *peer, const char *model, diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 6e2d952f17..0acdcc26a2 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -16,8 +16,9 @@ static void ra_timer_handler(void *opaque) { Slirp *slirp = 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_Interval); ndp_send_ra(slirp); } @@ -27,11 +28,9 @@ void icmp6_init(Slirp *slirp) return; } - slirp->ra_timer = 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 = slirp->cb->timer_new(ra_timer_handler, slirp); + slirp->cb->timer_mod(slirp->ra_timer, + slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interval); } void icmp6_cleanup(Slirp *slirp) @@ -40,8 +39,7 @@ void icmp6_cleanup(Slirp *slirp) return; } - timer_del(slirp->ra_timer); - timer_free(slirp->ra_timer); + slirp->cb->timer_free(slirp->ra_timer); } static void icmp6_send_echoreply(struct mbuf *m, Slirp *slirp, struct ip6 *ip, From patchwork Wed Nov 21 22:06:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001447 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cc02RT3z9s29 for ; Thu, 22 Nov 2018 09:26:08 +1100 (AEDT) Received: from localhost ([::1]:42652 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPawf-0003zE-Ln for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:26:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPafl-0005MB-7q for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPaff-0002W1-BH for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41164) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPaff-0002UT-2S for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:31 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62DDA307CDD0; Wed, 21 Nov 2018 22:08:30 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4276648BA; Wed, 21 Nov 2018 22:08:26 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:30 +0400 Message-Id: <20181121220647.18844-14-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 21 Nov 2018 22:08:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 13/30] build-sys: use a seperate slirp-obj-y && slirp.mo 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This will allow to have cflags for the whole slirp.mo -objs. It makes it possible to build tests that links only with slirp-obj-y (and not the whole common-obj). It is also a step towards building slirp as a shared library, although this requires a bit more thoughts to build with net/slirp.o (CONFIG_SLIRP would need to be 'm') and other build issues. Signed-off-by: Marc-André Lureau --- Makefile.objs | 3 +-- Makefile.target | 5 ++++- slirp/Makefile.objs | 35 ++++++++++++++++++++++++++++++----- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index 31852eaf8f..a11050a7aa 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -61,6 +61,7 @@ util-obj-y += qapi/qapi-events-ui.o util-obj-y += qapi/qapi-introspect.o chardev-obj-y = chardev/ +slirp-obj-$(CONFIG_SLIRP) = slirp/ ####################################################################### # block-obj-y is code used by both qemu system emulation and qemu-img @@ -123,8 +124,6 @@ common-obj-y += vl.o vl.o-cflags := $(GPROF_CFLAGS) $(SDL_CFLAGS) common-obj-$(CONFIG_TPM) += tpm.o -common-obj-$(CONFIG_SLIRP) += slirp/ - common-obj-y += backends/ common-obj-y += chardev/ diff --git a/Makefile.target b/Makefile.target index 4d56298bbf..3a970b1b77 100644 --- a/Makefile.target +++ b/Makefile.target @@ -168,6 +168,7 @@ target-obj-y := block-obj-y := common-obj-y := chardev-obj-y := +slirp-obj-y := include $(SRC_PATH)/Makefile.objs dummy := $(call unnest-vars,,target-obj-y) target-obj-y-save := $(target-obj-y) @@ -180,9 +181,11 @@ dummy := $(call unnest-vars,.., \ qom-obj-y \ io-obj-y \ common-obj-y \ - common-obj-m) + common-obj-m \ + slirp-obj-y) target-obj-y := $(target-obj-y-save) all-obj-y += $(common-obj-y) +all-obj-y += $(slirp-obj-y) all-obj-y += $(target-obj-y) all-obj-y += $(qom-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y) diff --git a/slirp/Makefile.objs b/slirp/Makefile.objs index 28049b03cd..21653f69e9 100644 --- a/slirp/Makefile.objs +++ b/slirp/Makefile.objs @@ -1,5 +1,30 @@ -common-obj-y = cksum.o if.o ip_icmp.o ip6_icmp.o ip6_input.o ip6_output.o \ - ip_input.o ip_output.o dnssearch.o dhcpv6.o -common-obj-y += slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o -common-obj-y += tcp_subr.o tcp_timer.o udp.o udp6.o bootp.o tftp.o arp_table.o \ - ndp_table.o ncsi.o +slirp-obj-y = slirp.mo + +slirp.mo-objs = \ + arp_table.o \ + bootp.o \ + cksum.o \ + dhcpv6.o \ + dnssearch.o \ + if.o \ + ip6_icmp.o \ + ip6_input.o \ + ip6_output.o \ + ip_icmp.o \ + ip_input.o \ + ip_output.o \ + mbuf.o \ + misc.o \ + ncsi.o \ + ndp_table.o \ + sbuf.o \ + slirp.o \ + socket.o \ + tcp_input.o \ + tcp_output.o \ + tcp_subr.o \ + tcp_timer.o \ + tftp.o \ + udp.o \ + udp6.o \ + $(NULL) From patchwork Wed Nov 21 22:06:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001436 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cNx47cLz9s29 for ; Thu, 22 Nov 2018 09:16:33 +1100 (AEDT) Received: from localhost ([::1]:42606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPanP-0003mn-8D for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:16:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPafv-0005UH-3A for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPafp-0002uD-5j for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37262) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPafn-0002oP-6D for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:41 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EFE9B3164672; Wed, 21 Nov 2018 22:08:37 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F18F17D23; Wed, 21 Nov 2018 22:08:33 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:31 +0400 Message-Id: <20181121220647.18844-15-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 21 Nov 2018 22:08:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 14/30] slirp: set G_LOG_DOMAIN 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We are moving to g_log() facilities to log errors and probably debug messages too. Let's have the "Slirp" prefix on messages slirp produces. Signed-off-by: Marc-André Lureau --- slirp/Makefile.objs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/slirp/Makefile.objs b/slirp/Makefile.objs index 21653f69e9..959558c732 100644 --- a/slirp/Makefile.objs +++ b/slirp/Makefile.objs @@ -28,3 +28,5 @@ slirp.mo-objs = \ udp.o \ udp6.o \ $(NULL) + +slirp.mo-cflags = -DG_LOG_DOMAIN=\"Slirp\" From patchwork Wed Nov 21 22:06:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cgQ4V07z9s29 for ; Thu, 22 Nov 2018 09:29:06 +1100 (AEDT) Received: from localhost ([::1]:42665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPazY-00073Z-6b for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:29:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPafw-0005Vb-BH for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPafv-0002zw-Aq for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46412) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPafv-0002yZ-2D for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:47 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 82F4B7F6C5; Wed, 21 Nov 2018 22:08:45 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09F7310002B9; Wed, 21 Nov 2018 22:08:41 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:32 +0400 Message-Id: <20181121220647.18844-16-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 21 Nov 2018 22:08:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 15/30] slirp: replace error_report() and a fprintf with g_critical() 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Reduce dependency on QEMU. QEMU could use a custom glib log handler if it wants to redirect/filter it. Signed-off-by: Marc-André Lureau --- slirp/misc.c | 2 +- slirp/socket.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/slirp/misc.c b/slirp/misc.c index 7c2ed8c67f..6ee0ff0231 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -164,7 +164,7 @@ fork_exec(struct socket *so, const char *ex) g_strfreev(argv); if (err) { - error_report("%s", err->message); + g_critical("fork_exec: %s", err->message); g_error_free(err); closesocket(sp[0]); closesocket(sp[1]); diff --git a/slirp/socket.c b/slirp/socket.c index 677fd20c9d..08a065f6a7 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -285,7 +285,7 @@ err: sofcantrcvmore(so); tcp_sockclosed(sototcpcb(so)); - fprintf(stderr, "soreadbuf buffer to small"); + g_critical("soreadbuf buffer too small"); return -1; } From patchwork Wed Nov 21 22:06:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001441 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cVg0qXsz9s3C for ; Thu, 22 Nov 2018 09:21:31 +1100 (AEDT) Received: from localhost ([::1]:42629 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPasC-00087N-NH for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:21:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPag5-0005bR-DG for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPag1-0003D0-DE for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46096) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPag1-0003Ap-7w for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:08:53 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87457308429E; Wed, 21 Nov 2018 22:08:52 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 738ED6013F; Wed, 21 Nov 2018 22:08:49 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:33 +0400 Message-Id: <20181121220647.18844-17-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 21 Nov 2018 22:08:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 16/30] slirp: replace some fprintf() with DEBUG_MISC 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Remove some clutter, and avoids direct call to fprintf(). Signed-off-by: Marc-André Lureau --- slirp/slirp.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/slirp/slirp.c b/slirp/slirp.c index 76b1f2f3e0..432adb02c4 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -163,9 +163,7 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, if (!f) return -1; -#ifdef DEBUG - fprintf(stderr, "IP address of your DNS(s): "); -#endif + DEBUG_MISC("IP address of your DNS(s): "); while (fgets(buff, 512, f) != NULL) { if (sscanf(buff, "nameserver%*[ \t]%256s", buff2) == 1) { char *c = strchr(buff2, '%'); @@ -187,15 +185,12 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, *scope_id = if_index; } *cached_time = curtime; + } else { + DEBUG_MISC(", "); } -#ifdef DEBUG - else - fprintf(stderr, ", "); -#endif + if (++found > 3) { -#ifdef DEBUG - fprintf(stderr, "(more)"); -#endif + DEBUG_MISC("(more)"); break; } #ifdef DEBUG @@ -205,7 +200,7 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, if (!res) { res = "(string conversion error)"; } - fprintf(stderr, "%s", res); + DEBUG_MISC("%s", res); } #endif } From patchwork Wed Nov 21 22:06:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cJ64R8hz9s29 for ; Thu, 22 Nov 2018 09:12:22 +1100 (AEDT) Received: from localhost ([::1]:42583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPajM-0007yU-6X for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:12:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPagD-0005jH-Ll for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPag9-0003ba-7d for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46520) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPag8-0003Zm-VK for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5F0489ACC; Wed, 21 Nov 2018 22:08:59 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C32D9F7A; Wed, 21 Nov 2018 22:08:56 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:34 +0400 Message-Id: <20181121220647.18844-18-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 21 Nov 2018 22:08:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 17/30] slirp: replace a DEBUG block with WITH_ICMP_ERROR_MSG 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" icmp_send_error() doesnt actually log messages when DEBUG is enabled. Let's use a different define that describes better the tweaked behaviour of the function, and avoid uncompiled code. Signed-off-by: Marc-André Lureau --- slirp/ip_icmp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index af11cfcefe..6c7e375ff8 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -34,6 +34,10 @@ #include "slirp.h" #include "ip_icmp.h" +#ifndef WITH_ICMP_ERROR_MSG +#define WITH_ICMP_ERROR_MSG 0 +#endif + /* The message sent when emulating PING */ /* Be nice and tell them it's just a pseudo-ping packet */ static const char icmp_ping_msg[] = "This is a pseudo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n"; @@ -319,8 +323,7 @@ icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int minsize, HTONS(icp->icmp_ip.ip_id); HTONS(icp->icmp_ip.ip_off); -#ifdef DEBUG - if(message) { /* DEBUG : append message to ICMP packet */ + if (message && WITH_ICMP_ERROR_MSG) { /* append message to ICMP packet */ int message_len; char *cpnt; message_len=strlen(message); @@ -329,7 +332,6 @@ icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int minsize, memcpy(cpnt, message, message_len); m->m_len+=message_len; } -#endif icp->icmp_cksum = 0; icp->icmp_cksum = cksum(m, m->m_len); From patchwork Wed Nov 21 22:06:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001434 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cMM0K3cz9s29 for ; Thu, 22 Nov 2018 09:15:11 +1100 (AEDT) Received: from localhost ([::1]:42596 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPam4-0002fb-M4 for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:15:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPagP-0005vQ-0w for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPagL-0004B9-Eo for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59176) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPagH-0003vU-Mr for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:11 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BD3CDC04FF84; Wed, 21 Nov 2018 22:09:07 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABB8B5C21E; Wed, 21 Nov 2018 22:09:03 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:35 +0400 Message-Id: <20181121220647.18844-19-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 21 Nov 2018 22:09:07 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 18/30] slirp: no need to make DPRINTF conditional on DEBUG 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" DEBUG_CALL is already handled conditionally. Signed-off-by: Marc-André Lureau --- slirp/bootp.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/slirp/bootp.c b/slirp/bootp.c index 5ab6692038..4c9a77eb98 100644 --- a/slirp/bootp.c +++ b/slirp/bootp.c @@ -36,11 +36,7 @@ static const uint8_t rfc1533_cookie[] = { RFC1533_COOKIE }; -#ifdef DEBUG #define DPRINTF(fmt, ...) DEBUG_CALL(fmt, ##__VA_ARGS__) -#else -#define DPRINTF(fmt, ...) do{}while(0) -#endif static BOOTPClient *get_new_addr(Slirp *slirp, struct in_addr *paddr, const uint8_t *macaddr) @@ -166,8 +162,9 @@ static void bootp_reply(Slirp *slirp, const struct bootp_t *bp) DPRINTF("bootp packet op=%d msgtype=%d", bp->bp_op, dhcp_msg_type); if (preq_addr.s_addr != htonl(0L)) DPRINTF(" req_addr=%08" PRIx32 "\n", ntohl(preq_addr.s_addr)); - else + else { DPRINTF("\n"); + } if (dhcp_msg_type == 0) dhcp_msg_type = DHCPREQUEST; /* Force reply for old BOOTP clients */ From patchwork Wed Nov 21 22:06:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001453 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430clC11trz9s29 for ; Thu, 22 Nov 2018 09:32:23 +1100 (AEDT) Received: from localhost ([::1]:42688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPb2i-00011R-RT for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:32:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPagi-00069Q-WC for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPagZ-0004XI-1y for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46626) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPagS-0004J9-U8 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:22 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 159B888E57; Wed, 21 Nov 2018 22:09:17 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3FB010002B9; Wed, 21 Nov 2018 22:09:11 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:36 +0400 Message-Id: <20181121220647.18844-20-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 21 Nov 2018 22:09:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 19/30] slirp: always build with debug statements 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Make debug statements condiitonal only on slirp_debug flags, instead of the pre-processor DEBUG blocks, as it may introduce breakage easily, since the debug code isn't always compiled. Signed-off-by: Marc-André Lureau --- slirp/debug.h | 15 +++------------ slirp/misc.c | 6 +++++- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/slirp/debug.h b/slirp/debug.h index ca3a4b04da..ff920f0b87 100644 --- a/slirp/debug.h +++ b/slirp/debug.h @@ -5,9 +5,8 @@ * terms and conditions of the copyright. */ -//#define DEBUG 1 - -#ifdef DEBUG +#ifndef DEBUG_H_ +#define DEBUG_H_ #define DBG_CALL 0x1 #define DBG_MISC 0x2 @@ -50,12 +49,4 @@ extern int slirp_debug; } \ } while (0) -#else - -#define DEBUG_CALL(fmt, ...) -#define DEBUG_ARG(fmt, ...) -#define DEBUG_ARGS(fmt, ...) -#define DEBUG_MISC(fmt, ...) -#define DEBUG_ERROR(fmt, ...) - -#endif +#endif /* DEBUG_H_ */ diff --git a/slirp/misc.c b/slirp/misc.c index 6ee0ff0231..0b7ec89595 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -12,9 +12,13 @@ #include "qemu/main-loop.h" #ifdef DEBUG -int slirp_debug = DBG_CALL|DBG_MISC|DBG_ERROR; +#define SLIRP_DEBUG (DBG_CALL | DBG_MISC | DBG_ERROR) +#else +#define SLIRP_DEBUG 0 #endif +int slirp_debug = SLIRP_DEBUG; + inline void insque(void *a, void *b) { From patchwork Wed Nov 21 22:06:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cRB5nCkz9s29 for ; Thu, 22 Nov 2018 09:18:30 +1100 (AEDT) Received: from localhost ([::1]:42613 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPapI-00056C-6K for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:18:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPagn-0006DT-Ob for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPagi-0004k1-VA for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48720) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPagc-0004R5-B0 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:32 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D4C41307D860; Wed, 21 Nov 2018 22:09:23 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id F40785D75C; Wed, 21 Nov 2018 22:09:20 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:37 +0400 Message-Id: <20181121220647.18844-21-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 21 Nov 2018 22:09:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 20/30] slirp: introduce SLIRP_DEBUG environment variable 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Learn to read SLIRP_DEBUG=call,misc,error (all or help also handled) to set the slirp_debug flags. Signed-off-by: Marc-André Lureau --- slirp/misc.c | 8 -------- slirp/slirp.c | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/slirp/misc.c b/slirp/misc.c index 0b7ec89595..f9b2c64541 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -11,14 +11,6 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" -#ifdef DEBUG -#define SLIRP_DEBUG (DBG_CALL | DBG_MISC | DBG_ERROR) -#else -#define SLIRP_DEBUG 0 -#endif - -int slirp_debug = SLIRP_DEBUG; - inline void insque(void *a, void *b) { diff --git a/slirp/slirp.c b/slirp/slirp.c index 432adb02c4..51c5813c7c 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -34,6 +34,8 @@ #include #endif +int slirp_debug; + /* Define to 1 if you want KEEPALIVE timers */ bool slirp_do_keepalive; @@ -249,6 +251,7 @@ int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id) static void slirp_init_once(void) { static int initialized; + const char *debug; #ifdef _WIN32 WSADATA Data; #endif @@ -265,6 +268,18 @@ static void slirp_init_once(void) loopback_addr.s_addr = htonl(INADDR_LOOPBACK); loopback_mask = htonl(IN_CLASSA_NET); + + debug = g_getenv("SLIRP_DEBUG"); + if (debug) { + const GDebugKey keys[] = { + { "call", DBG_CALL }, + { "misc", DBG_MISC }, + { "error", DBG_ERROR }, + }; + slirp_debug = g_parse_debug_string(debug, keys, G_N_ELEMENTS(keys)); + } + + } static void slirp_state_save(QEMUFile *f, void *opaque); From patchwork Wed Nov 21 22:06:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001445 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cXJ69yQz9s29 for ; Thu, 22 Nov 2018 09:22:56 +1100 (AEDT) Received: from localhost ([::1]:42637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPata-0000sc-EU for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:22:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPah6-0006Ug-Kz for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPah0-00051H-B1 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46258) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPagw-0004cT-Aj for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:52 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6749630842AC; Wed, 21 Nov 2018 22:09:29 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D73B5D75D; Wed, 21 Nov 2018 22:09:27 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:38 +0400 Message-Id: <20181121220647.18844-22-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 21 Nov 2018 22:09:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 21/30] slirp: use %p for pointers format 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This fixes some compilation warnings on mingw64. Signed-off-by: Marc-André Lureau --- slirp/ip6_icmp.c | 2 +- slirp/ip6_input.c | 2 +- slirp/ip6_output.c | 4 ++-- slirp/udp6.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 0acdcc26a2..95f8fddacc 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -388,7 +388,7 @@ void icmp6_input(struct mbuf *m) int hlen = sizeof(struct ip6); DEBUG_CALL("icmp6_input"); - DEBUG_ARG("m = %lx", (long) m); + DEBUG_ARG("m = %p", m); DEBUG_ARG("m_len = %d", m->m_len); if (ntohs(ip->ip_pl) < ICMP6_MINLEN) { diff --git a/slirp/ip6_input.c b/slirp/ip6_input.c index ac2e3ea882..ab656a0a9d 100644 --- a/slirp/ip6_input.c +++ b/slirp/ip6_input.c @@ -31,7 +31,7 @@ void ip6_input(struct mbuf *m) } DEBUG_CALL("ip6_input"); - DEBUG_ARG("m = %lx", (long)m); + DEBUG_ARG("m = %p", m); DEBUG_ARG("m_len = %d", m->m_len); if (m->m_len < sizeof(struct ip6)) { diff --git a/slirp/ip6_output.c b/slirp/ip6_output.c index 762cbfe89c..52c88ad691 100644 --- a/slirp/ip6_output.c +++ b/slirp/ip6_output.c @@ -19,8 +19,8 @@ int ip6_output(struct socket *so, struct mbuf *m, int fast) struct ip6 *ip = mtod(m, struct ip6 *); DEBUG_CALL("ip6_output"); - DEBUG_ARG("so = %lx", (long)so); - DEBUG_ARG("m = %lx", (long)m); + DEBUG_ARG("so = %p", so); + DEBUG_ARG("m = %p", m); /* Fill IPv6 header */ ip->ip_v = IP6VERSION; diff --git a/slirp/udp6.c b/slirp/udp6.c index 473ba1586e..8cdb1892e2 100644 --- a/slirp/udp6.c +++ b/slirp/udp6.c @@ -20,7 +20,7 @@ void udp6_input(struct mbuf *m) struct sockaddr_in6 lhost; DEBUG_CALL("udp6_input"); - DEBUG_ARG("m = %lx", (long)m); + DEBUG_ARG("m = %p", m); if (slirp->restricted) { goto bad; @@ -144,8 +144,8 @@ int udp6_output(struct socket *so, struct mbuf *m, struct udphdr *uh; DEBUG_CALL("udp6_output"); - DEBUG_ARG("so = %lx", (long)so); - DEBUG_ARG("m = %lx", (long)m); + DEBUG_ARG("so = %p", so); + DEBUG_ARG("m = %p", m); /* adjust for header */ m->m_data -= sizeof(struct udphdr); From patchwork Wed Nov 21 22:06:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001442 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cVs0nwKz9s29 for ; Thu, 22 Nov 2018 09:21:41 +1100 (AEDT) Received: from localhost ([::1]:42631 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPasM-0008HQ-Nd for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:21:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPagu-0006Jk-7l for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPagn-0004nJ-Lb for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59298) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPagl-0004jT-NK for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:40 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DE1CC07015F; Wed, 21 Nov 2018 22:09:36 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 217785C21E; Wed, 21 Nov 2018 22:09:32 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:39 +0400 Message-Id: <20181121220647.18844-23-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 21 Nov 2018 22:09:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 22/30] slirp: remove remaining DEBUG blocks 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Instead, rely on slirp_debug flags, or compile unconditionally (the substraction in cksum is unlikely to affect any benchmark result). Signed-off-by: Marc-André Lureau --- slirp/cksum.c | 4 ---- slirp/ip_icmp.c | 5 ++--- slirp/slirp.c | 5 +---- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/slirp/cksum.c b/slirp/cksum.c index b9466485b5..0a988b845d 100644 --- a/slirp/cksum.c +++ b/slirp/cksum.c @@ -70,9 +70,7 @@ int cksum(struct mbuf *m, int len) if (len < mlen) mlen = len; -#ifdef DEBUG len -= mlen; -#endif /* * Force to even boundary. */ @@ -122,12 +120,10 @@ int cksum(struct mbuf *m, int len) s_util.c[0] = *(uint8_t *)w; cont: -#ifdef DEBUG if (len) { DEBUG_ERROR("cksum: out of data\n"); DEBUG_ERROR(" len = %d\n", len); } -#endif if (mlen == -1) { /* The last mbuf has odd # of bytes. Follow the standard (the odd byte may be shifted left by 8 bits diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index 6c7e375ff8..cd2faeacb6 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -257,13 +257,12 @@ icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int minsize, /* check msrc */ if(!msrc) goto end_error; ip = mtod(msrc, struct ip *); -#ifdef DEBUG - { char bufa[20], bufb[20]; + if (slirp_debug & DBG_MISC) { + char bufa[20], bufb[20]; strcpy(bufa, inet_ntoa(ip->ip_src)); strcpy(bufb, inet_ntoa(ip->ip_dst)); DEBUG_MISC(" %.16s to %.16s\n", bufa, bufb); } -#endif if(ip->ip_off & IP_OFFMASK) goto end_error; /* Only reply to fragment 0 */ /* Do not reply to source-only IPs */ diff --git a/slirp/slirp.c b/slirp/slirp.c index 51c5813c7c..5954a99d3c 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -194,9 +194,7 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, if (++found > 3) { DEBUG_MISC("(more)"); break; - } -#ifdef DEBUG - else { + } else if (slirp_debug & DBG_MISC) { char s[INET6_ADDRSTRLEN]; const char *res = inet_ntop(af, tmp_addr, s, sizeof(s)); if (!res) { @@ -204,7 +202,6 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, } DEBUG_MISC("%s", res); } -#endif } } fclose(f); From patchwork Wed Nov 21 22:06:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cSm3cPhz9s3C for ; Thu, 22 Nov 2018 09:19:52 +1100 (AEDT) Received: from localhost ([::1]:42618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPaqc-0006tY-4o for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:19:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51547) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPah6-0006Uh-Le for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPah0-00051B-9S for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47466) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPagw-0004pr-9h for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:09:52 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E1DA983F42; Wed, 21 Nov 2018 22:09:43 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A3BB1054FD3; Wed, 21 Nov 2018 22:09:39 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:40 +0400 Message-Id: <20181121220647.18844-24-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 21 Nov 2018 22:09:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 23/30] slirp: replace DEBUG_ARGS with DEBUG_ARG 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" There is no clear benefit in calling an alias DEBUG_ARGS(). Replace calls with DEBUG_ARG(), and fix the white-spacing while at it. Signed-off-by: Marc-André Lureau --- slirp/debug.h | 2 -- slirp/arp_table.c | 12 ++++++------ slirp/ip6_icmp.c | 2 +- slirp/ndp_table.c | 18 +++++++++--------- slirp/slirp.c | 12 ++++++------ slirp/tcp_input.c | 6 +++--- 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/slirp/debug.h b/slirp/debug.h index ff920f0b87..50f30898fb 100644 --- a/slirp/debug.h +++ b/slirp/debug.h @@ -33,8 +33,6 @@ extern int slirp_debug; } \ } while (0) -#define DEBUG_ARGS(fmt, ...) DEBUG_ARG(fmt, ##__VA_ARGS__) - #define DEBUG_MISC(fmt, ...) do { \ if (slirp_debug & DBG_MISC) { \ fprintf(dfd, fmt, ##__VA_ARGS__); \ diff --git a/slirp/arp_table.c b/slirp/arp_table.c index ce19e6e7c0..bf71b984ad 100644 --- a/slirp/arp_table.c +++ b/slirp/arp_table.c @@ -34,9 +34,9 @@ void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]) DEBUG_CALL("arp_table_add"); DEBUG_ARG("ip = %s", inet_ntoa((struct in_addr){.s_addr = ip_addr})); - DEBUG_ARGS(" hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n", - ethaddr[0], ethaddr[1], ethaddr[2], - ethaddr[3], ethaddr[4], ethaddr[5]); + DEBUG_ARG("hw addr = %02x:%02x:%02x:%02x:%02x:%02x", + ethaddr[0], ethaddr[1], ethaddr[2], + ethaddr[3], ethaddr[4], ethaddr[5]); if (ip_addr == 0 || ip_addr == 0xffffffff || ip_addr == broadcast_addr) { /* Do not register broadcast addresses */ @@ -79,9 +79,9 @@ bool arp_table_search(Slirp *slirp, uint32_t ip_addr, for (i = 0; i < ARP_TABLE_SIZE; i++) { if (arptbl->table[i].ar_sip == ip_addr) { memcpy(out_ethaddr, arptbl->table[i].ar_sha, ETH_ALEN); - DEBUG_ARGS(" found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n", - out_ethaddr[0], out_ethaddr[1], out_ethaddr[2], - out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]); + DEBUG_ARG("found hw addr = %02x:%02x:%02x:%02x:%02x:%02x", + out_ethaddr[0], out_ethaddr[1], out_ethaddr[2], + out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]); return 1; } } diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 95f8fddacc..e72c57a81d 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -75,7 +75,7 @@ void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code) char addrstr[INET6_ADDRSTRLEN]; DEBUG_CALL("icmp6_send_error"); - DEBUG_ARGS(" type = %d, code = %d\n", type, code); + DEBUG_ARG("type = %d, code = %d", type, code); if (IN6_IS_ADDR_MULTICAST(&ip->ip_src) || in6_zero(&ip->ip_src)) { diff --git a/slirp/ndp_table.c b/slirp/ndp_table.c index 1401e1b322..b7b73722f7 100644 --- a/slirp/ndp_table.c +++ b/slirp/ndp_table.c @@ -18,9 +18,9 @@ void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr, DEBUG_CALL("ndp_table_add"); DEBUG_ARG("ip = %s", addrstr); - DEBUG_ARGS(" hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n", - ethaddr[0], ethaddr[1], ethaddr[2], - ethaddr[3], ethaddr[4], ethaddr[5]); + DEBUG_ARG("hw addr = %02x:%02x:%02x:%02x:%02x:%02x", + ethaddr[0], ethaddr[1], ethaddr[2], + ethaddr[3], ethaddr[4], ethaddr[5]); if (IN6_IS_ADDR_MULTICAST(&ip_addr) || in6_zero(&ip_addr)) { /* Do not register multicast or unspecified addresses */ @@ -67,18 +67,18 @@ bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr, out_ethaddr[3] = ip_addr.s6_addr[13]; out_ethaddr[4] = ip_addr.s6_addr[14]; out_ethaddr[5] = ip_addr.s6_addr[15]; - DEBUG_ARGS(" multicast addr = %02x:%02x:%02x:%02x:%02x:%02x\n", - out_ethaddr[0], out_ethaddr[1], out_ethaddr[2], - out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]); + DEBUG_ARG("multicast addr = %02x:%02x:%02x:%02x:%02x:%02x", + out_ethaddr[0], out_ethaddr[1], out_ethaddr[2], + out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]); return 1; } for (i = 0; i < NDP_TABLE_SIZE; i++) { if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) { memcpy(out_ethaddr, ndp_table->table[i].eth_addr, ETH_ALEN); - DEBUG_ARGS(" found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n", - out_ethaddr[0], out_ethaddr[1], out_ethaddr[2], - out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]); + DEBUG_ARG("found hw addr = %02x:%02x:%02x:%02x:%02x:%02x", + out_ethaddr[0], out_ethaddr[1], out_ethaddr[2], + out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]); return 1; } } diff --git a/slirp/slirp.c b/slirp/slirp.c index 5954a99d3c..12aad702c2 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -989,12 +989,12 @@ int if_encap(Slirp *slirp, struct mbuf *ifm) } memcpy(eh->h_dest, ethaddr, ETH_ALEN); - DEBUG_ARGS(" src = %02x:%02x:%02x:%02x:%02x:%02x\n", - eh->h_source[0], eh->h_source[1], eh->h_source[2], - eh->h_source[3], eh->h_source[4], eh->h_source[5]); - DEBUG_ARGS(" dst = %02x:%02x:%02x:%02x:%02x:%02x\n", - eh->h_dest[0], eh->h_dest[1], eh->h_dest[2], - eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]); + DEBUG_ARG("src = %02x:%02x:%02x:%02x:%02x:%02x", + eh->h_source[0], eh->h_source[1], eh->h_source[2], + eh->h_source[3], eh->h_source[4], eh->h_source[5]); + DEBUG_ARG("dst = %02x:%02x:%02x:%02x:%02x:%02x", + 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); return 1; diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c index bc4aa60046..d24295813a 100644 --- a/slirp/tcp_input.c +++ b/slirp/tcp_input.c @@ -215,8 +215,8 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *inso, unsigned short af) Slirp *slirp; DEBUG_CALL("tcp_input"); - DEBUG_ARGS(" m = %p iphlen = %2d inso = %p\n", - m, iphlen, inso); + DEBUG_ARG("m = %p iphlen = %2d inso = %p", + m, iphlen, inso); /* * If called with m == 0, then we're continuing the connect @@ -1389,7 +1389,7 @@ tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti) int opt, optlen; DEBUG_CALL("tcp_dooptions"); - DEBUG_ARGS(" tp = %p cnt=%i\n", tp, cnt); + DEBUG_ARG("tp = %p cnt=%i", tp, cnt); for (; cnt > 0; cnt -= optlen, cp += optlen) { opt = cp[0]; From patchwork Wed Nov 21 22:06:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cf85cCqz9s29 for ; Thu, 22 Nov 2018 09:28:00 +1100 (AEDT) Received: from localhost ([::1]:42662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPayT-0005Ll-PA for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:27:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPahO-0006od-VP for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPahK-0005Rd-Ih for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46742) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPahI-0004xN-Hj for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:13 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1497C89ADD; Wed, 21 Nov 2018 22:09:52 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 734329F7A; Wed, 21 Nov 2018 22:09:47 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:41 +0400 Message-Id: <20181121220647.18844-25-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 21 Nov 2018 22:09:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 24/30] slirp: call into g_debug() for DEBUG macros 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Make slirp use GLib logging, instead of fprintf(), so that applications can filter log, process it etc. With recent versions of glib, G_MESSAGES_DEBUG must be set to "all" or "Slirp" to see slirp debug messages. Reformat DEBUG_MISC & DEBUG_ERROR calls to not need \n ending. Signed-off-by: Marc-André Lureau --- slirp/debug.h | 17 ++++------------- slirp/cksum.c | 4 ++-- slirp/dhcpv6.c | 6 +++--- slirp/ip_icmp.c | 10 +++++----- slirp/slirp.c | 10 ++++------ slirp/socket.c | 24 ++++++++++++------------ slirp/tcp_input.c | 7 +++---- slirp/tcp_output.c | 2 +- slirp/tcp_subr.c | 2 +- slirp/udp.c | 5 ++--- slirp/udp6.c | 5 ++--- 11 files changed, 39 insertions(+), 53 deletions(-) diff --git a/slirp/debug.h b/slirp/debug.h index 50f30898fb..25a5d59439 100644 --- a/slirp/debug.h +++ b/slirp/debug.h @@ -12,38 +12,29 @@ #define DBG_MISC 0x2 #define DBG_ERROR 0x4 -#define dfd stderr - extern int slirp_debug; #define DEBUG_CALL(fmt, ...) do { \ if (slirp_debug & DBG_CALL) { \ - fprintf(dfd, fmt, ##__VA_ARGS__); \ - fprintf(dfd, "...\n"); \ - fflush(dfd); \ + g_debug(fmt "...", ##__VA_ARGS__); \ } \ } while (0) #define DEBUG_ARG(fmt, ...) do { \ if (slirp_debug & DBG_CALL) { \ - fputc(' ', dfd); \ - fprintf(dfd, fmt, ##__VA_ARGS__); \ - fputc('\n', dfd); \ - fflush(dfd); \ + g_debug(" " fmt, ##__VA_ARGS__); \ } \ } while (0) #define DEBUG_MISC(fmt, ...) do { \ if (slirp_debug & DBG_MISC) { \ - fprintf(dfd, fmt, ##__VA_ARGS__); \ - fflush(dfd); \ + g_debug(fmt, ##__VA_ARGS__); \ } \ } while (0) #define DEBUG_ERROR(fmt, ...) do { \ if (slirp_debug & DBG_ERROR) { \ - fprintf(dfd, fmt, ##__VA_ARGS__); \ - fflush(dfd); \ + g_debug(fmt, ##__VA_ARGS__); \ } \ } while (0) diff --git a/slirp/cksum.c b/slirp/cksum.c index 0a988b845d..84c858fafb 100644 --- a/slirp/cksum.c +++ b/slirp/cksum.c @@ -121,8 +121,8 @@ int cksum(struct mbuf *m, int len) cont: if (len) { - DEBUG_ERROR("cksum: out of data\n"); - DEBUG_ERROR(" len = %d\n", len); + DEBUG_ERROR("cksum: out of data"); + DEBUG_ERROR(" len = %d", len); } if (mlen == -1) { /* The last mbuf has odd # of bytes. Follow the diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c index 5d703e8ae6..752df40536 100644 --- a/slirp/dhcpv6.c +++ b/slirp/dhcpv6.c @@ -92,13 +92,13 @@ static int dhcpv6_parse_info_request(Slirp *slirp, uint8_t *odata, int olen, ri->want_boot_url = true; break; default: - DEBUG_MISC("dhcpv6: Unsupported option request %d\n", + DEBUG_MISC("dhcpv6: Unsupported option request %d", req_opt); } } break; default: - DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d\n", + DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d", option, len); } @@ -203,6 +203,6 @@ void dhcpv6_input(struct sockaddr_in6 *srcsas, struct mbuf *m) dhcpv6_info_request(m->slirp, srcsas, xid, &data[4], data_len - 4); break; default: - DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x\n", data[0]); + DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x", data[0]); } } diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index cd2faeacb6..7c7e042049 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -103,7 +103,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen) if (sendto(so->s, m->m_data + hlen, m->m_len - hlen, 0, (struct sockaddr *)&addr, sizeof(addr)) == -1) { - DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s\n", + DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s", errno, strerror(errno)); icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); icmp_detach(so); @@ -169,7 +169,7 @@ icmp_input(struct mbuf *m, int hlen) return; } if (udp_attach(so, AF_INET) == -1) { - DEBUG_MISC("icmp_input udp_attach errno = %d-%s\n", + DEBUG_MISC("icmp_input udp_attach errno = %d-%s", errno,strerror(errno)); sofree(so); m_free(m); @@ -192,7 +192,7 @@ icmp_input(struct mbuf *m, int hlen) if(sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0, (struct sockaddr *)&addr, sockaddr_size(&addr)) == -1) { - DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s\n", + DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s", errno,strerror(errno)); icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); udp_detach(so); @@ -261,7 +261,7 @@ icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int minsize, char bufa[20], bufb[20]; strcpy(bufa, inet_ntoa(ip->ip_src)); strcpy(bufb, inet_ntoa(ip->ip_dst)); - DEBUG_MISC(" %.16s to %.16s\n", bufa, bufb); + DEBUG_MISC(" %.16s to %.16s", bufa, bufb); } if(ip->ip_off & IP_OFFMASK) goto end_error; /* Only reply to fragment 0 */ @@ -458,7 +458,7 @@ void icmp_receive(struct socket *so) } else { error_code = ICMP_UNREACH_HOST; } - DEBUG_MISC(" udp icmp rx errno = %d-%s\n", errno, + DEBUG_MISC(" udp icmp rx errno = %d-%s", errno, strerror(errno)); icmp_send_error(so->so_m, ICMP_UNREACH, error_code, 0, strerror(errno)); } else { diff --git a/slirp/slirp.c b/slirp/slirp.c index 12aad702c2..f254a23a5a 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -165,7 +165,7 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, if (!f) return -1; - DEBUG_MISC("IP address of your DNS(s): "); + DEBUG_MISC("IP address of your DNS(s):"); while (fgets(buff, 512, f) != NULL) { if (sscanf(buff, "nameserver%*[ \t]%256s", buff2) == 1) { char *c = strchr(buff2, '%'); @@ -187,20 +187,18 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, *scope_id = if_index; } *cached_time = curtime; - } else { - DEBUG_MISC(", "); } if (++found > 3) { - DEBUG_MISC("(more)"); + DEBUG_MISC(" (more)"); break; } else if (slirp_debug & DBG_MISC) { char s[INET6_ADDRSTRLEN]; const char *res = inet_ntop(af, tmp_addr, s, sizeof(s)); if (!res) { - res = "(string conversion error)"; + res = " (string conversion error)"; } - DEBUG_MISC("%s", res); + DEBUG_MISC(" %s", res); } } } diff --git a/slirp/socket.c b/slirp/socket.c index 08a065f6a7..5ffbaa064a 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -208,7 +208,8 @@ soread(struct socket *so) } } - DEBUG_MISC(" --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)); + DEBUG_MISC(" --- soread() disconnected, nn = %d, errno = %d-%s", + nn, errno,strerror(errno)); sofcantrcvmore(so); if (err == ECONNRESET || err == ECONNREFUSED @@ -237,7 +238,7 @@ soread(struct socket *so) nn += ret; } - DEBUG_MISC(" ... read nn = %d bytes\n", nn); + DEBUG_MISC(" ... read nn = %d bytes", nn); /* Update fields */ sb->sb_cc += nn; @@ -370,7 +371,7 @@ sosendoob(struct socket *so) n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */ #ifdef DEBUG if (n != len) { - DEBUG_ERROR("Didn't send all data urgently XXXXX\n"); + DEBUG_ERROR("Didn't send all data urgently XXXXX"); } #endif } @@ -379,7 +380,7 @@ sosendoob(struct socket *so) return n; } so->so_urgc -= n; - DEBUG_MISC(" ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc); + DEBUG_MISC(" ---2 sent %d bytes urgent data, %d urgent bytes left", n, so->so_urgc); sb->sb_cc -= n; sb->sb_rptr += n; @@ -460,7 +461,7 @@ sowrite(struct socket *so) if (ret > 0) nn += ret; } - DEBUG_MISC(" ... wrote nn = %d bytes\n", nn); + DEBUG_MISC(" ... wrote nn = %d bytes", nn); /* Update sbuf */ sb->sb_cc -= nn; @@ -478,7 +479,7 @@ sowrite(struct socket *so) return nn; err_disconnected: - DEBUG_MISC(" --- sowrite disconnected, so->so_state = %x, errno = %d\n", + DEBUG_MISC(" --- sowrite disconnected, so->so_state = %x, errno = %d", so->so_state, errno); sofcantsendmore(so); tcp_sockclosed(sototcpcb(so)); @@ -512,7 +513,7 @@ sorecvfrom(struct socket *so) if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST; else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET; - DEBUG_MISC(" udp icmp rx errno = %d-%s\n", + DEBUG_MISC(" udp icmp rx errno = %d-%s", errno,strerror(errno)); icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno)); } else { @@ -564,7 +565,7 @@ sorecvfrom(struct socket *so) m->m_len = recvfrom(so->s, m->m_data, len, 0, (struct sockaddr *)&addr, &addrlen); - DEBUG_MISC(" did recvfrom %d, errno = %d-%s\n", + DEBUG_MISC(" did recvfrom %d, errno = %d-%s", m->m_len, errno,strerror(errno)); if(m->m_len<0) { /* Report error as ICMP */ @@ -579,7 +580,7 @@ sorecvfrom(struct socket *so) code = ICMP_UNREACH_NET; } - DEBUG_MISC(" rx error, tx icmp ICMP_UNREACH:%i\n", code); + DEBUG_MISC(" rx error, tx icmp ICMP_UNREACH:%i", code); icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno)); break; case AF_INET6: @@ -591,7 +592,7 @@ sorecvfrom(struct socket *so) code = ICMP6_UNREACH_NO_ROUTE; } - DEBUG_MISC(" rx error, tx icmp6 ICMP_UNREACH:%i\n", code); + DEBUG_MISC(" rx error, tx icmp6 ICMP_UNREACH:%i", code); icmp6_send_error(so->so_m, ICMP6_UNREACH, code); break; default: @@ -839,8 +840,7 @@ void sotranslate_out(struct socket *so, struct sockaddr_storage *addr) } } - DEBUG_MISC(" addr.sin_port=%d, " - "addr.sin_addr.s_addr=%.16s\n", + DEBUG_MISC(" addr.sin_port=%d, addr.sin_addr.s_addr=%.16s", ntohs(sin->sin_port), inet_ntoa(sin->sin_addr)); break; diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c index d24295813a..a6596b63ac 100644 --- a/slirp/tcp_input.c +++ b/slirp/tcp_input.c @@ -641,8 +641,7 @@ findso: (errno != EINPROGRESS) && (errno != EWOULDBLOCK) ) { uint8_t code; - DEBUG_MISC(" tcp fconnect errno = %d-%s\n", - errno,strerror(errno)); + DEBUG_MISC(" tcp fconnect errno = %d-%s", errno, strerror(errno)); if(errno == ECONNREFUSED) { /* ACK the SYN, send RST to refuse the connection */ tcp_respond(tp, ti, m, ti->ti_seq + 1, (tcp_seq) 0, @@ -1011,7 +1010,7 @@ trimthenstep6: if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) { if (ti->ti_len == 0 && tiwin == tp->snd_wnd) { - DEBUG_MISC(" dup ack m = %p so = %p\n", m, so); + DEBUG_MISC(" dup ack m = %p so = %p", m, so); /* * If we have outstanding data (other than * a window probe), this is a completely @@ -1550,7 +1549,7 @@ tcp_mss(struct tcpcb *tp, u_int offer) (mss - (TCP_RCVSPACE % mss)) : 0)); - DEBUG_MISC(" returning mss = %d\n", mss); + DEBUG_MISC(" returning mss = %d", mss); return mss; } diff --git a/slirp/tcp_output.c b/slirp/tcp_output.c index 44da8a4e47..2f7f90d67e 100644 --- a/slirp/tcp_output.c +++ b/slirp/tcp_output.c @@ -92,7 +92,7 @@ again: flags = tcp_outflags[tp->t_state]; - DEBUG_MISC(" --- tcp_output flags = 0x%x\n", flags); + DEBUG_MISC(" --- tcp_output flags = 0x%x", flags); /* * If in persist timeout with window of 0, send 1 byte. diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 042fa1e4fb..5dcf979c3c 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -964,7 +964,7 @@ int tcp_ctl(struct socket *so) so->guestfwd = ex_ptr; return 1; } - DEBUG_MISC(" executing %s\n", ex_ptr->ex_exec); + DEBUG_MISC(" executing %s", ex_ptr->ex_exec); return fork_exec(so, ex_ptr->ex_exec); } } diff --git a/slirp/udp.c b/slirp/udp.c index a45ad81dda..4cf0d34d64 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -172,8 +172,7 @@ udp_input(register struct mbuf *m, int iphlen) */ so = socreate(slirp); if (udp_attach(so, AF_INET) == -1) { - DEBUG_MISC(" udp_attach errno = %d-%s\n", - errno, strerror(errno)); + DEBUG_MISC(" udp_attach errno = %d-%s", errno, strerror(errno)); sofree(so); goto bad; } @@ -209,7 +208,7 @@ udp_input(register struct mbuf *m, int iphlen) m->m_len += iphlen; m->m_data -= iphlen; *ip=save_ip; - DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno)); + DEBUG_MISC("udp tx errno = %d-%s", errno, strerror(errno)); icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); goto bad; diff --git a/slirp/udp6.c b/slirp/udp6.c index 8cdb1892e2..fa531e03c4 100644 --- a/slirp/udp6.c +++ b/slirp/udp6.c @@ -92,8 +92,7 @@ void udp6_input(struct mbuf *m) /* If there's no socket for this packet, create one. */ so = socreate(slirp); if (udp_attach(so, AF_INET6) == -1) { - DEBUG_MISC(" udp6_attach errno = %d-%s\n", - errno, strerror(errno)); + DEBUG_MISC(" udp6_attach errno = %d-%s", errno, strerror(errno)); sofree(so); goto bad; } @@ -119,7 +118,7 @@ void udp6_input(struct mbuf *m) m->m_len += iphlen; m->m_data -= iphlen; *ip = save_ip; - DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno)); + DEBUG_MISC("udp tx errno = %d-%s", errno, strerror(errno)); icmp6_send_error(m, ICMP6_UNREACH, ICMP6_UNREACH_NO_ROUTE); goto bad; } From patchwork Wed Nov 21 22:06:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cZV2B2Lz9s29 for ; Thu, 22 Nov 2018 09:24:50 +1100 (AEDT) Received: from localhost ([::1]:42645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPavQ-0002xF-0g for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:24:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPahP-0006oe-04 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPahK-0005So-U9 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57160) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPahK-00058g-Hg for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:14 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 60D693091D5D; Wed, 21 Nov 2018 22:10:00 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEB54648A8; Wed, 21 Nov 2018 22:09:55 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:42 +0400 Message-Id: <20181121220647.18844-26-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 21 Nov 2018 22:10:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 25/30] 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Remove a dependency on QEMU. Use the existing logging facilities. Set SLIRP_DEBUG=tftp to get tftp log. Signed-off-by: Marc-André Lureau --- slirp/debug.h | 13 ++++++++++--- slirp/slirp.c | 1 + slirp/tftp.c | 7 ++++--- Makefile.objs | 1 - slirp/trace-events | 5 ----- 5 files changed, 15 insertions(+), 12 deletions(-) delete mode 100644 slirp/trace-events diff --git a/slirp/debug.h b/slirp/debug.h index 25a5d59439..20557f9866 100644 --- a/slirp/debug.h +++ b/slirp/debug.h @@ -8,9 +8,10 @@ #ifndef DEBUG_H_ #define DEBUG_H_ -#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) extern int slirp_debug; @@ -38,4 +39,10 @@ extern int slirp_debug; } \ } while (0) +#define DEBUG_TFTP(fmt, ...) do { \ + if (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 f254a23a5a..cd0ad81f26 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 = g_parse_debug_string(debug, keys, G_N_ELEMENTS(keys)); } 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" 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; - trace_slirp_tftp_error(msg); + DEBUG_TFTP("tftp error msg: %s", msg); + m = m_get(spt->slirp); if (!m) { @@ -325,7 +325,8 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas, break; } } - trace_slirp_tftp_rrq(req_fname); + + DEBUG_TFTP("tftp rrq file: %s", req_fname); /* check mode */ if ((pktlen - k) < 6) { diff --git a/Makefile.objs b/Makefile.objs index a11050a7aa..1cb2faab5e 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -250,7 +250,6 @@ trace-events-subdirs += net trace-events-subdirs += qapi trace-events-subdirs += qom trace-events-subdirs += scsi -trace-events-subdirs += slirp trace-events-subdirs += target/arm trace-events-subdirs += target/i386 trace-events-subdirs += target/mips 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" From patchwork Wed Nov 21 22:06:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001451 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cgh63J2z9s29 for ; Thu, 22 Nov 2018 09:29:20 +1100 (AEDT) Received: from localhost ([::1]:42667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPazm-0007Cl-Ay for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:29:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPahR-0006qj-8A for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPahP-0005h4-GN for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPahP-0005CB-45 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:19 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E42330821EF; Wed, 21 Nov 2018 22:10:08 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B33C5D75D; Wed, 21 Nov 2018 22:10:03 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:43 +0400 Message-Id: <20181121220647.18844-27-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 21 Nov 2018 22:10:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 26/30] slirp: add a set_nonblock() 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" qemu_set_nonblock() does some event registration with the main loop on win32, let's have a callback. Signed-off-by: Marc-André Lureau --- slirp/libslirp.h | 2 ++ net/slirp.c | 1 + slirp/misc.c | 2 +- slirp/tcp_subr.c | 4 ++-- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 3e75dadfa3..e79a2d2b11 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); + /* Put a fd in nonblocking mode and register it for future polling */ + void (*set_nonblock)(int fd); } SlirpCb; diff --git a/net/slirp.c b/net/slirp.c index f7cdf8398b..a31193a25a 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -193,6 +193,7 @@ static const SlirpCb slirp_cb = { .timer_new = net_slirp_timer_new, .timer_free = net_slirp_timer_free, .timer_mod = net_slirp_timer_mod, + .set_nonblock = qemu_set_nonblock, }; static int net_slirp_init(NetClientState *peer, const char *model, diff --git a/slirp/misc.c b/slirp/misc.c index f9b2c64541..7789cefefa 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -172,7 +172,7 @@ fork_exec(struct socket *so, const char *ex) socket_set_fast_reuse(so->s); opt = 1; qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); - qemu_set_nonblock(so->s); + so->slirp->cb->set_nonblock(so->s); return 1; } #endif diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 5dcf979c3c..3b15148187 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -412,7 +412,7 @@ int tcp_fconnect(struct socket *so, unsigned short af) int opt, s=so->s; struct sockaddr_storage addr; - qemu_set_nonblock(s); + so->slirp->cb->set_nonblock(s); socket_set_fast_reuse(s); opt = 1; qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt)); @@ -484,7 +484,7 @@ void tcp_connect(struct socket *inso) tcp_close(sototcpcb(so)); /* This will sofree() as well */ return; } - qemu_set_nonblock(s); + so->slirp->cb->set_nonblock(s); socket_set_fast_reuse(s); opt = 1; qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); From patchwork Wed Nov 21 22:06:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001448 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cdr1Q3Kz9s3C for ; Thu, 22 Nov 2018 09:27:44 +1100 (AEDT) Received: from localhost ([::1]:42660 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPayD-0005BE-SC for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:27:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPahR-0006rF-OJ for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPahP-0005hz-PO for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36268) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPahP-0005dI-AO for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE1FD307EA89; Wed, 21 Nov 2018 22:10:17 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 530931974F; Wed, 21 Nov 2018 22:10:12 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:44 +0400 Message-Id: <20181121220647.18844-28-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 21 Nov 2018 22:10:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 27/30] 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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é Lureau --- slirp/libslirp.h | 2 ++ slirp/sbuf.h | 2 +- slirp/socket.h | 1 + net/slirp.c | 1 + slirp/sbuf.c | 6 ++++-- slirp/socket.c | 7 +++++++ slirp/tcp_input.c | 6 +++--- 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/slirp/libslirp.h b/slirp/libslirp.h index e79a2d2b11..f2d71bd1f6 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); /* Put a fd in nonblocking mode and register it for future polling */ void (*set_nonblock)(int fd); + /* Kick the io-thread, to signal that new events may be processed */ + void (*notify)(void); } SlirpCb; 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 { }; 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.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 size); 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); #endif /* SLIRP_SOCKET_H */ diff --git a/net/slirp.c b/net/slirp.c index a31193a25a..fbdc6ea9a0 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -194,6 +194,7 @@ static const SlirpCb slirp_cb = { .timer_free = net_slirp_timer_free, .timer_mod = net_slirp_timer_mod, .set_nonblock = qemu_set_nonblock, + .notify = qemu_notify_event, }; static int net_slirp_init(NetClientState *peer, const char *model, 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); } -void +bool sbdrop(struct sbuf *sb, int num) { int limit = sb->sb_datalen / 2; @@ -34,8 +34,10 @@ sbdrop(struct sbuf *sb, int num) sb->sb_rptr -= sb->sb_datalen; if (sb->sb_cc < limit && sb->sb_cc + num >= limit) { - qemu_notify_event(); + return true; } + + return false; } void diff --git a/slirp/socket.c b/slirp/socket.c index 5ffbaa064a..4d5be38747 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/tcp_input.c b/slirp/tcp_input.c index a6596b63ac..f205a1e6cb 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 = ti->ti_ack - tp->snd_una; - sbdrop(&so->so_snd, acked); + sodrop(so, acked); tp->snd_una = ti->ti_ack; m_free(m); @@ -1118,10 +1118,10 @@ trimthenstep6: } if (acked > so->so_snd.sb_cc) { tp->snd_wnd -= so->so_snd.sb_cc; - sbdrop(&so->so_snd, (int )so->so_snd.sb_cc); + sodrop(so, (int)so->so_snd.sb_cc); ourfinisacked = 1; } else { - sbdrop(&so->so_snd, acked); + sodrop(so, acked); tp->snd_wnd -= acked; ourfinisacked = 0; } From patchwork Wed Nov 21 22:06:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001454 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cqB593nz9s29 for ; Thu, 22 Nov 2018 09:35:50 +1100 (AEDT) Received: from localhost ([::1]:42708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPb64-0003wJ-96 for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:35:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPahb-00075Q-Ia for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPahX-00066g-BS for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56854) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPahX-00063t-1A for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:27 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4695F2D2BEB; Wed, 21 Nov 2018 22:10:26 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id F05349F7A; Wed, 21 Nov 2018 22:10:21 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:45 +0400 Message-Id: <20181121220647.18844-29-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 21 Nov 2018 22:10:26 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 28/30] 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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é Lureau --- slirp/slirp.h | 3 + slirp/state.h | 9 + slirp/slirp.c | 372 ++--------------------------------------- slirp/state.c | 394 ++++++++++++++++++++++++++++++++++++++++++++ slirp/Makefile.objs | 3 +- 5 files changed, 419 insertions(+), 362 deletions(-) create mode 100644 slirp/state.h create mode 100644 slirp/state.c diff --git a/slirp/slirp.h b/slirp/slirp.h index 17056f4b83..6e7a663b6f 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -270,4 +270,7 @@ int tcp_emu(struct socket *, struct mbuf *); int tcp_ctl(struct socket *); struct tcpcb *tcp_drop(struct tcpcb *tp, int err); +struct socket * +slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, int guest_port); + #endif 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_ */ diff --git a/slirp/slirp.c b/slirp/slirp.c index cd0ad81f26..a1f42c8b19 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -30,6 +30,10 @@ #include "hw/hw.h" #include "qemu/cutils.h" +#ifdef WITH_QEMU +#include "state.h" +#endif + #ifndef _WIN32 #include #endif @@ -278,14 +282,6 @@ static void slirp_init_once(void) } -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 = { - .save_state = slirp_state_save, - .load_state = 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, struct in_addr vnetwork, slirp->opaque = opaque; - 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); return slirp; @@ -359,9 +356,9 @@ void slirp_cleanup(Slirp *slirp) } 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); @@ -1114,7 +1111,7 @@ ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags) return send(so->s, buf, len, flags); } -static struct socket * +struct socket * slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, int guest_port) { struct socket *so; @@ -1161,350 +1158,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 = { - .name = "slirp-tcp", - .version_id = 0, - .post_load = slirp_tcp_post_load, - .fields = (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 = opaque; - tmp->woff = tmp->parent->sb_wptr - tmp->parent->sb_data; - tmp->roff = tmp->parent->sb_rptr - tmp->parent->sb_data; - - return 0; -} - -static int sbuf_tmp_post_load(void *opaque, int version) -{ - struct sbuf_tmp *tmp = opaque; - uint32_t requested_len = 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 != requested_len) { - return -ENOMEM; - } - if (tmp->woff >= requested_len || - tmp->roff >= requested_len) { - g_critical("invalid sbuf offsets r/w=%u/%u len=%u", - tmp->roff, tmp->woff, requested_len); - return -EINVAL; - } - - tmp->parent->sb_wptr = tmp->parent->sb_data + tmp->woff; - tmp->parent->sb_rptr = tmp->parent->sb_data + tmp->roff; - - return 0; -} - - -static const VMStateDescription vmstate_slirp_sbuf_tmp = { - .name = "slirp-sbuf-tmp", - .post_load = sbuf_tmp_post_load, - .pre_save = sbuf_tmp_pre_save, - .version_id = 0, - .fields = (VMStateField[]) { - VMSTATE_UINT32(woff, struct sbuf_tmp), - VMSTATE_UINT32(roff, struct sbuf_tmp), - VMSTATE_END_OF_LIST() - } -}; - -static const VMStateDescription vmstate_slirp_sbuf = { - .name = "slirp-sbuf", - .version_id = 0, - .fields = (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 = (union slirp_sockaddr *)opaque; - return ssa->ss.ss_family == AF_INET; -} - -static int slirp_socket_pre_load(void *opaque) -{ - struct socket *so = opaque; - if (tcp_attach(so) < 0) { - return -ENOMEM; - } - /* Older versions don't load these fields */ - so->so_ffamily = AF_INET; - so->so_lfamily = 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 = opaque; - - tss->portable_family = SS_FAMILY_MIG_OTHER; - - if (tss->parent->ss.ss_family == AF_INET) { - tss->portable_family = SS_FAMILY_MIG_IPV4; - } else if (tss->parent->ss.ss_family == AF_INET6) { - tss->portable_family = SS_FAMILY_MIG_IPV6; - } - - return 0; -} - -static int ss_family_post_load(void *opaque, int version_id) -{ - SS_FamilyTmpStruct *tss = opaque; - - switch (tss->portable_family) { - case SS_FAMILY_MIG_IPV4: - tss->parent->ss.ss_family = 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 = 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 = { - .name = "slirp-socket-addr/ss_family", - .pre_save = ss_family_pre_save, - .post_load = ss_family_post_load, - .fields = (VMStateField[]) { - VMSTATE_UINT16(portable_family, SS_FamilyTmpStruct), - VMSTATE_END_OF_LIST() - } -}; - -static const VMStateDescription vmstate_slirp_socket_addr = { - .name = "slirp-socket-addr", - .version_id = 4, - .fields = (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 = { - .name = "slirp-socket", - .version_id = 4, - .pre_load = slirp_socket_pre_load, - .fields = (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 = { - .name = "slirp_bootpclient", - .fields = (VMStateField[]) { - VMSTATE_UINT16(allocated, BOOTPClient), - VMSTATE_BUFFER(macaddr, BOOTPClient), - VMSTATE_END_OF_LIST() - } -}; - -static const VMStateDescription vmstate_slirp = { - .name = "slirp", - .version_id = 4, - .fields = (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 = opaque; - struct gfwd_list *ex_ptr; - - for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) - if (ex_ptr->write_cb) { - struct socket *so; - so = 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 = opaque; - struct gfwd_list *ex_ptr; - - while (qemu_get_byte(f)) { - int ret; - struct socket *so = socreate(slirp); - - ret = vmstate_load_state(f, &vmstate_slirp_socket, so, version_id); - - if (ret < 0) - return ret; - - if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) != - slirp->vnetwork_addr.s_addr) { - return -EINVAL; - } - for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { - if (ex_ptr->write_cb && - so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr && - so->so_fport == ex_ptr->ex_fport) { - break; - } - } - if (!ex_ptr) - return -EINVAL; - } - - return vmstate_load_state(f, &vmstate_slirp, slirp, version_id); -} 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 OTHER + * 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 = { + .name = "slirp-tcp", + .version_id = 0, + .post_load = slirp_tcp_post_load, + .fields = (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 = opaque; + tmp->woff = tmp->parent->sb_wptr - tmp->parent->sb_data; + tmp->roff = tmp->parent->sb_rptr - tmp->parent->sb_data; + + return 0; +} + +static int sbuf_tmp_post_load(void *opaque, int version) +{ + struct sbuf_tmp *tmp = opaque; + uint32_t requested_len = 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 != requested_len) { + return -ENOMEM; + } + if (tmp->woff >= requested_len || + tmp->roff >= requested_len) { + g_critical("invalid sbuf offsets r/w=%u/%u len=%u", + tmp->roff, tmp->woff, requested_len); + return -EINVAL; + } + + tmp->parent->sb_wptr = tmp->parent->sb_data + tmp->woff; + tmp->parent->sb_rptr = tmp->parent->sb_data + tmp->roff; + + return 0; +} + + +static const VMStateDescription vmstate_slirp_sbuf_tmp = { + .name = "slirp-sbuf-tmp", + .post_load = sbuf_tmp_post_load, + .pre_save = sbuf_tmp_pre_save, + .version_id = 0, + .fields = (VMStateField[]) { + VMSTATE_UINT32(woff, struct sbuf_tmp), + VMSTATE_UINT32(roff, struct sbuf_tmp), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_slirp_sbuf = { + .name = "slirp-sbuf", + .version_id = 0, + .fields = (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 = (union slirp_sockaddr *)opaque; + return ssa->ss.ss_family == AF_INET; +} + +static int slirp_socket_pre_load(void *opaque) +{ + struct socket *so = opaque; + if (tcp_attach(so) < 0) { + return -ENOMEM; + } + /* Older versions don't load these fields */ + so->so_ffamily = AF_INET; + so->so_lfamily = 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 = opaque; + + tss->portable_family = SS_FAMILY_MIG_OTHER; + + if (tss->parent->ss.ss_family == AF_INET) { + tss->portable_family = SS_FAMILY_MIG_IPV4; + } else if (tss->parent->ss.ss_family == AF_INET6) { + tss->portable_family = SS_FAMILY_MIG_IPV6; + } + + return 0; +} + +static int ss_family_post_load(void *opaque, int version_id) +{ + SS_FamilyTmpStruct *tss = opaque; + + switch (tss->portable_family) { + case SS_FAMILY_MIG_IPV4: + tss->parent->ss.ss_family = 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 = 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 = { + .name = "slirp-socket-addr/ss_family", + .pre_save = ss_family_pre_save, + .post_load = ss_family_post_load, + .fields = (VMStateField[]) { + VMSTATE_UINT16(portable_family, SS_FamilyTmpStruct), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_slirp_socket_addr = { + .name = "slirp-socket-addr", + .version_id = 4, + .fields = (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 = { + .name = "slirp-socket", + .version_id = 4, + .pre_load = slirp_socket_pre_load, + .fields = (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 = { + .name = "slirp_bootpclient", + .fields = (VMStateField[]) { + VMSTATE_UINT16(allocated, BOOTPClient), + VMSTATE_BUFFER(macaddr, BOOTPClient), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_slirp = { + .name = "slirp", + .version_id = 4, + .fields = (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 = opaque; + struct gfwd_list *ex_ptr; + + for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) + if (ex_ptr->write_cb) { + struct socket *so; + so = 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 = opaque; + struct gfwd_list *ex_ptr; + + while (qemu_get_byte(f)) { + int ret; + struct socket *so = socreate(slirp); + + ret = vmstate_load_state(f, &vmstate_slirp_socket, so, version_id); + if (ret < 0) { + return ret; + } + + if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) != + slirp->vnetwork_addr.s_addr) { + return -EINVAL; + } + for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { + if (ex_ptr->write_cb && + so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr && + so->so_fport == 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 = { + .save_state = slirp_state_save, + .load_state = 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/Makefile.objs b/slirp/Makefile.objs index 959558c732..7abc7549ab 100644 --- a/slirp/Makefile.objs +++ b/slirp/Makefile.objs @@ -20,6 +20,7 @@ slirp.mo-objs = \ sbuf.o \ slirp.o \ socket.o \ + state.o \ tcp_input.o \ tcp_output.o \ tcp_subr.o \ @@ -29,4 +30,4 @@ slirp.mo-objs = \ udp6.o \ $(NULL) -slirp.mo-cflags = -DG_LOG_DOMAIN=\"Slirp\" +slirp.mo-cflags = -DG_LOG_DOMAIN=\"Slirp\" -DWITH_QEMU=1 From patchwork Wed Nov 21 22:06:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430ctr4wW9z9s1x for ; Thu, 22 Nov 2018 09:39:00 +1100 (AEDT) Received: from localhost ([::1]:42734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPb98-0007PG-Ax for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:38:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPahk-0007DP-Nt for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPahg-0006bS-ID for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36328) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPahg-0006YN-55 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:36 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 127B030020A8; Wed, 21 Nov 2018 22:10:35 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CB095D75C; Wed, 21 Nov 2018 22:10:29 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:46 +0400 Message-Id: <20181121220647.18844-30-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 21 Nov 2018 22:10:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 29/30] slirp: replace remaining QEMU 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Introduce utility header/object, and replace remaining qemu functions with SLIRP helpers. Signed-off-by: Marc-André Lureau --- slirp/ip.h | 14 +-- slirp/ip6.h | 5 +- slirp/ip6_icmp.h | 16 ++-- slirp/libslirp.h | 12 ++- slirp/qtailq.h | 218 ++++++++++++++++++++++++++++++++++++++++++++ slirp/slirp.h | 12 +-- slirp/util.h | 148 ++++++++++++++++++++++++++++++ slirp/arp_table.c | 1 - slirp/bootp.c | 1 - slirp/cksum.c | 1 - slirp/dhcpv6.c | 2 - slirp/dnssearch.c | 1 - slirp/if.c | 2 - slirp/ip6_icmp.c | 4 - slirp/ip6_input.c | 1 - slirp/ip6_output.c | 2 - slirp/ip_icmp.c | 7 +- slirp/ip_input.c | 1 - slirp/ip_output.c | 1 - slirp/mbuf.c | 1 - slirp/misc.c | 21 ++--- slirp/ncsi.c | 1 - slirp/ndp_table.c | 2 - slirp/sbuf.c | 2 - slirp/slirp.c | 7 -- slirp/socket.c | 18 ++-- slirp/tcp_input.c | 1 - slirp/tcp_output.c | 1 - slirp/tcp_subr.c | 13 ++- slirp/tcp_timer.c | 1 - slirp/tftp.c | 7 +- slirp/udp.c | 7 +- slirp/udp6.c | 2 - slirp/util.c | 176 +++++++++++++++++++++++++++++++++++ slirp/Makefile.objs | 1 + 35 files changed, 609 insertions(+), 101 deletions(-) create mode 100644 slirp/qtailq.h create mode 100644 slirp/util.h create mode 100644 slirp/util.c diff --git a/slirp/ip.h b/slirp/ip.h index 243b6c8b24..cd6ddf2bb7 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; #define IP_MAXPACKET 65535 /* maximum packet size */ @@ -151,7 +151,7 @@ struct ip_timestamp { n_long ipt_time; } ipt_ta[1]; } ipt_timestamp; -} QEMU_PACKED; +} SLIRP_PACKED; /* 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; /* * Ip reassembly queue structure. Each fragment @@ -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; +} SLIRP_PACKED; /* * Ip header, when holding a fragment. @@ -227,7 +227,7 @@ struct ipq { struct ipasfrag { struct qlink ipf_link; struct ip ipf_ip; -} QEMU_PACKED; +} SLIRP_PACKED; #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 14e9c78735..e0a13dec1c 100644 --- a/slirp/ip6.h +++ b/slirp/ip6.h @@ -7,7 +7,6 @@ #define SLIRP_IP6_H #include -#include "net/eth.h" #define ALLNODES_MULTICAST { .s6_addr = \ { 0xff, 0x02, 0x00, 0x00,\ @@ -133,7 +132,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; +} SLIRP_PACKED; /* * IPv6 pseudo-header used by upper-layer protocols @@ -145,7 +144,7 @@ struct ip6_pseudohdr { uint16_t ih_zero_hi; /* zero */ uint8_t ih_zero_lo; /* zero */ uint8_t ih_nh; /* next header */ -} QEMU_PACKED; +} SLIRP_PACKED; #endif diff --git a/slirp/ip6_icmp.h b/slirp/ip6_icmp.h index 32b0914055..1f09b485e3 100644 --- a/slirp/ip6_icmp.h +++ b/slirp/ip6_icmp.h @@ -48,12 +48,12 @@ 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; +} SLIRP_PACKED; struct ndp_ns { /* Neighbor Solicitation Message */ uint32_t reserved; struct in6_addr target; /* Target Address */ -} QEMU_PACKED; +} SLIRP_PACKED; struct ndp_na { /* Neighbor Advertisement Message */ #if G_BYTE_ORDER == G_BIG_ENDIAN @@ -72,13 +72,13 @@ struct ndp_na { /* Neighbor Advertisement Message */ reserved_lo:24; #endif struct in6_addr target; /* Target Address */ -} QEMU_PACKED; +} SLIRP_PACKED; struct ndp_redirect { uint32_t reserved; struct in6_addr target; /* Target Address */ struct in6_addr dest; /* Destination Address */ -} QEMU_PACKED; +} SLIRP_PACKED; /* * Structure of an icmpv6 header. @@ -103,7 +103,7 @@ 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; +} SLIRP_PACKED; #define ICMP6_MINLEN 4 #define ICMP6_ERROR_MINLEN 8 @@ -134,16 +134,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; /* NDP options type */ #define NDPOPT_LINKLAYER_SOURCE 1 /* Source Link-Layer Address */ diff --git a/slirp/libslirp.h b/slirp/libslirp.h index f2d71bd1f6..2c90738f89 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -1,7 +1,17 @@ #ifndef LIBSLIRP_H #define LIBSLIRP_H -#include "qemu-common.h" +#include +#include +#include + +#ifdef _WIN32 +#include +#include +#else +#include +#include +#endif typedef struct Slirp Slirp; diff --git a/slirp/qtailq.h b/slirp/qtailq.h new file mode 100644 index 0000000000..7c1d73a5bd --- /dev/null +++ b/slirp/qtailq.h @@ -0,0 +1,218 @@ +/* $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 PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * 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, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * 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. + */ + +#define Q_TAILQ_HEAD(name, type, qual) \ + struct name { \ + qual type *tqh_first; /* first element */ \ + qual type *qual *tqh_last; /* addr of last next element */ \ + } +#define QTAILQ_HEAD(name, type) Q_TAILQ_HEAD(name, struct type, ) + +#define QTAILQ_HEAD_INITIALIZER(head) \ + { \ + NULL, &(head).tqh_first \ + } + +#define Q_TAILQ_ENTRY(type, qual) \ + struct { \ + qual type *tqe_next; /* next element */ \ + qual type *qual *tqe_prev; /* address of previous next element */ \ + } +#define QTAILQ_ENTRY(type) Q_TAILQ_ENTRY(struct type, ) + +/* + * Tail queue functions. + */ +#define QTAILQ_INIT(head) \ + do { \ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ + } while (/*CONSTCOND*/ 0) + +#define QTAILQ_INSERT_HEAD(head, elm, field) \ + do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ + } while (/*CONSTCOND*/ 0) + +#define QTAILQ_INSERT_TAIL(head, elm, field) \ + do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + } while (/*CONSTCOND*/ 0) + +#define QTAILQ_INSERT_AFTER(head, listelm, elm, field) \ + do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ + } while (/*CONSTCOND*/ 0) + +#define QTAILQ_INSERT_BEFORE(listelm, elm, field) \ + do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ + } while (/*CONSTCOND*/ 0) + +#define QTAILQ_REMOVE(head, elm, field) \ + do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ + (elm)->field.tqe_prev = NULL; \ + } while (/*CONSTCOND*/ 0) + +#define QTAILQ_FOREACH(var, head, field) \ + for ((var) = ((head)->tqh_first); (var); (var) = ((var)->field.tqe_next)) + +#define QTAILQ_FOREACH_SAFE(var, head, field, next_var) \ + for ((var) = ((head)->tqh_first); \ + (var) && ((next_var) = ((var)->field.tqe_next), 1); \ + (var) = (next_var)) + +#define QTAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \ + (var); \ + (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last))) + +#define QTAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, prev_var) \ + for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \ + (var) && \ + ((prev_var) = \ + (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)), \ + 1); \ + (var) = (prev_var)) + +/* + * Tail queue access methods. + */ +#define QTAILQ_EMPTY(head) ((head)->tqh_first == 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_prev != NULL) + +#define QTAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) +#define QTAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + +#define field_at_offset(base, offset, type) \ + ((type)(((char *)(base)) + (offset))) + +typedef struct DUMMY_Q_ENTRY DUMMY_Q_ENTRY; +typedef struct DUMMY_Q DUMMY_Q; + +struct DUMMY_Q_ENTRY { + QTAILQ_ENTRY(DUMMY_Q_ENTRY) next; +}; + +struct DUMMY_Q { + QTAILQ_HEAD(DUMMY_Q_HEAD, DUMMY_Q_ENTRY) head; +}; + +#define dummy_q ((DUMMY_Q *)0) +#define dummy_qe ((DUMMY_Q_ENTRY *)0) + +/* + * Offsets of layout of a tail queue head. + */ +#define QTAILQ_FIRST_OFFSET (offsetof(typeof(dummy_q->head), tqh_first)) +#define QTAILQ_LAST_OFFSET (offsetof(typeof(dummy_q->head), tqh_last)) +/* + * Raw access of elements of a tail queue + */ +#define QTAILQ_RAW_FIRST(head) \ + (*field_at_offset(head, QTAILQ_FIRST_OFFSET, void **)) +#define QTAILQ_RAW_TQH_LAST(head) \ + (*field_at_offset(head, QTAILQ_LAST_OFFSET, void ***)) + +/* + * Offsets of layout of a tail queue element. + */ +#define QTAILQ_NEXT_OFFSET (offsetof(typeof(dummy_qe->next), tqe_next)) +#define QTAILQ_PREV_OFFSET (offsetof(typeof(dummy_qe->next), tqe_prev)) + +/* + * Raw access of elements of a tail entry + */ +#define QTAILQ_RAW_NEXT(elm, entry) \ + (*field_at_offset(elm, entry + QTAILQ_NEXT_OFFSET, void **)) +#define QTAILQ_RAW_TQE_PREV(elm, entry) \ + (*field_at_offset(elm, entry + QTAILQ_PREV_OFFSET, void ***)) +/* + * Tail queue tranversal using pointer arithmetic. + */ +#define QTAILQ_RAW_FOREACH(elm, head, entry) \ + for ((elm) = QTAILQ_RAW_FIRST(head); (elm); \ + (elm) = 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) = NULL; \ + QTAILQ_RAW_TQE_PREV(elm, entry) = QTAILQ_RAW_TQH_LAST(head); \ + *QTAILQ_RAW_TQH_LAST(head) = (elm); \ + QTAILQ_RAW_TQH_LAST(head) = &QTAILQ_RAW_NEXT(elm, entry); \ + } while (/*CONSTCOND*/ 0) + +#endif /* QTAILQ_H */ diff --git a/slirp/slirp.h b/slirp/slirp.h index 6e7a663b6f..08ec331ee5 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -5,8 +5,8 @@ typedef char *caddr_t; -# include # include +# include # include # include # include @@ -45,10 +45,8 @@ typedef char *caddr_t; #define quehead slirp_quehead #include "debug.h" - -#include "qemu/queue.h" -#include "qemu/sockets.h" -#include "net/eth.h" +#include "util.h" +#include "qtailq.h" #include "libslirp.h" #include "ip.h" @@ -93,7 +91,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; #define ARP_TABLE_SIZE 16 @@ -110,7 +108,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; #define NDP_TABLE_SIZE 16 diff --git a/slirp/util.h b/slirp/util.h new file mode 100644 index 0000000000..daf652d3e6 --- /dev/null +++ b/slirp/util.h @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2010-2016 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 OTHER + * 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_ + +#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 + +#ifndef DIV_ROUND_UP +#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) +#endif + +#define SCALE_MS 1000000 + +#ifndef container_of +#define container_of(ptr, type, member) (__extension__({ \ + const typeof(((type *) 0)->member) *__mptr = (ptr); \ + (type *) ((char *) __mptr - offsetof(type, member));})) +#endif + +#ifndef glue +#define xglue(x, y) x ## y +#define glue(x, y) xglue(x, y) +#define stringify(s) tostring(s) +#define tostring(s) #s +#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 ETH_ALEN 6 +#define ETH_HLEN 6 +#define ETH_P_IP (0x0800) /* Internet Protocol packet */ +#define ETH_P_ARP (0x0806) /* Address Resolution packet */ +#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); +int inet_aton(const char *cp, struct in_addr *ia); +#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 socket_set_nodelay(int fd) +{ + int v = 1; + return slirp_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v)); +} + +static inline int socket_set_fast_reuse(int fd) +{ +#ifndef _WIN32 + int v = 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 Windows + * 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.aspx */ + return 0; +#endif +} + +static inline void pstrcpy(char *buf, int buf_size, const char *str) +{ + int c; + char *q = buf; + + if (buf_size <= 0) + return; + + for(;;) { + c = *str++; + if (c == 0 || q >= buf + buf_size - 1) + break; + *q++ = c; + } + *q = '\0'; +} + +#endif diff --git a/slirp/arp_table.c b/slirp/arp_table.c index bf71b984ad..8ea655f79d 100644 --- a/slirp/arp_table.c +++ b/slirp/arp_table.c @@ -22,7 +22,6 @@ * THE SOFTWARE. */ -#include "qemu/osdep.h" #include "slirp.h" void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]) 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" #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 */ -#include "qemu/osdep.h" #include "slirp.h" /* diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c index 752df40536..9ffba38e8f 100644 --- a/slirp/dhcpv6.c +++ b/slirp/dhcpv6.c @@ -20,8 +20,6 @@ * along with this program; if not, see . */ -#include "qemu/osdep.h" -#include "qemu/log.h" #include "slirp.h" #include "dhcpv6.h" 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. */ -#include "qemu/osdep.h" #include "slirp.h" static const uint8_t RFC3397_OPT_DOMAIN_SEARCH = 119; diff --git a/slirp/if.c b/slirp/if.c index 73e3705740..2ad03b8a79 100644 --- a/slirp/if.c +++ b/slirp/if.c @@ -5,9 +5,7 @@ * terms and conditions of the copyright. */ -#include "qemu/osdep.h" #include "slirp.h" -#include "qemu/timer.h" static void ifs_insque(struct mbuf *ifm, struct mbuf *ifmhead) diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index e72c57a81d..2a432ebbd4 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -3,12 +3,8 @@ * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. */ -#include "qemu/osdep.h" #include "slirp.h" #include "ip6_icmp.h" -#include "qemu/timer.h" -#include "qemu/error-report.h" -#include "qemu/log.h" #define NDP_Interval g_rand_int_range(slirp->grand, \ NDP_MinRtrAdvInterval, NDP_MaxRtrAdvInterval) 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. */ -#include "qemu/osdep.h" #include "slirp.h" #include "ip6_icmp.h" 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. */ -#include "qemu/osdep.h" -#include "qemu-common.h" #include "slirp.h" /* Number of packets queued before we start sending diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index 7c7e042049..e2e673ceaa 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 */ -#include "qemu/osdep.h" #include "slirp.h" #include "ip_icmp.h" @@ -83,7 +82,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen) struct ip *ip = mtod(m, struct ip *); struct sockaddr_in addr; - so->s = qemu_socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); + so->s = slirp_socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); if (so->s == -1) { return -1; } @@ -114,7 +113,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen) void icmp_detach(struct socket *so) { - closesocket(so->s); + slirp_closesocket(so->s); sofree(so); } @@ -421,7 +420,7 @@ void icmp_receive(struct socket *so) icp = mtod(m, struct icmp *); id = icp->icmp_id; - len = qemu_recv(so->s, icp, M_ROOM(m), 0); + len = slirp_recv(so->s, icp, M_ROOM(m), 0); /* * The behavior of reading SOCK_DGRAM+IPPROTO_ICMP sockets is inconsistent * between host OSes. On Linux, only the ICMP header and payload is diff --git a/slirp/ip_input.c b/slirp/ip_input.c index 6831526320..cfda30fccd 100644 --- a/slirp/ip_input.c +++ b/slirp/ip_input.c @@ -38,7 +38,6 @@ * terms and conditions of the copyright. */ -#include "qemu/osdep.h" #include "slirp.h" #include "ip_icmp.h" 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. */ -#include "qemu/osdep.h" #include "slirp.h" /* 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 */ -#include "qemu/osdep.h" #include "slirp.h" #define MBUF_THRESH 30 diff --git a/slirp/misc.c b/slirp/misc.c index 7789cefefa..5b1c526f17 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -5,11 +5,8 @@ * terms and conditions of the copyright. */ -#include "qemu/osdep.h" #include "slirp.h" #include "libslirp.h" -#include "qemu/error-report.h" -#include "qemu/main-loop.h" inline void insque(void *a, void *b) @@ -83,14 +80,14 @@ slirp_socketpair_with_oob(int sv[2]) int ret, s; sv[1] = -1; - s = qemu_socket(AF_INET, SOCK_STREAM, 0); + s = 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; } - sv[1] = qemu_socket(AF_INET, SOCK_STREAM, 0); + sv[1] = slirp_socket(AF_INET, SOCK_STREAM, 0); if (sv[1] < 0) { goto err; } @@ -113,16 +110,16 @@ slirp_socketpair_with_oob(int sv[2]) goto err; } - closesocket(s); + slirp_closesocket(s); return 0; err: g_critical("slirp_socketpair(): %s", strerror(errno)); if (s >= 0) { - closesocket(s); + slirp_closesocket(s); } if (sv[1] >= 0) { - closesocket(sv[1]); + slirp_closesocket(sv[1]); } return -1; } @@ -162,16 +159,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; } so->s = sp[0]; - closesocket(sp[1]); + slirp_closesocket(sp[1]); socket_set_fast_reuse(so->s); opt = 1; - qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); + slirp_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); so->slirp->cb->set_nonblock(so->s); return 1; } 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" #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. */ -#include "qemu/osdep.h" -#include "qemu-common.h" #include "slirp.h" void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr, diff --git a/slirp/sbuf.c b/slirp/sbuf.c index 17f28e97a6..51a9f0cc7d 100644 --- a/slirp/sbuf.c +++ b/slirp/sbuf.c @@ -5,9 +5,7 @@ * terms and conditions of the copyright. */ -#include "qemu/osdep.h" #include "slirp.h" -#include "qemu/main-loop.h" static void sbappendsb(struct sbuf *sb, struct mbuf *m); diff --git a/slirp/slirp.c b/slirp/slirp.c index a1f42c8b19..39c0370e19 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -21,14 +21,7 @@ * 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 "qemu/timer.h" -#include "qemu/error-report.h" -#include "migration/register.h" #include "slirp.h" -#include "hw/hw.h" -#include "qemu/cutils.h" #ifdef WITH_QEMU #include "state.h" diff --git a/slirp/socket.c b/slirp/socket.c index 4d5be38747..7ae88b8e87 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -5,8 +5,6 @@ * terms and conditions of the copyright. */ -#include "qemu/osdep.h" -#include "qemu-common.h" #include "slirp.h" #include "ip_icmp.h" #ifdef __sun__ @@ -187,7 +185,7 @@ soread(struct socket *so) */ sopreprbuf(so, iov, &n); - nn = qemu_recv(so->s, iov[0].iov_base, iov[0].iov_len,0); + nn = slirp_recv(so->s, iov[0].iov_base, iov[0].iov_len,0); if (nn <= 0) { if (nn < 0 && (errno == EINTR || errno == EAGAIN)) return 0; @@ -203,7 +201,7 @@ soread(struct socket *so) if (getpeername(so->s, paddr, &alen) < 0) { err = errno; } else { - getsockopt(so->s, SOL_SOCKET, SO_ERROR, + slirp_getsockopt(so->s, SOL_SOCKET, SO_ERROR, &err, &elen); } } @@ -233,7 +231,7 @@ soread(struct socket *so) */ if (n == 2 && nn == iov[0].iov_len) { int ret; - ret = qemu_recv(so->s, iov[1].iov_base, iov[1].iov_len,0); + ret = slirp_recv(so->s, iov[1].iov_base, iov[1].iov_len,0); if (ret > 0) nn += ret; } @@ -554,7 +552,7 @@ sorecvfrom(struct socket *so) */ len = M_FREEROOM(m); /* if (so->so_fport != htons(53)) { */ - ioctlsocket(so->s, FIONREAD, &n); + slirp_ioctlsocket(so->s, FIONREAD, &n); if (n > len) { n = (m->m_data - m->m_dat) + m->m_len + n + 1; @@ -719,14 +717,14 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr, addr.sin_addr.s_addr = haddr; addr.sin_port = hport; - if (((s = qemu_socket(AF_INET,SOCK_STREAM,0)) < 0) || + if (((s = slirp_socket(AF_INET,SOCK_STREAM,0)) < 0) || (socket_set_fast_reuse(s) < 0) || (bind(s,(struct sockaddr *)&addr, sizeof(addr)) < 0) || (listen(s,1) < 0)) { int tmperrno = errno; /* Don't clobber the real reason we failed */ if (s >= 0) { - closesocket(s); + slirp_closesocket(s); } sofree(so); /* Restore the real errno */ @@ -737,9 +735,9 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_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 = 1; - qemu_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int)); + slirp_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int)); getsockname(s,(struct sockaddr *)&addr,&addrlen); so->so_ffamily = AF_INET; diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c index f205a1e6cb..3cd6277672 100644 --- a/slirp/tcp_input.c +++ b/slirp/tcp_input.c @@ -38,7 +38,6 @@ * terms and conditions of the copyright. */ -#include "qemu/osdep.h" #include "slirp.h" #include "ip_icmp.h" diff --git a/slirp/tcp_output.c b/slirp/tcp_output.c index 2f7f90d67e..f02b94b8f0 100644 --- a/slirp/tcp_output.c +++ b/slirp/tcp_output.c @@ -38,7 +38,6 @@ * terms and conditions of the copyright. */ -#include "qemu/osdep.h" #include "slirp.h" static const u_char tcp_outflags[TCP_NSTATES] = { diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 3b15148187..4e486093c0 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -38,7 +38,6 @@ * terms and conditions of the copyright. */ -#include "qemu/osdep.h" #include "slirp.h" /* patchable/settable parameters for tcp */ @@ -337,7 +336,7 @@ tcp_close(struct tcpcb *tp) /* clobber input socket cache if we're closing the cached connection */ if (so == slirp->tcp_last_so) slirp->tcp_last_so = &slirp->tcb; - closesocket(so->s); + slirp_closesocket(so->s); sbfree(&so->so_rcv); sbfree(&so->so_snd); sofree(so); @@ -407,7 +406,7 @@ int tcp_fconnect(struct socket *so, unsigned short af) DEBUG_CALL("tcp_fconnect"); DEBUG_ARG("so = %p", so); - ret = so->s = qemu_socket(af, SOCK_STREAM, 0); + ret = so->s = slirp_socket(af, SOCK_STREAM, 0); if (ret >= 0) { int opt, s=so->s; struct sockaddr_storage addr; @@ -415,9 +414,9 @@ int tcp_fconnect(struct socket *so, unsigned short af) so->slirp->cb->set_nonblock(s); socket_set_fast_reuse(s); opt = 1; - qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt)); + slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt)); opt = 1; - qemu_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)); + slirp_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)); addr = so->fhost.ss; DEBUG_CALL(" connect()ing"); @@ -487,7 +486,7 @@ void tcp_connect(struct socket *inso) so->slirp->cb->set_nonblock(s); socket_set_fast_reuse(s); opt = 1; - qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); + slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); socket_set_nodelay(s); so->fhost.ss = addr; @@ -496,7 +495,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); /* Don't select it yet, even though we have an FD */ /* if it's not FACCEPTONCE, it's already NOFDREF */ diff --git a/slirp/tcp_timer.c b/slirp/tcp_timer.c index d953a16386..ebc9d16f06 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 */ -#include "qemu/osdep.h" #include "slirp.h" static struct tcpcb *tcp_timers(register struct tcpcb *tp, int timer); diff --git a/slirp/tftp.c b/slirp/tftp.c index 6fb381ef33..eae7f7c7f2 100644 --- a/slirp/tftp.c +++ b/slirp/tftp.c @@ -22,10 +22,11 @@ * THE SOFTWARE. */ -#include "qemu/osdep.h" #include "slirp.h" -#include "qemu-common.h" -#include "qemu/cutils.h" + +#include +#include +#include static inline int tftp_session_in_use(struct tftp_session *spt) { diff --git a/slirp/udp.c b/slirp/udp.c index 4cf0d34d64..e49a8862d4 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -38,7 +38,6 @@ * terms and conditions of the copyright. */ -#include "qemu/osdep.h" #include "slirp.h" #include "ip_icmp.h" @@ -281,7 +280,7 @@ int udp_output(struct socket *so, struct mbuf *m, int udp_attach(struct socket *so, unsigned short af) { - so->s = qemu_socket(af, SOCK_DGRAM, 0); + so->s = slirp_socket(af, SOCK_DGRAM, 0); if (so->s != -1) { so->so_expire = curtime + SO_EXPIRE; insque(so, &so->slirp->udb); @@ -292,7 +291,7 @@ udp_attach(struct socket *so, unsigned short af) void udp_detach(struct socket *so) { - closesocket(so->s); + slirp_closesocket(so->s); sofree(so); } @@ -327,7 +326,7 @@ udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr, socklen_t addrlen = sizeof(struct sockaddr_in); so = socreate(slirp); - so->s = qemu_socket(AF_INET,SOCK_DGRAM,0); + so->s = slirp_socket(AF_INET,SOCK_DGRAM,0); if (so->s < 0) { sofree(so); return NULL; 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 */ -#include "qemu/osdep.h" -#include "qemu-common.h" #include "slirp.h" #include "udp.h" #include "dhcpv6.h" 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 OTHER + * 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 = inet_addr(cp); + if (addr == 0xffffffff) { + return 0; + } + ia->s_addr = addr; + return 1; +} +#endif + +static void slirp_set_cloexec(int fd) +{ +#ifndef _WIN32 + int f; + f = fcntl(fd, F_GETFD); + assert(f != -1); + f = fcntl(fd, F_SETFD, f | FD_CLOEXEC); + assert(f != -1); +#endif +} + +/* + * Opens a socket with FD_CLOEXEC set + */ +int slirp_socket(int domain, int type, int protocol) +{ + int ret; + +#ifdef SOCK_CLOEXEC + ret = socket(domain, type | SOCK_CLOEXEC, protocol); + if (ret != -1 || errno != EINVAL) { + return ret; + } +#endif + ret = socket(domain, type, protocol); + if (ret >= 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 = ioctlsocket(fd, req, val); + if (ret < 0) { + errno = socket_error(); + } + return ret; +} + +#undef closesocket +int slirp_closesocket(int fd) +{ + int ret; + ret = closesocket(fd); + if (ret < 0) { + errno = socket_error(); + } + return ret; +} +#endif /* WIN32 */ diff --git a/slirp/Makefile.objs b/slirp/Makefile.objs index 7abc7549ab..61cdcc6877 100644 --- a/slirp/Makefile.objs +++ b/slirp/Makefile.objs @@ -28,6 +28,7 @@ slirp.mo-objs = \ tftp.o \ udp.o \ udp6.o \ + util.o \ $(NULL) slirp.mo-cflags = -DG_LOG_DOMAIN=\"Slirp\" -DWITH_QEMU=1 From patchwork Wed Nov 21 22:06:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 1001452 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430cjG04Qnz9s29 for ; Thu, 22 Nov 2018 09:30:42 +1100 (AEDT) Received: from localhost ([::1]:42672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPb15-0008GQ-JC for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2018 17:30:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPai1-0007Oi-7B for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPahx-0006vP-21 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51770) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPahq-0006ng-V0 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 17:10:48 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12ABC30820CE; Wed, 21 Nov 2018 22:10:43 +0000 (UTC) Received: from localhost (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id A13ED5C21E; Wed, 21 Nov 2018 22:10:38 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Thu, 22 Nov 2018 02:06:47 +0400 Message-Id: <20181121220647.18844-31-marcandre.lureau@redhat.com> In-Reply-To: <20181121220647.18844-1-marcandre.lureau@redhat.com> References: <20181121220647.18844-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 21 Nov 2018 22:10:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-3.2 v2 30/30] build-sys: add a basic meson build 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: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This is a minimal file to build a libslirp shared library. It has been tested to build on Linux and with mingw64 cross-compilation. Signed-off-by: Marc-André Lureau --- slirp/meson.build | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 slirp/meson.build diff --git a/slirp/meson.build b/slirp/meson.build new file mode 100644 index 0000000000..aa6f1b39e2 --- /dev/null +++ b/slirp/meson.build @@ -0,0 +1,48 @@ +project('slirp', 'c', version : '3.1') + +add_global_arguments('-std=gnu99', language : 'c') + +host_system = host_machine.system() + +glib_dep = dependency('glib-2.0') + +cc = meson.get_compiler('c') + +platform_deps = [] + +if host_system == 'windows' + platform_deps += [ + cc.find_library('ws2_32'), + cc.find_library('iphlpapi') + ] +endif + +shared_library('slirp', + 'arp_table.c', + 'bootp.c', + 'cksum.c', + 'dhcpv6.c', + 'dnssearch.c', + 'if.c', + 'ip6_icmp.c', + 'ip6_input.c', + 'ip6_output.c', + 'ip_icmp.c', + 'ip_input.c', + 'ip_output.c', + 'mbuf.c', + 'misc.c', + 'ncsi.c', + 'ndp_table.c', + 'sbuf.c', + 'slirp.c', + 'socket.c', + 'tcp_input.c', + 'tcp_output.c', + 'tcp_subr.c', + 'tcp_timer.c', + 'tftp.c', + 'udp.c', + 'udp6.c', + 'util.c', + dependencies : [glib_dep, platform_deps])