130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* 230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * VMware vSockets Driver 330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Copyright (C) 2007-2013 VMware, Inc. All rights reserved. 530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * This program is free software; you can redistribute it and/or modify it 730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * under the terms of the GNU General Public License as published by the Free 830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Software Foundation version 2 and no later version. 930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 1030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * This program is distributed in the hope that it will be useful, but WITHOUT 1130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 1330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * more details. 1430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 1530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 1630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#ifndef _UAPI_VM_SOCKETS_H 1730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define _UAPI_VM_SOCKETS_H 1830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 1930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#include <linux/socket.h> 2030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 2130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Option name for STREAM socket buffer size. Use as the option name in 2230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * setsockopt(3) or getsockopt(3) to set or get an unsigned long long that 2330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * specifies the size of the buffer underlying a vSockets STREAM socket. 2430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Value is clamped to the MIN and MAX. 2530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 2630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 2730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SO_VM_SOCKETS_BUFFER_SIZE 0 2830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 2930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Option name for STREAM socket minimum buffer size. Use as the option name 3030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * in setsockopt(3) or getsockopt(3) to set or get an unsigned long long that 3130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * specifies the minimum size allowed for the buffer underlying a vSockets 3230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * STREAM socket. 3330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 3430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 3530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SO_VM_SOCKETS_BUFFER_MIN_SIZE 1 3630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 3730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Option name for STREAM socket maximum buffer size. Use as the option name 3830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * in setsockopt(3) or getsockopt(3) to set or get an unsigned long long 3930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * that specifies the maximum size allowed for the buffer underlying a 4030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * vSockets STREAM socket. 4130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 4230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 4330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SO_VM_SOCKETS_BUFFER_MAX_SIZE 2 4430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 4530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Option name for socket peer's host-specific VM ID. Use as the option name 4630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * in getsockopt(3) to get a host-specific identifier for the peer endpoint's 4730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * VM. The identifier is a signed integer. 4830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Only available for hypervisor endpoints. 4930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 5030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 5130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SO_VM_SOCKETS_PEER_HOST_VM_ID 3 5230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 5330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Option name for determining if a socket is trusted. Use as the option name 5430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * in getsockopt(3) to determine if a socket is trusted. The value is a 5530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * signed integer. 5630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 5730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 5830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SO_VM_SOCKETS_TRUSTED 5 5930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 6030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Option name for STREAM socket connection timeout. Use as the option name 6130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * in setsockopt(3) or getsockopt(3) to set or get the connection 6230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * timeout for a STREAM socket. 6330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 6430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 6530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SO_VM_SOCKETS_CONNECT_TIMEOUT 6 6630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 6730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Option name for using non-blocking send/receive. Use as the option name 6830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * for setsockopt(3) or getsockopt(3) to set or get the non-blocking 6930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * transmit/receive flag for a STREAM socket. This flag determines whether 7030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * send() and recv() can be called in non-blocking contexts for the given 7130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * socket. The value is a signed integer. 7230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 7330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * This option is only relevant to kernel endpoints, where descheduling the 7430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * thread of execution is not allowed, for example, while holding a spinlock. 7530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * It is not to be confused with conventional non-blocking socket operations. 7630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 7730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Only available for hypervisor endpoints. 7830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 7930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 8030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SO_VM_SOCKETS_NONBLOCK_TXRX 7 8130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 8230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* The vSocket equivalent of INADDR_ANY. This works for the svm_cid field of 8330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * sockaddr_vm and indicates the context ID of the current endpoint. 8430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 8530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 8630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define VMADDR_CID_ANY -1U 8730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 8830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Bind to any available port. Works for the svm_port field of 8930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * sockaddr_vm. 9030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 9130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 9230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define VMADDR_PORT_ANY -1U 9330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 9430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Use this as the destination CID in an address when referring to the 9530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * hypervisor. VMCI relies on it being 0, but this would be useful for other 9630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * transports too. 9730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 9830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 9930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define VMADDR_CID_HYPERVISOR 0 10030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 10130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* This CID is specific to VMCI and can be considered reserved (even VMCI 10230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * doesn't use it anymore, it's a legacy value from an older release). 10330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 10430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 10530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define VMADDR_CID_RESERVED 1 10630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 10730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Use this as the destination CID in an address when referring to the host 10830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * (any process other than the hypervisor). VMCI relies on it being 2, but 10930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * this would be useful for other transports too. 11030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 11130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 11230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define VMADDR_CID_HOST 2 11330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 11430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Invalid vSockets version. */ 11530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 11630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define VM_SOCKETS_INVALID_VERSION -1U 11730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 11830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* The epoch (first) component of the vSockets version. A single byte 11930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * representing the epoch component of the vSockets version. 12030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 12130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 12230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define VM_SOCKETS_VERSION_EPOCH(_v) (((_v) & 0xFF000000) >> 24) 12330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 12430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* The major (second) component of the vSockets version. A single byte 12530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * representing the major component of the vSockets version. Typically 12630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * changes for every major release of a product. 12730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 12830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 12930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define VM_SOCKETS_VERSION_MAJOR(_v) (((_v) & 0x00FF0000) >> 16) 13030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 13130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* The minor (third) component of the vSockets version. Two bytes representing 13230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * the minor component of the vSockets version. 13330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 13430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 13530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define VM_SOCKETS_VERSION_MINOR(_v) (((_v) & 0x0000FFFF)) 13630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 13730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Address structure for vSockets. The address family should be set to 13830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * AF_VSOCK. The structure members should all align on their natural 13930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * boundaries without resorting to compiler packing directives. The total size 14030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * of this structure should be exactly the same as that of struct sockaddr. 14130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */ 14230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 14330692c65c4174412c90e79489e98ab85c1a7412fBen Chengstruct sockaddr_vm { 14430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng __kernel_sa_family_t svm_family; 14530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng unsigned short svm_reserved1; 14630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng unsigned int svm_port; 14730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng unsigned int svm_cid; 14830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng unsigned char svm_zero[sizeof(struct sockaddr) - 14930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng sizeof(sa_family_t) - 15030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng sizeof(unsigned short) - 15130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng sizeof(unsigned int) - sizeof(unsigned int)]; 15230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng}; 15330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 15430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define IOCTL_VM_SOCKETS_GET_LOCAL_CID _IO(7, 0xb9) 15530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 15630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#endif /* _UAPI_VM_SOCKETS_H */ 157