/usr/src/open-vm-tools-10.0.7/vsock/linux/util.h is in open-vm-tools-dkms 2:10.0.7-3227872-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | /*********************************************************
* Copyright (C) 2007 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*********************************************************/
/*
* util.h --
*
* Utility functions for Linux VSocket module.
*/
#ifndef __UTIL_H__
#define __UTIL_H__
#include "driver-config.h"
#include "compat_sock.h"
#include "compat_spinlock.h"
#include "vsockCommon.h"
#include "vsockPacket.h"
/*
* Each bound VSocket is stored in the bind hash table and each connected
* VSocket is stored in the connected hash table.
*
* Unbound sockets are all put on the same list attached to the end of the hash
* table (vsockUnboundSockets). Bound sockets are added to the hash table in
* the bucket that their local address hashes to (vsockBoundSockets(addr)
* represents the list that addr hashes to).
*
* Specifically, we initialize the vsockBindTable array to a size of
* VSOCK_HASH_SIZE + 1 so that vsockBindTable[0] through
* vsockBindTable[VSOCK_HASH_SIZE - 1] are for bound sockets and
* vsockBindTable[VSOCK_HASH_SIZE] is for unbound sockets. The hash function
* mods with VSOCK_HASH_SIZE - 1 to ensure this.
*/
#define VSOCK_HASH_SIZE 251
#define LAST_RESERVED_PORT 1023
#define MAX_PORT_RETRIES 24
extern struct list_head vsockBindTable[VSOCK_HASH_SIZE + 1];
extern struct list_head vsockConnectedTable[VSOCK_HASH_SIZE];
extern spinlock_t vsockTableLock;
#define VSOCK_HASH(addr) ((addr)->svm_port % (VSOCK_HASH_SIZE - 1))
#define vsockBoundSockets(addr) (&vsockBindTable[VSOCK_HASH(addr)])
#define vsockUnboundSockets (&vsockBindTable[VSOCK_HASH_SIZE])
/* XXX This can probably be implemented in a better way. */
#define VSOCK_CONN_HASH(src, dst) \
(((src)->svm_cid ^ (dst)->svm_port) % (VSOCK_HASH_SIZE - 1))
#define vsockConnectedSockets(src, dst) \
(&vsockConnectedTable[VSOCK_CONN_HASH(src, dst)])
#define vsockConnectedSocketsVsk(vsk) \
vsockConnectedSockets(&(vsk)->remoteAddr, &(vsk)->localAddr)
/*
* Prototypes.
*/
void VSockVmciLogPkt(char const *function, uint32 line, VSockPacket *pkt);
void VSockVmciInitTables(void);
void __VSockVmciInsertBound(struct list_head *list, struct sock *sk);
void __VSockVmciInsertConnected(struct list_head *list, struct sock *sk);
void __VSockVmciRemoveBound(struct sock *sk);
void __VSockVmciRemoveConnected(struct sock *sk);
struct sock *__VSockVmciFindBoundSocket(struct sockaddr_vm *addr);
struct sock *__VSockVmciFindConnectedSocket(struct sockaddr_vm *src,
struct sockaddr_vm *dst);
Bool __VSockVmciInBoundTable(struct sock *sk);
Bool __VSockVmciInConnectedTable(struct sock *sk);
struct sock *VSockVmciGetPending(struct sock *listener, VSockPacket *pkt);
void VSockVmciReleasePending(struct sock *pending);
void VSockVmciAddPending(struct sock *listener, struct sock *pending);
void VSockVmciRemovePending(struct sock *listener, struct sock *pending);
void VSockVmciEnqueueAccept(struct sock *listener, struct sock *connected);
struct sock *VSockVmciDequeueAccept(struct sock *listener);
void VSockVmciRemoveAccept(struct sock *listener, struct sock *connected);
Bool VSockVmciInAcceptQueue(struct sock *sk);
Bool VSockVmciIsAcceptQueueEmpty(struct sock *sk);
Bool VSockVmciIsPending(struct sock *sk);
static INLINE void VSockVmciInsertBound(struct list_head *list, struct sock *sk);
static INLINE void VSockVmciInsertConnected(struct list_head *list, struct sock *sk);
static INLINE void VSockVmciRemoveBound(struct sock *sk);
static INLINE void VSockVmciRemoveConnected(struct sock *sk);
static INLINE struct sock *VSockVmciFindBoundSocket(struct sockaddr_vm *addr);
static INLINE struct sock *VSockVmciFindConnectedSocket(struct sockaddr_vm *src,
struct sockaddr_vm *dst);
static INLINE Bool VSockVmciInBoundTable(struct sock *sk);
static INLINE Bool VSockVmciInConnectedTable(struct sock *sk);
/*
*----------------------------------------------------------------------------
*
* VSockVmciInsertBound --
*
* Inserts socket into the bound table.
*
* Note that it is important to invoke the bottom-half versions of the
* spinlock functions since these may be called from tasklets.
*
* Results:
* None.
*
* Side effects:
* vsockTableLock is acquired and released.
*
*----------------------------------------------------------------------------
*/
static INLINE void
VSockVmciInsertBound(struct list_head *list, // IN
struct sock *sk) // IN
{
ASSERT(list);
ASSERT(sk);
spin_lock_bh(&vsockTableLock);
__VSockVmciInsertBound(list, sk);
spin_unlock_bh(&vsockTableLock);
}
/*
*----------------------------------------------------------------------------
*
* VSockVmciInsertConnected --
*
* Inserts socket into the connected table.
*
* Note that it is important to invoke the bottom-half versions of the
* spinlock functions since these may be called from tasklets.
*
* Results:
* None.
*
* Side effects:
* vsockTableLock is acquired and released.
*
*----------------------------------------------------------------------------
*/
static INLINE void
VSockVmciInsertConnected(struct list_head *list, // IN
struct sock *sk) // IN
{
ASSERT(list);
ASSERT(sk);
spin_lock_bh(&vsockTableLock);
__VSockVmciInsertConnected(list, sk);
spin_unlock_bh(&vsockTableLock);
}
/*
*----------------------------------------------------------------------------
*
* VSockVmciRemoveBound --
*
* Removes socket from the bound list.
*
* Note that it is important to invoke the bottom-half versions of the
* spinlock functions since these may be called from tasklets.
*
* Results:
* None.
*
* Side effects:
* vsockTableLock is acquired and released.
*
*----------------------------------------------------------------------------
*/
static INLINE void
VSockVmciRemoveBound(struct sock *sk) // IN
{
ASSERT(sk);
spin_lock_bh(&vsockTableLock);
__VSockVmciRemoveBound(sk);
spin_unlock_bh(&vsockTableLock);
}
/*
*----------------------------------------------------------------------------
*
* VSockVmciRemoveConnected --
*
* Removes socket from the connected list.
*
* Note that it is important to invoke the bottom-half versions of the
* spinlock functions since these may be called from tasklets.
*
* Results:
* None.
*
* Side effects:
* vsockTableLock is acquired and released.
*
*----------------------------------------------------------------------------
*/
static INLINE void
VSockVmciRemoveConnected(struct sock *sk) // IN
{
ASSERT(sk);
spin_lock_bh(&vsockTableLock);
__VSockVmciRemoveConnected(sk);
spin_unlock_bh(&vsockTableLock);
}
/*
*----------------------------------------------------------------------------
*
* VSockVmciFindBoundSocket --
*
* Finds the socket corresponding to the provided address in the bound
* sockets hash table.
*
* Note that it is important to invoke the bottom-half versions of the
* spinlock functions since these are called from tasklets.
*
* Results:
* The sock structure if found, NULL on failure.
*
* Side effects:
* vsockTableLock is acquired and released.
* The socket's reference count is increased.
*
*----------------------------------------------------------------------------
*/
static INLINE struct sock *
VSockVmciFindBoundSocket(struct sockaddr_vm *addr) // IN
{
struct sock *sk;
ASSERT(addr);
spin_lock_bh(&vsockTableLock);
sk = __VSockVmciFindBoundSocket(addr);
if (sk) {
sock_hold(sk);
}
spin_unlock_bh(&vsockTableLock);
return sk;
}
/*
*----------------------------------------------------------------------------
*
* VSockVmciFindConnectedSocket --
*
* Finds the socket corresponding to the provided address in the connected
* sockets hash table.
*
* Note that it is important to invoke the bottom-half versions of the
* spinlock functions since these are called from tasklets.
*
* Results:
* The sock structure if found, NULL on failure.
*
* Side effects:
* vsockTableLock is acquired and released.
* The socket's reference count is increased.
*
*----------------------------------------------------------------------------
*/
static INLINE struct sock *
VSockVmciFindConnectedSocket(struct sockaddr_vm *src, // IN
struct sockaddr_vm *dst) // IN
{
struct sock *sk;
ASSERT(src);
ASSERT(dst);
spin_lock_bh(&vsockTableLock);
sk = __VSockVmciFindConnectedSocket(src, dst);
if (sk) {
sock_hold(sk);
}
spin_unlock_bh(&vsockTableLock);
return sk;
}
/*
*----------------------------------------------------------------------------
*
* VSockVmciInBoundTable --
*
* Determines whether the provided socket is in the bound table.
*
* Note that it is important to invoke the bottom-half versions of the
* spinlock functions since these may be called from tasklets.
*
* Results:
* TRUE is socket is in bound table, FALSE otherwise.
*
* Side effects:
* vsockTableLock is acquired and released.
*
*----------------------------------------------------------------------------
*/
static INLINE Bool
VSockVmciInBoundTable(struct sock *sk) // IN
{
Bool ret;
ASSERT(sk);
spin_lock_bh(&vsockTableLock);
ret = __VSockVmciInBoundTable(sk);
spin_unlock_bh(&vsockTableLock);
return ret;
}
/*
*----------------------------------------------------------------------------
*
* VSockVmciInConnectedTable --
*
* Determines whether the provided socket is in the connected table.
*
* Note that it is important to invoke the bottom-half versions of the
* spinlock functions since these may be called from tasklets.
*
* Results:
* TRUE is socket is in connected table, FALSE otherwise.
*
* Side effects:
* vsockTableLock is acquired and released.
*
*----------------------------------------------------------------------------
*/
static INLINE Bool
VSockVmciInConnectedTable(struct sock *sk) // IN
{
Bool ret;
ASSERT(sk);
spin_lock_bh(&vsockTableLock);
ret = __VSockVmciInConnectedTable(sk);
spin_unlock_bh(&vsockTableLock);
return ret;
}
#endif /* __UTIL_H__ */
|