public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top
Subject: [PATCH 1/8] conf: Make the argument to --pcap option mandatory
Date: Fri, 26 Aug 2022 14:58:32 +1000	[thread overview]
Message-ID: <20220826045839.1112152-2-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20220826045839.1112152-1-david@gibson.dropbear.id.au>

[-- Attachment #1: Type: text/plain, Size: 4386 bytes --]

The --pcap or -p option can be used with or without an argument.  If given,
the argument gives the name of the file to save a packet trace to.  If
omitted, we generate a default name in /tmp.

Generating the default name isn't particularly useful though, since making
a suitable name can easily be done by the caller.  Remove this feature.

Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au>
---
 conf.c  | 18 +++---------------
 passt.1 | 10 ----------
 pcap.c  | 28 ----------------------------
 3 files changed, 3 insertions(+), 53 deletions(-)

diff --git a/conf.c b/conf.c
index d936157..4eb9e3d 100644
--- a/conf.c
+++ b/conf.c
@@ -737,14 +737,7 @@ static void usage(const char *name)
 		     UNIX_SOCK_PATH, 1);
 	}
 
-	info(   "  -p, --pcap [FILE]	Log tap-facing traffic to pcap file");
-	info(   "    if FILE is not given, log to:");
-
-	if (strstr(name, "pasta"))
-		info("      /tmp/pasta_ISO8601-TIMESTAMP_PID.pcap");
-	else
-		info("      /tmp/passt_ISO8601-TIMESTAMP_PID.pcap");
-
+	info(   "  -p, --pcap FILE	Log tap-facing traffic to pcap file");
 	info(   "  -P, --pid FILE	Write own PID to the given file");
 	info(   "  -m, --mtu MTU	Assign MTU via DHCP/NDP");
 	info(   "    a zero value disables assignment");
@@ -1021,7 +1014,7 @@ void conf(struct ctx *c, int argc, char **argv)
 		{"help",	no_argument,		NULL,		'h' },
 		{"socket",	required_argument,	NULL,		's' },
 		{"ns-ifname",	required_argument,	NULL,		'I' },
-		{"pcap",	optional_argument,	NULL,		'p' },
+		{"pcap",	required_argument,	NULL,		'p' },
 		{"pid",		required_argument,	NULL,		'P' },
 		{"mtu",		required_argument,	NULL,		'm' },
 		{"address",	required_argument,	NULL,		'a' },
@@ -1084,7 +1077,7 @@ void conf(struct ctx *c, int argc, char **argv)
 
 		name = getopt_long(argc, argv, optstring, options, NULL);
 
