]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests: net: add flag to force zerocopy mode in xdp_helper
authorBui Quang Minh <minhquangbui99@gmail.com>
Fri, 25 Apr 2025 07:10:16 +0000 (14:10 +0700)
committerJakub Kicinski <kuba@kernel.org>
Mon, 28 Apr 2025 22:49:10 +0000 (15:49 -0700)
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 <minhquangbui99@gmail.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://patch.msgid.link/20250425071018.36078-3-minhquangbui99@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/lib/xdp_helper.c

index d5bb8ac33efa5f151c1955be4e2d679b0908be85..6327863cafa6d95ea84ae6dc94982d671ead3591 100644 (file)
 #define NUM_DESC (UMEM_SZ / 2048)
 
 
+static void print_usage(const char *bin)
+{
+       fprintf(stderr, "Usage: %s ifindex queue_id [-z]\n\n"
+               "where:\n\t-z: force zerocopy mode", bin);
+}
+
 /* this is a simple helper program that creates an XDP socket and does the
  * minimum necessary to get bind() to succeed.
  *
@@ -36,8 +42,8 @@ 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) {
+               print_usage(argv[0]);
                return 1;
        }
 
@@ -87,6 +93,15 @@ int main(int argc, char **argv)
        sxdp.sxdp_queue_id = queue;
        sxdp.sxdp_flags = 0;
 
+       if (argc > 3) {
+               if (!strcmp(argv[3], "-z")) {
+                       sxdp.sxdp_flags = XDP_ZEROCOPY;
+               } else {
+                       print_usage(argv[0]);
+                       return 1;
+               }
+       }
+
        if (bind(sock_fd, (struct sockaddr *)&sxdp, sizeof(sxdp)) != 0) {
                munmap(umem_area, UMEM_SZ);
                perror("bind failed");