网络驱动Fragment 之NdisAllocateFragmentNetBufferList

NdisAllocateFragmentNetBufferList 在msdn上是这样说的“创建一个新分片NET_BUFFER_LIST结构,基于现存
NET_BUFFER_LIST结构”。

PNET_BUFFER_LIST NdisAllocateFragmentNetBufferList(
_In_ PNET_BUFFER_LIST OriginalNetBufferList,
_In_opt_ NDIS_HANDLE NetBufferListPoolHandle,
_In_opt_ NDIS_HANDLE NetBufferPoolHandle,
_In_ ULONG StartOffset,
_In_ ULONG MaximumLength,
_In_ ULONG DataOffsetDelta,
_In_ ULONG DataBackFill,
_In_ ULONG AllocateFragmentFlags
);
StartOffset [in]
An additional byte offset from the start of the data in each NET_BUFFER structure. This offset is in addition to the value of the DataOffset member specified in each NET_BUFFER structure.

从每个NET_BUFFER结构数据开始部分的附加字节偏移。此偏移是除了在每个NET_BUFFER结构的DataOffset成员值的值。

MaximumLength [in]
The maximum length, in bytes, for each fragment in the new NET_BUFFER_LIST structure. Each fragment is described by a NET_BUFFER structure.
最大长度,以字节为单位。对新的NET_BUFFER_LIST结构的每个分片,每个分片用NET_BUFFER结构描述。

DataOffsetDelta [in]
The additional amount of used data space that NDIS should make available in the new NET_BUFFER structures.
已用数据空间的额外数量,NDIS使新NET_BUFFER结构可用。

DataBackFill [in]
The amount of data space in addition to the value of the DataOffsetDelta parameter to allocate if allocation is necessary. If NDIS must allocate memory to supply the data space requested in DataOffsetDelta, it should also allocate the additional space that DataBackFill specifies.
分配的数据空间中除了DataOffsetDelta参数的值,需要分配的值。如果NDIS必须分配内存,以提供在数据空间请求DataOffsetDelta,应该分配附加空间DataBackFill指定的。

返回新NET_BUFFER_LIST值。
参数和使用很诡异,需要仔细看看。

也应该分配该DataBackFill指定额外的空间。

NET_BUFFER_LIST结构如下:
typedef struct _NET_BUFFER_LIST {
NET_BUFFER_LIST_HEADER NetBufferListHeader;
PNET_BUFFER_LIST_CONTEXT Context;
PNET_BUFFER_LIST ParentNetBufferList;
NDIS_HANDLE NdisPoolHandle;
DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT)PVOID NdisReserved[2];
DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT)PVOID ProtocolReserved[4];
DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT)PVOID MiniportReserved[2];
PVOID Scratch;
NDIS_HANDLE SourceHandle;
ULONG NblFlags;
LONG ChildRefCount;
ULONG Flags;
NDIS_STATUS Status;
PVOID NetBufferListInfo[MaxNetBufferListInfo];
} NET_BUFFER_LIST, *PNET_BUFFER_LIST;

NBL 回填空间Backfill Space
The data buffer described by a NB can be split into unused data space and used data space. The unused data space (also known as backfill space), if any, is located before the start of the used data space (i.e. space that contains the valid data) described by the NB. As the NB is forwarded from one driver to another in the networking stack the position of the split can be changed.
NB描述databuffer可分为未用和使用数据空间。未用数据空间(亦为backfill).

The NB structure fields DataOffset, CurrentMdl and CurrentMdlOffset determine the location of the split. DataOffset is the number of bytes from the start of the buffer described by the NB where the used data space begins.

CurrentMDL is a convenience provided by NDIS whereby a driver can get to the first MDL in the NB that describes the valid data. CurrentMdlOffset is the offset of the valid data from the start of the buffer described by CurrentMdl. NdisAdjustNetBufferCurrentMdl() sets the CurrentMdlOffset and CurrentMdl fields of the NB based on the current value of DataOffset.

发表评论