Changeset 26574 in vbox for trunk/src/VBox/NetworkServices/NetLib
- Timestamp:
- Feb 16, 2010 12:44:10 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 57756
- Location:
- trunk/src/VBox/NetworkServices/NetLib
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NetLib/VBoxNetARP.cpp
r26498 r26574 26 26 #include "VBoxNetLib.h" 27 27 #include <iprt/string.h> 28 #include <VBox/intnetinline.h> 28 29 #include <VBox/log.h> 29 30 … … 45 46 * Valid IntNet Ethernet frame? 46 47 */ 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) 49 51 return false; 50 52 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); 53 55 PCRTNETETHERHDR pEthHdr = (PCRTNETETHERHDR)pvFrame; 54 56 -
trunk/src/VBox/NetworkServices/NetLib/VBoxNetIntIf.cpp
r20864 r26574 26 26 #include "VBoxNetLib.h" 27 27 #include <VBox/intnet.h> 28 #include <VBox/intnetinline.h> 28 29 #include <VBox/sup.h> 29 30 #include <VBox/vmm.h> … … 87 88 * Validate input. 88 89 */ 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); 95 92 AssertPtr(paSegs); 96 93 Assert(cSegs > 0); 97 94 98 /* Calc frame size. */ 95 /* 96 * Calc frame size. 97 */ 99 98 uint32_t cbFrame = 0; 100 99 for (size_t iSeg = 0; iSeg < cSegs; iSeg++) 101 100 cbFrame += paSegs[iSeg].cb; 102 103 101 Assert(cbFrame >= sizeof(RTMAC) * 2); 104 102 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)) 108 110 { 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); 166 113 return VINF_SUCCESS; 167 114 } 168 115 169 /* (it didn't fit) */ 170 /** @todo stats */ 171 return VERR_BUFFER_OVERFLOW; 116 return rc; 172 117 } 173 118 -
trunk/src/VBox/NetworkServices/NetLib/VBoxNetLib.h
r20374 r26574 51 51 /** @} */ 52 52 53 void * VBoxNetUDPMatch(P CINTNETBUF pBuf, unsigned uDstPort, PCRTMAC pDstMac, uint32_t fFlags, PVBOXNETUDPHDRS pHdrs, size_t *pcb);53 void * VBoxNetUDPMatch(PINTNETBUF pBuf, unsigned uDstPort, PCRTMAC pDstMac, uint32_t fFlags, PVBOXNETUDPHDRS pHdrs, size_t *pcb); 54 54 int VBoxNetUDPUnicast(PSUPDRVSESSION pSession, INTNETIFHANDLE hIf, PINTNETBUF pBuf, 55 55 RTNETADDRIPV4 SrcIPv4Addr, PCRTMAC SrcMacAddr, unsigned uSrcPort, -
trunk/src/VBox/NetworkServices/NetLib/VBoxNetUDP.cpp
r18463 r26574 29 29 #include <iprt/rand.h> 30 30 #include <VBox/log.h> 31 #include <VBox/intnetinline.h> 31 32 32 33 … … 46 47 * @param pcb Where to return the size of the data on success. 47 48 */ 48 void *VBoxNetUDPMatch(P CINTNETBUF pBuf, unsigned uDstPort, PCRTMAC pDstMac, uint32_t fFlags, PVBOXNETUDPHDRS pHdrs, size_t *pcb)49 void *VBoxNetUDPMatch(PINTNETBUF pBuf, unsigned uDstPort, PCRTMAC pDstMac, uint32_t fFlags, PVBOXNETUDPHDRS pHdrs, size_t *pcb) 49 50 { 50 51 /* … … 62 63 * Valid IntNet Ethernet frame? 63 64 */ 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); 70 71 PCRTNETETHERHDR pEthHdr = (PCRTNETETHERHDR)pvFrame; 71 72 if (pHdrs)
Note:
See TracChangeset
for help on using the changeset viewer.