Skip to content

Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic

build(linux): build out of tree so only output/ receives final files

anof-cyberec50a2075b40
diff --git a/.gitignore b/.gitignore
index 0ebd9fb..f3c5aea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -107,6 +107,8 @@ Linux/gui/*.o
Linux/gui/ProxyBridgeGUI
Linux/ProxyBridgeGUI
Linux/src/tests/rules_test
+Linux/src/dns_test
+Linux/src/rules_test
Linux/src/tests/dns_test
Linux/**/*.o
Linux/**/*.skel.h
diff --git a/Linux/README.md b/Linux/README.md
index 521a062..7137e1d 100644
--- a/Linux/README.md
+++ b/Linux/README.md
@@ -501,10 +501,10 @@ MIT License - See LICENSE file for details
## Testing
```bash
-cd Linux/src && make && cd ../cli && make # build
-cd ../src && make test-rules # rule engine + DNS parser tests (no root needed)
+cd Linux && ./build.sh # builds in a temp dir, final files land in Linux/output/
+cd src && make test-rules BUILD_DIR=/tmp/pbt # rule engine + DNS parser tests (no root needed)
cd tests && ./run_relay_test.sh both # relay tests, plain and ASan/UBSan (no root needed)
-cd ../../tests && sudo ./e2e.sh # end-to-end with real kernel hooks (root)
+cd ../../tests && sudo ./e2e.sh # end-to-end with real kernel hooks (root); uses Linux/output, override with PB_DIR=
sudo ./e2e_domains.sh # domain rules with a real resolver client (root, needs dig)
sudo ./e2e_rules.sh # every rule form + every proxy type, incl. HTTP auth and UDP rules (root)
sudo ./api_live.sh # library API: edit/move/disable/delete rules and proxies on the live datapath (root)
diff --git a/Linux/build.sh b/Linux/build.sh
index 6d5f49b..a3e694e 100755
--- a/Linux/build.sh
+++ b/Linux/build.sh
@@ -1,101 +1,90 @@
#!/bin/bash
-
-set -e # Exit on error
+# Builds libproxybridge.so, the CLI and (if GTK3 is present) the GUI.
+# Everything is compiled in a temporary directory; only the final binaries are copied to output/,
+# so the source tree never collects .o files, generated headers or libraries.
+#
+# ./build.sh -> Linux/output/
+# OUTPUT_DIR=/some/dir ./build.sh
+set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-OUTPUT_DIR="$SCRIPT_DIR/output"
+OUTPUT_DIR="${OUTPUT_DIR:-$SCRIPT_DIR/output}"
+BUILD_DIR="$(mktemp -d "${TMPDIR:-/tmp}/proxybridge-build.XXXXXX")"
+trap 'rm -rf "$BUILD_DIR"' EXIT
-# Remove and recreate output directory
-if [ -d "$OUTPUT_DIR" ]; then
- echo "Removing existing output directory..."
- rm -rf "$OUTPUT_DIR"
+need() { # command, install hint
+ command -v "$1" >/dev/null 2>&1 || { echo "ERROR: '$1' not found. $2"; exit 1; }
+}
+need gcc "Install: sudo apt install build-essential | sudo dnf install gcc"
+need make "Install: sudo apt install make | sudo dnf install make"
+need clang "Needed to compile the eBPF program. Install: sudo apt install clang | sudo dnf install clang"
+need bpftool "Needed to generate the eBPF skeleton. Install: sudo apt install bpftool | sudo dnf install bpftool"
+if [ ! -f /usr/include/bpf/libbpf.h ] && ! pkg-config --exists libbpf 2>/dev/null; then
+ echo "ERROR: libbpf development files not found. Install: sudo apt install libbpf-dev | sudo dnf install libbpf-devel"
+ exit 1
fi
-echo "Creating output directory..."
+# Fresh output directory
+if [ -e "$OUTPUT_DIR" ]; then
+ echo "Removing existing output directory..."
+ rm -rf "$OUTPUT_DIR" 2>/dev/null || {
+ echo "ERROR: cannot remove $OUTPUT_DIR (files owned by another user, e.g. root)."
+ echo " Remove it manually (sudo rm -rf '$OUTPUT_DIR') or choose another one with OUTPUT_DIR=..."
+ exit 1
+ }
+fi
mkdir -p "$OUTPUT_DIR"
echo ""
-# Build library
+# Library
echo "=== Building Library ==="
-cd "$SCRIPT_DIR/src"
-make clean 2>/dev/null || true
-make
-
-if [ -f "libproxybridge.so" ]; then
- echo "Library build successful"
-else
- echo "Library build failed!"
- exit 1
-fi
+make -C "$SCRIPT_DIR/src" BUILD_DIR="$BUILD_DIR/lib"
+[ -f "$BUILD_DIR/lib/libproxybridge.so" ] || { echo "Library build failed!"; exit 1; }
+echo "Library build successful"
echo ""
-# Build CLI (library must stay for linking)
+# CLI
echo "=== Building CLI ==="
-cd "$SCRIPT_DIR/cli"
-make clean 2>/dev/null || true
-make
-
-if [ -f "ProxyBridge" ]; then
- echo "CLI build successful"
-else
- echo "CLI build failed!"
- exit 1
-fi
+make -C "$SCRIPT_DIR/cli" BUILD_DIR="$BUILD_DIR/cli" LIBDIR="$BUILD_DIR/lib"
+[ -f "$BUILD_DIR/cli/ProxyBridge" ] || { echo "CLI build failed!"; exit 1; }
+echo "CLI build successful"
echo ""
-# Move binaries to output
+# GUI (optional)
echo "=== Building GUI ==="
-cd "$SCRIPT_DIR"
-rm -f ProxyBridgeGUI
+GUI_BUILT=0
if pkg-config --exists gtk+-3.0; then
- GUI_CFLAGS="-Wall -Wno-unused-parameter -O3 -Isrc -D_GNU_SOURCE -fstack-protector-strong -D_FORTIFY_SOURCE=2 -fPIE -Wformat -Wformat-security -Werror=format-security -fno-strict-overflow -fno-delete-null-pointer-checks -fwrapv $(pkg-config --cflags gtk+-3.0)"
- GUI_LDFLAGS="-Lsrc -pie -Wl,-z,relro,-z,now -Wl,-z,noexecstack -s -Wl,-rpath,'$ORIGIN/.' -lproxybridge -lpthread $(pkg-config --libs gtk+-3.0) -export-dynamic"
-
- # Compile all GUI source files
- GUI_OBJS=""
- for src in gui/*.c; do
- obj="${src%.c}.o"
- gcc $GUI_CFLAGS -c "$src" -o "$obj"
- GUI_OBJS="$GUI_OBJS $obj"
+ mkdir -p "$BUILD_DIR/gui"
+ GUI_CFLAGS=(-Wall -Wno-unused-parameter -O3 "-I$SCRIPT_DIR/src" -D_GNU_SOURCE -fstack-protector-strong
+ -D_FORTIFY_SOURCE=2 -fPIE -Wformat -Wformat-security -Werror=format-security -fno-strict-overflow
+ -fno-delete-null-pointer-checks -fwrapv $(pkg-config --cflags gtk+-3.0))
+ GUI_OBJS=()
+ for src in "$SCRIPT_DIR"/gui/*.c; do
+ obj="$BUILD_DIR/gui/$(basename "${src%.c}").o"
+ gcc "${GUI_CFLAGS[@]}" -c "$src" -o "$obj"
+ GUI_OBJS+=("$obj")
done
-
- gcc -o ProxyBridgeGUI $GUI_OBJS $GUI_LDFLAGS
-
- rm -f gui/*.o
+ gcc -o "$BUILD_DIR/gui/ProxyBridgeGUI" "${GUI_OBJS[@]}" -pie -Wl,-z,relro,-z,now -Wl,-z,noexecstack -s \
+ "-L$BUILD_DIR/lib" -Wl,-rpath,'$ORIGIN' -lproxybridge -lpthread $(pkg-config --libs gtk+-3.0) -export-dynamic
+ GUI_BUILT=1
echo "GUI build successful"
else
echo "GTK3 not found. Skipping GUI build."
echo " Install with: sudo apt install libgtk-3-dev (Debian/Ubuntu/Mint)"
echo " sudo dnf install gtk3-devel (Fedora)"
fi
-
-echo ""
-echo "Moving binaries to output directory..."
-mv "$SCRIPT_DIR/src/libproxybridge.so" "$OUTPUT_DIR/"
-mv "$SCRIPT_DIR/cli/ProxyBridge" "$OUTPUT_DIR/"
-if [ -f ProxyBridgeGUI ]; then
- mv ProxyBridgeGUI "$OUTPUT_DIR/"
-fi
-echo "Binaries moved to output"
echo ""
-# Cleanup build files
-echo "Cleaning up build artifacts..."
-cd "$SCRIPT_DIR/src"
-rm -f *.o
-make clean 2>/dev/null || true
-cd "$SCRIPT_DIR/cli"
-rm -f *.o
-make clean 2>/dev/null || true
-echo "Cleanup complete"
+# Only the final files go to output/
+echo "Copying binaries to $OUTPUT_DIR ..."
+cp "$BUILD_DIR/lib/libproxybridge.so" "$OUTPUT_DIR/"
+cp "$BUILD_DIR/cli/ProxyBridge" "$OUTPUT_DIR/"
+[ "$GUI_BUILT" = 1 ] && cp "$BUILD_DIR/gui/ProxyBridgeGUI" "$OUTPUT_DIR/"
echo ""
-# Show results
echo "==================================="
echo "Build Complete!"
echo "==================================="
-cd "$OUTPUT_DIR"
-ls -lh
+ls -lh "$OUTPUT_DIR"
echo ""
echo "Output location: $OUTPUT_DIR"
-
diff --git a/Linux/cli/Makefile b/Linux/cli/Makefile
index 6aff0ac..0d9464e 100644
--- a/Linux/cli/Makefile
+++ b/Linux/cli/Makefile
@@ -1,4 +1,9 @@
CC = gcc
+
+# BUILD_DIR / LIBDIR: where generated files go and where libproxybridge.so was built (build.sh sets both).
+BUILD_DIR ?= .
+LIBDIR ?= ../src
+
CFLAGS = -Wall -Wextra -O3 -I../src \
-fstack-protector-strong \
-D_FORTIFY_SOURCE=2 \
@@ -8,22 +13,25 @@ CFLAGS = -Wall -Wextra -O3 -I../src \
-fno-strict-overflow \
-fno-delete-null-pointer-checks \
-fwrapv
-LDFLAGS = -L../src -pie -Wl,-z,relro,-z,now -Wl,-z,noexecstack -s \
+LDFLAGS = -L$(LIBDIR) -pie -Wl,-z,relro,-z,now -Wl,-z,noexecstack -s \
-Wl,-rpath,/usr/local/lib
LIBS = -lproxybridge -lpthread
-TARGET = ProxyBridge
+TARGET = $(BUILD_DIR)/ProxyBridge
SOURCES = main.c
-OBJECTS = $(SOURCES:.c=.o)
+OBJECTS = $(addprefix $(BUILD_DIR)/,$(SOURCES:.c=.o))
all: $(TARGET)
+$(BUILD_DIR):
+ mkdir -p $@
+
$(TARGET): $(OBJECTS)
$(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
@echo "Stripping debug symbols..."
strip --strip-all $@
-%.o: %.c
+$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
clean:
diff --git a/Linux/src/Makefile b/Linux/src/Makefile
index 677f8b8..6c1b482 100644
--- a/Linux/src/Makefile
+++ b/Linux/src/Makefile
@@ -3,7 +3,11 @@ CLANG ?= clang
BPFTOOL ?= bpftool
MULTIARCH := $(shell $(CC) -print-multiarch)
-CFLAGS = -Wall -Wextra -O2 -fPIC -D_GNU_SOURCE \
+# BUILD_DIR keeps every generated file (objects, BPF object, skeleton, library) out of the source tree.
+# build.sh points it at a temporary directory; a plain `make` builds in place for quick development.
+BUILD_DIR ?= .
+
+CFLAGS = -Wall -Wextra -O2 -fPIC -D_GNU_SOURCE -I$(BUILD_DIR) \
-fstack-protector-strong \
-D_FORTIFY_SOURCE=2 \
-fPIE \
@@ -15,34 +19,38 @@ CFLAGS = -Wall -Wextra -O2 -fPIC -D_GNU_SOURCE \
LDFLAGS = -shared -Wl,-z,relro,-z,now -Wl,-z,noexecstack -s
LIBS = -lpthread -lbpf
-TARGET = libproxybridge.so
SOURCES = ProxyBridge.c pb_rules.c pb_dns.c pb_bpf.c pb_relay.c
-OBJECTS = $(SOURCES:.c=.o)
-BPF_OBJ = bpf/proxybridge.bpf.o
-SKEL = proxybridge.skel.h
+OBJECTS = $(addprefix $(BUILD_DIR)/,$(SOURCES:.c=.o))
+TARGET = $(BUILD_DIR)/libproxybridge.so
+BPF_OBJ = $(BUILD_DIR)/proxybridge.bpf.o
+SKEL = $(BUILD_DIR)/proxybridge.skel.h
all: $(TARGET)
-$(BPF_OBJ): bpf/proxybridge.bpf.c bpf/pb_bpf_shared.h
+$(BUILD_DIR):
+ mkdir -p $@
+
+$(BPF_OBJ): bpf/proxybridge.bpf.c bpf/pb_bpf_shared.h | $(BUILD_DIR)
$(CLANG) -O2 -g -target bpf -D__BPF__ -I/usr/include/$(MULTIARCH) -c $< -o $@
$(SKEL): $(BPF_OBJ)
$(BPFTOOL) gen skeleton $< > $@
-pb_bpf.o: $(SKEL)
+$(BUILD_DIR)/pb_bpf.o: $(SKEL)
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-%.o: %.c pb_internal.h ProxyBridge.h
+$(BUILD_DIR)/%.o: %.c pb_internal.h ProxyBridge.h | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
-test-rules: tests/rules_test.c tests/dns_test.c pb_rules.c pb_rules.h pb_dns.c pb_dns.h
- $(CC) -Wall -Wextra -g -fsanitize=address,undefined -D_GNU_SOURCE tests/rules_test.c pb_rules.c -o tests/rules_test && tests/rules_test
- $(CC) -Wall -Wextra -g -fsanitize=address,undefined -D_GNU_SOURCE tests/dns_test.c pb_dns.c -o tests/dns_test && tests/dns_test
+# Unit tests (no root needed); binaries go to BUILD_DIR as well.
+test-rules: tests/rules_test.c tests/dns_test.c pb_rules.c pb_rules.h pb_dns.c pb_dns.h | $(BUILD_DIR)
+ $(CC) -Wall -Wextra -g -fsanitize=address,undefined -D_GNU_SOURCE tests/rules_test.c pb_rules.c -o $(BUILD_DIR)/rules_test && $(BUILD_DIR)/rules_test
+ $(CC) -Wall -Wextra -g -fsanitize=address,undefined -D_GNU_SOURCE tests/dns_test.c pb_dns.c -o $(BUILD_DIR)/dns_test && $(BUILD_DIR)/dns_test
clean:
- rm -f $(OBJECTS) $(TARGET) $(BPF_OBJ) $(SKEL) tests/rules_test tests/dns_test
+ rm -f $(OBJECTS) $(TARGET) $(BPF_OBJ) $(SKEL) $(BUILD_DIR)/rules_test $(BUILD_DIR)/dns_test
install: $(TARGET)
install -m 0755 $(TARGET) /usr/local/lib/
diff --git a/Linux/tests/api_live.sh b/Linux/tests/api_live.sh
index 6c7b9b8..45f71b6 100755
--- a/Linux/tests/api_live.sh
+++ b/Linux/tests/api_live.sh
@@ -1,8 +1,10 @@
#!/bin/bash
# Library API against the live datapath. Needs root, curl, python3, gcc. sudo tests/api_live.sh
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"; ROOT="$(dirname "$HERE")"
+PB_DIR="${PB_DIR:-$ROOT/output}" # directory holding the built ProxyBridge + libproxybridge.so (run ../build.sh first)
+[ -x "$PB_DIR/ProxyBridge" ] && [ -f "$PB_DIR/libproxybridge.so" ] || { echo "Build first: (cd Linux && ./build.sh), or set PB_DIR to a directory containing ProxyBridge and libproxybridge.so"; exit 1; }
WORK=$(mktemp -d); trap 'kill $FAKE 2>/dev/null; wait 2>/dev/null; rm -rf $WORK' EXIT
-gcc -Wall -Wextra -O1 -g -I"$ROOT/src" -o "$WORK/api_live_test" "$HERE/api_live_test.c" -L"$ROOT/src" -lproxybridge -lpthread || exit 1
+gcc -Wall -Wextra -O1 -g -I"$ROOT/src" -o "$WORK/api_live_test" "$HERE/api_live_test.c" -L"$PB_DIR" -lproxybridge -lpthread || exit 1
python3 "$HERE/fake_proxies.py" "$WORK/log" >/dev/null 2>&1 & FAKE=$!
sleep 1
-LD_LIBRARY_PATH="$ROOT/src" "$WORK/api_live_test"
+LD_LIBRARY_PATH="$PB_DIR" "$WORK/api_live_test"
diff --git a/Linux/tests/dnsbench.sh b/Linux/tests/dnsbench.sh
index ffe6f81..c39ec01 100755
--- a/Linux/tests/dnsbench.sh
+++ b/Linux/tests/dnsbench.sh
@@ -3,7 +3,9 @@
# sudo tests/dnsbench.sh [queries]
set -u
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"; ROOT="$(dirname "$HERE")"; N=${1:-20000}
-export LD_LIBRARY_PATH="$ROOT/src"; DNSIP=10.77.0.3
+PB_DIR="${PB_DIR:-$ROOT/output}" # directory holding the built ProxyBridge + libproxybridge.so (run ../build.sh first)
+[ -x "$PB_DIR/ProxyBridge" ] && [ -f "$PB_DIR/libproxybridge.so" ] || { echo "Build first: (cd Linux && ./build.sh), or set PB_DIR to a directory containing ProxyBridge and libproxybridge.so"; exit 1; }
+export LD_LIBRARY_PATH="$PB_DIR"; DNSIP=10.77.0.3
WORK=$(mktemp -d); trap 'kill $DNS $PB 2>/dev/null; wait 2>/dev/null; ip addr del $DNSIP/32 dev lo 2>/dev/null; rm -rf $WORK' EXIT
ip addr add $DNSIP/32 dev lo 2>/dev/null
python3 "$HERE/fake_dns.py" $DNSIP $WORK/dns.log >/dev/null 2>&1 & DNS=$!
@@ -22,10 +24,10 @@ print(" %d queries: %.0f qps avg=%.0fus p50=%.0fus p99=%.0fus" % (n, n / dt, s
PY
}
echo "== no ProxyBridge"; bench; bench
-stdbuf -oL "$ROOT/cli/ProxyBridge" --proxy a=socks5://127.0.0.1:19080 --rule "*:*.example.test:*:TCP:PROXY=a" > $WORK/pb.out 2>&1 & PB=$!
+stdbuf -oL "$PB_DIR/ProxyBridge" --proxy a=socks5://127.0.0.1:19080 --rule "*:*.example.test:*:TCP:PROXY=a" > $WORK/pb.out 2>&1 & PB=$!
for _ in $(seq 40); do grep -q "ProxyBridge started" $WORK/pb.out && break; sleep 0.25; done
echo "== ProxyBridge running, python3 covered by a domain rule (every query goes through the DNS tap)"; bench; bench
kill -INT $PB; wait $PB 2>/dev/null
-stdbuf -oL "$ROOT/cli/ProxyBridge" --proxy a=socks5://127.0.0.1:19080 --rule "someother:*.example.test:*:TCP:PROXY=a" > $WORK/pb.out 2>&1 & PB=$!
+stdbuf -oL "$PB_DIR/ProxyBridge" --proxy a=socks5://127.0.0.1:19080 --rule "someother:*.example.test:*:TCP:PROXY=a" > $WORK/pb.out 2>&1 & PB=$!
for _ in $(seq 40); do grep -q "ProxyBridge started" $WORK/pb.out && break; sleep 0.25; done
echo "== ProxyBridge running, python3 NOT covered (DNS untouched by the tap)"; bench; bench
diff --git a/Linux/tests/e2e.sh b/Linux/tests/e2e.sh
index a0fe0d1..9106ca5 100755
--- a/Linux/tests/e2e.sh
+++ b/Linux/tests/e2e.sh
@@ -4,6 +4,8 @@
set -u
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(dirname "$HERE")"
+PB_DIR="${PB_DIR:-$ROOT/output}" # directory holding the built ProxyBridge + libproxybridge.so (run ../build.sh first)
+[ -x "$PB_DIR/ProxyBridge" ] && [ -f "$PB_DIR/libproxybridge.so" ] || { echo "Build first: (cd Linux && ./build.sh), or set PB_DIR to a directory containing ProxyBridge and libproxybridge.so"; exit 1; }
WORK="$(mktemp -d)"
LOG="$WORK/proxy.log"; : > "$LOG"
PASS=0; FAIL=0
@@ -16,7 +18,7 @@ cleanup() { kill "$PB_PID" "$FAKE_PID" "$DIRECT_PID" 2>/dev/null; wait 2>/dev/nu
trap cleanup EXIT
[ "$(id -u)" = 0 ] || { echo "run as root"; exit 1; }
-export LD_LIBRARY_PATH="$ROOT/src"
+export LD_LIBRARY_PATH="$PB_DIR"
python3 "$HERE/fake_proxies.py" "$LOG" > "$WORK/fake.out" 2>&1 & FAKE_PID=$!
# a direct (non-proxied) origin on the host's own LAN address, so DIRECT rules can be seen to work
@@ -27,7 +29,7 @@ sleep 1
cp "$(command -v curl)" "$WORK/newcurl" # a binary that did not exist when ProxyBridge started
-stdbuf -oL "$ROOT/cli/ProxyBridge" --verbose 3 \
+stdbuf -oL "$PB_DIR/ProxyBridge" --verbose 3 \
--proxy a=socks5://127.0.0.1:19080 --proxy b=socks5://bob:[email protected]:19081 --proxy c=http://127.0.0.1:19082 \
--rule "curl:$MYIP/32:18399:TCP:DIRECT" \
--rule "curl:192.0.2.0/24:*:TCP:PROXY=a" \
diff --git a/Linux/tests/e2e_domains.sh b/Linux/tests/e2e_domains.sh
index 60cdadb..6f8c4c9 100755
--- a/Linux/tests/e2e_domains.sh
+++ b/Linux/tests/e2e_domains.sh
@@ -3,6 +3,8 @@
# sudo Linux/tests/e2e_domains.sh
set -u
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"; ROOT="$(dirname "$HERE")"
+PB_DIR="${PB_DIR:-$ROOT/output}" # directory holding the built ProxyBridge + libproxybridge.so (run ../build.sh first)
+[ -x "$PB_DIR/ProxyBridge" ] && [ -f "$PB_DIR/libproxybridge.so" ] || { echo "Build first: (cd Linux && ./build.sh), or set PB_DIR to a directory containing ProxyBridge and libproxybridge.so"; exit 1; }
WORK="$(mktemp -d)"; PLOG="$WORK/proxy.log"; DLOG="$WORK/dns.log"; : > "$PLOG"; : > "$DLOG"
PASS=0; FAIL=0; DNSIP=10.77.0.2
ok() { echo " PASS $1"; PASS=$((PASS+1)); }
@@ -11,13 +13,13 @@ has() { [[ "$2" == *"$3"* ]] && ok "$1" || bad "$1 (got: ${2:0:160})"; }
cleanup() { kill "$PB_PID" "$FAKE_PID" "$DNS_PID" 2>/dev/null; wait 2>/dev/null; ip addr del $DNSIP/32 dev lo 2>/dev/null; rm -rf "$WORK"; }
trap cleanup EXIT
[ "$(id -u)" = 0 ] || { echo "run as root"; exit 1; }
-export LD_LIBRARY_PATH="$ROOT/src"
+export LD_LIBRARY_PATH="$PB_DIR"
ip addr add $DNSIP/32 dev lo 2>/dev/null
python3 "$HERE/fake_proxies.py" "$PLOG" > /dev/null 2>&1 & FAKE_PID=$!
python3 "$HERE/fake_dns.py" $DNSIP "$DLOG" > /dev/null 2>&1 & DNS_PID=$!
sleep 1
-stdbuf -oL "$ROOT/cli/ProxyBridge" --verbose 2 \
+stdbuf -oL "$PB_DIR/ProxyBridge" --verbose 2 \
--proxy a=socks5://127.0.0.1:19080 --proxy b=socks5://bob:[email protected]:19081 --proxy h=socks5://localhost:19080 \
--rule "*:blocked.example.test:*:TCP:BLOCK" \
--rule "*:*.example.test:*:TCP:PROXY=a" \
diff --git a/Linux/tests/e2e_openssh.sh b/Linux/tests/e2e_openssh.sh
index 6124e9b..d371da8 100755
--- a/Linux/tests/e2e_openssh.sh
+++ b/Linux/tests/e2e_openssh.sh
@@ -3,13 +3,15 @@
# sudo tests/e2e_openssh.sh
set -u
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"; ROOT="$(dirname "$HERE")"
+PB_DIR="${PB_DIR:-$ROOT/output}" # directory holding the built ProxyBridge + libproxybridge.so (run ../build.sh first)
+[ -x "$PB_DIR/ProxyBridge" ] && [ -f "$PB_DIR/libproxybridge.so" ] || { echo "Build first: (cd Linux && ./build.sh), or set PB_DIR to a directory containing ProxyBridge and libproxybridge.so"; exit 1; }
WORK="$(mktemp -d)"; PASS=0; FAIL=0; ORIGIN=10.77.0.5
ok() { echo " PASS $1"; PASS=$((PASS+1)); }
bad() { echo " FAIL $1"; FAIL=$((FAIL+1)); }
cleanup() { kill $SSHD $SSH $WWW $PB 2>/dev/null; wait 2>/dev/null; ip addr del $ORIGIN/32 dev lo 2>/dev/null; rm -rf "$WORK"; }
trap cleanup EXIT
[ "$(id -u)" = 0 ] || { echo "run as root"; exit 1; }
-export LD_LIBRARY_PATH="$ROOT/src"
+export LD_LIBRARY_PATH="$PB_DIR"
command -v sshd >/dev/null && command -v ssh >/dev/null || { echo "SKIP: openssh not installed"; exit 0; }
ip addr add $ORIGIN/32 dev lo 2>/dev/null
@@ -41,7 +43,7 @@ python3 -m http.server 18500 --bind $ORIGIN --directory "$WORK" >/dev/null 2>&1
sleep 1
SUM=$(sha256sum "$WORK/big.bin" | cut -d' ' -f1)
-stdbuf -oL "$ROOT/cli/ProxyBridge" --verbose 1 --proxy ossh=socks5://127.0.0.1:19090 \
+stdbuf -oL "$PB_DIR/ProxyBridge" --verbose 1 --proxy ossh=socks5://127.0.0.1:19090 \
--rule "curl:$ORIGIN:18500:TCP:PROXY=ossh" > "$WORK/pb.out" 2>&1 & PB=$!
for _ in $(seq 40); do grep -q "ProxyBridge started" "$WORK/pb.out" && break; sleep 0.25; done
@@ -66,7 +68,7 @@ socketserver.ThreadingTCPServer(("10.77.0.5", 18501), H).serve_forever()
PY
UP=$!; sleep 1
kill -INT $PB; wait $PB 2>/dev/null
-stdbuf -oL "$ROOT/cli/ProxyBridge" --proxy ossh=socks5://127.0.0.1:19090 --rule "curl:$ORIGIN:18500-18501:TCP:PROXY=ossh" > "$WORK/pb.out" 2>&1 & PB=$!
+stdbuf -oL "$PB_DIR/ProxyBridge" --proxy ossh=socks5://127.0.0.1:19090 --rule "curl:$ORIGIN:18500-18501:TCP:PROXY=ossh" > "$WORK/pb.out" 2>&1 & PB=$!
for _ in $(seq 40); do grep -q "ProxyBridge started" "$WORK/pb.out" && break; sleep 0.25; done
GOT=$(curl -s -m 60 --data-binary @"$WORK/big.bin" http://$ORIGIN:18501/ )
[ "$GOT" = "$SUM" ] && ok "40 MB upload through OpenSSH SOCKS5: origin received identical bytes" || bad "upload checksum mismatch (got ${GOT:0:20})"
diff --git a/Linux/tests/e2e_rules.sh b/Linux/tests/e2e_rules.sh
index da0f700..38a9ebf 100755
--- a/Linux/tests/e2e_rules.sh
+++ b/Linux/tests/e2e_rules.sh
@@ -3,6 +3,8 @@
# sudo tests/e2e_rules.sh (needs curl, python3; only loopback + TEST-NET addresses are used)
set -u
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"; ROOT="$(dirname "$HERE")"
+PB_DIR="${PB_DIR:-$ROOT/output}" # directory holding the built ProxyBridge + libproxybridge.so (run ../build.sh first)
+[ -x "$PB_DIR/ProxyBridge" ] && [ -f "$PB_DIR/libproxybridge.so" ] || { echo "Build first: (cd Linux && ./build.sh), or set PB_DIR to a directory containing ProxyBridge and libproxybridge.so"; exit 1; }
WORK="$(mktemp -d)"; PLOG="$WORK/proxy.log"; : > "$PLOG"
PASS=0; FAIL=0
ok() { echo " PASS $1"; PASS=$((PASS+1)); }
@@ -17,7 +19,7 @@ blocked() { local out; out=$(curl -s -m 5 "$2" 2>&1; echo "rc=$?"); [[ "$out" ==
cleanup() { kill $PB_PID $FAKE_PID 2>/dev/null; wait 2>/dev/null; rm -rf "$WORK"; }
trap cleanup EXIT
[ "$(id -u)" = 0 ] || { echo "run as root"; exit 1; }
-export LD_LIBRARY_PATH="$ROOT/src"
+export LD_LIBRARY_PATH="$PB_DIR"
python3 "$HERE/fake_proxies.py" "$PLOG" >/dev/null 2>&1 & FAKE_PID=$!
mkdir -p "$WORK/bin" "$WORK/pbpath"
@@ -26,7 +28,7 @@ cp "$CURL" "$WORK/bin/wget"; cp "$CURL" "$WORK/bin/newtool"; cp "$CURL" "$WORK/b
sleep 1
start_pb() { # extra CLI args...
- stdbuf -oL "$ROOT/cli/ProxyBridge" --verbose 1 \
+ stdbuf -oL "$PB_DIR/ProxyBridge" --verbose 1 \
--proxy a=socks5://127.0.0.1:19080 --proxy b=socks5://bob:[email protected]:19081 --proxy c=http://127.0.0.1:19082 \
--proxy d=http://bob:[email protected]:19083 --proxy e=http://bob:[email protected]:19083 "$@" > "$WORK/pb.out" 2>&1 & PB_PID=$!
for _ in $(seq 40); do grep -q "ProxyBridge started" "$WORK/pb.out" && return 0; sleep 0.25; done
diff --git a/Linux/tests/hookbench.sh b/Linux/tests/hookbench.sh
index ea3affc..9bcb12c 100755
--- a/Linux/tests/hookbench.sh
+++ b/Linux/tests/hookbench.sh
@@ -1,13 +1,15 @@
#!/bin/bash
# Overhead of the eBPF hooks on DIRECT traffic. Needs root. sudo tests/hookbench.sh <path-to-hookbench-binary>
HB=${1:?path to hookbench}; ROOT="$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")"
-export LD_LIBRARY_PATH="$ROOT/src"
+PB_DIR="${PB_DIR:-$ROOT/output}" # directory holding the built ProxyBridge + libproxybridge.so (run ../build.sh first)
+[ -x "$PB_DIR/ProxyBridge" ] && [ -f "$PB_DIR/libproxybridge.so" ] || { echo "Build first: (cd Linux && ./build.sh), or set PB_DIR to a directory containing ProxyBridge and libproxybridge.so"; exit 1; }
+export LD_LIBRARY_PATH="$PB_DIR"
IP=10.77.0.1 # alias on lo: local like loopback, but not caught by the implicit-loopback bypass
ip addr add $IP/32 dev lo 2>/dev/null
trap 'ip addr del $IP/32 dev lo 2>/dev/null' EXIT
run() { for i in 1 2 3; do $HB tcp $IP 19555 20000; done; for i in 1 2 3; do $HB udp $IP 19556 1000000; done; }
echo "### A: ProxyBridge not running"; run
-start() { stdbuf -oL "$ROOT/cli/ProxyBridge" "$@" > /tmp/pbbench.out 2>&1 & PB=$!; for _ in $(seq 40); do grep -q "ProxyBridge started" /tmp/pbbench.out && break; sleep 0.25; done; }
+start() { stdbuf -oL "$PB_DIR/ProxyBridge" "$@" > /tmp/pbbench.out 2>&1 & PB=$!; for _ in $(seq 40); do grep -q "ProxyBridge started" /tmp/pbbench.out && break; sleep 0.25; done; }
echo "### B: running, 20 rules for other programs (this binary: empty class -> immediate direct)"
start $(for i in $(seq 20); do echo --rule "someapp$i:*:*:BOTH:PROXY"; done); run; kill -INT $PB; wait $PB 2>/dev/null
echo "### C: running, rules that match this binary but not this destination (full rule evaluation, then direct)"
diff --git a/Linux/tests/scale.sh b/Linux/tests/scale.sh
index 55a5cc0..16ef4d0 100755
--- a/Linux/tests/scale.sh
+++ b/Linux/tests/scale.sh
@@ -4,12 +4,14 @@
set -u
N=${1:-10000}
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"; ROOT="$(dirname "$HERE")"
-export LD_LIBRARY_PATH="$ROOT/src"
+PB_DIR="${PB_DIR:-$ROOT/output}" # directory holding the built ProxyBridge + libproxybridge.so (run ../build.sh first)
+[ -x "$PB_DIR/ProxyBridge" ] && [ -f "$PB_DIR/libproxybridge.so" ] || { echo "Build first: (cd Linux && ./build.sh), or set PB_DIR to a directory containing ProxyBridge and libproxybridge.so"; exit 1; }
+export LD_LIBRARY_PATH="$PB_DIR"
ulimit -n 200000
WORK=$(mktemp -d); trap 'kill $FAKE $PB 2>/dev/null; wait 2>/dev/null; rm -rf $WORK' EXIT
python3 "$HERE/fake_proxies.py" $WORK/log >/dev/null 2>&1 & FAKE=$!
sleep 1
-stdbuf -oL "$ROOT/cli/ProxyBridge" --proxy a=socks5://127.0.0.1:19080 --rule "python3*:192.0.2.0/24:*:TCP:PROXY=a" > $WORK/pb.out 2>&1 & PB=$!
+stdbuf -oL "$PB_DIR/ProxyBridge" --proxy a=socks5://127.0.0.1:19080 --rule "python3*:192.0.2.0/24:*:TCP:PROXY=a" > $WORK/pb.out 2>&1 & PB=$!
for _ in $(seq 40); do grep -q "ProxyBridge started" $WORK/pb.out && break; sleep 0.25; done
rss() { awk '/VmRSS/{print $2}' /proc/$PB/status; }
maps_kb() { bpftool map show 2>/dev/null | grep -oE 'memlock [0-9]+' | awk '{s+=$2} END{printf "%d", s/1024}'; }
diff --git a/Linux/tests/thrbench.sh b/Linux/tests/thrbench.sh
index e5d35bc..37fd38d 100755
--- a/Linux/tests/thrbench.sh
+++ b/Linux/tests/thrbench.sh
@@ -2,7 +2,9 @@
# Throughput through ProxyBridge vs the same application speaking SOCKS5 itself. Needs root.
# sudo tests/thrbench.sh <thrbench-binary> (binary must be named thrbench so process rules can match it)
TB=${1:?path to thrbench binary named "thrbench"}; ROOT="$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")"
-export LD_LIBRARY_PATH="$ROOT/src"
+PB_DIR="${PB_DIR:-$ROOT/output}" # directory holding the built ProxyBridge + libproxybridge.so (run ../build.sh first)
+[ -x "$PB_DIR/ProxyBridge" ] && [ -f "$PB_DIR/libproxybridge.so" ] || { echo "Build first: (cd Linux && ./build.sh), or set PB_DIR to a directory containing ProxyBridge and libproxybridge.so"; exit 1; }
+export LD_LIBRARY_PATH="$PB_DIR"
MB=${MB:-2048}
$TB sink 19990 & SINK=$!; $TB proxy 19991 19990 & PROXY=$!
trap 'kill $SINK $PROXY $PB 2>/dev/null' EXIT
@@ -11,7 +13,7 @@ echo "== baselines (ProxyBridge not running)"
for i in 1 2 3; do $TB direct 127.0.0.1 19990 $MB 1; done
for i in 1 2 3; do $TB socks 19991 192.0.2.7 9999 $MB 1; done
for i in 1 2; do $TB socks 19991 192.0.2.7 9999 $((MB/8)) 8; done
-stdbuf -oL "$ROOT/cli/ProxyBridge" --proxy a=socks5://127.0.0.1:19991 --rule "thrbench:192.0.2.0/24:*:TCP:PROXY=a" > /tmp/thr_pb.out 2>&1 & PB=$!
+stdbuf -oL "$PB_DIR/ProxyBridge" --proxy a=socks5://127.0.0.1:19991 --rule "thrbench:192.0.2.0/24:*:TCP:PROXY=a" > /tmp/thr_pb.out 2>&1 & PB=$!
for _ in $(seq 40); do grep -q "ProxyBridge started" /tmp/thr_pb.out && break; sleep 0.25; done
echo "== through ProxyBridge (app connects to 192.0.2.7:9999, transparently redirected)"
for i in 1 2 3; do $TB direct 192.0.2.7 9999 $MB 1; done