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

Commit 5820299a authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'VSOCK-sock_diag'



Stefan Hajnoczi says:

====================
VSOCK: add sock_diag interface

v3:
 * Rebased onto net-next/master and resolved Hyper-V transport conflict

v2:
 * Moved tests to tools/testing/vsock/.  I was unable to put them in selftests/
   because they require manual setup of a VMware/KVM guest.
 * Moved to __vsock_in_bound/connected_table() to af_vsock.h
 * Fixed local variable ordering in Patch 4

There is currently no way for userspace to query open AF_VSOCK sockets.  This
means ss(8), netstat(8), and other utilities cannot display AF_VSOCK sockets.

This patch series adds the netlink sock_diag interface for AF_VSOCK.  Userspace
programs sent a DUMP request including an sk_state bitmap to filter sockets
based on their state (connected, listening, etc).  The vsock_diag.ko module
replies with information about matching sockets.  This userspace ABI is defined
in <linux/vm_sockets_diag.h>.

The final patch adds a test suite that exercises the basic cases.

Jorgen and Dexuan: I have only tested the virtio transport but this should also
work for VMCI and Hyper-V.  Please give it a shot if you have time.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 53954cf8 0b025033
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -14286,12 +14286,15 @@ S: Maintained
F:	include/linux/virtio_vsock.h
F:	include/uapi/linux/virtio_vsock.h
F:	include/uapi/linux/vsockmon.h
F:	include/uapi/linux/vm_sockets_diag.h
F:	net/vmw_vsock/diag.c
F:	net/vmw_vsock/af_vsock_tap.c
F:	net/vmw_vsock/virtio_transport_common.c
F:	net/vmw_vsock/virtio_transport.c
F:	drivers/net/vsockmon.c
F:	drivers/vhost/vsock.c
F:	drivers/vhost/vsock.h
F:	tools/testing/vsock/

VIRTIO CONSOLE DRIVER
M:	Amit Shah <amit@kernel.org>
+17 −3
Original line number Diff line number Diff line
@@ -22,11 +22,13 @@

#include "vsock_addr.h"

/* vsock-specific sock->sk_state constants */
#define VSOCK_SS_LISTEN 255

#define LAST_RESERVED_PORT 1023

#define VSOCK_HASH_SIZE         251
extern struct list_head vsock_bind_table[VSOCK_HASH_SIZE + 1];
extern struct list_head vsock_connected_table[VSOCK_HASH_SIZE];
extern spinlock_t vsock_table_lock;

#define vsock_sk(__sk)    ((struct vsock_sock *)__sk)
#define sk_vsock(__vsk)   (&(__vsk)->sk)

@@ -175,6 +177,18 @@ const struct vsock_transport *vsock_core_get_transport(void);

/**** UTILS ****/

/* vsock_table_lock must be held */
static inline bool __vsock_in_bound_table(struct vsock_sock *vsk)
{
	return !list_empty(&vsk->bound_table);
}

/* vsock_table_lock must be held */
static inline bool __vsock_in_connected_table(struct vsock_sock *vsk)
{
	return !list_empty(&vsk->connected_table);
}

void vsock_release_pending(struct sock *pending);
void vsock_add_pending(struct sock *listener, struct sock *pending);
void vsock_remove_pending(struct sock *listener, struct sock *pending);
+33 −0
Original line number Diff line number Diff line
/* AF_VSOCK sock_diag(7) interface for querying open sockets */

#ifndef _UAPI__VM_SOCKETS_DIAG_H__
#define _UAPI__VM_SOCKETS_DIAG_H__

#include <linux/types.h>

/* Request */
struct vsock_diag_req {
	__u8	sdiag_family;	/* must be AF_VSOCK */
	__u8	sdiag_protocol;	/* must be 0 */
	__u16	pad;		/* must be 0 */
	__u32	vdiag_states;	/* query bitmap (e.g. 1 << TCP_LISTEN) */
	__u32	vdiag_ino;	/* must be 0 (reserved) */
	__u32	vdiag_show;	/* must be 0 (reserved) */
	__u32	vdiag_cookie[2];
};

/* Response */
struct vsock_diag_msg {
	__u8	vdiag_family;	/* AF_VSOCK */
	__u8	vdiag_type;	/* SOCK_STREAM or SOCK_DGRAM */
	__u8	vdiag_state;	/* sk_state (e.g. TCP_LISTEN) */
	__u8	vdiag_shutdown; /* local RCV_SHUTDOWN | SEND_SHUTDOWN */
	__u32   vdiag_src_cid;
	__u32   vdiag_src_port;
	__u32   vdiag_dst_cid;
	__u32   vdiag_dst_port;
	__u32	vdiag_ino;
	__u32	vdiag_cookie[2];
};

#endif /* _UAPI__VM_SOCKETS_DIAG_H__ */
+10 −0
Original line number Diff line number Diff line
@@ -15,6 +15,16 @@ config VSOCKETS
	  To compile this driver as a module, choose M here: the module
	  will be called vsock. If unsure, say N.

config VSOCKETS_DIAG
	tristate "Virtual Sockets monitoring interface"
	depends on VSOCKETS
	default y
	help
	  Support for PF_VSOCK sockets monitoring interface used by the ss tool.
	  If unsure, say Y.

	  Enable this module so userspace applications can query open sockets.

config VMWARE_VMCI_VSOCKETS
	tristate "VMware VMCI transport for Virtual Sockets"
	depends on VSOCKETS && VMWARE_VMCI
+3 −0
Original line number Diff line number Diff line
obj-$(CONFIG_VSOCKETS) += vsock.o
obj-$(CONFIG_VSOCKETS_DIAG) += vsock_diag.o
obj-$(CONFIG_VMWARE_VMCI_VSOCKETS) += vmw_vsock_vmci_transport.o
obj-$(CONFIG_VIRTIO_VSOCKETS) += vmw_vsock_virtio_transport.o
obj-$(CONFIG_VIRTIO_VSOCKETS_COMMON) += vmw_vsock_virtio_transport_common.o
@@ -6,6 +7,8 @@ obj-$(CONFIG_HYPERV_VSOCKETS) += hv_sock.o

vsock-y += af_vsock.o af_vsock_tap.o vsock_addr.o

vsock_diag-y += diag.o

vmw_vsock_vmci_transport-y += vmci_transport.o vmci_transport_notify.o \
	vmci_transport_notify_qstate.o

Loading