- Timestamp:
- Oct 12, 2007 11:21:09 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/intnet.h
r4071 r5283 20 20 #include <VBox/types.h> 21 21 #include <VBox/stam.h> 22 #include <VBox/sup.h> 22 23 #include <iprt/assert.h> 23 24 #include <iprt/asm.h> … … 25 26 __BEGIN_DECLS 26 27 28 29 /** Pointer to an internal network ring-0 instance. */ 30 typedef struct INTNET *PINTNET; 27 31 28 32 /** … … 164 168 Assert(pHdr->u16Type == INTNETHDR_TYPE_FRAME); 165 169 Assert(off < pBuf->cbBuf); 166 Assert(off + pHdr->cbFrame < pBuf->cbBuf);170 Assert(off + pHdr->cbFrame <= pBuf->cbBuf); 167 171 #endif 168 172 NOREF(pBuf); … … 198 202 199 203 200 201 /** 202 * The packed down arguments of INTNETR0Open(). 203 * @see INTNETR0Open() 204 */ 205 typedef struct INTNETOPENARGS 206 { 204 /** 205 * Request buffer for INTNETR0OpenReq / VMMR0_DO_INTNET_OPEN. 206 * @see INTNETR0Open. 207 */ 208 typedef struct INTNETOPENREQ 209 { 210 /** The request header. */ 211 SUPVMMR0REQHDR Hdr; 207 212 /** The network name. (input) */ 208 213 char szNetwork[INTNET_MAX_NETWORK_NAME]; … … 215 220 /** The handle to the network interface. (output) */ 216 221 INTNETIFHANDLE hIf; 217 } INTNETOPENARGS; 218 /** Pointer to an INTNETR0Open() argument package. */ 219 typedef INTNETOPENARGS *PINTNETOPENARGS; 220 221 222 /** 223 * The packed down arguments of INTNETR0IfClose(). 224 * @see INTNETR0IfClose() 225 */ 226 typedef struct INTNETCLOSEARGS 227 { 222 } INTNETOPENREQ; 223 /** Pointer to an INTNETR0OpenReq / VMMR0_DO_INTNET_OPEN request buffer. */ 224 typedef INTNETOPENREQ *PINTNETOPENREQ; 225 226 INTNETR0DECL(int) INTNETR0OpenReq(PINTNET pIntNet, PSUPDRVSESSION pSession, PINTNETOPENREQ pReq); 227 228 229 /** 230 * Request buffer for INTNETR0IfCloseReq / VMMR0_DO_INTNET_IF_CLOSE. 231 * @see INTNETR0IfClose. 232 */ 233 typedef struct INTNETIFCLOSEREQ 234 { 235 /** The request header. */ 236 SUPVMMR0REQHDR Hdr; 228 237 /** The handle to the network interface. */ 229 238 INTNETIFHANDLE hIf; 230 } INTNETIFCLOSEARGS; 231 /** Pointer to an INTNETR0Open() argument package. */ 232 typedef INTNETIFCLOSEARGS *PINTNETIFCLOSEARGS; 233 234 235 /** 236 * Argument buffer for calling INTNETR0IfGetRing3Buffer(). 237 * @see INTNETR0IfGetRing3Buffer() 238 */ 239 typedef struct INTNETIFGETRING3BUFFERARGS 240 { 239 } INTNETIFCLOSEREQ; 240 /** Pointer to an INTNETR0IfCloseReq / VMMR0_DO_INTNET_IF_CLOSE request buffer. */ 241 typedef INTNETIFCLOSEREQ *PINTNETIFCLOSEREQ; 242 243 INTNETR0DECL(int) INTNETR0IfCloseReq(PINTNET pIntNet, PINTNETIFCLOSEREQ pReq); 244 245 246 /** 247 * Request buffer for INTNETR0IfGetRing3BufferReq / VMMR0_DO_INTNET_IF_GET_RING3_BUFFER. 248 * @see INTNETR0IfGetRing3Buffer. 249 */ 250 typedef struct INTNETIFGETRING3BUFFERREQ 251 { 252 /** The request header. */ 253 SUPVMMR0REQHDR Hdr; 241 254 /** Handle to the interface. */ 242 INTNETIFHANDLE hIf;255 INTNETIFHANDLE hIf; 243 256 /** The pointer to the ring3 buffer. (output) */ 244 PINTNETBUF pRing3Buf; 245 } INTNETIFGETRING3BUFFERARGS; 246 /** Pointer to an INTNETR0IfGetRing3Buffer() argument package. */ 247 typedef INTNETIFGETRING3BUFFERARGS *PINTNETIFGETRING3BUFFERARGS; 248 249 /** 250 * Argument buffer for calling INTNETR0IfSetPromiscuousMode(). 251 * @see INTNETR0IfSetPromiscuousMode() 252 */ 253 typedef struct INTNETIFSETPROMISCUOUSMODEARGS 254 { 257 R3PTRTYPE(PINTNETBUF) pRing3Buf; 258 } INTNETIFGETRING3BUFFERREQ; 259 /** Pointer to an INTNETR0IfGetRing3BufferReq / VMMR0_DO_INTNET_IF_GET_RING3_BUFFER request buffer. */ 260 typedef INTNETIFGETRING3BUFFERREQ *PINTNETIFGETRING3BUFFERREQ; 261 262 INTNETR0DECL(int) INTNETR0IfGetRing3BufferReq(PINTNET pIntNet, PINTNETIFGETRING3BUFFERREQ pReq); 263 264 265 /** 266 * Request buffer for INTNETR0IfSetPromiscuousModeReq / VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE. 267 * @see INTNETR0IfSetPromiscuousMode. 268 */ 269 typedef struct INTNETIFSETPROMISCUOUSMODEREQ 270 { 271 /** The request header. */ 272 SUPVMMR0REQHDR Hdr; 255 273 /** Handle to the interface. */ 256 274 INTNETIFHANDLE hIf; 257 275 /** The new promiscuous mode. */ 258 276 bool fPromiscuous; 259 } INTNETIFSETPROMISCUOUSMODEARGS; 260 /** Pointer to an INTNETR0IfSetPromiscuousMode() argument package. */ 261 typedef INTNETIFSETPROMISCUOUSMODEARGS *PINTNETIFSETPROMISCUOUSMODEARGS; 262 263 264 /** 265 * Argument buffer for calling INTNETR0IfSend(). 266 * @see INTNETR0IfSend() 267 */ 268 typedef struct INTNETIFSENDARGS 269 { 277 } INTNETIFSETPROMISCUOUSMODEREQ; 278 /** Pointer to an INTNETR0IfSetPromiscuousModeReq / VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE request buffer. */ 279 typedef INTNETIFSETPROMISCUOUSMODEREQ *PINTNETIFSETPROMISCUOUSMODEREQ; 280 281 INTNETR0DECL(int) INTNETR0IfSetPromiscuousModeReq(PINTNET pIntNet, PINTNETIFSETPROMISCUOUSMODEREQ pReq); 282 283 284 /** 285 * Request buffer for INTNETR0IfSendReq / VMMR0_DO_INTNET_IF_SEND. 286 * @see INTNETR0IfSend. 287 */ 288 typedef struct INTNETIFSENDREQ 289 { 290 /** The request header. */ 291 SUPVMMR0REQHDR Hdr; 270 292 /** Handle to the interface. */ 271 293 INTNETIFHANDLE hIf; 272 /** Pointer to the frame. (Optional) */ 273 const void *pvFrame; 274 /** The size of the frame. (Optional) */ 275 uint32_t cbFrame; 276 } INTNETIFSENDARGS; 294 } INTNETIFSENDREQ; 277 295 /** Pointer to an INTNETR0IfSend() argument package. */ 278 typedef INTNETIFSENDARGS *PINTNETIFSENDARGS; 279 280 281 /** 282 * Argument buffer for calling INTNETR0IfWait(). 283 * @see INTNETR0IfWait() 284 */ 285 typedef struct INTNETIFWAITARGS 286 { 296 typedef INTNETIFSENDREQ *PINTNETIFSENDREQ; 297 298 INTNETR0DECL(int) INTNETR0IfSendReq(PINTNET pIntNet, PINTNETIFSENDREQ pReq); 299 300 301 /** 302 * Request buffer for INTNETR0IfWaitReq / VMMR0_DO_INTNET_IF_WAIT. 303 * @see INTNETR0IfWait. 304 */ 305 typedef struct INTNETIFWAITREQ 306 { 307 /** The request header. */ 308 SUPVMMR0REQHDR Hdr; 287 309 /** Handle to the interface. */ 288 310 INTNETIFHANDLE hIf; 289 311 /** The number of milliseconds to wait. */ 290 unsigned cMillies; 291 } INTNETSENDARGS; 292 /** Pointer to an INTNETR0IfWait() argument package. */ 293 typedef INTNETIFWAITARGS *PINTNETIFWAITARGS; 312 uint32_t cMillies; 313 } INTNETIFWAITREQ; 314 /** Pointer to an INTNETR0IfWaitReq / VMMR0_DO_INTNET_IF_WAIT request buffer. */ 315 typedef INTNETIFWAITREQ *PINTNETIFWAITREQ; 316 317 INTNETR0DECL(int) INTNETR0IfWaitReq(PINTNET pIntNet, PINTNETIFWAITREQ pReq); 294 318 295 319 … … 298 322 * @{ 299 323 */ 300 301 /** Pointer to an internal network ring-0 instance. */302 typedef struct INTNET *PINTNET;303 324 304 325 /** … … 358 379 * @param ppRing3Buf Where to store the address of the ring-3 mapping. 359 380 */ 360 INTNETR0DECL(int) INTNETR0IfGetRing3Buffer(PINTNET pIntNet, INTNETIFHANDLE hIf, PINTNETBUF*ppRing3Buf);381 INTNETR0DECL(int) INTNETR0IfGetRing3Buffer(PINTNET pIntNet, INTNETIFHANDLE hIf, R3PTRTYPE(PINTNETBUF) *ppRing3Buf); 361 382 362 383 /** … … 396 417 * used if indefinite wait is desired. 397 418 */ 398 INTNETR0DECL(int) INTNETR0IfWait(PINTNET pIntNet, INTNETIFHANDLE hIf, u nsignedcMillies);419 INTNETR0DECL(int) INTNETR0IfWait(PINTNET pIntNet, INTNETIFHANDLE hIf, uint32_t cMillies); 399 420 400 421 /** @} */ -
trunk/src/VBox/Devices/Network/DrvIntNet.cpp
r4071 r5283 113 113 114 114 /** 115 * Writes a frame packet to the buffer. 116 * 117 * @returns VBox status code. 118 * @param pBuf The buffer. 119 * @param pRingBuf The ring buffer to read from. 120 * @param pvFrame The frame to write. 121 * @param cbFrame The size of the frame. 122 * @remark This is the same as INTNETRingWriteFrame 123 */ 124 static int drvIntNetRingWriteFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, const void *pvFrame, uint32_t cbFrame) 125 { 126 /* 127 * Validate input. 128 */ 129 Assert(pBuf); 130 Assert(pRingBuf); 131 Assert(pvFrame); 132 Assert(cbFrame >= sizeof(PDMMAC) * 2); 133 uint32_t offWrite = pRingBuf->offWrite; 134 Assert(offWrite == RT_ALIGN_32(offWrite, sizeof(INTNETHDR))); 135 uint32_t offRead = pRingBuf->offRead; 136 Assert(offRead == RT_ALIGN_32(offRead, sizeof(INTNETHDR))); 137 138 const uint32_t cb = RT_ALIGN_32(cbFrame, sizeof(INTNETHDR)); 139 if (offRead <= offWrite) 140 { 141 /* 142 * Try fit it all before the end of the buffer. 143 */ 144 if (pRingBuf->offEnd - offWrite >= cb + sizeof(INTNETHDR)) 145 { 146 PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pBuf + offWrite); 147 pHdr->u16Type = INTNETHDR_TYPE_FRAME; 148 pHdr->cbFrame = cbFrame; 149 pHdr->offFrame = sizeof(INTNETHDR); 150 151 memcpy(pHdr + 1, pvFrame, cbFrame); 152 153 offWrite += cb + sizeof(INTNETHDR); 154 Assert(offWrite <= pRingBuf->offEnd && offWrite >= pRingBuf->offStart); 155 if (offWrite >= pRingBuf->offEnd) 156 offWrite = pRingBuf->offStart; 157 Log2(("WriteFrame: offWrite: %#x -> %#x (1)\n", pRingBuf->offWrite, offWrite)); 158 ASMAtomicXchgU32(&pRingBuf->offWrite, offWrite); 159 return VINF_SUCCESS; 160 } 161 162 /* 163 * Try fit the frame at the start of the buffer. 164 * (The header fits before the end of the buffer because of alignment.) 165 */ 166 AssertMsg(pRingBuf->offEnd - offWrite >= sizeof(INTNETHDR), ("offEnd=%x offWrite=%x\n", pRingBuf->offEnd, offWrite)); 167 if (offRead - pRingBuf->offStart > cb) /* not >= ! */ 168 { 169 PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pBuf + offWrite); 170 void *pvFrameOut = (PINTNETHDR)((uint8_t *)pBuf + pRingBuf->offStart); 171 pHdr->u16Type = INTNETHDR_TYPE_FRAME; 172 pHdr->cbFrame = cbFrame; 173 pHdr->offFrame = (intptr_t)pvFrameOut - (intptr_t)pHdr; 174 175 memcpy(pvFrameOut, pvFrame, cbFrame); 176 177 offWrite = pRingBuf->offStart + cb; 178 ASMAtomicXchgU32(&pRingBuf->offWrite, offWrite); 179 Log2(("WriteFrame: offWrite: %#x -> %#x (2)\n", pRingBuf->offWrite, offWrite)); 180 return VINF_SUCCESS; 181 } 182 } 183 /* 184 * The reader is ahead of the writer, try fit it into that space. 185 */ 186 else if (offRead - offWrite > cb + sizeof(INTNETHDR)) /* not >= ! */ 187 { 188 PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pBuf + offWrite); 189 pHdr->u16Type = INTNETHDR_TYPE_FRAME; 190 pHdr->cbFrame = cbFrame; 191 pHdr->offFrame = sizeof(INTNETHDR); 192 193 memcpy(pHdr + 1, pvFrame, cbFrame); 194 195 offWrite += cb + sizeof(INTNETHDR); 196 ASMAtomicXchgU32(&pRingBuf->offWrite, offWrite); 197 Log2(("WriteFrame: offWrite: %#x -> %#x (3)\n", pRingBuf->offWrite, offWrite)); 198 return VINF_SUCCESS; 199 } 200 201 /* (it didn't fit) */ 202 /** @todo stats */ 203 return VERR_BUFFER_OVERFLOW; 204 } 205 206 207 /** 115 208 * Send data to the network. 116 209 * … … 136 229 #endif 137 230 138 /** @todo copy to send buffer, this is not safe. */ 139 INTNETIFSENDARGS SendArgs; 140 SendArgs.hIf = pThis->hIf; 141 SendArgs.pvFrame = pvBuf; 142 SendArgs.cbFrame = cb; 143 int rc = pThis->pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pThis->pDrvIns, VMMR0_DO_INTNET_IF_SEND, &SendArgs, sizeof(SendArgs)); 231 /* 232 * Add the frame to the send buffer and push it onto the network. 233 */ 234 int rc = drvIntNetRingWriteFrame(pThis->pBuf, &pThis->pBuf->Send, pvBuf, cb); 235 if ( rc == VERR_BUFFER_OVERFLOW 236 && pThis->pBuf->cbSend < cb) 237 { 238 INTNETIFSENDREQ SendReq; 239 SendReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC; 240 SendReq.Hdr.cbReq = sizeof(SendReq); 241 SendReq.hIf = pThis->hIf; 242 pThis->pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pThis->pDrvIns, VMMR0_DO_INTNET_IF_SEND, &SendReq, sizeof(SendReq)); 243 244 rc = drvIntNetRingWriteFrame(pThis->pBuf, &pThis->pBuf->Send, pvBuf, cb); 245 } 246 247 if (RT_SUCCESS(rc)) 248 { 249 INTNETIFSENDREQ SendReq; 250 SendReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC; 251 SendReq.Hdr.cbReq = sizeof(SendReq); 252 SendReq.hIf = pThis->hIf; 253 rc = pThis->pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pThis->pDrvIns, VMMR0_DO_INTNET_IF_SEND, &SendReq, sizeof(SendReq)); 254 } 144 255 145 256 STAM_PROFILE_STOP(&pThis->StatTransmit, a); … … 162 273 { 163 274 PDRVINTNET pThis = PDMINETWORKCONNECTOR_2_DRVINTNET(pInterface); 164 INTNETIFSETPROMISCUOUSMODEARGS SetArgs = {0}; 165 SetArgs.hIf = pThis->hIf; 166 SetArgs.fPromiscuous = fPromiscuous; 167 int rc = pThis->pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pThis->pDrvIns, VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE, &SetArgs, sizeof(SetArgs)); 168 LogFlow(("drvIntNetSetPromiscuousMode: fPromiscuous=%d\n", fPromiscuous)); 275 INTNETIFSETPROMISCUOUSMODEREQ Req; 276 Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC; 277 Req.Hdr.cbReq = sizeof(Req); 278 Req.hIf = pThis->hIf; 279 Req.fPromiscuous = fPromiscuous; 280 int rc = pThis->pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pThis->pDrvIns, VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE, &Req, sizeof(Req)); 281 LogFlow(("drvIntNetSetPromiscuousMode: fPromiscuous=%RTbool\n", fPromiscuous)); 169 282 AssertRC(rc); 170 283 } … … 368 481 return VERR_STATE_CHANGED; 369 482 } 370 INTNETIFWAITARGS WaitArgs; 371 WaitArgs.hIf = pThis->hIf; 372 WaitArgs.cMillies = 30000; /* don't wait forever, timeout now and then. */ 483 INTNETIFWAITREQ WaitReq; 484 WaitReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC; 485 WaitReq.Hdr.cbReq = sizeof(WaitReq); 486 WaitReq.hIf = pThis->hIf; 487 WaitReq.cMillies = 30000; /* 30s - don't wait forever, timeout now and then. */ 373 488 STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a); 374 int rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_WAIT, &Wait Args, sizeof(WaitArgs));489 int rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_WAIT, &WaitReq, sizeof(WaitReq)); 375 490 if ( VBOX_FAILURE(rc) 376 491 && rc != VERR_TIMEOUT … … 547 662 if (pThis->hIf != INTNET_HANDLE_INVALID) 548 663 { 549 INTNETIFCLOSEARGS CloseArgs = {0}; 550 CloseArgs.hIf = pThis->hIf; 664 INTNETIFCLOSEREQ CloseReq; 665 CloseReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC; 666 CloseReq.Hdr.cbReq = sizeof(CloseReq); 667 CloseReq.hIf = pThis->hIf; 551 668 pThis->hIf = INTNET_HANDLE_INVALID; 552 int rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_CLOSE, &Close Args, sizeof(CloseArgs));669 int rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_CLOSE, &CloseReq, sizeof(CloseReq)); 553 670 AssertRC(rc); 554 671 } … … 638 755 * Read the configuration. 639 756 */ 640 INTNETOPENARGS OpenArgs; 641 memset(&OpenArgs, 0, sizeof(OpenArgs)); 642 rc = CFGMR3QueryString(pCfgHandle, "Network", OpenArgs.szNetwork, sizeof(OpenArgs.szNetwork)); 757 INTNETOPENREQ OpenReq; 758 memset(&OpenReq, 0, sizeof(OpenReq)); 759 OpenReq.Hdr.cbReq = sizeof(OpenReq); 760 OpenReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC; 761 762 rc = CFGMR3QueryString(pCfgHandle, "Network", OpenReq.szNetwork, sizeof(OpenReq.szNetwork)); 643 763 if (VBOX_FAILURE(rc)) 644 764 return PDMDRV_SET_ERROR(pDrvIns, rc, 645 765 N_("Configuration error: Failed to get the \"Network\" value")); 646 strcpy(pThis->szNetwork, Open Args.szNetwork);647 648 rc = CFGMR3QueryU32(pCfgHandle, "ReceiveBufferSize", &Open Args.cbRecv);766 strcpy(pThis->szNetwork, OpenReq.szNetwork); 767 768 rc = CFGMR3QueryU32(pCfgHandle, "ReceiveBufferSize", &OpenReq.cbRecv); 649 769 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 650 Open Args.cbRecv = _256K;770 OpenReq.cbRecv = _256K; 651 771 else if (VBOX_FAILURE(rc)) 652 772 return PDMDRV_SET_ERROR(pDrvIns, rc, 653 773 N_("Configuration error: Failed to get the \"ReceiveBufferSize\" value")); 654 774 655 rc = CFGMR3QueryU32(pCfgHandle, "SendBufferSize", &Open Args.cbSend);775 rc = CFGMR3QueryU32(pCfgHandle, "SendBufferSize", &OpenReq.cbSend); 656 776 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 657 Open Args.cbSend = _4K;777 OpenReq.cbSend = _4K; 658 778 else if (VBOX_FAILURE(rc)) 659 779 return PDMDRV_SET_ERROR(pDrvIns, rc, 660 780 N_("Configuration error: Failed to get the \"SendBufferSize\" value")); 661 662 rc = CFGMR3QueryBool(pCfgHandle, "RestrictAccess", &OpenArgs.fRestrictAccess); 781 if (OpenReq.cbSend < 16) 782 return PDMDRV_SET_ERROR(pDrvIns, rc, 783 N_("Configuration error: The \"SendBufferSize\" value is too small.")); 784 if (OpenReq.cbSend < 1536*2 + 4) 785 LogRel(("DrvIntNet: Warning! SendBufferSize=%u, Recommended minimum size %u butes.\n", OpenReq.cbSend, 1536*2 + 4)); 786 787 rc = CFGMR3QueryBool(pCfgHandle, "RestrictAccess", &OpenReq.fRestrictAccess); 663 788 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 664 Open Args.fRestrictAccess = true;789 OpenReq.fRestrictAccess = true; 665 790 else if (VBOX_FAILURE(rc)) 666 791 return PDMDRV_SET_ERROR(pDrvIns, rc, … … 680 805 * Create the interface. 681 806 */ 682 Open Args.hIf = INTNET_HANDLE_INVALID;683 rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_OPEN, &Open Args, sizeof(OpenArgs));807 OpenReq.hIf = INTNET_HANDLE_INVALID; 808 rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_OPEN, &OpenReq, sizeof(OpenReq)); 684 809 if (VBOX_FAILURE(rc)) 685 810 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, 686 811 N_("Failed to open/create the internal network '%s'"), pThis->szNetwork); 687 AssertRelease(Open Args.hIf != INTNET_HANDLE_INVALID);688 pThis->hIf = Open Args.hIf;812 AssertRelease(OpenReq.hIf != INTNET_HANDLE_INVALID); 813 pThis->hIf = OpenReq.hIf; 689 814 Log(("IntNet%d: hIf=%RX32 '%s'\n", pDrvIns->iInstance, pThis->hIf, pThis->szNetwork)); 690 815 … … 692 817 * Get default buffer. 693 818 */ 694 INTNETIFGETRING3BUFFERARGS GetRing3BufferArgs = {0}; 695 GetRing3BufferArgs.hIf = pThis->hIf; 696 GetRing3BufferArgs.pRing3Buf = NULL; 697 rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_GET_RING3_BUFFER, &GetRing3BufferArgs, sizeof(GetRing3BufferArgs)); 819 INTNETIFGETRING3BUFFERREQ GetRing3BufferReq; 820 GetRing3BufferReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC; 821 GetRing3BufferReq.Hdr.cbReq = sizeof(GetRing3BufferReq); 822 GetRing3BufferReq.hIf = pThis->hIf; 823 GetRing3BufferReq.pRing3Buf = NULL; 824 rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_GET_RING3_BUFFER, &GetRing3BufferReq, sizeof(GetRing3BufferReq)); 698 825 if (VBOX_FAILURE(rc)) 699 826 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, 700 827 N_("Failed to get ring-3 buffer for the newly created interface to '%s'"), pThis->szNetwork); 701 AssertRelease(VALID_PTR(GetRing3Buffer Args.pRing3Buf));702 pThis->pBuf = GetRing3Buffer Args.pRing3Buf;828 AssertRelease(VALID_PTR(GetRing3BufferReq.pRing3Buf)); 829 pThis->pBuf = GetRing3BufferReq.pRing3Buf; 703 830 704 831 /* … … 737 864 #endif 738 865 739 LogRel(("IntNet#%u: cbRecv=%u cbSend=%u fRestrictAccess=%d\n", pDrvIns->iInstance, Open Args.cbRecv, OpenArgs.cbSend, OpenArgs.fRestrictAccess));866 LogRel(("IntNet#%u: cbRecv=%u cbSend=%u fRestrictAccess=%d\n", pDrvIns->iInstance, OpenReq.cbRecv, OpenReq.cbSend, OpenReq.fRestrictAccess)); 740 867 741 868 return rc; -
trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp
r4071 r5283 60 60 PINTNETBUF pIntBuf; 61 61 /** Pointer to ring-3 mapping of the current exchange buffer. */ 62 PINTNETBUFpIntBufR3;62 R3PTRTYPE(PINTNETBUF) pIntBufR3; 63 63 /** Pointer to the default exchange buffer for the interface. */ 64 64 PINTNETBUF pIntBufDefault; 65 65 /** Pointer to ring-3 mapping of the default exchange buffer. */ 66 PINTNETBUFpIntBufDefaultR3;66 R3PTRTYPE(PINTNETBUF) pIntBufDefaultR3; 67 67 /** Event semaphore which a receiver thread will sleep on while waiting for data to arrive. */ 68 68 RTSEMEVENT Event; … … 625 625 * Process the send buffer. 626 626 */ 627 if (pIf->pIntBuf->Send.offRead != pIf->pIntBuf->Send.offWrite) 628 { 629 for (;;) 627 while (pIf->pIntBuf->Send.offRead != pIf->pIntBuf->Send.offWrite) 628 { 629 /* Send the frame if the type is sane. */ 630 PINTNETHDR pHdr = (PINTNETHDR)((uintptr_t)pIf->pIntBuf + pIf->pIntBuf->Send.offRead); 631 if (pHdr->u16Type == INTNETHDR_TYPE_FRAME) 630 632 { 631 /* 632 * Anything we know what is, if so send it. 633 */ 634 PINTNETHDR pHdr = (PINTNETHDR)((uintptr_t)pIf->pIntBuf + pIf->pIntBuf->Send.offRead); 635 if (pHdr->u16Type == INTNETHDR_TYPE_FRAME) 636 { 637 void *pvCurFrame = INTNETHdrGetFramePtr(pHdr, pIf->pIntBuf); 638 if (pvCurFrame) 639 intnetNetworkSend(pIf->pNetwork, pIf, pvCurFrame, pHdr->cbFrame); 640 } 641 /* else: ignore the frame */ 642 643 /* 644 * Skip to the next frame. 645 */ 646 INTNETRingSkipFrame(pIf->pIntBuf, &pIf->pIntBuf->Send); 633 void *pvCurFrame = INTNETHdrGetFramePtr(pHdr, pIf->pIntBuf); 634 if (pvCurFrame) 635 intnetNetworkSend(pIf->pNetwork, pIf, pvCurFrame, pHdr->cbFrame); 647 636 } 637 /* else: ignore the frame */ 638 639 /* Skip to the next frame. */ 640 INTNETRingSkipFrame(pIf->pIntBuf, &pIf->pIntBuf->Send); 648 641 } 649 642 650 643 return RTSemFastMutexRelease(pIf->pNetwork->FastMutex); 644 } 645 646 647 /** 648 * VMMR0 request wrapper for INTNETR0IfSend. 649 * 650 * @returns see INTNETR0IfSend. 651 * @param pIntNet The internal networking instance. 652 * @param pReq The request packet. 653 */ 654 INTNETR0DECL(int) INTNETR0IfSendReq(PINTNET pIntNet, PINTNETIFSENDREQ pReq) 655 { 656 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 657 return VERR_INVALID_PARAMETER; 658 return INTNETR0IfSend(pIntNet, pReq->hIf, NULL, 0); 651 659 } 652 660 … … 660 668 * @param ppRing3Buf Where to store the address of the ring-3 mapping. 661 669 */ 662 INTNETR0DECL(int) INTNETR0IfGetRing3Buffer(PINTNET pIntNet, INTNETIFHANDLE hIf, PINTNETBUF*ppRing3Buf)670 INTNETR0DECL(int) INTNETR0IfGetRing3Buffer(PINTNET pIntNet, INTNETIFHANDLE hIf, R3PTRTYPE(PINTNETBUF) *ppRing3Buf) 663 671 { 664 672 LogFlow(("INTNETR0IfGetRing3Buffer: pIntNet=%p hIf=%RX32 ppRing3Buf=%p\n", pIntNet, hIf, ppRing3Buf)); … … 687 695 LogFlow(("INTNETR0IfGetRing3Buffer: returns %Vrc *ppRing3Buf=%p\n", rc, *ppRing3Buf)); 688 696 return rc; 697 } 698 699 700 /** 701 * VMMR0 request wrapper for INTNETR0IfGetRing3Buffer. 702 * 703 * @returns see INTNETR0IfGetRing3Buffer. 704 * @param pIntNet The internal networking instance. 705 * @param pReq The request packet. 706 */ 707 INTNETR0DECL(int) INTNETR0IfGetRing3BufferReq(PINTNET pIntNet, PINTNETIFGETRING3BUFFERREQ pReq) 708 { 709 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 710 return VERR_INVALID_PARAMETER; 711 return INTNETR0IfGetRing3Buffer(pIntNet, pReq->hIf, &pReq->pRing3Buf); 689 712 } 690 713 … … 799 822 800 823 /** 824 * VMMR0 request wrapper for INTNETR0IfSetPromiscuousMode. 825 * 826 * @returns see INTNETR0IfSetPromiscuousMode. 827 * @param pIntNet The internal networking instance. 828 * @param pReq The request packet. 829 */ 830 INTNETR0DECL(int) INTNETR0IfSetPromiscuousModeReq(PINTNET pIntNet, PINTNETIFSETPROMISCUOUSMODEREQ pReq) 831 { 832 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 833 return VERR_INVALID_PARAMETER; 834 return INTNETR0IfSetPromiscuousMode(pIntNet, pReq->hIf, pReq->fPromiscuous); 835 } 836 837 838 /** 801 839 * Wait for the interface to get signaled. 802 840 * The interface will be signaled when is put into the receive buffer. … … 808 846 * used if indefinite wait is desired. 809 847 */ 810 INTNETR0DECL(int) INTNETR0IfWait(PINTNET pIntNet, INTNETIFHANDLE hIf, u nsignedcMillies)848 INTNETR0DECL(int) INTNETR0IfWait(PINTNET pIntNet, INTNETIFHANDLE hIf, uint32_t cMillies) 811 849 { 812 850 LogFlow(("INTNETR0IfWait: pIntNet=%p hIf=%RX32 cMillies=%u\n", pIntNet, hIf, cMillies)); … … 844 882 */ 845 883 ASMAtomicIncU32(&pIf->cSleepers); 846 int rc = RTSemEventWait (Event, cMillies);884 int rc = RTSemEventWaitNoResume(Event, cMillies); 847 885 if (pIf->Event == Event) 848 886 { … … 859 897 860 898 /** 899 * VMMR0 request wrapper for INTNETR0IfWait. 900 * 901 * @returns see INTNETR0IfWait. 902 * @param pIntNet The internal networking instance. 903 * @param pReq The request packet. 904 */ 905 INTNETR0DECL(int) INTNETR0IfWaitReq(PINTNET pIntNet, PINTNETIFWAITREQ pReq) 906 { 907 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 908 return VERR_INVALID_PARAMETER; 909 return INTNETR0IfWait(pIntNet, pReq->hIf, pReq->cMillies); 910 } 911 912 913 /** 861 914 * Close an interface. 862 915 * … … 880 933 LogFlow(("INTNETR0IfClose: returns %Vrc\n", rc)); 881 934 return rc; 935 } 936 937 938 /** 939 * VMMR0 request wrapper for INTNETR0IfCloseReq. 940 * 941 * @returns see INTNETR0IfClose. 942 * @param pIntNet The internal networking instance. 943 * @param pReq The request packet. 944 */ 945 INTNETR0DECL(int) INTNETR0IfCloseReq(PINTNET pIntNet, PINTNETIFCLOSEREQ pReq) 946 { 947 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 948 return VERR_INVALID_PARAMETER; 949 return INTNETR0IfClose(pIntNet, pReq->hIf); 882 950 } 883 951 … … 978 1046 SUPR0MemFree(pIf->pSession, (RTHCUINTPTR)pIf->pIntBufDefault); 979 1047 pIf->pIntBufDefault = NULL; 980 pIf->pIntBufDefaultR3 = NULL; 981 pIf->pIntBufR3 = NULL; 1048 pIf->pIntBufDefaultR3 = 0; 982 1049 pIf->pIntBuf = NULL; 1050 pIf->pIntBufR3 = 0; 983 1051 } 984 1052 … … 1419 1487 1420 1488 /** 1489 * VMMR0 request wrapper for GMMR0MapUnmapChunk. 1490 * 1491 * @returns see GMMR0MapUnmapChunk. 1492 * @param pIntNet The internal networking instance. 1493 * @param pSession The session handle. 1494 * @param pReq The request packet. 1495 */ 1496 INTNETR0DECL(int) INTNETR0OpenReq(PINTNET pIntNet, PSUPDRVSESSION pSession, PINTNETOPENREQ pReq) 1497 { 1498 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 1499 return VERR_INVALID_PARAMETER; 1500 return INTNETR0Open(pIntNet, pSession, &pReq->szNetwork[0], pReq->cbSend, pReq->cbRecv, pReq->fRestrictAccess, &pReq->hIf); 1501 } 1502 1503 1504 /** 1421 1505 * Destroys an instance of the Ring-0 internal networking service. 1422 1506 * -
trunk/src/VBox/Devices/Network/testcase/tstIntNetR0.cpp
r4071 r5283 202 202 203 203 204 #define TEST_TRANSFER_SIZE (_1M* 128)204 #define TEST_TRANSFER_SIZE (_1M*384) 205 205 206 206 /** … … 229 229 const unsigned cb = iFrame % 1519 + 12 + sizeof(unsigned); 230 230 *puFrame = iFrame; 231 #if 0 231 232 int rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, abBuf, cb); 233 #else 234 int rc = INTNETRingWriteFrame(pArgs->pBuf, &pArgs->pBuf->Send, abBuf, cb); 235 if (RT_SUCCESS(rc)) 236 rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, NULL, 0); 237 #endif 232 238 if (VBOX_FAILURE(rc)) 233 239 { 234 240 g_cErrors++; 235 RTPrintf("tstIntNetR0: Failed sending %d bytes, rc=%Vrc \n", cb, rc);241 RTPrintf("tstIntNetR0: Failed sending %d bytes, rc=%Vrc (%d)\n", cb, rc, INTNETRingGetWritable(&pArgs->pBuf->Send)); 236 242 } 237 243 cbSent += cb; … … 384 390 */ 385 391 INTNETIFHANDLE hIf0 = INTNET_HANDLE_INVALID; 386 rc = INTNETR0Open(pIntNet, g_pSession, "test", 1536 , 0x8000, true, &hIf0);392 rc = INTNETR0Open(pIntNet, g_pSession, "test", 1536*2 + 4, 0x8000, true, &hIf0); 387 393 if (VBOX_SUCCESS(rc)) 388 394 { … … 390 396 { 391 397 INTNETIFHANDLE hIf1 = INTNET_HANDLE_INVALID; 392 rc = INTNETR0Open(pIntNet, g_pSession, "test", 1536 , 0x8000, true, &hIf1);398 rc = INTNETR0Open(pIntNet, g_pSession, "test", 1536*2 + 4, 0x8000, true, &hIf1); 393 399 if (VBOX_SUCCESS(rc)) 394 400 { -
trunk/src/VBox/VMM/PDMDriver.cpp
r4800 r5283 991 991 if ( uOperation >= VMMR0_DO_SRV_START 992 992 && uOperation < VMMR0_DO_SRV_END) 993 #if 0 /** @todo fix internal networking */ 994 rc = SUPCallVMMR0Ex(pDrvIns->Internal.s.pVM->pVMR0, uOperation, pvArg, cbArg); 995 #else 996 { 997 LogRel(("Sorry, internal networking is currently broken in the devlopment tree. Will be fixed in a bit, no time right now.\n")); 998 rc = VERR_NOT_IMPLEMENTED; 999 } 1000 #endif 993 rc = SUPCallVMMR0Ex(pDrvIns->Internal.s.pVM->pVMR0, uOperation, 0, (PSUPVMMR0REQHDR)pvArg); 1001 994 else 1002 995 { -
trunk/src/VBox/VMM/VMMR0/VMMR0.cpp
r5274 r5283 832 832 833 833 834 #if 0//def VBOX_WITH_INTERNAL_NETWORKING - currently busted835 /* 836 * Services.834 #ifdef VBOX_WITH_INTERNAL_NETWORKING 835 /* 836 * Requests to the internal networking service. 837 837 */ 838 838 case VMMR0_DO_INTNET_OPEN: 839 if (!pVM || u64Arg) 840 return VERR_INVALID_PARAMETER; 841 if (!g_pIntNet) 842 return VERR_NOT_SUPPORTED; 843 return INTNETR0OpenReq(g_pIntNet, pVM->pSession, (PINTNETOPENREQ)pReqHdr); 844 839 845 case VMMR0_DO_INTNET_IF_CLOSE: 846 if (!pVM || u64Arg) 847 return VERR_INVALID_PARAMETER; 848 if (!g_pIntNet) 849 return VERR_NOT_SUPPORTED; 850 return INTNETR0IfCloseReq(g_pIntNet, (PINTNETIFCLOSEREQ)pReqHdr); 851 840 852 case VMMR0_DO_INTNET_IF_GET_RING3_BUFFER: 853 if (!pVM || u64Arg) 854 return VERR_INVALID_PARAMETER; 855 if (!g_pIntNet) 856 return VERR_NOT_SUPPORTED; 857 return INTNETR0IfGetRing3BufferReq(g_pIntNet, (PINTNETIFGETRING3BUFFERREQ)pReqHdr); 858 841 859 case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE: 860 if (!pVM || u64Arg) 861 return VERR_INVALID_PARAMETER; 862 if (!g_pIntNet) 863 return VERR_NOT_SUPPORTED; 864 return INTNETR0IfSetPromiscuousModeReq(g_pIntNet, (PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr); 865 842 866 case VMMR0_DO_INTNET_IF_SEND: 867 if (!pVM || u64Arg) 868 return VERR_INVALID_PARAMETER; 869 if (!g_pIntNet) 870 return VERR_NOT_SUPPORTED; 871 return INTNETR0IfSendReq(g_pIntNet, (PINTNETIFSENDREQ)pReqHdr); 872 843 873 case VMMR0_DO_INTNET_IF_WAIT: 844 { 845 /* 846 * Validate arguments a bit first. 847 */ 848 if (!VALID_PTR(pvArg)) 849 return VERR_INVALID_POINTER; 850 if (!VALID_PTR(pVM)) 851 return VERR_INVALID_POINTER; 852 if (pVM->pVMR0 != pVM) 853 return VERR_INVALID_POINTER; 854 if (!VALID_PTR(pVM->pSession)) 855 return VERR_INVALID_POINTER; 874 if (!pVM || u64Arg) 875 return VERR_INVALID_PARAMETER; 856 876 if (!g_pIntNet) 857 return VERR_FILE_NOT_FOUND; ///@todo fix this status code! 858 859 /* 860 * Unpack the arguments and call the service. 861 */ 862 switch (enmOperation) 863 { 864 case VMMR0_DO_INTNET_OPEN: 865 { 866 PINTNETOPENARGS pArgs = (PINTNETOPENARGS)pvArg; 867 return INTNETR0Open(g_pIntNet, pVM->pSession, &pArgs->szNetwork[0], pArgs->cbSend, pArgs->cbRecv, pArgs->fRestrictAccess, &pArgs->hIf); 868 } 869 870 case VMMR0_DO_INTNET_IF_CLOSE: 871 { 872 PINTNETIFCLOSEARGS pArgs = (PINTNETIFCLOSEARGS)pvArg; 873 return INTNETR0IfClose(g_pIntNet, pArgs->hIf); 874 } 875 876 case VMMR0_DO_INTNET_IF_GET_RING3_BUFFER: 877 { 878 PINTNETIFGETRING3BUFFERARGS pArgs = (PINTNETIFGETRING3BUFFERARGS)pvArg; 879 return INTNETR0IfGetRing3Buffer(g_pIntNet, pArgs->hIf, &pArgs->pRing3Buf); 880 } 881 882 case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE: 883 { 884 PINTNETIFSETPROMISCUOUSMODEARGS pArgs = (PINTNETIFSETPROMISCUOUSMODEARGS)pvArg; 885 return INTNETR0IfSetPromiscuousMode(g_pIntNet, pArgs->hIf, pArgs->fPromiscuous); 886 } 887 888 case VMMR0_DO_INTNET_IF_SEND: 889 { 890 PINTNETIFSENDARGS pArgs = (PINTNETIFSENDARGS)pvArg; 891 return INTNETR0IfSend(g_pIntNet, pArgs->hIf, pArgs->pvFrame, pArgs->cbFrame); 892 } 893 894 case VMMR0_DO_INTNET_IF_WAIT: 895 { 896 PINTNETIFWAITARGS pArgs = (PINTNETIFWAITARGS)pvArg; 897 return INTNETR0IfWait(g_pIntNet, pArgs->hIf, pArgs->cMillies); 898 } 899 900 default: 901 return VERR_NOT_SUPPORTED; 902 } 903 } 877 return VERR_NOT_SUPPORTED; 878 return INTNETR0IfWaitReq(g_pIntNet, (PINTNETIFWAITREQ)pReqHdr); 904 879 #endif /* VBOX_WITH_INTERNAL_NETWORKING */ 905 880
Note:
See TracChangeset
for help on using the changeset viewer.