From 414e9c83fbf10855389ec0ac9ae6714314383584 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Fri, 21 May 2021 14:22:43 +0900 Subject: [PATCH] docker-tests: support userspace and kernel backends --- .github/workflows/docker-tests.yml | 2 +- docker-tests/run-docker-tests.sh | 25 +++++++++++++++++++++++++ docker-tests/start-client.sh | 6 ++---- docker-tests/start-server.sh | 10 +++++----- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docker-tests.yml b/.github/workflows/docker-tests.yml index e9a7aaa..5bb06ef 100644 --- a/.github/workflows/docker-tests.yml +++ b/.github/workflows/docker-tests.yml @@ -17,5 +17,5 @@ jobs: - name: Build the Docker images run: docker-tests/build-docker-images.sh - name: Run the Docker tests - run: docker-tests/run-docker-tests.sh + run: docker-tests/run-docker-tests.sh userspace diff --git a/docker-tests/run-docker-tests.sh b/docker-tests/run-docker-tests.sh index f892e1e..4b635f5 100755 --- a/docker-tests/run-docker-tests.sh +++ b/docker-tests/run-docker-tests.sh @@ -1,9 +1,31 @@ #!/usr/bin/env bash set -e +shopt -s nocasematch SELF_DIR="$(dirname "$0")" cd "$SELF_DIR/.." +if [[ $# -eq 1 ]]; then + case "$1" in + kernel) + INNERNET_ARGS="" + ;; + userspace) + INNERNET_ARGS="--backend userspace" + ;; + *) + echo "invalid backend (must be kernel or userspace)" + exit 1 + esac +else + cat >&2 <<-_EOF + Usage: "${0##*/}" + + BACKEND: "kernel" or "userspace" +_EOF + exit +fi + cmd() { echo "[#] $*" >&2 "$@" @@ -31,6 +53,7 @@ SERVER_CONTAINER=$(cmd docker create -it --rm \ --ip 172.18.1.1 \ --volume /dev/net/tun:/dev/net/tun \ --env RUST_LOG=debug \ + --env INNERNET_ARGS="$INNERNET_ARGS" \ --cap-add NET_ADMIN \ innernet-server) cmd docker start -a "$SERVER_CONTAINER" & @@ -46,6 +69,7 @@ PEER1_CONTAINER=$(cmd docker create --rm -it \ --ip 172.18.1.2 \ --volume /dev/net/tun:/dev/net/tun \ --env INTERFACE=evilcorp \ + --env INNERNET_ARGS="$INNERNET_ARGS" \ --cap-add NET_ADMIN \ innernet) info "peer1 started as $PEER1_CONTAINER" @@ -86,6 +110,7 @@ PEER2_CONTAINER=$(docker create --rm -it \ --volume /dev/net/tun:/dev/net/tun \ --cap-add NET_ADMIN \ --env INTERFACE=evilcorp \ + --env INNERNET_ARGS="$INNERNET_ARGS" \ innernet) info "peer2 started as $PEER2_CONTAINER" cmd docker cp "$tmp_dir/peer2.toml" "$PEER2_CONTAINER:/app/invite.toml" diff --git a/docker-tests/start-client.sh b/docker-tests/start-client.sh index 11186be..263421d 100755 --- a/docker-tests/start-client.sh +++ b/docker-tests/start-client.sh @@ -1,16 +1,14 @@ #!/bin/bash set -e -DEFAULT_ARGS="--backend userspace" - INTERFACE="${INTERFACE:-innernet}" -innernet $DEFAULT_ARGS install \ +innernet $INNERNET_ARGS install \ --name "$INTERFACE" \ --delete-invite \ --no-write-hosts \ /app/invite.toml while true; do - innernet $DEFAULT_ARGS up --no-write-hosts "$INTERFACE" + innernet $INNERNET_ARGS up --no-write-hosts "$INTERFACE" sleep 1 done diff --git a/docker-tests/start-server.sh b/docker-tests/start-server.sh index 79e2443..be1a78a 100755 --- a/docker-tests/start-server.sh +++ b/docker-tests/start-server.sh @@ -1,10 +1,10 @@ #!/bin/bash set -e -DEFAULT_ARGS="--backend userspace" +INNERNET_ARGS="--backend userspace" innernet-server \ - $DEFAULT_ARGS \ + $INNERNET_ARGS \ new \ --network-name "evilcorp" \ --network-cidr "10.66.0.0/16" \ @@ -12,7 +12,7 @@ innernet-server \ --listen-port 51820 innernet-server \ - $DEFAULT_ARGS \ + $INNERNET_ARGS \ add-cidr evilcorp \ --name "humans" \ --cidr "10.66.1.0/24" \ @@ -20,7 +20,7 @@ innernet-server \ --yes innernet-server \ - $DEFAULT_ARGS \ + $INNERNET_ARGS \ add-peer evilcorp \ --name "admin" \ --cidr "humans" \ @@ -30,4 +30,4 @@ innernet-server \ --invite-expires "30d" \ --yes -innernet-server $DEFAULT_ARGS serve evilcorp +innernet-server $INNERNET_ARGS serve evilcorp