blob: c67e4fe7ddebaa02e8e11779f703d5afa9f6986c [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`
lh758261d2023-07-13 05:52:04 -07008dhcps_in_cap=`nv get dhcps_in_cap`
lh9ed821d2023-04-07 01:36:19 -07009
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
lh758261d2023-07-13 05:52:04 -070031 if [ "x$dhcps_in_cap" != "x1" ]; then
lh9ed821d2023-04-07 01:36:19 -070032 if [ -e ${pidfile} ]; then
33 kill `cat $pidfile`
34 rm -f $pidfile
35 fi
36 touch $leases
37 udhcpd -f $confile &
lh758261d2023-07-13 05:52:04 -070038 fi
lh9ed821d2023-04-07 01:36:19 -070039}
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"`
lh758261d2023-07-13 05:52:04 -070047 ifconfig $ps_if $ps_ip netmask 255.255.255.0 up 2>>$test_log
lh9ed821d2023-04-07 01:36:19 -070048 if [ $? -ne 0 ];then
49 echo "Error: ifconfig $ps_if $ps_ip up failed." >> $test_log
50 fi
51 nv set default_wan_rel=$ps_if
xf.li742dd022023-06-08 01:43:32 -070052 #nv set default_cid=$c_id
lh9ed821d2023-04-07 01:36:19 -070053 nv set $ext_br"_ip"=$br_ip
54 ifconfig $ext_br $br_ip 2>>$test_log
55 if [ $? -ne 0 ];then
56 echo "Error: ifconfig $ext_br $br_ip up failed." >> $test_log
57 fi
58}
59#·ÓɹæÔò£¬psÓëeth¼¶Áª
60route_set()
61{
62 marknum=`expr $c_id + 20`
63 iptables -t mangle -A PREROUTING -i $ps_if -j MARK --set-mark $marknum
64 rt_num=`expr $c_id + 120`
65
66 ip route add default dev $ext_br table $rt_num
67
68 ip rule add to $pdp_ip fwmark $marknum table $rt_num
69
70 marknum=`expr $c_id + 10`
71 iptables -t mangle -A PREROUTING -i $ext_br -j MARK --set-mark $marknum
72 rt_num=`expr $c_id + 100`
73
74 ip route add default dev $ps_if table $rt_num
75 ip rule add from $pdp_ip fwmark $marknum table $rt_num
76
77 ip route flush cache
78
79 #±¾µØÍøÂçÅäÖÃ
80 iptables -t nat -I POSTROUTING -s $ps_ip -o $ps_if -j SNAT --to $pdp_ip
81
xf.li742dd022023-06-08 01:43:32 -070082 route_info=`ip route|grep default`
lh9ed821d2023-04-07 01:36:19 -070083
84 if [ "$route_info" == "" ];then
85 route add default dev $ps_if
86 else
87 echo "Debug: default route already exist." >> $test_log
88 fi
89}
90
91mtu=`nv get mtu`
92ifconfig $ps_if mtu $mtu
93brctl addbr $ext_br
94brctl setfd $ext_br 0.1
95brctl addif $ext_br $eth_if
xf.li6c8fc1e2023-08-12 00:11:09 -070096if [ "$eth_if" != "zvnet"$c_id ]; then
lh9ed821d2023-04-07 01:36:19 -070097ifconfig $ext_br up
xf.li6c8fc1e2023-08-12 00:11:09 -070098else
99ifconfig $ext_br -arp up
100fi
lh9ed821d2023-04-07 01:36:19 -0700101get_ipaddr
102dhcp_set
103route_set
104arp_proxy_set
105ifconfig $eth_if up
106ismbim=`ps |grep -v grep |grep -w mbim |awk '{printf $1}'`
107if [ "-$ismbim" != "-" ]; then
108 eth_mac=`cat "/sys/class/net/"$eth_if"/address"`
109 arp -s $pdp_ip $eth_mac -i $ext_br 2>>$test_log
110fi
111tc_tbf.sh up $c_id