Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should IntermediateBuffer be !Send? #20

Closed
kgv opened this issue Jan 10, 2024 · 2 comments
Closed

Should IntermediateBuffer be !Send? #20

kgv opened this issue Jan 10, 2024 · 2 comments

Comments

@kgv
Copy link
Contributor

kgv commented Jan 10, 2024

If try to filter in a separate asynchronous thread (tokio::spawn), it is required IntermediateBuffer be Send. But it's not.
Is there any way to overcome this?

let mut adapter = AsyncNdisapiAdapter::new(driver, adapter.get_handle())?;
tokio::spawn(async move {
    // Put network interface into the tunnel mode
    adapter
        .set_adapter_mode(FilterFlags::MSTCP_FLAG_SENT_RECEIVE_TUNNEL)
        .unwrap();
    // Allocate IntermediateBuffer
    let mut buffer = vec![IntermediateBuffer::default(); LEN];
    while !terminate {
        let len = match adapter.read_packets::<LEN>(&mut buffer).await {
            Ok(len) if len != 0 => len,
            _ => continue,
        };
        // Partition the iterator into two collections based on the device flag.
        let packets: (Vec<_>, Vec<_>) = buffer[0..len].iter_mut().partition(|buffer| {
            buffer.get_device_flags() == DirectionFlags::PACKET_FLAG_ON_SEND
        });
        // Re-inject packets back into the network stack
        if let Err(error) = adapter.send_packets_to_adapter::<LEN>(packets.0.into_iter()) {
            println!("Error sending packet to adapter. Error code = {error}");
        }
        if let Err(error) = adapter.send_packets_to_mstcp::<LEN>(packets.1.into_iter()) {
            println!("Error sending packet to mstcp. Error code = {error}");
        }
    }
    // Put the network interface into default mode
    adapter.set_adapter_mode(FilterFlags::default()).unwrap();
});

Error:

has type `Vec<IntermediateBuffer>` which is not `Send`
@wiresock
Copy link
Owner

I apologize for the oversight regarding the raw pointers in ListEntry, which led to the IntermediateBuffer not implementing the Send trait. This issue has been addressed and resolved in the latest commit.

@kgv
Copy link
Contributor Author

kgv commented Jan 11, 2024

Fixed: b5c624b

@kgv kgv closed this as completed Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants