Changeset 10843 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Jul 23, 2008 9:49:52 PM (16 years ago)
- Location:
- trunk/src/VBox/Devices/Network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DrvIntNet.cpp
r10762 r10843 72 72 /** The network interface. */ 73 73 PPDMINETWORKPORT pPort; 74 /** The network config interface. 75 * Can (in theory at least) be NULL. */ 76 PPDMINETWORKCONFIG pConfigIf; 74 77 /** Pointer to the driver instance. */ 75 78 PPDMDRVINS pDrvIns; … … 111 114 /** Converts a pointer to DRVINTNET::INetworkConnector to a PDRVINTNET. */ 112 115 #define PDMINETWORKCONNECTOR_2_DRVINTNET(pInterface) ( (PDRVINTNET)((uintptr_t)pInterface - RT_OFFSETOF(DRVINTNET, INetworkConnector)) ) 116 117 118 /** 119 * Updates the MAC address on the kernel side. 120 * 121 * @returns VBox status code. 122 * @param pThis The driver instance. 123 */ 124 static int drvIntNetUpdateMacAddress(PDRVINTNET pThis) 125 { 126 if (!pThis->pConfigIf) 127 return VINF_SUCCESS; 128 129 INTNETIFSETMACADDRESSREQ SetMacAddressReq; 130 SetMacAddressReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC; 131 SetMacAddressReq.Hdr.cbReq = sizeof(SetMacAddressReq); 132 SetMacAddressReq.pSession = NIL_RTR0PTR; 133 SetMacAddressReq.hIf = pThis->hIf; 134 int rc = pThis->pConfigIf->pfnGetMac(pThis->pConfigIf, &SetMacAddressReq.Mac); 135 if (RT_SUCCESS(rc)) 136 rc = pThis->pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pThis->pDrvIns, VMMR0_DO_INTNET_IF_SET_MAC_ADDRESS, 137 &SetMacAddressReq, sizeof(SetMacAddressReq)); 138 139 Log(("drvIntNetUpdateMacAddress: %.*Rhxs rc=%Rrc\n", sizeof(SetMacAddressReq.Mac), &SetMacAddressReq.Mac, rc)); 140 return rc; 141 } 142 143 144 /** 145 * Sets the kernel interface active or inactive. 146 * 147 * Worker for poweron, poweroff, suspend and resume. 148 * 149 * @returns VBox status code. 150 * @param pThis The driver instance. 151 * @param fActive The new state. 152 */ 153 static int drvIntNetSetActive(PDRVINTNET pThis, bool fActive) 154 { 155 if (!pThis->pConfigIf) 156 return VINF_SUCCESS; 157 158 INTNETIFSETACTIVEREQ SetActiveReq; 159 SetActiveReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC; 160 SetActiveReq.Hdr.cbReq = sizeof(SetActiveReq); 161 SetActiveReq.pSession = NIL_RTR0PTR; 162 SetActiveReq.hIf = pThis->hIf; 163 SetActiveReq.fActive = fActive; 164 int rc = pThis->pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pThis->pDrvIns, VMMR0_DO_INTNET_IF_SET_ACTIVE, 165 &SetActiveReq, sizeof(SetActiveReq)); 166 167 Log(("drvIntNetUpdateMacAddress: fActive=%d rc=%Rrc\n", fActive, rc)); 168 AssertRC(rc); 169 return rc; 170 } 113 171 114 172 … … 541 599 PDRVINTNET pThis = PDMINS2DATA(pDrvIns, PDRVINTNET); 542 600 if (!pThis->fActivateEarlyDeactivateLate) 601 { 543 602 ASMAtomicXchgSize(&pThis->enmState, ASYNCSTATE_SUSPENDED); 603 drvIntNetSetActive(pThis, false /* fActive */); 604 } 544 605 } 545 606 … … 558 619 ASMAtomicXchgSize(&pThis->enmState, ASYNCSTATE_RUNNING); 559 620 RTSemEventSignal(pThis->EventSuspended); 621 drvIntNetUpdateMacAddress(pThis); /* (could be a state restore) */ 622 drvIntNetSetActive(pThis, true /* fActive */); 560 623 } 561 624 } … … 572 635 PDRVINTNET pThis = PDMINS2DATA(pDrvIns, PDRVINTNET); 573 636 if (!pThis->fActivateEarlyDeactivateLate) 637 { 574 638 ASMAtomicXchgSize(&pThis->enmState, ASYNCSTATE_SUSPENDED); 639 drvIntNetSetActive(pThis, false /* fActive */); 640 } 575 641 } 576 642 … … 589 655 ASMAtomicXchgSize(&pThis->enmState, ASYNCSTATE_RUNNING); 590 656 RTSemEventSignal(pThis->EventSuspended); 657 drvIntNetUpdateMacAddress(pThis); 658 drvIntNetSetActive(pThis, true /* fActive */); 591 659 } 592 660 } … … 704 772 return VERR_PDM_MISSING_INTERFACE_ABOVE; 705 773 } 774 pThis->pConfigIf = (PPDMINETWORKCONFIG)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_NETWORK_CONFIG); 706 775 707 776 /* … … 887 956 ASMAtomicXchgSize(&pThis->enmState, ASYNCSTATE_RUNNING); 888 957 RTSemEventSignal(pThis->EventSuspended); 958 drvIntNetUpdateMacAddress(pThis); 959 drvIntNetSetActive(pThis, true /* fActive */); 889 960 } 890 961 -
trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp
r10819 r10843 1167 1167 1168 1168 /** 1169 * Sets the MAC address of an interface. 1170 * 1171 * @returns VBox status code. 1172 * @param pIntNet The instance handle. 1173 * @param hIf The interface handle. 1174 * @param pSession The caller's session. 1175 * @param pMAC The new MAC address. 1176 */ 1177 INTNETR0DECL(int) INTNETR0IfSetMacAddress(PINTNET pIntNet, INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, PCPDMMAC pMac) 1178 { 1179 LogFlow(("INTNETR0IfSetMacAddress: pIntNet=%p hIf=%RX32 pMac=%p:{%.6Rhxs}\n", pIntNet, hIf, pMac, pMac)); 1180 1181 /* 1182 * Validate & translate input. 1183 */ 1184 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 1185 AssertPtrReturn(pMac, VERR_INVALID_PARAMETER); 1186 PINTNETIF pIf = (PINTNETIF)RTHandleTableLookupWithCtx(pIntNet->hHtIfs, hIf, pSession); 1187 if (!pIf) 1188 { 1189 Log(("INTNETR0IfSetMacAddress: returns VERR_INVALID_HANDLE\n")); 1190 return VERR_INVALID_HANDLE; 1191 } 1192 1193 /* 1194 * Grab the network semaphore and make the change. 1195 */ 1196 int rc; 1197 PINTNETNETWORK pNetwork = pIf->pNetwork; 1198 if (pNetwork) 1199 { 1200 rc = RTSemFastMutexRequest(pNetwork->FastMutex); 1201 if (RT_SUCCESS(rc)) 1202 { 1203 if (memcmp(&pIf->Mac, pMac, sizeof(pIf->Mac))) 1204 { 1205 Log(("INTNETR0IfSetMacAddress: hIf=%RX32: Changed from %.6Rhxs -> %.6Rhxs\n", 1206 hIf, &pIf->Mac, pMac)); 1207 pIf->Mac = *pMac; 1208 pIf->fMacSet = true; 1209 } 1210 1211 rc = RTSemFastMutexRelease(pNetwork->FastMutex); 1212 } 1213 } 1214 else 1215 rc = VERR_WRONG_ORDER; 1216 1217 intnetR0IfRelease(pIf, pSession); 1218 return rc; 1219 } 1220 1221 1222 /** 1223 * VMMR0 request wrapper for INTNETR0IfSetMacAddress. 1224 * 1225 * @returns see INTNETR0IfSetMacAddress. 1226 * @param pIntNet The internal networking instance. 1227 * @param pSession The caller's session. 1228 * @param pReq The request packet. 1229 */ 1230 INTNETR0DECL(int) INTNETR0IfSetMacAddressReq(PINTNET pIntNet, PSUPDRVSESSION pSession, PINTNETIFSETMACADDRESSREQ pReq) 1231 { 1232 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 1233 return VERR_INVALID_PARAMETER; 1234 return INTNETR0IfSetMacAddress(pIntNet, pReq->hIf, pSession, &pReq->Mac); 1235 } 1236 1237 1238 /** 1169 1239 * Worker for intnetR0IfSetActive. 1170 1240 * … … 1256 1326 return VERR_WRONG_ORDER; 1257 1327 return intnetR0NetworkSetIfActive(pNetwork, pIf, fActive); 1328 } 1329 1330 1331 /** 1332 * Sets the active property of an interface. 1333 * 1334 * @returns VBox status code. 1335 * @param pIntNet The instance handle. 1336 * @param hIf The interface handle. 1337 * @param pSession The caller's session. 1338 * @param fActive The new state. 1339 */ 1340 INTNETR0DECL(int) INTNETR0IfSetActive(PINTNET pIntNet, INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, bool fActive) 1341 { 1342 LogFlow(("INTNETR0IfSetActive: pIntNet=%p hIf=%RX32 fActive=%RTbool\n", pIntNet, hIf, fActive)); 1343 1344 /* 1345 * Validate & translate input. 1346 */ 1347 AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER); 1348 PINTNETIF pIf = (PINTNETIF)RTHandleTableLookupWithCtx(pIntNet->hHtIfs, hIf, pSession); 1349 if (!pIf) 1350 { 1351 Log(("INTNETR0IfSetActive: returns VERR_INVALID_HANDLE\n")); 1352 return VERR_INVALID_HANDLE; 1353 } 1354 1355 /* 1356 * Hand it to the network since it might involve the trunk 1357 * and things are tricky there wrt to locking order. 1358 */ 1359 int rc; 1360 PINTNETNETWORK pNetwork = pIf->pNetwork; 1361 if (pNetwork) 1362 rc = intnetR0NetworkSetIfActive(pNetwork, pIf, fActive); 1363 else 1364 rc = VERR_WRONG_ORDER; 1365 1366 intnetR0IfRelease(pIf, pSession); 1367 return rc; 1368 } 1369 1370 1371 /** 1372 * VMMR0 request wrapper for INTNETR0IfSetActive. 1373 * 1374 * @returns see INTNETR0IfSetActive. 1375 * @param pIntNet The internal networking instance. 1376 * @param pSession The caller's session. 1377 * @param pReq The request packet. 1378 */ 1379 INTNETR0DECL(int) INTNETR0IfSetActiveReq(PINTNET pIntNet, PSUPDRVSESSION pSession, PINTNETIFSETACTIVEREQ pReq) 1380 { 1381 if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq))) 1382 return VERR_INVALID_PARAMETER; 1383 return INTNETR0IfSetActive(pIntNet, pReq->hIf, pSession, pReq->fActive); 1258 1384 } 1259 1385
Note:
See TracChangeset
for help on using the changeset viewer.