blob: ba2d226a9e3e0c124998860ed80b03d595a2161b (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#!/bin/sh
# adapted from
# https://unix.stackexchange.com/questions/149293/feed-all-traffic-through-openvpn-for-a-specific-network-namespace-only
# vpn_wrapper.sh creates another script of name helper_script<timestamp>.sh,
# which gets called by openvpn process, exports NAMESPACE_NAME and WRAPPER_PID
# variables and then runs this script
case $script_type in
up)
env
ip netns add $NAMESPACE_NAME
ip netns exec $NAMESPACE_NAME ip link set dev lo up
ip link set dev "$1" up netns $NAMESPACE_NAME mtu "$2"
ip netns exec $NAMESPACE_NAME ip addr add dev "$1" \
"$4/${ifconfig_netmask:-30}" \
${ifconfig_broadcast:+broadcast "$ifconfig_broadcast"}
if [ -n "$ifconfig_ipv6_local" ]; then
ip netns exec $NAMESPACE_NAME ip addr add dev "$1" \
"$ifconfig_ipv6_local"/112
fi
;;
route-up)
ip netns exec $NAMESPACE_NAME ip route add default via "$ifconfig_remote"
if [ -n "$ifconfig_ipv6_remote" ]; then
ip netns exec $NAMESPACE_NAME ip route add default via \
"$ifconfig_ipv6_remote"
fi
# notify our sh process, that openvpn finished initializing
kill -usr1 $WRAPPER_PID
;;
down)
ip netns delete $NAMESPACE_NAME
;;
esac
|