- Timestamp:
- Jul 16, 2008 7:54:17 PM (16 years ago)
- Location:
- trunk/src/VBox/Devices/Network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp
r10681 r10711 59 59 * In promiscuous mode the interface will receive all packages except the one it's sending. */ 60 60 bool fPromiscuous; 61 /** Whether the interface is active or not. */ 62 bool fActive; 61 63 /** Number of yields done to try make the interface read pending data. 62 64 * We will stop yeilding when this reaches a threshold assuming that the VM is paused or … … 139 141 /** Network creation flags (INTNET_OPEN_FLAGS_*). */ 140 142 uint32_t fFlags; 143 /** The number of active interfaces (excluding the trunk). */ 144 uint32_t cActiveIFs; 141 145 /** The length of the network name. */ 142 146 uint8_t cchName; … … 208 212 * Internal Functions * 209 213 *******************************************************************************/ 210 static PINTNETTRUNKIF intnet TrunkIfRetain(PINTNETTRUNKIF pThis);211 static void intnet TrunkIfRelease(PINTNETTRUNKIF pThis);212 static bool intnet TrunkIfOutLock(PINTNETTRUNKIF pThis);213 static void intnet TrunkIfOutUnlock(PINTNETTRUNKIF pThis);214 static PINTNETTRUNKIF intnetR0TrunkIfRetain(PINTNETTRUNKIF pThis); 215 static void intnetR0TrunkIfRelease(PINTNETTRUNKIF pThis); 216 static bool intnetR0TrunkIfOutLock(PINTNETTRUNKIF pThis); 217 static void intnetR0TrunkIfOutUnlock(PINTNETTRUNKIF pThis); 214 218 215 219 … … 228 232 * @internal 229 233 */ 230 DECLINLINE(PINTNETIF) intnet Handle2IFPtrLocked(PINTNETHT pHT, INTNETIFHANDLE hIF)234 DECLINLINE(PINTNETIF) intnetR0Handle2IFPtrLocked(PINTNETHT pHT, INTNETIFHANDLE hIF) 231 235 { 232 236 if (RT_LIKELY((hIF & INTNET_HANDLE_MAGIC) == INTNET_HANDLE_MAGIC)) … … 250 254 * @param hIF The interface handle to validate and translate. 251 255 */ 252 DECLINLINE(PINTNETIF) intnet Handle2IFPtr(PINTNETHT pHT, INTNETIFHANDLE hIF)256 DECLINLINE(PINTNETIF) intnetR0Handle2IFPtr(PINTNETHT pHT, INTNETIFHANDLE hIF) 253 257 { 254 258 AssertPtr(pHT); 255 259 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 256 260 RTSpinlockAcquire(pHT->Spinlock, &Tmp); 257 PINTNETIF pIF = intnet Handle2IFPtrLocked(pHT, hIF);261 PINTNETIF pIF = intnetR0Handle2IFPtrLocked(pHT, hIF); 258 262 RTSpinlockRelease(pHT->Spinlock, &Tmp); 259 263 … … 270 274 * @param pIF The interface which we're allocating a handle for. 271 275 */ 272 static INTNETIFHANDLE intnet HandleAllocate(PINTNET pIntNet, PINTNETIF pIF)276 static INTNETIFHANDLE intnetR0HandleAllocate(PINTNET pIntNet, PINTNETIF pIF) 273 277 { 274 278 Assert(pIF); … … 355 359 * @param h The handle we're freeing. 356 360 */ 357 static PINTNETIF intnet HandleFree(PINTNETHT pHT, INTNETIFHANDLE h)361 static PINTNETIF intnetR0HandleFree(PINTNETHT pHT, INTNETIFHANDLE h) 358 362 { 359 363 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; … … 364 368 * at the end of the free list. 365 369 */ 366 PINTNETIF pIF = intnet Handle2IFPtrLocked(pHT, h);370 PINTNETIF pIF = intnetR0Handle2IFPtrLocked(pHT, h); 367 371 if (pIF) 368 372 { … … 395 399 * ensuring that there is sufficient space for the frame. 396 400 */ 397 static unsigned intnetR ingReadFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, void *pvFrame)401 static unsigned intnetR0RingReadFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, void *pvFrame) 398 402 { 399 403 Assert(pRingBuf->offRead < pBuf->cbBuf); … … 415 419 return cb; 416 420 } 417 #endif 421 #endif /* IN_INTNET_TESTCASE */ 418 422 419 423 … … 427 431 * @param cbFrame The size of the frame. 428 432 */ 429 static int intnetR ingWriteFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, const void *pvFrame, uint32_t cbFrame)433 static int intnetR0RingWriteFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, const void *pvFrame, uint32_t cbFrame) 430 434 { 431 435 /* … … 530 534 * @param cbFrame The size of the frame. 531 535 */ 532 static void intnet IfSend(PINTNETIF pIf, const void *pvFrame, unsigned cbFrame)533 { 534 LogFlow(("intnet IfSend: pIf=%p:{.hIf=%RX32}\n", pIf, pIf->hIf));535 int rc = intnetR ingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pvFrame, cbFrame);536 static void intnetR0IfSend(PINTNETIF pIf, const void *pvFrame, unsigned cbFrame) 537 { 538 LogFlow(("intnetR0IfSend: pIf=%p:{.hIf=%RX32}\n", pIf, pIf->hIf)); 539 int rc = intnetR0RingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pvFrame, cbFrame); 536 540 if (RT_SUCCESS(rc)) 537 541 { … … 554 558 RTSemEventSignal(pIf->Event); 555 559 RTThreadYield(); 556 rc = intnetR ingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pvFrame, cbFrame);560 rc = intnetR0RingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pvFrame, cbFrame); 557 561 if (RT_SUCCESS(rc)) 558 562 { … … 587 591 * @param cbFrame The size of the frame. 588 592 */ 589 static void intnet NetworkSend(PINTNETNETWORK pNetwork, PINTNETIF pIfSender, const void *pvFrame, unsigned cbFrame)593 static void intnetR0NetworkSend(PINTNETNETWORK pNetwork, PINTNETIF pIfSender, const void *pvFrame, unsigned cbFrame) 590 594 { 591 595 /* … … 632 636 for (PINTNETIF pIf = pNetwork->pIFs; pIf; pIf = pIf->pNext) 633 637 if (pIf != pIfSender) 634 intnet IfSend(pIf, pvFrame, cbFrame);638 intnetR0IfSend(pIf, pvFrame, cbFrame); 635 639 } 636 640 else … … 647 651 || ( pIf->fPromiscuous 648 652 && pIf != pIfSender /* promiscuous mode: omit the sender */)) 649 intnet IfSend(pIf, pvFrame, cbFrame);653 intnetR0IfSend(pIf, pvFrame, cbFrame); 650 654 } 651 655 } … … 675 679 */ 676 680 AssertReturn(pIntNet, VERR_INVALID_PARAMETER); 677 PINTNETIF pIf = intnet Handle2IFPtr(&pIntNet->IfHandles, hIf);681 PINTNETIF pIf = intnetR0Handle2IFPtr(&pIntNet->IfHandles, hIf); 678 682 if (!pIf) 679 683 return VERR_INVALID_HANDLE; … … 696 700 */ 697 701 if (pvFrame && cbFrame) 698 intnet NetworkSend(pIf->pNetwork, pIf, pvFrame, cbFrame);702 intnetR0NetworkSend(pIf->pNetwork, pIf, pvFrame, cbFrame); 699 703 700 704 /* … … 709 713 void *pvCurFrame = INTNETHdrGetFramePtr(pHdr, pIf->pIntBuf); 710 714 if (pvCurFrame) 711 intnet NetworkSend(pIf->pNetwork, pIf, pvCurFrame, pHdr->cbFrame);715 intnetR0NetworkSend(pIf->pNetwork, pIf, pvCurFrame, pHdr->cbFrame); 712 716 } 713 717 /* else: ignore the frame */ … … 752 756 */ 753 757 AssertReturn(pIntNet, VERR_INVALID_PARAMETER); 754 PINTNETIF pIf = intnet Handle2IFPtr(&pIntNet->IfHandles, hIf);758 PINTNETIF pIf = intnetR0Handle2IFPtr(&pIntNet->IfHandles, hIf); 755 759 if (!pIf) 756 760 return VERR_INVALID_HANDLE; … … 807 811 *ppRing0Buf = NULL; 808 812 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 809 PINTNETIF pIf = intnet Handle2IFPtr(&pIntNet->IfHandles, hIf);813 PINTNETIF pIf = intnetR0Handle2IFPtr(&pIntNet->IfHandles, hIf); 810 814 if (!pIf) 811 815 return VERR_INVALID_HANDLE; … … 843 847 */ 844 848 AssertReturn(pIntNet, VERR_INVALID_PARAMETER); 845 PINTNETIF pIf = intnet Handle2IFPtr(&pIntNet->IfHandles, hIf);849 PINTNETIF pIf = intnetR0Handle2IFPtr(&pIntNet->IfHandles, hIf); 846 850 if (!pIf) 847 851 return VERR_INVALID_HANDLE; … … 884 888 */ 885 889 AssertReturn(pIntNet, VERR_INVALID_PARAMETER); 886 PINTNETIF pIf = intnet Handle2IFPtr(&pIntNet->IfHandles, hIf);890 PINTNETIF pIf = intnetR0Handle2IFPtr(&pIntNet->IfHandles, hIf); 887 891 if (!pIf) 888 892 { … … 894 898 * Grab the network semaphore and make the change. 895 899 */ 896 int rc = RTSemFastMutexRequest(pIf->pNetwork->FastMutex); 900 PINTNETNETWORK pNetwork = pIf->pNetwork; 901 if (!pNetwork) 902 return VERR_WRONG_ORDER; 903 int rc = RTSemFastMutexRequest(pNetwork->FastMutex); 897 904 if (RT_FAILURE(rc)) 898 905 return rc; … … 905 912 } 906 913 907 RTSemFastMutexRelease(p If->pNetwork->FastMutex);914 RTSemFastMutexRelease(pNetwork->FastMutex); 908 915 return VINF_SUCCESS; 909 916 } … … 922 929 return VERR_INVALID_PARAMETER; 923 930 return INTNETR0IfSetPromiscuousMode(pIntNet, pReq->hIf, pReq->fPromiscuous); 931 } 932 933 934 /** 935 * Worker for intnetR0IfSetActive. 936 * 937 * This function will update the active interface count on the network and 938 * activate or deactivate the trunk connection if necessary. Note that in 939 * order to do this it is necessary to abandond the network semaphore. 940 * 941 * @returns VBox status code. 942 * @param pNetwork The network. 943 * @param fIf The interface. 944 * @param fActive What to do. 945 */ 946 static int intnetR0NetworkSetIfActive(PINTNETNETWORK pNetwork, PINTNETIF pIf, bool fActive) 947 { 948 /* quick santiy check */ 949 AssertPtr(pNetwork); 950 AssertPtr(pIf); 951 952 /* 953 * If we've got a trunk, lock it now in case we need to call out, and 954 * then lock the network. 955 */ 956 PINTNETTRUNKIF pTrunkIf = pNetwork->pTrunkIF; 957 if (pTrunkIf && !intnetR0TrunkIfOutLock(pTrunkIf)) 958 return VERR_SEM_DESTROYED; 959 960 int rc = RTSemFastMutexRequest(pNetwork->FastMutex); AssertRC(rc); 961 if (RT_SUCCESS(rc)) 962 { 963 bool fNetworkLocked = true; 964 965 /* 966 * Make the change if necessary. 967 */ 968 if (pIf->fActive != fActive) 969 { 970 pIf->fActive = fActive; 971 972 uint32_t const cActiveIFs = pNetwork->cActiveIFs; 973 Assert((int32_t)cActiveIFs + (fActive ? 1 : -1) >= 0); 974 pNetwork->cActiveIFs += fActive ? 1 : -1; 975 976 if ( pTrunkIf 977 && ( !pNetwork->cActiveIFs 978 || !cActiveIFs)) 979 { 980 /* 981 * We'll have to change the trunk status, so, leave 982 * the network semaphore so we don't create any deadlocks. 983 */ 984 int rc2 = RTSemFastMutexRelease(pNetwork->FastMutex); AssertRC(rc2); 985 fNetworkLocked = false; 986 987 if (pTrunkIf->pIfPort) 988 pTrunkIf->pIfPort->pfnSetActive(pTrunkIf->pIfPort, fActive); 989 } 990 } 991 992 if (fNetworkLocked) 993 RTSemFastMutexRelease(pNetwork->FastMutex); 994 } 995 if (pTrunkIf) 996 intnetR0TrunkIfOutUnlock(pTrunkIf); 997 return rc; 998 } 999 1000 1001 /** 1002 * Activates or deactivates a interface. 1003 * 1004 * This is used to enable and disable the trunk connection on demans as well as 1005 * know when not to expect an interface to want to receive packets. 1006 * 1007 * @returns VBox status code. 1008 * @param pIf The interface. 1009 * @param fActive What to do. 1010 */ 1011 static int intnetR0IfSetActive(PINTNETIF pIf, bool fActive) 1012 { 1013 /* quick sanity check */ 1014 AssertPtrReturn(pIf, VERR_INVALID_POINTER); 1015 1016 /* 1017 * Hand it to the network since it might involve the trunk 1018 * and things are tricky there wrt to locking order. 1019 */ 1020 PINTNETNETWORK pNetwork = pIf->pNetwork; 1021 if (!pNetwork) 1022 return VERR_WRONG_ORDER; 1023 return intnetR0NetworkSetIfActive(pNetwork, pIf, fActive); 924 1024 } 925 1025 … … 943 1043 */ 944 1044 AssertReturn(pIntNet, VERR_INVALID_PARAMETER); 945 PINTNETIF pIf = intnet Handle2IFPtr(&pIntNet->IfHandles, hIf);1045 PINTNETIF pIf = intnetR0Handle2IFPtr(&pIntNet->IfHandles, hIf); 946 1046 if (!pIf) 947 1047 { … … 1015 1115 */ 1016 1116 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 1017 PINTNETIF pIf = intnet HandleFree(&pIntNet->IfHandles, hIf);1117 PINTNETIF pIf = intnetR0HandleFree(&pIntNet->IfHandles, hIf); 1018 1118 if (!pIf) 1019 1119 return VERR_INVALID_HANDLE; … … 1052 1152 * @param pvUser2 Pointer to the INTNET instance data. 1053 1153 */ 1054 static DECLCALLBACK(void) intnet IfDestruct(void *pvObj, void *pvUser1, void *pvUser2)1055 { 1056 LogFlow(("intnet IfDestruct: pvObj=%p pvUser1=%p pvUser2=%p\n", pvObj, pvUser1, pvUser2));1154 static DECLCALLBACK(void) intnetR0IfDestruct(void *pvObj, void *pvUser1, void *pvUser2) 1155 { 1156 LogFlow(("intnetR0IfDestruct: pvObj=%p pvUser1=%p pvUser2=%p\n", pvObj, pvUser1, pvUser2)); 1057 1157 PINTNETIF pIf = (PINTNETIF)pvUser1; 1058 1158 PINTNET pIntNet = (PINTNET)pvUser2; … … 1065 1165 INTNETIFHANDLE hIf = ASMAtomicXchgU32(&pIf->hIf, INTNET_HANDLE_INVALID); 1066 1166 if (hIf != INTNET_HANDLE_INVALID) 1067 intnet HandleFree(&pIntNet->IfHandles, hIf);1068 1069 /* 1070 * If we've got a network unlink ourselves from it.1167 intnetR0HandleFree(&pIntNet->IfHandles, hIf); 1168 1169 /* 1170 * If we've got a network deactivate and unlink ourselves from it. 1071 1171 * Because of cleanup order we might be an orphan now. 1072 1172 */ … … 1074 1174 if (pNetwork) 1075 1175 { 1176 intnetR0IfSetActive(pIf, false); 1177 1076 1178 if (pNetwork->pIFs == pIf) 1077 1179 pNetwork->pIFs = pIf->pNext; … … 1176 1278 * @param phIf Where to store the interface handle. 1177 1279 */ 1178 static int intnet NetworkCreateIf(PINTNETNETWORK pNetwork, PSUPDRVSESSION pSession, unsigned cbSend, unsigned cbRecv, PINTNETIFHANDLE phIf)1179 { 1180 LogFlow(("intnet NetworkCreateIf: pNetwork=%p pSession=%p cbSend=%u cbRecv=%u phIf=%p\n",1280 static int intnetR0NetworkCreateIf(PINTNETNETWORK pNetwork, PSUPDRVSESSION pSession, unsigned cbSend, unsigned cbRecv, bool *pfCloseNetwork, PINTNETIFHANDLE phIf) 1281 { 1282 LogFlow(("intnetR0NetworkCreateIf: pNetwork=%p pSession=%p cbSend=%u cbRecv=%u phIf=%p\n", 1181 1283 pNetwork, pSession, cbSend, cbRecv, phIf)); 1182 1284 … … 1186 1288 AssertPtr(pNetwork); 1187 1289 AssertPtr(phIf); 1290 AssertPtr(pfCloseNetwork); 1291 *pfCloseNetwork = false; 1188 1292 1189 1293 /* … … 1193 1297 if (!pIf) 1194 1298 return VERR_NO_MEMORY; 1195 1299 //pIf->pNext = NULL; 1196 1300 memset(&pIf->Mac, 0xff, sizeof(pIf->Mac)); /* broadcast */ 1197 //pIf->fMacSet = 0; 1301 //pIf->fMacSet = false; 1302 //pIf->fPromiscuous = false; 1303 //pIf->fActive = false; 1304 //pIf->pIntBuf = 0; 1305 //pIf->pIntBufR3 = NIL_RTR3PTR; 1306 //pIf->pIntBufDefault = 0; 1307 //pIf->pIntBufDefaultR3 = NIL_RTR3PTR; 1308 //pIf->cYields = 0; 1309 pIf->Event = NIL_RTSEMEVENT; 1310 //pIf->cSleepers = 0; 1311 pIf->hIf = INTNET_HANDLE_INVALID; 1312 pIf->pNetwork = pNetwork; 1313 pIf->pSession = pSession; 1314 //pIf->pvObj = NULL; 1198 1315 int rc = RTSemEventCreate(&pIf->Event); 1199 1316 if (RT_SUCCESS(rc)) 1200 1317 { 1201 pIf->pSession = pSession;1202 pIf->pNetwork = pNetwork;1203 1204 1318 /* 1205 1319 * Create the default buffer. … … 1240 1354 * Register the interface with the session. 1241 1355 */ 1242 pIf->pvObj = SUPR0ObjRegister(pSession, SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE, intnet IfDestruct, pIf, pNetwork->pIntNet);1356 pIf->pvObj = SUPR0ObjRegister(pSession, SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE, intnetR0IfDestruct, pIf, pNetwork->pIntNet); 1243 1357 if (pIf->pvObj) 1244 1358 { 1245 pIf->hIf = intnet HandleAllocate(pNetwork->pIntNet, pIf);1359 pIf->hIf = intnetR0HandleAllocate(pNetwork->pIntNet, pIf); 1246 1360 if (pIf->hIf != INTNET_HANDLE_INVALID) 1247 1361 { 1362 /* auto activation */ /** @todo do this manually in the future, ditto for setting the MAC address. */ 1363 rc = intnetR0IfSetActive(pIf, true /* activate */); 1364 AssertRC(rc); 1365 1248 1366 *phIf = pIf->hIf; 1249 LogFlow(("intnet NetworkCreateIf: returns VINF_SUCCESS *phIf=%p\n", *phIf));1367 LogFlow(("intnetR0NetworkCreateIf: returns VINF_SUCCESS *phIf=%p\n", *phIf)); 1250 1368 return VINF_SUCCESS; 1251 1369 } … … 1253 1371 1254 1372 SUPR0ObjRelease(pIf->pvObj, pSession); 1255 LogFlow(("intnet NetworkCreateIf: returns %Rrc\n", rc));1373 LogFlow(("intnetR0NetworkCreateIf: returns %Rrc\n", rc)); 1256 1374 return rc; 1257 1375 } 1376 1258 1377 rc = VERR_NO_MEMORY; 1259 1378 RTSemFastMutexDestroy(pNetwork->FastMutex); 1260 1379 pNetwork->FastMutex = NIL_RTSEMFASTMUTEX; 1261 1380 } 1381 1262 1382 SUPR0MemFree(pIf->pSession, (RTHCUINTPTR)pIf->pIntBufDefault); 1263 1383 pIf->pIntBufDefault = NULL; … … 1269 1389 } 1270 1390 RTMemFree(pIf); 1271 LogFlow(("intnetNetworkCreateIf: returns %Rrc\n", rc)); 1391 LogFlow(("intnetR0NetworkCreateIf: returns %Rrc\n", rc)); 1392 *pfCloseNetwork = true; 1272 1393 return rc; 1273 1394 } … … 1278 1399 1279 1400 /** @copydoc INTNETTRUNKSWPORT::pfnSetSGPhys */ 1280 static DECLCALLBACK(bool) intnet TrunkIfPortSetSGPhys(PINTNETTRUNKSWPORT pSwitchPort, bool fEnable)1401 static DECLCALLBACK(bool) intnetR0TrunkIfPortSetSGPhys(PINTNETTRUNKSWPORT pSwitchPort, bool fEnable) 1281 1402 { 1282 1403 PINTNETTRUNKIF pThis = INTNET_SWITCHPORT_2_TRUNKIF(pSwitchPort); … … 1287 1408 1288 1409 /** @copydoc INTNETTRUNKSWPORT::pfnRecv */ 1289 static DECLCALLBACK(bool) intnet TrunkIfPortRecv(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG, uint32_t fSrc)1410 static DECLCALLBACK(bool) intnetR0TrunkIfPortRecv(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG, uint32_t fSrc) 1290 1411 { 1291 1412 PINTNETTRUNKIF pThis = INTNET_SWITCHPORT_2_TRUNKIF(pSwitchPort); … … 1308 1429 1309 1430 /** @copydoc INTNETTRUNKSWPORT::pfnSGRetain */ 1310 static DECLCALLBACK(void) intnet TrunkIfPortSGRetain(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG)1431 static DECLCALLBACK(void) intnetR0TrunkIfPortSGRetain(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG) 1311 1432 { 1312 1433 PINTNETTRUNKIF pThis = INTNET_SWITCHPORT_2_TRUNKIF(pSwitchPort); … … 1325 1446 1326 1447 /** @copydoc INTNETTRUNKSWPORT::pfnSGRelease */ 1327 static DECLCALLBACK(void) intnet TrunkIfPortSGRelease(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG)1448 static DECLCALLBACK(void) intnetR0TrunkIfPortSGRelease(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG) 1328 1449 { 1329 1450 PINTNETTRUNKIF pThis = INTNET_SWITCHPORT_2_TRUNKIF(pSwitchPort); … … 1355 1476 * @remarks Any locks. 1356 1477 */ 1357 static PINTNETTRUNKIF intnet TrunkIfRetain(PINTNETTRUNKIF pThis)1478 static PINTNETTRUNKIF intnetR0TrunkIfRetain(PINTNETTRUNKIF pThis) 1358 1479 { 1359 1480 if (pThis && pThis->pIfPort) … … 1368 1489 * @param pThis The trunk. 1369 1490 */ 1370 static void intnet TrunkIfRelease(PINTNETTRUNKIF pThis)1491 static void intnetR0TrunkIfRelease(PINTNETTRUNKIF pThis) 1371 1492 { 1372 1493 if (pThis && pThis->pIfPort) … … 1385 1506 * @remarks No locks other than the create/destroy one. 1386 1507 */ 1387 static bool intnet TrunkIfOutLock(PINTNETTRUNKIF pThis)1508 static bool intnetR0TrunkIfOutLock(PINTNETTRUNKIF pThis) 1388 1509 { 1389 1510 AssertPtrReturn(pThis, false); … … 1406 1527 * @param pThis The trunk. 1407 1528 */ 1408 static void intnet TrunkIfOutUnlock(PINTNETTRUNKIF pThis)1529 static void intnetR0TrunkIfOutUnlock(PINTNETTRUNKIF pThis) 1409 1530 { 1410 1531 if (pThis) … … 1424 1545 * @remarks Caller may only own the create/destroy lock. 1425 1546 */ 1426 static void intnet TrunkIfActivate(PINTNETTRUNKIF pThis, bool fActive)1427 { 1428 if (intnet TrunkIfOutLock(pThis))1547 static void intnetR0TrunkIfActivate(PINTNETTRUNKIF pThis, bool fActive) 1548 { 1549 if (intnetR0TrunkIfOutLock(pThis)) 1429 1550 { 1430 1551 pThis->pIfPort->pfnSetActive(pThis->pIfPort, fActive); 1431 intnet TrunkIfOutUnlock(pThis);1552 intnetR0TrunkIfOutUnlock(pThis); 1432 1553 } 1433 1554 } … … 1443 1564 * create/destroy lock is fine though. 1444 1565 */ 1445 static void intnet TrunkIfDestroy(PINTNETTRUNKIF pThis, PINTNETNETWORK pNetwork)1566 static void intnetR0TrunkIfDestroy(PINTNETTRUNKIF pThis, PINTNETNETWORK pNetwork) 1446 1567 { 1447 1568 /* assert sanity */ … … 1459 1580 if (pIfPort) 1460 1581 { 1461 intnet TrunkIfOutLock(pThis);1582 intnetR0TrunkIfOutLock(pThis); 1462 1583 1463 1584 /* unset it */ … … 1515 1636 * @param pSession The session handle. 1516 1637 */ 1517 static int intnet NetworkCreateTrunkConnection(PINTNETNETWORK pNetwork, PSUPDRVSESSION pSession)1638 static int intnetR0NetworkCreateTrunkIf(PINTNETNETWORK pNetwork, PSUPDRVSESSION pSession) 1518 1639 { 1519 1640 const char *pszName; … … 1552 1673 return VERR_NO_MEMORY; 1553 1674 pTrunkIF->SwitchPort.u32Version = INTNETTRUNKSWPORT_VERSION; 1554 pTrunkIF->SwitchPort.pfnSetSGPhys = intnet TrunkIfPortSetSGPhys;1555 pTrunkIF->SwitchPort.pfnRecv = intnet TrunkIfPortRecv;1556 pTrunkIF->SwitchPort.pfnSGRetain = intnet TrunkIfPortSGRetain;1557 pTrunkIF->SwitchPort.pfnSGRelease = intnet TrunkIfPortSGRelease;1675 pTrunkIF->SwitchPort.pfnSetSGPhys = intnetR0TrunkIfPortSetSGPhys; 1676 pTrunkIF->SwitchPort.pfnRecv = intnetR0TrunkIfPortRecv; 1677 pTrunkIF->SwitchPort.pfnSGRetain = intnetR0TrunkIfPortSGRetain; 1678 pTrunkIF->SwitchPort.pfnSGRelease = intnetR0TrunkIfPortSGRelease; 1558 1679 pTrunkIF->SwitchPort.u32VersionEnd = INTNETTRUNKSWPORT_VERSION; 1559 1680 //pTrunkIF->pIfPort = NULL; … … 1577 1698 Assert(pTrunkIF->pIfPort); 1578 1699 pNetwork->pTrunkIF = pTrunkIF; 1579 LogFlow(("intnet NetworkCreateTrunkConnection: VINF_SUCCESS - pszName=%s szTrunk=%s Network=%s\n",1700 LogFlow(("intnetR0NetworkCreateTrunkIf: VINF_SUCCESS - pszName=%s szTrunk=%s Network=%s\n", 1580 1701 rc, pszName, pNetwork->szTrunk, pNetwork->szName)); 1581 1702 return VINF_SUCCESS; … … 1586 1707 } 1587 1708 RTMemFree(pTrunkIF); 1588 LogFlow(("intnet NetworkCreateTrunkConnection: %Rrc - pszName=%s szTrunk=%s Network=%s\n",1709 LogFlow(("intnetR0NetworkCreateTrunkIf: %Rrc - pszName=%s szTrunk=%s Network=%s\n", 1589 1710 rc, pszName, pNetwork->szTrunk, pNetwork->szName)); 1590 1711 return rc; … … 1594 1715 1595 1716 /** 1596 * Close a network which was opened/created using intnet OpenNetwork()/intnetCreateNetwork().1717 * Close a network which was opened/created using intnetR0OpenNetwork()/intnetR0CreateNetwork(). 1597 1718 * 1598 1719 * @param pNetwork The network to close. 1599 1720 * @param pSession The session handle. 1600 1721 */ 1601 static int intnet NetworkClose(PINTNETNETWORK pNetwork, PSUPDRVSESSION pSession)1602 { 1603 LogFlow(("intnet NetworkClose: pNetwork=%p pSession=%p\n", pNetwork, pSession));1722 static int intnetR0NetworkClose(PINTNETNETWORK pNetwork, PSUPDRVSESSION pSession) 1723 { 1724 LogFlow(("intnetR0NetworkClose: pNetwork=%p pSession=%p\n", pNetwork, pSession)); 1604 1725 AssertPtrReturn(pSession, VERR_INVALID_PARAMETER); 1605 1726 AssertPtrReturn(pNetwork, VERR_INVALID_PARAMETER); 1606 1727 1607 1728 int rc = SUPR0ObjRelease(pNetwork->pvObj, pSession); 1608 LogFlow(("intnet NetworkClose: return %Rrc\n", rc));1729 LogFlow(("intnetR0NetworkClose: return %Rrc\n", rc)); 1609 1730 return rc; 1610 1731 } … … 1619 1740 * @param pvUser2 Pointer to the INTNET instance data. 1620 1741 */ 1621 static DECLCALLBACK(void) intnet NetworkDestruct(void *pvObj, void *pvUser1, void *pvUser2)1622 { 1623 LogFlow(("intnet NetworkDestruct: pvObj=%p pvUser1=%p pvUser2=%p\n", pvObj, pvUser1, pvUser2));1742 static DECLCALLBACK(void) intnetR0NetworkDestruct(void *pvObj, void *pvUser1, void *pvUser2) 1743 { 1744 LogFlow(("intnetR0NetworkDestruct: pvObj=%p pvUser1=%p pvUser2=%p\n", pvObj, pvUser1, pvUser2)); 1624 1745 PINTNETNETWORK pNetwork = (PINTNETNETWORK)pvUser1; 1625 1746 PINTNET pIntNet = (PINTNET)pvUser2; … … 1633 1754 */ 1634 1755 if (pNetwork->pTrunkIF) 1635 intnet TrunkIfActivate(pNetwork->pTrunkIF, false /* fActive */);1756 intnetR0TrunkIfActivate(pNetwork->pTrunkIF, false /* fActive */); 1636 1757 1637 1758 /* … … 1681 1802 */ 1682 1803 if (pTrunkIF) 1683 intnet TrunkIfDestroy(pTrunkIF, pNetwork);1804 intnetR0TrunkIfDestroy(pTrunkIF, pNetwork); 1684 1805 1685 1806 /* … … 1707 1828 * @param ppNetwork Where to store the pointer to the network on success. 1708 1829 */ 1709 static int intnet OpenNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType,1710 const char *pszTrunk, uint32_t fFlags, PINTNETNETWORK *ppNetwork)1711 { 1712 LogFlow(("intnet OpenNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x ppNetwork=%p\n",1830 static int intnetR0OpenNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType, 1831 const char *pszTrunk, uint32_t fFlags, PINTNETNETWORK *ppNetwork) 1832 { 1833 LogFlow(("intnetR0OpenNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x ppNetwork=%p\n", 1713 1834 pIntNet, pSession, pszNetwork, pszNetwork, enmTrunkType, pszTrunk, pszTrunk, fFlags, ppNetwork)); 1714 1835 … … 1771 1892 rc = VERR_INTNET_INCOMPATIBLE_TRUNK; 1772 1893 1773 LogFlow(("intnet OpenNetwork: returns %Rrc *ppNetwork=%p\n", rc, *ppNetwork));1894 LogFlow(("intnetR0OpenNetwork: returns %Rrc *ppNetwork=%p\n", rc, *ppNetwork)); 1774 1895 return rc; 1775 1896 } … … 1777 1898 } 1778 1899 1779 LogFlow(("intnet OpenNetwork: returns VERR_NOT_FOUND\n"));1900 LogFlow(("intnetR0OpenNetwork: returns VERR_NOT_FOUND\n")); 1780 1901 return VERR_NOT_FOUND; 1781 1902 } … … 1799 1920 * here should be dereferenced outside the INTNET::FastMutex. 1800 1921 */ 1801 static int intnet CreateNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType,1802 const char *pszTrunk, uint32_t fFlags, PINTNETNETWORK *ppNetwork)1803 { 1804 LogFlow(("intnet CreateNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x ppNetwork=%p\n",1922 static int intnetR0CreateNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType, 1923 const char *pszTrunk, uint32_t fFlags, PINTNETNETWORK *ppNetwork) 1924 { 1925 LogFlow(("intnetR0CreateNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x ppNetwork=%p\n", 1805 1926 pIntNet, pSession, pszNetwork, pszNetwork, enmTrunkType, pszTrunk, pszTrunk, fFlags, ppNetwork)); 1806 1927 … … 1826 1947 //pNew->pIFs = NULL; 1827 1948 pNew->pIntNet = pIntNet; 1949 //pNew->cActiveIFs = 0; 1828 1950 pNew->fFlags = fFlags; 1829 1951 size_t cchName = strlen(pszNetwork); … … 1838 1960 * Register the object in the current session and link it into the network list. 1839 1961 */ 1840 pNew->pvObj = SUPR0ObjRegister(pSession, SUPDRVOBJTYPE_INTERNAL_NETWORK, intnet NetworkDestruct, pNew, pIntNet);1962 pNew->pvObj = SUPR0ObjRegister(pSession, SUPDRVOBJTYPE_INTERNAL_NETWORK, intnetR0NetworkDestruct, pNew, pIntNet); 1841 1963 if (pNew->pvObj) 1842 1964 { … … 1855 1977 * Connect the trunk. 1856 1978 */ 1857 #ifdef IN_RING0 1858 rc = intnetNetworkCreateTrunkConnection(pNew, pSession); 1859 #endif 1979 rc = intnetR0NetworkCreateTrunkIf(pNew, pSession); 1860 1980 if (RT_SUCCESS(rc)) 1861 1981 { 1862 1982 *ppNetwork = pNew; 1863 LogFlow(("intnet CreateNetwork: returns VINF_SUCCESS *ppNetwork=%p\n", pNew));1983 LogFlow(("intnetR0CreateNetwork: returns VINF_SUCCESS *ppNetwork=%p\n", pNew)); 1864 1984 return VINF_SUCCESS; 1865 1985 } … … 1875 1995 1876 1996 *ppNetwork = pNew; 1877 LogFlow(("intnet CreateNetwork: returns %Rrc\n", rc));1997 LogFlow(("intnetR0CreateNetwork: returns %Rrc\n", rc)); 1878 1998 return rc; 1879 1999 } … … 1884 2004 } 1885 2005 RTMemFree(pNew); 1886 LogFlow(("intnet CreateNetwork: returns %Rrc\n", rc));2006 LogFlow(("intnetR0CreateNetwork: returns %Rrc\n", rc)); 1887 2007 return rc; 1888 2008 } … … 1963 2083 * Note that because of the destructors grabbing INTNET::FastMutex and us being required 1964 2084 * to own this semaphore for the entire network opening / creation and interface creation 1965 * sequence, intnet CreateNetwork will have to defer the network cleanup to us on failure.2085 * sequence, intnetR0CreateNetwork will have to defer the network cleanup to us on failure. 1966 2086 */ 1967 2087 PINTNETNETWORK pNetwork = NULL; 1968 rc = intnet OpenNetwork(pIntNet, pSession, pszNetwork, enmTrunkType, pszTrunk, fFlags, &pNetwork);2088 rc = intnetR0OpenNetwork(pIntNet, pSession, pszNetwork, enmTrunkType, pszTrunk, fFlags, &pNetwork); 1969 2089 if (RT_SUCCESS(rc) || rc == VERR_NOT_FOUND) 1970 2090 { 2091 bool fCloseNetwork = true; 1971 2092 if (rc == VERR_NOT_FOUND) 1972 rc = intnet CreateNetwork(pIntNet, pSession, pszNetwork, enmTrunkType, pszTrunk, fFlags, &pNetwork);2093 rc = intnetR0CreateNetwork(pIntNet, pSession, pszNetwork, enmTrunkType, pszTrunk, fFlags, &pNetwork); 1973 2094 if (RT_SUCCESS(rc)) 1974 rc = intnet NetworkCreateIf(pNetwork, pSession, cbSend, cbRecv, phIf);2095 rc = intnetR0NetworkCreateIf(pNetwork, pSession, cbSend, cbRecv, &fCloseNetwork, phIf); 1975 2096 1976 2097 RTSemFastMutexRelease(pIntNet->FastMutex); 1977 2098 1978 if (RT_FAILURE(rc) && pNetwork )1979 intnet NetworkClose(pNetwork, pSession);2099 if (RT_FAILURE(rc) && pNetwork && fCloseNetwork) 2100 intnetR0NetworkClose(pNetwork, pSession); 1980 2101 } 1981 2102 else -
trunk/src/VBox/Devices/Network/testcase/tstIntNetR0.cpp
r10681 r10711 238 238 int rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, abBuf, cb); 239 239 #else 240 int rc = intnetR ingWriteFrame(pArgs->pBuf, &pArgs->pBuf->Send, abBuf, cb);240 int rc = intnetR0RingWriteFrame(pArgs->pBuf, &pArgs->pBuf->Send, abBuf, cb); 241 241 if (RT_SUCCESS(rc)) 242 242 rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, NULL, 0); … … 315 315 { 316 316 uint8_t abBuf[16384]; 317 unsigned cb = intnetR ingReadFrame(pArgs->pBuf, &pArgs->pBuf->Recv, abBuf);317 unsigned cb = intnetR0RingReadFrame(pArgs->pBuf, &pArgs->pBuf->Recv, abBuf); 318 318 unsigned *puFrame = (unsigned *)&abBuf[sizeof(PDMMAC) * 2]; 319 319 … … 461 461 g_cErrors++; 462 462 } 463 unsigned cb = intnetR ingReadFrame(pBuf1, &pBuf1->Recv, abBuf);463 unsigned cb = intnetR0RingReadFrame(pBuf1, &pBuf1->Recv, abBuf); 464 464 if (cb != sizeof(g_TestFrame0)) 465 465 {
Note:
See TracChangeset
for help on using the changeset viewer.