From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id C3A825A0274 for ; Fri, 11 Aug 2023 05:20:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1691724000; bh=k1t6eWNirmvpxVLbDCXEjx7lgld5645w+yxBw9B7Lag=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AYo2QtogkZkc0gZIfy+xXBDurEh2kWcMHTI9a8wLAS/nXN8HIruiPCNt7rg0YChoN aqJ/VlHxK0qeZ8sNvK3MYp0ykfYeFi5X5Cicq6zuoTvDZkuTBMJRr2y81rloTwHkc3 /VNUM0gCyv566ZFt2LlC8RYavMBp6qJ5eXVn3JLA= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4RMTYr0mc5z4wjG; Fri, 11 Aug 2023 13:20:00 +1000 (AEST) Date: Fri, 11 Aug 2023 13:07:26 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v2 04/13] tap: Fold reset handling into tap_handler_passt() Message-ID: References: <20230810023315.684784-1-david@gibson.dropbear.id.au> <20230810023315.684784-5-david@gibson.dropbear.id.au> <20230810214946.4bdf200b@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ITua1rVI/cYlmLig" Content-Disposition: inline In-Reply-To: <20230810214946.4bdf200b@elisabeth> Message-ID-Hash: ONXKLH53MIKNP64MYPNVQJXJRGABG6DO X-Message-ID-Hash: ONXKLH53MIKNP64MYPNVQJXJRGABG6DO X-MailFrom: dgibson@gandalf.ozlabs.org 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: --ITua1rVI/cYlmLig Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 10, 2023 at 09:49:46PM +0200, Stefano Brivio wrote: > On Thu, 10 Aug 2023 12:33:06 +1000 > David Gibson wrote: >=20 > > 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 it= self > > which simplifies the caller. > >=20 > > Signed-off-by: David Gibson > > --- > > tap.c | 63 ++++++++++++++++++++++++++++++----------------------------- > > 1 file changed, 32 insertions(+), 31 deletions(-) > >=20 > > 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; > > } > > =20 > > +/** > > + * tap_sock_reset() - Handle closing or failure of connect AF_UNIX soc= ket > > + * @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 =3D -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; > > =20 > > + if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) { > > + tap_sock_reset(c); > > + return; > > + } > > + > > redo: > > p =3D pkt_buf; > > rem =3D 0; > > @@ -914,12 +936,13 @@ redo: > > n =3D recv(c->fd_tap, p, TAP_BUF_FILL, MSG_DONTWAIT); > > if (n < 0) { > > if (errno =3D=3D EINTR || errno =3D=3D EAGAIN || errno =3D=3D EWOULD= BLOCK) > > - return 0; > > + return; > > =20 > > epoll_ctl(c->epollfd, EPOLL_CTL_DEL, c->fd_tap, NULL); > > close(c->fd_tap); > > =20 > > - return -ECONNRESET; > > + tap_sock_reset(c); >=20 > ...also reported by covscan: close() before this is redundant now. Oops, yes. I spotted that, but then forgot to fix it. Fixed for a new spin. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --ITua1rVI/cYlmLig Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmTVpdMACgkQzQJF27ox 2Gf2bxAAk+XRjO20rita2Qeh4COKBbUclJn/V7nAvil4NDTWy5715EIjdg3952cC qBY4A9p16/Oi44Jg53IoMXrdSI+5FI71aytvY/6oJXhhIp/JsboAb5/YSc0hD5ok HZOtRBQsycP8J48jyxxmThcDgUMbcWbQOhHI8IgEqCCBS39PnLEfs1StYlLkGGEA b0N6vmEqcZ5Kx8P2BfyOVAlEmpQpHLSiaBtay+VixSGUaYydYJ8ttgwzNM0D00bE R4JUFpzPYfF1VrkV9Y/g8MR18lGkN/rMaTtHAtVjnURkzbBRbO99dqTxJD66TWC5 TyBfXYdqVR5vco6cxlJC6btBzTNFb5/i/+oi9psHsyPb+yfQJ1+Is9woWS3unsiM gEeD5EvwSK4gTXMzNvGzRKwD4VMOZrq9MkY/OirvlONzHKw0of2aUlJgeAQXVBhk qv/YyzGkHvt424BQ4Cq6JbEltJ/womHkJ5BBgo1MA0XNuP8TCs5L/sWBmZcZBSfP NmNRUYGMSdiJ6IIVtlgKwvs5i1Z07ROlJlXZ40CxSJysvuTqPosatf9wsfp6FyyF PloDb0ZsgG3kRtglrgI0j8RtJF2fDkrPZVjuHmi4A42OO580YkACq7H3+CtMzTz3 XLd6/iWrjpoA/xNstkxZANJhs/GVWOaUkK4O66tNIPZsCUYFZy8= =rJ2u -----END PGP SIGNATURE----- --ITua1rVI/cYlmLig--