VirtualBox

Changeset 25367 in vbox


Ignore:
Timestamp:
Dec 14, 2009 4:29:10 PM (15 years ago)
Author:
vboxsync
Message:

Solaris/VBoxBow: some bits before OS upgrade.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/Makefile.kmk

    r25336 r25367  
    337337vboxnetbow_DEPS         += $(VBOX_SVN_REV_KMK)
    338338vboxnetbow_INCS         := $(PATH_SUB_CURRENT)
    339 vboxnetbow_LDFLAGS      += -N drv/vboxdrv -N misc/mac
     339vboxnetbow_LDFLAGS      += -N drv/vboxdrv -N drv/vnic -N misc/mac -N misc/dls
    340340vboxnetbow_LIBS = \
    341341        $(PATH_LIB)/SUPR0IdcClient$(VBOX_SUFF_LIB)
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h

    r25302 r25367  
    176176             * @{ */
    177177#  ifdef VBOX_WITH_NETFLT_CROSSBOW
     178            /** The link Id of the VNIC */
     179            datalink_id_t VNICLinkId;
     180            /** Instance number of VNIC */
     181            uint16_t uInstance;
     182            /** Whether we created the VNIC or not */
     183            bool fCreatedVNIC;
    178184            /** The lower MAC handle */
    179185            mac_handle_t hInterface;
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFltBow-solaris.c

    r25327 r25367  
    2525#define LOG_GROUP LOG_GROUP_NET_FLT_DRV
    2626#include <VBox/log.h>
     27#include <VBox/err.h>
    2728#include <VBox/cdefs.h>
    2829#include <VBox/version.h>
     
    3132#include <iprt/assert.h>
    3233#include <iprt/err.h>
     34#include <iprt/string.h>
    3335#include <iprt/net.h>
    3436#include <iprt/spinlock.h>
    3537
     38#include <sys/types.h>
    3639#include <sys/modctl.h>
    3740#include <sys/conf.h>
     
    4245#include <sys/strsubr.h>
    4346#include <sys/dlpi.h>
     47#include <sys/dls_mgmt.h>
    4448#include <sys/mac.h>
    4549#include <sys/strsun.h>
    46 
    47 #include "include/mac_provider.h"
    48 #include "include/mac_client.h"
    49 #include "include/mac_client_priv.h"
     50#include <sys/sunddi.h>
     51
     52#include "include/mac_provider.h"       /* dependency for other headers */
     53#include "include/mac_client.h"         /* for mac_* */
     54#include "include/mac_client_priv.h"    /* for mac_info, mac_capab_get etc. */
     55#if 0
     56#include "include/dls.h"                /* for dls_mgmt_* */
     57#include "include/dld_ioc.h"            /* required by vnic.h */
     58#include "include/vnic.h"               /* for vnic_ioc_diag_t */
     59#include "include/vnic_impl.h"          /* for vnic_dev_create */
     60#endif
    5061
    5162#define VBOXNETFLT_OS_SPECFIC 1
     
    5970/** The module descriptions as seen in 'modinfo'. */
    6071#define DEVICE_DESC_DRV                 "VirtualBox NetBow"
     72/** The dynamically created VNIC name */
     73#define VBOXFLT_VNIC_NAME               "vboxvnic"
    6174/** Debugging switch for using symbols in kmdb */
    6275# define LOCAL      static
     
    143156{
    144157    MODREV_1,
    145     &g_VBoxNetFltSolarisModule,
    146     NULL,
     158    {
     159        &g_VBoxNetFltSolarisModule,
     160        NULL,
     161    }
    147162};
    148163
     
    592607 * @param   fLoopback       Whether this is a loopback packet or not.
    593608 */
    594 
    595609LOCAL void vboxNetFltSolarisRecv(void *pvData, mac_resource_handle_t hResource, mblk_t *pMsg, boolean_t fLoopback)
    596610{
     
    638652
    639653/**
     654 * Create a VNIC dynamically over the given interface.
     655 *
     656 * @param   pThis           The VM connection instance.
     657 *
     658 * @returns corresponding VBox error code.
     659 */
     660LOCAL int vboxNetFltSolarisCreateVNIC(PVBOXNETFLTINS pThis)
     661{
     662#if 0
     663    LogFlow((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC pThis=%p\n", pThis));
     664
     665    datalink_id_t InterfaceLinkId;
     666    int rc = dls_mgmt_get_linkid(pThis->szName, &InterfaceLinkId);
     667    if (!rc)
     668    {
     669        dev_t DeviceNum = makedevice(ddi_driver_major(g_pVBoxNetFltSolarisDip), pThis->u.s.uInstance);
     670        char szVNICName[sizeof(VBOXFLT_VNIC_NAME) + 16];
     671        RTStrPrintf(szVNICName, sizeof(szVNICName), "%s%d", VBOXFLT_VNIC_NAME, pThis->u.s.uInstance);
     672        LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC Creating VNIC '%s' over '%s'\n", szVNICName, pThis->szName));
     673        rc = dls_mgmt_create(szVNICName, DeviceNum, DATALINK_CLASS_VNIC, DL_ETHER, B_FALSE /* Persist */, &pThis->u.s.VNICLinkId);
     674        if (!rc)
     675        {
     676            /* -XXX- @todo remove hardcoded Guest MAC address, should be sent from guest later. */
     677            RTMAC GuestMac;
     678            GuestMac.au8[0] = 0x08;
     679            GuestMac.au8[1] = 0x00;
     680            GuestMac.au8[2] = 0x27;
     681            GuestMac.au8[3] = 0xFE;
     682            GuestMac.au8[4] = 0x21;
     683            GuestMac.au8[5] = 0x03;
     684
     685            AssertCompile(sizeof(RTMAC) <= MAXMACADDRLEN);
     686            uchar_t MacAddr[MAXMACADDRLEN];
     687            bzero(MacAddr, sizeof(MacAddr));
     688            bcopy(GuestMac.au8, MacAddr, RT_MIN(sizeof(GuestMac), sizeof(MacAddr)));
     689
     690            int MacSlot = 0;
     691            vnic_ioc_diag_t Diag = VNIC_IOC_DIAG_NONE;
     692            vnic_mac_addr_type_t MacAddrType = VNIC_MAC_ADDR_TYPE_FIXED;
     693            int cbMac = sizeof(RTMAC);
     694            int fFlags = VNIC_IOC_CREATE_NODUPCHECK | VNIC_IOC_CREATE_REQ_HWRINGS;
     695            rc = vnic_dev_create(pThis->u.s.VNICLinkId, InterfaceLinkId, &MacAddrType, &cbMac, MacAddr,
     696                                &MacSlot, 0 /* Mac Prefix */, 0 /* VLAN Id */, NULL /* Resources Caps */,
     697                                fFlags, &Diag, kcred);
     698            if (rc)
     699            {
     700                if (Diag == VNIC_IOC_DIAG_NO_HWRINGS)
     701                {
     702                    /*
     703                     * No hardware rings available, retry without requesting hardware ring.
     704                     */
     705                    LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC No hardware rings available for VNIC over '%s'. Recreating VNIC '%s'\n", pThis->szName,
     706                                    szVNICName));
     707
     708                    fFlags = VNIC_IOC_CREATE_NODUPCHECK;
     709                    rc = vnic_dev_create(pThis->u.s.VNICLinkId, InterfaceLinkId, &MacAddrType, &cbMac, MacAddr,
     710                                        &MacSlot, 0 /* Mac Prefix */, 0 /* VLAN Id */, NULL /* Resources Caps */,
     711                                        fFlags, &Diag, kcred);
     712                }
     713            }
     714
     715            if (!rc)
     716            {
     717                pThis->u.s.fCreatedVNIC = true;
     718                pThis->u.s.uInstance++;
     719                LogFlow((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC successfully created VNIC '%s' over '%s'\n", "vboxvnic", pThis->szName));
     720                return VINF_SUCCESS;
     721            }
     722            else
     723            {
     724                LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to create VNIC over '%s'. rc=%d Diagnosis=%d\n", pThis->szName,
     725                            rc, Diag));
     726                rc = VERR_INTNET_FLT_VNIC_CREATE_FAILED;
     727            }
     728
     729            dls_mgmt_destroy(pThis->u.s.VNICLinkId, B_FALSE /* Persist */);
     730        }
     731        else
     732        {
     733            LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to create a link id for a VNIC over '%s' rc=%d\n", pThis->szName, rc));
     734            rc = VERR_INTNET_FLT_VNIC_CREATE_FAILED;
     735        }
     736    }
     737    else
     738    {
     739        LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to find interface '%s' rc=%d\n", pThis->szName, rc));
     740        rc = VERR_INTNET_FLT_IF_NOT_FOUND;
     741    }
     742
     743    return rc;
     744#endif
     745}
     746
     747
     748/**
    640749 * Attach to the network interface.
    641750 *
     
    647756LOCAL int vboxNetFltSolarisAttachToInterface(PVBOXNETFLTINS pThis, bool fRediscovery)
    648757{
     758    LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface pThis=%p fRediscovery=%d\n", pThis, fRediscovery));
     759
    649760    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
    650761
     
    655766    if (RT_LIKELY(!rc))
    656767    {
    657         const mac_info_t *pMacInfo = mac_info(pThis->u.s.hInterface);
    658         if (RT_LIKELY(pMacInfo))
    659         {
    660             if (   pMacInfo->mi_media == DL_ETHER
    661                 && pMacInfo->mi_nativemedia == DL_ETHER)
     768        /*
     769         * If this is not a VNIC, create a VNIC and open it instead.
     770         */
     771        rc = mac_is_vnic(pThis->u.s.hInterface);
     772        if (!rc)
     773        {
     774            LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface '%s' is not a VNIC. Creating one.\n", pThis->szName));
     775
     776            mac_close(pThis->u.s.hInterface);
     777            pThis->u.s.hInterface = NULL;
     778            rc = vboxNetFltSolarisCreateVNIC(pThis);
     779            if (RT_SUCCESS(rc))
     780                rc = mac_open_by_linkid(pThis->u.s.VNICLinkId, &pThis->u.s.hInterface);
     781            else
    662782            {
    663                 /*
    664                  * Obtain the MAC address of the interface.
    665                  */
    666                 AssertCompile(sizeof(RTMAC) == ETHERADDRL);
    667                 mac_unicast_primary_get(pThis->u.s.hInterface, (uint8_t *)&pThis->u.s.Mac.au8);
    668 
    669                 LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface MAC address of %s is %.*Rhxs\n", pThis->szName,
    670                                 sizeof(pThis->u.s.Mac), &pThis->u.s.Mac));
    671 
    672                 /** @todo Obtain the MTU size using mac_sdu_get() */
    673                 /** @todo Obtain capabilities (hardware checksum etc.) using mac_capab_get() */
    674 
    675                 /*
    676                  * Open a client connection to the lower MAC interface.
    677                  */
    678                 rc = mac_client_open(pThis->u.s.hInterface, &pThis->u.s.hClient,
    679                                      NULL                                   /* name of this client */,
    680                                      MAC_OPEN_FLAGS_USE_DATALINK_NAME |     /* client name same as underlying NIC */
    681                                      MAC_OPEN_FLAGS_MULTI_PRIMARY           /* allow multiple primary unicasts */
    682                                      );
    683                 if (RT_LIKELY(!rc))
     783                pThis->u.s.hInterface = NULL;
     784                LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to create VNIC. rc=%Rrc\n", rc));
     785            }
     786        }
     787        else
     788            rc = VINF_SUCCESS;
     789
     790        /*
     791         * At this point "hInterface" should be a handle to a VNIC, we no longer would deal with physical interface
     792         * if it has been passed by the user.
     793         */
     794        if (RT_SUCCESS(rc))
     795        {
     796            const mac_info_t *pMacInfo = mac_info(pThis->u.s.hInterface);
     797            if (RT_LIKELY(pMacInfo))
     798            {
     799                if (   pMacInfo->mi_media == DL_ETHER
     800                    && pMacInfo->mi_nativemedia == DL_ETHER)
    684801                {
    685802                    /*
    686                      * Set a unicast address for this client and the packet receive callback.
    687                      * We want to use the primary unicast address of the underlying interface hence we pass NULL.
    688                      * Also we don't really set the RX function here, this is done when we activate promiscuous mode.
     803                     * Obtain the MAC address of the interface.
    689804                     */
    690                     mac_diag_t MacDiag;
    691                     rc = mac_unicast_add_set_rx(pThis->u.s.hClient, NULL /* MAC Address */,
    692                                                 MAC_UNICAST_PRIMARY | MAC_UNICAST_STRIP_DISABLE |
    693                                                 MAC_UNICAST_DISABLE_TX_VID_CHECK | MAC_UNICAST_NODUPCHECK,
    694                                                 &pThis->u.s.hUnicast, 0 /* VLAN id */, &MacDiag, NULL /* pfnRecv */, pThis);
    695                     if (!rc)
     805                    AssertCompile(sizeof(RTMAC) == ETHERADDRL);
     806                    mac_unicast_primary_get(pThis->u.s.hInterface, (uint8_t *)&pThis->u.s.Mac.au8);
     807
     808                    LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface MAC address of %s is %.*Rhxs\n", pThis->szName,
     809                                    sizeof(pThis->u.s.Mac), &pThis->u.s.Mac));
     810
     811                    /** @todo Obtain the MTU size using mac_sdu_get() */
     812                    /** @todo Obtain capabilities (hardware checksum etc.) using mac_capab_get() */
     813
     814                    /*
     815                     * Open a client connection to the lower MAC interface.
     816                     */
     817                    rc = mac_client_open(pThis->u.s.hInterface, &pThis->u.s.hClient,
     818                                         NULL                                   /* name of this client */,
     819                                         MAC_OPEN_FLAGS_USE_DATALINK_NAME |     /* client name same as underlying NIC */
     820                                         MAC_OPEN_FLAGS_MULTI_PRIMARY           /* allow multiple primary unicasts */
     821                                         );
     822                    if (RT_LIKELY(!rc))
    696823                    {
    697                         LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface successfully attached over '%s'\n", pThis->szName));
    698                         return VINF_SUCCESS;
     824                        /** @todo -XXX- if possible we must move unicast_add and rx_set to when the Guest advertises it's MAC to us.  */
     825
     826                        /*
     827                         * Set a unicast address for this client and the packet receive callback.
     828                         * We want to use the primary unicast address of the underlying interface (VNIC) hence we pass NULL.
     829                         * Also we don't really set the RX function here, this is done when we activate promiscuous mode.
     830                         */
     831                        mac_diag_t MacDiag;
     832                        rc = mac_unicast_add(pThis->u.s.hClient, NULL /* MAC Address */,
     833                                            MAC_UNICAST_PRIMARY | MAC_UNICAST_STRIP_DISABLE |
     834                                            MAC_UNICAST_DISABLE_TX_VID_CHECK | MAC_UNICAST_NODUPCHECK | MAC_UNICAST_HW,
     835                                            &pThis->u.s.hUnicast, 0 /* VLAN id */, &MacDiag);
     836                        if (!rc)
     837                        {
     838                            LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface successfully attached over '%s'\n", pThis->szName));
     839                            return VINF_SUCCESS;
     840                        }
     841                        else
     842                            LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to set client MAC address over link '%s' rc=%d\n",
     843                                    pThis->szName, rc));
     844
     845                        mac_client_close(pThis->u.s.hClient, 0 /* fFlags */);
     846                        pThis->u.s.hClient = NULL;
    699847                    }
    700848                    else
    701                         LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to set client MAC address over link '%s' rc=%d\n",
     849                    {
     850                        LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to create client over link '%s' rc=%d\n",
    702851                                pThis->szName, rc));
    703 
    704                     mac_client_close(pThis->u.s.hClient, 0 /* fFlags */);
    705                     pThis->u.s.hClient = NULL;
     852                    }
    706853                }
    707854                else
    708855                {
    709                     LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to create client over link '%s' rc=%d\n",
    710                             pThis->szName, rc));
     856                    LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface media type incompatible: %d %d\n", pMacInfo->mi_media,
     857                            pMacInfo->mi_nativemedia));
     858                    rc = EPROTO;
    711859                }
    712860            }
    713861            else
    714862            {
    715                 LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface media type incompatible: %d %d\n", pMacInfo->mi_media,
    716                         pMacInfo->mi_nativemedia));
    717                 rc = EPROTO;
     863                LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to obtain info for link '%s'\n", pThis->szName));
     864                rc = ENXIO;
    718865            }
    719866        }
    720867        else
    721868        {
    722             LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to obtain info for link '%s'\n", pThis->szName));
     869            LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface VNIC creation failed over '%s'\n", pThis->szName));
    723870            rc = ENXIO;
    724871        }
    725872
    726         mac_close(pThis->u.s.hInterface);
     873        if (pThis->u.s.hInterface)
     874        {
     875            mac_close(pThis->u.s.hInterface);
     876            pThis->u.s.hInterface = NULL;
     877        }
    727878    }
    728879    else
     
    768919        mac_close(pThis->u.s.hInterface);
    769920        pThis->u.s.hInterface = NULL;
     921    }
     922
     923    if (pThis->u.s.fCreatedVNIC)
     924    {
     925#if 0
     926        vnic_dev_delete(pThis->u.s.VNICLinkId, 0 /* Flags -- ununsed in snv_127 */, kcred);
     927        dls_mgmt_destroy(pThis->u.s.VNICLinkId, B_FALSE /* Persist */);
     928        pThis->u.s.VNICLinkId = DATALINK_INVALID_LINKID;
     929        pThis->u.s.fCreatedVNIC = false;
     930#endif
    770931    }
    771932}
     
    8611022     * Init. the solaris specific data.
    8621023     */
     1024    pThis->u.s.VNICLinkId = DATALINK_INVALID_LINKID;
     1025    pThis->u.s.uInstance = 0;
     1026    pThis->u.s.fCreatedVNIC = false;
    8631027    pThis->u.s.hInterface = NULL;
    8641028    pThis->u.s.hClient = NULL;
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