From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 04/12] conf: Remove duplicate parsing of -F option
Date: Fri, 26 Jun 2026 17:09:55 +1000 [thread overview]
Message-ID: <20260626071003.3472194-5-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20260626071003.3472194-1-david@gibson.dropbear.id.au>
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 <david@gibson.dropbear.id.au>
---
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 <sys/random.h>
#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
next prev parent reply other threads:[~2026-06-26 7:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 7:09 [PATCH 00/12] Rework option parsing in preparation for destination remapping David Gibson
2026-06-26 7:09 ` [PATCH 01/12] Makefile: Add missing PESTO_HEADERS variable David Gibson
2026-06-26 7:09 ` [PATCH 02/12] conf: Use parameter instead of global in conf_nat() David Gibson
2026-06-26 7:09 ` [PATCH 03/12] parse: Start splitting out parsing helpers David Gibson
2026-06-26 7:09 ` David Gibson [this message]
2026-06-26 7:09 ` [PATCH 05/12] conf: Clean up conf_ip4_prefix() David Gibson
2026-06-26 7:09 ` [PATCH 06/12] parse: Add helper to parse unsigned integer values David Gibson
2026-06-26 7:09 ` [PATCH 07/12] parse: Move parse_port_range() to new parsing framework David Gibson
2026-06-26 7:09 ` [PATCH 08/12] parse: Add helpers for parsing IP addresses David Gibson
2026-06-26 7:10 ` [PATCH 09/12] conf: Move address configuration into helper function David Gibson
2026-06-26 7:10 ` [PATCH 10/12] conf: Use new parsing tools to handle -a option David Gibson
2026-06-26 7:10 ` [PATCH 11/12] fwd_rule: Allow "all" port specs to be combined with other options David Gibson
2026-06-26 7:10 ` [PATCH 12/12] fwd_rule: Rewrite forward rule parsing using parse.c helpers David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260626071003.3472194-5-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).