Skip to content

Commit

Permalink
net: pktgen: fix mpls reset parsing
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Peter Seiderer authored and Paolo Abeni committed Mar 4, 2025
1 parent c5cdbf2 commit 4bedafa
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion net/core/pktgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,8 +913,13 @@ static ssize_t get_labels(const char __user *buffer,

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 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;
Expand Down

0 comments on commit 4bedafa

Please sign in to comment.