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