VirtualBox

Ignore:
Timestamp:
Feb 16, 2010 12:44:10 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
57756
Message:

Networking: Preparing to make the driver return a send buffer to the device emulation.

Location:
trunk/src/VBox/NetworkServices/NetLib
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/NetLib/VBoxNetARP.cpp

    r26498 r26574  
    2626#include "VBoxNetLib.h"
    2727#include <iprt/string.h>
     28#include <VBox/intnetinline.h>
    2829#include <VBox/log.h>
    2930
     
    4546     * Valid IntNet Ethernet frame?
    4647     */
    47     PCINTNETHDR pHdr = (PINTNETHDR)((uintptr_t)pBuf + pBuf->Recv.offRead);
    48     if (pHdr->u16Type != INTNETHDR_TYPE_FRAME)
     48    PCINTNETHDR pHdr = INTNETRingGetNextFrameToRead(&pBuf->Recv);
     49    if (   !pHdr
     50        || pHdr->u16Type != INTNETHDR_TYPE_FRAME)
    4951        return false;
    5052
    51     size_t      cbFrame = pHdr->cbFrame;
    52     const void *pvFrame = INTNETHdrGetFramePtr(pHdr, pBuf);
     53    size_t          cbFrame = pHdr->cbFrame;
     54    const void     *pvFrame = INTNETHdrGetFramePtr(pHdr, pBuf);
    5355    PCRTNETETHERHDR pEthHdr = (PCRTNETETHERHDR)pvFrame;
    5456
  • trunk/src/VBox/NetworkServices/NetLib/VBoxNetIntIf.cpp

    r20864 r26574  
    2626#include "VBoxNetLib.h"
    2727#include <VBox/intnet.h>
     28#include <VBox/intnetinline.h>
    2829#include <VBox/sup.h>
    2930#include <VBox/vmm.h>
     
    8788     * Validate input.
    8889     */
    89     Assert(pBuf);
    90     Assert(pRingBuf);
    91     uint32_t offWrite = pRingBuf->offWrite;
    92     Assert(offWrite == RT_ALIGN_32(offWrite, sizeof(INTNETHDR)));
    93     uint32_t offRead = pRingBuf->offRead;
    94     Assert(offRead == RT_ALIGN_32(offRead, sizeof(INTNETHDR)));
     90    AssertPtr(pBuf);
     91    AssertPtr(pRingBuf);
    9592    AssertPtr(paSegs);
    9693    Assert(cSegs > 0);
    9794
    98     /* Calc frame size. */
     95    /*
     96     * Calc frame size.
     97     */
    9998    uint32_t cbFrame = 0;
    10099    for (size_t iSeg = 0; iSeg < cSegs; iSeg++)
    101100        cbFrame += paSegs[iSeg].cb;
    102 
    103101    Assert(cbFrame >= sizeof(RTMAC) * 2);
    104102
    105 
    106     const uint32_t cb = RT_ALIGN_32(cbFrame, sizeof(INTNETHDR));
    107     if (offRead <= offWrite)
     103    /*
     104     * Allocate a frame, copy the data and commit it.
     105     */
     106    PINTNETHDR pHdr;
     107    void *pvFrame;
     108    int rc = INTNETRingAllocateFrame(pRingBuf, cbFrame, &pHdr, &pvFrame);
     109    if (RT_SUCCESS(rc))
    108110    {
    109         /*
    110          * Try fit it all before the end of the buffer.
    111          */
    112         if (pRingBuf->offEnd - offWrite >= cb + sizeof(INTNETHDR))
    113         {
    114             PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pBuf + offWrite);
    115             pHdr->u16Type  = INTNETHDR_TYPE_FRAME;
    116             pHdr->cbFrame  = cbFrame;
    117             pHdr->offFrame = sizeof(INTNETHDR);
    118 
    119             vboxnetIntIfCopySG(pHdr + 1, cSegs, paSegs);
    120 
    121             offWrite += cb + sizeof(INTNETHDR);
    122             Assert(offWrite <= pRingBuf->offEnd && offWrite >= pRingBuf->offStart);
    123             if (offWrite >= pRingBuf->offEnd)
    124                 offWrite = pRingBuf->offStart;
    125             Log2(("WriteFrame: offWrite: %#x -> %#x (1)\n", pRingBuf->offWrite, offWrite));
    126             ASMAtomicXchgU32(&pRingBuf->offWrite, offWrite);
    127             return VINF_SUCCESS;
    128         }
    129 
    130         /*
    131          * Try fit the frame at the start of the buffer.
    132          * (The header fits before the end of the buffer because of alignment.)
    133          */
    134         AssertMsg(pRingBuf->offEnd - offWrite >= sizeof(INTNETHDR), ("offEnd=%x offWrite=%x\n", pRingBuf->offEnd, offWrite));
    135         if (offRead - pRingBuf->offStart > cb) /* not >= ! */
    136         {
    137             PINTNETHDR  pHdr = (PINTNETHDR)((uint8_t *)pBuf + offWrite);
    138             void       *pvFrameOut = (PINTNETHDR)((uint8_t *)pBuf + pRingBuf->offStart);
    139             pHdr->u16Type  = INTNETHDR_TYPE_FRAME;
    140             pHdr->cbFrame  = cbFrame;
    141             pHdr->offFrame = (intptr_t)pvFrameOut - (intptr_t)pHdr;
    142 
    143             vboxnetIntIfCopySG(pvFrameOut, cSegs, paSegs);
    144 
    145             offWrite = pRingBuf->offStart + cb;
    146             ASMAtomicXchgU32(&pRingBuf->offWrite, offWrite);
    147             Log2(("WriteFrame: offWrite: %#x -> %#x (2)\n", pRingBuf->offWrite, offWrite));
    148             return VINF_SUCCESS;
    149         }
    150     }
    151     /*
    152      * The reader is ahead of the writer, try fit it into that space.
    153      */
    154     else if (offRead - offWrite > cb + sizeof(INTNETHDR)) /* not >= ! */
    155     {
    156         PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pBuf + offWrite);
    157         pHdr->u16Type  = INTNETHDR_TYPE_FRAME;
    158         pHdr->cbFrame  = cbFrame;
    159         pHdr->offFrame = sizeof(INTNETHDR);
    160 
    161         vboxnetIntIfCopySG(pHdr + 1, cSegs, paSegs);
    162 
    163         offWrite += cb + sizeof(INTNETHDR);
    164         ASMAtomicXchgU32(&pRingBuf->offWrite, offWrite);
    165         Log2(("WriteFrame: offWrite: %#x -> %#x (3)\n", pRingBuf->offWrite, offWrite));
     111        vboxnetIntIfCopySG(pvFrame, cSegs, paSegs);
     112        INTNETRingCommitFrame(pRingBuf, pHdr);
    166113        return VINF_SUCCESS;
    167114    }
    168115
    169     /* (it didn't fit) */
    170     /** @todo stats */
    171     return VERR_BUFFER_OVERFLOW;
     116    return rc;
    172117}
    173118
  • trunk/src/VBox/NetworkServices/NetLib/VBoxNetLib.h

    r20374 r26574  
    5151/** @}  */
    5252
    53 void *  VBoxNetUDPMatch(PCINTNETBUF pBuf, unsigned uDstPort, PCRTMAC pDstMac, uint32_t fFlags, PVBOXNETUDPHDRS pHdrs, size_t *pcb);
     53void *  VBoxNetUDPMatch(PINTNETBUF pBuf, unsigned uDstPort, PCRTMAC pDstMac, uint32_t fFlags, PVBOXNETUDPHDRS pHdrs, size_t *pcb);
    5454int     VBoxNetUDPUnicast(PSUPDRVSESSION pSession, INTNETIFHANDLE hIf, PINTNETBUF pBuf,
    5555                          RTNETADDRIPV4 SrcIPv4Addr, PCRTMAC SrcMacAddr, unsigned uSrcPort,
  • trunk/src/VBox/NetworkServices/NetLib/VBoxNetUDP.cpp

    r18463 r26574  
    2929#include <iprt/rand.h>
    3030#include <VBox/log.h>
     31#include <VBox/intnetinline.h>
    3132
    3233
     
    4647 * @param   pcb             Where to return the size of the data on success.
    4748 */
    48 void *VBoxNetUDPMatch(PCINTNETBUF pBuf, unsigned uDstPort, PCRTMAC pDstMac, uint32_t fFlags, PVBOXNETUDPHDRS pHdrs, size_t *pcb)
     49void *VBoxNetUDPMatch(PINTNETBUF pBuf, unsigned uDstPort, PCRTMAC pDstMac, uint32_t fFlags, PVBOXNETUDPHDRS pHdrs, size_t *pcb)
    4950{
    5051    /*
     
    6263     * Valid IntNet Ethernet frame?
    6364     */
    64     PCINTNETHDR pHdr = (PINTNETHDR)((uintptr_t)pBuf + pBuf->Recv.offRead);
    65     if (pHdr->u16Type != INTNETHDR_TYPE_FRAME)
    66         return NULL;
    67 
    68     size_t      cbFrame = pHdr->cbFrame;
    69     const void *pvFrame = INTNETHdrGetFramePtr(pHdr, pBuf);
     65    PCINTNETHDR pHdr = INTNETRingGetNextFrameToRead(&pBuf->Recv);
     66    if (!pHdr || pHdr->u16Type != INTNETHDR_TYPE_FRAME)
     67        return NULL;
     68
     69    size_t          cbFrame = pHdr->cbFrame;
     70    const void     *pvFrame = INTNETHdrGetFramePtr(pHdr, pBuf);
    7071    PCRTNETETHERHDR pEthHdr = (PCRTNETETHERHDR)pvFrame;
    7172    if (pHdrs)
Note: See TracChangeset for help on using the changeset viewer.

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