The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.
Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/
I have already asked this question on Microsoft forums (https://docs.microsoft.com/en-us/answers/questions/541601/indicating-packets-from-wsk-to-netadaptercx.html, but I feel I could get a (faster) answer here.
I am working on the virtual network adapter driver which uses NetAdapterCx, WSK and CNG.
Here is what driver does on Tx path:
iterate over packets in "post" subsection of NET_RING
for each packet, get the first fragment and fragment's MDL. If MDL is NULL (packet was bounced by NetAdapter), allocate MDL from fragment's VA.
encrypt MDL chain with CNG using chaining mode (account for plaintext length must be multiplier of block size)
send MDL chain with WskSendTo/WskSend, pass NET_PACKET as completion routine context
move sent fragments and packets to "drain" subsection by adjusting NextIndex
in WSK completion routine, set NET_PACKET::Scratch to 1 to indicate that packet has been sent
iterate over packets in "drain" subsection and drain them to OS by adjusting BeginIndex if Scratch is set to 1
The code could be found here: https://github.com/lstipakov/ovpn-dco-win/blob/zerocopy/txqueue.cpp#L139
My question is - what would be the proper way to implement the same "zerocopy" approach on Rx path? At the moment it works like this:
packet is received by WskReceiveFromEvent callback
packet is decrypted into ciphertext buffer, fetched from pre-allocated "producer" pool (I use DMF_BufferQueue)
ciphertext buffer is enqueued into "consumer" queue
call NetRxQueueNotifyMoreReceivedPacketsAvailable() to trigger Rx queue's Advance callback
in Rx Advance callback, iterate over fragments, dequeue buffer from "consumer" queue and copy buffer content to fragment's VA
buffer is "reused" by placing into "producer" pool
I can do decryption in-place and make WSK retain data by returning STATUS_PENDING from WskReceiveFromEvent callback, but how do I "indicate" data provided by WSK to NetAdapter without memcpying? Can I somehow tell NET_FRAGMENT "hey use this MDL which I got from WSK and decrypted in-place" ?
|Upcoming OSR Seminars|
|OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!|
|Internals & Software Drivers||15 November 2021||Live, Online|
|Writing WDF Drivers||TBD||Live, Online|
|Developing Minifilters||7 February 2022||Live, Online|
|Kernel Debugging||21 March 2022||Live, Online|