VirtualBox

Changeset 29469 in vbox


Ignore:
Timestamp:
May 14, 2010 12:30:51 PM (15 years ago)
Author:
vboxsync
Message:

Solaris/VBoxNetFltBow: got the Crossbow NetFilter working again. Disabled building them as the build box is old.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Config.kmk

    r29430 r29469  
    595595 VBOX_SOLARIS_NSL_RESOLVED = 1
    596596 ifeq ($(KBUILD_TARGET),solaris)
    597   VBOX_WITH_NETFLT_CROSSBOW = 1
     597# Disabled until some Nevada version ships the required headers.
     598#  VBOX_WITH_NETFLT_CROSSBOW = 1
    598599 endif
    599600 if1of ($(KBUILD_TARGET), darwin freebsd linux solaris)
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFltBow-solaris.c

    r28830 r29469  
    4646#include <sys/sunddi.h>
    4747
     48#include <sys/vnic_mgmt.h>
     49#include <sys/mac_client.h>
     50#include <sys/mac_provider.h>
     51#include <sys/dls.h>
     52
     53#if 0
    4854#include "include/mac_provider.h"       /* dependency for other headers */
    4955#include "include/mac_client.h"         /* for mac_* */
    5056#include "include/mac_client_priv.h"    /* for mac_info, mac_capab_get etc. */
    51 #if 0
     57#if 1
    5258#include "include/dls.h"                /* for dls_mgmt_* */
    5359#include "include/dld_ioc.h"            /* required by vnic.h */
    5460#include "include/vnic.h"               /* for vnic_ioc_diag_t */
    5561#include "include/vnic_impl.h"          /* for vnic_dev_create */
     62#endif
    5663#endif
    5764
     
    6976#define VBOXFLT_VNIC_NAME               "vboxvnic"
    7077/** Debugging switch for using symbols in kmdb */
    71 # define LOCAL      static
     78# define LOCAL                          static
    7279
    7380#if defined(DEBUG_ramshankar)
     
    7986# define LOCAL
    8087#endif
     88
     89/** VLAN tag masking, should probably be in IPRT? */
     90#define VLAN_ID(vlan)          (((vlan) >>  0) & 0x0fffu)
     91#define VLAN_CFI(vlan)         (((vlan) >> 12) & 0x0001u)
     92#define VLAN_PRI(vlan)         (((vlan) >> 13) & 0x0007u)
     93#define VLAN_TAG(pri,cfi,vid)  (((pri) << 13) | ((cfi) << 12) | ((vid) << 0))
     94
     95typedef struct VLANHEADER
     96{
     97    uint16_t Type;
     98    uint16_t Data;
     99} VLANHEADER;
     100typedef struct VLANHEADER *PVLANHEADER;
    81101
    82102
     
    521541 * @param   pMsg    Pointer to the message to analyze and dump.
    522542 */
    523 static void vboxNetFltSolarisAnalyzeMBlk(mblk_t *pMsg)
    524 {
    525     LogFlow((DEVICE_NAME ":vboxNetFltSolarisAnalyzeMBlk pMsg=%p\n", pMsg));
     543LOCAL void vboxNetFltSolarisAnalyzeMBlk(mblk_t *pMsg)
     544{
     545    LogFlowFunc((DEVICE_NAME ":vboxNetFltSolarisAnalyzeMBlk pMsg=%p\n", pMsg));
    526546
    527547    PCRTNETETHERHDR pEthHdr = (PCRTNETETHERHDR)pMsg->b_rptr;
     
    533553        {
    534554            if (pIpHdr->ip_p == RTNETIPV4_PROT_ICMP)
    535                 LogFlow((DEVICE_NAME ":ICMP D=%.6Rhxs  S=%.6Rhxs  T=%04x\n", pb, pb + 6, RT_BE2H_U16(*(uint16_t *)(pb + 12))));
     555                LogRel((DEVICE_NAME ":ICMP D=%.6Rhxs  S=%.6Rhxs  T=%04x\n", pb, pb + 6, RT_BE2H_U16(*(uint16_t *)(pb + 12))));
    536556            else if (pIpHdr->ip_p == RTNETIPV4_PROT_TCP)
    537                 LogFlow((DEVICE_NAME ":TCP D=%.6Rhxs  S=%.6Rhxs\n", pb, pb + 6));
     557                LogRel((DEVICE_NAME ":TCP D=%.6Rhxs  S=%.6Rhxs\n", pb, pb + 6));
    538558            else if (pIpHdr->ip_p == RTNETIPV4_PROT_UDP)
    539559            {
     
    554574    else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_VLAN))
    555575    {
    556         typedef struct VLANHEADER
    557         {
    558             int Pcp:3;
    559             int Cfi:1;
    560             int Vid:12;
    561         } VLANHEADER;
    562 
    563         VLANHEADER *pVlanHdr = (VLANHEADER *)(pMsg->b_rptr + sizeof(RTNETETHERHDR));
    564         LogFlow((DEVICE_NAME ":VLAN Pcp=%d Cfi=%d Id=%d\n", pVlanHdr->Pcp, pVlanHdr->Cfi, pVlanHdr->Vid >> 4));
    565         LogFlow((DEVICE_NAME "%.*Rhxd\n", MBLKL(pMsg), pMsg->b_rptr));
     576        PVLANHEADER pVlanHdr = (PVLANHEADER)(pMsg->b_rptr + sizeof(RTNETETHERHDR) - sizeof(pEthHdr->EtherType));
     577        LogRel((DEVICE_NAME ":VLAN Pcp=%u Cfi=%u Id=%u\n", VLAN_PRI(RT_BE2H_U16(pVlanHdr->Data)), VLAN_CFI(RT_BE2H_U16(pVlanHdr->Data)), VLAN_ID(RT_BE2H_U16(pVlanHdr->Data))));
     578        LogRel((DEVICE_NAME "%.*Rhxd\n", sizeof(VLANHEADER), pVlanHdr));
    566579    }
    567580    else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_ARP))
    568581    {
    569582        PRTNETARPHDR pArpHdr = (PRTNETARPHDR)(pEthHdr + 1);
    570         LogFlow((DEVICE_NAME ":ARP Op=%d\n", pArpHdr->ar_oper));
     583        LogRel((DEVICE_NAME ":ARP Op=%d\n", pArpHdr->ar_oper));
    571584    }
    572585    else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPV6))
    573586    {
    574         LogFlow((DEVICE_NAME ":IPv6 D=%.6Rhxs S=%.6Rhxs\n", pb, pb + 6));
     587        LogRel((DEVICE_NAME ":IPv6 D=%.6Rhxs S=%.6Rhxs\n", pb, pb + 6));
    575588    }
    576589    else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_1)
     
    578591             || pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_3))
    579592    {
    580         LogFlow((DEVICE_NAME ":IPX packet.\n"));
     593        LogRel((DEVICE_NAME ":IPX packet.\n"));
    581594    }
    582595    else
    583596    {
    584         LogFlow((DEVICE_NAME ":Unknown EtherType=%x D=%.6Rhxs S=%.6Rhxs\n", RT_H2BE_U16(pEthHdr->EtherType), &pEthHdr->DstMac,
     597        LogRel((DEVICE_NAME ":Unknown EtherType=%x D=%.6Rhxs S=%.6Rhxs\n", RT_H2BE_U16(pEthHdr->EtherType), &pEthHdr->DstMac,
    585598                    &pEthHdr->SrcMac));
    586599        /* LogFlow((DEVICE_NAME ":%.*Rhxd\n", MBLKL(pMsg), pMsg->b_rptr)); */
     
    631644     * Route all received packets into the internal network.
    632645     */
    633     unsigned cSegs = vboxNetFltSolarisMBlkCalcSGSegs(pThis, pMsg);
    634     PINTNETSG pSG = (PINTNETSG)alloca(RT_OFFSETOF(INTNETSG, aSegs[cSegs]));
    635     int rc = vboxNetFltSolarisMBlkToSG(pThis, pMsg, pSG, cSegs, fSrc);
    636     if (RT_SUCCESS(rc))
    637         pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, pSG, fSrc);
     646    uint16_t cFailed = 0;
     647    for (mblk_t *pCurMsg = pMsg; pCurMsg != NULL; pCurMsg = pCurMsg->b_next)
     648    {
     649        unsigned cSegs = vboxNetFltSolarisMBlkCalcSGSegs(pThis, pCurMsg);
     650        PINTNETSG pSG = (PINTNETSG)alloca(RT_OFFSETOF(INTNETSG, aSegs[cSegs]));
     651        int rc = vboxNetFltSolarisMBlkToSG(pThis, pMsg, pSG, cSegs, fSrc);
     652        if (RT_SUCCESS(rc))
     653            pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, pSG, fSrc);
     654        else
     655            cFailed++;
     656    }
     657    vboxNetFltRelease(pThis, true /* fBusy */);
     658
     659    if (RT_UNLIKELY(cFailed))
     660        LogRel((DEVICE_NAME ":vboxNetFltSolarisMBlkToSG failed for %u packets.\n", cFailed));
     661
     662    freemsgchain(pMsg);
     663
     664    NOREF(hResource);
     665}
     666
     667
     668/**
     669 * Destroy a created VNIC.
     670 *
     671 * @param   pThis           The VM connection instance.
     672 */
     673LOCAL void vboxNetFltSolarisDestroyVNIC(PVBOXNETFLTINS pThis)
     674{
     675    if (pThis->u.s.fCreatedVNIC)
     676    {
     677        vnic_delete(pThis->u.s.VNICLinkId, 0 /* Flags */);
     678        pThis->u.s.VNICLinkId = DATALINK_INVALID_LINKID;
     679        pThis->u.s.fCreatedVNIC = false;
     680    }
     681}
     682
     683
     684/**
     685 * Create a non-persistent VNIC over the given interface.
     686 *
     687 * @param   pThis           The VM connection instance.
     688 *
     689 * @returns corresponding VBox error code.
     690 */
     691LOCAL int vboxNetFltSolarisCreateVNIC(PVBOXNETFLTINS pThis)
     692{
     693    LogFlow((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC pThis=%p\n", pThis));
     694
     695    char szVNICName[sizeof(VBOXFLT_VNIC_NAME) + 32];
     696    RTStrPrintf(szVNICName, sizeof(szVNICName), "%s%d", VBOXFLT_VNIC_NAME, pThis->u.s.uInstance);
     697
     698    /* -XXX- @todo remove hardcoded Guest MAC address, should be sent from guest later. */
     699    RTMAC GuestMac;
     700    GuestMac.au8[0] = 0x08;
     701    GuestMac.au8[1] = 0x00;
     702    GuestMac.au8[2] = 0x27;
     703    GuestMac.au8[3] = 0xFE;
     704    GuestMac.au8[4] = 0x21;
     705    GuestMac.au8[5] = 0x03;
     706
     707    AssertCompile(sizeof(RTMAC) <= MAXMACADDRLEN);
     708    uchar_t MacAddr[MAXMACADDRLEN];
     709    bzero(MacAddr, sizeof(MacAddr));
     710    bcopy(GuestMac.au8, MacAddr, RT_MIN(sizeof(GuestMac), sizeof(MacAddr)));
     711
     712    vnic_mac_addr_type_t AddrType = VNIC_MAC_ADDR_TYPE_FIXED;
     713    vnic_ioc_diag_t Diag = VNIC_IOC_DIAG_NONE;
     714    int MacSlot = 0;
     715    int MacLen = sizeof(GuestMac);
     716    uint32_t fFlags = 0; /* no VNIC_IOC_CREATE_NODUPCHECK */
     717    int rc = vnic_create(szVNICName, pThis->szName, &AddrType, &MacLen, MacAddr, &MacSlot, 0 /* Mac-Prefix Length */, 0 /* VLAN-ID */,
     718                        fFlags, &pThis->u.s.VNICLinkId, &Diag, NULL /* Reserved */);
     719    if (!rc)
     720    {
     721        pThis->u.s.fCreatedVNIC = true;
     722        pThis->u.s.uInstance++;
     723
     724        /*
     725         * Now try opening the created VNIC.
     726         */
     727        rc = mac_open_by_linkid(pThis->u.s.VNICLinkId, &pThis->u.s.hInterface);
     728        if (!rc)
     729        {
     730            Assert(pThis->u.s.hInterface);
     731            LogFlow((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC successfully created VNIC '%s' over '%s'\n", szVNICName, pThis->szName));
     732            return VINF_SUCCESS;
     733        }
     734        else
     735        {
     736            LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to open VNIC '%s' over '%s'. rc=%d\n", szVNICName,
     737                        pThis->szName, rc));
     738        }
     739
     740        vboxNetFltSolarisDestroyVNIC(pThis);
     741        rc = VERR_INTNET_FLT_IF_FAILED;
     742    }
    638743    else
    639         LogRel((DEVICE_NAME ":vboxNetFltSolarisMBlkToSG failed. rc=%d\n", rc));
    640 
    641     vboxNetFltRelease(pThis, true /* fBusy */);
    642     freemsgchain(pMsg);
    643 
    644     NOREF(hResource);
    645 }
    646 
    647 
    648 /**
    649  * Create a VNIC dynamically over the given interface.
    650  *
    651  * @param   pThis           The VM connection instance.
    652  *
    653  * @returns corresponding VBox error code.
    654  */
    655 LOCAL int vboxNetFltSolarisCreateVNIC(PVBOXNETFLTINS pThis)
    656 {
    657 #if 0
    658     LogFlow((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC pThis=%p\n", pThis));
    659 
    660     datalink_id_t InterfaceLinkId;
    661     int rc = dls_mgmt_get_linkid(pThis->szName, &InterfaceLinkId);
    662     if (!rc)
    663     {
    664         dev_t DeviceNum = makedevice(ddi_driver_major(g_pVBoxNetFltSolarisDip), pThis->u.s.uInstance);
    665         char szVNICName[sizeof(VBOXFLT_VNIC_NAME) + 16];
    666         RTStrPrintf(szVNICName, sizeof(szVNICName), "%s%d", VBOXFLT_VNIC_NAME, pThis->u.s.uInstance);
    667         LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC Creating VNIC '%s' over '%s'\n", szVNICName, pThis->szName));
    668         rc = dls_mgmt_create(szVNICName, DeviceNum, DATALINK_CLASS_VNIC, DL_ETHER, B_FALSE /* Persist */, &pThis->u.s.VNICLinkId);
    669         if (!rc)
    670         {
    671             /* -XXX- @todo remove hardcoded Guest MAC address, should be sent from guest later. */
    672             RTMAC GuestMac;
    673             GuestMac.au8[0] = 0x08;
    674             GuestMac.au8[1] = 0x00;
    675             GuestMac.au8[2] = 0x27;
    676             GuestMac.au8[3] = 0xFE;
    677             GuestMac.au8[4] = 0x21;
    678             GuestMac.au8[5] = 0x03;
    679 
    680             AssertCompile(sizeof(RTMAC) <= MAXMACADDRLEN);
    681             uchar_t MacAddr[MAXMACADDRLEN];
    682             bzero(MacAddr, sizeof(MacAddr));
    683             bcopy(GuestMac.au8, MacAddr, RT_MIN(sizeof(GuestMac), sizeof(MacAddr)));
    684 
    685             int MacSlot = 0;
    686             vnic_ioc_diag_t Diag = VNIC_IOC_DIAG_NONE;
    687             vnic_mac_addr_type_t MacAddrType = VNIC_MAC_ADDR_TYPE_FIXED;
    688             int cbMac = sizeof(RTMAC);
    689             int fFlags = VNIC_IOC_CREATE_NODUPCHECK | VNIC_IOC_CREATE_REQ_HWRINGS;
    690             rc = vnic_dev_create(pThis->u.s.VNICLinkId, InterfaceLinkId, &MacAddrType, &cbMac, MacAddr,
    691                                 &MacSlot, 0 /* Mac Prefix */, 0 /* VLAN Id */, NULL /* Resources Caps */,
    692                                 fFlags, &Diag, kcred);
    693             if (rc)
    694             {
    695                 if (Diag == VNIC_IOC_DIAG_NO_HWRINGS)
    696                 {
    697                     /*
    698                      * No hardware rings available, retry without requesting hardware ring.
    699                      */
    700                     LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC No hardware rings available for VNIC over '%s'. Recreating VNIC '%s'\n", pThis->szName,
    701                                     szVNICName));
    702 
    703                     fFlags = VNIC_IOC_CREATE_NODUPCHECK;
    704                     rc = vnic_dev_create(pThis->u.s.VNICLinkId, InterfaceLinkId, &MacAddrType, &cbMac, MacAddr,
    705                                         &MacSlot, 0 /* Mac Prefix */, 0 /* VLAN Id */, NULL /* Resources Caps */,
    706                                         fFlags, &Diag, kcred);
    707                 }
    708             }
    709 
    710             if (!rc)
    711             {
    712                 pThis->u.s.fCreatedVNIC = true;
    713                 pThis->u.s.uInstance++;
    714                 LogFlow((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC successfully created VNIC '%s' over '%s'\n", "vboxvnic", pThis->szName));
    715                 return VINF_SUCCESS;
    716             }
    717             else
    718             {
    719                 LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to create VNIC over '%s'. rc=%d Diagnosis=%d\n", pThis->szName,
    720                             rc, Diag));
    721                 rc = VERR_INTNET_FLT_VNIC_CREATE_FAILED;
    722             }
    723 
    724             dls_mgmt_destroy(pThis->u.s.VNICLinkId, B_FALSE /* Persist */);
    725         }
    726         else
    727         {
    728             LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to create a link id for a VNIC over '%s' rc=%d\n", pThis->szName, rc));
    729             rc = VERR_INTNET_FLT_VNIC_CREATE_FAILED;
    730         }
    731     }
    732     else
    733     {
    734         LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to find interface '%s' rc=%d\n", pThis->szName, rc));
    735         rc = VERR_INTNET_FLT_IF_NOT_FOUND;
     744    {
     745        LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed! rc=%d Diag=%d\n", rc, (int)Diag));
     746        rc = VERR_INTNET_FLT_IF_FAILED;
    736747    }
    737748
    738749    return rc;
    739 #endif
    740750}
    741751
     
    772782            pThis->u.s.hInterface = NULL;
    773783            rc = vboxNetFltSolarisCreateVNIC(pThis);
    774             if (RT_SUCCESS(rc))
    775                 rc = mac_open_by_linkid(pThis->u.s.VNICLinkId, &pThis->u.s.hInterface);
    776             else
    777             {
    778                 pThis->u.s.hInterface = NULL;
    779                 LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to create VNIC. rc=%Rrc\n", rc));
    780             }
    781784        }
    782785        else
     
    789792        if (RT_SUCCESS(rc))
    790793        {
    791             const mac_info_t *pMacInfo = mac_info(pThis->u.s.hInterface);
    792             if (RT_LIKELY(pMacInfo))
     794            /*
     795             * Obtain the MAC address of the interface.
     796             */
     797            Assert(pThis->u.s.hInterface);
     798            AssertCompile(sizeof(RTMAC) == ETHERADDRL);
     799            mac_unicast_primary_get(pThis->u.s.hInterface, (uint8_t *)&pThis->u.s.MacAddr.au8);
     800
     801            LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface MAC address of %s is %.*Rhxs\n", pThis->szName,
     802                     sizeof(pThis->u.s.MacAddr), &pThis->u.s.MacAddr));
     803
     804            /** @todo Obtain the MTU size using mac_sdu_get() */
     805            /** @todo Obtain capabilities (hardware checksum etc.) using mac_capab_get() */
     806
     807            /*
     808             * Open a client connection to the lower MAC interface.
     809             */
     810            rc = mac_client_open(pThis->u.s.hInterface, &pThis->u.s.hClient,
     811                                 NULL,                                   /* name of this client */
     812                                 MAC_OPEN_FLAGS_USE_DATALINK_NAME |     /* client name same as underlying NIC */
     813                                 MAC_OPEN_FLAGS_MULTI_PRIMARY           /* allow multiple primary unicasts */
     814                                 );
     815            if (RT_LIKELY(!rc))
    793816            {
    794                 if (   pMacInfo->mi_media == DL_ETHER
    795                     && pMacInfo->mi_nativemedia == DL_ETHER)
     817                /** @todo -XXX- if possible we must move unicast_add and rx_set to when the Guest advertises it's MAC to us.  */
     818
     819                /*
     820                 * Set a unicast address for this client and the packet receive callback.
     821                 * We want to use the primary unicast address of the underlying interface (VNIC) hence we pass NULL.
     822                 * Also we don't really set the RX function here, this is done when we activate promiscuous mode.
     823                 */
     824                mac_diag_t MacDiag;
     825                rc = mac_unicast_add(pThis->u.s.hClient, NULL /* MAC Address */,
     826                                    MAC_UNICAST_PRIMARY | MAC_UNICAST_STRIP_DISABLE |
     827                                    MAC_UNICAST_DISABLE_TX_VID_CHECK | MAC_UNICAST_NODUPCHECK | MAC_UNICAST_HW,
     828                                    &pThis->u.s.hUnicast, 0 /* VLAN id */, &MacDiag);
     829                if (!rc)
    796830                {
     831                    if (vboxNetFltTryRetainBusyNotDisconnected(pThis))
     832                    {
     833                        Assert(pThis->pSwitchPort);
     834                        pThis->pSwitchPort->pfnReportMacAddress(pThis->pSwitchPort, &pThis->u.s.MacAddr);
     835                        pThis->pSwitchPort->pfnReportPromiscuousMode(pThis->pSwitchPort, false); /** @todo Promisc */
     836                        pThis->pSwitchPort->pfnReportGsoCapabilities(pThis->pSwitchPort, 0, INTNETTRUNKDIR_WIRE | INTNETTRUNKDIR_HOST);
     837                        pThis->pSwitchPort->pfnReportNoPreemptDsts(pThis->pSwitchPort, 0 /* none */);
     838                        vboxNetFltRelease(pThis, true /*fBusy*/);
     839                    }
     840
    797841                    /*
    798                      * Obtain the MAC address of the interface.
     842                     * If the user passed in the VNIC, we need to obtain the datalink ID now.
    799843                     */
    800                     AssertCompile(sizeof(RTMAC) == ETHERADDRL);
    801                     mac_unicast_primary_get(pThis->u.s.hInterface, (uint8_t *)&pThis->u.s.MacAddr.au8);
    802 
    803                     LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface MAC address of %s is %.*Rhxs\n", pThis->szName,
    804                              sizeof(pThis->u.s.MacAddr), &pThis->u.s.MacAddr));
    805 
    806                     /** @todo Obtain the MTU size using mac_sdu_get() */
    807                     /** @todo Obtain capabilities (hardware checksum etc.) using mac_capab_get() */
    808 
    809                     /*
    810                      * Open a client connection to the lower MAC interface.
    811                      */
    812                     rc = mac_client_open(pThis->u.s.hInterface, &pThis->u.s.hClient,
    813                                          NULL                                   /* name of this client */,
    814                                          MAC_OPEN_FLAGS_USE_DATALINK_NAME |     /* client name same as underlying NIC */
    815                                          MAC_OPEN_FLAGS_MULTI_PRIMARY           /* allow multiple primary unicasts */
    816                                          );
    817                     if (RT_LIKELY(!rc))
     844                    if (pThis->u.s.fCreatedVNIC == false)
     845                        rc = dls_mgmt_get_linkid(pThis->szName, &pThis->u.s.VNICLinkId);
     846
     847                    if (!rc)
    818848                    {
    819                         /** @todo -XXX- if possible we must move unicast_add and rx_set to when the Guest advertises it's MAC to us.  */
    820 
    821849                        /*
    822                          * Set a unicast address for this client and the packet receive callback.
    823                          * We want to use the primary unicast address of the underlying interface (VNIC) hence we pass NULL.
    824                          * Also we don't really set the RX function here, this is done when we activate promiscuous mode.
     850                         * Modify the MAC address of the VNIC to match the guest's MAC address
    825851                         */
    826                         mac_diag_t MacDiag;
    827                         rc = mac_unicast_add(pThis->u.s.hClient, NULL /* MAC Address */,
    828                                             MAC_UNICAST_PRIMARY | MAC_UNICAST_STRIP_DISABLE |
    829                                             MAC_UNICAST_DISABLE_TX_VID_CHECK | MAC_UNICAST_NODUPCHECK | MAC_UNICAST_HW,
    830                                             &pThis->u.s.hUnicast, 0 /* VLAN id */, &MacDiag);
     852                        LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface success!\n"));
     853
     854                        RTMAC GuestMac;
     855                        GuestMac.au8[0] = 0x08;
     856                        GuestMac.au8[1] = 0x00;
     857                        GuestMac.au8[2] = 0x27;
     858                        GuestMac.au8[3] = 0xFE;
     859                        GuestMac.au8[4] = 0x21;
     860                        GuestMac.au8[5] = 0x03;
     861
     862                        uchar_t MacAddr[MAXMACADDRLEN];
     863                        bcopy(GuestMac.au8, MacAddr, sizeof(GuestMac));
     864
     865                        vnic_mac_addr_type_t AddrType = VNIC_MAC_ADDR_TYPE_FIXED;
     866                        vnic_ioc_diag_t Result = VNIC_IOC_DIAG_NONE;
     867                        int MacSlot = 0;
     868                        int MacLen = sizeof(GuestMac);
     869                        rc = vnic_modify_addr(pThis->u.s.VNICLinkId, &AddrType, &MacLen, MacAddr, &MacSlot, 0 /* Mac-Prefix Length */, &Result);
    831870                        if (!rc)
    832871                        {
    833                             /*
    834                              * Report MAC address, promiscuous mode and capabilities.
    835                              */
    836                             if (vboxNetFltTryRetainBusyNotDisconnected(pThis))
    837                             {
    838                                 Assert(pThis->pSwitchPort);
    839                                 pThis->pSwitchPort->pfnReportMacAddress(pThis->pSwitchPort, &pThis->u.s.MacAddr);
    840                                 pThis->pSwitchPort->pfnReportPromiscuousMode(pThis->pSwitchPort, false); /** @todo Promisc */
    841                                 pThis->pSwitchPort->pfnReportGsoCapabilities(pThis->pSwitchPort, 0, INTNETTRUNKDIR_WIRE | INTNETTRUNKDIR_HOST);
    842                                 pThis->pSwitchPort->pfnReportNoPreemptDsts(pThis->pSwitchPort, 0 /* none */);
    843                                 vboxNetFltRelease(pThis, true /*fBusy*/);
    844                             }
    845 
    846                             LogFlow((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface successfully attached over '%s'\n", pThis->szName));
    847                             return VINF_SUCCESS;
     872                            LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface vnic_modify successful %s mac %.*Rhxs\n", pThis->szName,
     873                                            sizeof(GuestMac), &GuestMac));
     874
     875                            mac_unicast_remove(pThis->u.s.hClient, pThis->u.s.hUnicast);
     876                            pThis->u.s.hUnicast = NULL;
     877                            rc = mac_unicast_add(pThis->u.s.hClient, NULL /* MAC Address */,
     878                                                MAC_UNICAST_PRIMARY | MAC_UNICAST_STRIP_DISABLE |
     879                                                MAC_UNICAST_DISABLE_TX_VID_CHECK | MAC_UNICAST_NODUPCHECK | MAC_UNICAST_HW,
     880                                                &pThis->u.s.hUnicast, 0 /* VLAN id */, &MacDiag);
     881
     882                            if (!rc)
     883                                return VINF_SUCCESS;
     884
     885                            LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to set client MAC address (2) '%s' rc=%d\n",
     886                                    pThis->szName, rc));
    848887                        }
    849 
    850                         LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to set client MAC address over link '%s' rc=%d\n",
    851                                 pThis->szName, rc));
    852 
    853                         mac_client_close(pThis->u.s.hClient, 0 /* fFlags */);
    854                         pThis->u.s.hClient = NULL;
     888                        else
     889                        {
     890                            LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to modify MAC address for VNIC over '%s' rc=%d\n",
     891                                    pThis->szName, rc));
     892                        }
    855893                    }
    856894                    else
    857895                    {
    858                         LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to create client over link '%s' rc=%d\n",
    859                                 pThis->szName, rc));
     896                        LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to obtain VNIC link id for '%s' rc=%d\n",
     897                                    pThis->szName, rc));
    860898                    }
    861899                }
    862900                else
    863                 {
    864                     LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface media type incompatible: %d %d\n", pMacInfo->mi_media,
    865                             pMacInfo->mi_nativemedia));
    866                     rc = EPROTO;
    867                 }
     901                    LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to set client MAC address over link '%s' rc=%d\n",
     902                            pThis->szName, rc));
     903
     904                mac_client_close(pThis->u.s.hClient, 0 /* fFlags */);
     905                pThis->u.s.hClient = NULL;
    868906            }
    869907            else
    870908            {
    871                 LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to obtain info for link '%s'\n", pThis->szName));
    872                 rc = ENXIO;
     909                LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachToInterface failed to create client over link '%s' rc=%d\n",
     910                        pThis->szName, rc));
    873911            }
    874912        }
     
    884922            pThis->u.s.hInterface = NULL;
    885923        }
     924
     925        vboxNetFltSolarisDestroyVNIC(pThis);
    886926    }
    887927    else
     
    929969    }
    930970
    931     if (pThis->u.s.fCreatedVNIC)
    932     {
    933 #if 0
    934         vnic_dev_delete(pThis->u.s.VNICLinkId, 0 /* Flags -- ununsed in snv_127 */, kcred);
    935         dls_mgmt_destroy(pThis->u.s.VNICLinkId, B_FALSE /* Persist */);
    936         pThis->u.s.VNICLinkId = DATALINK_INVALID_LINKID;
    937         pThis->u.s.fCreatedVNIC = false;
    938 #endif
    939     }
     971    vboxNetFltSolarisDestroyVNIC(pThis);
    940972}
    941973
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