forked from DanielAdolfsson/ndppd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
76 lines (66 loc) · 1.7 KB
/
start.sh
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh
TEST_IP="2606:4700:4700::1111"
function exit_trap() {
echo "Program closed."
}
trap exit_trap INT EXIT
if [ -z "$PROXY_INTERFACE" ]
then
echo "Proxy Interface is not given. Trying to find interface.
You can also set manualy env variable in docker with -e PROXY_INTERFACE=\"eth0\""
PROXY_INTERFACE=`ip ro get $TEST_IP | awk -F"dev " '{print $2}' | cut -d " " -f 1`
if [ $? -eq 0 ]
then
if [ -d "/sys/class/net/$PROXY_INTERFACE" ]; then
echo "Proxy interface is setted to $PROXY_INTERFACE"
else
echo "Err: Program does not found correct interface, $PROXY_INTERFACE" >&2
fi
else
echo "Err: Program can not found interface, $PROXY_INTERFACE" >&2
fi
fi
if [ -z "$IPv6_SUBNET" ]
then
echo "IPv6_SUBNET is not set. System try to find subnet.
You can set manualy env variable in docker with -e IPv6_SUBNET=\"2001:db8:900d:c0de::/64\" arg."
IPv6_SUBNET=`ip ro get $TEST_IP | awk -F"src " '{print $2}' | awk -F":" '{print $1":"$2":"$3":"$4"::/64"}'`
fi
echo "
Proxy Interface: $PROXY_INTERFACE
IPv6 Subnet: $IPv6_SUBNET"
if [ -z "$DOCKER_INTERFACE" ]
then
echo "Docker Interface: is not setted. Using static method"
cat << EOF > /etc/ndppd.conf
route-ttl 30000
proxy $PROXY_INTERFACE {
router yes
timeout 500
ttl 30000
rule $IPv6_SUBNET {
static
}
}
EOF
else
# This method recommend for Scaleway,Ovh,Digitalocean
echo "Docker Interface: $DOCKER_INTERFACE"
cat << EOF > /etc/ndppd.conf
route-ttl 30000
proxy $PROXY_INTERFACE {
router yes
timeout 500
ttl 30000
rule $IPv6_SUBNET {
iface $DOCKER_INTERFACE
}
}
EOF
fi
/usr/sbin/ndppd -c /etc/ndppd.conf -v
if [ $? != 0 ]
then
echo "Error. ndppd exited with err."
sleep 5 # Prevent too many loops
fi