阅读:2639回复:4
各位高手,DDK ndisprot驱动丢包问题, 有偿解决问题。我用DDK 的例子,ndisprot 协议驱动。 在客户端不停发送大量数据的时候,服务端会出现丢包问题。 我用的是readfile/writefile非重叠IO。 请问是什么原因? 有知道的么? 郁闷了很久了。 。。。。。 |
|
沙发#
发布于:2011-07-02 00:33
发现一个奇怪的问题:
1、我打开远程连接, 管理远程测试机。 发现只要开着远程连接就会出现丢包现象。 2、打开网卡的混杂模式也不会出现丢包现象。 3、我的笔记本无线网卡不管怎么着都会出现丢包现象。 而且我的无线网卡不能用混杂模式打开。 到底怎么回事? |
|
板凳#
发布于:2011-07-01 23:16
又跟踪了一下, 是驱动层丢包。
应用层的代码很简单 , 就是使用writefile/readfile不停的发包和收包。 bool ethnet_sendpacket(/*in*/ HANDLE eth_handle,/*in*/ void * packet,/*in*/ ULONG sendlen) { if((NULL == eth_handle) || !packet || sendlen<=0) return false; ULONG writelen = 0; if(!WriteFile(eth_handle,packet,sendlen,&writelen,NULL)) return false; if(writelen!=sendlen) return false; return true; } bool ethnet_receivepacket(/*in*/ HANDLE eth_handle,/*out*/ void * packet,/*in*/ ULONG buflen,/*out*/ULONG * receive) { if((NULL == eth_handle) || !packet || buflen<=0) return false; ULONG recelen = 0; if(!ReadFile(eth_handle,packet,buflen,&recelen,NULL)) return false; if(receive) *receive = recelen; return true; } 驱动代码: NDIS_STATUS NdisProtReceive( IN NDIS_HANDLE ProtocolBindingContext, IN NDIS_HANDLE MacReceiveContext, __in_bcount(HeaderBufferSize) IN PVOID pHeaderBuffer, IN UINT HeaderBufferSize, __in_bcount(LookaheadBufferSize) IN PVOID pLookaheadBuffer, IN UINT LookaheadBufferSize, IN UINT PacketSize ) /*++ Routine Description: Our protocol receive handler called by NDIS, typically if we have a miniport below that doesn't indicate packets. We make a local packet/buffer copy of this data, queue it up, and kick off the read service routine. Arguments: ProtocolBindingContext - pointer to open context MacReceiveContext - for use in NdisTransferData pHeaderBuffer - pointer to data header HeaderBufferSize - size of the above pLookaheadBuffer - pointer to buffer containing lookahead data LookaheadBufferSize - size of the above PacketSize - size of the entire packet, minus header size. Return Value: NDIS_STATUS_NOT_ACCEPTED - if this packet is uninteresting NDIS_STATUS_SUCCESS - if we processed this successfully --*/ { PNDISPROT_OPEN_CONTEXT pOpenContext; NDIS_STATUS Status; PNDIS_PACKET pRcvPacket; PUCHAR pRcvData; UINT BytesTransferred; PNDIS_BUFFER pOriginalNdisBuffer, pPartialNdisBuffer; pOpenContext = (PNDISPROT_OPEN_CONTEXT)ProtocolBindingContext; NPROT_STRUCT_ASSERT(pOpenContext, oc); pRcvPacket = NULL; pRcvData = NULL; Status = NDIS_STATUS_SUCCESS; do { if (HeaderBufferSize != sizeof(NDISPROT_ETH_HEADER)) { Status = NDIS_STATUS_NOT_ACCEPTED; break; } // // Protocol Type filter. // //DbgPrint("Receive ProtoType:%04x",((ETH_HEADER*)pHeaderBuffer)->EthType); if((pOpenContext->ProtoType!=0) && (pOpenContext->ProtoType != (ULONG)(((ETH_HEADER*)pHeaderBuffer)->EthType))) { Status = NDIS_STATUS_NOT_ACCEPTED; break; } // // Allocate resources for queueing this up. // if ((PacketSize + HeaderBufferSize) < PacketSize) { Status = NDIS_STATUS_NOT_ACCEPTED; break; } g_ReceivePacketsCount++; DbgPrint("Receive Packet:%08x\n",g_ReceivePacketsCount); pRcvPacket = ndisprotAllocateReceivePacket( pOpenContext, PacketSize + HeaderBufferSize, &pRcvData ); if ((pRcvPacket == NULL) || (pRcvData == NULL)) { DbgPrint("NdisProtReceive error 3"); Status = NDIS_STATUS_NOT_ACCEPTED; break; } NdisMoveMappedMemory(pRcvData, pHeaderBuffer, HeaderBufferSize); // // Check if the entire packet is within the lookahead. // if (PacketSize == LookaheadBufferSize) { NdisCopyLookaheadData(pRcvData+HeaderBufferSize, pLookaheadBuffer, LookaheadBufferSize, pOpenContext->MacOptions); // // Queue this up for receive processing, and // try to complete some read IRPs. // ndisprotQueueReceivePacket(pOpenContext, pRcvPacket); } else { // // Allocate an NDIS buffer to map the receive area // at an offset "HeaderBufferSize" from the current // start. This is so that NdisTransferData can copy // in at the right point in the destination buffer. // NdisAllocateBuffer( &Status, &pPartialNdisBuffer, pOpenContext->RecvBufferPool, pRcvData + HeaderBufferSize, PacketSize); if (Status == NDIS_STATUS_SUCCESS) { // // Unlink and save away the original NDIS Buffer // that maps the full receive buffer. // NdisUnchainBufferAtFront(pRcvPacket, &pOriginalNdisBuffer); NPROT_RCV_PKT_TO_ORIGINAL_BUFFER(pRcvPacket) = pOriginalNdisBuffer; // // Link in the partial buffer for NdisTransferData to // operate on. // NdisChainBufferAtBack(pRcvPacket, pPartialNdisBuffer); DEBUGP(DL_LOUD, ("Receive: setting up for TransferData:" " Pkt %p, OriginalBuf %p, PartialBuf %p\n", pRcvPacket, pOriginalNdisBuffer, pPartialNdisBuffer)); NdisTransferData( &Status, pOpenContext->BindingHandle, MacReceiveContext, 0, // ByteOffset PacketSize, pRcvPacket, &BytesTransferred); } else { // // Failure handled below in TransferDataComplete. // BytesTransferred = 0; } if (Status != NDIS_STATUS_PENDING) { NdisProtTransferDataComplete( (NDIS_HANDLE)pOpenContext, pRcvPacket, Status, BytesTransferred); } } } while (FALSE); DEBUGP(DL_LOUD, ("Receive: Open %p, Pkt %p, Size %d\n", pOpenContext, pRcvPacket, PacketSize)); return Status; } 这段驱动的代码是DDK 7600.16385.1里的5.x的例子。 不知道什么原因? 难道是我发送太快了么? 我用Wireshark抓包, 发现也存在丢包的问题。 请楼上的大侠给看看。 到底怎么回事情? 可以有偿解决问题。 帮帮忙吧!!!! |
|
地板#
发布于:2011-06-28 09:43
描述不清, 别人没有办法说阿
把问题描述清楚些: 是驱动层就发现丢包了,还是应用层丢包了?把问题定位出来啊 |
|
|
地下室#
发布于:2011-06-26 11:39
没有人知道么? 自己顶一下!
|
|