Read () from tun device without deleting data read from OS buffer

Short version . Is there a Linux API that allows reading from a file descriptor (similar to read ()) without actually deleting data from the OS buffer? Somehow split read () into equivalent to front () (read without deleting) and pop () (delete).

Script . I have a TUN device that I use to deliver IP datagrams through my own networking stack. The problem is, when the above application uses UDP, the TUN device may be flooded with OS data that my stack cannot manage fast enough.

Purpose . I would like to: read the datagram as soon as it arrives through the TUN device, without removing it from the kernel buffer, validate the datagram and decide if the rest of the proprietary protocol stack can handle it, and if so, pop () the data from kernel buffer, otherwise save the data there.

Why . The reason this does not affect pop () from the kernel buffer is that the above application might actually understand that the lower layers of network protocols are overloaded (since its own write () or send () functions on the network interface will not completed) and proceed accordingly. If the data is deleted, as with a normal read (), the application has no idea about the overload and continues to flood.

+3


source to share


1 answer


The source is available, so you can always write an option like this.

You can also use iptables

with the option -j TEE

to duplicate packets to the second interface and read from there. The originals will remain unread.



Not the best answer, I agree ...

0


source







All Articles