Tap Interface Not Coming Up

broadcast packets sent from tap interface not received

Solved it by using proper checksum and proper byte order for tot_len for ip header

iph->tot_len = (htons)sizeof (struct iphdr) + sizeof (struct udphdr) + strlen(data);

iph->id = htons (54321); //Id of this packet

iph->check = htons(csum ((unsigned short *) datagram,sizeof(struct ip_hdr)));
**where csum is a common function to calculate checksum.

from a different machine packet was received because kernel's network stack was recalculating iph->tot_len and the ip checksum. so the packet was properly formed.

with my tun interface after correcting the checksum and byteorder of tot_len packet was received by the application.

Tap device in linux not properly passing ARP/IP packets?

I regret that this was unrelated to the way tap/tun devices work in Linux. In fact, this mechanism will work.

The issue was in that I was using "send" and "recv" to talk to the raw tap device. Wireshark can't tell the difference, but the Linux OS will refuse to use the data coming from the socket.

Use this guy's example: http://www.cis.syr.edu/~wedu/seed/Labs/VPN/files/simpletun.c

iOS Network Extension error creating TUN/TAP interface SIOCGIFMTU failed: device not configured

Okay I managed to solve this on my own. I created a Packet Tunnel Network Extension and in my PacketTunnelProvider class came the problems. It did not crash so setting up the debugger in that class was not worth it. I ran my target and started my app and set several NSLogs in the functions so I could see in the device's console what was happening. My problem was that I tried to set a nil value in a dictionary for a key thus terminating the extension. That crash message can easily be seen in the console.

The problem was when extending PacketTunnelProvider with OpenVPNAdapterDelegate in the function to configure the tunnel

func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings?, completionHandler: @escaping (OpenVPNAdapterPacketFlow?) -> Void) {
networkSettings?.dnsSettings?.matchDomains = [""];
}

Previously I had networkSettings.dnsSettings?.matchDomains = [""]; so networkSettings was unwrapped and it was nil making it crash the extension and the tunnel not being able to get connected.

How to connect a tap interface to the internet?

The tap device is only a virtual ethernet interface - what you send on it, you can read it back on a device file (/dev/tap), and what you write into this device, you get as incoming packet on tap0.

What you can do:

  1. You can do this by netlink or raw sockets. Essentially, it is a special socket type, you can send and receive raw ethernet packets on it.

  2. You can bridge tap0 and wlan0 into a br0 bridge with the brctl command. Wifi and ethernet interfaces can not be bridged together (they are different on the ethernet level, a 802.11 packet is meaningless on 802.3 and vice versa).

Probably you can not create a well-working tcp implementation below a hundred kB of C code. It is because tcp is only simple on the user level.



Related Topics



Leave a reply



Submit