VirtualBox

Ignore:
Timestamp:
May 4, 2011 12:54:03 PM (14 years ago)
Author:
vboxsync
Message:

Solaris/VBoxNetFltBow: cleanup, link notification support (disabled).

Location:
trunk/src/VBox/HostDrivers/VBoxNetFlt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h

    r36730 r36956  
    188188            /** The MAC address of the host interface. */
    189189            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;
    192194#  else
    193195            /** Pointer to the bound IPv4 stream. */
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFltBow-solaris.c

    r36876 r36956  
    218218    /** Pointer to the VirtualBox interface instance. */
    219219    void                       *pvIf;
    220     /** The lower MAC handle. */
     220    /** The MAC handle. */
    221221    mac_handle_t                hInterface;
    222222    /** The VNIC link ID. */
     
    224224    /** The MAC client handle */
    225225    mac_client_handle_t         hClient;
    226     /** The unicast address handle.  */
     226    /** The unicast address handle. */
    227227    mac_unicast_handle_t        hUnicast;
    228228    /* The VNIC name. */
     
    484484 * @returns Solaris message block.
    485485 */
    486 LOCAL mblk_t *vboxNetFltSolarisMBlkFromSG(PVBOXNETFLTINS pThis, PINTNETSG pSG, uint32_t fDst)
     486LOCAL inline mblk_t *vboxNetFltSolarisMBlkFromSG(PVBOXNETFLTINS pThis, PINTNETSG pSG, uint32_t fDst)
    487487{
    488488    LogFlow((DEVICE_NAME ":vboxNetFltSolarisMBlkFromSG pThis=%p pSG=%p\n", pThis, pSG));
     
    729729
    730730
     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 */
     742LOCAL 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
    731772/**
    732773 * Report capabilities and MAC address to IntNet after obtaining the MAC address
     
    744785LOCAL int vboxNetFltSolarisReportInfo(PVBOXNETFLTINS pThis, mac_handle_t hInterface, bool fIsVNIC)
    745786{
    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;
    775829}
    776830
     
    795849    AssertReturn(pVNIC->hInterface, VERR_INVALID_POINTER);
    796850    AssertReturn(pVNIC->hLinkId != DATALINK_INVALID_LINKID, VERR_INVALID_HANDLE);
    797     AssertReturn(!pVNIC->hClient, VERR_INVALID_HANDLE);
     851    AssertReturn(!pVNIC->hClient, VERR_INVALID_POINTER);
    798852
    799853    int rc = mac_client_open(pVNIC->hInterface, &pVNIC->hClient,
     
    809863        if (RT_LIKELY(!rc))
    810864        {
    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;
    819867        }
    820868        else
     
    10541102        pVNIC->pVNICTemplate = RTMemAllocZ(sizeof(VBOXNETFLTVNICTEMPLATE));
    10551103        if (RT_UNLIKELY(!pVNIC->pVNICTemplate))
     1104        {
     1105            vboxNetFltSolarisFreeVNIC(pVNIC);
    10561106            return VERR_NO_MEMORY;
     1107        }
    10571108
    10581109        /*
     
    12051256    LogFlow((DEVICE_NAME ":vboxNetFltOsDeleteInstance pThis=%p\n", pThis));
    12061257
     1258    if (pThis->u.s.hNotify)
     1259        mac_notify_remove(pThis->u.s.hNotify, B_TRUE /* Wait */);
     1260
    12071261    /*
    12081262     * Destroy all managed VNICs. If a VNIC was passed to us, there
     
    12271281
    12281282    /*
    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().
    12301285     */
    12311286    mac_handle_t hInterface;
     
    12361291        if (!rc)
    12371292        {
    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));
    12421294            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));
    12621309
    12631310        /*
    1264          * VNIC: Alloc & init. the VNIC structure and use the VNIC directly.
     1311         * Report info. (host MAC address, promiscuous, GSO capabilities etc.) to IntNet.
    12651312         */
    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));
    13011316
    13021317        mac_close(hInterface);
     
    13051320    {
    13061321        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;
    13081323    }
    13091324
     
    13211336    list_create(&pThis->u.s.hVNICs, sizeof(VBOXNETFLTVNIC), offsetof(VBOXNETFLTVNIC, hNode));
    13221337    pThis->u.s.uInstance       = 0;
     1338    pThis->u.s.hNotify         = NULL;
    13231339    RT_ZERO(pThis->u.s.MacAddr);
    1324     pThis->u.s.fReportedInfo   = false;
    13251340    return VINF_SUCCESS;
    13261341}
     
    13621377        pMsg = NULL;
    13631378        rc = VERR_NET_IO_ERROR;
    1364         LogFlow((DEVICE_NAME ":vboxNetFltPortOsXmit Xmit failed pVNIC=%p.\n", pVNIC));
     1379        LogRel((DEVICE_NAME ":vboxNetFltPortOsXmit Xmit failed pVNIC=%p.\n", pVNIC));
    13651380    }
    13661381    else
     
    13841399    PVBOXNETFLTVNIC pVNIC = pvIfData;
    13851400    AssertMsgReturnVoid(VALID_PTR(pVNIC) && pVNIC->u32Magic == VBOXNETFLTVNIC_MAGIC,
    1386                     ("Invalid pvIfData=%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));
    13871402    AssertMsgReturnVoid(pVNIC->hLinkId != DATALINK_INVALID_LINKID,
    13881403                    ("Invalid hLinkId pVNIC=%p magic=%#x\n", pVNIC, pVNIC->u32Magic));
     
    14521467
    14531468
    1454 
    14551469int vboxNetFltPortOsConnectInterface(PVBOXNETFLTINS pThis, void *pvIf, void **ppvIfData)
    14561470{
     
    14631477     * a VNIC per guest NIC.
    14641478     */
    1465     if (   !pThis->u.s.fIsVNIC
     1479    if (  !pThis->u.s.fIsVNIC
    14661480        || pThis->u.s.fIsVNICTemplate)
    14671481    {
     
    14901504         * This is a VNIC passed to us, use it directly.
    14911505         */
    1492         PVBOXNETFLTVNIC pVNIC = list_head(&pThis->u.s.hVNICs);
     1506        PVBOXNETFLTVNIC pVNIC = vboxNetFltSolarisAllocVNIC();
    14931507        if (RT_LIKELY(pVNIC))
    14941508        {
    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);
    14971545        }
    14981546        else
    14991547        {
    1500             LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface huh!? Missing VNIC!\n"));
    1501             return VERR_GENERAL_FAILURE;
     1548            LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance failed to allocate VNIC private data.\n"));
     1549            rc = VERR_NO_MEMORY;
    15021550        }
    15031551    }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette