blob: 9098fab4d80d3fb7f3e44e76c2c28a04583be79f [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001#!/bin/sh
2
3path_sh=`nv get path_sh`
4. $path_sh/global.sh
5
6echo "input param is $1"
7echo "Info: wan_ipv6_config.sh $1 start" >> $test_log
8
9wan_addr_temp=`nv get $wan_if"ipv6_wan_ipaddr"`
10wan_addr=`echo $wan_addr_temp | sed 's/\/64//'`
11
12is_chinamobile_pd_diff=`nv get pd_chinamobile_enable`
13pd_chinamobile=`nv get pd_chinamobile`
14#prefix_len=`nv get pd_len_chinamobile`
15prefix_len=`nv get $wan_if"_ipv6_prefix_len"`
16
17b_dhcpv6stateEnabled=`nv get dhcpv6stateEnabled`
18b_dhcpv6statelessEnabled=`nv get dhcpv6statelessEnabled`
19b_dhcpv6statePdEnabled=`nv get dhcpv6statePdEnabled`
20
21############# »ñȡĬÈÏÍø¿ÚÃûÏà¹ØÐÅÏ¢ ############
22get_default_wan_info()
23{
24 wan_if_name=$1
25 wan_if=$defwan6_if
26 wan_addr=`nv get $wan_if"_ipv6_ip"`
27 def_cid=`nv get default_cid`
28
29 if [ "$1" == "pswan" ]; then
30 ipaddr_type=`nv get "pdp_act_type"$def_cid`
31 elif [ "$1" == "ethwan" ]; then
32 ipaddr_type=`nv get eth_act_type`
33 elif [ "$1" == "wifiwan" ]; then
34 ipaddr_type=`nv get wifi_act_type`
35 fi
36
37 #ÐèÒªÓõ½Ïà¹ØÅäÖÃÎļþ
38 dhcp6s_conf=$path_conf/dhcp6s_$wan_if.conf
39 radvd_conf=$path_conf/radvd_$wan_if.conf
40 radvd_pidfile=$path_tmp/radvd_$wan_if.pid
41 ndp_log=$path_conf/ndp_$wan_if.log
42
43 echo "test: default_wan_if_info = $wan_if, wan_addr:$wan_addr"
44}
45
46#############linkup dhcpserver set############
47linkup_add_dns_to_dhcp6s_radvd_conf()
48{
49 # ipv6 dns set
50 ipv6_dns_mode=`nv get $wan_if_name"_ipv6_dns_mode"`
51 echo "ipv6_dns_mode:$ipv6_dns_mode"
52 echo "the input param is $1"
53
54 ipv6_prefer_dns=""
55 ipv6_standby_dns=""
56 if [ "-$ipv6_dns_mode" = "-auto" ];then
57
58 ipv6_pridns_auto=`nv get $wan_if"_ipv6_pridns_auto"`
59 ipv6_secdns_auto=`nv get $wan_if"_ipv6_secdns_auto"`
60
61 if [ -n "$ipv6_pridns_auto" ] && [ "-$ipv6_pridns_auto" != "-::" ] && [ "-$ipv6_pridns_auto" != "-::0" ];then
62 ipv6_prefer_dns=$ipv6_pridns_auto
63 fi
64
65 if [ -n "$ipv6_secdns_auto" ] && [ "-$ipv6_secdns_auto" != "-::" ] && [ "-$ipv6_secdns_auto" != "-::0" ];then
66 ipv6_standby_dns=$ipv6_secdns_auto
67 fi
68
69 elif [ "-$ipv6_dns_mode" = "-manual" ];then
70 #¶ÔÓÚÊÖ¶¯DNS£¬Ò³ÃæÖ»ÄÜÉèÖõ½pswan¿Ú£¬ËùÒÔ¶ÔÓÚÊÖ¶¯dns£¬²»¹ÜºÎÖÖģʽ£¬ÔÝʱ¶¼È¡ÓÃpswanµÄÊÖ¶¯dnsµØÖ·
71 ipv6_pridns_manual=`nv get $pswan_if_name"_ipv6_pridns_manual"`
72 ipv6_secdns_manual=`nv get $pswan_if_name"_ipv6_secdns_manual"`
73
74 if [ -n "$ipv6_pridns_manual" ] && [ "-$ipv6_pridns_manual" != "-::" ] && [ "-$ipv6_pridns_manual" != "-::0" ];then
75 ipv6_prefer_dns=$ipv6_pridns_manual
76 fi
77
78 if [ -n "$ipv6_secdns_manual" ] && [ "-$ipv6_secdns_manual" != "-::" ] && [ "-$ipv6_secdns_manual" != "-::0" ];then
79 ipv6_standby_dns=$ipv6_secdns_manual
80 fi
81
82 fi
83
84 if [ "-$ipv6_prefer_dns" == "-" -a "-$ipv6_standby_dns" == "-" ]; then
85 return
86 else
87 if [ -n "$1" ] && [ "$1" == "dhcp6s" ] ;then
88 echo -e "\toption dns_servers $ipv6_prefer_dns $ipv6_standby_dns;" >> $dhcp6s_conf
89 elif [ -n "$1" ] && [ "$1" == "radvd" ] ;then
90 # del last line
91 sed -i '$d' $radvd_conf
92 echo -e "\tRDNSS $ipv6_prefer_dns $ipv6_standby_dns\n\t{" >> $radvd_conf
93 echo -e "\t\tAdvRDNSSPreference 15;" >> $radvd_conf
94 echo -e "\t\tAdvRDNSSOpen on;" >> $radvd_conf
95 echo -e "\t};\n};" >> $radvd_conf
96 fi
97 fi
98}
99
100linkup_dhcpv6_server_set()
101{
102 dhcp6s_kill
103 rm -fr $dhcp6s_conf
104
105 if [ "-$is_chinamobile_pd_diff" = "-1" ] ; then
106 nv set pd_chinamobile=""
107 nv set pd_len_chinamobile=""
108 dhcp6c -dDf -z $wan_if &
109 for i in a b c d e; do
110 #sleep 1;
111 pd_chinamobile=`nv get pd_chinamobile`
112 if [ "-$pd_chinamobile" == "-" ]; then
113 echo "no pd get";
114 else
115 echo "pd get";
116 break;
117 fi
118 done
119 pd_chinamobile=`nv get pd_chinamobile`
120 prefix_len=`nv get pd_len_chinamobile`
121 if [ "-$pd_chinamobile" == "-" ]; then
122 dhcp6c_kill
123 prefix_len="64"
124 else
125 wan_addr=$pd_chinamobile
126 # here br0 is bind by dhcp6c, need to kill then run dhcp6s£¬need to fix
127 dhcp6c_kill
128 #sleep 1
129 fi
130 else
131 if [ "-$prefix_len" == "-" ]; then
132 prefix_len=64
133 fi
134 echo "not chinamobile"
135 fi
136
137 ipv6_addr_conver "$wan_addr" "$wan_if"
138 dhcpv6_start=`nv get $wan_if"_dhcpv6_start"`
139 dhcpv6_end=`nv get $wan_if"_dhcpv6_end"`
140 prefix_info_temp=`nv get $wan_if"_ipv6_prefix_info"`
141 echo -e "interface br0 {" > $dhcp6s_conf
142 #dhcpv6 pd
143 if [ "-$b_dhcpv6statePdEnabled" = "-1" ];then
144 echo -e "\tserver-preference 255;\n\trenew-time 6000;" >> $dhcp6s_conf
145 echo -e "\trebind-time 9000;\n\tprefer-life-time 1300;" >> $dhcp6s_conf
146 echo -e "\tvalid-life-time 2000;\n\tallow rapid-commit;" >> $dhcp6s_conf
147 echo -e "\tlink br0 {\n\t\tallow unicast;\n\t\tsend unicast;" >> $dhcp6s_conf
148 echo -e "\t\tprefix $prefix_info_temp:/$prefix_len;\n\t};" >> $dhcp6s_conf
149 linkup_add_dns_to_dhcp6s_radvd_conf dhcp6s
150 echo -e "};" >> $dhcp6s_conf
151 dhcp6s -dDf -c $dhcp6s_conf $lan_if &
152 return
153 fi
154 #set up dhcpv6 addr pool
155 if [ "-$b_dhcpv6stateEnabled" = "-1" ];then
156 echo -e "\tserver-preference 255;\n\trenew-time 6000;" >> $dhcp6s_conf
157 echo -e "\trebind-time 9000;\n\tprefer-life-time 1300;" >> $dhcp6s_conf
158 echo -e "\tvalid-life-time 2000;\n\tallow rapid-commit;" >> $dhcp6s_conf
159 echo -e "\tlink br0 {\n\t\tallow unicast;\n\t\tsend unicast;" >> $dhcp6s_conf
160 echo -e "\t\tpool {\n\t\t\trange $dhcpv6_start to $dhcpv6_end/$prefix_len;" >> $dhcp6s_conf
161 echo -e "\t\t};\n\t};" >> $dhcp6s_conf
162 linkup_add_dns_to_dhcp6s_radvd_conf dhcp6s
163 echo -e "};" >> $dhcp6s_conf
164 dhcp6s -dDf -c $dhcp6s_conf $lan_if &
165 else
166 #slaac with dhcp statelessset dns info
167 if [ "-$b_dhcpv6statelessEnabled" = "-1" ];then
168 echo -e "\tlink br0 {\n\t};" >> $dhcp6s_conf
169 linkup_add_dns_to_dhcp6s_radvd_conf dhcp6s
170 echo -e "};" >> $dhcp6s_conf
171 dhcp6s -dDf -c $dhcp6s_conf $lan_if &
172 fi
173 fi
174}
175
176#############linkup radvd set############
177linkup_radvd_set()
178{
179 echo "enter linkup_radvd_set "
180
181 if [ "-$is_chinamobile_pd_diff" = "-1" ] ; then
182 pd_chinamobile=`nv get pd_chinamobile`
183 prefix_len=`nv get pd_len_chinamobile`
184 if [ "-$pd_chinamobile" == "-" ]; then
185 prefix_len="64"
186 else
187 wan_addr=$pd_chinamobile
188 fi
189 else
190 if [ "-$prefix_len" == "-" ]; then
191 prefix_len=64
192 fi
193 echo "not chinamobile"
194 fi
195
196 rm -rf $radvd_conf
197 #wangming delete
198 if [ "-$b_dhcpv6stateEnabled" = "-1" -o "-$b_dhcpv6statePdEnabled" = "-1"];then
199 echo -e "interface br0\n{\n\tAdvSendAdvert on;" > $radvd_conf
200 echo -e "\tAdvManagedFlag on;\n};" >> $radvd_conf
201 radvd_kill
202 rm -rf $radvd_pidfile
203 radvd -d 3 -C $radvd_conf -p $radvd_pidfile &
204 echo "leave linkup_radvd_set "
205 return
206 fi
207
208 cp $path_ro/radvd_template.conf $radvd_conf
209
210 sed -i -e 's/#ipv6_wan_addr#\/64/#ipv6_wan_addr#\/#prefix_len#/g' $radvd_conf
211 sed -i -e s/#ipv6_wan_addr#/$wan_addr/g $radvd_conf
212 sed -i -e s/#prefix_len#/$prefix_len/g $radvd_conf
213 sed -i -e s/#adv_switch#/on/g $radvd_conf
214
215 echo "copy radvd_template.conf"
216 echo "wan_addr:$wan_addr"
217 echo "prefix_len:$prefix_len"
218
219#slaac with dns info
220 if [ "-$b_dhcpv6statelessEnabled" = "-1" ];then
221 echo "use dhcpv6stateless for dns"
222 else
223 sed -i -e 's/AdvOtherConfigFlag on;/AdvOtherConfigFlag off;/g' $radvd_conf
224 linkup_add_dns_to_dhcp6s_radvd_conf radvd
225 fi
226
227 radvd_kill
228 #sleep 1
229 rm -rf $radvd_pidfile
230 radvd -d 3 -C $radvd_conf -p $radvd_pidfile &
231
232 echo "leave linkup_radvd_set "
233}
234
235#############linkup resolve config set############
236linkup_route_set()
237{
238 default_gw_addr_temp=`nv get $wan_if"_ipv6_gw"`
239 echo "ipv6_wan_default_gw = $default_gw_addr_temp"
240
241 echo 0 > /proc/sys/net/ipv6/conf/all/forwarding
242
243 if [ -n "$default_gw_addr_temp" -a "-$default_gw_addr_temp" != "-::" ] ; then
244 ip -6 route add default via $default_gw_addr_temp dev $defwan6_rel
245 else
246 ip -6 route add default dev $defwan6_rel
247 fi
248
249 nv set ipv6_br0_addr="::"
250
251 ipv6_addr_conver "$wan_addr" "$wan_if"
252
253 ipv6_br0_addr_tmp=`nv get ipv6_br0_addr`
254 echo "ipv6_br0_addr_tmp = $ipv6_br0_addr_tmp"
255
256 ip -6 addr add $ipv6_br0_addr_tmp/64 dev br0
257
258 #enable ipv6 packet forwarding
259 #sleep 3
260 echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
261
262 #enable ipv6 neigh discovery proxy
263 echo 1 > /proc/sys/net/ipv6/conf/all/proxy_ndp
264
265 ndp_kill
266 zte_ndp -a -s br0 -d "$wan_if" -l $ndp_log &
267 xlat_enable=`nv get xlat_enable`
268 if [ "-$xlat_enable" == "-1" ];then
269 route_info=`route|grep default`
270 if [ "$route_info" == "" ];then
271 xlat_prefix=`nv get xlat_prefix`
272 #chmod 777 /dev/net/tun
273 if [ "$xlat_prefix" == "" ];then
274 clatd -i $defwan6_if &
275 else
276 clatd -i $defwan6_if -p $xlat_prefix &
277 fi
278 echo 1 > /proc/sys/net/ipv4/ip_forward
279 iptables -t nat -A POSTROUTING -o v4-$defwan6_if -j MASQUERADE
280 sleep 1
281 ip route add default dev v4-$defwan6_if
282 fi
283 fi
284}
285
286############ipv6 shell entry#################
287get_default_wan_info $1
288linkup_route_set
289linkup_dhcpv6_server_set
290linkup_radvd_set
291#linkup_resolve_config_set #ÓÉzte_router¶ÔIPv4£¬IPv6ͳ¼Æ½øÐÐdnsµÄÏà¹Ø²Ù×÷
292