100 lines
2.5 KiB
Bash
Executable file
100 lines
2.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -e
|
|
set -u
|
|
set -x
|
|
|
|
INT_650="wlx000f55a862c8"
|
|
INT_550="wlxbi"
|
|
INT_LOCAL="wlx503eaa74ba0b"
|
|
|
|
export HOME=${HOME:-"/root"}
|
|
|
|
cd $PWD
|
|
|
|
function create_virt_ap() {
|
|
dev=$1
|
|
newname=$2
|
|
|
|
iw dev $dev interface add $newname type managed addr 50:3e:aa:74:ba:1b || echo "Failed to setup virtual ap interface"
|
|
}
|
|
|
|
function setup_ns() {
|
|
name=$1
|
|
interface=$2
|
|
subnet=$3
|
|
public_addr=$(echo $subnet | perl -pe 's|\.0(/\d+)$|.2$1|')
|
|
private_addr=$(echo $subnet | perl -pe 's|\.0(/\d+)$|.1$1|')
|
|
mirror_addr=$(echo $subnet | perl -pe 's|\.0(/\d+)$|.1|')
|
|
|
|
ip netns delete $name >& /dev/null && echo "Removed old $name net namespace" || echo "No $name net namespace present"
|
|
ip link delete $name-public type veth >& /dev/null && echo "Removed old $name veth device" || echo "No $name veth device present"
|
|
|
|
ip netns add $name
|
|
ip link add ${name}-private type veth peer name ${name}-public
|
|
ip link set ${name}-private netns $name
|
|
|
|
export PHY=$(iw dev $interface info | grep wiphy | perl -pe 's/^\s+wiphy (.*)\n$/phy$1/g;')
|
|
|
|
iw phy $PHY set netns name $name
|
|
|
|
sleep 1
|
|
|
|
ip addr add $public_addr dev ${name}-public
|
|
ip link set ${name}-public up
|
|
|
|
ip netns exec $name ip link set dev lo up
|
|
ip netns exec $name ip addr add $private_addr dev ${name}-private
|
|
ip netns exec $name ip link set ${name}-private up
|
|
# ip netns exec $name iptables -t nat -A OUTPUT -d $mirror_addr -j DNAT --to-destination 10.99.77.1
|
|
# ip netns exec $name iptables -t nat -A POSTROUTING -s 10.99.77.1 -j SNAT --to-source $mirror_addr
|
|
}
|
|
|
|
function enable_interface() {
|
|
name=$1
|
|
interface=$2
|
|
wpa_config=$3
|
|
|
|
export PATH_DHCLIENT_PID=$PWD/pids/dhclient.$name.pid
|
|
|
|
# if [[ -e $PWD/pids/wpa.$name.pid ]]; then
|
|
# fi
|
|
|
|
ip netns exec $name dhclient -r || echo "No dhclient found"
|
|
(
|
|
ip netns exec $name wpa_supplicant -c$wpa_config -i$interface -P$PWD/pids/wpa.$name.pid &
|
|
sleep 10;
|
|
ip netns exec $name dhclient -cf $PWD/dhclient/dhclient_iso.conf $interface
|
|
) &
|
|
|
|
unset PATH_DHCLIENT_PID
|
|
}
|
|
|
|
function start_proxy() {
|
|
name=$1
|
|
|
|
ip netns exec $name tinyproxy -c $PWD/proxy/$name.conf
|
|
}
|
|
|
|
# virtual_interfaces "wlan0" "wlan650gw" "wlan550gw6"
|
|
|
|
echo ENV
|
|
export
|
|
echo
|
|
echo
|
|
|
|
sleep 10
|
|
|
|
setup_ns "dr650gw" $INT_650 "10.99.79.0/24"
|
|
setup_ns "dr550gw" $INT_550 "10.99.78.0/24"
|
|
|
|
enable_interface "dr650gw" $INT_650 "$PWD/wpa_supplicant/wpa_650gw.conf"
|
|
enable_interface "dr550gw" $INT_550 "$PWD/wpa_supplicant/wpa_550gw.conf"
|
|
|
|
sleep 2
|
|
|
|
start_proxy "dr550gw"
|
|
start_proxy "dr650gw"
|
|
|
|
create_virt_ap $INT_LOCAL "wlxaproot"
|
|
|