fix
This commit is contained in:
parent
896d1a7a3c
commit
8dc1ac818a
@ -1,13 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
import subprocess,os
|
||||
newenv = os.environ.copy()
|
||||
newenv["LD_PRELOAD"] = "/snacks/wireguard/bin/resolve.so"
|
||||
newenv["LD_PRELOAD"] = "/snacks/wireguard/bin/wireguard-resolve.so"
|
||||
|
||||
def default_devices():
|
||||
with open("/proc/1/net/dev", "r") as f:
|
||||
return f.read()
|
||||
def vpn_devices():
|
||||
with open("/proc/self/net/dev", "r") as f:
|
||||
return f.read()
|
||||
|
||||
def wireguard():
|
||||
try:
|
||||
os.mkdir("/run/netns")
|
||||
except FileExistsError:
|
||||
pass
|
||||
|
||||
try:
|
||||
os.symlink("/run/vpn/net", "/run/netns/vpn")
|
||||
os.symlink("/proc/1/ns/net", "/run/netns/default")
|
||||
@ -21,34 +29,30 @@ def wireguard():
|
||||
with open("/proc/sys/net/ipv4/ping_group_range", "w") as f:
|
||||
f.write("0 2147483647")
|
||||
|
||||
with open("/proc/self/net/dev", "r") as f:
|
||||
vpn_devices = f.read()
|
||||
with open("/proc/1/net/dev", "r") as f:
|
||||
default_devices = f.read()
|
||||
|
||||
if "veth-inner" in vpn_devices:
|
||||
if "veth-inner" in vpn_devices():
|
||||
subprocess.run(["ip", "link", "del", "dev", "veth-inner"])
|
||||
if "veth-outer" in vpn_devices:
|
||||
if "veth-outer" in vpn_devices():
|
||||
subprocess.run(["ip", "link", "del", "dev", "veth-outer"])
|
||||
if "vpn" in vpn_devices:
|
||||
if "vpn" in vpn_devices():
|
||||
subprocess.run(["ip", "link", "del", "dev", "vpn"])
|
||||
|
||||
if "veth-inner" in default_devices:
|
||||
if "mynet0" not in vpn_devices():
|
||||
subprocess.run(["ip", "link", "add", "name", "mynet0", "type", "bridge"])
|
||||
|
||||
if "veth-inner" in default_devices():
|
||||
subprocess.run(["nsenter", "--net=/proc/1/ns/net", "ip", "link", "del", "dev", "veth-inner"])
|
||||
if "veth-outer" in default_devices:
|
||||
if "veth-outer" in default_devices():
|
||||
subprocess.run(["nsenter", "--net=/proc/1/ns/net", "ip", "link", "del", "dev", "veth-outer"])
|
||||
if "vpn" in default_devices:
|
||||
if "vpn" in default_devices():
|
||||
subprocess.run(["nsenter", "--net=/proc/1/ns/net", "ip", "link", "del", "dev", "vpn"])
|
||||
|
||||
subprocess.run(["modprobe", "wireguard"])
|
||||
subprocess.run(["nsenter", "--net=/proc/1/ns/net", "ip", "link", "add", "dev", "vpn", "type", "wireguard"])
|
||||
subprocess.run(["nsenter", "--net=/proc/1/ns/net", "ip", "link", "set", "dev", "vpn", "netns", "vpn"])
|
||||
|
||||
subprocess.run(["nsenter", "--net=/run/vpn/net", "/snacks/wireguard/bin/inner.sh"], newenv)
|
||||
subprocess.run(["nsenter", "--net=/proc/1/ns/net", "/snacks/wireguard/bin/outer.sh"], newenv)
|
||||
subprocess.run(["nsenter", "--net=/run/vpn/net", "/snacks/wireguard/scripts/inner.sh"], env=newenv)
|
||||
subprocess.run(["nsenter", "--net=/proc/1/ns/net", "/snacks/wireguard/scripts/outer.sh"], env=newenv)
|
||||
|
||||
try:
|
||||
self_ns = os.readlink("/proc/1/ns/net")
|
||||
self_ns = os.readlink("/proc/self/ns/net")
|
||||
vpn_ns = os.readlink("/run/vpn/net")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
ip link add name mynet0 type bridge
|
||||
#!/usr/bin/env bash
|
||||
ip link add veth-inner type veth peer name veth-outer
|
||||
ip link set dev veth-outer netns default
|
||||
ip link set dev veth-inner master mynet0
|
||||
|
||||
ip link set dev veth-inner up
|
||||
@ -12,7 +12,11 @@ ip link set dev vpn up
|
||||
ip addr flush dev vpn
|
||||
ip route flush dev vpn
|
||||
|
||||
echo ${VPN_IPV4_ADDRESS}
|
||||
echo ${VPN_IPV6_ADDRESS}
|
||||
|
||||
ip addr add ${VPN_IPV4_ADDRESS} dev vpn
|
||||
ip addr add ${VPN_IPV6_ADDRESS} dev vpn
|
||||
|
||||
ip -4 route add default dev vpn
|
||||
ip -6 route add default dev vpn
|
||||
|
Loading…
Reference in New Issue
Block a user