run_net_test.sh revision 1eccad2f9baf2dc69e46d2ef5a6f2b6f928e185b
1#!/bin/bash
2
3# Kernel configration options.
4OPTIONS=" IPV6 IPV6_ROUTER_PREF IPV6_MULTIPLE_TABLES IPV6_ROUTE_INFO"
5OPTIONS="$OPTIONS TUN SYN_COOKIES IP_ADVANCED_ROUTER IP_MULTIPLE_TABLES"
6OPTIONS="$OPTIONS NETFILTER NETFILTER_ADVANCED NETFILTER_XTABLES"
7OPTIONS="$OPTIONS NETFILTER_XT_MARK NETFILTER_XT_TARGET_MARK"
8OPTIONS="$OPTIONS IP_NF_IPTABLES IP_NF_MANGLE"
9OPTIONS="$OPTIONS IP6_NF_IPTABLES IP6_NF_MANGLE"
10
11# How many tap interfaces to create.
12NUMTAPINTERFACES=2
13
14# The root filesystem disk image we'll use.
15ROOTFS=$(dirname $0)/net_test.rootfs
16
17# Figure out which test to run.
18if [ -z "$1" ]; then
19  echo "Usage: $0 <test>" >&2
20  exit 1
21fi
22test=$1
23
24set -e
25
26# Check if we need to uncompress the disk image.
27# We use xz because it compresses better: to 42M vs 72M (gzip) / 62M (bzip2).
28if [ $ROOTFS.xz -nt $ROOTFS ]; then
29  echo "Deleting $ROOTFS" >&2
30  rm -f $ROOTFS
31  echo "Uncompressing $ROOTFS.xz" >&2
32  unxz --keep $ROOTFS.xz
33fi
34
35
36# Create NUMTAPINTERFACES tap interfaces on the host, and prepare UML command
37# line params to use them. The interfaces are called <user>TAP0, <user>TAP1,
38# ..., on the host, and eth0, eth1, ..., in the VM.
39user=${USER:0:10}
40tapinterfaces=
41netconfig=
42for id in $(seq 0 $(( NUMTAPINTERFACES - 1 )) ); do
43  tap=${user}TAP$id
44  tapinterfaces="$tapinterfaces $tap"
45  mac=$(printf fe:fd:00:00:00:%02x $id)
46  netconfig="$netconfig eth$id=tuntap,$tap,$mac"
47done
48
49for tap in $tapinterfaces; do
50  if ! ip link list $tap > /dev/null; then
51    echo "Creating tap interface $tap" >&2
52    sudo tunctl -u $USER -t $tap
53    sudo ip link set $tap up
54  fi
55done
56
57# Exporting ARCH=um SUBARCH=x86_64 doesn't seem to work, as it "sometimes" (?)
58# results in a 32-bit kernel.
59
60# If there's no kernel config at all, create one or UML won't work.
61[ -f .config ] || make defconfig ARCH=um SUBARCH=x86_64
62
63# Enable the kernel config options listed in $OPTIONS.
64cmdline=${OPTIONS// / -e }
65./scripts/config $cmdline
66
67# olddefconfig doesn't work on old kernels.
68if ! make olddefconfig ARCH=um SUBARCH=x86_64 CROSS_COMPILE= ; then
69  cat >&2 << EOF
70
71Warning: "make olddefconfig" failed.
72Perhaps this kernel is too old to support it.
73You may get asked lots of questions.
74Keep enter pressed to accept the defaults.
75
76EOF
77fi
78
79# Compile the kernel.
80make -j12 linux ARCH=um SUBARCH=x86_64 CROSS_COMPILE=
81
82# Get the absolute path to the test file that's being run.
83dir=/host$(dirname $(readlink -f $0))
84
85# Start the VM.
86exec ./linux umid=net_test ubda=$(dirname $0)/net_test.rootfs \
87    mem=512M init=/sbin/net_test.sh net_test=$dir/$test \
88    $netconfig
89