阅读:1682回复:3
急!!在ReturnPacket的问题
我在做的是一个包转发的驱动,就是类似于XP下的Mac桥。用passthru改的。具体步骤,就是在PtReceivePacket后,调用NdisSend把包从另外一个网卡发出去。我现在已经实现的很好了,可是在XP系统下却有问题。我查了一下,发现如果使用NDIS5.1的特性(包可以重用),然后使用完后ReturnPacket。可是却在瞬时包数很多的情况下就会崩溃。
程序框架是这样的:PtReceivePacket时,调用SendBridgePackets发送数据包到另外一个网卡。然后在网卡发送完后调用PtSendComplete释放资源(ReturnPacket也是在这里调用的)。 部分程序如下: VOID SendBridgePackets( PNDIS_STATUS Status, PADAPT pAdapt, PNDIS_PACKET Packet, DWORD dwFlags ) { if( NdisGetPacketFlags( Packet ) & NDIS_FLAGS_IS_LOOPBACK_PACKET )return; if( pAdapt->pBridgeAdapt ) { NdisSetPacketFlags( Packet, dwFlags | BRIDGE_SEND_PACKET_FLAGS | NDIS_FLAGS_IPF_RECEIVED_PACKET ); NdisSend( Status, pAdapt->pBridgeAdapt->BindingHandle, Packet ); if( *Status != NDIS_STATUS_PENDING ) { #ifdef NDIS51 if( NdisGetPoolFromPacket( Packet ) == pAdapt->RecvPacketPoolHandle ) #endif // NDIS51 { NdisDprFreePacket( Packet ); *Status = NDIS_STATUS_RESOURCES; } } } PtReceivePacket( ... ) { #ifdef NDIS51 // // Check if we can reuse the same packet for indicating up. // See also: PtReceive(). // NdisIMGetCurrentPacketStack( Packet, &Remaining ); if( Remaining ) { // // We can reuse \"Packet\". Indicate it up and be done with it. // Status = NDIS_GET_PACKET_STATUS( Packet ); SendBridgePackets( &Status, pAdapt, Packet, 0 ); return Status != NDIS_STATUS_RESOURCES ? 1 : 0; #endif // NDIS51 ... } VOID IPF_PtSendComplete ( IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_PACKET Packet, IN NDIS_STATUS Status ) { PADAPT pAdapt = ( PADAPT )ProtocolBindingContext; PNDIS_PACKET Pkt; if( NdisGetPacketFlags( Packet ) & NDIS_FLAGS_IPF_RECEIVED_PACKET ) { #ifdef NDIS51 if( NdisGetPoolFromPacket( Packet ) != pAdapt->RecvPacketPoolHandle && NdisGetPoolFromPacket( Packet ) != pAdapt->pBridgeAdapt->RecvPacketPoolHandle ) { NdisReturnPackets( &Packet, 1 ); } else #endif // NDIS51 { if( NdisGetPacketFlags( Packet ) & NDIS_FLAGS_IPF_LOCAL_BUFFER ) { UINT nLength; PVOID pData; PNDIS_BUFFER pBuffer; NdisUnchainBufferAtFront( Packet, &pBuffer ); NdisDprFreePacket( Packet ); NdisQueryBuffer( pBuffer, &pData, &nLength ); NdisFreeBuffer( pBuffer ); NdisFreeMemory( pData, nLength, 0 ); } else { // Pkt = ( ( PRECV_RSVD )Packet->MiniportReserved )->OriginalPkt; NdisDprFreePacket( Packet ); // if( Pkt )NdisReturnPackets( &Pkt, 1 ); } } } else { #ifdef NDIS51 if( NdisGetPoolFromPacket( Packet ) != pAdapt->SendPacketPoolHandle ) { // // We had passed down a packet belonging to the protocol above us. // NdisMSendComplete( pAdapt->MiniportHandle, Packet, Status ); } else #endif // NDIS51 { Pkt = ( ( PSEND_RSVD )Packet->ProtocolReserved )->OriginalPkt; #ifndef WIN9X NdisIMCopySendCompletePerPacketInfo( Pkt, Packet ); #endif NdisDprFreePacket( Packet ); NdisMSendComplete( pAdapt->MiniportHandle, Pkt, Status ); } } } |
|
沙发#
发布于:2003-05-06 21:41
没人回答啊?老大们呢?帮帮忙吧,焦头烂额了
|
|
板凳#
发布于:2004-01-04 12:21
你把原代码发到我信箱里,我帮你看看,我已经做了多个转发包的项目了,x2651@163.com
|
|
地板#
发布于:2004-01-08 09:48
建议了解Mobile ad-hoc network(MANET),不用两个网卡这么麻烦,呵呵
|
|