From nobody Mon Sep 29 02:39:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547726905893906.6703354525883; Thu, 17 Jan 2019 04:08:25 -0800 (PST) Received: from localhost ([127.0.0.1]:42907 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gk6T8-00065J-Cf for importer@patchew.org; Thu, 17 Jan 2019 07:08:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gk67d-0006nl-BG for qemu-devel@nongnu.org; Thu, 17 Jan 2019 06:46:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gk67b-0005zf-9B for qemu-devel@nongnu.org; Thu, 17 Jan 2019 06:46:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40540) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gk67Z-0005xT-BO for qemu-devel@nongnu.org; Thu, 17 Jan 2019 06:46:06 -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 7B4B7A786E; Thu, 17 Jan 2019 11:46:03 +0000 (UTC) Received: from localhost (unknown [10.36.112.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 059D21835A; Thu, 17 Jan 2019 11:46:01 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 17 Jan 2019 15:43:54 +0400 Message-Id: <20190117114359.5164-23-marcandre.lureau@redhat.com> In-Reply-To: <20190117114359.5164-1-marcandre.lureau@redhat.com> References: <20190117114359.5164-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.30]); Thu, 17 Jan 2019 11:46:03 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 22/27] slirp: improve send_packet() callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Zhijian , Jan Kiszka , Jason Wang , Zhang Chen , Samuel Thibault , pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Use a more descriptive name for the callback. Reuse the SlirpWriteCb type. Wrap it to check that all data has been writte= n. Return a ssize_t for potential error handling and data-loss reporting. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/net/net.h | 2 +- slirp/libslirp.h | 11 +++++++---- slirp/slirp.h | 2 ++ net/net.c | 4 ++-- net/slirp.c | 9 +++++---- slirp/ncsi.c | 2 +- slirp/slirp.c | 17 ++++++++++++++--- 7 files changed, 32 insertions(+), 15 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 643295d1637..075cc012671 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -146,7 +146,7 @@ ssize_t qemu_sendv_packet(NetClientState *nc, const str= uct iovec *iov, int iovcnt); ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *io= v, int iovcnt, NetPacketSent *sent_cb); -void qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size); +ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size); ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int s= ize); ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf, int size, NetPacketSent *sent_cb); diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 02cbec9f8be..8e5d4ed11b5 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -15,7 +15,7 @@ =20 typedef struct Slirp Slirp; =20 -typedef int (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); +typedef ssize_t (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); typedef void (*SlirpTimerCb)(void *opaque); =20 /* @@ -23,10 +23,13 @@ typedef void (*SlirpTimerCb)(void *opaque); */ typedef struct SlirpCb { /* - * Send an ethernet frame to the guest network. The opaque parameter - * is the one given to slirp_init(). + * Send an ethernet frame to the guest network. The opaque + * parameter is the one given to slirp_init(). The function + * doesn't need to send all the data and may return nc, pkt, pkt_len); + return qemu_send_packet(&s->nc, pkt, pkt_len); } =20 static ssize_t net_slirp_receive(NetClientState *nc, const uint8_t *buf, s= ize_t size) @@ -197,7 +198,7 @@ static void net_slirp_unregister_poll_fd(int fd) } =20 static const SlirpCb slirp_cb =3D { - .output =3D net_slirp_output, + .send_packet =3D net_slirp_send_packet, .guest_error =3D net_slirp_guest_error, .clock_get_ns =3D net_slirp_clock_get_ns, .timer_new =3D net_slirp_timer_new, @@ -780,7 +781,7 @@ static void guestfwd_read(void *opaque, const uint8_t *= buf, int size) slirp_socket_recv(fwd->slirp, fwd->server, fwd->port, buf, size); } =20 -static int guestfwd_write(const void *buf, size_t len, void *chr) +static ssize_t guestfwd_write(const void *buf, size_t len, void *chr) { return qemu_chr_fe_write_all(chr, buf, len); } diff --git a/slirp/ncsi.c b/slirp/ncsi.c index 327f17543ce..359f52c2840 100644 --- a/slirp/ncsi.c +++ b/slirp/ncsi.c @@ -162,5 +162,5 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int p= kt_len) *pchecksum =3D htonl(checksum); ncsi_rsp_len +=3D 4; =20 - slirp->cb->output(slirp->opaque, ncsi_reply, ETH_HLEN + ncsi_rsp_len); + slirp_send_packet_all(slirp, ncsi_reply, ETH_HLEN + ncsi_rsp_len); } diff --git a/slirp/slirp.c b/slirp/slirp.c index c7e15e88c0c..f42d31fb632 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -800,7 +800,7 @@ static void arp_input(Slirp *slirp, const uint8_t *pkt,= int pkt_len) rah->ar_sip =3D ah->ar_tip; memcpy(rah->ar_tha, ah->ar_sha, ETH_ALEN); rah->ar_tip =3D ah->ar_sip; - slirp->cb->output(slirp->opaque, arp_reply, sizeof(arp_reply)); + slirp_send_packet_all(slirp, arp_reply, sizeof(arp_reply)); } break; case ARPOP_REPLY: @@ -900,7 +900,7 @@ static int if_encap4(Slirp *slirp, struct mbuf *ifm, st= ruct ethhdr *eh, /* target IP */ rah->ar_tip =3D iph->ip_dst.s_addr; slirp->client_ipaddr =3D iph->ip_dst; - slirp->cb->output(slirp->opaque, arp_req, sizeof(arp_req)); + slirp_send_packet_all(slirp, arp_req, sizeof(arp_req)); ifm->resolution_requested =3D true; =20 /* Expire request and drop outgoing packet after 1 second */ @@ -985,7 +985,7 @@ int if_encap(Slirp *slirp, struct mbuf *ifm) eh->h_dest[0], eh->h_dest[1], eh->h_dest[2], eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]); memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len); - slirp->cb->output(slirp->opaque, buf, ifm->m_len + ETH_HLEN); + slirp_send_packet_all(slirp, buf, ifm->m_len + ETH_HLEN); return 1; } =20 @@ -1152,3 +1152,14 @@ void slirp_socket_recv(Slirp *slirp, struct in_addr = guest_addr, int guest_port, if (ret > 0) tcp_output(sototcpcb(so)); } + +void slirp_send_packet_all(Slirp *slirp, const void *buf, size_t len) +{ + ssize_t ret =3D slirp->cb->send_packet(buf, len, slirp->opaque); + + if (ret < 0) { + g_critical("Failed to send packet, ret: %zd", ret); + } else if (ret < len) { + DEBUG_ERROR("send_packet() didn't send all data: %zd < %zu", ret, = len); + } +} --=20 2.20.1.98.gecbdaf0899