blob: 58613505de2d3fcddea91408e3cd16dc4da78312 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/bin/sh
2test_log=`nv get telog_path`
3if [ "$test_log" == "" ]; then
4 test_log=`nv get path_log`"te.log"
5fi
6
7c_id=$1
8path_conf=`nv get path_conf`
9path_tmp=`nv get path_tmp`
10dhcp6s_conf=$path_conf/dhcp6s$c_id.conf
11radvd_conf=$path_conf/radvd$c_id.conf
12ndp_log=$path_conf/ndp$c_id.log
13radvd_pidfile=$path_tmp/radvd$c_id.pid
14
15ps_if=`nv get pswan`$c_id
16eth_if=`nv get "ps_ext"$c_id`
17br_if="br"$c_id
18
19echo "Info: psext_updown_ipv6.sh $ps_if $eth_if $br_if start" >> $test_log
20
21prefix_len=`nv get $ps_if"_ipv6_prefix_len"`
22br_ip=`nv get $br_if"_ipv6_ip"`
23ps_ip=`nv get $ps_if"_ipv6_ip"`
24pdp_ip=`nv get $ps_if"_ipv6_pdp"`
25local_ipv6_addr=`nv get $ps_if"_ipv6_local"`
lh758261d2023-07-13 05:52:04 -070026dhcps_in_cap=`nv get dhcps_in_cap`
lh9ed821d2023-04-07 01:36:19 -070027
28#获取ip并配置ps、eth
29linkup_get_addr()
30{
31 #disable the forwarding to send RS and not set the addr when receive ra packet
32 echo 0 > /proc/sys/net/ipv6/conf/all/forwarding
33 echo 0 > /proc/sys/net/ipv6/conf/$ps_if/accept_ra
34 echo 0 > /proc/sys/net/ipv6/conf/$eth_if/accept_ra
35 echo 0 > /proc/sys/net/ipv6/conf/$br_if/accept_ra
36 #call the slaac program to get the prefix addr
37 ifconfig $ps_if up 2>>$test_log
38 if [ $? -ne 0 ];then
39 echo "Error: ifconfig $ps_if up failed." >> $test_log
40 fi
41 ip -6 addr add $local_ipv6_addr/64 dev $ps_if 2>>$test_log
42 brctl addbr $br_if
43 brctl setfd $br_if 0.1
xf.li6c8fc1e2023-08-12 00:11:09 -070044 if [ "$eth_if" != "zvnet"$c_id ]; then
lh9ed821d2023-04-07 01:36:19 -070045 ifconfig $br_if up 2>>$test_log
xf.li6c8fc1e2023-08-12 00:11:09 -070046 else
47 ifconfig $br_if -arp up 2>>$test_log
48 fi
lh9ed821d2023-04-07 01:36:19 -070049 if [ $? -ne 0 ];then
50 echo "Error: ifconfig $br_if up failed." >> $test_log
51 fi
52 ip -6 addr add $br_ip/64 dev $br_if
53 ip -6 addr add $ps_ip/126 dev $ps_if 2>>$test_log
54 if [ $? -ne 0 ];then
55 echo "Error: ip -6 addr add $ps_ip/126 dev $ps_if failed." >> $test_log
56 fi
57 nv set $ps_if"_ipv6_state"="working"
58}
59
60#路由规则,ps与eth级联
61linkup_route_set()
62{
63 echo 0 > /proc/sys/net/ipv6/conf/all/forwarding
64
65 marknum=`expr $c_id + 60`
66 ip6tables -t mangle -A PREROUTING -i $ps_if -j MARK --set-mark $marknum
67 rt_num=`expr $c_id + 160`
68 ip -6 route add default dev $br_if table $rt_num
69 ip -6 rule add to $pdp_ip/64 fwmark $marknum table $rt_num
70
71 marknum=`expr $c_id + 50`
72 ip6tables -t mangle -A PREROUTING -i $br_if -j MARK --set-mark $marknum
73 rt_num=`expr $c_id + 150`
74 ip -6 route add default dev $ps_if table $rt_num
75 ip -6 rule add from $pdp_ip/64 fwmark $marknum table $rt_num
xf.lie31de8b2023-12-26 23:38:58 -080076 gw_in_cap=`nv get gw_in_cap`
77 if [ "x$gw_in_cap" != "x1" ]; then
lh9ed821d2023-04-07 01:36:19 -070078 ip6tables -t filter -A FORWARD -p icmpv6 --icmpv6-type 135 -j DROP
xf.lie31de8b2023-12-26 23:38:58 -080079 fi
lh9ed821d2023-04-07 01:36:19 -070080 ip -6 route flush cache
xf.li9d1a0e12023-09-20 01:43:20 -070081
82 route_info=`ip -6 route|grep default`
lh9ed821d2023-04-07 01:36:19 -070083
xf.li9d1a0e12023-09-20 01:43:20 -070084 if [ "$route_info" == "" ];then
85 #这句设完,里面可以ping通外网了
86 echo "Info: route_set ps_ip=$ps_ip" >> $test_log
87 #ip -6 route add default via $ps_ip dev $ps_if
88 ip -6 route add default dev $ps_if 2>>$test_log
89 else
90 echo "Debug: default route6 already exist." >> $test_log
91 fi
92
lh9ed821d2023-04-07 01:36:19 -070093 if [ $? -ne 0 ];then
94 echo "Error: ip -6 route add default dev $ps_if failed." >> $test_log
95 fi
96
97 #enable ipv6 packet forwarding
98 echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
99 echo 1 > /proc/sys/net/ipv6/conf/$ps_if/accept_ra
100 echo 1 > /proc/sys/net/ipv6/conf/$eth_if/accept_ra
101 echo 1 > /proc/sys/net/ipv6/conf/$br_if/accept_ra
102 #enable ipv6 neigh discovery proxy
103 echo 1 > /proc/sys/net/ipv6/conf/all/proxy_ndp
lh758261d2023-07-13 05:52:04 -0700104 if [ "x$dhcps_in_cap" != "x1" ]; then
lh9ed821d2023-04-07 01:36:19 -0700105 zte_ndp -a -s $br_if -d $ps_if -l $ndp_log -p &
lh758261d2023-07-13 05:52:04 -0700106 fi
lh9ed821d2023-04-07 01:36:19 -0700107}
108
109linkup_dhcpv6_set()
110{
lh758261d2023-07-13 05:52:04 -0700111 if [ "x$dhcps_in_cap" != "x1" ]; then
lh9ed821d2023-04-07 01:36:19 -0700112 dhcp6s -dDf -c $dhcp6s_conf $br_if &
lh758261d2023-07-13 05:52:04 -0700113 fi
lh9ed821d2023-04-07 01:36:19 -0700114}
115
116linkup_radvd_set()
117{
lh758261d2023-07-13 05:52:04 -0700118 if [ "x$dhcps_in_cap" != "x1" ]; then
lh9ed821d2023-04-07 01:36:19 -0700119 radvd -d 3 -C $radvd_conf -p $radvd_pidfile &
lh758261d2023-07-13 05:52:04 -0700120 fi
lh9ed821d2023-04-07 01:36:19 -0700121}
122
123mtu=`nv get mtu`
124ifconfig $ps_if mtu $mtu
125linkup_get_addr
126linkup_route_set
127linkup_dhcpv6_set
128linkup_radvd_set
129brctl addif $br_if $eth_if
130ifconfig $eth_if up
131tc_tbf.sh up $c_id
132echo "Info: psext_up_ipv6.sh leave" >> $test_log