--- /dev/null
+#!/bin/sh
+
+. ./testlib.sh
+
+test "$(id -u)" = "0" || exit $EXIT_SKIP_TEST
+test -e /dev/net/tun || exit $EXIT_SKIP_TEST
+ip netns list || exit $EXIT_SKIP_TEST
+command -v socat || exit $EXIT_SKIP_TEST
+
+ip_foo=192.168.1.1
+ip_bar=192.168.1.2
+port_foo=30100
+recv_port_foo=30101
+mask=24
+
+echo '[STEP] Determining supported compression levels'
+
+features=$(tincd foo --version)
+bogus_levels="-1 13"
+levels=0
+
+add_levels() {
+ algo=$1
+ shift
+
+ if echo "$features" | grep "comp_$algo"; then
+ levels="$levels $*"
+ else
+ bogus_levels="$bogus_levels $*"
+ fi
+}
+
+add_levels zlib 1 2 3 4 5 6 7 8 9
+add_levels lzo 10 11
+add_levels lz4 12
+
+echo "Supported compression levels: $levels"
+echo "Unsupported compression levels: $bogus_levels"
+
+echo [STEP] Create network namespaces
+
+ip netns add foo
+ip netns add bar
+tmp_file=$(mktemp)
+
+cleanup_hook() {
+ ip netns del foo
+ ip netns del bar
+ rm -f "$tmp_file"
+}
+
+echo [STEP] Initialize two nodes
+
+tinc foo <<EOF
+init foo
+set Subnet $ip_foo
+set Interface foo
+set Port $port_foo
+set Address localhost
+EOF
+
+tinc bar <<EOF
+init bar
+set Subnet $ip_bar
+set Interface bar
+set ConnectTo foo
+EOF
+
+# shellcheck disable=SC2016
+create_script foo tinc-up "
+ ip link set dev \$INTERFACE netns foo
+ ip netns exec foo ip addr add $ip_foo/$mask dev \$INTERFACE
+ ip netns exec foo ip link set \$INTERFACE up
+"
+
+# shellcheck disable=SC2016
+create_script bar tinc-up "
+ ip link set dev \$INTERFACE netns bar
+ ip netns exec bar ip addr add $ip_bar/$mask dev \$INTERFACE
+ ip netns exec bar ip link set \$INTERFACE up
+"
+
+echo [STEP] Exchange configuration files
+
+tinc foo export | tinc bar exchange | tinc foo import
+
+echo [STEP] Test supported compression levels
+
+ref_file=$0
+
+create_script foo hosts/bar-up
+create_script bar hosts/foo-up
+
+for level in $levels; do
+ echo "[STEP] Testing compression level $level"
+
+ tinc foo set Compression "$level"
+ tinc bar set Compression "$level"
+
+ start_tinc foo
+ wait_script foo tinc-up
+
+ start_tinc bar
+ wait_script bar tinc-up
+
+ wait_script foo hosts/bar-up
+ wait_script bar hosts/foo-up
+
+ ip netns exec foo \
+ socat -u TCP4-LISTEN:$recv_port_foo,reuseaddr OPEN:"$tmp_file",creat &
+
+ ip netns exec bar \
+ socat -u OPEN:"$ref_file" TCP4:$ip_foo:$recv_port_foo,retry=30
+
+ diff -w "$ref_file" "$tmp_file"
+
+ tinc foo stop
+ tinc bar stop
+done
+
+echo '[STEP] Invalid compression levels should fail'
+
+for level in $bogus_levels; do
+ echo "[STEP] Testing bogus compression level $level"
+ tinc foo set Compression "$level"
+
+ output=$(must_fail start_tinc foo 2>&1)
+
+ if ! echo "$output" | grep -q 'Bogus compression level'; then
+ bail 'expected message about the wrong compression level'
+ fi
+done