Changeset 36956 in vbox for trunk/src/VBox/HostDrivers/VBoxNetFlt
- Timestamp:
- May 4, 2011 12:54:03 PM (14 years ago)
- Location:
- trunk/src/VBox/HostDrivers/VBoxNetFlt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h
r36730 r36956 188 188 /** The MAC address of the host interface. */ 189 189 RTMAC MacAddr; 190 /** Whether required capabilities have been reported. */ 191 bool fReportedInfo; 190 /** Handle of this interface (lower MAC). */ 191 mac_handle_t hInterface; 192 /** Handle to link state notifier. */ 193 mac_notify_handle_t hNotify; 192 194 # else 193 195 /** Pointer to the bound IPv4 stream. */ -
trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFltBow-solaris.c
r36876 r36956 218 218 /** Pointer to the VirtualBox interface instance. */ 219 219 void *pvIf; 220 /** The lowerMAC handle. */220 /** The MAC handle. */ 221 221 mac_handle_t hInterface; 222 222 /** The VNIC link ID. */ … … 224 224 /** The MAC client handle */ 225 225 mac_client_handle_t hClient; 226 /** The unicast address handle. 226 /** The unicast address handle. */ 227 227 mac_unicast_handle_t hUnicast; 228 228 /* The VNIC name. */ … … 484 484 * @returns Solaris message block. 485 485 */ 486 LOCAL mblk_t *vboxNetFltSolarisMBlkFromSG(PVBOXNETFLTINS pThis, PINTNETSG pSG, uint32_t fDst)486 LOCAL inline mblk_t *vboxNetFltSolarisMBlkFromSG(PVBOXNETFLTINS pThis, PINTNETSG pSG, uint32_t fDst) 487 487 { 488 488 LogFlow((DEVICE_NAME ":vboxNetFltSolarisMBlkFromSG pThis=%p pSG=%p\n", pThis, pSG)); … … 729 729 730 730 731 #if 0 732 /** 733 * MAC layer link notification hook. 734 * 735 * @param pvArg Opaque pointer to the instance. 736 * @param Type Notification Type. 737 * 738 * @remarks This hook will be invoked for various changes to the underlying 739 * interface even when VMs aren't running so don't do any funky stuff 740 * here. 741 */ 742 LOCAL void vboxNetFltSolarisLinkNotify(void *pvArg, mac_notify_type_t Type) 743 { 744 LogRel((DEVICE_NAME ":vboxNetFltSolarisLinkNotify pvArg=%p Type=%d\n", pvArg, Type)); 745 746 PVBOXNETFLTINS pThis = pvArg; 747 AssertReturnVoid(VALID_PTR(pThis)); 748 AssertReturnVoid(pThis->u.s.hInterface); 749 750 switch (Type) 751 { 752 case MAC_NOTE_LINK: 753 { 754 LogRel((DEVICE_NAME ":vboxNetFltSolarisLinkNotify link state change\n")); 755 link_state_t hLinkState = mac_stat_get(pThis->u.s.hInterface, MAC_STAT_LINK_STATE); 756 bool fDisconnectedFromHost = hLinkState == LINK_STATE_UP ? false : true; 757 if (fDisconnectedFromHost != ASMAtomicUoReadBool(&pThis->fDisconnectedFromHost)) 758 { 759 ASMAtomicUoWriteBool(&pThis->fDisconnectedFromHost, fDisconnectedFromHost); 760 LogRel((DEVICE_NAME ":vboxNetFltSolarisLinkNotify link state change: new state=%s\n", fDisconnectedFromHost ? "DOWN" : "UP")); 761 } 762 break; 763 } 764 765 default: 766 return; 767 } 768 } 769 #endif 770 771 731 772 /** 732 773 * Report capabilities and MAC address to IntNet after obtaining the MAC address … … 744 785 LOCAL int vboxNetFltSolarisReportInfo(PVBOXNETFLTINS pThis, mac_handle_t hInterface, bool fIsVNIC) 745 786 { 746 if (!pThis->u.s.fReportedInfo) 747 { 748 mac_handle_t hLowerMac = NULL; 749 if (!fIsVNIC) 750 hLowerMac = hInterface; 751 else 752 { 753 hLowerMac = mac_get_lower_mac_handle(hInterface); 754 if (RT_UNLIKELY(!hLowerMac)) 755 { 756 LogRel((DEVICE_NAME ":vboxNetFltSolarisReportInfo failed to get lower MAC handle for '%s'\n", pThis->szName)); 757 return VERR_INVALID_HANDLE; 758 } 759 } 760 761 mac_unicast_primary_get(hLowerMac, (uint8_t *)pThis->u.s.MacAddr.au8); 762 if (vboxNetFltTryRetainBusyNotDisconnected(pThis)) 763 { 764 Assert(pThis->pSwitchPort); 765 LogFlow((DEVICE_NAME ":vboxNetFltSolarisReportInfo phys mac %.6Rhxs\n", &pThis->u.s.MacAddr)); 766 pThis->pSwitchPort->pfnReportMacAddress(pThis->pSwitchPort, &pThis->u.s.MacAddr); 767 pThis->pSwitchPort->pfnReportPromiscuousMode(pThis->pSwitchPort, false); /** @todo Promisc */ 768 pThis->pSwitchPort->pfnReportGsoCapabilities(pThis->pSwitchPort, 0, INTNETTRUNKDIR_WIRE | INTNETTRUNKDIR_HOST); 769 pThis->pSwitchPort->pfnReportNoPreemptDsts(pThis->pSwitchPort, 0 /* none */); 770 pThis->u.s.fReportedInfo = true; 771 vboxNetFltRelease(pThis, true /*fBusy*/); 772 } 773 } 774 return VINF_SUCCESS; 787 mac_handle_t hLowerMac = NULL; 788 if (!fIsVNIC) 789 hLowerMac = hInterface; 790 else 791 { 792 hLowerMac = mac_get_lower_mac_handle(hInterface); 793 if (RT_UNLIKELY(!hLowerMac)) 794 { 795 LogRel((DEVICE_NAME ":vboxNetFltSolarisReportInfo failed to get lower MAC handle for '%s'\n", pThis->szName)); 796 return VERR_INVALID_HANDLE; 797 } 798 } 799 800 pThis->u.s.hInterface = hLowerMac; 801 802 #if 0 803 /* 804 * Try setup link notification hooks, this might fail if mac_no_notification() 805 * doesn't support it. We won't bother using the private function since link notification 806 * isn't critical for us and ignore failures. 807 */ 808 pThis->u.s.hNotify = mac_notify_add(hLowerMac, vboxNetFltSolarisLinkNotify, pThis); 809 if (!pThis->u.s.hNotify) 810 LogRel((DEVICE_NAME ":vboxNetFltSolarisReportInfo Warning! Failed to setup link notification hook.\n")); 811 #endif 812 813 mac_unicast_primary_get(hLowerMac, (uint8_t *)pThis->u.s.MacAddr.au8); 814 if (vboxNetFltTryRetainBusyNotDisconnected(pThis)) 815 { 816 Assert(pThis->pSwitchPort); 817 LogFlow((DEVICE_NAME ":vboxNetFltSolarisReportInfo phys mac %.6Rhxs\n", &pThis->u.s.MacAddr)); 818 pThis->pSwitchPort->pfnReportMacAddress(pThis->pSwitchPort, &pThis->u.s.MacAddr); 819 pThis->pSwitchPort->pfnReportPromiscuousMode(pThis->pSwitchPort, false); /** @todo Promisc */ 820 pThis->pSwitchPort->pfnReportGsoCapabilities(pThis->pSwitchPort, 0, INTNETTRUNKDIR_WIRE | INTNETTRUNKDIR_HOST); 821 pThis->pSwitchPort->pfnReportNoPreemptDsts(pThis->pSwitchPort, 0 /* none */); 822 vboxNetFltRelease(pThis, true /*fBusy*/); 823 return VINF_SUCCESS; 824 } 825 else 826 LogRel((DEVICE_NAME ":vboxNetFltSolarisReportInfo failed to retain interface. pThis=%p\n", pThis)); 827 828 return VERR_INTNET_FLT_IF_BUSY; 775 829 } 776 830 … … 795 849 AssertReturn(pVNIC->hInterface, VERR_INVALID_POINTER); 796 850 AssertReturn(pVNIC->hLinkId != DATALINK_INVALID_LINKID, VERR_INVALID_HANDLE); 797 AssertReturn(!pVNIC->hClient, VERR_INVALID_ HANDLE);851 AssertReturn(!pVNIC->hClient, VERR_INVALID_POINTER); 798 852 799 853 int rc = mac_client_open(pVNIC->hInterface, &pVNIC->hClient, … … 809 863 if (RT_LIKELY(!rc)) 810 864 { 811 rc = vboxNetFltSolarisReportInfo(pThis, pVNIC->hInterface, true /* fIsVNIC */); 812 if (RT_SUCCESS(rc)) 813 { 814 LogFlow((DEVICE_NAME ":vboxNetFltSolarisInitVNIC pThis=%p szName=%s succeeded.\n", pThis, pThis->szName)); 815 return rc; 816 } 817 else 818 LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNIC failed to report info. rc=%d\n", rc)); 865 LogFlow((DEVICE_NAME ":vboxNetFltSolarisInitVNIC succesfully initialized VNIC.\n")); 866 return VINF_SUCCESS; 819 867 } 820 868 else … … 1054 1102 pVNIC->pVNICTemplate = RTMemAllocZ(sizeof(VBOXNETFLTVNICTEMPLATE)); 1055 1103 if (RT_UNLIKELY(!pVNIC->pVNICTemplate)) 1104 { 1105 vboxNetFltSolarisFreeVNIC(pVNIC); 1056 1106 return VERR_NO_MEMORY; 1107 } 1057 1108 1058 1109 /* … … 1205 1256 LogFlow((DEVICE_NAME ":vboxNetFltOsDeleteInstance pThis=%p\n", pThis)); 1206 1257 1258 if (pThis->u.s.hNotify) 1259 mac_notify_remove(pThis->u.s.hNotify, B_TRUE /* Wait */); 1260 1207 1261 /* 1208 1262 * Destroy all managed VNICs. If a VNIC was passed to us, there … … 1227 1281 1228 1282 /* 1229 * Figure out if the interface is a VNIC or a physical/etherstub/whatever NIC. 1283 * Figure out if the interface is a VNIC or a physical/etherstub/whatever NIC, then 1284 * do the actual VNIC creation if necessary in vboxNetFltPortOsConnectInterface(). 1230 1285 */ 1231 1286 mac_handle_t hInterface; … … 1236 1291 if (!rc) 1237 1292 { 1238 /* 1239 * Physical Interface: Just pretend success for now. 1240 * We will create a VNIC per VM interface later, see vboxNetFltPortOsConnectInterface(). 1241 */ 1293 LogFlow((DEVICE_NAME ":vboxNetFltOsInitInstance pThis=%p physical interface '%s' detected.\n", pThis, pThis->szName)); 1242 1294 pThis->u.s.fIsVNIC = false; 1243 vboxNetFltSolarisReportInfo(pThis, hInterface, pThis->u.s.fIsVNIC); 1244 mac_close(hInterface); 1245 return VINF_SUCCESS; 1246 } 1247 1248 pThis->u.s.fIsVNIC = true; 1249 1250 if (RTStrNCmp(pThis->szName, VBOXFLT_VNIC_TEMPLATE_NAME, sizeof(VBOXFLT_VNIC_TEMPLATE_NAME) - 1) == 0) 1251 { 1252 /* 1253 * VNIC Template: Just pretend success for now. 1254 * We will create a VNIC per VM interface later, see vboxNetFltPortOsConnectInterface(). 1255 */ 1256 LogFlow((DEVICE_NAME ":vboxNetFltOsInitInstance pThis=%p VNIC template '%s' detected.\n", pThis, pThis->szName)); 1257 pThis->u.s.fIsVNICTemplate = true; 1258 vboxNetFltSolarisReportInfo(pThis, hInterface, pThis->u.s.fIsVNIC); 1259 mac_close(hInterface); 1260 return VINF_SUCCESS; 1261 } 1295 } 1296 else 1297 { 1298 pThis->u.s.fIsVNIC = true; 1299 if (RTStrNCmp(pThis->szName, VBOXFLT_VNIC_TEMPLATE_NAME, sizeof(VBOXFLT_VNIC_TEMPLATE_NAME) - 1) == 0) 1300 { 1301 LogFlow((DEVICE_NAME ":vboxNetFltOsInitInstance pThis=%p VNIC template '%s' detected.\n", pThis, pThis->szName)); 1302 pThis->u.s.fIsVNICTemplate = true; 1303 } 1304 } 1305 1306 if ( pThis->u.s.fIsVNIC 1307 && !pThis->u.s.fIsVNICTemplate) 1308 LogFlow((DEVICE_NAME ":vboxNetFltOsInitInstance pThis=%p VNIC '%s' detected.\n", pThis, pThis->szName)); 1262 1309 1263 1310 /* 1264 * VNIC: Alloc & init. the VNIC structure and use the VNIC directly.1311 * Report info. (host MAC address, promiscuous, GSO capabilities etc.) to IntNet. 1265 1312 */ 1266 PVBOXNETFLTVNIC pVNIC = vboxNetFltSolarisAllocVNIC(); 1267 if (RT_LIKELY(pVNIC)) 1268 { 1269 pVNIC->fCreated = false; 1270 pVNIC->hInterface = hInterface; 1271 1272 /* 1273 * Obtain the data link ID for this VNIC, it's needed for modifying the MAC address among other things. 1274 */ 1275 rc = vboxNetFltSolarisGetLinkId(pThis->szName, &pVNIC->hLinkId); 1276 if (RT_SUCCESS(rc)) 1277 { 1278 /* 1279 * Initialize the VNIC and add it to the list of managed VNICs. 1280 */ 1281 RTStrPrintf(pVNIC->szName, sizeof(pVNIC->szName), "%s", pThis->szName); 1282 rc = vboxNetFltSolarisInitVNIC(pThis, pVNIC); 1283 if (!rc) 1284 { 1285 list_insert_head(&pThis->u.s.hVNICs, pVNIC); 1286 return VINF_SUCCESS; 1287 } 1288 else 1289 LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance vboxNetFltSolarisInitVNIC failed. rc=%d\n", rc)); 1290 } 1291 else 1292 LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance failed to get link id for '%s'. rc=%d\n", pThis->szName, rc)); 1293 1294 vboxNetFltSolarisFreeVNIC(pVNIC); 1295 } 1296 else 1297 { 1298 LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance failed to allocate VNIC private data.\n")); 1299 rc = VERR_NO_MEMORY; 1300 } 1313 rc = vboxNetFltSolarisReportInfo(pThis, hInterface, pThis->u.s.fIsVNIC); 1314 if (RT_FAILURE(rc)) 1315 LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance failed to report info. rc=%d\n", rc)); 1301 1316 1302 1317 mac_close(hInterface); … … 1305 1320 { 1306 1321 LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance failed to open link '%s'! rc=%d\n", pThis->szName, rc)); 1307 rc = VERR_ OPEN_FAILED;1322 rc = VERR_INTNET_FLT_IF_FAILED; 1308 1323 } 1309 1324 … … 1321 1336 list_create(&pThis->u.s.hVNICs, sizeof(VBOXNETFLTVNIC), offsetof(VBOXNETFLTVNIC, hNode)); 1322 1337 pThis->u.s.uInstance = 0; 1338 pThis->u.s.hNotify = NULL; 1323 1339 RT_ZERO(pThis->u.s.MacAddr); 1324 pThis->u.s.fReportedInfo = false;1325 1340 return VINF_SUCCESS; 1326 1341 } … … 1362 1377 pMsg = NULL; 1363 1378 rc = VERR_NET_IO_ERROR; 1364 Log Flow((DEVICE_NAME ":vboxNetFltPortOsXmit Xmit failed pVNIC=%p.\n", pVNIC));1379 LogRel((DEVICE_NAME ":vboxNetFltPortOsXmit Xmit failed pVNIC=%p.\n", pVNIC)); 1365 1380 } 1366 1381 else … … 1384 1399 PVBOXNETFLTVNIC pVNIC = pvIfData; 1385 1400 AssertMsgReturnVoid(VALID_PTR(pVNIC) && pVNIC->u32Magic == VBOXNETFLTVNIC_MAGIC, 1386 ("Invalid p vIfData=%p magic=%#x (expected %#x)\n", pvIfData, pVNIC? pVNIC->u32Magic : 0, VBOXNETFLTVNIC_MAGIC));1401 ("Invalid pVNIC=%p magic=%#x (expected %#x)\n", pvIfData, VALID_PTR(pVNIC) ? pVNIC->u32Magic : 0, VBOXNETFLTVNIC_MAGIC)); 1387 1402 AssertMsgReturnVoid(pVNIC->hLinkId != DATALINK_INVALID_LINKID, 1388 1403 ("Invalid hLinkId pVNIC=%p magic=%#x\n", pVNIC, pVNIC->u32Magic)); … … 1452 1467 1453 1468 1454 1455 1469 int vboxNetFltPortOsConnectInterface(PVBOXNETFLTINS pThis, void *pvIf, void **ppvIfData) 1456 1470 { … … 1463 1477 * a VNIC per guest NIC. 1464 1478 */ 1465 if ( 1479 if ( !pThis->u.s.fIsVNIC 1466 1480 || pThis->u.s.fIsVNICTemplate) 1467 1481 { … … 1490 1504 * This is a VNIC passed to us, use it directly. 1491 1505 */ 1492 PVBOXNETFLTVNIC pVNIC = list_head(&pThis->u.s.hVNICs);1506 PVBOXNETFLTVNIC pVNIC = vboxNetFltSolarisAllocVNIC(); 1493 1507 if (RT_LIKELY(pVNIC)) 1494 1508 { 1495 *ppvIfData = pVNIC; 1496 LogFlow((DEVICE_NAME ":vboxNetFltPortOsConnectInterface set VNIC '%s' private data\n", pVNIC->szName)); 1509 pVNIC->fCreated = false; 1510 1511 rc = mac_open_by_linkname(pThis->szName, &pVNIC->hInterface); 1512 if (!rc) 1513 { 1514 /* 1515 * Obtain the data link ID for this VNIC, it's needed for modifying the MAC address among other things. 1516 */ 1517 rc = vboxNetFltSolarisGetLinkId(pThis->szName, &pVNIC->hLinkId); 1518 if (RT_SUCCESS(rc)) 1519 { 1520 /* 1521 * Initialize the VNIC and add it to the list of managed VNICs. 1522 */ 1523 RTStrPrintf(pVNIC->szName, sizeof(pVNIC->szName), "%s", pThis->szName); 1524 rc = vboxNetFltSolarisInitVNIC(pThis, pVNIC); 1525 if (!rc) 1526 { 1527 pVNIC->pvIf = pvIf; 1528 *ppvIfData = pVNIC; 1529 list_insert_head(&pThis->u.s.hVNICs, pVNIC); 1530 return VINF_SUCCESS; 1531 } 1532 else 1533 LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface failed to initialize VNIC. rc=%d\n", rc)); 1534 } 1535 else 1536 LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface failed to get link id for '%s'. rc=%d\n", pThis->szName, rc)); 1537 } 1538 else 1539 { 1540 LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface failed to open VNIC '%s'. rc=%d\n", pThis->szName, rc)); 1541 rc = VERR_OPEN_FAILED; 1542 } 1543 1544 vboxNetFltSolarisFreeVNIC(pVNIC); 1497 1545 } 1498 1546 else 1499 1547 { 1500 LogRel((DEVICE_NAME ":vboxNetFlt PortOsConnectInterface huh!? Missing VNIC!\n"));1501 r eturn VERR_GENERAL_FAILURE;1548 LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance failed to allocate VNIC private data.\n")); 1549 rc = VERR_NO_MEMORY; 1502 1550 } 1503 1551 }
Note:
See TracChangeset
for help on using the changeset viewer.