netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Liang Chen <liangchen.linux@gmail.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, benjamin.poirier@gmail.com
Cc: netdev@vger.kernel.org, liangchen.linux@gmail.com
Subject: [PATCH net-next v3 1/2] pktgen: Automate flag enumeration for unknown flag handling
Date: Fri, 15 Sep 2023 20:23:16 +0800	[thread overview]
Message-ID: <20230915122317.100390-1-liangchen.linux@gmail.com> (raw)

When specifying an unknown flag, it will print all available flags.
Currently, these flags are provided as fixed strings, which requires
manual updates when flags change. Replacing it with automated flag
enumeration.

Signed-off-by: Liang Chen <liangchen.linux@gmail.com>
---
 net/core/pktgen.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index f56b8d697014..ffd659dbd6c3 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -1318,6 +1318,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		return count;
 	}
 	if (!strcmp(name, "flag")) {
+		unsigned int n;
 		__u32 flag;
 		char f[32];
 		bool disable = false;
@@ -1339,18 +1340,19 @@ static ssize_t pktgen_if_write(struct file *file,
 			else
 				pkt_dev->flags |= flag;
 		} else {
-			sprintf(pg_result,
-				"Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
-				f,
-				"IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, "
-				"MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, "
-				"MPLS_RND, VID_RND, SVID_RND, FLOW_SEQ, "
-				"QUEUE_MAP_RND, QUEUE_MAP_CPU, UDPCSUM, "
-				"NO_TIMESTAMP, "
-#ifdef CONFIG_XFRM
-				"IPSEC, "
+			pg_result += sprintf(pg_result,
+				"Flag -:%s:- unknown\n%s", f,
+				"Available flags, (prepend ! to un-set flag):\n");
+			for (n = 0; n < NR_PKT_FLAGS; n++) {
+#ifndef CONFIG_XFRM
+				if (!strcmp("IPSEC", pkt_flag_names[n]))
+					continue;
 #endif
-				"NODE_ALLOC\n");
+				pg_result += sprintf(pg_result, "%s, ", pkt_flag_names[n]);
+			}
+			/* Remove the comma and whitespace at the end */
+			*(pg_result - 2) = '\n';
+
 			return count;
 		}
 		sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags);
-- 
2.40.1


             reply	other threads:[~2023-09-15 12:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-15 12:23 Liang Chen [this message]
2023-09-15 12:23 ` [PATCH net-next v3 2/2] pktgen: Introducing 'SHARED' flag for testing with non-shared skb Liang Chen
2023-09-16  0:45   ` Benjamin Poirier
2023-09-16  3:20     ` Liang Chen

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=20230915122317.100390-1-liangchen.linux@gmail.com \
    --to=liangchen.linux@gmail.com \
    --cc=benjamin.poirier@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@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.
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 NNTP newsgroup(s).