blob: e324c8d489020ad84c9bfb36d010938dc242f268 [file] [log] [blame]
xf.libfc6e712025-02-07 01:54:34 -08001#!/bin/sh
2test_log=`nv get telog_path`
3if [ "$test_log" == "" ]; then
4 test_log=`nv get path_log`"te.log"
5fi
6echo "Info: psext_up.sh $1 start" >> $test_log
7path_conf=`nv get path_conf`
8dhcps_in_cap=`nv get dhcps_in_cap`
9
10echo 1 > /proc/sys/net/ipv4/ip_forward
11c_id=$1
12ps_if=`nv get pswan`$c_id
13eth_if=`nv get "ps_ext"$c_id`
14ext_br="br"$c_id
15pidfile=$path_conf"/udhcpd"$c_id".pid"
16confile=$path_conf"/udhcpd"$c_id".conf"
17leases=$path_conf"/udhcpd"$c_id".leases"
18
19arp_proxy_set()
20{
21 (zte_arp_proxy -i $ext_br 2>> $test_log || echo "Error: zte_arp_proxy -i $ext_br failed." >> $test_log) &
22}
23
24dhcp_set()
25{
26 mask=`nv get $ext_br"_nm"`
27 ifconfig $ext_br netmask $mask 2>>$test_log
28 if [ $? -ne 0 ];then
29 echo "Error: ifconfig $eth_br netmask $mask failed." >> $test_log
30 fi
31 if [ "x$dhcps_in_cap" != "x1" ]; then
32 if [ -e ${pidfile} ]; then
33 kill `cat $pidfile`
34 rm -f $pidfile
35 fi
36 touch $leases
37 udhcpd -f $confile &
38 fi
39}
40
41#»ñÈ¡ip²¢ÅäÖÃps¡¢eth
42get_ipaddr()
43{
44 pdp_ip=`nv get $ps_if"_pdp_ip"`
45 ps_ip=`nv get $ps_if"_ip"`
46 br_ip=`nv get $ext_br"_ip"`
47 ifconfig $ps_if $ps_ip up 2>>$test_log
48 wan_nm=`nv get static_wan_netmask`
49 ifconfig $ps_if netmask $wan_nm 2>>$test_log
50 if [ $? -ne 0 ];then
51 echo "Error: ifconfig $ps_if $ps_ip up failed." >> $test_log
52 fi
53 nv set default_wan_rel=$ps_if
54 #nv set default_cid=$c_id
55 nv set $ext_br"_ip"=$br_ip
56 ifconfig $ext_br $br_ip 2>>$test_log
57 if [ $? -ne 0 ];then
58 echo "Error: ifconfig $ext_br $br_ip up failed." >> $test_log
59 fi
60}
61#·ÓɹæÔò£¬psÓëeth¼¶Áª
62route_set()
63{
64 marknum=`expr $c_id + 20`
65 iptables -t mangle -A PREROUTING -i $ps_if -j MARK --set-mark $marknum
66 rt_num=`expr $c_id + 120`
67
68 ip route add default dev $ext_br table $rt_num
69
70 ip rule add to $pdp_ip fwmark $marknum table $rt_num
71
72 marknum=`expr $c_id + 10`
73 iptables -t mangle -A PREROUTING -i $ext_br -j MARK --set-mark $marknum
74 rt_num=`expr $c_id + 100`
75
76 ip route add default dev $ps_if table $rt_num
77 ip rule add from $pdp_ip fwmark $marknum table $rt_num
78
79 ip route flush cache
80
81 #±¾µØÍøÂçÅäÖÃ
82 iptables -t nat -I POSTROUTING -s $ps_ip -o $ps_if -j SNAT --to $pdp_ip
83
84 route_info=`ip route|grep default`
85
86 if [ "$route_info" == "" ];then
87 route add default dev $ps_if
88 else
89 echo "Debug: default route already exist." >> $test_log
90 fi
91}
92
93ra_mtu_enable=`nv get ra_mtu_enable`
94if [ "$ra_mtu_enable" != "1" ]; then
95 mtu=`nv get mtu`
96 ifconfig $ps_if mtu $mtu
97fi
98brctl addbr $ext_br
99brctl setfd $ext_br 0.1
100brctl addif $ext_br $eth_if
101if [ "$eth_if" != "zvnet"$c_id ]; then
102ifconfig $ext_br up
103else
104ifconfig $ext_br -arp up
105fi
106get_ipaddr
107dhcp_set
108route_set
109arp_proxy_set
110ifconfig $eth_if up
111ismbim=`ps |grep -v grep |grep -w mbim |awk '{printf $1}'`
112if [ "-$ismbim" != "-" ]; then
113 eth_mac=`cat "/sys/class/net/"$eth_if"/address"`
114 arp -s $pdp_ip $eth_mac -i $ext_br 2>>$test_log
115fi
116tc_tbf.sh up $c_id