feat(scripts): made scripts take optional args

This commit is contained in:
2025-10-12 01:18:16 +01:00
parent a8aa6bb01c
commit 98aa70e08f
3 changed files with 114 additions and 11 deletions

View File

@@ -19,7 +19,7 @@ type RunCmd struct {
DNSSEC bool `long:"dnssec" help:"Enable DNSSEC"` DNSSEC bool `long:"dnssec" help:"Enable DNSSEC"`
AuthoritativeDNSSEC bool `short:"a" long:"auth-dnssec" help:"Use authoritative DNSSEC validation instead of trusting resolver"` AuthoritativeDNSSEC bool `short:"a" long:"auth-dnssec" help:"Use authoritative DNSSEC validation instead of trusting resolver"`
KeepAlive bool `short:"k" long:"keep-alive" help:"Use persistent connections"` KeepAlive bool `short:"k" long:"keep-alive" help:"Use persistent connections"`
Interface string `long:"iface" default:"any" help:"Capture interface (e.g., eth0, any)"` Interface string `long:"iface" default:"veth1" help:"Capture interface (e.g., eth0, any)"`
Servers []string `short:"s" long:"server" help:"Upstream servers (udp://..., tls://..., https://..., doq://...)"` Servers []string `short:"s" long:"server" help:"Upstream servers (udp://..., tls://..., https://..., doq://...)"`
} }

80
run.sh
View File

@@ -1,8 +1,72 @@
#!/bin/bash #!/bin/bash
TOOL_PATH="$1"/"qol" # Exit on error
DOMAINS_FILE="$1"/"domains.txt" set -e
OUTPUT_DIR="$1"/"results"
# Default values
TOOL_PATH="./qol"
DOMAINS_FILE="./domains.txt"
OUTPUT_DIR="./results"
INTERFACE="veth1"
TIMEOUT="5s"
SLEEP_TIME="1"
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-t|--tool-path)
TOOL_PATH="$2"
shift 2
;;
-d|--domains-file)
DOMAINS_FILE="$2"
shift 2
;;
-o|--output-dir)
OUTPUT_DIR="$2"
shift 2
;;
-I|--interface)
INTERFACE="$2"
shift 2
;;
-T|--timeout)
TIMEOUT="$2"
shift 2
;;
-s|--sleep)
SLEEP_TIME="$2"
shift 2
;;
--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -t, --tool-path PATH Path to qol tool (default: ./qol)"
echo " -d, --domains-file PATH Path to domains file (default: ./domains.txt)"
echo " -o, --output-dir PATH Output directory (default: ./results)"
echo " -I, --interface NAME Network interface (default: veth1)"
echo " -T, --timeout DURATION Timeout duration (default: 5s)"
echo " -s, --sleep SECONDS Sleep between runs (default: 1)"
echo " --help Show this help"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
echo "Configuration:"
echo " Tool path: $TOOL_PATH"
echo " Domains file: $DOMAINS_FILE"
echo " Output dir: $OUTPUT_DIR"
echo " Interface: $INTERFACE"
echo " Timeout: $TIMEOUT"
echo " Sleep time: ${SLEEP_TIME}s"
echo ""
# Connection-based protocols that benefit from keep-alive (TCP-based) # Connection-based protocols that benefit from keep-alive (TCP-based)
CONN_SERVERS=( CONN_SERVERS=(
@@ -35,8 +99,8 @@ CONNLESS_SERVERS=(
# Common args # Common args
COMMON_ARGS=( COMMON_ARGS=(
"$DOMAINS_FILE" "$DOMAINS_FILE"
--interface veth0 --interface "$INTERFACE"
--timeout 5s --timeout "$TIMEOUT"
) )
# Combinations for TCP-based connection protocols # Combinations for TCP-based connection protocols
@@ -78,7 +142,7 @@ for FLAGS in "${CONN_COMBINATIONS[@]}"; do
"${CONN_SERVERS[@]}" \ "${CONN_SERVERS[@]}" \
"${FLAGS_ARRAY[@]}" "${FLAGS_ARRAY[@]}"
sleep 1 sleep "$SLEEP_TIME"
done done
echo "" echo ""
@@ -94,7 +158,7 @@ for FLAGS in "${NO_KEEPALIVE_COMBINATIONS[@]}"; do
"${QUIC_SERVERS[@]}" \ "${QUIC_SERVERS[@]}" \
"${FLAGS_ARRAY[@]}" "${FLAGS_ARRAY[@]}"
sleep 1 sleep "$SLEEP_TIME"
done done
echo "" echo ""
@@ -110,7 +174,7 @@ for FLAGS in "${NO_KEEPALIVE_COMBINATIONS[@]}"; do
"${CONNLESS_SERVERS[@]}" \ "${CONNLESS_SERVERS[@]}" \
"${FLAGS_ARRAY[@]}" "${FLAGS_ARRAY[@]}"
sleep 1 sleep "$SLEEP_TIME"
done done
echo "" echo ""

View File

@@ -3,13 +3,47 @@
# Exit on error # Exit on error
set -e set -e
NETNS_NAME="sdns" # Default values
NETNS_NAME="myapp"
VETH_HOST="veth0" VETH_HOST="veth0"
VETH_NS="veth1" VETH_NS="veth1"
HOST_IP="192.168.100.1" HOST_IP="192.168.100.1"
NS_IP="192.168.100.2" NS_IP="192.168.100.2"
SUBNET="192.168.100.0/24" SUBNET="192.168.100.0/24"
PHYSICAL_IF="en0" PHYSICAL_IF="eth0"
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-n|--namespace)
NETNS_NAME="$2"
shift 2
;;
-p|--physical-if)
PHYSICAL_IF="$2"
shift 2
;;
--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -n, --namespace NAME Namespace name (default: myapp)"
echo " -p, --physical-if NAME Physical interface (default: eth0)"
echo " --help Show this help"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
echo "Configuration:"
echo " Namespace: $NETNS_NAME"
echo " Physical interface: $PHYSICAL_IF"
echo ""
echo "Creating network namespace: $NETNS_NAME" echo "Creating network namespace: $NETNS_NAME"
sudo ip netns add $NETNS_NAME sudo ip netns add $NETNS_NAME
@@ -36,6 +70,11 @@ sudo sysctl -w net.ipv4.ip_forward=1
echo "Setting up NAT" echo "Setting up NAT"
sudo iptables -t nat -A POSTROUTING -s $SUBNET -o $PHYSICAL_IF -j MASQUERADE sudo iptables -t nat -A POSTROUTING -s $SUBNET -o $PHYSICAL_IF -j MASQUERADE
echo "Setting up forwarding rules"
sudo iptables -I FORWARD -i $VETH_HOST -o $PHYSICAL_IF -j ACCEPT
sudo iptables -I FORWARD -i $PHYSICAL_IF -o $VETH_HOST -j ACCEPT
echo ""
echo "Done! Network namespace '$NETNS_NAME' is ready." echo "Done! Network namespace '$NETNS_NAME' is ready."
echo "" echo ""
echo "To run your app in the namespace:" echo "To run your app in the namespace:"