NDIS接收网络数据

辛苦翻译,可以转载,注明来源即可!如有错误之处望留言指出,谢谢了!



Receiving Network Data
接收网络数据


The following figure illustrates a basic receive operation, which involves a miniport driver, NDIS, and a protocol driver.

下图说明了一个基本的接收操作,这涉及到小端口驱动,NDIS,和协议驱动

Miniport drivers call the NdisMIndicateReceiveNetBufferLists function to indicated NET_BUFFER structures to higher level drivers. Every NET_BUFFER structure should usually be attached to a separate NET_BUFFER_LIST structure. This allows protocol drivers to create a subset of the original list of NET_BUFFER_LIST structures and forward them to different clients. Some drivers, for example native IEEE 802.11 miniport drivers, might attach more than one NET_BUFFER structure to a NET_BUFFER_LIST structure.

小端口驱动调用NdisMIndicateReceiveNetBufferLists函数以指示上层驱动来接收NET_BUFFER。每个NET_BUFFER通常附加到一个单独的NET_BUFFER_LIST中。这允许协议驱动来创建一个原始NET_BUFFER_LIST列表的子集并且转发它们到不同的客户端。一些驱动,比如native IEEE 802.11小端口驱动,可能附加多个NET_BUFFER到NET_BUFFER_LIST中。

After linking all the NET_BUFFER_LIST structures, a miniport driver passes a pointer to the first NET_BUFFER_LIST structure in the list to the NdisMIndicateReceiveNetBufferLists function. NDIS examines the NET_BUFFER_LIST structures and it calls the ProtocolReceiveNetBufferLists function of each protocol driver that is associated with the NET_BUFFER_LIST structures. NDIS passes a subset of the list that includes only the NET_BUFFER_LIST structures that are associated with the correct binding to each protocol driver. NDIS matches the NetBufferListFrameType value that is specified in the NET_BUFFER_LIST structure to the frame type that each protocol driver registers.

在链接所有NET_BUFFER_LIST之后,小端口驱动传送链表中的第一个NET_BUFFER_LIST的指针给NdisMIndicateReceiveNetBufferLists函数。NDIS检查NET_BUFFER_LIST并调用和这个NET_BUFFER_LIST相关的协议驱动的ProtocolReceiveNetBufferLists回调函数。NDIS仅传送与适当的绑定相关的NET_BUFFER_LIST给每个协议驱动(译注:NDIS传送给每个协议驱动的NET_BUFFER_LIST都是和这个协议驱动的绑定相关的)。NDIS会将NET_BUFFER_LIST中指定的NetBufferListFrameType值和协议驱动注册的Frame Type进行匹配。

If the NDIS_RECEIVE_FLAGS_RESOURCES flag in the ReceiveFlags parameter that is passed to a protocol driver's ProtocolReceiveNetBufferLists function is set, NDIS regains the ownership of the NET_BUFFER_LISTstructures immediately after the ProtocolReceiveNetBufferLists call returns.

如果传送给协议驱动的ProtocolReceiveNetBufferLists回调函数的ReceiveFlags参数置位了NDIS_RECEIVE_FLAGS_RESOURCES标志,那么NDIS将在ProtocolReceiveNetBufferLists函数返回后马上重新获得NET_BUFFER_LIST的控制权(译注:同步模式)。

Note If the NDIS_RECEIVE_FLAGS_RESOURCES flag is set, the protocol driver must retain the original set of NET_BUFFER_LIST structures in the linked list. For example, when this flag is set the driver might process the structures and indicate them up the stack one at a time but before the function returns it must restore the original linked list.

注意:如果NDIS_RECEIVE_FLAGS_RESOURCES标志置位了,协议驱动必须保持链表中的NET_BUFFER_LIST的原始状态。例如,当置位了此标志时,驱动可能处理这个结构体并且指示上层接收它们(译注:这句翻译的可能不太贴切),但是在函数返回之前必须恢复原始链表。

If the NDIS_RECEIVE_FLAGS_RESOURCES flag in the ReceiveFlags parameter that is passed to a protocol driver's ProtocolReceiveNetBufferLists function is not set, the protocol driver can retain ownership of the NET_BUFFER_LIST structures. In this case, the protocol driver must return the NET_BUFFER_LIST structures by calling the NdisReturnNetBufferLists function.

如果传送给协议驱动的ProtocolReceiveNetBufferLists回调函数的ReceiveFlags参数未置位NDIS_RECEIVE_FLAGS_RESOURCES标志,协议驱动可以保留对NET_BUFFER_LIST的控制权。这种情况下,协议驱动必须通过调用NdisReturnNetBufferLists函数来返还NET_BUFFER_LIST。

If a miniport driver is running low on receive resources, it can set the NDIS_RECEIVE_FLAGS_RESOURCES flag in the ReceiveFlags parameter in the call to NdisMIndicateReceiveNetBufferLists. In that case, the driver can reclaim the ownership of all the indicated NET_BUFFER_LIST structures and embedded NET_BUFFER structures as soon as NdisMIndicateReceiveNetBufferLists returns. Indicating NET_BUFFER structures with the NDIS_RECEIVE_FLAGS_RESOURCES flag set forces the protocol drivers to copy the data and therefore should be avoided. A miniport driver should detect when it is about to run out of receive resources and take any steps that are necessary to avoid this situation.

