VirtualBox

Changeset 17118 in vbox for trunk


Ignore:
Timestamp:
Feb 25, 2009 10:46:39 AM (16 years ago)
Author:
vboxsync
Message:

#2957: VBoxNetAdp: More fixes in generic and darwin parts. Pings go through.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdp.c

    r17095 r17118  
    331331    }
    332332    RTSpinlockRelease(pThis->hSpinlock, &Tmp);
     333    Log(("vboxNetAdpPrepareToReceive: fCanReceive=%d.\n", fCanReceive));
    333334
    334335    return fCanReceive;
     
    350351    AssertPtr(pThis->pSwitchPort);
    351352    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
     353    Log(("vboxNetAdpReceive: forwarding packet to internal net...\n"));
    352354    pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, pSG, INTNETTRUNKDIR_HOST);
    353355    vboxNetAdpIdle(pThis);
     
    362364DECLHIDDEN(void) vboxNetAdpCancelReceive(PVBOXNETADP pThis)
    363365{
     366    Log(("vboxNetAdpCancelReceive: cancelled.\n"));
    364367    vboxNetAdpIdle(pThis);
    365368    vboxNetAdpRelease(pThis);
     
    405408    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
    406409
     410    Log(("vboxNetAdpPortXmit: outgoing packet (len=%d)\n", pSG->cbTotal));
     411
    407412    /*
    408413     * Do a retain/busy, invoke the OS specific code.
     
    439444    AssertPtr(pThis);
    440445    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
    441     Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Connected);
     446    Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Active);
    442447
    443448    /*
     
    460465    AssertPtr(pThis);
    461466    Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
    462     Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Connected);
     467    Assert(vboxNetAdpGetStateWithLock(pThis) == kVBoxNetAdpState_Active);
    463468
    464469    /*
     
    548553            case kVBoxNetAdpState_Active:
    549554                vboxNetAdpSetState(pThis, kVBoxNetAdpState_Connected);
     555                break;
     556            default:
    550557                break;
    551558        }
  • trunk/src/VBox/HostDrivers/VBoxNetAdp/darwin/VBoxNetAdp-darwin.cpp

    r17095 r17118  
    4242#include <iprt/string.h>
    4343#include <iprt/uuid.h>
     44#include <iprt/alloca.h>
    4445
    4546#include <sys/systm.h>
     
    6364*   Defined Constants And Macros                                               *
    6465*******************************************************************************/
    65 #define VBOXNETADP_MAX_FAMILIES   4
    66 #define VBOXNETADP_NAME           "vboxnet"
    67 #define VBOXNETADP_MTU            1500
    68 #define VBOXNETADP_DETACH_TIMEOUT 500
     66/** The maximum number of SG segments.
     67 * Used to prevent stack overflow and similar bad stuff. */
     68#define VBOXNETADP_DARWIN_MAX_SEGS       32
     69#define VBOXNETADP_DARWIN_MAX_FAMILIES   4
     70#define VBOXNETADP_DARWIN_NAME           "vboxnet"
     71#define VBOXNETADP_DARWIN_MTU            1500
     72#define VBOXNETADP_DARWIN_DETACH_TIMEOUT 500
    6973
    7074#define VBOXNETADP_FROM_IFACE(iface) ((PVBOXNETADP) ifnet_softc(iface))
     
    121125DECLINLINE(ifnet_t) vboxNetAdpDarwinRetainIfNet(PVBOXNETADP pThis)
    122126{
    123     ifnet_t pIfNet = NULL;
    124 
    125     ifnet_reference(pThis->u.s.pIface);
    126 
    127     return pIfNet;
     127    if (pThis->u.s.pIface)
     128        ifnet_reference(pThis->u.s.pIface);
     129
     130    return pThis->u.s.pIface;
    128131}
    129132
     
    141144    if (pIfNet)
    142145        ifnet_release(pIfNet);
    143 }
    144 
    145 
    146 
    147 static errno_t vboxNetAdpDarwinOutput(ifnet_t pIface, mbuf_t pMBuf)
    148 {
    149     PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface);
    150     Assert(pThis);
    151     if (vboxNetAdpPrepareToReceive(pThis))
    152     {
    153         if (/* converted to SG */0)
    154             vboxNetAdpReceive(pThis, NULL);
    155         else
    156             vboxNetAdpCancelReceive(pThis);
    157     }
    158     mbuf_freem_list(pMBuf);
    159     return 0;
    160 }
    161 
    162 static void vboxNetAdpDarwinAttachFamily(PVBOXNETADP pThis, protocol_family_t Family)
    163 {
    164     u_int32_t i;
    165     for (i = 0; i < VBOXNETADP_MAX_FAMILIES; i++)
    166         if (pThis->u.s.aAttachedFamilies[i] == 0)
    167         {
    168             pThis->u.s.aAttachedFamilies[i] = Family;
    169             break;
    170         }
    171 }
    172 
    173 static void vboxNetAdpDarwinDetachFamily(PVBOXNETADP pThis, protocol_family_t Family)
    174 {
    175     u_int32_t i;
    176     for (i = 0; i < VBOXNETADP_MAX_FAMILIES; i++)
    177         if (pThis->u.s.aAttachedFamilies[i] == Family)
    178             pThis->u.s.aAttachedFamilies[i] = 0;
    179 }
    180 
    181 static errno_t vboxNetAdpDarwinAddProto(ifnet_t pIface, protocol_family_t Family, const struct ifnet_demux_desc *pDemuxDesc, u_int32_t nDesc)
    182 {
    183     PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface);
    184     Assert(pThis);
    185     vboxNetAdpDarwinAttachFamily(pThis, Family);
    186     LogFlow(("vboxNetAdpAddProto: Family=%d.\n", Family));
    187     return ether_add_proto(pIface, Family, pDemuxDesc, nDesc);
    188 }
    189 
    190 static errno_t vboxNetAdpDarwinDelProto(ifnet_t pIface, protocol_family_t Family)
    191 {
    192     PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface);
    193     Assert(pThis);
    194     LogFlow(("vboxNetAdpDelProto: Family=%d.\n", Family));
    195     vboxNetAdpDarwinDetachFamily(pThis, Family);
    196     return ether_del_proto(pIface, Family);
    197 }
    198 
    199 static void vboxNetAdpDarwinDetach(ifnet_t pIface)
    200 {
    201     PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface);
    202     Assert(pThis);
    203     Log2(("vboxNetAdpDarwinDetach: Signaling detach to vboxNetAdpUnregisterDevice.\n"));
    204     /* Let vboxNetAdpDarwinUnregisterDevice know that the interface has been detached. */
    205     RTSemEventSignal(pThis->u.s.hEvtDetached);
    206146}
    207147
     
    500440}
    501441
     442
     443static errno_t vboxNetAdpDarwinOutput(ifnet_t pIface, mbuf_t pMBuf)
     444{
     445    PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface);
     446    Assert(pThis);
     447    if (vboxNetAdpPrepareToReceive(pThis))
     448    {
     449        unsigned cSegs = vboxNetAdpDarwinMBufCalcSGSegs(pThis, pMBuf, NULL);
     450        if (cSegs < VBOXNETADP_DARWIN_MAX_SEGS)
     451        {
     452            PINTNETSG pSG = (PINTNETSG)alloca(RT_OFFSETOF(INTNETSG, aSegs[cSegs]));
     453            vboxNetAdpDarwinMBufToSG(pThis, pMBuf, NULL, pSG, cSegs, INTNETTRUNKDIR_HOST);
     454            vboxNetAdpReceive(pThis, pSG);
     455        }
     456        else
     457            vboxNetAdpCancelReceive(pThis);
     458    }
     459    mbuf_freem_list(pMBuf);
     460    return 0;
     461}
     462
     463static void vboxNetAdpDarwinAttachFamily(PVBOXNETADP pThis, protocol_family_t Family)
     464{
     465    u_int32_t i;
     466    for (i = 0; i < VBOXNETADP_MAX_FAMILIES; i++)
     467        if (pThis->u.s.aAttachedFamilies[i] == 0)
     468        {
     469            pThis->u.s.aAttachedFamilies[i] = Family;
     470            break;
     471        }
     472}
     473
     474static void vboxNetAdpDarwinDetachFamily(PVBOXNETADP pThis, protocol_family_t Family)
     475{
     476    u_int32_t i;
     477    for (i = 0; i < VBOXNETADP_MAX_FAMILIES; i++)
     478        if (pThis->u.s.aAttachedFamilies[i] == Family)
     479            pThis->u.s.aAttachedFamilies[i] = 0;
     480}
     481
     482static errno_t vboxNetAdpDarwinAddProto(ifnet_t pIface, protocol_family_t Family, const struct ifnet_demux_desc *pDemuxDesc, u_int32_t nDesc)
     483{
     484    PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface);
     485    Assert(pThis);
     486    vboxNetAdpDarwinAttachFamily(pThis, Family);
     487    LogFlow(("vboxNetAdpAddProto: Family=%d.\n", Family));
     488    return ether_add_proto(pIface, Family, pDemuxDesc, nDesc);
     489}
     490
     491static errno_t vboxNetAdpDarwinDelProto(ifnet_t pIface, protocol_family_t Family)
     492{
     493    PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface);
     494    Assert(pThis);
     495    LogFlow(("vboxNetAdpDelProto: Family=%d.\n", Family));
     496    vboxNetAdpDarwinDetachFamily(pThis, Family);
     497    return ether_del_proto(pIface, Family);
     498}
     499
     500static void vboxNetAdpDarwinDetach(ifnet_t pIface)
     501{
     502    PVBOXNETADP pThis = VBOXNETADP_FROM_IFACE(pIface);
     503    Assert(pThis);
     504    Log2(("vboxNetAdpDarwinDetach: Signaling detach to vboxNetAdpUnregisterDevice.\n"));
     505    /* Let vboxNetAdpDarwinUnregisterDevice know that the interface has been detached. */
     506    RTSemEventSignal(pThis->u.s.hEvtDetached);
     507}
     508
     509
     510
    502511int  vboxNetAdpPortOsXmit(PVBOXNETADP pThis, PINTNETSG pSG, uint32_t fDst)
    503512{
     
    509518         * Create a mbuf for the gather list and push it onto the host stack.
    510519         */
    511         if (fDst & INTNETTRUNKDIR_HOST)
    512         {
    513             mbuf_t pMBuf = vboxNetAdpDarwinMBufFromSG(pThis, pSG);
    514             if (pMBuf)
    515             {
    516                 /* This is what IONetworkInterface::inputPacket does. */
    517                 unsigned const cbEthHdr = 14;
    518                 mbuf_pkthdr_setheader(pMBuf, mbuf_data(pMBuf));
    519                 mbuf_pkthdr_setlen(pMBuf, mbuf_pkthdr_len(pMBuf) - cbEthHdr);
    520                 mbuf_setdata(pMBuf, (uint8_t *)mbuf_data(pMBuf) + cbEthHdr, mbuf_len(pMBuf) - cbEthHdr);
    521                 mbuf_pkthdr_setrcvif(pMBuf, pIfNet); /* will crash without this. */
    522 
    523                 errno_t err = ifnet_input(pIfNet, pMBuf, NULL);
    524                 if (err)
    525                     rc = RTErrConvertFromErrno(err);
    526             }
    527             else
    528                 rc = VERR_NO_MEMORY;
     520        mbuf_t pMBuf = vboxNetAdpDarwinMBufFromSG(pThis, pSG);
     521        if (pMBuf)
     522        {
     523            /* This is what IONetworkInterface::inputPacket does. */
     524            unsigned const cbEthHdr = 14;
     525            mbuf_pkthdr_setheader(pMBuf, mbuf_data(pMBuf));
     526            mbuf_pkthdr_setlen(pMBuf, mbuf_pkthdr_len(pMBuf) - cbEthHdr);
     527            mbuf_setdata(pMBuf, (uint8_t *)mbuf_data(pMBuf) + cbEthHdr, mbuf_len(pMBuf) - cbEthHdr);
     528            mbuf_pkthdr_setrcvif(pMBuf, pIfNet); /* will crash without this. */
     529
     530            Log(("vboxNetAdpPortOsXmit: calling ifnet_input()\n"));
     531            errno_t err = ifnet_input(pIfNet, pMBuf, NULL);
     532            if (err)
     533                rc = RTErrConvertFromErrno(err);
     534        }
     535        else
     536        {
     537            Log(("vboxNetAdpPortOsXmit: failed to convert SG to mbuf.\n"));
     538            rc = VERR_NO_MEMORY;
    529539        }
    530540
    531541        vboxNetAdpDarwinReleaseIfNet(pThis, pIfNet);
    532542    }
     543    else
     544        Log(("vboxNetAdpPortOsXmit: failed to retain the interface.\n"));
    533545
    534546    return rc;
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