Help with TUN device impl.

6 views
Skip to first unread message

Vanegicloh J

<vanegicloh@gmail.com>
unread,
Jun 2, 2026, 7:08:48 AM (6 days ago) Jun 2
to seastar-dev
Hello. I'm working on TUN/TAP device. It's a network device in user space with a behavior of a file descriptor. I can open it, write packets to it and read packets from it. 
What is the best way to work with it in a seastar way from a seastar code? 
  1. Raw syscalls ::open, ::read, ::write. Seems bad because can block and not friendly with seastar reactor.
  2. seastar::open_file_dma, read_dma, write_dma. I tried it on TUN fd and got errors in log. Smth like "io_submit ENOTSUP - operation not supported". Seems that TUN is not designed for io_submit.  Packets were delivered to TUN though. Also, DMA way seems a bit over-complicated for a TUN device.
  3. seastar::pollable_fd. Looks good. It has simple co_await pfd.read_some(char* buffer, size_t size). But write looks weird. It has co_await write_some(std::span<iovec> iov) but no simple co_await write(char* buffer, size_t size). Why?
  4. Finally, seastar::file_desc. I can get access to it with file_desc& pollable_fd::get_file_desc(); But API is not intuitive at all. write()/read() are not futurized. No idea how to use it :)
If you had to choose, what would it be? Is there any other better options? What is the best way to implement TUN entity? 

Thank you!

Avi Kivity

<avi@scylladb.com>
unread,
Jun 2, 2026, 8:19:41 AM (6 days ago) Jun 2
to Vanegicloh J, seastar-dev
pollable_fd is an internal data structure and shouldn't be used. It's the right tool though, we just need to use it indirectly.

We need a way for an existing abstraction to "adopt" a file descriptor. I think the best existing abstraction is datagram_channel. It uses sendmsg/recvmsg and I believe TUN supports that. Best to verify that with a small C program.

Option 1:
datagram_channel network_stack::make_datagram_channel_from_file_descriptor(file_desc)

Option 2:
datagram_channel network_stack::make_datagram_channel_from_tun_device(path)


Option 1 is more generic.


 
Reply all
Reply to author
Forward
0 new messages