forked from cpcowart/ubiquiti-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path6rd-up
86 lines (77 loc) · 2.44 KB
/
6rd-up
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
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
# This first pass script is intended to be installed as
# /config/scripts/ppp/ip-up.d/6rd-up
#
# /etc/ppp/ip-up exports the following variables to this script:
# PPP_IFACE - interface name (e.g., pppoe0)
# PPP_TTY
# PPP_SPEED
# PPP_LOCAL - our IPv4 address
# PPP_REMOTE
# PPP_IPPARAM
# PPP_TTYNAME
# Future goals:
# - pull configuration out of the script
# - use a template for the config scripts
# - act like a PD client and auto-compute assignments to downstream interfaces
# I want to make this more automatic in the future. Not used yet.
SIXRD_ISP_PREFIX=2602::/24
SIXRD_PREFIX_LEN=$(echo ${SIXRD_ISP_PREFIX} | /usr/bin/cut -d/ -f2)
CPE_PREFIX_LEN=$(( ${SIXRD_PREFIX_LEN} + 32 ))
# This unrolls '::' and 0-pads the quads. Not used yet, but will be useful
# soon
normalize_ipv6() {
ipv6="$1"
/usr/bin/awk -v ipv6="$ipv6" 'END {
while (gsub(/:/,":",ipv6) < 7) {
sub(/::/,":::",ipv6)
}
split(ipv6, arr, /:/)
for (i=1; i <= 8 ; i = i + 1) {
printf "%04x", strtonum("0x" arr[i])
if (i < 8) {
printf ":"
} else {
printf "\n"
}
}
}' </dev/null
}
SPLIT_IP="$(echo $PPP_LOCAL | /usr/bin/tr . ' ')"
SIXRD_LOCAL_FORMAT="2602:%02x:%02x%02x:%02x"
SIXRD_LOCAL_PREFIX=$(printf "${SIXRD_LOCAL_FORMAT}" $SPLIT_IP)
ROUTE6_IPV6="${SIXRD_LOCAL_PREFIX}00::/56"
SWITCH0_IPV6="${SIXRD_LOCAL_PREFIX}00::1/64"
TUN0_IPV6="${SIXRD_LOCAL_PREFIX}FF::/128"
DNS_SERVER="${SIXRD_LOCAL_PREFIX}ff::1"
# If we've run before, we've cached a cleanup script
if [ -f /config/ppp-6rd-cleanup ] ; then
CLEANUP=/config/ppp-6rd-cleanup
else
CLEANUP="/dev/null"
fi
# Source the cleanup script and run the commands to set up the
# address-specific configs again
/bin/vbash $CLEANUP
/bin/vbash <<EOF
source /opt/vyatta/etc/functions/script-template
configure
set protocols static route6 ${ROUTE6_IPV6} blackhole
set interfaces tunnel tun0 address ${TUN0_IPV6}
set interfaces switch switch0 address ${SWITCH0_IPV6}
commit
save
exit
EOF
#set interfaces switch switch0 ipv6 router-advert name-server ${DNS_SERVER}
/bin/cat > /config/ppp-6rd-cleanup <<EOF
source /opt/vyatta/etc/functions/script-template
configure
delete protocols static route6 ${ROUTE6_IPV6}
delete interfaces tunnel tun0 address ${TUN0_IPV6}
delete interfaces switch switch0 address ${SWITCH0_IPV6}
commit
save
exit
EOF
#delete interfaces switch switch0 ipv6 router-advert name-server ${DNS_SERVER}