beginning async version (#84)

This commit is contained in:
ssrlive 2024-02-01 19:15:32 +08:00 committed by GitHub
parent 337619169e
commit 9c4fa4260a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 2022 additions and 3286 deletions

24
scripts/dante.conf Normal file
View file

@ -0,0 +1,24 @@
# logoutput: /var/log/socks.log
internal: 10.0.0.3 port = 10800
external: 10.0.0.3
clientmethod: none
socksmethod: none
user.privileged: root
user.notprivileged: nobody
client pass {
from: 0/0 to: 0/0
log: error connect disconnect
}
socks pass {
from: 0/0 to: 0/0
command: bind connect udpassociate
log: error connect disconnect
socksmethod: none
}
socks pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
command: bindreply udpreply
}

54
scripts/iperf3.sh Executable file
View file

@ -0,0 +1,54 @@
#!/bin/bash
# sudo apt install iperf3 dante-server
# sudo systemctl stop danted
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo $SCRIPT_DIR
netns="test"
dante="danted"
tun2proxy="${SCRIPT_DIR}/../target/release/tun2proxy"
ip netns add "$netns"
ip link add veth0 type veth peer name veth0 netns "$netns"
# Configure veth0 in default ns
ip addr add 10.0.0.2/24 dev veth0
ip link set dev veth0 up
# Configure veth0 in child ns
ip netns exec "$netns" ip addr add 10.0.0.3/24 dev veth0
ip netns exec "$netns" ip addr add 10.0.0.4/24 dev veth0
ip netns exec "$netns" ip link set dev veth0 up
# Configure lo interface in child ns
ip netns exec "$netns" ip addr add 127.0.0.1/8 dev lo
ip netns exec "$netns" ip link set dev lo up
echo "Starting Dante in background ..."
ip netns exec "$netns" "$dante" -f ${SCRIPT_DIR}/dante.conf &
# Start iperf3 server in netns
ip netns exec "$netns" iperf3 -s -B 10.0.0.4 &
sleep 1
# Prepare tun2proxy
ip tuntap add name tun0 mode tun
ip link set tun0 up
ip route add 10.0.0.4 dev tun0
"$tun2proxy" --proxy socks5://10.0.0.3:10800 -v off &
sleep 3
# Run iperf client through tun2proxy
iperf3 -c 10.0.0.4 -P 10 -R
sleep 3
iperf3 -c 10.0.0.4 -P 10
# Clean up
# sudo sh -c "pkill tun2proxy; pkill iperf3; pkill danted; ip link del tun0; ip netns del test"

66
scripts/linux.sh Executable file
View file

@ -0,0 +1,66 @@
#! /usr/bin/bash -x
# Please set the following parameters according to your environment
# BYPASS_IP=123.45.67.89
PROXY_IP=127.0.0.1
PROXY_PORT=1080
PROXY_TYPE=SOCKS5
function core_function() {
local is_envonly="${1}"
local bypass_ip="${2}"
sudo ip tuntap add name tun0 mode tun
sudo ip link set tun0 up
sudo ip route add "${bypass_ip}" $(ip route | grep '^default' | cut -d ' ' -f 2-)
sudo ip route add 128.0.0.0/1 dev tun0
sudo ip route add 0.0.0.0/1 dev tun0
sudo ip route add ::/1 dev tun0
sudo ip route add 8000::/1 dev tun0
sudo sh -c "echo nameserver 198.18.0.1 > /etc/resolv.conf"
if [ "$is_envonly" = true ]; then
read -n 1 -s -r -p "Don't do anything. If you want to exit and clearup environment, press any key..."
echo ""
restore
else
trap 'echo "" && echo "tun2proxy exited with code: $?" && restore' EXIT
local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local APP_BIN_PATH="${SCRIPT_DIR}/../target/release/tun2proxy"
"${APP_BIN_PATH}" --tun tun0 --proxy "${PROXY_TYPE}://${PROXY_IP}:${PROXY_PORT}" -v trace
fi
}
function restore() {
sudo ip link del tun0
sudo systemctl restart systemd-resolved.service
}
function main() {
local action=${1}
# [ -z ${1} ] && action="envonly"
local bypass_ip=${2}
# [ -z ${2} ] && bypass_ip="123.45.67.89"
case "${action}" in
envonly)
core_function true "${bypass_ip}"
;;
tun2proxy)
core_function false "${bypass_ip}"
;;
*)
echo "Arguments error! [${action}]"
echo "Usage: `basename $0` [envonly|tun2proxy] [bypass_ip]"
;;
esac
exit 0
}
main "$@"

83
scripts/rperf.sh Executable file
View file

@ -0,0 +1,83 @@
#!/bin/bash
function install_rperf_bin() {
local rperf_bin_url="https://github.com/ssrlive/rperf/releases/latest/download/rperf-x86_64-unknown-linux-musl.zip"
local rperf_bin_zip_file="rperf-x86_64-unknown-linux-musl.zip"
command -v rperf > /dev/null
if [ $? -ne 0 ]; then
echo "Downloading rperf binary ..."
wget "$rperf_bin_url" >/dev/null 2>&1
unzip "$rperf_bin_zip_file" rperf -d /usr/local/bin/ >/dev/null 2>&1
rm "$rperf_bin_zip_file"
fi
rperf -h >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to install rperf binary"
exit 1
fi
}
install_rperf_bin
sudo apt install dante-server -y >/dev/null 2>&1
sudo systemctl stop danted
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# echo $SCRIPT_DIR
netns="test"
dante="danted"
tun2proxy="${SCRIPT_DIR}/../target/release/tun2proxy"
ip netns add "$netns"
ip link add veth0 type veth peer name veth0 netns "$netns"
# Configure veth0 in default ns
ip addr add 10.0.0.2/24 dev veth0
ip link set dev veth0 up
# Configure veth0 in child ns
ip netns exec "$netns" ip addr add 10.0.0.3/24 dev veth0
ip netns exec "$netns" ip addr add 10.0.0.4/24 dev veth0
ip netns exec "$netns" ip link set dev veth0 up
# Configure lo interface in child ns
ip netns exec "$netns" ip addr add 127.0.0.1/8 dev lo
ip netns exec "$netns" ip link set dev lo up
echo "Starting Dante in background ..."
ip netns exec "$netns" "$dante" -f ${SCRIPT_DIR}/dante.conf &
# Start rperf server in netns
ip netns exec "$netns" rperf -s -B 10.0.0.4 &
sleep 1
# Prepare tun2proxy
ip tuntap add name tun0 mode tun
ip link set tun0 up
ip route add 10.0.0.4 dev tun0
"$tun2proxy" --proxy socks5://10.0.0.3:10800 -v off &
sleep 3
# Run rperf client through tun2proxy
rperf -c 10.0.0.4 -v off -P 1 -r
sleep 3
rperf -c 10.0.0.4 -v off -P 1
sleep 3
rperf -c 10.0.0.4 -v off -P 1 -u
sleep 3
rperf -c 10.0.0.4 -v trace -P 1 -u -r
# Clean up
# sudo sh -c "pkill tun2proxy; pkill rperf; pkill danted; ip link del tun0; ip netns del test"