From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id E6EAF5A0275 for ; Thu, 10 Aug 2023 04:33:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1691634801; bh=6EyJq8M1IrieeD68It7CdtmpD2AjVbP9oOSgm2Pj/Ac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hMb/cA8eLrey6dTWAT/UD29nelCpdd9nZVhdfolCgnkW1Yjh/zpLCZ1F4dQ7O6iwe q3Yxg2arkT72xBgTBs9fWRmx1Upy/TgBXqtIdLVDTU3BqnI4GSSiw0KABaKUs1TZNs KhX9WsKjP1hnifEy235H7yy8Wz0VQhxtDA4+dTI4= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4RLrZT2Lgqz4wy7; Thu, 10 Aug 2023 12:33:21 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 03/13] tap: Fold reset handling into tap_handler_pasta() Date: Thu, 10 Aug 2023 12:33:05 +1000 Message-ID: <20230810023315.684784-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230810023315.684784-1-david@gibson.dropbear.id.au> References: <20230810023315.684784-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: V3TSM42XOQ5IMHD752YAOSKARGBS5KAO X-Message-ID-Hash: V3TSM42XOQ5IMHD752YAOSKARGBS5KAO 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: David Gibson 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: If tap_handler_pasta() fails, we reset the connection. But in the case of pasta the "reset" is just a fatal error. Fold the die() calls directly into tap_handler_pasta() for simplicity. Signed-off-by: David Gibson --- tap.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tap.c b/tap.c index c883d7e..866ca4d 100644 --- a/tap.c +++ b/tap.c @@ -982,15 +982,18 @@ next: /** * tap_handler_pasta() - Packet handler for tuntap file descriptor * @c: Execution context + * @events: epoll events * @now: Current timestamp - * - * Return: -ECONNRESET on receive error, 0 otherwise */ -static int tap_handler_pasta(struct ctx *c, const struct timespec *now) +static void tap_handler_pasta(struct ctx *c, uint32_t events, + const struct timespec *now) { ssize_t n, len; int ret; + if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) + die("Disconnect event on /dev/net/tun device, exiting"); + redo: n = 0; @@ -1037,15 +1040,12 @@ restart: tap6_handler(c, pool_tap6, now); if (len > 0 || ret == EAGAIN) - return 0; + return; if (n == TAP_BUF_BYTES) goto redo; - epoll_ctl(c->epollfd, EPOLL_CTL_DEL, c->fd_tap, NULL); - close(c->fd_tap); - - return -ECONNRESET; + die("Error on tap device, exiting"); } /** @@ -1269,9 +1269,6 @@ static void tap_sock_reset(struct ctx *c) exit(EXIT_SUCCESS); } - if (c->mode == MODE_PASTA) - die("Error on tap device, exiting"); - /* Close the connected socket, wait for a new connection */ epoll_ctl(c->epollfd, EPOLL_CTL_DEL, c->fd_tap, NULL); close(c->fd_tap); @@ -1293,8 +1290,11 @@ void tap_handler(struct ctx *c, int fd, uint32_t events, return; } - if ((c->mode == MODE_PASST && tap_handler_passt(c, now)) || - (c->mode == MODE_PASTA && tap_handler_pasta(c, now)) || - (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR))) - tap_sock_reset(c); + if (c->mode == MODE_PASST) { + if (tap_handler_passt(c, now) || + (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR))) + tap_sock_reset(c); + } else if (c->mode == MODE_PASTA) { + tap_handler_pasta(c, events, now); + } } -- 2.41.0