如果小端口驱动接收资源不足,它可以在调用NdisMIndicateReceiveNetBufferLists函数时置位ReceiveFlags参数的NDIS_RECEIVE_FLAGS_RESOURCES标志。这种情况下,一旦NdisMIndicateReceiveNetBufferLists返回,驱动就会马上获得NET_BUFFER_LIST和嵌入其中的NET_BUFFER的控制权。带NDIS_RECEIVE_FLAGS_RESOURCES标志指示接收NET_BUFFER时强制协议驱动复制这些数据,因此可以避免上述问题(译注:应该是指函数返回后小端口会立即获取到NBL的控制权的问题,可以通过复制一份数据来解决)。 小端口驱动可以检测是否接收资源不足,并且用一些必要的步骤以避开这种情况。

NDIS calls a miniport driver's MiniportReturnNetBufferLists function after the protocol driver calls NdisReturnNetBufferLists.

在协议驱动调用NdisReturnNetBufferLists函数之后,NDIS会调用小端口的MiniportReturnNetBufferLists回调函数。

Note If a miniport driver indicates a NET_BUFFER_LIST structure with the NDIS_RECEIVE_FLAGS_RESOURCES flag set, that does not mean that NDIS will indicate the NET_BUFFER_LIST structure to the protocol driver with the same status. For example, NDIS could copy a NET_BUFFER_LIST structure with the NDIS_RECEIVE_FLAGS_RESOURCES flag set and indicate the copy to the protocol driver with the flag cleared.

注意:如果小端口驱动指示接收一个NET_BUFFER_LIST时带有NDIS_RECEIVE_FLAGS_RESOURCES标志,并非意味着NDIS将会在指示协议驱动接收NET_BUFFER_LIST时会带有同样的状态(译注:指NDIS_RECEIVE_FLAGS_RESOURCES标志)。例如:NDIS可以复制一份标记为NDIS_RECEIVE_FLAGS_RESOURCES的NET_BUFFER_LIST,并指示协议驱动接收这个新复制的清除了这个标志的NET_BUFFER_LIST。(NDIS好淘气。。。- -|||)

NDIS can return NET_BUFFER_LIST structures to the miniport driver in any arbitrary order and in any combination. That is, the linked list of NET_BUFFER_LIST structures returned back to a miniport driver by a call to its MiniportReturnNetBufferLists function, can have NET_BUFFER_LIST structures from different previous calls to NdisMIndicateReceiveNetBufferLists.

NDIS能以任意顺序和组合返还NET_BUFFER_LIST给小端口驱动。也就是说,通过调用MiniportReturnNetBufferLists函数返还给小端口驱动的NET_BUFFER_LIST链表,可能包含之前不同的NdisMIndicateReceiveNetBufferLists调用中传送出去的NET_BUFFER_LIST(译注:就是说多次调用NdisMIndicateReceiveNetBufferLists传送的NBL在返还时可能会链接成同一NBL链后返还给小端口)。

Miniport drivers should set the SourceHandle member in the NET_BUFFER_LIST structures to the MiniportAdapterHandle that NDIS provided to the miniport driver in the MiniportInitializeEx function. Filter drivers must set the SourceHandle member of each NET_BUFFER_LIST structure that the filter driver originated to the filter's NdisFilterHandle that NDIS provided to the filter driver in the FilterAttachfunction. Filter drivers must not modify the SourceHandle member in any NET_BUFFER_LIST structures that were not originated by the filter driver.

小端口驱动应该设置NET_BUFFER_LIST的SourceHandle成员为MiniportAdapterHandle(调用MiniPortInitializeEx函数得到的)。过滤驱动必须设置它自己发起的每个NET_BUFFER_LIST的SourceHandle成员为过滤模块的NdisFilterHandle,它是在FilterAttach回调函数中给出的

Intermediate drivers also set the SourceHandle member in the NET_BUFFER_LIST structure to the MiniportAdapterHandle value that NDIS provided to the intermediate driver in the MiniportInitializeEx function. If an intermediate driver forwards a receive indication, the driver must save the SourceHandle value that the underlying driver provided before it writes to the SourceHandle member. When NDIS returns a forwarded NET_BUFFER_LIST structure to the intermediate driver, the intermediate driver must restore the SourceHandle that it saved.

中间层驱动同样应该设置NET_BUFFER_LIST的SourceHandle成员为MiniportAdapterHandle(在中间层驱动调用MiniportInitializeEx函数时得到的)的值。如果中间层驱动转发一个接收指示,那么它必须在写入SourceHandle之前保存下层驱动提供的既有SourceHandle值。当NDIS返还这个转发的NET_BUFFER_LIST给中间层驱动时,中间层驱动必须恢复SourceHandle为之前保存的值。


英文原文地址:https://docs.microsoft.com/zh-cn/windows-hardware/drivers/network/receiving-network-data

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值