| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * VMware vSockets Driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2007-2013 VMware, Inc. All rights reserved. |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 7 | | - * under the terms of the GNU General Public License as published by the Free |
|---|
| 8 | | - * Software Foundation version 2 and no later version. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 11 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 12 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 13 | | - * more details. |
|---|
| 14 | 6 | */ |
|---|
| 15 | 7 | |
|---|
| 16 | 8 | #ifndef __AF_VSOCK_H__ |
|---|
| .. | .. |
|---|
| 18 | 10 | |
|---|
| 19 | 11 | #include <linux/kernel.h> |
|---|
| 20 | 12 | #include <linux/workqueue.h> |
|---|
| 21 | | -#include <linux/vm_sockets.h> |
|---|
| 13 | +#include <uapi/linux/vm_sockets.h> |
|---|
| 22 | 14 | |
|---|
| 23 | 15 | #include "vsock_addr.h" |
|---|
| 24 | 16 | |
|---|
| .. | .. |
|---|
| 35 | 27 | struct vsock_sock { |
|---|
| 36 | 28 | /* sk must be the first member. */ |
|---|
| 37 | 29 | struct sock sk; |
|---|
| 30 | + const struct vsock_transport *transport; |
|---|
| 38 | 31 | struct sockaddr_vm local_addr; |
|---|
| 39 | 32 | struct sockaddr_vm remote_addr; |
|---|
| 40 | 33 | /* Links for the global tables of bound and connected sockets. */ |
|---|
| .. | .. |
|---|
| 72 | 65 | bool sent_request; |
|---|
| 73 | 66 | bool ignore_connecting_rst; |
|---|
| 74 | 67 | |
|---|
| 68 | + /* Protected by lock_sock(sk) */ |
|---|
| 69 | + u64 buffer_size; |
|---|
| 70 | + u64 buffer_min_size; |
|---|
| 71 | + u64 buffer_max_size; |
|---|
| 72 | + |
|---|
| 75 | 73 | /* Private to transport. */ |
|---|
| 76 | 74 | void *trans; |
|---|
| 77 | 75 | }; |
|---|
| 78 | 76 | |
|---|
| 79 | 77 | s64 vsock_stream_has_data(struct vsock_sock *vsk); |
|---|
| 80 | 78 | s64 vsock_stream_has_space(struct vsock_sock *vsk); |
|---|
| 81 | | -struct sock *__vsock_create(struct net *net, |
|---|
| 82 | | - struct socket *sock, |
|---|
| 83 | | - struct sock *parent, |
|---|
| 84 | | - gfp_t priority, unsigned short type, int kern); |
|---|
| 79 | +struct sock *vsock_create_connected(struct sock *parent); |
|---|
| 85 | 80 | |
|---|
| 86 | 81 | /**** TRANSPORT ****/ |
|---|
| 87 | 82 | |
|---|
| .. | .. |
|---|
| 96 | 91 | u64 data2; /* Transport-defined. */ |
|---|
| 97 | 92 | }; |
|---|
| 98 | 93 | |
|---|
| 94 | +/* Transport features flags */ |
|---|
| 95 | +/* Transport provides host->guest communication */ |
|---|
| 96 | +#define VSOCK_TRANSPORT_F_H2G 0x00000001 |
|---|
| 97 | +/* Transport provides guest->host communication */ |
|---|
| 98 | +#define VSOCK_TRANSPORT_F_G2H 0x00000002 |
|---|
| 99 | +/* Transport provides DGRAM communication */ |
|---|
| 100 | +#define VSOCK_TRANSPORT_F_DGRAM 0x00000004 |
|---|
| 101 | +/* Transport provides local (loopback) communication */ |
|---|
| 102 | +#define VSOCK_TRANSPORT_F_LOCAL 0x00000008 |
|---|
| 103 | + |
|---|
| 99 | 104 | struct vsock_transport { |
|---|
| 105 | + struct module *module; |
|---|
| 106 | + |
|---|
| 100 | 107 | /* Initialize/tear-down socket. */ |
|---|
| 101 | 108 | int (*init)(struct vsock_sock *, struct vsock_sock *); |
|---|
| 102 | 109 | void (*destruct)(struct vsock_sock *); |
|---|
| .. | .. |
|---|
| 147 | 154 | struct vsock_transport_send_notify_data *); |
|---|
| 148 | 155 | int (*notify_send_post_enqueue)(struct vsock_sock *, ssize_t, |
|---|
| 149 | 156 | struct vsock_transport_send_notify_data *); |
|---|
| 157 | + /* sk_lock held by the caller */ |
|---|
| 158 | + void (*notify_buffer_size)(struct vsock_sock *, u64 *); |
|---|
| 150 | 159 | |
|---|
| 151 | 160 | /* Shutdown. */ |
|---|
| 152 | 161 | int (*shutdown)(struct vsock_sock *, int); |
|---|
| 153 | | - |
|---|
| 154 | | - /* Buffer sizes. */ |
|---|
| 155 | | - void (*set_buffer_size)(struct vsock_sock *, u64); |
|---|
| 156 | | - void (*set_min_buffer_size)(struct vsock_sock *, u64); |
|---|
| 157 | | - void (*set_max_buffer_size)(struct vsock_sock *, u64); |
|---|
| 158 | | - u64 (*get_buffer_size)(struct vsock_sock *); |
|---|
| 159 | | - u64 (*get_min_buffer_size)(struct vsock_sock *); |
|---|
| 160 | | - u64 (*get_max_buffer_size)(struct vsock_sock *); |
|---|
| 161 | 162 | |
|---|
| 162 | 163 | /* Addressing. */ |
|---|
| 163 | 164 | u32 (*get_local_cid)(void); |
|---|
| .. | .. |
|---|
| 165 | 166 | |
|---|
| 166 | 167 | /**** CORE ****/ |
|---|
| 167 | 168 | |
|---|
| 168 | | -int __vsock_core_init(const struct vsock_transport *t, struct module *owner); |
|---|
| 169 | | -static inline int vsock_core_init(const struct vsock_transport *t) |
|---|
| 170 | | -{ |
|---|
| 171 | | - return __vsock_core_init(t, THIS_MODULE); |
|---|
| 172 | | -} |
|---|
| 173 | | -void vsock_core_exit(void); |
|---|
| 169 | +int vsock_core_register(const struct vsock_transport *t, int features); |
|---|
| 170 | +void vsock_core_unregister(const struct vsock_transport *t); |
|---|
| 174 | 171 | |
|---|
| 175 | 172 | /* The transport may downcast this to access transport-specific functions */ |
|---|
| 176 | | -const struct vsock_transport *vsock_core_get_transport(void); |
|---|
| 173 | +const struct vsock_transport *vsock_core_get_transport(struct vsock_sock *vsk); |
|---|
| 177 | 174 | |
|---|
| 178 | 175 | /**** UTILS ****/ |
|---|
| 179 | 176 | |
|---|
| .. | .. |
|---|
| 201 | 198 | struct sockaddr_vm *dst); |
|---|
| 202 | 199 | void vsock_remove_sock(struct vsock_sock *vsk); |
|---|
| 203 | 200 | void vsock_for_each_connected_socket(void (*fn)(struct sock *sk)); |
|---|
| 201 | +int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk); |
|---|
| 202 | +bool vsock_find_cid(unsigned int cid); |
|---|
| 204 | 203 | |
|---|
| 205 | 204 | /**** TAP ****/ |
|---|
| 206 | 205 | |
|---|