-		if ((name == 'p' || name == 'D' || name == 'S') && !optarg &&
+		if ((name == 'D' || name == 'S') && !optarg &&
 		    optind < argc && *argv[optind] && *argv[optind] != '-') {
 			if (c->mode == MODE_PASTA) {
 				if (conf_ns_opt(c, nsdir, userns, argv[optind]))
@@ -1289,11 +1282,6 @@ void conf(struct ctx *c, int argc, char **argv)
 				usage(argv[0]);
 			}
 
-			if (!optarg) {
-				*c->pcap = 1;
-				break;
-			}
-
 			ret = snprintf(c->pcap, sizeof(c->pcap), "%s", optarg);
 			if (ret <= 0 || ret >= (int)sizeof(c->pcap)) {
 				err("Invalid pcap path: %s", optarg);
diff --git a/passt.1 b/passt.1
index 378778c..9bed946 100644
--- a/passt.1
+++ b/passt.1
@@ -111,16 +111,6 @@ Display a help message and exit.
 Capture tap-facing (that is, guest-side or namespace-side) network packets to
 \fIfile\fR in \fBpcap\fR format.
 
-If \fIfile\fR is not given, capture packets to
-
-	\fB/tmp/passt_\fIISO8601-timestamp\fR_\fIPID\fB.pcap\fR
-
-in \fBpasst\fR mode and to
-
-	\fB/tmp/pasta_\fIISO8601-timestamp\fR_\fIPID\fB.pcap\fR
-
-in \fBpasta\fR mode, where \fIPID\fR is the ID of the running process.
-
 .TP
 .BR \-P ", " \-\-pid " " \fIfile
 Write own PID to \fIfile\fR once initialisation is done, before forking to
diff --git a/pcap.c b/pcap.c
index 64beb34..7a48baf 100644
--- a/pcap.c
+++ b/pcap.c
@@ -31,11 +31,6 @@
 #include "util.h"
 #include "passt.h"
 
-#define PCAP_PREFIX		"/tmp/passt_"
-#define PCAP_PREFIX_PASTA	"/tmp/pasta_"
-#define PCAP_ISO8601_FORMAT	"%FT%H:%M:%SZ"
-#define PCAP_ISO8601_STR	"YYYY-MM-ddTHH:mm:ssZ"
-
 #define PCAP_VERSION_MINOR 4
 
 static int pcap_fd = -1;
@@ -171,7 +166,6 @@ fail:
 void pcap_init(struct ctx *c)
 {
 	int flags = O_WRONLY | O_CREAT | O_TRUNC;
-	struct timeval tv;
 
 	if (pcap_fd != -1)
 		return;
@@ -179,28 +173,6 @@ void pcap_init(struct ctx *c)
 	if (!*c->pcap)
 		return;
 
-	if (*c->pcap == 1) {
-		char name[] = PCAP_PREFIX PCAP_ISO8601_STR STR(UINT_MAX)
-			      ".pcap";
-		struct tm *tm;
-
-		if (c->mode == MODE_PASTA)
-			memcpy(name, PCAP_PREFIX_PASTA,
-			       sizeof(PCAP_PREFIX_PASTA));
-
-		gettimeofday(&tv, NULL);
-		tm = localtime(&tv.tv_sec);
-		strftime(name + strlen(PCAP_PREFIX),
-			 sizeof(PCAP_ISO8601_STR) - 1, PCAP_ISO8601_FORMAT, tm);
-
-		snprintf(name + strlen(PCAP_PREFIX) + strlen(PCAP_ISO8601_STR),
-			 sizeof(name) - strlen(PCAP_PREFIX) -
-					strlen(PCAP_ISO8601_STR),
-			 "_%i.pcap", getpid());
-
-		strncpy(c->pcap, name, PATH_MAX);
-	}
-
 	flags |= c->foreground ? O_CLOEXEC : 0;
 	pcap_fd = open(c->pcap, flags, S_IRUSR | S_IWUSR);
 	if (pcap_fd == -1) {
-- 
@@ -31,11 +31,6 @@
 #include "util.h"
 #include "passt.h"
 
-#define PCAP_PREFIX		"/tmp/passt_"
-#define PCAP_PREFIX_PASTA	"/tmp/pasta_"
-#define PCAP_ISO8601_FORMAT	"%FT%H:%M:%SZ"
-#define PCAP_ISO8601_STR	"YYYY-MM-ddTHH:mm:ssZ"
-
 #define PCAP_VERSION_MINOR 4
 
 static int pcap_fd = -1;
@@ -171,7 +166,6 @@ fail:
 void pcap_init(struct ctx *c)
 {
 	int flags = O_WRONLY | O_CREAT | O_TRUNC;
-	struct timeval tv;
 
 	if (pcap_fd != -1)
 		return;
@@ -179,28 +173,6 @@ void pcap_init(struct ctx *c)
 	if (!*c->pcap)
 		return;
 
-	if (*c->pcap == 1) {
-		char name[] = PCAP_PREFIX PCAP_ISO8601_STR STR(UINT_MAX)
-			      ".pcap";
-		struct tm *tm;
-
-		if (c->mode == MODE_PASTA)
-			memcpy(name, PCAP_PREFIX_PASTA,
-			       sizeof(PCAP_PREFIX_PASTA));
-
-		gettimeofday(&tv, NULL);
-		tm = localtime(&tv.tv_sec);
-		strftime(name + strlen(PCAP_PREFIX),
-			 sizeof(PCAP_ISO8601_STR) - 1, PCAP_ISO8601_FORMAT, tm);
-
-		snprintf(name + strlen(PCAP_PREFIX) + strlen(PCAP_ISO8601_STR),
-			 sizeof(name) - strlen(PCAP_PREFIX) -
-					strlen(PCAP_ISO8601_STR),
-			 "_%i.pcap", getpid());
-
-		strncpy(c->pcap, name, PATH_MAX);
-	}
-
 	flags |= c->foreground ? O_CLOEXEC : 0;
 	pcap_fd = open(c->pcap, flags, S_IRUSR | S_IWUSR);
 	if (pcap_fd == -1) {
-- 
2.37.2


  reply	other threads:[~2022-08-26  4:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26  4:58 [PATCH 0/8] Allow pasta to take a command to spawn instead of shell David Gibson
2022-08-26  4:58 ` David Gibson [this message]
2022-08-26  4:58 ` [PATCH 2/8] conf: Use "-D none" and "-S none" instead of missing empty option arguments David Gibson
2022-08-30 17:41   ` Stefano Brivio
2022-08-26  4:58 ` [PATCH 3/8] Correct manpage for --userns David Gibson
2022-08-26  4:58 ` [PATCH 4/8] Remove --nsrun-dir option David Gibson
2022-08-26  4:58 ` [PATCH 5/8] Move ENOENT error message into conf_ns_opt() David Gibson
2022-08-26  4:58 ` [PATCH 6/8] More deterministic detection of whether argument is a PID, PATH or NAME David Gibson
2022-08-26  4:58 ` [PATCH 7/8] Use explicit --netns option rather than multiplexing with PID David Gibson
2022-08-29 19:16   ` Stefano Brivio
2022-08-30  1:12     ` David Gibson
2022-08-30  8:25       ` Stefano Brivio
2022-08-26  4:58 ` [PATCH 8/8] Allow pasta to take a command to execute David Gibson
2022-08-29 19:16   ` Stefano Brivio
2022-08-30  1:16     ` David Gibson
2022-08-30  8:26       ` Stefano Brivio
2022-08-30 17:41         ` Stefano Brivio
2022-09-01 10:07 ` [PATCH 0/8] Allow pasta to take a command to spawn instead of shell Stefano Brivio

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=20220826045839.1112152-2-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /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).