-
Notifications
You must be signed in to change notification settings - Fork 0
/
option-6rd
141 lines (114 loc) · 4.29 KB
/
option-6rd
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#sample test data
#new_option_6rd="14 42 9735 64072 28160 0 0 0 0 0 96.23.219.1"
#reason=RENEW
#new_ip_address=96.21.142.29
#
# Bases on
# 1) dhclient-6rd by Nathan Lutchansky for Ubuntu 10.04
# 2) Alexandre Beloin http://beloin.net/doc/6rd.txt
# Any possessor of a copy of this program may treat it as if it
# were in the public domain. I waive all rights.
# 3) converted to dash by peter silva [email protected] 2015-08-31
#
# Tested on Debian testing as for 2011-11-19, will not work on stable due to lack of ipv6rd kernel option
#
# Last modified 2011-11-19
#
#
# ************************* Installation Instructions *************************
#
# 1) Place this script in /etc/dhcp3/dhclient-exit-hooks.d/option-6rd to assign IPv6 adresses
# 2) Script asumes eth1 - ISP link, eth0 - LAN link
# 3) Do not forget to turn of ipv6 forwarding
# 4) ftp://ftp.bieringer.de/pub/linux/IPv6/ipv6calc/ipv6calc-0.92.0.tar.gz or newer should be in /usr/local/bin
#
# 5) You must edit /etc/dhcp3/dhclient.conf to add the option-6rd definition:
#
# option option-6rd code 212 = { integer 8, integer 8, integer 16, integer 16,
# integer 16, integer 16, integer 16, integer 16,
# integer 16, integer 16, array of ip-address };
#
# 6) In the same file you must also add option-6rd to the "request" list !!!!!!!!!
# 7) apt-get install radvd
#
# *****************************************************************************
#
PATH=/sbin:/usr/local/bin:$PATH
log_6rd() {
##$new_ip_address, and the interface name is passed in $interface
WANIF=$interface
LANIF="eth0"
WANIP4=$new_ip_address
if [ -z "$new_option_6rd" ]; then
logger -p daemon.info -t option-6rd "no 6RD parameters available"
return
fi
if [ "$*" ]; then
push_args=$*
else
push_args=
fi
set $new_option_6rd
srd_masklen=${1}
srd_prefixlen=${2}
srd_prefix="`printf "%x:%x:%x:%x:%x:%x:%x:%x" $3 $4 $5 $6 $7 $8 $9 ${10} | sed -E s/\(:0\)+$/::/`"
srd_braddr=${11}
ipsep="`echo $new_ip_address | sed 's+\.+ +g'`"
set ${ipsep}
if [ $srd_masklen -eq 0 ]; then
logger -p daemon.info -t option-6rd "6RD parameters: 6rd-prefix ${srd_prefix}/${srd_prefixlen} br ${srd_braddr}"
return
elif [ $srd_masklen -le 8 ]; then
masked=$((${1} & ~((1 << (8 - srd_masklen)) - 1)))
srd_relayprefix=${masked}.0.0.0
elif [ $srd_masklen -le 16 ]; then
masked=$((${2} & ~((1 << (16 - srd_masklen)) - 1)))
srd_relayprefix=${1}.${masked}.0.0
elif [ $srd_masklen -le 24 ]; then
masked=$((${3} & ~((1 << (24 - srd_masklen)) - 1)))
srd_relayprefix=${1}.${2}.${masked}.0
elif [ $srd_masklen -le 32 ]; then
masked=$((${4} & ~((1 << (32 - srd_masklen)) - 1)))
srd_relayprefix=${1}.${2}.${3}.${masked}
else
logger -p daemon.info -t option-6rd "invalid IPv4MaskLen $srd_masklen"
return
fi
if [ "$push_args" ]; then
set $push_args
fi
logger -p daemon.info -t option-6rd "6RD parameters: 6rd-prefix ${srd_prefix}/${srd_prefixlen} 6rd-relay_prefix ${srd_relayprefix}/${srd_masklen} br ${srd_braddr}"
delagated_prefix=`ipv6calc -q --action 6rd_local_prefix --6rd_prefix ${srd_prefix}/${srd_prefixlen} --6rd_relay_prefix ${srd_relayprefix}/${srd_masklen} $WANIP4`
ifname_ip6addr="$(echo "$delagated_prefix" | awk '{split($0,a,"/"); print a[1]}')1/$(echo "$delagated_prefix" | awk '{split($0,a,"/"); print a[2]}')"
lan_ip6addr="$(echo "$delagated_prefix" | awk '{split($0,a,"/"); print a[1]}')1"
lan_ip6net="$(echo "$delagated_prefix" | awk '{split($0,a,"/"); print a[1]}')/64" # Need to change if using subnet (if Delagated prefix < 64)
ip tunnel add 6rdif mode sit local $WANIP4
ip tunnel 6rd dev 6rdif 6rd-prefix ${srd_prefix}/${srd_prefixlen} 6rd-relay_prefix ${srd_relayprefix}/${srd_masklen}
ip link set dev 6rdif up
ip -6 addr add "$ifname_ip6addr" dev 6rdif
ip -6 route add default via ::${srd_braddr} dev 6rdif metric 1
ip -6 addr add ${lan_ip6addr}/64 dev $LANIF # Need to change if using subnet (if Delagated prefix < 64)
echo "
interface $LANIF {
AdvSendAdvert on;
MinRtrAdvInterval 3;
MaxRtrAdvInterval 10;
AdvLinkMTU 1280;
prefix $lan_ip6net {
AdvOnLink on;
AdvAutonomous on;
AdvRouterAddr on;
AdvValidLifetime 86400;
AdvPreferredLifetime 86400;
};
RDNSS $lan_ip6addr {
};
};
" > /etc/radvd.conf
/etc/init.d/radvd restart
}
case $reason in
BOUND|RENEW|REBIND|REBOOT)
log_6rd
;;
esac