This file is indexed.

/usr/src/open-vm-tools-10.0.7/vsock/linux/vsockPacket.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
/*********************************************************
 * Copyright (C) 2007-2012 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
 *
 *********************************************************/

/*
 * vsockPacket.h --
 *
 *    Packet constants, types and functions.
 */

#ifndef _VSOCK_PACKET_H_
#define _VSOCK_PACKET_H_

#include "vmci_sockets_packet.h"

#if defined(_WIN32) || defined(VMKERNEL) || defined(__APPLE__) || defined(VMX86_VMX)
# include "vsockOSInt.h"
#else
# define VSockOS_ClearMemory(_dst, _sz)   memset(_dst, 0, _sz)
# define VSockOS_Memcpy(_dst, _src, _sz)  memcpy(_dst, _src, _sz)
#endif

#include "vsockCommon.h"


/*
 *-----------------------------------------------------------------------------
 *
 * VSockPacket_Init --
 *
 *      Initialize the given packet.  The packet version is set and the fields
 *      are filled out.  Reserved fields are cleared.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

static INLINE void
VSockPacket_Init(VSockPacket *pkt,        // OUT
                 struct sockaddr_vm *src, // IN
                 struct sockaddr_vm *dst, // IN
                 uint8 type,              // IN
                 uint64 size,             // IN
                 uint64 mode,             // IN
                 VSockWaitingInfo *wait,  // IN
                 VSockProtoVersion proto, // IN
                 VMCIHandle handle)       // IN
{
   ASSERT(pkt);
   VSOCK_ADDR_NOFAMILY_ASSERT(src);
   VSOCK_ADDR_NOFAMILY_ASSERT(dst);

   /*
    * We register the stream control handler as an any cid handle so we
    * must always send from a source address of VMADDR_CID_ANY
    */
   pkt->dg.src = VMCI_MAKE_HANDLE(VMADDR_CID_ANY, VSOCK_PACKET_LOCAL_RID);
   pkt->dg.dst = VMCI_MAKE_HANDLE(dst->svm_cid,
                                  dst->svm_cid == VMCI_HYPERVISOR_CONTEXT_ID ?
                                  VSOCK_PACKET_HYPERVISOR_RID :
                                  VSOCK_PACKET_RID);
   pkt->dg.payloadSize = sizeof *pkt - sizeof pkt->dg;
   pkt->version = VSOCK_PACKET_VERSION;
   pkt->type = type;
   pkt->srcPort = src->svm_port;
   pkt->dstPort = dst->svm_port;
   VSockOS_ClearMemory(&pkt->proto, sizeof pkt->proto);
   VSockOS_ClearMemory(&pkt->_reserved2, sizeof pkt->_reserved2);

   switch (pkt->type) {
   case VSOCK_PACKET_TYPE_INVALID:
      pkt->u.size = 0;
      break;

   case VSOCK_PACKET_TYPE_REQUEST:
   case VSOCK_PACKET_TYPE_NEGOTIATE:
      pkt->u.size = size;
      break;

   case VSOCK_PACKET_TYPE_OFFER:
   case VSOCK_PACKET_TYPE_ATTACH:
      pkt->u.handle = handle;
      break;

   case VSOCK_PACKET_TYPE_WROTE:
   case VSOCK_PACKET_TYPE_READ:
   case VSOCK_PACKET_TYPE_RST:
      pkt->u.size = 0;
      break;

   case VSOCK_PACKET_TYPE_SHUTDOWN:
      pkt->u.mode = mode;
      break;

   case VSOCK_PACKET_TYPE_WAITING_READ:
   case VSOCK_PACKET_TYPE_WAITING_WRITE:
      ASSERT(wait);
      VSockOS_Memcpy(&pkt->u.wait, wait, sizeof pkt->u.wait);
      break;

   case VSOCK_PACKET_TYPE_REQUEST2:
   case VSOCK_PACKET_TYPE_NEGOTIATE2:
      pkt->u.size = size;
      pkt->proto = proto;
      break;
   }

   VSOCK_PACKET_ASSERT(pkt);
}


/*
 *-----------------------------------------------------------------------------
 *
 * VSockPacket_Validate --
 *
 *      Validate the given packet.
 *
 * Results:
 *      0 on success, EFAULT if the address is invalid, EINVAL if the packet
 *      fields are invalid.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

static INLINE int32
VSockPacket_Validate(VSockPacket *pkt)
{
   int32 err = EINVAL;

   if (NULL == pkt) {
      err = EFAULT;
      goto exit;
   }

   if (VMCI_HANDLE_INVALID(pkt->dg.src)) {
      goto exit;
   }

   if (VMCI_HANDLE_INVALID(pkt->dg.dst)) {
      goto exit;
   }

   if (VMCI_INVALID_ID == pkt->dstPort || VMCI_INVALID_ID == pkt->srcPort) {
      goto exit;
   }

   if (VSOCK_PACKET_VERSION != pkt->version) {
      goto exit;
   }

   /* See the comment above VSOCK_PACKET_ASSERT. */
   if (pkt->type < VSOCK_PACKET_TYPE_REQUEST2) {
      if (0 != pkt->proto || 0 != pkt->_reserved2) {
         goto exit;
      }
   }

   switch (pkt->type) {
   case VSOCK_PACKET_TYPE_INVALID:
      if (0 != pkt->u.size) {
         goto exit;
      }
      break;

   case VSOCK_PACKET_TYPE_REQUEST:
   case VSOCK_PACKET_TYPE_NEGOTIATE:
      if (0 == pkt->u.size) {
         goto exit;
      }
      break;

   case VSOCK_PACKET_TYPE_OFFER:
   case VSOCK_PACKET_TYPE_ATTACH:
      if (VMCI_HANDLE_INVALID(pkt->u.handle)) {
         goto exit;
      }
      break;

   case VSOCK_PACKET_TYPE_WROTE:
   case VSOCK_PACKET_TYPE_READ:
   case VSOCK_PACKET_TYPE_RST:
      if (0 != pkt->u.size) {
         goto exit;
      }
      break;
   }

   err = 0;

exit:
   return sockerr2err(err);
}


/*
 *-----------------------------------------------------------------------------
 *
 * VSockPacket_GetAddresses --
 *
 *      Get the local and remote addresses from the given packet.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

static INLINE void
VSockPacket_GetAddresses(VSockPacket *pkt,           // IN
                         struct sockaddr_vm *local,  // OUT
                         struct sockaddr_vm *remote) // OUT
{
   VSOCK_PACKET_ASSERT(pkt);
   VSockAddr_Init(local, VMCI_HANDLE_TO_CONTEXT_ID(pkt->dg.dst),
                  pkt->dstPort);
   VSockAddr_Init(remote, VMCI_HANDLE_TO_CONTEXT_ID(pkt->dg.src),
                  pkt->srcPort);
}

#endif // _VSOCK_PACKET_H_