-
Notifications
You must be signed in to change notification settings - Fork 4
/
run.sh
executable file
·62 lines (48 loc) · 1.67 KB
/
run.sh
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# An example script for running the flow-disruptor using Linux veth interfaces.
#
# Copyright 2015 Teclo Networks AG
set -e
DEV=eth0
function die {
echo "$@";
exit 1;
}
# Determine current network settings
IP=$(ip addr show dev $DEV | perl -nle '/inet ([\d.]+)/ && print $1')
[ -n "$IP" ] || die "Can't determine ip of $DEV"
GW=$(ip route show default dev $DEV | perl -nle '/^default via (\S+)/ && print $1' | head -1)
[ -n "$GW" ] || die "Can't determine default route"
# Restore original settings once we quit
function cleanup {
echo Restoring original setup
sleep 1
ifconfig $DEV $IP
ifconfig veth1 0.0.0.0
route add default gw $GW dev $DEV
ifconfig veth0 down
ifconfig veth1 down
}
trap cleanup EXIT
echo Setting up interfaces ip $IP gw $GW
# Create the veth0/veth1 pair if it doesn't exist.
ip link ls | grep veth0 || ip link add type veth
ifconfig veth0 down
ifconfig veth1 down
# Turn off tx segment offload on the veths
ethtool -K veth0 tx off
ethtool -K veth1 tx off
# Turn off all known kinds of offload on the actual interface
ethtool -K $DEV tso off gso off gro off
# Make sure we can route all kinds of packets through the interface.
echo 1 | tee /proc/sys/net/ipv4/conf/$DEV/rp_filter
# Bind the IP to veth1 instead of the real interface
echo Switching to veth interface
ifconfig veth0 up promisc
ifconfig veth1 $IP up promisc
ifconfig $DEV down
ifconfig $DEV up 0.0.0.0 promisc
route add default gw $GW dev veth1
# ip route change $TARGET via $GW dev veth1 proto static initrwnd 100
# Start the flow-disruptor between veth0 and the real interface
./bin/flow-disruptor --downlink_iface veth0 --uplink_iface $DEV --config my.conf