I create a script that sends all traffic to Eth0 with Tap0 and sends Tap0 all traffic to Eth0. After I found many examples on the Internet, I managed to get it to work. The problem is that performance is very low.
Ping between two virtual machines without using a script takes less than 1 ms. Using a script, it takes ~ 15 ms.
When I send a 10 MB file from a virtual machine to another using scp, avg. transfer rate is 12 Mbps without a script. With a script, it drops to less than 1 Mbps.
I know that Python is actually not the fastest language for working with network traffic, but is it slow?
Is there any way to optimize this code?
My Ubuntu 10.04 32bit virtual machines.
Here is the code:
import os,sys,getopt,struct,re,string,logging from socket import * from fcntl import ioctl from select import select from scapy.all import * TUNSETIFF = 0x400454ca IFF_TAP = 0x0002 TUNMODE = IFF_TAP ETH_IFACE = "eth0" TAP_IFACE = "tap0" conf.iface = ETH_IFACE
source share