]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
xsk: Add getsockopt XDP_OPTIONS
authorMaxim Mikityanskiy <maximmi@mellanox.com>
Wed, 26 Jun 2019 14:35:25 +0000 (17:35 +0300)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 27 Jun 2019 20:53:26 +0000 (22:53 +0200)
Make it possible for the application to determine whether the AF_XDP
socket is running in zero-copy mode. To achieve this, add a new
getsockopt option XDP_OPTIONS that returns flags. The only flag
supported for now is the zero-copy mode indicator.

Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com>
Signed-off-by: Tariq Toukan <tariqt@mellanox.com>
Acked-by: Saeed Mahameed <saeedm@mellanox.com>
Acked-by: Björn Töpel <bjorn.topel@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
include/uapi/linux/if_xdp.h
net/xdp/xsk.c
tools/include/uapi/linux/if_xdp.h

index caed8b1614ffc0aae5e43ffca0c403a0c7b9401f..faaa5ca2a11767a3cfd967661f21645799b95f9c 100644 (file)
@@ -46,6 +46,7 @@ struct xdp_mmap_offsets {
 #define XDP_UMEM_FILL_RING             5
 #define XDP_UMEM_COMPLETION_RING       6
 #define XDP_STATISTICS                 7
+#define XDP_OPTIONS                    8
 
 struct xdp_umem_reg {
        __u64 addr; /* Start of packet data area */
@@ -60,6 +61,13 @@ struct xdp_statistics {
        __u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
 };
 
+struct xdp_options {
+       __u32 flags;
+};
+
+/* Flags for the flags field of struct xdp_options */
+#define XDP_OPTIONS_ZEROCOPY (1 << 0)
+
 /* Pgoff for mmaping the rings */
 #define XDP_PGOFF_RX_RING                        0
 #define XDP_PGOFF_TX_RING               0x80000000
index b68a380f50b373520fdd06f560149f9702477a93..35ca531ac74e65664e00c3802dc31ad786b8a11f 100644 (file)
@@ -650,6 +650,26 @@ static int xsk_getsockopt(struct socket *sock, int level, int optname,
 
                return 0;
        }
+       case XDP_OPTIONS:
+       {
+               struct xdp_options opts = {};
+
+               if (len < sizeof(opts))
+                       return -EINVAL;
+
+               mutex_lock(&xs->mutex);
+               if (xs->zc)
+                       opts.flags |= XDP_OPTIONS_ZEROCOPY;
+               mutex_unlock(&xs->mutex);
+
+               len = sizeof(opts);
+               if (copy_to_user(optval, &opts, len))
+                       return -EFAULT;
+               if (put_user(len, optlen))
+                       return -EFAULT;
+
+               return 0;
+       }
        default:
                break;
        }
index caed8b1614ffc0aae5e43ffca0c403a0c7b9401f..faaa5ca2a11767a3cfd967661f21645799b95f9c 100644 (file)
@@ -46,6 +46,7 @@ struct xdp_mmap_offsets {
 #define XDP_UMEM_FILL_RING             5
 #define XDP_UMEM_COMPLETION_RING       6
 #define XDP_STATISTICS                 7
+#define XDP_OPTIONS                    8
 
 struct xdp_umem_reg {
        __u64 addr; /* Start of packet data area */
@@ -60,6 +61,13 @@ struct xdp_statistics {
        __u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
 };
 
+struct xdp_options {
+       __u32 flags;
+};
+
+/* Flags for the flags field of struct xdp_options */
+#define XDP_OPTIONS_ZEROCOPY (1 << 0)
+
 /* Pgoff for mmaping the rings */
 #define XDP_PGOFF_RX_RING                        0
 #define XDP_PGOFF_TX_RING               0x80000000