From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202606 header.b=ot5eG3Fs; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 6C5475A0272 for ; Fri, 26 Jun 2026 09:10:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1782457808; bh=wwvIeVfmr7dAQfBaOSHSJ0cLVd+Ti807MFH8dkHzDks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ot5eG3Fs9Hjxge7eWhdzK4d0MuudP/uzQm5AZ1IO6loscZrT836cF3bp5AyX1YkAq OOKmmZVXmwI10QN3nEk0u9oS66dZh0KkGaGsegRw+S1k86i2o7lmgHpl6cfAAG+ur1 mNuoAGaE37uVVEYahqb1hWWhmaT7JGVhAWovoe/YiBmlwieL00Uzfi0ZzGWDZSg50u 8smqURmLN23OrAJhcTX3M/Ovey8ABjonLj8ktHLQT7w6iiJkRG/0K629QgBwa5td4p PkmJUy0dSu5K22jYP8ci/PIalQOEQ3Wpw17LPY/XTj6aDldRh3hZE5FpUmAIBfxHdW 8+Uf3CMjzyaVg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gmmym42sTz4whS; Fri, 26 Jun 2026 17:10:08 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 04/12] conf: Remove duplicate parsing of -F option Date: Fri, 26 Jun 2026 17:09:55 +1000 Message-ID: <20260626071003.3472194-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260626071003.3472194-1-david@gibson.dropbear.id.au> References: <20260626071003.3472194-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: PI73VJ3MLPRINHFAXVUV6O6UI2LCFCXB X-Message-ID-Hash: PI73VJ3MLPRINHFAXVUV6O6UI2LCFCXB 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: The -F option is parsed in conf() along with everything else. However, because it informs what fds we can close at startup, we also have a special case parse of it in close_open_files(). At present we duplicate the parsing and validation code, which is a bit risky. Avoid that with a conf_tap_fd() helper. Signed-off-by: David Gibson --- conf.c | 29 +++++++++++++++++++---------- conf.h | 1 + util.c | 12 +++--------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/conf.c b/conf.c index ca6c859c..32163f56 100644 --- a/conf.c +++ b/conf.c @@ -1153,6 +1153,24 @@ static void conf_sock_listen(const struct ctx *c) die_perror("Couldn't add configuration socket to epoll"); } +/** + * conf_tap_fd() - Read tap fd as supplied by -F command line option + * @arg: Argument to -F command line option + */ +int conf_tap_fd(const char *arg) +{ + long val; + + errno = 0; + val = strtol(arg, NULL, 0); + + if (errno || (val != STDIN_FILENO && val <= STDERR_FILENO) || + val > INT_MAX) + die("Invalid --fd: %s", arg); + + return val; +} + /** * conf() - Process command-line arguments and set configuration * @c: Execution context @@ -1253,7 +1271,6 @@ void conf(struct ctx *c, int argc, char **argv) const char *logfile = NULL; char *runas = NULL; size_t logsize = 0; - long fd_tap_opt; int name, ret; uid_t uid; gid_t gid; @@ -1506,15 +1523,7 @@ void conf(struct ctx *c, int argc, char **argv) c->fd_control_listen = c->fd_control = -1; break; case 'F': - errno = 0; - fd_tap_opt = strtol(optarg, NULL, 0); - - if (errno || - (fd_tap_opt != STDIN_FILENO && fd_tap_opt <= STDERR_FILENO) || - fd_tap_opt > INT_MAX) - die("Invalid --fd: %s", optarg); - - c->fd_tap = fd_tap_opt; + c->fd_tap = conf_tap_fd(optarg); c->one_off = true; *c->sock_path = 0; break; diff --git a/conf.h b/conf.h index 16f97189..1fa1280e 100644 --- a/conf.h +++ b/conf.h @@ -7,6 +7,7 @@ #define CONF_H enum passt_modes conf_mode(int argc, char *argv[]); +int conf_tap_fd(const char *arg); void conf(struct ctx *c, int argc, char **argv); void conf_listen_handler(struct ctx *c, uint32_t events); void conf_handler(struct ctx *c, uint32_t events); diff --git a/util.c b/util.c index 0aa4d42d..4bc5d6f8 100644 --- a/util.c +++ b/util.c @@ -38,6 +38,7 @@ #include "epoll_ctl.h" #include "pasta.h" #include "serialise.h" +#include "conf.h" #ifdef HAS_GETRANDOM #include #endif @@ -939,15 +940,8 @@ void close_open_files(int argc, char **argv) do { name = getopt_long(argc, argv, "-:F:", optfd, NULL); - if (name == 'F') { - errno = 0; - fd = strtol(optarg, NULL, 0); - - if (errno || - (fd != STDIN_FILENO && fd <= STDERR_FILENO) || - fd > INT_MAX) - die("Invalid --fd: %s", optarg); - } + if (name == 'F') + fd = conf_tap_fd(optarg); } while (name != -1); if (fd == -1) { -- 2.54.0