Skip to content

Use all your internet connections at once on Windows, macOS, Linux and Android: per-connection load balancing over Wi-Fi, Ethernet, mobile data and phone tethers

e2e: keep the test uplink's traffic out of the TUN; count UDP DNS answers (#16)

Rohit Mahto03cff8b8771e
diff --git a/scripts/linux-e2e.sh b/scripts/linux-e2e.sh
index e34207f..0100b2c 100755
--- a/scripts/linux-e2e.sh
+++ b/scripts/linux-e2e.sh
@@ -31,6 +31,8 @@ cleanup() {
sudo ip netns del nmup 2>/dev/null
sudo ip link del nmup-h 2>/dev/null
sudo ip link del nmgw-h 2>/dev/null
+ sudo ip rule del iif nmgw-h lookup 100 2>/dev/null
+ sudo ip route flush table 100 2>/dev/null
sudo iptables -t nat -D POSTROUTING -s 10.88.0.0/24 -o "$REAL" -j MASQUERADE 2>/dev/null
sudo iptables -D FORWARD -i nmgw-h -j ACCEPT 2>/dev/null
sudo iptables -D FORWARD -o nmgw-h -j ACCEPT 2>/dev/null
@@ -48,6 +50,13 @@ nic_bytes() { # bytes net-merge relayed through an adapter, from its status file
jq -r --arg n "$1" '.NICs[] | select(.Name == $n) | .BytesIn' "$STATE/status.json"
}
+dns_answers() { # dns_answers RESOLVER: how many of 12 single-try queries are answered (each is a new UDP flow)
+ local n=0
+ for _ in $(seq 1 12); do
+ dig +short +tries=1 +time=2 @"$1" example.com 2>/dev/null | grep -qE '^[0-9.]+$' && n=$((n + 1))
+ done
+ echo $n
+}
echo "== real uplink: $REAL"
rm -rf "$STATE" && mkdir -p "$STATE"
@@ -69,12 +78,20 @@ sudo iptables -t nat -A POSTROUTING -s 10.88.0.0/24 -o "$REAL" -j MASQUERADE
sudo iptables -I FORWARD -i nmgw-h -j ACCEPT
sudo iptables -I FORWARD -o nmgw-h -j ACCEPT
sudo ip route add default via 10.77.0.2 dev nmup-h metric 900
+# What the namespace sends out through the host must leave through the real NIC. Without this it would
+# match net-merge's capture routes, re-enter the TUN and loop (thousands of flows per second).
+gw=$(ip -4 route show default dev "$REAL" | awk '{print $3; exit}')
+sudo ip route add default ${gw:+via $gw} dev "$REAL" table 100
+sudo ip rule add iif nmgw-h lookup 100 priority 90
ip=$(curl -4 -s --max-time 10 --interface nmup-h https://api.ipify.org) &&
pass "second uplink reaches the internet on its own (exit IP $ip)" || fail "second uplink has no internet"
echo "== adapter detection (the veth is virtual, so it is used only via -include)"
"$BIN" list
+if command -v dig >/dev/null; then
+ echo "== DNS over UDP without net-merge (baseline): 1.1.1.1 $(dns_answers 1.1.1.1)/12, 8.8.8.8 $(dns_answers 8.8.8.8)/12, 9.9.9.9 $(dns_answers 9.9.9.9)/12"
+fi
echo "== system-wide ON over $REAL + nmup-h"
sudo "$BIN" run -include "$REAL,nmup-h" -state-dir "$STATE" -log "$STATE/net-merge.log" -stats 0 -for 170s &
wait_on && pass "net-merge turned on" || { fail "net-merge did not turn on"; cat "$STATE/net-merge.log"; exit 1; }
@@ -90,8 +107,13 @@ mtu=$(cat /sys/class/net/net-merge/mtu)
code=$(curl -4 -s --max-time 10 -o /dev/null -w '%{http_code}' https://example.com)
[ "$code" = 200 ] && pass "plain HTTPS works through net-merge" || fail "HTTPS through net-merge: $code"
if command -v dig >/dev/null; then
- dig +short +time=3 @1.1.1.1 example.com | grep -qE '^[0-9.]+$' &&
- pass "UDP DNS to 1.1.1.1 works through net-merge" || fail "UDP DNS through net-merge"
+ # Each query is a new UDP flow, so they spread over both uplinks.
+ nics() { jq -c '.NICs[] | {n: .Name, flows: .Total, in: .BytesIn, out: .BytesOut}' "$STATE/status.json" | tr '\n' ' '; echo; }
+ sleep 2; echo " before: $(nics)"
+ a1=$(dns_answers 1.1.1.1); a2=$(dns_answers 8.8.8.8); a3=$(dns_answers 9.9.9.9)
+ sleep 2; echo " after: $(nics)"
+ echo " UDP DNS through net-merge: 1.1.1.1 $a1/12, 8.8.8.8 $a2/12, 9.9.9.9 $a3/12"
+ [ $((a1 + a2 + a3)) -ge 30 ] && pass "UDP DNS works through net-merge (36 queries, over both uplinks)" || fail "UDP DNS through net-merge: $((a1 + a2 + a3)) of 36 answered"
fi
echo "== 12 parallel downloads: both uplinks must carry traffic"