Passthru中为什么要不直接把Packet发送或接收,而另外再建一个MyPacket用来发

NDIS4.0及5.0中的中间层驱动必须分配新的包描述符,即使不对包做任何修改(如同Passthru那样)。NDIS5.1支持Packet stack方式

看DDK的说明:
NDIS 4.0 and 5.0 intermediate drivers must allocate a new NDIS_PACKET to encapsulate data that they pass on. These intermediate drivers must also copy any out-of-band (OOB) data to the new packet. Even if the intermediate driver does nothing other than simply pass on incoming packets — for example, if it simply counts the packets — it must allocate a fresh packet descriptor and manage some or all of a new packet structure.

NDIS 5.1 intermediate drivers that support packet stacking avoid this extra data handling in most common cases. Each NDIS_PACKET allocated includes "stacks", where each stack is defined as:

typedef struct _NDIS_PACKET_STACK
{
ULONG_PTR IMReserved[2];
ULONG_PTR NdisReserved[4];
} NDIS_PACKET_STACK, *PNDIS_PACKET_STACK;

NDIS 5.1 intermediate drivers call the NdisIMGetCurrentPacketStack function to access the IMReserved member in the NDIS_PACKET_STACK structure. This member can be used by an NDIS 5.1 intermediate driver to store its context information, if any, for the packet. NDIS 4.0 and 5.0 intermediate drivers use the ProtocolReserved and MiniportReserved members, for sent and received packets, in the NDIS_PACKET structure. If a call to NdisIMGetCurrentPacketStack indicates *StacksRemaining is FALSE, the NDIS 5.1 intermediate driver must revert to the NDIS 5.0 packet handling model.

Every NDIS 4.0 and 5.0 intermediate driver must allocate new packet descriptors to replace those of the overlying driver. If an intermediate driver converts the packet from one format to another, it also can allocate buffer descriptors to map intermediate-allocated buffers into which the converted data is copied. If there is OOB data associated with the packet descriptor being copied, this data can be copied to the new OOB block associated with the intermediate-allocated packet descriptor, using the macro NDIS_OOB_DATA_FROM_PACKET, to obtain a pointer to the OOB data area and, then, calling NdisMoveMemory to move the contents into the OOB area associated with the new packet descriptor. Alternatively, such an intermediate driver can use the NDIS_GET_PACKET_XXX and NDIS_SET_PACKET_XXX macros to read specific items from the OOB data associated with the old packet descriptor and to write the OOB data for the new packet descriptor.

发布者