[PATCH net-next v4 16/17] net: pktgen: fix mpls reset parsing

Peter Seiderer
2025-02-05T13:12:15Z

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>
---
Changes v3 -> v4
- add rev-by Simon Horman

Changes v2 -> v3:
- new patch
---
net/core/pktgen.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index a46eb20edf6c..434531a3e3c0 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -930,8 +930,13 @@ static int get_labels(const char __user *buffer, int maxlen, struct pktgen_dev *

max = min(HEX_8_DIGITS, 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;
--
2.48.1