This commit adds an optional -z flag to xdp_helper. When this flag is
provided, the XDP socket binding is forced to be in zerocopy mode.

Signed-off-by: Bui Quang Minh <[email protected]>
---
 tools/testing/selftests/net/lib/xdp_helper.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/lib/xdp_helper.c 
b/tools/testing/selftests/net/lib/xdp_helper.c
index aeed25914104..6afd77bfbe8b 100644
--- a/tools/testing/selftests/net/lib/xdp_helper.c
+++ b/tools/testing/selftests/net/lib/xdp_helper.c
@@ -81,8 +81,9 @@ int main(int argc, char **argv)
        int sock_fd;
        int queue;
 
-       if (argc != 3) {
-               fprintf(stderr, "Usage: %s ifindex queue_id\n", argv[0]);
+       if (argc != 3 && argc != 4) {
+               fprintf(stderr, "Usage: %s ifindex queue_id [-z]\n\n"
+                       "where:\n\t-z: force zerocopy mode", argv[0]);
                return 1;
        }
 
@@ -132,6 +133,14 @@ int main(int argc, char **argv)
        sxdp.sxdp_queue_id = queue;
        sxdp.sxdp_flags = 0;
 
+       if (argc == 4 && strcmp(argv[3], "-z")) {
+               fprintf(stderr, "Usage: %s ifindex queue_id [-z]\n\n"
+                       "where:\n\t-z: force zerocopy mode\n", argv[0]);
+               return 1;
+       } else if (argc == 4) {
+               sxdp.sxdp_flags = XDP_ZEROCOPY;
+       }
+
        if (bind(sock_fd, (struct sockaddr *)&sxdp, sizeof(sxdp)) != 0) {
                munmap(umem_area, UMEM_SZ);
                perror("bind failed");
-- 
2.43.0


Reply via email to