aboutsummaryrefslogtreecommitdiff
path: root/netns-script
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-05-22 03:43:57 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-05-22 03:43:57 +0200
commit22ed117607f89e9fba4894e4dce18bb78e51b3ee (patch)
treeed9a29482e4fbdead87eb5c5f0544809a2d30cc3 /netns-script
parent83a419bf1559fb4742e3155dab4c1fab3a0dc128 (diff)
download0tdns-22ed117607f89e9fba4894e4dce18bb78e51b3ee.tar.gz
0tdns-22ed117607f89e9fba4894e4dce18bb78e51b3ee.zip
add up/down/route-up script for openvpn
Diffstat (limited to 'netns-script')
-rwxr-xr-xnetns-script37
1 files changed, 37 insertions, 0 deletions
diff --git a/netns-script b/netns-script
new file mode 100755
index 0000000..36cbda9
--- /dev/null
+++ b/netns-script
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# adapted from
+# https://unix.stackexchange.com/questions/149293/feed-all-traffic-through-openvpn-for-a-specific-network-namespace-only
+
+case $script_type in
+ up)
+ ip netns add 0tdns
+ ip netns exec 0tdns ip link set dev lo up
+ ip link set dev "$1" up netns 0tdns mtu "$2"
+ ip netns exec 0tdns ip addr add dev "$1" \
+ "$4/${ifconfig_netmask:-30}" \
+ ${ifconfig_broadcast:+broadcast "$ifconfig_broadcast"}
+ if [ -n "$ifconfig_ipv6_local" ]; then
+ ip netns exec 0tdns ip addr add dev "$1" \
+ "$ifconfig_ipv6_local"/112
+ fi
+ ;;
+ route-up)
+ ip netns exec 0tdns ip route add default via "$ifconfig_remote"
+
+ if [ -n "$ifconfig_ipv6_remote" ]; then
+ ip netns exec 0tdns ip route add default via \
+ "$ifconfig_ipv6_remote"
+ fi
+
+ # notify our sh process, that openvpn finished initializing
+ kill -usr1 `cat /var/lib/0tdns/shell_pid`
+
+ # we no longer need this connection
+ #kill $OPENVPN_PID
+
+ ;;
+ down)
+ ip netns delete 0tdns
+ ;;
+esac