Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a36b38aa authored by Björn Töpel's avatar Björn Töpel Committed by Daniel Borkmann
Browse files

xsk: add sock_diag interface for AF_XDP



This patch adds the sock_diag interface for querying sockets from user
space. Tools like iproute2 ss(8) can use this interface to list open
AF_XDP sockets.

The user-space ABI is defined in linux/xdp_diag.h and includes netlink
request and response structs. The request can query sockets and the
response contains socket information about the rings, umems, inode and
more.

Signed-off-by: default avatarBjörn Töpel <bjorn.topel@intel.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent 50e74c01
Loading
Loading
Loading
Loading
+72 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
 * xdp_diag: interface for query/monitor XDP sockets
 * Copyright(c) 2019 Intel Corporation.
 */

#ifndef _LINUX_XDP_DIAG_H
#define _LINUX_XDP_DIAG_H

#include <linux/types.h>

struct xdp_diag_req {
	__u8	sdiag_family;
	__u8	sdiag_protocol;
	__u16	pad;
	__u32	xdiag_ino;
	__u32	xdiag_show;
	__u32	xdiag_cookie[2];
};

struct xdp_diag_msg {
	__u8	xdiag_family;
	__u8	xdiag_type;
	__u16	pad;
	__u32	xdiag_ino;
	__u32	xdiag_cookie[2];
};

#define XDP_SHOW_INFO		(1 << 0) /* Basic information */
#define XDP_SHOW_RING_CFG	(1 << 1)
#define XDP_SHOW_UMEM		(1 << 2)
#define XDP_SHOW_MEMINFO	(1 << 3)

enum {
	XDP_DIAG_NONE,
	XDP_DIAG_INFO,
	XDP_DIAG_UID,
	XDP_DIAG_RX_RING,
	XDP_DIAG_TX_RING,
	XDP_DIAG_UMEM,
	XDP_DIAG_UMEM_FILL_RING,
	XDP_DIAG_UMEM_COMPLETION_RING,
	XDP_DIAG_MEMINFO,
	__XDP_DIAG_MAX,
};

#define XDP_DIAG_MAX (__XDP_DIAG_MAX - 1)

struct xdp_diag_info {
	__u32	ifindex;
	__u32	queue_id;
};

struct xdp_diag_ring {
	__u32	entries; /*num descs */
};

#define XDP_DU_F_ZEROCOPY (1 << 0)

struct xdp_diag_umem {
	__u64	size;
	__u32	id;
	__u32	num_pages;
	__u32	chunk_size;
	__u32	headroom;
	__u32	ifindex;
	__u32	queue_id;
	__u32	flags;
	__u32	refs;
};

#endif /* _LINUX_XDP_DIAG_H */
+8 −0
Original line number Diff line number Diff line
@@ -5,3 +5,11 @@ config XDP_SOCKETS
	help
	  XDP sockets allows a channel between XDP programs and
	  userspace applications.

config XDP_SOCKETS_DIAG
	tristate "XDP sockets: monitoring interface"
	depends on XDP_SOCKETS
	default n
	help
	  Support for PF_XDP sockets monitoring interface used by the ss tool.
	  If unsure, say Y.
+1 −0
Original line number Diff line number Diff line
obj-$(CONFIG_XDP_SOCKETS) += xsk.o xdp_umem.o xsk_queue.o
obj-$(CONFIG_XDP_SOCKETS_DIAG) += xsk_diag.o
+1 −5
Original line number Diff line number Diff line
@@ -27,14 +27,10 @@

#include "xsk_queue.h"
#include "xdp_umem.h"
#include "xsk.h"

#define TX_BATCH_SIZE 16

static struct xdp_sock *xdp_sk(struct sock *sk)
{
	return (struct xdp_sock *)sk;
}

bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs)
{
	return READ_ONCE(xs->rx) &&  READ_ONCE(xs->umem) &&

net/xdp/xsk.h

0 → 100644
+12 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright(c) 2019 Intel Corporation. */

#ifndef XSK_H_
#define XSK_H_

static inline struct xdp_sock *xdp_sk(struct sock *sk)
{
	return (struct xdp_sock *)sk;
}

#endif /* XSK_H_ */
Loading