public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v3 1/2] pktgen: Automate flag enumeration for unknown flag handling
@ 2023-09-15 12:23 Liang Chen
  2023-09-15 12:23 ` [PATCH net-next v3 2/2] pktgen: Introducing 'SHARED' flag for testing with non-shared skb Liang Chen
  0 siblings, 1 reply; 4+ messages in thread
From: Liang Chen @ 2023-09-15 12:23 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, benjamin.poirier; +Cc: netdev, liangchen.linux

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-16  3:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-15 12:23 [PATCH net-next v3 1/2] pktgen: Automate flag enumeration for unknown flag handling Liang Chen
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox