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 7083D5A0271 for ; Wed, 2 Aug 2023 05:15:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1690946145; bh=WP3Hs2ac42RXwAsmrV067OWH3n+xTBiPaJ/UTRhcq8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mHLaWzPEI22syzpl7mRz6VcTSJAK2MWR5hOZptCnY4GiXzCAhyqqC3R6PCwkAkCV8 uuKVzHuZg7ztO2MmaIZsXptqRw2lQRrGG1IliJK8oz789unSU1rn3TS7kN2z8eMIso 2+bseb1wORRPrUq9ZJ+MOCXEUcsOt9Zvn8F30DXk= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4RFxv53qdBz4yLZ; Wed, 2 Aug 2023 13:15:45 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 3/3] tap: Remove unnecessary global tun_ns_fd Date: Wed, 2 Aug 2023 13:15:42 +1000 Message-ID: <20230802031542.2726758-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802031542.2726758-1-david@gibson.dropbear.id.au> References: <20230802031542.2726758-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 5Z5Z5QTHA6JJVV3U75RYDH33HEJ5T7CL X-Message-ID-Hash: 5Z5Z5QTHA6JJVV3U75RYDH33HEJ5T7CL 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: Paul Holzinger , 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: tap_ns_tun(), which runs in an ephemeral thread puts the fd it opens into the global variable tun_ns_fd to communicate it back to the main thread in tap_sock_tun_init(). However, the only thing tap_sock_tun_init() does with it is copies it to c->fd_tap and everything else uses it from there. tap_ns_tun() already has access to the context structure, so we might as well store the value directly in there rather than having a global as an intermediate. Signed-off-by: David Gibson --- tap.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tap.c b/tap.c index a5d357a..e034f94 100644 --- a/tap.c +++ b/tap.c @@ -1165,8 +1165,6 @@ static void tap_sock_unix_new(struct ctx *c) epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); } -static int tun_ns_fd = -1; - /** * tap_ns_tun() - Get tuntap fd in namespace * @c: Execution context @@ -1182,7 +1180,7 @@ static int tap_ns_tun(void *arg) struct ctx *c = (struct ctx *)arg; int fd, rc; - tun_ns_fd = -1; + c->fd_tap = -1; memcpy(ifr.ifr_name, c->pasta_ifn, IFNAMSIZ); ns_enter(c); @@ -1197,7 +1195,7 @@ static int tap_ns_tun(void *arg) if (!(c->pasta_ifi = if_nametoindex(c->pasta_ifn))) die("Tap device opened but no network interface found"); - tun_ns_fd = fd; + c->fd_tap = fd; return 0; } @@ -1211,13 +1209,11 @@ static void tap_sock_tun_init(struct ctx *c) struct epoll_event ev = { 0 }; NS_CALL(tap_ns_tun, c); - if (tun_ns_fd == -1) + if (c->fd_tap == -1) die("Failed to set up tap device in namespace"); pasta_ns_conf(c); - c->fd_tap = tun_ns_fd; - ev.data.fd = c->fd_tap; ev.events = EPOLLIN | EPOLLRDHUP; epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); -- 2.41.0