It's been some time since I've looked at the OVPN source code but I found some cool TUN interface flags recently!
Hey all,
I've been busy in life and I haven't had much time to keep up with the development of the OVPN source code and all the commits and everything (it's been a little while since I last posted). I ended up creating a custom framework for my own personal use that is based on the original modifications I did for OpenVPN (multi-threaded, bulk-reads, TCP-only, standard-MTU). I was able to get over a gigabit speeds on my wifi client with this network-wide VPN solution I have now.
I found these 2 new-to-me parameters for TUN interfaces which are really cool and I didn't know existed (I also didn't see them last time I checked the source code here) - IFF_MULTI_QUEUE | IFF_VNET_HDR. Obviously the multi-queue flag wouldn't work by default here (since it's not multi-threaded) however this other one is pretty nice if you adjust your buffer sizes to be much bigger :)
For example, I was able to read thousands of bytes of data in one call from TUN if you set the below parameters in C:
ifrq.ifr_flags = (IFF_TUN | IFF_NO_PI | IFF_MULTI_QUEUE | IFF_VNET_HDR); TUNF[z] = open("/dev/net/tun", O_RDWR);
...
erro = ioctl(TUNF[z], TUNSETIFF, &ifrq);
if (erro < 0) { printf("%s ERRO TUNSETIFF [%d]\n", date(), z); }
...
int leng = sizeof(struct virtio_net_hdr);
erro = ioctl(TUNF[z], TUNSETVNETHDRSZ, &leng);
...
if (erro < 0) { printf("%s ERRO TUNSETVNETHDRSZ [%d]\n", date(), z); } unsigned int offl = (TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6);
...
erro = ioctl(TUNF[z], TUNSETOFFLOAD, offl);
if (erro < 0) { printf("%s ERRO TUNSETOFFLOAD [%d]\n", date(), z); }
I don't know the full history here yet and am still learning but was this option ever considered to be implemented for OpenVPN?
Thanks again for your support and help and time on this open source project! I still like it way better than WG haha :)
https://fossjon.com/2026/09/03/finally-got-multi-queue-batch-io-linux-kernel-tun-interface-in-c/
Jon C (root)
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Am 03.09.26 um 23:37 schrieb Jon Chiappetta via Openvpn-devel:
Quoted 23 lines
Hey all,
I've been busy in life and I haven't had much time to keep up with the development of the OVPN source code and all the commits and everything (it's been a little while since I last posted). I ended up creating a custom framework for my own personal use that is based on the original modifications I did for OpenVPN (multi-threaded, bulk-reads, TCP-only, standard-MTU). I was able to get over a gigabit speeds on my wifi client with this network-wide VPN solution I have now.
I found these 2 new-to-me parameters for TUN interfaces which are really cool and I didn't know existed (I also didn't see them last time I checked the source code here) -
IFF_MULTI_QUEUE|IFF_VNET_HDR. Obviously the multi-queue flag wouldn't work by default here (since it's not multi-threaded) however this other one is pretty nice if you adjust your buffer sizes to be much bigger :)For example, I was able to read thousands of bytes of data in one call from TUN if you set the below parameters in C:
ifrq.ifr_flags = (
IFF_TUN|IFF_NO_PI|IFF_MULTI_QUEUE|IFF_VNET_HDR); TUNF[z] =open("/dev/net/tun", O_RDWR);
...
erro =ioctl(TUNF[z], TUNSETIFF, &ifrq);
if (erro < 0) {printf("%s ERRO TUNSETIFF [%d]\n", date(), z); }
...
int leng =sizeof(struct virtio_net_hdr);
erro =ioctl(TUNF[z], TUNSETVNETHDRSZ, &leng);
...
if (erro < 0) {printf("%s ERRO TUNSETVNETHDRSZ [%d]\n", date(), z); } unsigned int offl = (TUN_F_CSUM|TUN_F_TSO4|TUN_F_TSO6);
...
erro =ioctl(TUNF[z], TUNSETOFFLOAD, offl);
if (erro < 0) {printf("%s ERRO TUNSETOFFLOAD [%d]\n", date(), z); }
Quoted 1 line
I don't know the full history here yet and am still learning but was this option ever considered to be implemented for OpenVPN?
I had a quick look into what IFF_VNET_HDR does. And it seem thatIFF_VNET_HDR does GSO/GRO and basically merging multiple packets into one on receive and send. This works probably well on a client as that does not forward IP packets. For an OpenVPN server, this will probably really mess with the packets as it changes the segmentation of the packets traversing the OpenVPN server. This will probably work for 95% of traffic and cause extremely hard to debug problems on the rest of them.
Soe this needs a lot more careful consideration when we could use this flag as MTU related problem are already often present on connection and this flag has the potential to cause more of them.
Arne
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Apologies, I placed the dots ... on the wrong lines, I meant to put them after the if error statements. But yeah, I think you're right about that, I forgot and I remember now there was a part of the OVPN code base where it parses the IPv4 headers out but I forget why and what that part of the code was doing within the framework. So I guess bulk reading packets may not be the best idea also because you'd have to unpack it all anyway!
Thanks for the reply and all the work you folks do on this project,
Jon C (root)
:)
Quoted 34 lines · Arne Schwabe
Am 03.09.26 um 23:37 schrieb Jon Chiappetta via Openvpn-devel:
Quoted 23 lines
Hey all,
I've been busy in life and I haven't had much time to keep up with the development of the OVPN source code and all the commits and everything (it's been a little while since I last posted). I ended up creating a custom framework for my own personal use that is based on the original modifications I did for OpenVPN (multi-threaded, bulk-reads, TCP-only, standard-MTU). I was able to get over a gigabit speeds on my wifi client with this network-wide VPN solution I have now.
I found these 2 new-to-me parameters for TUN interfaces which are really cool and I didn't know existed (I also didn't see them last time I checked the source code here) -
IFF_MULTI_QUEUE|IFF_VNET_HDR. Obviously the multi-queue flag wouldn't work by default here (since it's not multi-threaded) however this other one is pretty nice if you adjust your buffer sizes to be much bigger :)For example, I was able to read thousands of bytes of data in one call from TUN if you set the below parameters in C:
ifrq.ifr_flags = (
IFF_TUN|IFF_NO_PI|IFF_MULTI_QUEUE|IFF_VNET_HDR); TUNF[z] =open("/dev/net/tun", O_RDWR);
...
erro =ioctl(TUNF[z], TUNSETIFF, &ifrq);
if (erro < 0) {printf("%s ERRO TUNSETIFF [%d]\n", date(), z); }
...
int leng =sizeof(struct virtio_net_hdr);
erro =ioctl(TUNF[z], TUNSETVNETHDRSZ, &leng);
...
if (erro < 0) {printf("%s ERRO TUNSETVNETHDRSZ [%d]\n", date(), z); } unsigned int offl = (TUN_F_CSUM|TUN_F_TSO4|TUN_F_TSO6);
...
erro =ioctl(TUNF[z], TUNSETOFFLOAD, offl);
if (erro < 0) {printf("%s ERRO TUNSETOFFLOAD [%d]\n", date(), z); }Quoted 1 line
I don't know the full history here yet and am still learning but was this option ever considered to be implemented for OpenVPN?
I had a quick look into what
IFF_VNET_HDRdoes. And it seem thatIFF_VNET_HDRdoes GSO/GRO and basically merging multiple packets into one on receive and send. This works probably well on a client as that does not forward IP packets. For an OpenVPN server, this will probably really mess with the packets as it changes the segmentation of the packets traversing the OpenVPN server. This will probably work for 95% of traffic and cause extremely hard to debug problems on the rest of them.
Quoted 5 lines
Soe this needs a lot more careful consideration when we could use this flag as MTU related problem are already often present on connection and this flag has the potential to cause more of them.
Arne
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Hi,
Quoted 2 lines · Jon Chiappetta via Openvpn-devel
I don't know the full history here yet and am still learning but was this option ever considered to be implemented for OpenVPN?
The canoncial answer for "make things complicated but fast" on Linux is DCO - there is nothing you can do to in userland process to get the speeds you can get with DCO (except go full DPDK), so the focus for userland is more on "avoid platform-specific complications" nowadays.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Hi Gert,
Thanks, I had just one other question on the DCO and what functionality it covers, I tried to look at the source code some time back but I am unable to read kernel level C properly compared to app level C, it hurts my eyes. For example, let's say there are these basic components to a VPN:
- read from interface
- encrypted buffer data
- send to socket
- recv from socket
- decrypt buffer data
- write to interface
When I was looking at the OVPN source code some time back, I saw that the read from tun and write to tun was at the app level and then it handed it off to the DCO module? Does the DCO module primarily cover the encrypt and socket operations and functionality alone?
Thanks again,
Jon C (root)
Quoted 7 lines · Gert Doering
Hi,
Quoted 2 lines · Jon Chiappetta via Openvpn-devel
I don't know the full history here yet and am still learning but was this option ever considered to be implemented for OpenVPN?
Quoted 17 lines
The canoncial answer for "make things complicated but fast" on Linux is DCO - there is nothing you can do to in userland process to get the speeds you can get with DCO (except go full DPDK), so the focus for userland is more on "avoid platform-specific complications" nowadays.
gert
Signature · 9 lines
"If was one thing all people took for granted, was conviction that if you feed honest figures into a computer, honest figures come out. Never doubted it myself till I met a computer with a sense of humor." Robert A. Heinlein, The Moon is a Harsh Mistress Gert Doering - Munich, Germany [email protected] Attachments: * signature.asc
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Hi,
Quoted 6 lines · Jon Chiappetta
- read from interface
- encrypted buffer data
- send to socket
- recv from socket
- decrypt buffer data
- write to interface
For data packets, this all happens at kernel level.
Control channel packets (= TLS handling, user auth, all the stuff you do not want to do in kernel) are handed to the userland process.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel