From patchwork Wed Jan 22 14:41:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Seiderer X-Patchwork-Id: 13947377 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5340E214805; Wed, 22 Jan 2025 14:41:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556904; cv=none; b=ltx2qisKxOmBtG4a1abtSikLpHymh8IEvUGjO+MNKvYxS1UNm95IFIC+ZBPT8DJrphtm+XOEtZsbqrdNCWF8niy6a+9ldhb9Rt/XCWogkds4AV4Q0bkiOt0ckp1BfDdpQ2pcKuTnDN/feyR0wMTTUyp8VK5v60ETPnZlsjB0+Xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556904; c=relaxed/simple; bh=lUzNxOeGI0LuccPLT80V3d8mFbkoLYfx1I9UgEERrPY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AtDaSyMPPOQMvIbOSB27D0m3ztRKcfp3rNJ+bGs576FpvHBNps1pX1DwHNUO0jYdks21X4LREjsUAG4+/Ne/R5OFhM/dz+356ZCmhWNXB1pwiy4vfpI0xhRiht2tX5TkYyN94MlB+DFR2PNzEWgKBHrXatd4ttSIns+n0z7Er48= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net; spf=pass smtp.mailfrom=gmx.net; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b=AY8kJAGw; arc=none smtp.client-ip=212.227.15.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b="AY8kJAGw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1737556887; x=1738161687; i=ps.report@gmx.net; bh=lUzNxOeGI0LuccPLT80V3d8mFbkoLYfx1I9UgEERrPY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=AY8kJAGw0g72kwm7t9PAq7wJwzM6pvAHh1rAnzi4MavoUnfYaqywX1WtdsJFJDON Gbq7g9KmjIfwLp/2DByRiqfVrN9SlBDFg1qdz/U17K6aZVLqQBJxFoOu+U3qaz91u uiuoWA8C3xias5lqItvdv20777YoexH6wN056g8H80/Pufem5KiZ0xds0SnH778Jo jsdepKpOTsbRylS1h/WDGZQ8bxOqnLulXrejHnKXj8hflZbM52isL4Nrvj952bphf AL0oOvzwgdlD5rLvh+JlJRhQnlbi76ukIMip5dtdOWSe/1W308rwoIv8hBHWHIgSG SqIP3/bzIp6peNOl0Q== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.fritz.box ([82.135.81.9]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MN5eR-1tt6fq2QKL-00WwbV; Wed, 22 Jan 2025 15:41:27 +0100 From: Peter Seiderer To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Frederic Weisbecker , Artem Chernyshev , Nam Cao , Peter Seiderer Subject: [PATCH net-next v2 1/8] net: pktgen: replace ENOTSUPP with EOPNOTSUPP Date: Wed, 22 Jan 2025 15:41:03 +0100 Message-ID: <20250122144110.619989-2-ps.report@gmx.net> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250122144110.619989-1-ps.report@gmx.net> References: <20250122144110.619989-1-ps.report@gmx.net> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:nLWXdbhIuNeJfjk1QrJ3BJLUr8VKVD2O924VQHvWNSy7BB7Dl2L 67cEhD1+nRmK/hYCnmk6sZ8O+d0Exx+WDBgfxVErDU6vZcMlTRMfwyjAMUFI102C+Ds+zCW d5NASfVTBt/tw53Ayz9VNN8Z+UbRaGKC2edHkPGN7jWN3aWMT2YPjzvlCj9cUOV5wgxA1rv eRUyEEJ5CO2XmYEZhtexA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:NAfkfSU8IN0=;6tIJuGhJguqVl1CeLWYQ+7xr/Y9 OBE+qkDy9egaa79Qq+HNybT6Gs6n+ABOVkKsXnATBx0XfE7R6t88ICWhvp0+C+Uvr82MDI0Z3 VUuAt6RfnhgyKStGhG60XqmSQZW8pJLp82GSYEMhnkY+qLgLrNWGH1o9o66GNfH827sMVS2Tc j1SLFUtgfDBPsT2aUZyETCGqjCL0O/01Nuy8yH2cSsmml3JLuUHWs4AaT6noEYlYmK4W0qxZ/ rowMFuG1Xpe+3+Sz2v7Ku1uiEJW5+V0OyGHAB0hRokm5NyfbpDkRHa21aiF1Qzv8Aun0e4LsH ACBEvgccwit12jNpnebgEibpfy4VHeF6Hi3PEyNS1LvWX9sW9TjnY6/vzLgK99j/oKy01JLr4 PS0v97n/E3DuP0vZE2w7QV/kwswLs0peINcYXCucGlkSVnTODPd8LOIJ7i7fbw8G1YYOj7XnJ 2dcM4Z4TDh4m3cnpbbl30Exa1IJvSW6pr/1uaQO1HlZEzkJIrWA+r3xPXJgrJSUkBgWkg/AG+ zBgtPR3BfSXSDUK7ujciOV0QNMlQo2bQFeQaTDSVZIm3mNQBdcWtoRpMPWEZayw+q3LugIkGg /gfFkmU2fbteMETwHmXWaOmm2O9iYkLCKAww8K4Cu5or5inEJv1C8WxjCHlZgJ5tmimv7l4QT 4Nih3GTXvKJRWv0txj7VsooPdC2Gj72ieI45nuB8+CvErw0yXuwwdcmdNq/4TCnED+XQD5k/4 Wh/wq5vX1D+PnjQ0kblMCJVvmvdeIrMHVRbtys0JGobTxN8voASEsgE16mUSSfqFCJ6UwSAHa FTrx6FfpdG4k/ENlAJB8WRj8YL1lzcJzqWAIVJ1izc5uPsU0dx1yoJNWfZgW+Z4oxLD/PSy5W 7n+udGmKqCdZvNI7HL4ocmLU7xQjHHH7x8uJ4rsIORyCEmMjkijNF7AwyvQcynJ6KFlMob6RS b9wgtSq0ZqEOEcyJ7XhP8uxujTfR2kRjAVKr9YsKr55gkFYZlEh47v6LIynCajh9xXFMvFKzd HyILoixSPa1Za4PRTj1ZgXSYpuxa+liJp2nHHRVLtjehEqOSnfDX/4WrjheWE7f1kkBRS7IYG nxRKGdoGmDthLRGGwVLWlbof0/qY9W+NezQvzYJrgoEVWUI8c+uREjUR18K3hyQ4HsDodCLUb SJFrTa13KukySbnaZKW4/RKLCvmFiPSSXemUU8/3HvA== Replace ENOTSUPP with EOPNOTSUPP, fixes checkpatch hint WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP and e.g. $ echo "clone_skb 1" > /proc/net/pktgen/lo\@0 -bash: echo: write error: Unknown error 524 Signed-off-by: Peter Seiderer --- Changes v1 -> v2 - no changes --- net/core/pktgen.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 82b6a2c3c141..496aa16773e7 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -1198,7 +1198,7 @@ static ssize_t pktgen_if_write(struct file *file, if ((value > 0) && ((pkt_dev->xmit_mode == M_NETIF_RECEIVE) || !(pkt_dev->odev->priv_flags & IFF_TX_SKB_SHARING))) - return -ENOTSUPP; + return -EOPNOTSUPP; if (value > 0 && (pkt_dev->n_imix_entries > 0 || !(pkt_dev->flags & F_SHARED))) return -EINVAL; @@ -1258,7 +1258,7 @@ static ssize_t pktgen_if_write(struct file *file, ((pkt_dev->xmit_mode == M_QUEUE_XMIT) || ((pkt_dev->xmit_mode == M_START_XMIT) && (!(pkt_dev->odev->priv_flags & IFF_TX_SKB_SHARING))))) - return -ENOTSUPP; + return -EOPNOTSUPP; if (value > 1 && !(pkt_dev->flags & F_SHARED)) return -EINVAL; @@ -1303,7 +1303,7 @@ static ssize_t pktgen_if_write(struct file *file, } else if (strcmp(f, "netif_receive") == 0) { /* clone_skb set earlier, not supported in this mode */ if (pkt_dev->clone_skb > 0) - return -ENOTSUPP; + return -EOPNOTSUPP; pkt_dev->xmit_mode = M_NETIF_RECEIVE; From patchwork Wed Jan 22 14:41:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Seiderer X-Patchwork-Id: 13947372 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83E5742065; Wed, 22 Jan 2025 14:41:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556894; cv=none; b=cnZo04RF0yx7srbxrm4JUFdTVpC6UXdUlY0mbTfl9jGfuSi9WJafBDLYLO28ve7+WpuJxp3Q/M4B9gJzmTQ3mCiCrqo1/0yIAAC5eJPwTT8eEak1Z//FlzUMP8Y+VNXhtPEpK4SdV77ho029zE/wXf/CE1qWOSRN4I+g71urXRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556894; c=relaxed/simple; bh=hJpa3LFI+V2r5MNhTK9NUermXo1BXqvohCjsUbamfmk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A7HZvPYEcVp50IdCnuNdkClb2HffAd1444vi6DpxAdkT4+M9wWkUuQawBsTIHVw3UA8N8n4ytt8yQUd8f2arCwOffHtyVCtU/d4SevtUZkFOQzTsuY+4gsF+UD7ltTSDA8wcRnJymAXvqJZzfK1tk6kIYvbpEyPJXSx72zZnuEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net; spf=pass smtp.mailfrom=gmx.net; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b=I3bYkoH0; arc=none smtp.client-ip=212.227.15.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b="I3bYkoH0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1737556889; x=1738161689; i=ps.report@gmx.net; bh=hJpa3LFI+V2r5MNhTK9NUermXo1BXqvohCjsUbamfmk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=I3bYkoH0YjQ2Rk+BpVVOqP2EWkpr2lgh8/VwTV6F0AG01LMWR9rTWTTtwtdrzPY7 iXJkF+qW2zhDk9UIXv4sDbPbldYP06ttA5oynEg2u4DoQPCmQ625RyQwh310tfIYO Qp8tNF/EtUMM9+5sfhWAkj0z4OdNAFFEOQKSewcwh9/ODuGoicCUikQWHmNXz+TQB H4iC2Sw1uCIT3VxODrkjDpvXx4kjHrzU6YuKVuZlVfG4XXraC+YuGgQdZQLIaacRV 7Mt3SlmUBl5C80+gPkvJQT7PfmOEIT8vF6YpEe/SoOfNIq5EaxnHQ9Ssoc4NLhb1G ZPD3NtFZFR/dkF8ytQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.fritz.box ([82.135.81.9]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MrhUE-1t76b71U9M-00auke; Wed, 22 Jan 2025 15:41:29 +0100 From: Peter Seiderer To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Frederic Weisbecker , Artem Chernyshev , Nam Cao , Peter Seiderer Subject: [PATCH net-next v2 2/8] net: pktgen: enable 'param=value' parsing Date: Wed, 22 Jan 2025 15:41:04 +0100 Message-ID: <20250122144110.619989-3-ps.report@gmx.net> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250122144110.619989-1-ps.report@gmx.net> References: <20250122144110.619989-1-ps.report@gmx.net> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:xEA2ancdL0uEYz5QzgEMV5d8silehZOpj9FntnijP7xuKu0zLhq BJHwR19cQvL1S3+djm9ORqG+J6z2BmtlCZvKS2iDSixS0P0QCQCen1ByjzCwmtfzCa1MA7g pdqooRik1GHqJJPMj2ewv1VSiWeX+gMDu2LsqB/apMvcWgFA8/h9cYJl/rypD3RxhSbWNXs RJRT72T7ZRN9tqIMgdt7w== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:Lh+3Kui+bqA=;EkzXMPaOmuRvI7hVRbnLnL92kES aYaq9tziU9jyJX2QQ7sD9O5bgkAQlQPTIut2JR5o+oW7UoR53nwD6e/FtzFhHkabWWzXqAhoo SVWvL0S2JY91Bl2QDh/Nku5wGAClrPH2YIswS8lEJ4X5D6Y0Q8SC6oPEqn16OfKuEG6nHcM65 Sy3GfsU059+Y2fZaM48BG8d194uOCwrjYDsJ1iqjDU6o9Yw4lHozAKNUfnXHW/JqV9UooVTuK sEl8tjZx9lyiuTzl4rjPeMdKpMsDGT3+ZkyQoq3cGmEf98/gs5eNkE76WHyv6wqP/yWzS//mb hM449lSWkzH4VhfOVc4bqQXZGVbYhf3s7CKdcPNzbx2xgvjT+GgxmXHwdzkRE8KN/TACEXBDk TIL60ijj2eQMsE4JPhbo2Wqf4mVG8KH5iCvFLKA45vIv49Nfq1iXyZe9LC1Ns+B0I5rwnxbwv B4NheX6hbXs765xAnoi4KU3fYJ5xa3mz9jl/0IO0i2winhApxNpxd+vCGs5MB04eEwXqd7yOK /6QyMSZAF+6n07L4cw3ZdUoSxan8mddz6nhXAUkfJwACWx8ItdSekDkRmhmKwj6Ta3xBGwehm gm5pPbffmfgGUq/wK3C2DwIBgXMVxjI/MbFpbr6ZMrkgrLcvDJtyoOi3weROBMWOJzR7KHXGA 6EXqC3ZJ0YEJDKQgnZpNR6cQg5XKMVN/B3AERR7N2o79bM3O1KyuaHNxGTYLGpc0oNKtdqmaY RvBYuCxHBP5kn8UhePQhqAyHuKmkWTVzICJFIlDjBTgusza1NkJXdK5Yhl9dTCqzRaZ/gohPF qaZ0V5LVMaVkHmP6uvQUamGjcZvq8gsZ92eUNXHjZFxi2ijqGmSLgIrAsN5H3fEWnzq0Z38kx MEsHrYSzfEnlXSnUGv25+/pf589IjsBVyHizRFD4h1tGG1T2j0j9QmzYMWvpfxLJBo4+yaHAR Q5z61K9EqzT9YBEWIw+bNbtYlaI3FdMpQjnwUArwphu4PsD8Yif6GUOBFw9VegHCUExlYCN4y 8cc9ntbLeOmf7b6FnH2DxUA2MG3zMZPn1PGBdAzkMJLQADHyE/K0gvggocGoisYKFhKqBBLFP 0tnNpvrDGQoorVd+bVh/dtA12JYxK4E2qZgun0fN8vMeA9lTw4wy6oapUEHFQDFZUWpu9bvBr tsE+3ldtxQF4lPCNRfpPyGDDaOVsRjGmZEFIn/+by8QNaJuJ39iqXOZLpEz7FbmdYa6B+Y4W0 hzYYdqsyYoaR33wC0uL+Mi4KH/L9DlGaV0wtzEKZi9R4m9a5/JNUGj1WRlt7psdx7I5zsik8o gkaSvSnDxzcGi9tLDzUHBy5PWCjO/+kVh8ZEuOaimrucjg= Enable additional to 'parm value' the 'param=value' parsing (otherwise skipping '=' in count_trail_chars() is useless). Tested with: $ echo "min_pkt_size 999" > /proc/net/pktgen/lo\@0 $ echo "min_pkt_size=999" > /proc/net/pktgen/lo\@0 $ echo "min_pkt_size =999" > /proc/net/pktgen/lo\@0 $ echo "min_pkt_size= 999" > /proc/net/pktgen/lo\@0 $ echo "min_pkt_size = 999" > /proc/net/pktgen/lo\@0 Signed-off-by: Peter Seiderer --- Changes v1 -> v2: - no changes --- net/core/pktgen.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 496aa16773e7..4f8ec6c9bed4 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -823,6 +823,7 @@ static int strn_len(const char __user * user_buffer, unsigned int maxlen) case '\r': case '\t': case ' ': + case '=': goto done_str; default: break; From patchwork Wed Jan 22 14:41:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Seiderer X-Patchwork-Id: 13947373 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB4D8214205; Wed, 22 Jan 2025 14:41:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556896; cv=none; b=u+PR9fT/cAa5sX58oSTwsal17zOsE9/lpYTTBGKo9OcQzTTuUUcdGNzmF6mulOggqk5vFgX5RGq3WgowQLhGCNHnq591KZ5ISXLcnUEg8xLHOP+S2kDA3VVgpjwRjAebeptWWOzfdlqCPGBFARm3eZcrmmSyd/9TBRvW4FCmhD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556896; c=relaxed/simple; bh=V5UmF8gW4RvXtY10lRp+LF0r3060eq4XPbZN/wKQ6yI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ErfdyrUN7KRKVkYVmd3NanH0FIubEZ6kPd0RyPGnsYNGs+VUke8q/he2GfiY0htPGkGin7VE0GHa2SaJPSdncsAyeY5xYWO7e9xu7KRLSt9S+bqp2nCU4mZWpMjZ2/kUB8buXJMFPuTTyzY/ocTZ2Sl7ej8WAG9CHCoFaRy0xPA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net; spf=pass smtp.mailfrom=gmx.net; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b=DvWObkag; arc=none smtp.client-ip=212.227.15.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b="DvWObkag" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1737556890; x=1738161690; i=ps.report@gmx.net; bh=V5UmF8gW4RvXtY10lRp+LF0r3060eq4XPbZN/wKQ6yI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=DvWObkag++p4MqiVRxNngw+nvfllVXGjV+LzDCSYll9G7w8U7sCSVV+MKTIrL1DM SBF8yDLqNixADGGf6tRvfegqFiN5j88tDxxi8GvSRFVB3CQfYLB2zvbuSUahcopPa GQNqtmnZo/dHdlrtN4N4VlilUACnwADJ+6RNDTEQcsN46lTXndCPeGHOlGwtQqR4b +xjB0VngLjoXZS6qTORnlKBQQ2k25yvNePYYGwUYHDaSf9Y5r3cWZaWyCNoNR/fH+ BdoSirPopUm/RQkqLVx3/j1o16+5ZL3RqYnhjzp4aso0TTj8w4O/O175dk8t8vbLm xcWdKNtVY32GGTRUgw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.fritz.box ([82.135.81.9]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MNbkv-1tqNNZ2OCZ-00T62t; Wed, 22 Jan 2025 15:41:30 +0100 From: Peter Seiderer To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Frederic Weisbecker , Artem Chernyshev , Nam Cao , Peter Seiderer Subject: [PATCH net-next v2 3/8] net: pktgen: fix hex32_arg parsing for short reads Date: Wed, 22 Jan 2025 15:41:05 +0100 Message-ID: <20250122144110.619989-4-ps.report@gmx.net> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250122144110.619989-1-ps.report@gmx.net> References: <20250122144110.619989-1-ps.report@gmx.net> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:Z9HGwG8S3ratyxebtluKy5iOM0nXJSHOOlfIQYuQsThz6hs8Kt6 bkXSkLQaCQFDQ3CYeNGNHNDuMaMkZac/mDS/7vxVWCKts85tNsMOuA3EeGH1eyNVBbFxout Q5VZ3froBcQ7POSXqRpiMJEFNN3BF29gBLk3kEQvQ0Hfo+rA0OQPCs6lg903WPjRGsyw9Lp x6WAFimHktIBX1dGr+9hg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:pfo27eJ2jCs=;YuPh8Z3S1TDNvuoGaDRu+xx/U8R LP9yS1UoeTuu2KZzUSecWoLtsOl6bvhtIlx3qAjKrxDWmw8B0VcUPLkEcfDbm30DiiiHnP1Ow 0NlUXou/kzaHkC2afg0Z2byZ9FHyFyCapcqwV9IsrOFn1fd7GiM8Lu/Dh47fYLZVg/ScFoldt +ObcPAhyPW9ZQ8BrmTCJgpF3aQJprRgGQs1RM1EjirIQXs3KrwH4yuTLnDVameNvXiQqU0GpT MWhN7ZbZNg/cHCxuKrAefErnuapcHq95lBXnrWtp7DQ2O/7vKSmTnxRZvKvWO+doY+FtO5XJ4 5NYg8WIUuO7bcUUcxzJ2f9oVazrB14pt9pI4PEFSWCsXJ6DcLh9qI4C2g1ni1lXGvcSn3MKlN 2/gyyadNyxEph3Cqq2HloA6b6igUwhxiav/Ctu6TKHN2GFC8uhGvTSni7oprxB8AXVfwZ+tvi zPkRGYfpa06L3fpSi1p1mBrisLzJFFTKmK6LCRQqZ8S2yC3ZAWt9kOpFmnz2+rOF+VlcQBol3 S5DAGjzyalvkC9T+OnPmx3fvcYYwq+LfSKi6MsMmGHU3upW2pGkU5WG9YDhl+IVBvHDo54Hqs +QMDR0QbnFflUSmeRL9CnhSXSg6lz4sKRxigIHEWFBxNZzeqyJ3KLW/5uiCkkehmnrwWd1Q5c ADgEaLlrf+A3Ya4KX+qKSU8KahDbXCciFtK15e3t0xERQcjTjLLxkChoYeyiTbFHnATYjw4az Nfwf5UO2Oi7ogEcJCRX1zJO9eXnafIfop7sgBMJuQw4+Fyaizo4gWeb0Im0xdfx4I6LDdyMKi P7gYVSa0bazXPSg0J7SPknJwen2n3CNitvxbiLa3k7vrNv1Ezk5RWeg+igayH0VKkNEdR9dJ2 90dqK2iILxnrn5koSbcGTXnsMMsELP/tw299xQo0XUsftEjErfIw59jQnV4Ky0SdwTr9jAULC vwF13gXDlQucuv++EwA+sR/Fq2X0kLqVEIZItHbGXXNwWjU1MUTDLfefrjvijSmu8lYnC88is 6IPXxj/CeEOuogcogCxMbeuQvnzbIonhnWfGCJH5opEz1VJe9p1b0vSJNZ8kIfK7yMQFVr8g6 /U81k46rqGQ/FfSzwQZSuxurfcf2PBDgn+eJN5wCax6Fg4NVcLdHcgN+qzZeqrWOG83Byueq3 bzCoOTN4UADpYO5BUQ+jNi2x+WLjki3RpkPeVuCYb6PfqZHc9JATvfowLk431LXZkHzc+33Jp yGFNDB0ueTDZFK+F7CU3jf9NJQ0HJcyhhbkKFUWWXITYqW3Y6TJaRfZENbooP8ampkcVVVr1E 79dYVq5BFwPafLcpSqfMRGjmvhElxoQ1HqHwoAt2Mo7EnU= Fix hex32_arg parsing for short reads (here 7 hex digits instead of the expected 8), shift result only on successful input parsing. - before the patch $ echo "mpls 0000123" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 mpls: 00001230 Result: OK: mpls=00001230 - with patch applied $ echo "mpls 0000123" > /proc/net/pktgen/lo\@0 $ grep mpls /proc/net/pktgen/lo\@0 mpls: 00000123 Result: OK: mpls=00000123 Signed-off-by: Peter Seiderer --- Changes v1 -> v2: - new patch --- net/core/pktgen.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 4f8ec6c9bed4..28dbbf70e142 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -753,14 +753,15 @@ static int hex32_arg(const char __user *user_buffer, unsigned long maxlen, for (; i < maxlen; i++) { int value; char c; - *num <<= 4; if (get_user(c, &user_buffer[i])) return -EFAULT; value = hex_to_bin(c); - if (value >= 0) + if (value >= 0) { + *num <<= 4; *num |= value; - else + } else { break; + } } return i; } From patchwork Wed Jan 22 14:41:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Seiderer X-Patchwork-Id: 13947374 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 404EE2144D7; Wed, 22 Jan 2025 14:41:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556900; cv=none; b=DEhjNs4UStGFjYTmP5gaOdHApGTzlO/g6g6cMUtbRBLNQbd2Zm9lyplOLDNL1+BE7XomNmidW7Lkx+pu1ljKDzKTUr7N9AimFSRxEEmeyJcdGoVi8sIA+AYalnIJIBG+QvI0wky+pQ8BtfC+P/38w1y6DHYOl1xPbKwHGiTkmZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556900; c=relaxed/simple; bh=QNioxeMF5QY+yfijWq8Oz+GP2w5KHG1Qp+4ZaEPJKKo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tCvI5uzdOlKY6rHiecGPhNEpxBJOvqIQ2mx5ckH4Fz99rKwU2kWSJcQmLVrN1x0Zoya9oGSJRNWxv9Csuk1H1dE/td7xoswg+rXfYORC89AS52gSILi2z1SCamiEKtfskbUfRV/+vyDi7NLO/qiTvP3hcNcL9QzCKAryAeT4Svg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net; spf=pass smtp.mailfrom=gmx.net; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b=Rf9k1Ya5; arc=none smtp.client-ip=212.227.15.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b="Rf9k1Ya5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1737556892; x=1738161692; i=ps.report@gmx.net; bh=QNioxeMF5QY+yfijWq8Oz+GP2w5KHG1Qp+4ZaEPJKKo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=Rf9k1Ya5CjX1eW/IQ4/DBm3alY+rup/KMDC3Oi7d57Qft+deelprPpYXbhC19kHD Kv8RtEvgrXVnkLDmzMGQ1XKE3F3g8KZnf4pcvwA7YzD6TWFQD5yzrrH0bbdsRVvNw prRcLdjujive4pGQpHNaVi9Wz0YvgiccoiRRQXJkJIbxVD4xej9KHO/Ma7KhDZKzF T+h3NcFwYq/URLNUEH+ybAiCTeLCr8q2ZO5+sm5xAnQ7LSym0uTeboNtALvXhXP5t 4d0EVe1fZ71oFdEosesONkSwlxdbf0Q/EfHjfMW7o0OXMrflEMVQQKcOH6TnhcCKA rzwLA0PZ4o0bMhRtLw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.fritz.box ([82.135.81.9]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MIMfW-1tgAMp3bJU-001r36; Wed, 22 Jan 2025 15:41:31 +0100 From: Peter Seiderer To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Frederic Weisbecker , Artem Chernyshev , Nam Cao , Peter Seiderer Subject: [PATCH net-next v2 4/8] net: pktgen: fix 'rate 0' error handling (return -EINVAL) Date: Wed, 22 Jan 2025 15:41:06 +0100 Message-ID: <20250122144110.619989-5-ps.report@gmx.net> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250122144110.619989-1-ps.report@gmx.net> References: <20250122144110.619989-1-ps.report@gmx.net> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:MOlpTxhwS2bv8sL4JbpGptY7cZEIgDzucj7ui8UQaDMs2MjYHMD F8kRVFKMLcZnte8RIxKZ7FGgqhQSDjfUCISlmgE0KkMofyDJbrTeAVQh2oWylxxl2skXbHu lpx9XaRslaf3wuyW1ZGnTi/wkIIxfv3lFUJTez4pv0jPJzL/fwofyZlWLwTbk2Ss7Ea+kxI 9Ja5CeUI+oxm7ZV+1NlVg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:OJyiNSrDKdw=;DSqCLDVhN9Rb3SLZaUQOnMpXjp4 ybvonFkNAcv45FBedk4iJ5XzFWULf4OArnPwAuPtlU3W1RPzXTpmhsmrMoO5HWEbWMuNmShYX G9N3aSTqy+b4B3AqG5bSRuFDB4XUY86r8VC9R/vxfaFlhe6EtZk7yw/iFqoGsD0+jnlr4Glsq xRHwcPHk9oVFqU9DkLpB6CCNZbQxdhpjxBptQT2WEaM2+8/40Zy4VnMHfBBIhfloirzVz1dzU MjmIqezZxooemTP5b1yXhVhkfqQTby1PevhQJ3yyPsb9REyd7iakBDNLXGO4z/9kYhhsiBt9a 0co+K2bv5oMBMyuxn+PzrZZdySMNrBDlTYYxOeOn434lZteKkIEbVZEx+yiVmaUpYDL3nX85x k8jKlNja5F5+6nkr2KxR1OhZ2Ka8vWkhFEo6sSizZdFX+G21Mz6Iur+WKtoZn6p8d1lCL3jDn 0RndQhtc2HX4jnIPUbB7adKBYaxSDqdF5mlV7FZMGM1sS0bI8qzBt/G0e05xJAqgN8ZtWo74W KPFUHcr+Yizg2qg7+OPg7/LKL82mgU5hMKU5rUsj21o0byqy5A9Be/1PdtCCaeaTzssxk8CoJ gQjNxOEgUxUSJTD2Pc/GsDIkVAlD64WAC650epW2AUN0XVFG3t5wLvEuOMcwKRBYcvIMD3QW/ ccwz6b68pz2jLa1cYrp6Pya5W7yXWG/UNPheyKLGHxc3UvSLK+s1Sew/2TOlWPvOWZYGwWcCY rLb05XFxHPFbzvSy/iPCY5A7gOYdL1G8T5nSFZp3UxxrUEuZO57nGzCJID2Qrtii126bJYgMr 4wZguLUKYm9CFWPsvJ0X2KLUmzQ79Jhq/TW3l0UX8mDXyYgRl3/TAns+lFzKCDVAffDhoR07T U1gLHebC5VPXnLhYYA0l1f7U8Pp4v7p6vl4KlbNf0TBNpZsNFnSigpV9yRMYyJ3luI9QNMZm7 K0ii45Jf6mkhKEGUBlUUu/ejkDJebrHNqnIQAA+vnsu5oWeWCZND9+FPdye2qEB128a7ySyuy 0Cc2bCpXtUNyVlgljxR6VHW0dT+uq426v0c+EAw/gqe0foZSQKJdwtdvSATyRF2PRon6xbX3b i0g80p8gyCQNw/qk1Lb9fkpf0v+YhTKcevvRiwORwHa0Jom5m2Ya6Jf/5eBsAFSB31k+cJBDl PWqCKkw7uwWbBlNrSSOFMml7osISiiomMUIyUF+0xdA== Given an invalid 'rate' command e.g. 'rate 0' the return value is '1', leading to the following misleading output: - the good case $ echo "rate 100" > /proc/net/pktgen/lo\@0 $ grep "Result:" /proc/net/pktgen/lo\@0 Result: OK: rate=100 - the bad case (before the patch) $ echo "rate 0" > /proc/net/pktgen/lo\@0" -bash: echo: write error: Invalid argument $ grep "Result:" /proc/net/pktgen/lo\@0 Result: No such parameter "ate" - with patch applied $ echo "rate 0" > /proc/net/pktgen/lo\@0 -bash: echo: write error: Invalid argument $ grep "Result:" /proc/net/pktgen/lo\@0 Result: Idle Signed-off-by: Peter Seiderer --- Changes v1 -> v2: - new patch --- net/core/pktgen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 28dbbf70e142..75c7511bf492 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -1115,7 +1115,7 @@ static ssize_t pktgen_if_write(struct file *file, i += len; if (!value) - return len; + return -EINVAL; pkt_dev->delay = pkt_dev->min_pkt_size*8*NSEC_PER_USEC/value; if (debug) pr_info("Delay set at: %llu ns\n", pkt_dev->delay); From patchwork Wed Jan 22 14:41:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Seiderer X-Patchwork-Id: 13947375 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39C4E214205; Wed, 22 Jan 2025 14:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556902; cv=none; b=uJlrOhyP7EYfqNkoJokQtZeB+PYpKyTZwlskWwHM9DCb3k/SkdxrGjvnhbO4oZoMaaxJcIkS5GE6+X8c5MKgp97q/hP7KCfVXdYp+iVgQLCbeBPdrm5iB6xdN6/M4vBZAV0z1xQ3jjThcIykwSRldrMVLFMld9lquyq3wh/VYIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556902; c=relaxed/simple; bh=q+DeEF53Y/cb5V9LljwFbWurT4RT/qgfwLs4GI4NwU0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cwnIvFfwq0a6iyO1Ld3Oh2+KO/xtNCfwgoreuO8GHwBA7PIBGd229V13JhwwOU7Bwg7xhnHx3mFJtjTxdzy3dxBEjlSqPV99LUY3Pn7BkNbPDbVqoRUbdN/m90xVIp43do8/bKeg0dKM2aP6s3BgFNfEMNmAlMhCiZIEEdy9j2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net; spf=pass smtp.mailfrom=gmx.net; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b=VYzHMR1F; arc=none smtp.client-ip=212.227.15.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b="VYzHMR1F" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1737556893; x=1738161693; i=ps.report@gmx.net; bh=q+DeEF53Y/cb5V9LljwFbWurT4RT/qgfwLs4GI4NwU0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=VYzHMR1FFcAvBOXpzl/wd99I2bF9vrlTo3u+31KbAcDg3HS+uNbcZeWY65wsMi/R x5bLycmIwMZRRxV/imVe4tt6I+LNSrhTxq0o91SS/aaGIxrGhqjydUOAfr9BIMllg PUtxZEOgxnsL32AsOTV2RoBdaAZO2nUuG2+L7J7K42isj2U9fqqEj45P5wUtv1HXm /hnoVXUz7fOzehb/vH3PYxncA9dwLyxSdweFNImWAuUgvpeU4uR2vDXoZxwkdzayE bJy28AKt4ZKwE3sncTo3IEDjUFHqbAU3+kUPTe9lKtMIBlBbyro4sBiRO6IbA/77L QzNFykAaPIJ+M8aLoA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.fritz.box ([82.135.81.9]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mof5H-1t7vwS0yz3-00cH7x; Wed, 22 Jan 2025 15:41:33 +0100 From: Peter Seiderer To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Frederic Weisbecker , Artem Chernyshev , Nam Cao , Peter Seiderer Subject: [PATCH net-next v2 5/8] net: pktgen: fix 'ratep 0' error handling (return -EINVAL) Date: Wed, 22 Jan 2025 15:41:07 +0100 Message-ID: <20250122144110.619989-6-ps.report@gmx.net> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250122144110.619989-1-ps.report@gmx.net> References: <20250122144110.619989-1-ps.report@gmx.net> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:91nyc8Mk0+LSRJLOCCiqwDh5f4HOyh8aQNJS20GMLH7RYoh1W9g H9Q3jNVjw17Y8G55O4RD+k2qL9VP1A9+l5mIaHs/IbkiD6x/Dl2WkdXQCeQAN0h2iaIc71i 1JntLAgLX6RKOCeSjtFk2xuWGifYF3MDpkoSM3oFdBB7iK9IpwTvjM/q7BYryZQxaxDYkoY ULpUPcdXH/vX7ndNdkhtQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:wBbKBw/Q5DY=;m4EOd4EHHmXp2eqYmDu0XITgk7i iKUNzrOz/YQ4LN8+QcXdZ+pvEp2TP+OuiKQWyQnUuGu5Ro1SXG2dcm6N37Z2FC7yApa/zOjIX srt2nJiK+KydBfhDXw//OijgW+qyOYDkH7D7PulVkOtIRR03hC/YEvdzdZ3O1+kDsta7kC+BL 7eavYJ4r3UYn7Ml4hcuQo0AuDvob7gEoBsNQXWQiQRASvtKGIQo6FubbVT5qLaavYQ6hE5wz+ zNwH4JKEWA7caJ96a95ZwBHOF1YsnoQBLj+irvgQWOR8TYktzIs2C89aG6tbb9Q5rSoU7qJ2J zcQLmZYxvVxNnWYlg8NFqo2RPKK4JNnE5Zp2Q+uRIqOzUHRpNuBRYKzrzv8Iv8A7ZD6N7HCRO gSAhPqTTTKYyImBC1QC8WgsPces0fS9cK2qBfCCxXHiFdj/BUAhffzizkCpwmlOLuqCw6PPZw ni8MqF+akxje6unfKMbGnTnqyA6iThukyRHJfy4c5m8Yf0Y7cict/kcOscvry4SSFGXurKSCX iUs4GSrSN8LT26RFYkNijxEoNv9Si51pxXmXqqTxuUIkZ8ct1XdScpAKbCs/T5FDOwkOO5pcb ooeX6HZX9FS9e/UwzM5yt6kzAMEu93eEaMMKLwYToALtSpU+P9i7ZVOQNfj/SrIwK6ISkdui+ en7EsNO6FbMx2733bBfiUKYOMQ2VboE84Um4For0cbdwaXCEiT0arMj0bs50bmUX3zp8CpwAB fmcf7qiv5UgiTiz6LCz5jX40zy+KxZHVkyzsTXE0xQ2QhhpTfmpMPIU1gHkj3iKDRlK1IheuA 2AqKL+rS3HpoPxpHCAEPBHGTmYOtPMNhRf0FIPoDv1y1zwguORTQOxJ1O91kolnsRpLJ/Jer1 IUu+D84S1BsFu7WWJQO5f5XtK0K3Wufqh4i5Srr5RgUgcHa/Ar6ClI5ZDRNh5KPC8iS2raDDl /bgrftbY9R6BNznbw2QGzdvBk/PNn7opfUTLvVasB7XsDUvq8b8b2D8pz7NKnZ80kxakse3pB uk4wFFIJbsopCFWSRk9eriZ8RhAZMYPULXFKs/0nEfUQ2LGOKwR+qjEc2YLNQmlQBo3tA/B7A AWKPSIFn073m3mEII9r0yEAPEzmleluRMoQ92fnuWDF8HdK3lOj8QTfV6O3DsOgVEdek0/vG5 yngMHluKNLfAmWZOpyUDOBWX+k8gGt6I/p9YULrLJyA== Given an invalid 'ratep' command e.g. 'ratep 0' the return value is '1', leading to the following misleading output: - the good case $ echo "ratep 100" > /proc/net/pktgen/lo\@0 $ grep "Result:" /proc/net/pktgen/lo\@0 Result: OK: ratep=100 - the bad case (before the patch) $ echo "ratep 0" > /proc/net/pktgen/lo\@0" -bash: echo: write error: Invalid argument $ grep "Result:" /proc/net/pktgen/lo\@0 Result: No such parameter "atep" - with patch applied $ echo "ratep 0" > /proc/net/pktgen/lo\@0 -bash: echo: write error: Invalid argument $ grep "Result:" /proc/net/pktgen/lo\@0 Result: Idle Signed-off-by: Peter Seiderer --- Changes v1 -> v2: - new patch --- net/core/pktgen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 75c7511bf492..c8a5b4d17407 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -1130,7 +1130,7 @@ static ssize_t pktgen_if_write(struct file *file, i += len; if (!value) - return len; + return -EINVAL; pkt_dev->delay = NSEC_PER_SEC/value; if (debug) pr_info("Delay set at: %llu ns\n", pkt_dev->delay); From patchwork Wed Jan 22 14:41:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Seiderer X-Patchwork-Id: 13947380 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F329215170; Wed, 22 Jan 2025 14:41:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556913; cv=none; b=axUcmt2HZmnc3/V3ZBJUI6xtMML4K4WdV/3Vmnqg+vXK8a64OdQk1nSZkXvpXtog2wsy8c6yQjgTiYf0KnKesoim3uvDWmMj9dTHudzfuETAox33QHXW2qi978Qh7Ga+7LqYIMTTZl1zbn6k+CLSkwJfVVnQkGjnjLfDjo+9Im4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556913; c=relaxed/simple; bh=on1/UJL7pVlH767fNUBKBDbo/X5LknLYmgFA3ie0ZEo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NOzZUmhKkPzQCfbi3JbKs7ZFQkICy6kTTKzlWjthuEVzV8UlHL+FJ+mlbFa4cpt9MtKUtddJpAUv0T/4fgHzULrgZEpPA7ZJxbnkEL30vMcGYj4phT3CpQmU+wPCf2JwMIAPksRywQAxJoA9agmSibD0V/g1W27UoONjdy54eyk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net; spf=pass smtp.mailfrom=gmx.net; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b=EBoBmJgA; arc=none smtp.client-ip=212.227.15.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b="EBoBmJgA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1737556894; x=1738161694; i=ps.report@gmx.net; bh=on1/UJL7pVlH767fNUBKBDbo/X5LknLYmgFA3ie0ZEo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=EBoBmJgAqjibLNSKwszCS1gPkfJQFecTdv+isxDP4OsjQWad6xxMQ91KByPSgOOz gsnGg6NnybjpVcT4kiW2lr68HU7Ee6FU+hrKzTqvtvRr/a5eWxpANHhIEgjnhwEK2 VXJEnFxVBWegZX0w9dKVvZKYAP3DO1fI1KSs6yVxx0naWc7n6Ikm4sIBsnKIcaZ9m 8iZNYUV9RqtjziS6J5irKQBbBMSeaAjrQ98yErqXIZZMYDb2h+2e9fIeM/tVwTLuY sVTGkrTisJ6Xi/KP3m1F/ytioIQGO5MpzZxwfF8iyj3Lcdp5ppCBaxrvcC9TdL1dV jHkUeypG62iMaSnoYQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.fritz.box ([82.135.81.9]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MGyxN-1tfKkn2XBL-000TL1; Wed, 22 Jan 2025 15:41:34 +0100 From: Peter Seiderer To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Frederic Weisbecker , Artem Chernyshev , Nam Cao , Peter Seiderer Subject: [PATCH net-next v2 6/8] net: pktgen: fix access outside of user given buffer in pktgen_thread_write() Date: Wed, 22 Jan 2025 15:41:08 +0100 Message-ID: <20250122144110.619989-7-ps.report@gmx.net> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250122144110.619989-1-ps.report@gmx.net> References: <20250122144110.619989-1-ps.report@gmx.net> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:kKJDrPCpHnFyzcAyruWjkTQ24FHSL9dUBybh07+84NzTesAIpjD 4TxdJkanXcULkWtUQts0c9lQuDIGQxU8swp0t/1dcei/7oFyk1CiGR4hOzUTp/KnRdX3Y+1 TfRExHHXtnZ+E4XQ5jljv+u75rautNlO06GGUrzXSHtbZGKu0ODOUDlU9EQli0HIqDNICXQ Q6UD2oEOwM0t+UBuYg77A== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:+ZZ3qlWOV9M=;CQCLPNRqnemM10p9MLnBUmeSerh pEWa4wNmV0W5iT08N5g7XKAtsKpuPCOqcATGTUKvFKeuuJi0Ynx4/gkUSmTbF0lQPfqGgqR3J /HYQpsqM8EmBld/RmSz33SqOdaJDhfVrlhkyWh/rpfKR7mA8PP2rFiDRkakRb81fDBFlz00R3 5Gmi4fTL2c0nmKqGtHuPzGFffC/XIYgLnEorig/FDF3ti3t07r59qgG9DjnR2DL4wrGI9hFOT cBxmRpxpVz5Yc7A+hGoYbT0/D/5cfUjwkbMSUu4+RNuXJKvnt6SzcBsvPbfX7t2DVBLvpWelC MbxtGWAh0wlWWSBHJWHazjslaboilVwfvOuS9dzAS9qa45fJSUxx97lre2JtRPwPHJFsvJnAq 3vpEo4FmtTMwPzQgITZLtxKhECFyU/9xb4A2Oj/Yw5s6WozTbqdsGKo6iTaS3TwDaY5virBbV abuG/9/0j+N/ni9O51ug9lAcEo9yx7Yj33e9x6w9acWit9JNJNMwT/EAWCKhEzSs+dbcAR2iV OfJf75K7JjTYu2UaeuiViB41iwyhGZHWhddwYhvX8EtUJ8PnMiPTIWwosq0e9z7+6GBWW+B9d Gg5poO4ykRyNWx2HHqUeyFl1oiGwq1sLOXdSJnpmdAzIy2gthhfO8aQbvKma/v/Uv9pDMt84T rYw9vTdmSsbcBDMvbChvgWrgwTGy+8Szuus9YTVMN0UuZ0TRjEXqRoAobZodP5W9ZuTQ+pBH9 okdxBCOujnRL+p7FReqGIswnTsUOJLra01bH/a/viAteemHdnqTHkzBEByjwGezf6oXEesqrv jW26ctvT6n1GrRK6oMZlx3nUfgkJhx6rqhaj2HwDnqXhP8T3rrsvMrUbhKuQ4e7HcaYo4suDZ ntr6DEvLYgw+kFi80hiS9fT6qP70LucDR7CSKIY4ZKswfcsD+cDPMqfWaH58ozcr1PMEr/YJw WIaOWCWd8rTg7ZffO7uWZn0QNINV6yXFQiJJ7TkyeY9wKrC4BXpgTU4ywemdYqg2HQ/gVOStf AOSKHufKWBFApVFTUugDs1sYDKCk2L7l1m7LShj1YEFKvjR1zmmlukxHtGixwVxQ9hSuK99TA vJWpcR3FXC9D2z8PtrGojomdGQj6zVZKyq1qkA3HUh/dDmBZ3kwEi6yeugrCeoCCR6OgaVddy 8/quhKBERgJRKvqh/Ij3m+Pow/PD9iWLZd1yDkkWVYw== Honour the user given buffer size for the strn_len() calls (otherwise strn_len() will access memory outside of the user given buffer). Signed-off-by: Peter Seiderer --- Changes v1 -> v2: - no changes --- net/core/pktgen.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/core/pktgen.c b/net/core/pktgen.c index c8a5b4d17407..9fe2a2db0d34 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -1898,8 +1898,8 @@ static ssize_t pktgen_thread_write(struct file *file, i = len; /* Read variable name */ - - len = strn_len(&user_buffer[i], sizeof(name) - 1); + max = min(sizeof(name) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1929,7 +1929,8 @@ static ssize_t pktgen_thread_write(struct file *file, if (!strcmp(name, "add_device")) { char f[32]; memset(f, 0, 32); - len = strn_len(&user_buffer[i], sizeof(f) - 1); + max = min(sizeof(f) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) { ret = len; goto out; From patchwork Wed Jan 22 14:41:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Seiderer X-Patchwork-Id: 13947379 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6B15215072; Wed, 22 Jan 2025 14:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556911; cv=none; b=V19Af0PC+vjDIDjKarQk4QVzI8yXMHg9P1ulRSyqZd+DEDoYHSnjx6LBRHMcY7dYMsvTOceCOMqmHP2Y+QEdw15LBsMsp+dpn8VMSQ0+0PTjRUgr8f8VdldPzqtWjiBxifGk98A2401FeYoPAkKMY9hVRmhk3ylQuZJvWdCNvMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556911; c=relaxed/simple; bh=bFRmCxcDRw4P/M46YqZ3qFTwpdewh/L9b10ZMVqQxXU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XOHswIQCTwwri/D61DfzgbaIp02E+rhiGuyQFfjaxTaY3bxgnsPRw3yhGR1fmTh+B2X+gG0I4YG/frEQMdBtol3pJs0DJsZpdTYhTME5UPYIVpd5IFCJPPMkBXXiZOYwDmpLP2EXuzlGXyhG580JRUInyvxnYQ9/kpmFsfLF4KI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net; spf=pass smtp.mailfrom=gmx.net; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b=Bk13AtR9; arc=none smtp.client-ip=212.227.15.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b="Bk13AtR9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1737556896; x=1738161696; i=ps.report@gmx.net; bh=bFRmCxcDRw4P/M46YqZ3qFTwpdewh/L9b10ZMVqQxXU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=Bk13AtR9q2tm4y0cLP0XiSBYJ9nAsVWnsD7P4zhN5ySGjHecux4gSohfF+imBWnH /EW5RUSYOsw+plAUxypC/Bgedyp1hTs7XMQ0/2fNajURa86AmROyVYAUlSo8zsX1g 1dHK/3HE/ZsaUC76M9Yb26fFJlU6JCJL/pWUsbwEPBnj/fAC8E9jmFFfo2QLPa+OE D/oZmqalGphcF+uNh2Pmnz7SLAmLl7XEah0D1yJoA0emGqYfY/G04i0gIfPygBlq3 Qr8NVHljh7zBzKJsC4LVBwcZ+qsWmJANKtRO4DVNdiDm7iYpsMu2KqlH5q490bR5t wmTVHXt9Hp5bY7gfbA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.fritz.box ([82.135.81.9]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mirna-1syGtP3l80-00jgC4; Wed, 22 Jan 2025 15:41:36 +0100 From: Peter Seiderer To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Frederic Weisbecker , Artem Chernyshev , Nam Cao , Peter Seiderer Subject: [PATCH net-next v2 7/8] net: pktgen: fix access outside of user given buffer in pktgen_if_write() Date: Wed, 22 Jan 2025 15:41:09 +0100 Message-ID: <20250122144110.619989-8-ps.report@gmx.net> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250122144110.619989-1-ps.report@gmx.net> References: <20250122144110.619989-1-ps.report@gmx.net> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:me8HBN71d8jSdZY23NV4wmfROuotuHwNloLCxbL1IVfYuOKhOF0 dz4zqAn68qSB+9bEdL46WcUrG7lDC2PGLwpjO5/5cSLTo4vTKw6gfJAFXCtYcD9RsPZcwy8 1Gt3tkPoOhsC1DI1UTaTAjHU6R0JqDnkP4lVrzhqoln7r47CyxFAAYPESoWBGrxbpdFEcpp iDtIQZy66A9j5GUrqhLrg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:IbPIFGcAjfs=;shPOiddkJm91Zf+Kq1rZGaeM910 fKyKu10sTZ3XXKXeFZ0oiT5/gpwe/QTtIxBlkkIuaYJZlhEkztEvtxmpZ9ee1VY4EzJd1Azyh xbnxGaX66v4pk0YubecoKVhjDllSgKHeu4n/+NDn7mWsjS1ABrlnvsDHJbhN1PfBHubRtgjSa NdFWtZGRLZDYaPKErB/ojnTg7RtJlahIacktoz9sSqMWYS7dslfjbbRoxH2xdRT52vryos1Zl hCYgjQEB9QbpGD27fN90k6W+6QxFSDbSvX/uOyKmGMWJ+b2KbWLMf/oPlCsZpR+/F+FWJVlpw DSc3cS+vGNkGMTA+WK6f82WIdVOk+Q3Gkcdy7+IpPQUKJwBt5rMzWRZVdMk5GyEEYr3mVBiM3 6FaBRKsgaQL2SQV7YQWFNSm7KkwIxAThsDOgj98G5XrM9v0eakFPWw41ocMLIsDG860PLWm0y FydyCBwdV2+pTjMRkpmYmj9SeJd79JqBInuvRHCHZK6xw7c4rK+noqeeCkqqkx4y3bRvXtyCO ujtiZvWnMywPG8qdnxsSIpo83BTISrmH6afZ8Sh3dNAk65QyxbF78aF+Vx02tnIDOnpUxMVwO CMCmv6k3pvcJSjpsRisnoVQRJt2aGSdFwCB0nFLtXPmsB14PxNTvJ1X6pNBToCnvRZ/96FzbC Q7MaLnH/5rS3BmAJ+x9Ef/JBq/YGkWFZ1jtfOSyJKHg1Kh97WM3CDUgC0tYIE2q9RdIdhDVin vblbdAiSaG5sigz/xxjtzawg5HM670WDU8ZNF0dIqZbm4nw+QaHpCdHx/SucMxqhZuwtyq1Sd aCd1kzAsEKD8SoX1hCk8oiGaK4Ig5Vmi1k/ylRA1bpFa3TYvgcWOkq1bVP1JIs9Rh6TBSn7tz TL6s7kls/+0j6EhDr9luAT/ylnjyJXhygNewXDKue7GyeW3vCieaQ242OPC2nC0noPaT/qrWo eyOkz5YsVD/wN66MNrtrCPkGOxx5RiB0Z3Zy8jnqwkrhlv7cyQV/PayXVxaFwvWJTtxLD2+y3 J9Ra7dg1Bl22Otm1sc0RMEv5bsqoYGIwIs41oB3BzmRvHwd3OnXG7tlPOq9pm1vWXEUhRu/v+ nK7B70xpGSVKpXFwRkreR/Bn6BKx9dTWRFw+zm0EUi0UHtlbs+0h2lXrqPm3chqQZMwAityYo y9golyiPMqe/bEVPNZ1jv8UaculGKXkXq5RK0JsKdVivl4JbDzQl1wRZ/yiFqG+g= Honour the user given buffer size for the hex32_arg(), num_arg(), strn_len(), get_imix_entries() and get_labels() calls (otherwise they will access memory outside of the user given buffer). In hex32_arg(), num_arg(), strn_len() error out in case no characters are available (maxlen = 0), in num_arg() additional error out in case no valid character is parsed. In get_labels() additional enable parsing labels up to MAX_IMIX_ENTRIES instead of (MAX_IMIX_ENTRIES - 1). Additional remove some superfluous variable initializing and align some variable declarations to the most common pattern. Signed-off-by: Peter Seiderer --- Changes v1 -> v2: - additional fix get_imix_entries() and get_labels() --- net/core/pktgen.c | 213 ++++++++++++++++++++++++++++++---------------- 1 file changed, 140 insertions(+), 73 deletions(-) diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 9fe2a2db0d34..1fc037641610 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -750,6 +750,9 @@ static int hex32_arg(const char __user *user_buffer, unsigned long maxlen, int i = 0; *num = 0; + if (!maxlen) + return -EINVAL; + for (; i < maxlen; i++) { int value; char c; @@ -797,6 +800,9 @@ static long num_arg(const char __user *user_buffer, unsigned long maxlen, int i; *num = 0; + if (!maxlen) + return -EINVAL; + for (i = 0; i < maxlen; i++) { char c; if (get_user(c, &user_buffer[i])) @@ -804,6 +810,9 @@ static long num_arg(const char __user *user_buffer, unsigned long maxlen, if ((c >= '0') && (c <= '9')) { *num *= 10; *num += c - '0'; + } else if (i == 0) { + // no valid character parsed, error out + return -EINVAL; } else break; } @@ -814,6 +823,9 @@ static int strn_len(const char __user * user_buffer, unsigned int maxlen) { int i; + if (!maxlen) + return -EINVAL; + for (i = 0; i < maxlen; i++) { char c; if (get_user(c, &user_buffer[i])) @@ -840,11 +852,10 @@ static int strn_len(const char __user * user_buffer, unsigned int maxlen) * "size1,weight_1 size2,weight_2 ... size_n,weight_n" for example. */ static ssize_t get_imix_entries(const char __user *buffer, + unsigned int maxlen, struct pktgen_dev *pkt_dev) { - const int max_digits = 10; - int i = 0; - long len; + int i = 0, max, len; char c; pkt_dev->n_imix_entries = 0; @@ -856,10 +867,13 @@ static ssize_t get_imix_entries(const char __user *buffer, if (pkt_dev->n_imix_entries >= MAX_IMIX_ENTRIES) return -E2BIG; - len = num_arg(&buffer[i], max_digits, &size); + max = min(10, maxlen - i); + len = num_arg(&buffer[i], max, &size); if (len < 0) return len; i += len; + if (i >= maxlen) + return -EINVAL; if (get_user(c, &buffer[i])) return -EFAULT; /* Check for comma between size_i and weight_i */ @@ -870,7 +884,8 @@ static ssize_t get_imix_entries(const char __user *buffer, if (size < 14 + 20 + 8) size = 14 + 20 + 8; - len = num_arg(&buffer[i], max_digits, &weight); + max = min(10, maxlen - i); + len = num_arg(&buffer[i], max, &weight); if (len < 0) return len; if (weight <= 0) @@ -880,39 +895,45 @@ static ssize_t get_imix_entries(const char __user *buffer, pkt_dev->imix_entries[pkt_dev->n_imix_entries].weight = weight; i += len; + pkt_dev->n_imix_entries++; + + if (i >= maxlen) + break; if (get_user(c, &buffer[i])) return -EFAULT; - i++; - pkt_dev->n_imix_entries++; } while (c == ' '); return i; } -static ssize_t get_labels(const char __user *buffer, struct pktgen_dev *pkt_dev) +static ssize_t get_labels(const char __user *buffer, int maxlen, struct pktgen_dev *pkt_dev) { unsigned int n = 0; char c; - ssize_t i = 0; - int len; + int i = 0, max, len; pkt_dev->nr_labels = 0; do { __u32 tmp; - len = hex32_arg(&buffer[i], 8, &tmp); - if (len <= 0) + + if (n >= MAX_MPLS_LABELS) + return -E2BIG; + + max = min(8, maxlen - i); + len = hex32_arg(&buffer[i], max, &tmp); + if (len < 0) return len; pkt_dev->labels[n] = htonl(tmp); if (pkt_dev->labels[n] & MPLS_STACK_BOTTOM) pkt_dev->flags |= F_MPLS_RND; i += len; + n++; + if (i >= maxlen) + break; if (get_user(c, &buffer[i])) return -EFAULT; i++; - n++; - if (n >= MAX_MPLS_LABELS) - return -E2BIG; } while (c == ','); pkt_dev->nr_labels = n; @@ -958,7 +979,6 @@ static ssize_t pktgen_if_write(struct file *file, char name[16], valstr[32]; unsigned long value = 0; char *pg_result = NULL; - int tmp = 0; char buf[128]; pg_result = &(pkt_dev->result[0]); @@ -968,17 +988,16 @@ static ssize_t pktgen_if_write(struct file *file, return -EINVAL; } - max = count; - tmp = count_trail_chars(user_buffer, max); - if (tmp < 0) { + len = count_trail_chars(user_buffer, count); + if (len < 0) { pr_warn("illegal format\n"); - return tmp; + return len; } - i = tmp; + i = len; /* Read variable name */ - - len = strn_len(&user_buffer[i], sizeof(name) - 1); + max = min(sizeof(name) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1006,7 +1025,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "min_pkt_size")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1023,7 +1043,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "max_pkt_size")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1042,7 +1063,8 @@ static ssize_t pktgen_if_write(struct file *file, /* Shortcut for min = max */ if (!strcmp(name, "pkt_size")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1062,7 +1084,8 @@ static ssize_t pktgen_if_write(struct file *file, if (pkt_dev->clone_skb > 0) return -EINVAL; - len = get_imix_entries(&user_buffer[i], pkt_dev); + max = count - i; + len = get_imix_entries(&user_buffer[i], max, pkt_dev); if (len < 0) return len; @@ -1073,7 +1096,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "debug")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1084,7 +1108,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "frags")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1094,7 +1119,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "delay")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1109,7 +1135,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "rate")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1124,7 +1151,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "ratep")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1139,7 +1167,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "udp_src_min")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1152,7 +1181,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "udp_dst_min")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1165,7 +1195,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "udp_src_max")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1178,7 +1209,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "udp_dst_max")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1191,7 +1223,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "clone_skb")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; /* clone_skb is not supported for netif_receive xmit_mode and @@ -1212,7 +1245,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "count")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1223,7 +1257,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "src_mac_count")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1237,7 +1272,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "dst_mac_count")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1251,7 +1287,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "burst")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1270,7 +1307,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "node")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1291,11 +1329,12 @@ static ssize_t pktgen_if_write(struct file *file, if (!strcmp(name, "xmit_mode")) { char f[32]; - memset(f, 0, 32); - len = strn_len(&user_buffer[i], sizeof(f) - 1); + max = min(sizeof(f) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; + memset(f, 0, sizeof(f)); if (copy_from_user(f, &user_buffer[i], len)) return -EFAULT; i += len; @@ -1331,11 +1370,12 @@ static ssize_t pktgen_if_write(struct file *file, char f[32]; char *end; - memset(f, 0, 32); - len = strn_len(&user_buffer[i], sizeof(f) - 1); + max = min(sizeof(f) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; + memset(f, 0, 32); if (copy_from_user(f, &user_buffer[i], len)) return -EFAULT; i += len; @@ -1380,7 +1420,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "dst_min") || !strcmp(name, "dst")) { - len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_min) - 1); + max = min(sizeof(pkt_dev->dst_min) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1400,7 +1441,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "dst_max")) { - len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_max) - 1); + max = min(sizeof(pkt_dev->dst_max) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1420,7 +1462,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "dst6")) { - len = strn_len(&user_buffer[i], sizeof(buf) - 1); + max = min(sizeof(buf) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1443,7 +1486,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "dst6_min")) { - len = strn_len(&user_buffer[i], sizeof(buf) - 1); + max = min(sizeof(buf) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1465,7 +1509,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "dst6_max")) { - len = strn_len(&user_buffer[i], sizeof(buf) - 1); + max = min(sizeof(buf) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1486,7 +1531,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "src6")) { - len = strn_len(&user_buffer[i], sizeof(buf) - 1); + max = min(sizeof(buf) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1509,7 +1555,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "src_min")) { - len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_min) - 1); + max = min(sizeof(pkt_dev->src_min) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1529,7 +1576,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "src_max")) { - len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_max) - 1); + max = min(sizeof(pkt_dev->src_max) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1549,7 +1597,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "dst_mac")) { - len = strn_len(&user_buffer[i], sizeof(valstr) - 1); + max = min(sizeof(valstr) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1566,7 +1615,8 @@ static ssize_t pktgen_if_write(struct file *file, return count; } if (!strcmp(name, "src_mac")) { - len = strn_len(&user_buffer[i], sizeof(valstr) - 1); + max = min(sizeof(valstr) - 1, count - i); + len = strn_len(&user_buffer[i], max); if (len < 0) return len; @@ -1590,7 +1640,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "flows")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1604,7 +1655,8 @@ static ssize_t pktgen_if_write(struct file *file, } #ifdef CONFIG_XFRM if (!strcmp(name, "spi")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1615,7 +1667,8 @@ static ssize_t pktgen_if_write(struct file *file, } #endif if (!strcmp(name, "flowlen")) { - len = num_arg(&user_buffer[i], 10, &value); + max = min(10, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1626,7 +1679,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "queue_map_min")) { - len = num_arg(&user_buffer[i], 5, &value); + max = min(5, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1637,7 +1691,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "queue_map_max")) { - len = num_arg(&user_buffer[i], 5, &value); + max = min(5, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1650,7 +1705,8 @@ static ssize_t pktgen_if_write(struct file *file, if (!strcmp(name, "mpls")) { unsigned int n, cnt; - len = get_labels(&user_buffer[i], pkt_dev); + max = count - i; + len = get_labels(&user_buffer[i], max, pkt_dev); if (len < 0) return len; i += len; @@ -1671,7 +1727,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "vlan_id")) { - len = num_arg(&user_buffer[i], 4, &value); + max = min(4, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1698,7 +1755,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "vlan_p")) { - len = num_arg(&user_buffer[i], 1, &value); + max = min(1, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1713,7 +1771,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "vlan_cfi")) { - len = num_arg(&user_buffer[i], 1, &value); + max = min(1, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1728,7 +1787,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "svlan_id")) { - len = num_arg(&user_buffer[i], 4, &value); + max = min(4, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1755,7 +1815,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "svlan_p")) { - len = num_arg(&user_buffer[i], 1, &value); + max = min(1, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1770,7 +1831,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "svlan_cfi")) { - len = num_arg(&user_buffer[i], 1, &value); + max = min(1, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; @@ -1785,8 +1847,10 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "tos")) { - __u32 tmp_value = 0; - len = hex32_arg(&user_buffer[i], 2, &tmp_value); + __u32 tmp_value; + + max = min(2, count - i); + len = hex32_arg(&user_buffer[i], max, &tmp_value); if (len < 0) return len; @@ -1801,8 +1865,10 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "traffic_class")) { - __u32 tmp_value = 0; - len = hex32_arg(&user_buffer[i], 2, &tmp_value); + __u32 tmp_value; + + max = min(2, count - i); + len = hex32_arg(&user_buffer[i], max, &tmp_value); if (len < 0) return len; @@ -1817,7 +1883,8 @@ static ssize_t pktgen_if_write(struct file *file, } if (!strcmp(name, "skb_priority")) { - len = num_arg(&user_buffer[i], 9, &value); + max = min(9, count - i); + len = num_arg(&user_buffer[i], max, &value); if (len < 0) return len; From patchwork Wed Jan 22 14:41:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Seiderer X-Patchwork-Id: 13947376 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5535E2147EA; Wed, 22 Jan 2025 14:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556903; cv=none; b=jVd33w4Zpn4irYGyodU1NpHKt+NXu83XHyJIiBtsiDAZuB90tGSgrPHCK2US9q7x07kPyegLYTUckWQMNWxPCkx0BjbFRNzLcG217/WAoaVFt62rInvDAigPOJI3gTEaHgWBhhtH6nRHze+nt4Z7eax6xJfLam75sAe1LXGm7rI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737556903; c=relaxed/simple; bh=nXa3Xh3wsOvOtJ3WzC+/pCuVSny/ta0XQcDhb5H4To8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yt6Uks313/G+8jOf86LVuZZJE1ALlF1um4gCC5vNO7bjGTlZSdTeJT7h+XjS6jB6ktOay8T0J9R1JqLpm1cb5Jo5wqCfjQOSMWmxGs3FVebi5GCsyTc7zW/RDm5KKVCPWql1WysR01WItJVFeBZT7OKvECTswoizQxCpXAzk22w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net; spf=pass smtp.mailfrom=gmx.net; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b=gCliRAqp; arc=none smtp.client-ip=212.227.15.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.net header.i=ps.report@gmx.net header.b="gCliRAqp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1737556898; x=1738161698; i=ps.report@gmx.net; bh=nXa3Xh3wsOvOtJ3WzC+/pCuVSny/ta0XQcDhb5H4To8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=gCliRAqps8CAL9m9xoAPQGuCAI0AHqelZ5whruPTA/nh1MV8KO4TAWL194XO304M 4R99dXFc5V+GcRMRTj1w4PK59WKHA52gDxlkUGVRzAPzvvmgY3c6MRtiVSis9XRhQ HaBuPAkcQaBIpQJOPx09m9tFN3lVNDokMBnnyTdjDNKXtZfNRlUxjC0CQ02aRjC43 wsJzWvYjdVgsqau/D04Zo6gG1P/Ni56eelyO3XpF8s6h3c2VwX32Ws29mhtqeID+A 0PzW36GfUzq4cueBWeguFESdV2kaZonjTWeyQ4OJCuv9q42AWFntBNQZg4GhqkJ6v zPPQ4GYnunjySmHMSg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.fritz.box ([82.135.81.9]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N95e9-1tP2qj1ech-00sIud; Wed, 22 Jan 2025 15:41:38 +0100 From: Peter Seiderer To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Frederic Weisbecker , Artem Chernyshev , Nam Cao , Peter Seiderer Subject: [PATCH net-next v2 8/8] selftest: net: add proc_net_pktgen Date: Wed, 22 Jan 2025 15:41:10 +0100 Message-ID: <20250122144110.619989-9-ps.report@gmx.net> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250122144110.619989-1-ps.report@gmx.net> References: <20250122144110.619989-1-ps.report@gmx.net> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:+qOR47IwguYPrlHu1xU6oMbtulDznTuo2lQQmfNyBz0oe1jTyFk OfzKgCEiiV7ut894ZRF+HmDxoRbjA2ft1BJpTigkj6023TyIInuSgagl/FB1NVh9qrI6EXr vELAGTk43H6g6FtQiREk1pkhGtQ3rq+rxzt4NEVWs+bCrzTXnb/r6GJB7xg43Vu8b3O/VL6 JWl2l77UwEzCvDOsVb5bg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:TQvVwgD9X7M=;Eyymux7TwCHXRC+yA4De4irdsZI RPbKDIrmK7QzuZHWmL0VKqGvgAyzZ/jhfoE6jU/Wjt2yO4IHftqjzmxiuDXk8GvW255wnXs+G +jyC2rSNi58aVD69h0zLxlPPOsnQoVfSjt3UywZSVvPdR0Up3WxbaaZEwuSQLmBfhSU5uUa69 lkhWoR6OtiwyBDKciZG+C5UHtYGf4HYjlHtaolSqG4dAIrULHPRcjTNfuFLayx3aV7EM22Vfv 3RmouJmm8Wy0mTf+6NzxGKQgZWZIbXN7q3Jzu+2wZu9VWScdHMn0D0JBB+/ysJe6yQ+oUyb3d rMQuTQWfcTF7Z+eM1rkAV5kzInnHEIOlFuX0kbBUeM/IDK4dXdDaCSInf31ji90IEtzVeHMLw xgdYzaACBlCXuMzM8nY1aFNYUKS7cEm6N7xK6I4JrDoJ7rP1e21a2peTLcMvsRHcyBboMbODg u+hiRnMwUizj7rGoHvzRIL+zqB7l05PNvR9uyBFdlZhZAPVOkheva4cRGY6dJAleu46EjXDSM +nIK+K4tjV1ikT1svimycJiHjfFpbDdohiWxuxpc2gFKxphv+9++RNjS+iSwGGb3mbzeiv07Y pEy3nUgnBFSjwxxrKYhtX7qaC/0yTQSGKUxdk85e196aSAp5THJAfYGnNUlTPTMTwSo2Kl0Ck asENEcAj+GkF+dDDSckNa3YDFiGZTh3Q8vzXXwXawYDmW+1oj3Br+rf5CSrpy4YXn2M5x0VT/ iy5QcSRfSMBDjghJBK0OtJ7+SHF+02sdS4DYpVC9Iaz+5x8mbgCZ0impRNgk+YHFtlIYZIZbh ea38BlFo8Gja4x5w35eyw1/GX3BpI5dS4l5zHYSo8UYjF5xUKuPChJFtliYDBt8GS23obe3Rx 9j7Py0k7PNy0Z/TcOTJ0nJdi9mfwxdOy5c8mXTPrIgUL8o5Uz0Zrm3StZ25mB3i8NN56KxRE+ his46s6RZveUnoyMkzPIq0dRNZhyBfAIL4BVlEOGOh4bp8YQYV8MLmYZg7LAMdqe40jexZied 3iytwx6n5YxWvTyH9E1J0IAttMh1DmC45jWKq+9LSHox91EcxZzypSXK9QTn4mh6zfbNqg4iG z3ma37AArHXxw5jLpla/GjhsIKt4i0orQHDHAPrClaY9TfHXanAyklseM6cWo7s8wKD3+cDhq 66V2VT3H0muVnCV32g97OBu0LbuGubIVhHyvVx6XrBg== Add some test for /proc/net/pktgen/... interface. - enable 'CONFIG_NET_PKTGEN=m' in tools/testing/selftests/net/config Signed-off-by: Peter Seiderer --- Changes v1 -> v1: - fix tyop not vs. nod (suggested by Jakub Kicinski) - fix misaligned line (suggested by Jakub Kicinski) - enable fomerly commented out CONFIG_XFRM dependent test (command spi), as CONFIG_XFRM is enabled via tools/testing/selftests/net/config CONFIG_XFRM_INTERFACE/CONFIG_XFRM_USER (suggestex by Jakub Kicinski) - add CONFIG_NET_PKTGEN=m to tools/testing/selftests/net/config (suggested by Jakub Kicinski) - add modprobe pktgen to FIXTURE_SETUP() (suggested by Jakub Kicinski) - fix some checkpatch warnings (Missing a blank line after declarations) - shrink line length by re-naming some variables (command -> cmd, device -> dev) - add 'rate 0' testcase - add 'ratep 0' testcase --- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 1 + tools/testing/selftests/net/proc_net_pktgen.c | 605 ++++++++++++++++++ 3 files changed, 607 insertions(+) create mode 100644 tools/testing/selftests/net/proc_net_pktgen.c diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 73ee88d6b043..095708cd8345 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -100,6 +100,7 @@ TEST_PROGS += vlan_bridge_binding.sh TEST_PROGS += bpf_offload.py TEST_PROGS += ipv6_route_update_soft_lockup.sh TEST_PROGS += busy_poll_test.sh +TEST_GEN_PROGS += proc_net_pktgen # YNL files, must be before "include ..lib.mk" YNL_GEN_FILES := busy_poller netlink-dumps diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config index 5b9baf708950..9fe1b3464fbc 100644 --- a/tools/testing/selftests/net/config +++ b/tools/testing/selftests/net/config @@ -107,3 +107,4 @@ CONFIG_XFRM_INTERFACE=m CONFIG_XFRM_USER=m CONFIG_IP_NF_MATCH_RPFILTER=m CONFIG_IP6_NF_MATCH_RPFILTER=m +CONFIG_NET_PKTGEN=m diff --git a/tools/testing/selftests/net/proc_net_pktgen.c b/tools/testing/selftests/net/proc_net_pktgen.c new file mode 100644 index 000000000000..5e2a2926d14a --- /dev/null +++ b/tools/testing/selftests/net/proc_net_pktgen.c @@ -0,0 +1,605 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * proc_net_pktgen: kselftest for /proc/net/pktgen interface + * + * Copyright (c) 2025 Peter Seiderer + * + */ +#include +#include +#include +#include + +#include "../kselftest_harness.h" + +static const char add_loopback_0[] = "add_device lo@0"; +static const char rm_loopback_0[] = "rem_device_all"; + +static const char wrong_ctrl_cmd[] = "forsureawrongcommand"; +static const char legacy_ctrl_cmd[] = "max_before_softirq"; + +static const char wrong_dev_cmd[] = "forsurewrongcommand"; +static const char dev_cmd_min_pkt_size_0[] = "min_pkt_size"; +static const char dev_cmd_min_pkt_size_1[] = "min_pkt_size "; +static const char dev_cmd_min_pkt_size_2[] = "min_pkt_size 0"; +static const char dev_cmd_min_pkt_size_3[] = "min_pkt_size 1"; +static const char dev_cmd_min_pkt_size_4[] = "min_pkt_size 100"; +static const char dev_cmd_min_pkt_size_5[] = "min_pkt_size=1001"; +static const char dev_cmd_min_pkt_size_6[] = "min_pkt_size =2002"; +static const char dev_cmd_min_pkt_size_7[] = "min_pkt_size= 3003"; +static const char dev_cmd_min_pkt_size_8[] = "min_pkt_size = 4004"; +static const char dev_cmd_max_pkt_size_0[] = "max_pkt_size 200"; +static const char dev_cmd_pkt_size_0[] = "pkt_size 300"; +static const char dev_cmd_imix_weights_0[] = "imix_weights 0,7 576,4 1500,1"; +static const char dev_cmd_imix_weights_1[] = "imix_weights 101,1 102,2 103,3 104,4 105,5 106,6 107,7 108,8 109,9 110,10 111,11 112,12 113,13 114,14 115,15 116,16 117,17 118,18 119,19 120,20"; +static const char dev_cmd_imix_weights_2[] = "imix_weights 100,1 102,2 103,3 104,4 105,5 106,6 107,7 108,8 109,9 110,10 111,11 112,12 113,13 114,14 115,15 116,16 117,17 118,18 119,19 120,20 121,21"; +static const char dev_cmd_debug_0[] = "debug 1"; +static const char dev_cmd_debug_1[] = "debug 0"; +static const char dev_cmd_frags_0[] = "frags 100"; +static const char dev_cmd_delay_0[] = "delay 100"; +static const char dev_cmd_delay_1[] = "delay 2147483647"; +static const char dev_cmd_rate_0[] = "rate 0"; +static const char dev_cmd_rate_1[] = "rate 100"; +static const char dev_cmd_ratep_0[] = "ratep 0"; +static const char dev_cmd_ratep_1[] = "ratep 200"; +static const char dev_cmd_udp_src_min_0[] = "udp_src_min 1"; +static const char dev_cmd_udp_dst_min_0[] = "udp_dst_min 2"; +static const char dev_cmd_udp_src_max_0[] = "udp_src_max 3"; +static const char dev_cmd_udp_dst_max_0[] = "udp_dst_max 4"; +static const char dev_cmd_clone_skb_0[] = "clone_skb 1"; +static const char dev_cmd_clone_skb_1[] = "clone_skb 0"; +static const char dev_cmd_count_0[] = "count 100"; +static const char dev_cmd_src_mac_count_0[] = "src_mac_count 100"; +static const char dev_cmd_dst_mac_count_0[] = "dst_mac_count 100"; +static const char dev_cmd_burst_0[] = "burst 0"; +static const char dev_cmd_node_0[] = "node 100"; +static const char dev_cmd_xmit_mode_0[] = "xmit_mode start_xmit"; +static const char dev_cmd_xmit_mode_1[] = "xmit_mode netif_receive"; +static const char dev_cmd_xmit_mode_2[] = "xmit_mode queue_xmit"; +static const char dev_cmd_xmit_mode_3[] = "xmit_mode nonsense"; +static const char dev_cmd_flag_0[] = "flag UDPCSUM"; +static const char dev_cmd_flag_1[] = "flag !UDPCSUM"; +static const char dev_cmd_flag_2[] = "flag nonsense"; +static const char dev_cmd_dst_min_0[] = "dst_min 101.102.103.104"; +static const char dev_cmd_dst_0[] = "dst 101.102.103.104"; +static const char dev_cmd_dst_max_0[] = "dst_max 201.202.203.204"; +static const char dev_cmd_dst6_0[] = "dst6 2001:db38:1234:0000:0000:0000:0000:0000"; +static const char dev_cmd_dst6_min_0[] = "dst6_min 2001:db8:1234:0000:0000:0000:0000:0000"; +static const char dev_cmd_dst6_max_0[] = "dst6_max 2001:db8:1234:0000:0000:0000:0000:0000"; +static const char dev_cmd_src6_0[] = "src6 2001:db38:1234:0000:0000:0000:0000:0000"; +static const char dev_cmd_src_min_0[] = "src_min 101.102.103.104"; +static const char dev_cmd_src_max_0[] = "src_max 201.202.203.204"; +static const char dev_cmd_dst_mac_0[] = "dst_mac 01:02:03:04:05:06"; +static const char dev_cmd_src_mac_0[] = "src_mac 11:12:13:14:15:16"; +static const char dev_cmd_clear_counters_0[] = "clear_counters"; +static const char dev_cmd_flows_0[] = "flows 100"; +static const char dev_cmd_spi_0[] = "spi 100"; +static const char dev_cmd_flowlen_0[] = "flowlen 100"; +static const char dev_cmd_queue_map_min_0[] = "queue_map_min 1"; +static const char dev_cmd_queue_map_max_0[] = "queue_map_max 2"; +static const char dev_cmd_mpls_0[] = "mpls 00000001"; +static const char dev_cmd_mpls_1[] = "mpls 00000001,000000f2"; +static const char dev_cmd_mpls_2[] = "mpls 00000f00,00000f01,00000f02,00000f03,00000f04,00000f05,00000f06,00000f07,00000f08,00000f09,00000f0a,00000f0b,00000f0c,00000f0d,00000f0e,00000f0f"; +static const char dev_cmd_mpls_3[] = "mpls 00000f00,00000f01,00000f02,00000f03,00000f04,00000f05,00000f06,00000f07,00000f08,00000f09,00000f0a,00000f0b,00000f0c,00000f0d,00000f0e,00000f0f,00000f10"; +static const char dev_cmd_vlan_id_0[] = "vlan_id 1"; +static const char dev_cmd_vlan_p_0[] = "vlan_p 1"; +static const char dev_cmd_vlan_cfi_0[] = "vlan_cfi 1"; +static const char dev_cmd_vlan_id_1[] = "vlan_id 4096"; +static const char dev_cmd_svlan_id_0[] = "svlan_id 1"; +static const char dev_cmd_svlan_p_0[] = "svlan_p 1"; +static const char dev_cmd_svlan_cfi_0[] = "svlan_cfi 1"; +static const char dev_cmd_svlan_id_1[] = "svlan_id 4096"; +static const char dev_cmd_tos_0[] = "tos 0"; +static const char dev_cmd_tos_1[] = "tos 0f"; +static const char dev_cmd_tos_2[] = "tos 0ff"; +static const char dev_cmd_traffic_class_0[] = "traffic_class f0"; +static const char dev_cmd_skb_priority_0[] = "skb_priority 999"; + +FIXTURE(proc_net_pktgen) { + int ctrl_fd; + int dev_fd; +}; + +FIXTURE_SETUP(proc_net_pktgen) { + int r; + ssize_t len; + + r = system("modprobe pktgen"); + ASSERT_EQ(r, 0) TH_LOG("CONFIG_NET_PKTGEN not enabled, module pktgen not loaded?"); + + self->ctrl_fd = open("/proc/net/pktgen/kpktgend_0", O_RDWR); + ASSERT_GE(self->ctrl_fd, 0) TH_LOG("CONFIG_NET_PKTGEN not enabled, module pktgen not loaded?"); + + len = write(self->ctrl_fd, add_loopback_0, sizeof(add_loopback_0)); + ASSERT_EQ(len, sizeof(add_loopback_0)) TH_LOG("device lo@0 already registered?"); + + self->dev_fd = open("/proc/net/pktgen/lo@0", O_RDWR); + ASSERT_GE(self->dev_fd, 0) TH_LOG("device entry for lo@0 missing?"); +} + +FIXTURE_TEARDOWN(proc_net_pktgen) { + int ret; + ssize_t len; + + ret = close(self->dev_fd); + EXPECT_EQ(ret, 0); + + len = write(self->ctrl_fd, rm_loopback_0, sizeof(rm_loopback_0)); + EXPECT_EQ(len, sizeof(rm_loopback_0)); + + ret = close(self->ctrl_fd); + EXPECT_EQ(ret, 0); +} + +TEST_F(proc_net_pktgen, wrong_ctrl_cmd) { + for (int i = 0; i <= sizeof(wrong_ctrl_cmd); i++) { + ssize_t len; + + len = write(self->ctrl_fd, wrong_ctrl_cmd, i); + EXPECT_EQ(len, -1); + EXPECT_EQ(errno, EINVAL); + } +} + +TEST_F(proc_net_pktgen, legacy_ctrl_cmd) { + for (int i = 0; i <= sizeof(legacy_ctrl_cmd); i++) { + ssize_t len; + + len = write(self->ctrl_fd, legacy_ctrl_cmd, i); + if (i < (sizeof(legacy_ctrl_cmd) - 1)) { + // incomplete command string + EXPECT_EQ(len, -1); + EXPECT_EQ(errno, EINVAL); + } else { + // complete command string without/with trailing '\0' + EXPECT_EQ(len, i); + } + } +} + +TEST_F(proc_net_pktgen, wrong_dev_cmd) { + for (int i = 0; i <= sizeof(wrong_dev_cmd); i++) { + ssize_t len; + + len = write(self->dev_fd, wrong_dev_cmd, i); + EXPECT_EQ(len, -1); + EXPECT_EQ(errno, EINVAL); + } +} + +TEST_F(proc_net_pktgen, dev_cmd_min_pkt_size) { + ssize_t len; + + // with trailing '\0' + len = write(self->dev_fd, dev_cmd_min_pkt_size_0, sizeof(dev_cmd_min_pkt_size_0)); + EXPECT_EQ(len, -1); + EXPECT_EQ(errno, EINVAL); + + // without trailing '\0' + len = write(self->dev_fd, dev_cmd_min_pkt_size_0, sizeof(dev_cmd_min_pkt_size_0) - 1); + EXPECT_EQ(len, -1); + EXPECT_EQ(errno, EINVAL); + + // with trailing '\0' + len = write(self->dev_fd, dev_cmd_min_pkt_size_1, sizeof(dev_cmd_min_pkt_size_1)); + EXPECT_EQ(len, -1); + EXPECT_EQ(errno, EINVAL); + + // without trailing '\0' + len = write(self->dev_fd, dev_cmd_min_pkt_size_1, sizeof(dev_cmd_min_pkt_size_1) - 1); + EXPECT_EQ(len, -1); + EXPECT_EQ(errno, EINVAL); + + // with trailing '\0' + len = write(self->dev_fd, dev_cmd_min_pkt_size_2, sizeof(dev_cmd_min_pkt_size_2)); + EXPECT_EQ(len, sizeof(dev_cmd_min_pkt_size_2)); + + // without trailing '\0' + len = write(self->dev_fd, dev_cmd_min_pkt_size_2, sizeof(dev_cmd_min_pkt_size_2) - 1); + EXPECT_EQ(len, sizeof(dev_cmd_min_pkt_size_2) - 1); + + len = write(self->dev_fd, dev_cmd_min_pkt_size_3, sizeof(dev_cmd_min_pkt_size_3)); + EXPECT_EQ(len, sizeof(dev_cmd_min_pkt_size_3)); + + len = write(self->dev_fd, dev_cmd_min_pkt_size_4, sizeof(dev_cmd_min_pkt_size_4)); + EXPECT_EQ(len, sizeof(dev_cmd_min_pkt_size_4)); + + len = write(self->dev_fd, dev_cmd_min_pkt_size_5, sizeof(dev_cmd_min_pkt_size_5)); + EXPECT_EQ(len, sizeof(dev_cmd_min_pkt_size_5)); + + len = write(self->dev_fd, dev_cmd_min_pkt_size_6, sizeof(dev_cmd_min_pkt_size_6)); + EXPECT_EQ(len, sizeof(dev_cmd_min_pkt_size_6)); + + len = write(self->dev_fd, dev_cmd_min_pkt_size_7, sizeof(dev_cmd_min_pkt_size_7)); + EXPECT_EQ(len, sizeof(dev_cmd_min_pkt_size_7)); + + len = write(self->dev_fd, dev_cmd_min_pkt_size_8, sizeof(dev_cmd_min_pkt_size_8)); + EXPECT_EQ(len, sizeof(dev_cmd_min_pkt_size_8)); +} + +TEST_F(proc_net_pktgen, dev_cmd_max_pkt_size) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_max_pkt_size_0, sizeof(dev_cmd_max_pkt_size_0)); + EXPECT_EQ(len, sizeof(dev_cmd_max_pkt_size_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_pkt_size) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_pkt_size_0, sizeof(dev_cmd_pkt_size_0)); + EXPECT_EQ(len, sizeof(dev_cmd_pkt_size_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_imix_weights) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_imix_weights_0, sizeof(dev_cmd_imix_weights_0)); + EXPECT_EQ(len, sizeof(dev_cmd_imix_weights_0)); + + len = write(self->dev_fd, dev_cmd_imix_weights_1, sizeof(dev_cmd_imix_weights_1)); + EXPECT_EQ(len, sizeof(dev_cmd_imix_weights_1)); + + len = write(self->dev_fd, dev_cmd_imix_weights_2, sizeof(dev_cmd_imix_weights_2)); + EXPECT_EQ(len, -1); + EXPECT_EQ(errno, E2BIG); +} + +TEST_F(proc_net_pktgen, dev_cmd_debug) { + ssize_t len; + + // debug on + len = write(self->dev_fd, dev_cmd_debug_0, sizeof(dev_cmd_debug_0)); + EXPECT_EQ(len, sizeof(dev_cmd_debug_0)); + + // debug off + len = write(self->dev_fd, dev_cmd_debug_1, sizeof(dev_cmd_debug_1)); + EXPECT_EQ(len, sizeof(dev_cmd_debug_1)); +} + +TEST_F(proc_net_pktgen, dev_cmd_frags) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_frags_0, sizeof(dev_cmd_frags_0)); + EXPECT_EQ(len, sizeof(dev_cmd_frags_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_delay) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_delay_0, sizeof(dev_cmd_delay_0)); + EXPECT_EQ(len, sizeof(dev_cmd_delay_0)); + + len = write(self->dev_fd, dev_cmd_delay_1, sizeof(dev_cmd_delay_1)); + EXPECT_EQ(len, sizeof(dev_cmd_delay_1)); +} + +TEST_F(proc_net_pktgen, dev_cmd_rate) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_rate_0, sizeof(dev_cmd_rate_0)); + EXPECT_EQ(len, -1); + EXPECT_EQ(errno, EINVAL); + + len = write(self->dev_fd, dev_cmd_rate_1, sizeof(dev_cmd_rate_1)); + EXPECT_EQ(len, sizeof(dev_cmd_rate_1)); +} + +TEST_F(proc_net_pktgen, dev_cmd_ratep) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_ratep_0, sizeof(dev_cmd_ratep_0)); + EXPECT_EQ(len, -1); + EXPECT_EQ(errno, EINVAL); + + len = write(self->dev_fd, dev_cmd_ratep_1, sizeof(dev_cmd_ratep_1)); + EXPECT_EQ(len, sizeof(dev_cmd_ratep_1)); +} + +TEST_F(proc_net_pktgen, dev_cmd_udp_src_min) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_udp_src_min_0, sizeof(dev_cmd_udp_src_min_0)); + EXPECT_EQ(len, sizeof(dev_cmd_udp_src_min_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_udp_dst_min) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_udp_dst_min_0, sizeof(dev_cmd_udp_dst_min_0)); + EXPECT_EQ(len, sizeof(dev_cmd_udp_dst_min_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_udp_src_max) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_udp_src_max_0, sizeof(dev_cmd_udp_src_max_0)); + EXPECT_EQ(len, sizeof(dev_cmd_udp_src_max_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_udp_dst_max) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_udp_dst_max_0, sizeof(dev_cmd_udp_dst_max_0)); + EXPECT_EQ(len, sizeof(dev_cmd_udp_dst_max_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_clone_skb) { + ssize_t len; + + // clone_skb on (gives EOPNOTSUPP on lo device) + len = write(self->dev_fd, dev_cmd_clone_skb_0, sizeof(dev_cmd_clone_skb_0)); + EXPECT_EQ(len, -1); + EXPECT_EQ(errno, EOPNOTSUPP); + + // clone_skb off + len = write(self->dev_fd, dev_cmd_clone_skb_1, sizeof(dev_cmd_clone_skb_1)); + EXPECT_EQ(len, sizeof(dev_cmd_clone_skb_1)); +} + +TEST_F(proc_net_pktgen, dev_cmd_count) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_count_0, sizeof(dev_cmd_count_0)); + EXPECT_EQ(len, sizeof(dev_cmd_count_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_src_mac_count) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_src_mac_count_0, sizeof(dev_cmd_src_mac_count_0)); + EXPECT_EQ(len, sizeof(dev_cmd_src_mac_count_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_dst_mac_count) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_dst_mac_count_0, sizeof(dev_cmd_dst_mac_count_0)); + EXPECT_EQ(len, sizeof(dev_cmd_dst_mac_count_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_burst) { + ssize_t len; + + // burst off + len = write(self->dev_fd, dev_cmd_burst_0, sizeof(dev_cmd_burst_0)); + EXPECT_EQ(len, sizeof(dev_cmd_burst_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_node) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_node_0, sizeof(dev_cmd_node_0)); + EXPECT_EQ(len, sizeof(dev_cmd_node_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_xmit_mode) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_xmit_mode_0, sizeof(dev_cmd_xmit_mode_0)); + EXPECT_EQ(len, sizeof(dev_cmd_xmit_mode_0)); + + len = write(self->dev_fd, dev_cmd_xmit_mode_1, sizeof(dev_cmd_xmit_mode_1)); + EXPECT_EQ(len, sizeof(dev_cmd_xmit_mode_1)); + + len = write(self->dev_fd, dev_cmd_xmit_mode_2, sizeof(dev_cmd_xmit_mode_2)); + EXPECT_EQ(len, sizeof(dev_cmd_xmit_mode_2)); + + len = write(self->dev_fd, dev_cmd_xmit_mode_3, sizeof(dev_cmd_xmit_mode_3)); + EXPECT_EQ(len, sizeof(dev_cmd_xmit_mode_3)); +} + +TEST_F(proc_net_pktgen, dev_cmd_flag) { + ssize_t len; + + // flag UDPCSUM on + len = write(self->dev_fd, dev_cmd_flag_0, sizeof(dev_cmd_flag_0)); + EXPECT_EQ(len, sizeof(dev_cmd_flag_0)); + + // flag UDPCSUM off + len = write(self->dev_fd, dev_cmd_flag_1, sizeof(dev_cmd_flag_1)); + EXPECT_EQ(len, sizeof(dev_cmd_flag_1)); + + // flag invalid + len = write(self->dev_fd, dev_cmd_flag_2, sizeof(dev_cmd_flag_2)); + EXPECT_EQ(len, sizeof(dev_cmd_flag_2)); +} + +TEST_F(proc_net_pktgen, dev_cmd_dst_min) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_dst_min_0, sizeof(dev_cmd_dst_min_0)); + EXPECT_EQ(len, sizeof(dev_cmd_dst_min_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_dst) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_dst_0, sizeof(dev_cmd_dst_0)); + EXPECT_EQ(len, sizeof(dev_cmd_dst_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_dst_max) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_dst_max_0, sizeof(dev_cmd_dst_max_0)); + EXPECT_EQ(len, sizeof(dev_cmd_dst_max_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_dst6) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_dst6_0, sizeof(dev_cmd_dst6_0)); + EXPECT_EQ(len, sizeof(dev_cmd_dst6_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_dst6_min) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_dst6_min_0, sizeof(dev_cmd_dst6_min_0)); + EXPECT_EQ(len, sizeof(dev_cmd_dst6_min_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_dst6_max) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_dst6_max_0, sizeof(dev_cmd_dst6_max_0)); + EXPECT_EQ(len, sizeof(dev_cmd_dst6_max_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_src6) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_src6_0, sizeof(dev_cmd_src6_0)); + EXPECT_EQ(len, sizeof(dev_cmd_src6_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_src_min) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_src_min_0, sizeof(dev_cmd_src_min_0)); + EXPECT_EQ(len, sizeof(dev_cmd_src_min_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_src_max) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_src_max_0, sizeof(dev_cmd_src_max_0)); + EXPECT_EQ(len, sizeof(dev_cmd_src_max_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_dst_mac) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_dst_mac_0, sizeof(dev_cmd_dst_mac_0)); + EXPECT_EQ(len, sizeof(dev_cmd_dst_mac_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_src_mac) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_src_mac_0, sizeof(dev_cmd_src_mac_0)); + EXPECT_EQ(len, sizeof(dev_cmd_src_mac_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_clear_counters) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_clear_counters_0, sizeof(dev_cmd_clear_counters_0)); + EXPECT_EQ(len, sizeof(dev_cmd_clear_counters_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_flows) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_flows_0, sizeof(dev_cmd_flows_0)); + EXPECT_EQ(len, sizeof(dev_cmd_flows_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_spi) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_spi_0, sizeof(dev_cmd_spi_0)); + EXPECT_EQ(len, sizeof(dev_cmd_spi_0)) TH_LOG("CONFIG_XFRM not enabled?"); +} + +TEST_F(proc_net_pktgen, dev_cmd_flowlen) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_flowlen_0, sizeof(dev_cmd_flowlen_0)); + EXPECT_EQ(len, sizeof(dev_cmd_flowlen_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_queue_map_min) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_queue_map_min_0, sizeof(dev_cmd_queue_map_min_0)); + EXPECT_EQ(len, sizeof(dev_cmd_queue_map_min_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_queue_map_max) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_queue_map_max_0, sizeof(dev_cmd_queue_map_max_0)); + EXPECT_EQ(len, sizeof(dev_cmd_queue_map_max_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_mpls) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_mpls_0, sizeof(dev_cmd_mpls_0)); + EXPECT_EQ(len, sizeof(dev_cmd_mpls_0)); + + len = write(self->dev_fd, dev_cmd_mpls_1, sizeof(dev_cmd_mpls_1)); + EXPECT_EQ(len, sizeof(dev_cmd_mpls_1)); + + len = write(self->dev_fd, dev_cmd_mpls_2, sizeof(dev_cmd_mpls_2)); + EXPECT_EQ(len, sizeof(dev_cmd_mpls_2)); + + len = write(self->dev_fd, dev_cmd_mpls_3, sizeof(dev_cmd_mpls_3)); + EXPECT_EQ(len, -1); + EXPECT_EQ(errno, E2BIG); +} + +TEST_F(proc_net_pktgen, dev_cmd_vlan_id) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_vlan_id_0, sizeof(dev_cmd_vlan_id_0)); + EXPECT_EQ(len, sizeof(dev_cmd_vlan_id_0)); + + len = write(self->dev_fd, dev_cmd_vlan_p_0, sizeof(dev_cmd_vlan_p_0)); + EXPECT_EQ(len, sizeof(dev_cmd_vlan_p_0)); + + len = write(self->dev_fd, dev_cmd_vlan_cfi_0, sizeof(dev_cmd_vlan_cfi_0)); + EXPECT_EQ(len, sizeof(dev_cmd_vlan_cfi_0)); + + len = write(self->dev_fd, dev_cmd_vlan_id_1, sizeof(dev_cmd_vlan_id_1)); + EXPECT_EQ(len, sizeof(dev_cmd_vlan_id_1)); +} + +TEST_F(proc_net_pktgen, dev_cmd_svlan_id) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_svlan_id_0, sizeof(dev_cmd_svlan_id_0)); + EXPECT_EQ(len, sizeof(dev_cmd_svlan_id_0)); + + len = write(self->dev_fd, dev_cmd_svlan_p_0, sizeof(dev_cmd_svlan_p_0)); + EXPECT_EQ(len, sizeof(dev_cmd_svlan_p_0)); + + len = write(self->dev_fd, dev_cmd_svlan_cfi_0, sizeof(dev_cmd_svlan_cfi_0)); + EXPECT_EQ(len, sizeof(dev_cmd_svlan_cfi_0)); + + len = write(self->dev_fd, dev_cmd_svlan_id_1, sizeof(dev_cmd_svlan_id_1)); + EXPECT_EQ(len, sizeof(dev_cmd_svlan_id_1)); +} + + +TEST_F(proc_net_pktgen, dev_cmd_tos) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_tos_0, sizeof(dev_cmd_tos_0)); + EXPECT_EQ(len, sizeof(dev_cmd_tos_0)); + + len = write(self->dev_fd, dev_cmd_tos_1, sizeof(dev_cmd_tos_1)); + EXPECT_EQ(len, sizeof(dev_cmd_tos_1)); + + len = write(self->dev_fd, dev_cmd_tos_2, sizeof(dev_cmd_tos_2)); + EXPECT_EQ(len, sizeof(dev_cmd_tos_2)); +} + + +TEST_F(proc_net_pktgen, dev_cmd_traffic_class) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_traffic_class_0, sizeof(dev_cmd_traffic_class_0)); + EXPECT_EQ(len, sizeof(dev_cmd_traffic_class_0)); +} + +TEST_F(proc_net_pktgen, dev_cmd_skb_priority) { + ssize_t len; + + len = write(self->dev_fd, dev_cmd_skb_priority_0, sizeof(dev_cmd_skb_priority_0)); + EXPECT_EQ(len, sizeof(dev_cmd_skb_priority_0)); +} + +TEST_HARNESS_MAIN