networking

Mininet: Set Interface MTU

1
2
3
4
5
6
import subprocess
MTU = 9000
net = Mininet( ... )
for intf in [intf for sw in net.switches for intf in sw.intfNames()]:
subprocess.call(['ifconfig', intf, 'mtu', str(MTU)])

Wait for a Local TCP Port with Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python
import time
def waitForTcpPort(port, timeout=20, poll=0.1):
start = time.time()
with open('/proc/net/tcp','r') as f4, open(
'/proc/net/tcp6', 'r') as f6:
while True:
f4.seek(0)
f6.seek(0)
lines = f4.readlines()[1:] + f6.readlines()[1:]
sockets = map(str.split, lines)
listeners = [l for l in sockets if l[3] == '0A']
ports = [int(l[1].split(':')[1], 16) for l in listeners]
if port in ports:
break
time.sleep(poll)
if time.time() - start > timeout:
raise Exception("Timed out waiting (>%gs) for TCP port %d"
% (timeout, port))
if __name__ == '__main__':
import argparse
p = argparse.ArgumentParser()
p.add_argument('port', help='port to wait for', type=int)
args = p.parse_args()
waitForTcpPort(args.port)

Compile Tor Statically

Make a temporary directory to work in:

1
2
mkdir /tmp/static_tor
cd /tmp/static_tor

Make a directory that we will install the static libraries in:

1
mkdir install

Download and compile the dependencies (libevent, openssl and zlib):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
tar xf libevent-2.0.22-stable.tar.gz
cd libevent-2.0.22-stable
./configure --disable-shared --enable-static --with-pic --prefix=/tmp/static_tor/install
make -j4
make install
cd ..
wget https://www.openssl.org/source/openssl-1.0.1r.tar.gz
tar xf openssl-1.0.1r.tar.gz
cd openssl-1.0.1r
./config no-shared no-dso --prefix=/tmp/static_tor/install
make -j4
make install
cd ..
wget http://zlib.net/zlib-1.2.8.tar.gz
tar xf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure --static --prefix=/tmp/static_tor/install
make -j4
make install
cd ..

Clone the Tor source and compile it:

1
2
3
4
5
6
git clone https://git.torproject.org/tor.git
cd tor
git co tor-0.2.7.6
./autogen.sh
./configure --disable-asciidoc --enable-static-tor --with-libevent-dir=/tmp/static_tor/install --with-openssl-dir=/tmp/static_tor/install --with-zlib-dir=/tmp/static_tor/install
make -j4

The Tor binary should be statically compiled:

1
./src/or/tor --version