3

I'm using pytun to setup a TUN and forward packets that arrive on it to another machine using UDP. What's puzzling me is that even though I've configured the TUN to have MTU of 141 bytes, I'm reading packets of size 145 on it. See the code below:

from pytun import TunTapDevice
tun = TunTapDevice(name="vpn")
tun.addr = '10.8.0.1'
tun.dstaddr = '10.8.0.2'
tun.netmask = '255.255.255.0'
tun.mtu = 141
tun.up()
assert len(tun.read(1000)) <= tun.mtu # <-- fails for some packets

I've verified the actual MTU of the interface using ifconfig.

Am I missing something?

4

1 に答える 1

4

IFF_NO_PI フラグを追加しないと、フレームに 4 バイトのヘッダーが表示されます。

カーネル Documentation/networking/tuntap.txt から

3.2 フレームフォーマット:

フラグ IFF_NO_PI が設定されていない場合、各フレーム フォーマットは次のとおりです。
フラグ [2 バイト]
プロト [2 バイト]
生のプロトコル (IP、IPv6 など) フレーム。

おそらく、あなたはあなたが望むものを手に入れることができるはずです

from pytun import TunTapDevice, IFF_TUN, IFF_NO_PI
tun = TunTapDevice(name="vpn",flags=(IFF_TUN | IFF_NO_PI))
于 2014-12-01T09:30:42.600 に答える