diff mbox series

[net-next,v3,09/10] net: pktgen: fix mpls reset parsing

Message ID 20250203170201.1661703-10-ps.report@gmx.net (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Some pktgen fixes/improvments | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 1 this patch: 1
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-04--00-00 (tests: 886)

Commit Message

Peter Seiderer Feb. 3, 2025, 5:02 p.m. UTC
Fix mpls list reset parsing to work as describe in
Documentation/networking/pktgen.rst:

  pgset "mpls 0"    turn off mpls (or any invalid argument works too!)

- before the patch

	$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0
	$ grep mpls /proc/net/pktgen/lo\@0
	     mpls: 00000001, 00000002
	Result: OK: mpls=00000001,00000002

	$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0
	$ echo "mpls 0" > /proc/net/pktgen/lo\@0
	$ grep mpls /proc/net/pktgen/lo\@0
	     mpls: 00000000
	Result: OK: mpls=00000000

	$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0
	$ echo "mpls invalid" > /proc/net/pktgen/lo\@0
	$ grep mpls /proc/net/pktgen/lo\@0
	Result: OK: mpls=

- after the patch

	$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0
	$ grep mpls /proc/net/pktgen/lo\@0
	     mpls: 00000001, 00000002
	Result: OK: mpls=00000001,00000002

	$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0
	$ echo "mpls 0" > /proc/net/pktgen/lo\@0
	$ grep mpls /proc/net/pktgen/lo\@0
	Result: OK: mpls=

	$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0
	$ echo "mpls invalid" > /proc/net/pktgen/lo\@0
	$ grep mpls /proc/net/pktgen/lo\@0
	Result: OK: mpls=

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
---
Changes v2 -> v3:
  - new patch
---
 net/core/pktgen.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Simon Horman Feb. 4, 2025, 2:45 p.m. UTC | #1
On Mon, Feb 03, 2025 at 06:02:00PM +0100, Peter Seiderer wrote:
> Fix mpls list reset parsing to work as describe in
> Documentation/networking/pktgen.rst:
> 
>   pgset "mpls 0"    turn off mpls (or any invalid argument works too!)
> 
> - before the patch
> 
> 	$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0
> 	$ grep mpls /proc/net/pktgen/lo\@0
> 	     mpls: 00000001, 00000002
> 	Result: OK: mpls=00000001,00000002
> 
> 	$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0
> 	$ echo "mpls 0" > /proc/net/pktgen/lo\@0
> 	$ grep mpls /proc/net/pktgen/lo\@0
> 	     mpls: 00000000
> 	Result: OK: mpls=00000000
> 
> 	$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0
> 	$ echo "mpls invalid" > /proc/net/pktgen/lo\@0
> 	$ grep mpls /proc/net/pktgen/lo\@0
> 	Result: OK: mpls=
> 
> - after the patch
> 
> 	$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0
> 	$ grep mpls /proc/net/pktgen/lo\@0
> 	     mpls: 00000001, 00000002
> 	Result: OK: mpls=00000001,00000002
> 
> 	$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0
> 	$ echo "mpls 0" > /proc/net/pktgen/lo\@0
> 	$ grep mpls /proc/net/pktgen/lo\@0
> 	Result: OK: mpls=
> 
> 	$ echo "mpls 00000001,00000002" > /proc/net/pktgen/lo\@0
> 	$ echo "mpls invalid" > /proc/net/pktgen/lo\@0
> 	$ grep mpls /proc/net/pktgen/lo\@0
> 	Result: OK: mpls=
> 
> Signed-off-by: Peter Seiderer <ps.report@gmx.net>

Reviewed-by: Simon Horman <horms@kernel.org>
diff mbox series

Patch

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 6675375c052c..7328681bafb2 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -924,8 +924,13 @@  static ssize_t get_labels(const char __user *buffer, int maxlen, struct pktgen_d
 
 		max = min(8, maxlen - i);
 		len = hex32_arg(&buffer[i], max, &tmp);
-		if (len <= 0)
+		if (len < 0)
 			return len;
+
+		// return empty list in case of invalid input and/or zero value
+		if (len == 0 || tmp == 0)
+			return maxlen;
+
 		pkt_dev->labels[n] = htonl(tmp);
 		if (pkt_dev->labels[n] & MPLS_STACK_BOTTOM)
 			pkt_dev->flags |= F_MPLS_RND;