From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 4673A5A0272 for ; Thu, 10 Aug 2023 21:49:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691696991; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uA69D5l0EiswiLjGSuaq9ZUU1WrMQL5i8oZZJeNAtv4=; b=GFtFBbf9KaEDkyS72rZM6RIJpIiyG3gS0ZKhjQa5CyVOkY8DKErwc+3NtmlEPp+SVahamN zbkHbWhwlpU7/LKxN6QL61+vP5qGao8qvFIa5q3J1Q20ytP1QBxBadAC8/JR24FB8uEnnP vVHLMefl/VR5VOb3Me9YXe0/HHYJ4K0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-212-ZXC4RckjN_ORmblkCyZ-pg-1; Thu, 10 Aug 2023 15:49:49 -0400 X-MC-Unique: ZXC4RckjN_ORmblkCyZ-pg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 45C8E185A78F; Thu, 10 Aug 2023 19:49:49 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 91384140E96E; Thu, 10 Aug 2023 19:49:48 +0000 (UTC) Date: Thu, 10 Aug 2023 21:49:46 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v2 04/13] tap: Fold reset handling into tap_handler_passt() Message-ID: <20230810214946.4bdf200b@elisabeth> In-Reply-To: <20230810023315.684784-5-david@gibson.dropbear.id.au> References: <20230810023315.684784-1-david@gibson.dropbear.id.au> <20230810023315.684784-5-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 53V2WSDRRDJEMGSRDVS2POF67FKRF3EP X-Message-ID-Hash: 53V2WSDRRDJEMGSRDVS2POF67FKRF3EP X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Thu, 10 Aug 2023 12:33:06 +1000 David Gibson wrote: > We call tap_sock_reset() if tap_handler_passt() fails, or if we get an > error event on the socket. Fold that logic into tap_handler() passt itself > which simplifies the caller. > > Signed-off-by: David Gibson > --- > tap.c | 63 ++++++++++++++++++++++++++++++----------------------------- > 1 file changed, 32 insertions(+), 31 deletions(-) > > diff --git a/tap.c b/tap.c > index 866ca4d..501af33 100644 > --- a/tap.c > +++ b/tap.c > @@ -891,19 +891,41 @@ append: > return in->count; > } > > +/** > + * tap_sock_reset() - Handle closing or failure of connect AF_UNIX socket > + * @c: Execution context > + */ > +static void tap_sock_reset(struct ctx *c) > +{ > + if (c->one_off) { > + info("Client closed connection, exiting"); > + exit(EXIT_SUCCESS); > + } > + > + /* Close the connected socket, wait for a new connection */ > + epoll_ctl(c->epollfd, EPOLL_CTL_DEL, c->fd_tap, NULL); > + close(c->fd_tap); > + c->fd_tap = -1; > +} > + > /** > * tap_handler_passt() - Packet handler for AF_UNIX file descriptor > * @c: Execution context > + * @events: epoll events > * @now: Current timestamp > - * > - * Return: -ECONNRESET on receive error, 0 otherwise > */ > -static int tap_handler_passt(struct ctx *c, const struct timespec *now) > +static void tap_handler_passt(struct ctx *c, uint32_t events, > + const struct timespec *now) > { > struct ethhdr *eh; > ssize_t n, rem; > char *p; > > + if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) { > + tap_sock_reset(c); > + return; > + } > + > redo: > p = pkt_buf; > rem = 0; > @@ -914,12 +936,13 @@ redo: > n = recv(c->fd_tap, p, TAP_BUF_FILL, MSG_DONTWAIT); > if (n < 0) { > if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) > - return 0; > + return; > > epoll_ctl(c->epollfd, EPOLL_CTL_DEL, c->fd_tap, NULL); > close(c->fd_tap); > > - return -ECONNRESET; > + tap_sock_reset(c); ...also reported by covscan: close() before this is redundant now. -- Stefano