Recently I've been using a tun interface to redirect the Internet traffic through my methods. To do so, I followed this tutorial.My idea is to have a program which receives the IP packets that go to 10.0.0.15 through tun0 interface and redirect them to customSend(), which sends the packet to another computer (using another protocol, but this is not relevant). The other computer would respond to that packet and customRecv() would get it and send it the tun0 interface.Here is a sample of my code:void customSend() {    // whenever a packet is sent from my computer to 10.0.0.15 the    // read method will be triggered.    size = read(tunfd, buffer, sizeof(buffer));    // send packet using another protocol    write(otherProtocolSendfd, buffer, size);}void customRecv() {    // whenever a packet is received from another protocol    // this will be triggered    size = read(otherProtocolRecvfd, buffer, sizeof(buffer));    // redirect the packet to tun0    write(tunfd, buffer, size);}void main() {    // init the tun0 interface    int tunfd = init_tun_interface();    // create a thread running customSend and one running customRecv}To make it easier to understand, I'll show an example.Workstation1 (10.0.0.14) pings Workstation2 (10.0.0.15)ping application creates an ICMP packet and sends it through tun0.read method at customSend() intercepts the ICMP packet.customSend() thread sends it to the other protocol method through otherProtocolSendfd.The other protocol sends the message through the network and the ping packet reaches Workstation2.Workstation2 replies with a pong message.The other protocol receives the network message and writes it through otherProtocolRecvfdread mehod at customRecv() receives the response packet and the write method sends it to tun0 interface.tun0 interface gives the response (pong) packet to the ping application.For now, I have implemented the customSend() part, which does work and transmits the message to the other computer.My concern is about the writting part. Will a write to tunfd actually send the message to the interface or will I receive it at the customSend() method, which is what I would expect. If it's the latter, how could I send the message to the interface?Also, and this is a more general question, will I have any concurrency problems if I have a thread executing customToSend() and another one executing customRecv(), since both are using tunfd.Thanks!
Writting to a Tun/Tap interface
network interface;devices;file descriptors;tap