binarysec / node-tuntap

Network Tuntap binding for nodejs
34 stars 15 forks source link

write to tun device with ip packet, bad format #8

Open chengen opened 6 years ago

chengen commented 6 years ago

i use: tt.write(packet); to send ip packet and than use tcp dump to capture the packet: tcpdump -i tun8 it seems tcp dump can't recognize the packet.
here is my tun device setup: tt = tuntap({ type: 'tun', name: 'tun8', mtu: 1500, addr: '192.168.100.1', dest: '192.168.100.2', mask: '255.255.255.0', ethtype_comp: 'none', persist: true, up: true, running: true, });

than i look into the code, and modify the code in src/tuntap-itf/tuntap-itf-linux.inc.cc while open the tun device, and add the flag as follows:

109 if(opts.mode == tuntap_itf_opts_t::MODE_TUN) 110 ifr.ifr_flags |= IFF_TUN; 111 else if(opts.mode == tuntap_itf_opts_t::MODE_TAP) 112 ifr.ifr_flags |= IFF_TAP; 113 114 //add by chengen 115 ifr.ifr_flags |= IFF_NO_PI; 116 117 MK_IOCTL(*fd, TUNSETIFF, &ifr)

line 115. and then it works. tcpdump can recognize the packet. is this a bug or i missed something on configuration?

Dagrut commented 6 years ago

I think that it's more a packet formatting issue than a code error here, since I never had this problem. You may be adding too much data with this flag.

Currently, the only non-data value added to the packet is the ethernet type (two bytes), as listed in src/ethertypes.itm, written on 4 byte (two of them will then be 0). The code was not made to handle more than this, and may crash when being close to the MTU (IFF_NO_PI seems to require more data : https://www.mjmwired.net/kernel/Documentation/networking/tuntap.txt ).

Try to read data from the interface and dump it as a hex string, to compare the code output and the wireshark output :-) .